Skip to content

Commit bd10422

Browse files
committed
seeded rng: support resetting of seeded RNG
When using the API to set a seeded RNG with a NULL parameter, leancrypto now reverts back to use the internal, fully seeded RNG again. This change supports the ACVP testing. Signed-off-by: Stephan Mueller <smueller@chronox.de>
1 parent 090e593 commit bd10422

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

drng/api/lc_rng.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ int lc_rng_seed(struct lc_rng_ctx *ctx, const uint8_t *seed, size_t seedlen,
147147
* initial seed, and reseed. Also, that RNG is responsible for selecting and
148148
* managing the entropy source(s).
149149
*
150-
* @param [in] new_ctx externally defined RNG cipher handle
150+
* @param [in] new_ctx externally defined RNG cipher handle - when using NULL
151+
* then the leancrypto-internal fully seeded RNG used
152+
* (again).
151153
*
152154
* @return 0 upon success; < 0 on error
153155
*/

drng/src/rng_api_non_fips.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919

2020
#include "atomic.h"
2121
#include "lc_rng.h"
22+
#include "seeded_rng.h"
2223
#include "visibility.h"
2324

2425
LC_INTERFACE_FUNCTION(int, lc_rng_set_seeded, struct lc_rng_ctx *new_ctx)
2526
{
27+
mb();
28+
2629
if (!new_ctx)
27-
return -EINVAL;
30+
lc_seeded_rng = lc_seeded_rng_internal;
31+
else
32+
lc_seeded_rng = new_ctx;
2833

29-
mb();
30-
lc_seeded_rng = new_ctx;
3134
mb();
3235
return 0;
3336
}

drng/src/seeded_rng.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,6 @@ static const struct lc_rng _lc_seeded_rng = {
378378

379379
static struct lc_rng_ctx _lc_seeded_rng_ctx = { &_lc_seeded_rng, NULL };
380380

381+
struct lc_rng_ctx *lc_seeded_rng_internal = &_lc_seeded_rng_ctx;
382+
381383
LC_INTERFACE_SYMBOL(struct lc_rng_ctx *, lc_seeded_rng) = &_lc_seeded_rng_ctx;

drng/src/seeded_rng.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ void seeded_rng_noise_fini(void);
3232

3333
void lc_seeded_rng_zero_state(void);
3434

35+
extern struct lc_rng_ctx *lc_seeded_rng_internal;
36+
3537
#ifdef __cplusplus
3638
}
3739
#endif

0 commit comments

Comments
 (0)