iPXE
rsa.h
Go to the documentation of this file.
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_OR_UBDL );
10 
11 #include <stdarg.h>
12 #include <ipxe/crypto.h>
13 #include <ipxe/bigint.h>
14 #include <ipxe/asn1.h>
15 #include <ipxe/tables.h>
16 
17 /** RSA digestAlgorithm sequence contents */
18 #define RSA_DIGESTALGORITHM_CONTENTS( ... ) \
19  ASN1_OID, VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__, \
20  ASN1_NULL, 0x00
21 
22 /** RSA digestAlgorithm sequence */
23 #define RSA_DIGESTALGORITHM( ... ) \
24  ASN1_SEQUENCE, \
25  VA_ARG_COUNT ( RSA_DIGESTALGORITHM_CONTENTS ( __VA_ARGS__ ) ), \
26  RSA_DIGESTALGORITHM_CONTENTS ( __VA_ARGS__ )
27 
28 /** RSA digest prefix */
29 #define RSA_DIGEST_PREFIX( digest_size ) \
30  ASN1_OCTET_STRING, digest_size
31 
32 /** RSA digestInfo prefix */
33 #define RSA_DIGESTINFO_PREFIX( digest_size, ... ) \
34  ASN1_SEQUENCE, \
35  ( VA_ARG_COUNT ( RSA_DIGESTALGORITHM ( __VA_ARGS__ ) ) + \
36  VA_ARG_COUNT ( RSA_DIGEST_PREFIX ( digest_size ) ) + \
37  digest_size ), \
38  RSA_DIGESTALGORITHM ( __VA_ARGS__ ), \
39  RSA_DIGEST_PREFIX ( digest_size )
40 
41 /** An RSA digestInfo prefix */
43  /** Digest algorithm */
45  /** Prefix */
46  const void *data;
47  /** Length of prefix */
48  size_t len;
49 };
50 
51 /** RSA digestInfo prefix table */
52 #define RSA_DIGESTINFO_PREFIXES \
53  __table ( struct rsa_digestinfo_prefix, "rsa_digestinfo_prefixes" )
54 
55 /** Declare an RSA digestInfo prefix */
56 #define __rsa_digestinfo_prefix __table_entry ( RSA_DIGESTINFO_PREFIXES, 01 )
57 
58 /** An RSA context */
59 struct rsa_context {
60  /** Allocated memory */
61  void *dynamic;
62  /** Modulus */
64  /** Modulus size */
65  unsigned int size;
66  /** Modulus length */
67  size_t max_len;
68  /** Exponent */
70  /** Exponent size */
71  unsigned int exponent_size;
72  /** Input buffer */
74  /** Output buffer */
76  /** Temporary working space for modular exponentiation */
77  void *tmp;
78 };
79 
80 /** RSA context size */
81 #define RSA_CTX_SIZE sizeof ( struct rsa_context )
82 
83 extern struct pubkey_algorithm rsa_algorithm;
84 
85 #endif /* _IPXE_RSA_H */
void * tmp
Temporary working space for modular exponentiation.
Definition: rsa.h:77
bigint_element_t * output0
Output buffer.
Definition: rsa.h:75
unsigned int exponent_size
Exponent size.
Definition: rsa.h:71
Cryptographic API.
Big integer support.
bigint_element_t * modulus0
Modulus.
Definition: rsa.h:63
struct pubkey_algorithm rsa_algorithm
RSA public-key algorithm.
Definition: rsa.c:632
An RSA context.
Definition: rsa.h:59
ASN.1 encoding.
unsigned int size
Modulus size.
Definition: rsa.h:65
size_t max_len
Modulus length.
Definition: rsa.h:67
void * dynamic
Allocated memory.
Definition: rsa.h:61
uint32_t bigint_element_t
Element of a big integer.
Definition: bigint.h:15
bigint_element_t * input0
Input buffer.
Definition: rsa.h:73
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
const void * data
Prefix.
Definition: rsa.h:46
An RSA digestInfo prefix.
Definition: rsa.h:42
bigint_element_t * exponent0
Exponent.
Definition: rsa.h:69
size_t len
Length of prefix.
Definition: rsa.h:48
A message digest algorithm.
Definition: crypto.h:17
Linker tables.
struct digest_algorithm * digest
Digest algorithm.
Definition: rsa.h:44
A public key algorithm.
Definition: crypto.h:120