iPXE
rsa.h
Go to the documentation of this file.
00001 #ifndef _IPXE_RSA_H
00002 #define _IPXE_RSA_H
00003 
00004 /** @file
00005  *
00006  * RSA public-key cryptography
00007  */
00008 
00009 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00010 
00011 #include <stdarg.h>
00012 #include <ipxe/crypto.h>
00013 #include <ipxe/bigint.h>
00014 #include <ipxe/asn1.h>
00015 #include <ipxe/tables.h>
00016 
00017 /** RSA digestAlgorithm sequence contents */
00018 #define RSA_DIGESTALGORITHM_CONTENTS( ... )                             \
00019         ASN1_OID, VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__,            \
00020         ASN1_NULL, 0x00
00021 
00022 /** RSA digestAlgorithm sequence */
00023 #define RSA_DIGESTALGORITHM( ... )                                      \
00024         ASN1_SEQUENCE,                                                  \
00025         VA_ARG_COUNT ( RSA_DIGESTALGORITHM_CONTENTS ( __VA_ARGS__ ) ),  \
00026         RSA_DIGESTALGORITHM_CONTENTS ( __VA_ARGS__ )
00027 
00028 /** RSA digest prefix */
00029 #define RSA_DIGEST_PREFIX( digest_size )                                \
00030         ASN1_OCTET_STRING, digest_size
00031 
00032 /** RSA digestInfo prefix */
00033 #define RSA_DIGESTINFO_PREFIX( digest_size, ... )                       \
00034         ASN1_SEQUENCE,                                                  \
00035         ( VA_ARG_COUNT ( RSA_DIGESTALGORITHM ( __VA_ARGS__ ) ) +        \
00036           VA_ARG_COUNT ( RSA_DIGEST_PREFIX ( digest_size ) ) +          \
00037           digest_size ),                                                \
00038         RSA_DIGESTALGORITHM ( __VA_ARGS__ ),                            \
00039         RSA_DIGEST_PREFIX ( digest_size )
00040 
00041 /** An RSA digestInfo prefix */
00042 struct rsa_digestinfo_prefix {
00043         /** Digest algorithm */
00044         struct digest_algorithm *digest;
00045         /** Prefix */
00046         const void *data;
00047         /** Length of prefix */
00048         size_t len;
00049 };
00050 
00051 /** RSA digestInfo prefix table */
00052 #define RSA_DIGESTINFO_PREFIXES \
00053         __table ( struct rsa_digestinfo_prefix, "rsa_digestinfo_prefixes" )
00054 
00055 /** Declare an RSA digestInfo prefix */
00056 #define __rsa_digestinfo_prefix __table_entry ( RSA_DIGESTINFO_PREFIXES, 01 )
00057 
00058 /** An RSA context */
00059 struct rsa_context {
00060         /** Allocated memory */
00061         void *dynamic;
00062         /** Modulus */
00063         bigint_element_t *modulus0;
00064         /** Modulus size */
00065         unsigned int size;
00066         /** Modulus length */
00067         size_t max_len;
00068         /** Exponent */
00069         bigint_element_t *exponent0;
00070         /** Exponent size */
00071         unsigned int exponent_size;
00072         /** Input buffer */
00073         bigint_element_t *input0;
00074         /** Output buffer */
00075         bigint_element_t *output0;
00076         /** Temporary working space for modular exponentiation */
00077         void *tmp;
00078 };
00079 
00080 /** RSA context size */
00081 #define RSA_CTX_SIZE sizeof ( struct rsa_context )
00082 
00083 extern struct pubkey_algorithm rsa_algorithm;
00084 
00085 #endif /* _IPXE_RSA_H */