Software APIs
ecc256_keygen_serial.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_SCA_OTBN_VERTICAL_ECC256_KEYGEN_SERIAL_H_
6 #define OPENTITAN_SW_DEVICE_SCA_OTBN_VERTICAL_ECC256_KEYGEN_SERIAL_H_
7 
8 #include "sw/device/lib/crypto/drivers/otbn.h"
9 
10 /**
11  * App configuration for p256_key_from_seed_sca
12  */
13 OTBN_DECLARE_APP_SYMBOLS(p256_key_from_seed_sca);
14 
15 OTBN_DECLARE_SYMBOL_ADDR(p256_key_from_seed_sca, mode);
16 OTBN_DECLARE_SYMBOL_ADDR(p256_key_from_seed_sca, seed0);
17 OTBN_DECLARE_SYMBOL_ADDR(p256_key_from_seed_sca, seed1);
18 OTBN_DECLARE_SYMBOL_ADDR(p256_key_from_seed_sca, d0);
19 OTBN_DECLARE_SYMBOL_ADDR(p256_key_from_seed_sca, d1);
20 OTBN_DECLARE_SYMBOL_ADDR(p256_key_from_seed_sca, x);
21 OTBN_DECLARE_SYMBOL_ADDR(p256_key_from_seed_sca, y);
22 
23 extern const otbn_app_t kOtbnAppP256KeyFromSeed;
24 
25 static const otbn_addr_t kOtbnVarMode;
26 static const otbn_addr_t kOtbnVarSeed0;
27 static const otbn_addr_t kOtbnVarSeed1;
28 static const otbn_addr_t kOtbnVarD0;
29 static const otbn_addr_t kOtbnVarD1;
30 static const otbn_addr_t kOtbnVarX;
31 static const otbn_addr_t kOtbnVarY;
32 
33 /**
34  * Simple serial 'm' (set masks enable) command handler.
35  *
36  * This can be used for batch mode.
37  *
38  * @param enable 1 => masks enabled, 0 => masks disabled.
39  * @param enable_len Length of sent enable value.
40  */
41 void ecc256_en_masks(const uint8_t *enable, size_t enable_len);
42 
43 /**
44  * Simple serial 'x' (set seed) command handler.
45  *
46  * The seed must be `kEcc256SeedNumBytes` bytes long.
47  *
48  * @param seed Value for seed share.
49  * @param seed_len Length of seed share.
50  */
51 void ecc256_set_seed(const uint8_t *seed, size_t seed_len);
52 
53 /**
54  * Simple serial 'c' (set constant) command handler.
55  *
56  * The constant must be `kEcc256SeedNumBytes` bytes long.
57  *
58  * @param C Value of the C constant.
59  * @param len Length of the C constant.
60  */
61 void ecc256_set_c(const uint8_t *C, size_t len);
62 
63 /**
64  * Simple serial 'e' (secret keygen fvsr key batch mode) command handler.
65  *
66  * Collects data for ECDSA keygen fixed-vs-random test in the KEY mode.
67  * In the KEY mode, the fixed set of measurements is generated using the fixed
68  * 320 bit seed. The random set of measurements is generated in two steps:
69  * 1. Choose a random 256 bit number r
70  * 2. Compute the seed as (C + r) where C is the fixed 320 bit constant. Note
71  * that in this case the used key is equal to (C + r) mod curve_order_n.
72  * Takes a number of traces that has to be captured in one batch as input.
73  *
74  * @param data Value for trace count.
75  * @param data_len Length of trace count input.
76  */
77 void ecc256_ecdsa_keygen_fvsr_key_batch(const uint8_t *data, size_t data_len);
78 
79 /**
80  * Simple serial 'b' (secret keygen batch mode) command handler.
81  *
82  * Collects data for ECDSA keygen fixed-vs-random test in the SEED mode.
83  * In the SEED mode, the fixed set of measurements is generated using the fixed
84  * 320 bit seed. The random set of measurements is generated using a random 320
85  * bit seed. In both cases, the used key is equal to seed mod curve_order_n
86  *
87  * Takes a number of traces that has to be captured in one batch as input.
88  *
89  * @param data Value for trace count.
90  * @param data_len Length of trace count input.
91  */
92 void ecc256_ecdsa_keygen_fvsr_seed_batch(const uint8_t *data, size_t data_len);
93 
94 /**
95  * Simple serial 'k' (secret keygen) command handler.
96  *
97  * Takes the mask value from the simple serial UART and triggers an OTBN
98  * secret key generation operation. The mask must be `kEcc256SeedNumBytes`
99  * bytes long.
100  *
101  * Uses a fixed seed. To overwrite the seed, use the simpleserial command 's'.
102  *
103  * @param[in] mask The mask provided by the simpleserial UART.
104  * @param[in] mask_len Length of the mask.
105  */
106 void ecc256_ecdsa_secret_keygen(const uint8_t *mask, size_t mask_len);
107 
108 /**
109  * Simple serial 'p' (keypair generation) command handler.
110  *
111  * Takes the mask value from the simple serial UART and triggers an OTBN
112  * secret key generation operation. The mask must be `kEcc256SeedNumBytes`
113  * bytes long.
114  *
115  * Uses a fixed seed. To overwrite the seed, use the simpleserial command 's'.
116  *
117  * @param[in] mask The mask provided by the simpleserial UART.
118  * @param[in] mask_len Length of the mask.
119  */
120 void ecc256_ecdsa_gen_keypair(const uint8_t *mask, size_t mask_len);
121 
122 #endif // OPENTITAN_SW_DEVICE_SCA_OTBN_VERTICAL_ECC256_KEYGEN_SERIAL_H_