allow reading arbitrary number of bytes from xmpp_rand_bytes()
If we expose the API it shouldn't be limited. Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
18
src/rand.c
18
src/rand.c
@@ -284,12 +284,18 @@ void xmpp_rand_free(xmpp_ctx_t *ctx, xmpp_rand_t *rand)
|
|||||||
void xmpp_rand_bytes(xmpp_rand_t *rand, unsigned char *output, size_t len)
|
void xmpp_rand_bytes(xmpp_rand_t *rand, unsigned char *output, size_t len)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
size_t gen, tot = 0;
|
||||||
rc = Hash_DRBG_Generate(&rand->ctx, (uint8_t *)output, len);
|
while (tot < len) {
|
||||||
if (rc == RESEED_NEEDED) {
|
gen = len - tot;
|
||||||
xmpp_rand_reseed(rand);
|
if (gen > GENERATE_MAX)
|
||||||
rc = Hash_DRBG_Generate(&rand->ctx, (uint8_t *)output, len);
|
gen = GENERATE_MAX;
|
||||||
assert(rc == 0);
|
rc = Hash_DRBG_Generate(&rand->ctx, (uint8_t *)output + tot, gen);
|
||||||
|
if (rc == RESEED_NEEDED) {
|
||||||
|
xmpp_rand_reseed(rand);
|
||||||
|
rc = Hash_DRBG_Generate(&rand->ctx, (uint8_t *)output + tot, gen);
|
||||||
|
assert(rc == 0);
|
||||||
|
}
|
||||||
|
tot += gen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user