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