9 #include "sw/device/lib/crypto/drivers/entropy.h"
10 #include "sw/device/lib/crypto/impl/status.h"
14 #define MODULE_ID MAKE_MODULE_ID('r', 'b', 'g')
30 if (value.len > kEntropySeedBytes) {
31 return OTCRYPTO_BAD_ARGS;
34 size_t nwords =
ceil_div(value.len,
sizeof(uint32_t));
35 seed_material->
len = nwords;
38 memset(seed_material->
data, 0, nwords *
sizeof(uint32_t));
46 memcpy(seed_material->
data, value.data, value.len);
65 if (value.len > kEntropySeedBytes) {
66 return OTCRYPTO_BAD_ARGS;
74 size_t nwords =
ceil_div(value.len,
sizeof(uint32_t));
75 uint32_t value_words[nwords];
76 value_words[nwords - 1] = 0;
77 memcpy(value_words, value.data, value.len);
80 for (
size_t i = 0; i < nwords; i++) {
81 seed_material->
data[i] ^= value_words[i];
90 if (perso_string.len != 0 && perso_string.data == NULL) {
91 return OTCRYPTO_BAD_ARGS;
95 seed_material_construct(perso_string, &seed_material);
97 HARDENED_TRY(entropy_csrng_uninstantiate());
105 if (additional_input.len != 0 && additional_input.data == NULL) {
106 return OTCRYPTO_BAD_ARGS;
110 seed_material_construct(additional_input, &seed_material);
119 if (perso_string.len != 0 && perso_string.data == NULL) {
120 return OTCRYPTO_BAD_ARGS;
122 if (entropy.data == NULL || entropy.len != kEntropySeedBytes) {
123 return OTCRYPTO_BAD_ARGS;
127 seed_material_construct(entropy, &seed_material);
128 seed_material_xor(perso_string, &seed_material);
140 if (additional_input.len != 0 && additional_input.data == NULL) {
141 return OTCRYPTO_BAD_ARGS;
143 if (entropy.data == NULL || entropy.len != kEntropySeedBytes) {
144 return OTCRYPTO_BAD_ARGS;
148 seed_material_construct(entropy, &seed_material);
149 seed_material_xor(additional_input, &seed_material);
172 if (drbg_output.len == 0) {
176 if ((additional_input.len != 0 && additional_input.data == NULL) ||
177 drbg_output.data == NULL) {
178 return OTCRYPTO_BAD_ARGS;
182 seed_material_construct(additional_input, &seed_material);
183 HARDENED_TRY(entropy_csrng_generate(&seed_material, drbg_output.data,
184 drbg_output.len, fips_check));
204 return entropy_csrng_uninstantiate();