public_key.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* Asymmetric public-key algorithm definitions
  3. *
  4. * See Documentation/crypto/asymmetric-keys.txt
  5. *
  6. * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
  7. * Written by David Howells (dhowells@redhat.com)
  8. */
  9. #ifndef _LINUX_PUBLIC_KEY_H
  10. #define _LINUX_PUBLIC_KEY_H
  11. #ifdef __UBOOT__
  12. #include <linux/types.h>
  13. #else
  14. #include <linux/keyctl.h>
  15. #endif
  16. #include <linux/oid_registry.h>
  17. /*
  18. * Cryptographic data for the public-key subtype of the asymmetric key type.
  19. *
  20. * Note that this may include private part of the key as well as the public
  21. * part.
  22. */
  23. struct public_key {
  24. void *key;
  25. u32 keylen;
  26. enum OID algo;
  27. void *params;
  28. u32 paramlen;
  29. bool key_is_private;
  30. const char *id_type;
  31. const char *pkey_algo;
  32. };
  33. extern void public_key_free(struct public_key *key);
  34. /*
  35. * Public key cryptography signature data
  36. */
  37. struct public_key_signature {
  38. struct asymmetric_key_id *auth_ids[2];
  39. u8 *s; /* Signature */
  40. u32 s_size; /* Number of bytes in signature */
  41. u8 *digest;
  42. u8 digest_size; /* Number of bytes in digest */
  43. const char *pkey_algo;
  44. const char *hash_algo;
  45. const char *encoding;
  46. };
  47. extern void public_key_signature_free(struct public_key_signature *sig);
  48. #ifndef __UBOOT__
  49. extern struct asymmetric_key_subtype public_key_subtype;
  50. struct key;
  51. struct key_type;
  52. union key_payload;
  53. extern int restrict_link_by_signature(struct key *dest_keyring,
  54. const struct key_type *type,
  55. const union key_payload *payload,
  56. struct key *trust_keyring);
  57. extern int restrict_link_by_key_or_keyring(struct key *dest_keyring,
  58. const struct key_type *type,
  59. const union key_payload *payload,
  60. struct key *trusted);
  61. extern int restrict_link_by_key_or_keyring_chain(struct key *trust_keyring,
  62. const struct key_type *type,
  63. const union key_payload *payload,
  64. struct key *trusted);
  65. extern int query_asymmetric_key(const struct kernel_pkey_params *,
  66. struct kernel_pkey_query *);
  67. extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *);
  68. extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *);
  69. extern int create_signature(struct kernel_pkey_params *, const void *, void *);
  70. extern int verify_signature(const struct key *,
  71. const struct public_key_signature *);
  72. #endif /* __UBOOT__ */
  73. int public_key_verify_signature(const struct public_key *pkey,
  74. const struct public_key_signature *sig);
  75. #endif /* _LINUX_PUBLIC_KEY_H */