8 #include "sw/device/lib/crypto/impl/integrity.h"
9 #include "sw/device/lib/crypto/impl/keyblob.h"
10 #include "sw/device/lib/crypto/impl/status.h"
15 #define MODULE_ID MAKE_MODULE_ID('k', 't', 'r')
19 if (key == NULL || key->keyblob == NULL) {
20 return OTCRYPTO_BAD_ARGS;
25 HARDENED_TRY(keyblob_ensure_xor_masked(key->config));
31 HARDENED_TRY(keyblob_to_shares(key, &share0, &share1));
36 .len = keyblob_share_num_words(key->config),
40 .len = keyblob_share_num_words(key->config),
53 key->checksum = integrity_blinded_checksum(key);
58 const uint32_t salt[7],
60 if (key == NULL || key->keyblob == NULL) {
61 return OTCRYPTO_BAD_ARGS;
63 if (key->keyblob_length != 8 *
sizeof(uint32_t) ||
65 return OTCRYPTO_BAD_ARGS;
72 if (key_type == kOtcryptoKeyTypeRsa) {
73 return OTCRYPTO_BAD_ARGS;
77 key->keyblob[0] = version;
78 memcpy(&key->keyblob[1], salt, 7 *
sizeof(uint32_t));
81 key->checksum = integrity_blinded_checksum(key);
90 if (blinded_key == NULL || blinded_key->keyblob == NULL ||
91 key_share0.data == NULL || key_share1.data == NULL) {
92 return OTCRYPTO_BAD_ARGS;
96 HARDENED_TRY(keyblob_ensure_xor_masked(blinded_key->config));
99 size_t share_words = launder32(keyblob_share_num_words(blinded_key->config));
100 if (launder32(key_share0.len) != share_words ||
101 launder32(key_share1.len) != share_words) {
102 return OTCRYPTO_BAD_ARGS;
105 keyblob_share_num_words(blinded_key->config));
107 keyblob_share_num_words(blinded_key->config));
110 size_t keyblob_words = launder32(keyblob_num_words(blinded_key->config));
111 if ((blinded_key->keyblob_length %
sizeof(uint32_t) != 0) ||
112 (blinded_key->keyblob_length /
sizeof(uint32_t) != keyblob_words)) {
113 return OTCRYPTO_BAD_ARGS;
116 keyblob_words *
sizeof(uint32_t));
119 keyblob_from_shares(key_share0.data, key_share1.data, blinded_key->config,
120 blinded_key->keyblob);
121 blinded_key->checksum = integrity_blinded_checksum(blinded_key);
128 if (blinded_key.keyblob == NULL || key_share0.data == NULL ||
129 key_share1.data == NULL) {
130 return OTCRYPTO_BAD_ARGS;
134 if (launder32(integrity_blinded_key_check(&blinded_key)) !=
136 return OTCRYPTO_BAD_ARGS;
142 HARDENED_TRY(keyblob_ensure_xor_masked(blinded_key.config));
146 return OTCRYPTO_BAD_ARGS;
151 size_t share_words = launder32(keyblob_share_num_words(blinded_key.config));
152 if (launder32(key_share0.len) != share_words ||
153 launder32(key_share1.len) != share_words) {
154 return OTCRYPTO_BAD_ARGS;
157 keyblob_share_num_words(blinded_key.config));
159 keyblob_share_num_words(blinded_key.config));
162 size_t keyblob_words = launder32(keyblob_num_words(blinded_key.config));
163 if ((blinded_key.keyblob_length %
sizeof(uint32_t) != 0) ||
164 (blinded_key.keyblob_length /
sizeof(uint32_t) != keyblob_words)) {
165 return OTCRYPTO_BAD_ARGS;
168 keyblob_words *
sizeof(uint32_t));
171 uint32_t *keyblob_share0;
172 uint32_t *keyblob_share1;
174 keyblob_to_shares(&blinded_key, &keyblob_share0, &keyblob_share1));