Skip to content

Commit 06d0b6a

Browse files
Flavio Ceolinnashif
authored andcommitted
ext: tinycrypt: Update tinycrypt revision
Bump tincyrypt library revision. Signed-off-by: Flavio Ceolin <[email protected]>
1 parent b8ad89e commit 06d0b6a

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

ext/lib/crypto/tinycrypt/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open source project. The original upstream code can be found at:
33

44
https://github.com/01org/tinycrypt
55

6-
At revision 3ea1a609e7aff9f2d8d13803e1076b7a8e551804, version 0.2.8
6+
At revision 6e0eb53fc8403988f97345e94081b0453f47231d, version 0.2.8
77

88
Any changes to the local version should include Zephyr's TinyCrypt
99
maintainer in the review. That can be found via the git history.

ext/lib/crypto/tinycrypt/source/hmac.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,19 @@ static void rekey(uint8_t *key, const uint8_t *new_key, unsigned int key_size)
5252
int tc_hmac_set_key(TCHmacState_t ctx, const uint8_t *key,
5353
unsigned int key_size)
5454
{
55-
56-
/* input sanity check: */
55+
/* Input sanity check */
5756
if (ctx == (TCHmacState_t) 0 ||
5857
key == (const uint8_t *) 0 ||
5958
key_size == 0) {
6059
return TC_CRYPTO_FAIL;
6160
}
6261

63-
const uint8_t dummy_key[key_size];
62+
const uint8_t dummy_key[TC_SHA256_BLOCK_SIZE];
6463
struct tc_hmac_state_struct dummy_state;
6564

6665
if (key_size <= TC_SHA256_BLOCK_SIZE) {
6766
/*
68-
* The next three lines consist of dummy calls just to avoid
67+
* The next three calls are dummy calls just to avoid
6968
* certain timing attacks. Without these dummy calls,
7069
* adversaries would be able to learn whether the key_size is
7170
* greater than TC_SHA256_BLOCK_SIZE by measuring the time

ext/lib/crypto/tinycrypt/source/hmac_prng.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,28 @@ static const unsigned int MAX_GENS = UINT32_MAX;
7373
static const unsigned int MAX_OUT = (1 << 19);
7474

7575
/*
76-
* Assumes: prng != NULL, e != NULL, len >= 0.
76+
* Assumes: prng != NULL
7777
*/
78-
static void update(TCHmacPrng_t prng, const uint8_t *e, unsigned int len)
78+
static void update(TCHmacPrng_t prng, const uint8_t *data, unsigned int datalen, const uint8_t *additional_data, unsigned int additional_datalen)
7979
{
8080
const uint8_t separator0 = 0x00;
8181
const uint8_t separator1 = 0x01;
8282

83+
/* configure the new prng key into the prng's instance of hmac */
84+
tc_hmac_set_key(&prng->h, prng->key, sizeof(prng->key));
85+
8386
/* use current state, e and separator 0 to compute a new prng key: */
8487
(void)tc_hmac_init(&prng->h);
8588
(void)tc_hmac_update(&prng->h, prng->v, sizeof(prng->v));
8689
(void)tc_hmac_update(&prng->h, &separator0, sizeof(separator0));
87-
(void)tc_hmac_update(&prng->h, e, len);
90+
91+
if (data && datalen)
92+
(void)tc_hmac_update(&prng->h, data, datalen);
93+
if (additional_data && additional_datalen)
94+
(void)tc_hmac_update(&prng->h, additional_data, additional_datalen);
95+
8896
(void)tc_hmac_final(prng->key, sizeof(prng->key), &prng->h);
97+
8998
/* configure the new prng key into the prng's instance of hmac */
9099
(void)tc_hmac_set_key(&prng->h, prng->key, sizeof(prng->key));
91100

@@ -94,12 +103,21 @@ static void update(TCHmacPrng_t prng, const uint8_t *e, unsigned int len)
94103
(void)tc_hmac_update(&prng->h, prng->v, sizeof(prng->v));
95104
(void)tc_hmac_final(prng->v, sizeof(prng->v), &prng->h);
96105

106+
if (data == 0 || datalen == 0)
107+
return;
108+
109+
/* configure the new prng key into the prng's instance of hmac */
110+
tc_hmac_set_key(&prng->h, prng->key, sizeof(prng->key));
111+
97112
/* use current state, e and separator 1 to compute a new prng key: */
98113
(void)tc_hmac_init(&prng->h);
99114
(void)tc_hmac_update(&prng->h, prng->v, sizeof(prng->v));
100115
(void)tc_hmac_update(&prng->h, &separator1, sizeof(separator1));
101-
(void)tc_hmac_update(&prng->h, e, len);
116+
(void)tc_hmac_update(&prng->h, data, datalen);
117+
if (additional_data && additional_datalen)
118+
(void)tc_hmac_update(&prng->h, additional_data, additional_datalen);
102119
(void)tc_hmac_final(prng->key, sizeof(prng->key), &prng->h);
120+
103121
/* configure the new prng key into the prng's instance of hmac */
104122
(void)tc_hmac_set_key(&prng->h, prng->key, sizeof(prng->key));
105123

@@ -124,10 +142,8 @@ int tc_hmac_prng_init(TCHmacPrng_t prng,
124142
/* put the generator into a known state: */
125143
_set(prng->key, 0x00, sizeof(prng->key));
126144
_set(prng->v, 0x01, sizeof(prng->v));
127-
tc_hmac_set_key(&prng->h, prng->key, sizeof(prng->key));
128-
/* update assumes SOME key has been configured into HMAC */
129145

130-
update(prng, personalization, plen);
146+
update(prng, personalization, plen, 0, 0);
131147

132148
/* force a reseed before allowing tc_hmac_prng_generate to succeed: */
133149
prng->countdown = 0;
@@ -159,13 +175,12 @@ int tc_hmac_prng_reseed(TCHmacPrng_t prng,
159175
additionallen > MAX_ALEN) {
160176
return TC_CRYPTO_FAIL;
161177
} else {
162-
/* call update for the seed and additional_input */
163-
update(prng, seed, seedlen);
164-
update(prng, additional_input, additionallen);
178+
/* call update for the seed and additional_input */
179+
update(prng, seed, seedlen, additional_input, additionallen);
165180
}
166181
} else {
167182
/* call update only for the seed */
168-
update(prng, seed, seedlen);
183+
update(prng, seed, seedlen, 0, 0);
169184
}
170185

171186
/* ... and enable hmac_prng_generate */
@@ -191,6 +206,9 @@ int tc_hmac_prng_generate(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng)
191206
prng->countdown--;
192207

193208
while (outlen != 0) {
209+
/* configure the new prng key into the prng's instance of hmac */
210+
tc_hmac_set_key(&prng->h, prng->key, sizeof(prng->key));
211+
194212
/* operate HMAC in OFB mode to create "random" outputs */
195213
(void)tc_hmac_init(&prng->h);
196214
(void)tc_hmac_update(&prng->h, prng->v, sizeof(prng->v));
@@ -206,7 +224,7 @@ int tc_hmac_prng_generate(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng)
206224
}
207225

208226
/* block future PRNG compromises from revealing past state */
209-
update(prng, prng->v, TC_SHA256_DIGEST_SIZE);
227+
update(prng, 0, 0, 0, 0);
210228

211229
return TC_CRYPTO_SUCCESS;
212230
}

0 commit comments

Comments
 (0)