Software APIs
otbn_sca_commands.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_TESTS_PENETRATIONTESTS_JSON_OTBN_SCA_COMMANDS_H_
6 #define OPENTITAN_SW_DEVICE_TESTS_PENETRATIONTESTS_JSON_OTBN_SCA_COMMANDS_H_
7 #include "sw/device/lib/ujson/ujson_derive.h"
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #define OTBNSCA_CMD_MAX_BATCH_DIGEST_BYTES 40
13 #define OTBNSCA_CMD_MAX_SEED_BYTES 40
14 
15 // clang-format off
16 
17 // OTBN SCA arguments
18 
19 #define OTBNSCA_SUBCOMMAND(_, value) \
20  value(_, Ecc256EcdsaKeygenFvsrKeyBatch) \
21  value(_, Ecc256EcdsaKeygenFvsrSeedBatch) \
22  value(_, Ecc256EnMasks) \
23  value(_, Ecc256SetC) \
24  value(_, Ecc256SetSeed) \
25  value(_, EcdsaP256Sign) \
26  value(_, EcdsaP256SignBatch) \
27  value(_, EcdsaP256SignFvsrBatch) \
28  value(_, Init) \
29  value(_, InitKeyMgr) \
30  value(_, InsnCarryFlag) \
31  value(_, KeySideloadFvsr) \
32  value(_, Rsa512Decrypt)
33 UJSON_SERDE_ENUM(OtbnScaSubcommand, otbn_sca_subcommand_t, OTBNSCA_SUBCOMMAND);
34 
35 #define OTBN_SCA_EN_MASKS(field, string) \
36  field(en_masks, bool)
37 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaEnMasks, penetrationtest_otbn_sca_en_masks_t, OTBN_SCA_EN_MASKS);
38 
39 #define OTBN_SCA_NUM_TRACES(field, string) \
40  field(num_traces, uint32_t)
41 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaNumTraces, penetrationtest_otbn_sca_num_traces_t, OTBN_SCA_NUM_TRACES);
42 
43 #define OTBN_SCA_BATCH_DIGEST(field, string) \
44  field(batch_digest, uint8_t, OTBNSCA_CMD_MAX_BATCH_DIGEST_BYTES)
45 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaBatchDigest, penetrationtest_otbn_sca_batch_digest_t, OTBN_SCA_BATCH_DIGEST);
46 
47 #define OTBN_SCA_SEED(field, string) \
48  field(seed, uint8_t, OTBNSCA_CMD_MAX_SEED_BYTES)
49 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaSeed, penetrationtest_otbn_sca_seed_t, OTBN_SCA_SEED);
50 
51 #define OTBN_SCA_CONSTANT(field, string) \
52  field(constant, uint8_t, OTBNSCA_CMD_MAX_SEED_BYTES)
53 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaConstant, penetrationtest_otbn_sca_constant_t, OTBN_SCA_CONSTANT);
54 
55 #define OTBN_SCA_KEY(field, string) \
56  field(shares, uint32_t, 4) \
57  field(keys, uint32_t, 2)
58 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaKey, penetrationtest_otbn_sca_key_t, OTBN_SCA_KEY);
59 
60 #define OTBN_SCA_FIXED_SEED(field, string) \
61  field(fixed_seed, uint32_t)
62 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaFixedKey, penetrationtest_otbn_sca_fixed_seed_t, OTBN_SCA_FIXED_SEED);
63 
64 #define OTBN_SCA_RSA512_DEC(field, string) \
65  field(mod, uint8_t, 64) \
66  field(exp, uint8_t, 64) \
67  field(msg, uint8_t, 64)
68 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaRsa512Dec, penetrationtest_otbn_sca_rsa512_dec_t, OTBN_SCA_RSA512_DEC);
69 
70 #define OTBN_SCA_RSA512_DEC_OUT(field, string) \
71  field(out, uint8_t, 64)
72 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaRsa512DecOut, penetrationtest_otbn_sca_rsa512_dec_out_t, OTBN_SCA_RSA512_DEC_OUT);
73 
74 #define OTBN_SCA_BIG_NUM(field, string) \
75  field(big_num, uint32_t, 8)
76 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaBigNum, penetrationtest_otbn_sca_big_num_t, OTBN_SCA_BIG_NUM);
77 
78 #define OTBN_SCA_ECDSA_P256_SIGN(field, string) \
79  field(msg, uint32_t, 8) \
80  field(d0, uint32_t, 10) \
81  field(k0, uint32_t, 10)
82 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaEcdsaP256Sign, penetrationtest_otbn_sca_ecdsa_p256_sign_t, OTBN_SCA_ECDSA_P256_SIGN);
83 
84 #define OTBN_SCA_ECDSA_P256_SIGNATURE(field, string) \
85  field(r, uint8_t, 32) \
86  field(s, uint8_t, 32)
87 UJSON_SERDE_STRUCT(PenetrationtestOtbnScaEcdsaP256Signature, penetrationtest_otbn_sca_ecdsa_p256_signature_t, OTBN_SCA_ECDSA_P256_SIGNATURE);
88 
89 // clang-format on
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 #endif // OPENTITAN_SW_DEVICE_TESTS_PENETRATIONTESTS_JSON_OTBN_SCA_COMMANDS_H_