You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rsa.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef _IPXE_RSA_H
  2. #define _IPXE_RSA_H
  3. /** @file
  4. *
  5. * RSA public-key cryptography
  6. */
  7. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  8. #include <stdarg.h>
  9. #include <ipxe/crypto.h>
  10. #include <ipxe/bigint.h>
  11. #include <ipxe/asn1.h>
  12. #include <ipxe/tables.h>
  13. /** RSA digestAlgorithm sequence contents */
  14. #define RSA_DIGESTALGORITHM_CONTENTS( ... ) \
  15. ASN1_OID, VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__, \
  16. ASN1_NULL, 0x00
  17. /** RSA digestAlgorithm sequence */
  18. #define RSA_DIGESTALGORITHM( ... ) \
  19. ASN1_SEQUENCE, \
  20. VA_ARG_COUNT ( RSA_DIGESTALGORITHM_CONTENTS ( __VA_ARGS__ ) ), \
  21. RSA_DIGESTALGORITHM_CONTENTS ( __VA_ARGS__ )
  22. /** RSA digest prefix */
  23. #define RSA_DIGEST_PREFIX( digest_size ) \
  24. ASN1_OCTET_STRING, digest_size
  25. /** RSA digestInfo prefix */
  26. #define RSA_DIGESTINFO_PREFIX( digest_size, ... ) \
  27. ASN1_SEQUENCE, \
  28. ( VA_ARG_COUNT ( RSA_DIGESTALGORITHM ( __VA_ARGS__ ) ) + \
  29. VA_ARG_COUNT ( RSA_DIGEST_PREFIX ( digest_size ) ) + \
  30. digest_size ), \
  31. RSA_DIGESTALGORITHM ( __VA_ARGS__ ), \
  32. RSA_DIGEST_PREFIX ( digest_size )
  33. /** An RSA digestInfo prefix */
  34. struct rsa_digestinfo_prefix {
  35. /** Digest algorithm */
  36. struct digest_algorithm *digest;
  37. /** Prefix */
  38. const void *data;
  39. /** Length of prefix */
  40. size_t len;
  41. };
  42. /** RSA digestInfo prefix table */
  43. #define RSA_DIGESTINFO_PREFIXES \
  44. __table ( struct rsa_digestinfo_prefix, "rsa_digestinfo_prefixes" )
  45. /** Declare an RSA digestInfo prefix */
  46. #define __rsa_digestinfo_prefix __table_entry ( RSA_DIGESTINFO_PREFIXES, 01 )
  47. /** An RSA context */
  48. struct rsa_context {
  49. /** Allocated memory */
  50. void *dynamic;
  51. /** Modulus */
  52. bigint_element_t *modulus0;
  53. /** Modulus size */
  54. unsigned int size;
  55. /** Modulus length */
  56. size_t max_len;
  57. /** Exponent */
  58. bigint_element_t *exponent0;
  59. /** Exponent size */
  60. unsigned int exponent_size;
  61. /** Input buffer */
  62. bigint_element_t *input0;
  63. /** Output buffer */
  64. bigint_element_t *output0;
  65. /** Temporary working space for modular exponentiation */
  66. void *tmp;
  67. };
  68. extern struct pubkey_algorithm rsa_algorithm;
  69. #endif /* _IPXE_RSA_H */