mirror of
https://github.com/strophe/libstrophe.git
synced 2026-07-18 11:56:22 +00:00
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)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = Hash_DRBG_Generate(&rand->ctx, (uint8_t *)output, len);
|
||||
if (rc == RESEED_NEEDED) {
|
||||
xmpp_rand_reseed(rand);
|
||||
rc = Hash_DRBG_Generate(&rand->ctx, (uint8_t *)output, len);
|
||||
assert(rc == 0);
|
||||
size_t gen, tot = 0;
|
||||
while (tot < len) {
|
||||
gen = len - tot;
|
||||
if (gen > GENERATE_MAX)
|
||||
gen = GENERATE_MAX;
|
||||
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