public_key.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Asymmetric public-key algorithm definitions
  2. *
  3. * See Documentation/crypto/asymmetric-keys.txt
  4. *
  5. * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
  6. * Written by David Howells (dhowells@redhat.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public Licence
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the Licence, or (at your option) any later version.
  12. */
  13. #ifndef _LINUX_PUBLIC_KEY_H
  14. #define _LINUX_PUBLIC_KEY_H
  15. #include <linux/mpi.h>
  16. #include <crypto/hash_info.h>
  17. enum pkey_algo {
  18. PKEY_ALGO_DSA,
  19. PKEY_ALGO_RSA,
  20. PKEY_ALGO__LAST
  21. };
  22. extern const char *const pkey_algo_name[PKEY_ALGO__LAST];
  23. extern const struct public_key_algorithm *pkey_algo[PKEY_ALGO__LAST];
  24. /* asymmetric key implementation supports only up to SHA224 */
  25. #define PKEY_HASH__LAST (HASH_ALGO_SHA224 + 1)
  26. enum pkey_id_type {
  27. PKEY_ID_PGP, /* OpenPGP generated key ID */
  28. PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */
  29. PKEY_ID_PKCS7, /* Signature in PKCS#7 message */
  30. PKEY_ID_TYPE__LAST
  31. };
  32. extern const char *const pkey_id_type_name[PKEY_ID_TYPE__LAST];
  33. /*
  34. * The use to which an asymmetric key is being put.
  35. */
  36. enum key_being_used_for {
  37. VERIFYING_MODULE_SIGNATURE,
  38. VERIFYING_FIRMWARE_SIGNATURE,
  39. VERIFYING_KEXEC_PE_SIGNATURE,
  40. VERIFYING_KEY_SIGNATURE,
  41. VERIFYING_KEY_SELF_SIGNATURE,
  42. VERIFYING_UNSPECIFIED_SIGNATURE,
  43. NR__KEY_BEING_USED_FOR
  44. };
  45. extern const char *const key_being_used_for[NR__KEY_BEING_USED_FOR];
  46. /*
  47. * Cryptographic data for the public-key subtype of the asymmetric key type.
  48. *
  49. * Note that this may include private part of the key as well as the public
  50. * part.
  51. */
  52. struct public_key {
  53. const struct public_key_algorithm *algo;
  54. u8 capabilities;
  55. #define PKEY_CAN_ENCRYPT 0x01
  56. #define PKEY_CAN_DECRYPT 0x02
  57. #define PKEY_CAN_SIGN 0x04
  58. #define PKEY_CAN_VERIFY 0x08
  59. enum pkey_algo pkey_algo : 8;
  60. enum pkey_id_type id_type : 8;
  61. union {
  62. MPI mpi[5];
  63. struct {
  64. MPI p; /* DSA prime */
  65. MPI q; /* DSA group order */
  66. MPI g; /* DSA group generator */
  67. MPI y; /* DSA public-key value = g^x mod p */
  68. MPI x; /* DSA secret exponent (if present) */
  69. } dsa;
  70. struct {
  71. MPI n; /* RSA public modulus */
  72. MPI e; /* RSA public encryption exponent */
  73. MPI d; /* RSA secret encryption exponent (if present) */
  74. MPI p; /* RSA secret prime (if present) */
  75. MPI q; /* RSA secret prime (if present) */
  76. } rsa;
  77. };
  78. };
  79. extern void public_key_destroy(void *payload);
  80. /*
  81. * Public key cryptography signature data
  82. */
  83. struct public_key_signature {
  84. u8 *digest;
  85. u8 digest_size; /* Number of bytes in digest */
  86. u8 nr_mpi; /* Occupancy of mpi[] */
  87. enum pkey_algo pkey_algo : 8;
  88. enum hash_algo pkey_hash_algo : 8;
  89. union {
  90. MPI mpi[2];
  91. struct {
  92. MPI s; /* m^d mod n */
  93. } rsa;
  94. struct {
  95. MPI r;
  96. MPI s;
  97. } dsa;
  98. };
  99. };
  100. struct key;
  101. extern int verify_signature(const struct key *key,
  102. const struct public_key_signature *sig);
  103. struct asymmetric_key_id;
  104. extern struct key *x509_request_asymmetric_key(struct key *keyring,
  105. const struct asymmetric_key_id *id,
  106. const struct asymmetric_key_id *skid,
  107. bool partial);
  108. #endif /* _LINUX_PUBLIC_KEY_H */