public_key.h 2.5 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. enum pkey_algo {
  17. PKEY_ALGO_DSA,
  18. PKEY_ALGO_RSA,
  19. PKEY_ALGO__LAST
  20. };
  21. extern const char *const pkey_algo[PKEY_ALGO__LAST];
  22. enum pkey_hash_algo {
  23. PKEY_HASH_MD4,
  24. PKEY_HASH_MD5,
  25. PKEY_HASH_SHA1,
  26. PKEY_HASH_RIPE_MD_160,
  27. PKEY_HASH_SHA256,
  28. PKEY_HASH_SHA384,
  29. PKEY_HASH_SHA512,
  30. PKEY_HASH_SHA224,
  31. PKEY_HASH__LAST
  32. };
  33. extern const char *const pkey_hash_algo[PKEY_HASH__LAST];
  34. enum pkey_id_type {
  35. PKEY_ID_PGP, /* OpenPGP generated key ID */
  36. PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */
  37. PKEY_ID_TYPE__LAST
  38. };
  39. extern const char *const pkey_id_type[PKEY_ID_TYPE__LAST];
  40. /*
  41. * Cryptographic data for the public-key subtype of the asymmetric key type.
  42. *
  43. * Note that this may include private part of the key as well as the public
  44. * part.
  45. */
  46. struct public_key {
  47. const struct public_key_algorithm *algo;
  48. u8 capabilities;
  49. #define PKEY_CAN_ENCRYPT 0x01
  50. #define PKEY_CAN_DECRYPT 0x02
  51. #define PKEY_CAN_SIGN 0x04
  52. #define PKEY_CAN_VERIFY 0x08
  53. enum pkey_id_type id_type : 8;
  54. union {
  55. MPI mpi[5];
  56. struct {
  57. MPI p; /* DSA prime */
  58. MPI q; /* DSA group order */
  59. MPI g; /* DSA group generator */
  60. MPI y; /* DSA public-key value = g^x mod p */
  61. MPI x; /* DSA secret exponent (if present) */
  62. } dsa;
  63. struct {
  64. MPI n; /* RSA public modulus */
  65. MPI e; /* RSA public encryption exponent */
  66. MPI d; /* RSA secret encryption exponent (if present) */
  67. MPI p; /* RSA secret prime (if present) */
  68. MPI q; /* RSA secret prime (if present) */
  69. } rsa;
  70. };
  71. };
  72. extern void public_key_destroy(void *payload);
  73. /*
  74. * Public key cryptography signature data
  75. */
  76. struct public_key_signature {
  77. u8 *digest;
  78. u8 digest_size; /* Number of bytes in digest */
  79. u8 nr_mpi; /* Occupancy of mpi[] */
  80. enum pkey_hash_algo pkey_hash_algo : 8;
  81. union {
  82. MPI mpi[2];
  83. struct {
  84. MPI s; /* m^d mod n */
  85. } rsa;
  86. struct {
  87. MPI r;
  88. MPI s;
  89. } dsa;
  90. };
  91. };
  92. struct key;
  93. extern int verify_signature(const struct key *key,
  94. const struct public_key_signature *sig);
  95. #endif /* _LINUX_PUBLIC_KEY_H */