public_key.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_TYPE__LAST
  31. };
  32. extern const char *const pkey_id_type_name[PKEY_ID_TYPE__LAST];
  33. /*
  34. * Cryptographic data for the public-key subtype of the asymmetric key type.
  35. *
  36. * Note that this may include private part of the key as well as the public
  37. * part.
  38. */
  39. struct public_key {
  40. const struct public_key_algorithm *algo;
  41. u8 capabilities;
  42. #define PKEY_CAN_ENCRYPT 0x01
  43. #define PKEY_CAN_DECRYPT 0x02
  44. #define PKEY_CAN_SIGN 0x04
  45. #define PKEY_CAN_VERIFY 0x08
  46. enum pkey_algo pkey_algo : 8;
  47. enum pkey_id_type id_type : 8;
  48. union {
  49. MPI mpi[5];
  50. struct {
  51. MPI p; /* DSA prime */
  52. MPI q; /* DSA group order */
  53. MPI g; /* DSA group generator */
  54. MPI y; /* DSA public-key value = g^x mod p */
  55. MPI x; /* DSA secret exponent (if present) */
  56. } dsa;
  57. struct {
  58. MPI n; /* RSA public modulus */
  59. MPI e; /* RSA public encryption exponent */
  60. MPI d; /* RSA secret encryption exponent (if present) */
  61. MPI p; /* RSA secret prime (if present) */
  62. MPI q; /* RSA secret prime (if present) */
  63. } rsa;
  64. };
  65. };
  66. extern void public_key_destroy(void *payload);
  67. /*
  68. * Public key cryptography signature data
  69. */
  70. struct public_key_signature {
  71. u8 *digest;
  72. u8 digest_size; /* Number of bytes in digest */
  73. u8 nr_mpi; /* Occupancy of mpi[] */
  74. enum pkey_algo pkey_algo : 8;
  75. enum hash_algo pkey_hash_algo : 8;
  76. union {
  77. MPI mpi[2];
  78. struct {
  79. MPI s; /* m^d mod n */
  80. } rsa;
  81. struct {
  82. MPI r;
  83. MPI s;
  84. } dsa;
  85. };
  86. };
  87. struct key;
  88. extern int verify_signature(const struct key *key,
  89. const struct public_key_signature *sig);
  90. struct asymmetric_key_id;
  91. extern struct key *x509_request_asymmetric_key(struct key *keyring,
  92. const struct asymmetric_key_id *kid,
  93. bool partial);
  94. #endif /* _LINUX_PUBLIC_KEY_H */