public_key.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 <keys/asymmetric-type.h>
  17. #include <crypto/hash_info.h>
  18. enum pkey_algo {
  19. PKEY_ALGO_DSA,
  20. PKEY_ALGO_RSA,
  21. PKEY_ALGO__LAST
  22. };
  23. extern const char *const pkey_algo_name[PKEY_ALGO__LAST];
  24. extern const struct public_key_algorithm *pkey_algo[PKEY_ALGO__LAST];
  25. /* asymmetric key implementation supports only up to SHA224 */
  26. #define PKEY_HASH__LAST (HASH_ALGO_SHA224 + 1)
  27. enum pkey_id_type {
  28. PKEY_ID_PGP, /* OpenPGP generated key ID */
  29. PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */
  30. PKEY_ID_PKCS7, /* Signature in PKCS#7 message */
  31. PKEY_ID_TYPE__LAST
  32. };
  33. extern const char *const pkey_id_type_name[PKEY_ID_TYPE__LAST];
  34. /*
  35. * The use to which an asymmetric key is being put.
  36. */
  37. enum key_being_used_for {
  38. VERIFYING_MODULE_SIGNATURE,
  39. VERIFYING_FIRMWARE_SIGNATURE,
  40. VERIFYING_KEXEC_PE_SIGNATURE,
  41. VERIFYING_KEY_SIGNATURE,
  42. VERIFYING_KEY_SELF_SIGNATURE,
  43. VERIFYING_UNSPECIFIED_SIGNATURE,
  44. NR__KEY_BEING_USED_FOR
  45. };
  46. extern const char *const key_being_used_for[NR__KEY_BEING_USED_FOR];
  47. /*
  48. * Cryptographic data for the public-key subtype of the asymmetric key type.
  49. *
  50. * Note that this may include private part of the key as well as the public
  51. * part.
  52. */
  53. struct public_key {
  54. const struct public_key_algorithm *algo;
  55. u8 capabilities;
  56. #define PKEY_CAN_ENCRYPT 0x01
  57. #define PKEY_CAN_DECRYPT 0x02
  58. #define PKEY_CAN_SIGN 0x04
  59. #define PKEY_CAN_VERIFY 0x08
  60. enum pkey_algo pkey_algo : 8;
  61. enum pkey_id_type id_type : 8;
  62. union {
  63. MPI mpi[5];
  64. struct {
  65. MPI p; /* DSA prime */
  66. MPI q; /* DSA group order */
  67. MPI g; /* DSA group generator */
  68. MPI y; /* DSA public-key value = g^x mod p */
  69. MPI x; /* DSA secret exponent (if present) */
  70. } dsa;
  71. struct {
  72. MPI n; /* RSA public modulus */
  73. MPI e; /* RSA public encryption exponent */
  74. MPI d; /* RSA secret encryption exponent (if present) */
  75. MPI p; /* RSA secret prime (if present) */
  76. MPI q; /* RSA secret prime (if present) */
  77. } rsa;
  78. };
  79. };
  80. extern void public_key_destroy(void *payload);
  81. /*
  82. * Public key cryptography signature data
  83. */
  84. struct public_key_signature {
  85. u8 *digest;
  86. u8 digest_size; /* Number of bytes in digest */
  87. u8 nr_mpi; /* Occupancy of mpi[] */
  88. enum pkey_algo pkey_algo : 8;
  89. enum hash_algo pkey_hash_algo : 8;
  90. union {
  91. MPI mpi[2];
  92. struct {
  93. MPI s; /* m^d mod n */
  94. } rsa;
  95. struct {
  96. MPI r;
  97. MPI s;
  98. } dsa;
  99. };
  100. };
  101. struct key;
  102. extern int verify_signature(const struct key *key,
  103. const struct public_key_signature *sig);
  104. struct asymmetric_key_id;
  105. extern struct key *x509_request_asymmetric_key(struct key *keyring,
  106. const struct asymmetric_key_id *id,
  107. const struct asymmetric_key_id *skid,
  108. bool partial);
  109. #endif /* _LINUX_PUBLIC_KEY_H */