Software APIs
rsa_datatypes.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_RSA_RSA_DATATYPES_H_
6 #define OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_RSA_RSA_DATATYPES_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
12 #include "sw/device/lib/crypto/impl/status.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif // __cplusplus
17 
18 enum {
19  /* Length of the RSA-2048 modulus and private exponent in bits. */
20  kRsa2048NumBits = 2048,
21  /* Length of the RSA-2048 modulus in bytes */
22  kRsa2048NumBytes = kRsa2048NumBits / 8,
23  /* Length of the RSA-2048 modulus in words */
24  kRsa2048NumWords = kRsa2048NumBytes / sizeof(uint32_t),
25  /* Length of the RSA-3072 modulus and private exponent in bits. */
26  kRsa3072NumBits = 3072,
27  /* Length of the RSA-3072 modulus in bytes */
28  kRsa3072NumBytes = kRsa3072NumBits / 8,
29  /* Length of the RSA-3072 modulus in words */
30  kRsa3072NumWords = kRsa3072NumBytes / sizeof(uint32_t),
31  /* Length of the RSA-4096 modulus and private exponent in bits. */
32  kRsa4096NumBits = 4096,
33  /* Length of the RSA-4096 modulus in bytes */
34  kRsa4096NumBytes = kRsa4096NumBits / 8,
35  /* Length of the RSA-4096 modulus in words */
36  kRsa4096NumWords = kRsa4096NumBytes / sizeof(uint32_t),
37 };
38 
39 /**
40  * A type that holds a 2048-bit number.
41  *
42  * This type can be used for RSA-2048 signatures, moduli, private exponents,
43  * and intermediate values.
44  */
45 typedef struct rsa_2048_int_t {
46  uint32_t data[kRsa2048NumWords];
48 
49 /**
50  * A type that holds a 3072-bit number.
51  *
52  * This type can be used for RSA-3072 signatures, moduli, private exponents,
53  * and intermediate values.
54  */
55 typedef struct rsa_3072_int_t {
56  uint32_t data[kRsa3072NumWords];
58 
59 /**
60  * A type that holds a 4096-bit number.
61  *
62  * This type can be used for RSA-4096 signatures, moduli, private exponents,
63  * and intermediate values.
64  */
65 typedef struct rsa_4096_int_t {
66  uint32_t data[kRsa4096NumWords];
68 
69 /**
70  * A type that holds an RSA-2048 public key.
71  *
72  * The public key consists of a 2048-bit modulus n and a public exponent e.
73  */
74 typedef struct rsa_2048_public_key_t {
76  uint32_t e;
78 
79 /**
80  * A type that holds an RSA-3072 public key.
81  *
82  * The public key consists of a 3072-bit modulus n and a public exponent e.
83  */
84 typedef struct rsa_3072_public_key_t {
86  uint32_t e;
88 
89 /**
90  * A type that holds an RSA-4096 public key.
91  *
92  * The public key consists of a 4096-bit modulus n and a public exponent e.
93  */
94 typedef struct rsa_4096_public_key_t {
96  uint32_t e;
98 
99 /**
100  * A type that holds an RSA-2048 private key.
101  *
102  * The private key consists of a 2048-bit private exponent d and a public
103  * modulus n.
104  */
105 typedef struct rsa_2048_private_key_t {
106  rsa_2048_int_t d;
107  rsa_2048_int_t n;
109 
110 /**
111  * A type that holds an RSA-3072 private key.
112  *
113  * The private key consists of a 3072-bit private exponent d and a public
114  * modulus n.
115  */
116 typedef struct rsa_3072_private_key_t {
117  rsa_3072_int_t d;
118  rsa_3072_int_t n;
120 
121 /**
122  * A type that holds an RSA-4096 private key.
123  *
124  * The private key consists of a 4096-bit private exponent d and a public
125  * modulus n.
126  */
127 typedef struct rsa_4096_private_key_t {
128  rsa_4096_int_t d;
129  rsa_4096_int_t n;
131 
132 /**
133  * A type that holds a cofactor for an RSA-2048 key.
134  *
135  * This type is half the size of an RSA-2048 integer.
136  */
137 typedef struct rsa_2048_cofactor_t {
138  uint32_t data[kRsa2048NumWords / 2];
140 
141 /**
142  * A type that holds a cofactor for an RSA-3072 key.
143  *
144  * This type is half the size of an RSA-3072 integer.
145  */
146 typedef struct rsa_3072_cofactor_t {
147  uint32_t data[kRsa3072NumWords / 2];
149 
150 /**
151  * A type that holds a cofactor for an RSA-4096 key.
152  *
153  * This type is half the size of an RSA-4096 integer.
154  */
155 typedef struct rsa_4096_cofactor_t {
156  uint32_t data[kRsa4096NumWords / 2];
158 
159 #ifdef __cplusplus
160 } // extern "C"
161 #endif // __cplusplus
162 
163 #endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_RSA_RSA_DATATYPES_H_