if ((flags & SMIME_DETACHED) && data) {
/* We want multipart/signed */
/* Generate a random boundary */
- if (RAND_bytes_ex(libctx, (unsigned char *)bound, 32) <= 0)
+ if (RAND_bytes_ex(libctx, (unsigned char *)bound, 32, 0) <= 0)
return 0;
for (i = 0; i < 32; i++) {
c = bound[i] & 0xf;
}
if (salt)
memcpy(sstr, salt, saltlen);
- else if (RAND_bytes_ex(ctx, sstr, saltlen) <= 0)
+ else if (RAND_bytes_ex(ctx, sstr, saltlen, 0) <= 0)
goto err;
ASN1_STRING_set0(pbe->salt, sstr, saltlen);
if (EVP_CIPHER_iv_length(cipher)) {
if (aiv)
memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher));
- else if (RAND_bytes_ex(libctx, iv, EVP_CIPHER_iv_length(cipher)) <= 0)
+ else if (RAND_bytes_ex(libctx, iv, EVP_CIPHER_iv_length(cipher),
+ 0) <= 0)
goto err;
}
if (salt)
memcpy(osalt->data, salt, saltlen);
- else if (RAND_bytes_ex(libctx, osalt->data, saltlen) <= 0)
+ else if (RAND_bytes_ex(libctx, osalt->data, saltlen, 0) <= 0)
goto merr;
if (iter <= 0)
do {
int rv;
- if (!BN_priv_rand_range_ex(ret->A, ret->mod, ctx))
+ if (!BN_priv_rand_range_ex(ret->A, ret->mod, 0, ctx))
goto err;
if (int_bn_mod_inverse(ret->Ai, ret->A, ret->mod, ctx, &rv))
break;
/* generate blinding value */
do {
if (!BN_priv_rand_ex(b, BN_num_bits(p) - 1,
- BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, ctx))
+ BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, 0, ctx))
goto err;
} while (BN_is_zero(b));
goto err;
do {
if (!BN_priv_rand_ex(rho, p[0], BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY,
- ctx))
+ 0, ctx))
goto err;
if (!BN_GF2m_mod_arr(rho, rho, p))
goto err;
/* (Step 4) */
for (i = 0; i < iterations; ++i) {
/* (Step 4.1) obtain a Random string of bits b where 1 < b < w-1 */
- if (!BN_priv_rand_range_ex(b, w3, ctx)
+ if (!BN_priv_rand_range_ex(b, w3, 0, ctx)
|| !BN_add_word(b, 2)) /* 1 < b < w-1 */
goto err;
again:
/* TODO: Not all primes are private */
- if (!BN_priv_rand_ex(rnd, bits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ODD, ctx))
+ if (!BN_priv_rand_ex(rnd, bits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ODD, 0,
+ ctx))
return 0;
if (safe && !BN_set_bit(rnd, 1))
return 0;
maxdelta = BN_MASK2 - BN_get_word(add);
again:
- if (!BN_rand_ex(rnd, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD, ctx))
+ if (!BN_rand_ex(rnd, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD, 0, ctx))
goto err;
/* we need ((rnd-rem) % add) == 0 */
if (Xp1 == NULL) {
/* Set the top and bottom bits to make it odd and the correct size */
if (!BN_priv_rand_ex(Xp1i, bitlen, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD,
- ctx))
+ 0, ctx))
goto err;
}
/* (Steps 4.1/5.1): Randomly generate Xp2 if it is not passed in */
if (Xp2 == NULL) {
/* Set the top and bottom bits to make it odd and the correct size */
if (!BN_priv_rand_ex(Xp2i, bitlen, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD,
- ctx))
+ 0, ctx))
goto err;
}
* (Step 3) Choose Random X such that
* sqrt(2) * 2^(nlen/2-1) <= Random X <= (2^(nlen/2)) - 1.
*/
- if (!BN_priv_rand_range_ex(X, range, ctx) || !BN_add(X, X, base))
+ if (!BN_priv_rand_range_ex(X, range, 0, ctx) || !BN_add(X, X, base))
goto end;
}
/* (Step 4) Y = X + ((R - X) mod 2r1r2) */
if (!BN_set_word(y, i))
goto end;
} else {
- if (!BN_priv_rand_ex(y, BN_num_bits(p), 0, 0, ctx))
+ if (!BN_priv_rand_ex(y, BN_num_bits(p), 0, 0, 0, ctx))
goto end;
if (BN_ucmp(y, p) >= 0) {
if (!(p->neg ? BN_add : BN_sub) (y, y, p))
* - 1. By setting the top two bits we ensure that the lower bound is
* exceeded.
*/
- if (!BN_priv_rand_ex(Xp, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY, ctx))
+ if (!BN_priv_rand_ex(Xp, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY, 0,
+ ctx))
return 0;
BN_CTX_start(ctx);
goto err;
for (i = 0; i < 1000; i++) {
- if (!BN_priv_rand_ex(Xq, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY,
+ if (!BN_priv_rand_ex(Xq, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY, 0,
ctx))
goto err;
if (Xp1 == NULL || Xp2 == NULL)
goto error;
- if (!BN_priv_rand_ex(Xp1, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY, ctx))
+ if (!BN_priv_rand_ex(Xp1, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY, 0, ctx))
goto error;
- if (!BN_priv_rand_ex(Xp2, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY, ctx))
+ if (!BN_priv_rand_ex(Xp2, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY, 0, ctx))
goto error;
if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb))
goto error;
unsigned char *bytes = OPENSSL_malloc(len);
int res = 0;
- if (bytes == NULL || RAND_bytes_ex(ctx->libctx, bytes, len) <= 0)
+ if (bytes == NULL || RAND_bytes_ex(ctx->libctx, bytes, len, 0) <= 0)
ERR_raise(ERR_LIB_CMP, CMP_R_FAILURE_OBTAINING_RANDOM);
else
res = ossl_cmp_asn1_octet_string_set1_bytes(tgt, bytes, len);
/* Generate a random IV if we need one */
ivlen = EVP_CIPHER_CTX_iv_length(ctx);
if (ivlen > 0) {
- if (RAND_bytes_ex(libctx, iv, ivlen) <= 0)
+ if (RAND_bytes_ex(libctx, iv, ivlen, 0) <= 0)
goto err;
piv = iv;
}
else {
if (!ASN1_STRING_set(rr->signedContentIdentifier, NULL, 32))
goto merr;
- if (RAND_bytes_ex(libctx, rr->signedContentIdentifier->data, 32) <= 0)
+ if (RAND_bytes_ex(libctx, rr->signedContentIdentifier->data, 32,
+ 0) <= 0)
goto err;
}
ivlen = EVP_CIPHER_CTX_iv_length(ctx);
if (ivlen > 0) {
- if (RAND_bytes_ex(ossl_cms_ctx_get0_libctx(cms_ctx), iv, ivlen) <= 0)
+ if (RAND_bytes_ex(ossl_cms_ctx_get0_libctx(cms_ctx), iv, ivlen, 0) <= 0)
goto err;
if (EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0) {
ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
/* Add random padding to end */
if (olen > inlen + 4
&& RAND_bytes_ex(ossl_cms_ctx_get0_libctx(cms_ctx), out + 4 + inlen,
- olen - 4 - inlen) <= 0)
+ olen - 4 - inlen, 0) <= 0)
return 0;
/* Encrypt twice */
if (!EVP_EncryptUpdate(ctx, out, &dummy, out, olen)
*/
if ((salt = OPENSSL_malloc(slen)) == NULL)
goto err;
- if (RAND_bytes_ex(libctx, salt, (int)slen) <= 0) {
+ if (RAND_bytes_ex(libctx, salt, (int)slen, 0) <= 0) {
ERR_raise(ERR_LIB_CRMF, CRMF_R_FAILURE_OBTAINING_RANDOM);
goto err;
}
goto err;
l = dh->length ? dh->length : BN_num_bits(dh->params.p) - 1;
if (!BN_priv_rand_ex(priv_key, l, BN_RAND_TOP_ONE,
- BN_RAND_BOTTOM_ANY, ctx))
+ BN_RAND_BOTTOM_ANY, 0, ctx))
goto err;
/*
* We handle just one known case where g is a quadratic non-residue:
/* Generate a blinding value */
do {
if (!BN_priv_rand_ex(blind, BN_num_bits(dsa->params.q) - 1,
- BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, ctx))
+ BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, 0, ctx))
goto err;
} while (BN_is_zero(blind));
BN_set_flags(blind, BN_FLG_CONSTTIME);
if (!BN_generate_dsa_nonce(k, dsa->params.q, dsa->priv_key, dgst,
dlen, ctx))
goto err;
- } else if (!BN_priv_rand_range_ex(k, dsa->params.q, ctx))
+ } else if (!BN_priv_rand_range_ex(k, dsa->params.q, 0, ctx))
goto err;
} while (BN_is_zero(k));
/* s blinding: make sure lambda (s->Z here) is not zero */
do {
if (!BN_priv_rand_ex(s->Z, BN_num_bits(group->field) - 1,
- BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, ctx)) {
+ BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, 0, ctx)) {
ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
return 0;
}
/* r blinding: make sure lambda (r->Y here for storage) is not zero */
do {
if (!BN_priv_rand_ex(r->Y, BN_num_bits(group->field) - 1,
- BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, ctx)) {
+ BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, 0, ctx)) {
ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
return 0;
}
}
do
- if (!BN_priv_rand_range_ex(priv_key, order, ctx))
+ if (!BN_priv_rand_range_ex(priv_key, order, 0, ctx))
goto err;
while (BN_is_zero(priv_key)) ;
goto err;
}
} else {
- if (!BN_priv_rand_range_ex(k, order, ctx)) {
+ if (!BN_priv_rand_range_ex(k, order, 0, ctx)) {
ERR_raise(ERR_LIB_EC, EC_R_RANDOM_NUMBER_GENERATION_FAILED);
goto err;
}
* internally implementing counter-measures for RNG weakness.
*/
if (RAND_priv_bytes_ex(eckey->libctx, param + S390X_OFF_RN(len),
- len) != 1) {
+ len, 0) != 1) {
ERR_raise(ERR_LIB_EC, EC_R_RANDOM_NUMBER_GENERATION_FAILED);
goto ret;
}
goto err;
do {
- if (!BN_priv_rand_range_ex(e, group->field, ctx))
+ if (!BN_priv_rand_range_ex(e, group->field, 0, ctx))
goto err;
} while (BN_is_zero(e));
*/
do {
ERR_set_mark();
- ret = BN_priv_rand_range_ex(lambda, group->field, ctx);
+ ret = BN_priv_rand_range_ex(lambda, group->field, 0, ctx);
ERR_pop_to_mark();
if (ret == 0) {
ret = 1;
/* make sure lambda (r->Y here for storage) is not zero */
do {
- if (!BN_priv_rand_range_ex(r->Y, group->field, ctx))
+ if (!BN_priv_rand_range_ex(r->Y, group->field, 0, ctx))
return 0;
} while (BN_is_zero(r->Y));
/* make sure lambda (s->Z here for storage) is not zero */
do {
- if (!BN_priv_rand_range_ex(s->Z, group->field, ctx))
+ if (!BN_priv_rand_range_ex(s->Z, group->field, 0, ctx))
return 0;
} while (BN_is_zero(s->Z));
}
if (op == KEY_OP_KEYGEN) {
if (id != EVP_PKEY_NONE) {
- if (RAND_priv_bytes_ex(libctx, privkey, KEYLENID(id)) <= 0)
+ if (RAND_priv_bytes_ex(libctx, privkey, KEYLENID(id), 0) <= 0)
goto err;
if (id == EVP_PKEY_X25519) {
privkey[0] &= 248;
goto err;
}
- if (RAND_priv_bytes_ex(ctx->libctx, privkey, X25519_KEYLEN) <= 0)
+ if (RAND_priv_bytes_ex(ctx->libctx, privkey, X25519_KEYLEN, 0) <= 0)
goto err;
privkey[0] &= 248;
goto err;
}
- if (RAND_priv_bytes_ex(ctx->libctx, privkey, X448_KEYLEN) <= 0)
+ if (RAND_priv_bytes_ex(ctx->libctx, privkey, X448_KEYLEN, 0) <= 0)
goto err;
privkey[0] &= 252;
goto err;
}
- if (RAND_priv_bytes_ex(ctx->libctx, privkey, ED25519_KEYLEN) <= 0)
+ if (RAND_priv_bytes_ex(ctx->libctx, privkey, ED25519_KEYLEN, 0) <= 0)
goto err;
md = EVP_MD_fetch(ctx->libctx, "SHA512", ctx->propquery);
goto err;
}
- if (RAND_priv_bytes_ex(ctx->libctx, privkey, ED448_KEYLEN) <= 0)
+ if (RAND_priv_bytes_ex(ctx->libctx, privkey, ED448_KEYLEN, 0) <= 0)
goto err;
hashctx = EVP_MD_CTX_new();
OSSL_LIB_CTX *libctx = EVP_CIPHER_CTX_get_libctx(ctx);
kl = EVP_CIPHER_CTX_key_length(ctx);
- if (kl <= 0 || RAND_priv_bytes_ex(libctx, key, kl) <= 0)
+ if (kl <= 0 || RAND_priv_bytes_ex(libctx, key, kl, 0) <= 0)
return 0;
return 1;
}
return 0;
len = EVP_CIPHER_CTX_iv_length(ctx);
- if (len < 0 || RAND_priv_bytes_ex(libctx, iv, len) <= 0)
+ if (len < 0 || RAND_priv_bytes_ex(libctx, iv, len, 0) <= 0)
goto err;
len = EVP_CIPHER_CTX_key_length(ctx);
do {
/* Steps (3, 4 & 7) : c + 1 = 1 + random[0..2^N - 1] */
- if (!BN_priv_rand_range_ex(priv, two_powN, ctx)
+ if (!BN_priv_rand_range_ex(priv, two_powN, 0, ctx)
|| !BN_add_word(priv, 1))
goto err;
/* Step (6) : loop if c > M - 2 (i.e. c + 1 >= M) */
/* A.1.1.2 Step (5) : generate seed with size seed_len */
if (generate_seed
- && RAND_bytes_ex(libctx, seed, (int)seedlen) < 0)
+ && RAND_bytes_ex(libctx, seed, (int)seedlen, 0) < 0)
goto err;
/*
* A.1.1.2 Step (6) AND
if (!BN_GENCB_call(cb, 0, m++))
goto err;
- if (generate_seed && RAND_bytes_ex(libctx, seed, (int)qsize) <= 0)
+ if (generate_seed && RAND_bytes_ex(libctx, seed, (int)qsize, 0) <= 0)
goto err;
memcpy(buf, seed, qsize);
p12->mac->salt->length = saltlen;
if (!salt) {
if (RAND_bytes_ex(p12->authsafes->ctx.libctx, p12->mac->salt->data,
- saltlen) <= 0)
+ saltlen, 0) <= 0)
return 0;
} else
memcpy(p12->mac->salt->data, salt, saltlen);
ivlen = EVP_CIPHER_iv_length(evp_cipher);
xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
if (ivlen > 0)
- if (RAND_bytes_ex(libctx, iv, ivlen) <= 0)
+ if (RAND_bytes_ex(libctx, iv, ivlen, 0) <= 0)
goto err;
(void)ERR_set_mark();
db[emlen - flen - mdlen - 1] = 0x01;
memcpy(db + emlen - flen - mdlen, from, (unsigned int)flen);
/* step 3d: generate random byte string */
- if (RAND_bytes_ex(libctx, seed, mdlen) <= 0)
+ if (RAND_bytes_ex(libctx, seed, mdlen, 0) <= 0)
goto err;
dbmask_len = emlen - mdlen;
/* pad out with non-zero random data */
j = tlen - 3 - flen;
- if (RAND_bytes_ex(libctx, p, j) <= 0)
+ if (RAND_bytes_ex(libctx, p, j, 0) <= 0)
return 0;
for (i = 0; i < j; i++) {
if (*p == '\0')
do {
- if (RAND_bytes_ex(libctx, p, 1) <= 0)
+ if (RAND_bytes_ex(libctx, p, 1, 0) <= 0)
return 0;
} while (*p == '\0');
p++;
* to decrypt.
*/
if (RAND_priv_bytes_ex(libctx, rand_premaster_secret,
- sizeof(rand_premaster_secret)) <= 0) {
+ sizeof(rand_premaster_secret), 0) <= 0) {
ERR_raise(ERR_LIB_RSA, ERR_R_INTERNAL_ERROR);
return -1;
}
ERR_raise(ERR_LIB_RSA, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (RAND_bytes_ex(rsa->libctx, salt, sLen) <= 0)
+ if (RAND_bytes_ex(rsa->libctx, salt, sLen, 0) <= 0)
goto err;
}
maskedDBLen = emLen - hLen - 1;
memset(ciphertext_buf, 0, *ciphertext_len);
- if (!BN_priv_rand_range_ex(k, order, ctx)) {
+ if (!BN_priv_rand_range_ex(k, order, 0, ctx)) {
ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
goto done;
}
}
for (;;) {
- if (!BN_priv_rand_range_ex(k, order, ctx)) {
+ if (!BN_priv_rand_range_ex(k, order, 0, ctx)) {
ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
goto done;
}
}
if (*salt == NULL) {
- if (RAND_bytes_ex(libctx, tmp2, SRP_RANDOM_SALT_LEN) <= 0)
+ if (RAND_bytes_ex(libctx, tmp2, SRP_RANDOM_SALT_LEN, 0) <= 0)
goto err;
s = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);
goto err;
if (*salt == NULL) {
- if (RAND_bytes_ex(libctx, tmp2, SRP_RANDOM_SALT_LEN) <= 0)
+ if (RAND_bytes_ex(libctx, tmp2, SRP_RANDOM_SALT_LEN, 0) <= 0)
goto err;
salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);