bit = (bits - 1) % 8;
mask = 0xff << (bit + 1);
- buf = (unsigned char *)OPENSSL_malloc(bytes);
+ buf = OPENSSL_malloc(bytes);
if (buf == NULL) {
BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);
goto err;
RAND_add(&tim, sizeof(tim), 0.0);
if (pseudorand) {
- if (RAND_pseudo_bytes(buf, bytes) == -1)
+ if (RAND_bytes(buf, bytes) <= 0)
goto err;
} else {
if (RAND_bytes(buf, bytes) <= 0)
goto err;
}
-#if 1
if (pseudorand == 2) {
/*
* generate patterns that are more likely to trigger BN library bugs
unsigned char c;
for (i = 0; i < bytes; i++) {
- RAND_pseudo_bytes(&c, 1);
+ if (RAND_bytes(&c, 1) <= 0)
+ goto err;
if (c >= 128 && i > 0)
buf[i] = buf[i - 1];
else if (c < 42)
buf[i] = 255;
}
}
-#endif
if (top != -1) {
if (top) {
goto err;
ret = 1;
err:
- if (buf != NULL) {
- OPENSSL_cleanse(buf, bytes);
- OPENSSL_free(buf);
- }
+ OPENSSL_clear_free(buf, bytes);
bn_check_top(rnd);
return (ret);
}
return bnrand(1, rnd, bits, top, bottom);
}
-#if 1
int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
{
return bnrand(2, rnd, bits, top, bottom);
}
-#endif
/* random number r: 0 <= r < range */
static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)
return bn_rand_range(1, r, range);
}
-#ifndef OPENSSL_NO_SHA512
/*
* BN_generate_dsa_nonce generates a random number 0 <= out < range. Unlike
* BN_rand_range, it also includes the contents of |priv| and |message| in
ret = 1;
err:
- if (k_bytes)
- OPENSSL_free(k_bytes);
+ OPENSSL_free(k_bytes);
return ret;
}
-#endif /* OPENSSL_NO_SHA512 */