public_key.h 2.4 KB

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