Skip to content

Commit c2f70ba

Browse files
Vge0rgerlubos
authored andcommitted
nrf_security: Minor refactor in CTR_DRBG
Refactor the temp_size to be a define and not a variable. This solves build issues when build with no optimizations because this value is evaluated by static assert and if it is not optimized it results to a compilcation error. Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent 1366248 commit c2f70ba

File tree

1 file changed

+6
-5
lines changed
  • subsys/nrf_security/src/drivers/cracen/cracenpsa/src

1 file changed

+6
-5
lines changed

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/ctr_drbg.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
type var[size] __attribute__((aligned(alignment)));
4848
#endif
4949

50+
#define CRACEN_ENTROPY_AND_NONCE_SIZE (CRACEN_PRNG_ENTROPY_SIZE + CRACEN_PRNG_NONCE_SIZE)
51+
5052
/*
5153
* This driver uses a global context and discards the context passed from the user. We do that
5254
* because we are not aware of a requirement for multiple PRNG contexts from the users of the
@@ -122,19 +124,18 @@ static psa_status_t ctr_drbg_update(uint8_t *data)
122124
{
123125
psa_status_t status = SX_OK;
124126

125-
const size_t temp_sizeof = CRACEN_PRNG_ENTROPY_SIZE + CRACEN_PRNG_NONCE_SIZE;
126-
ALIGN_ON_STACK(char, temp, temp_sizeof, CONFIG_DCACHE_LINE_SIZE);
127+
ALIGN_ON_STACK(char, temp, CRACEN_ENTROPY_AND_NONCE_SIZE, CONFIG_DCACHE_LINE_SIZE);
127128

128129
size_t temp_length = 0;
129-
_Static_assert(temp_sizeof % SX_BLKCIPHER_AES_BLK_SZ == 0, "");
130+
_Static_assert(CRACEN_ENTROPY_AND_NONCE_SIZE % SX_BLKCIPHER_AES_BLK_SZ == 0, "");
130131

131132
psa_key_attributes_t attr = PSA_KEY_ATTRIBUTES_INIT;
132133

133134
psa_set_key_type(&attr, PSA_KEY_TYPE_AES);
134135
psa_set_key_bits(&attr, PSA_BYTES_TO_BITS(sizeof(prng.key)));
135136
psa_set_key_usage_flags(&attr, PSA_KEY_USAGE_ENCRYPT);
136137

137-
while (temp_length < temp_sizeof) {
138+
while (temp_length < CRACEN_ENTROPY_AND_NONCE_SIZE) {
138139
cracen_be_add(prng.V, SX_BLKCIPHER_AES_BLK_SZ, 1);
139140

140141
status = sx_blkcipher_ecb_simple(prng.key, sizeof(prng.key), prng.V, sizeof(prng.V),
@@ -148,7 +149,7 @@ static psa_status_t ctr_drbg_update(uint8_t *data)
148149
}
149150

150151
if (data) {
151-
cracen_xorbytes(temp, data, temp_sizeof);
152+
cracen_xorbytes(temp, data, CRACEN_ENTROPY_AND_NONCE_SIZE);
152153
}
153154

154155
memcpy(prng.key, temp, sizeof(prng.key));

0 commit comments

Comments
 (0)