/*
- * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
#include <stdio.h>
#include <time.h>
#include "internal/cryptlib.h"
-#include "internal/rand_int.h"
-#include "bn_lcl.h"
+#include "crypto/rand.h"
+#include "bn_local.h"
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
}
/* make a random number and set the top and bottom bits */
- b = flag == NORMAL ? rand_bytes_ex(libctx, buf, bytes)
- : rand_priv_bytes_ex(libctx, buf, bytes);
+ b = flag == NORMAL ? RAND_bytes_ex(libctx, buf, bytes)
+ : RAND_priv_bytes_ex(libctx, buf, bytes);
if (b <= 0)
goto err;
unsigned char c;
for (i = 0; i < bytes; i++) {
- if (rand_bytes_ex(libctx, &c, 1) <= 0)
+ if (RAND_bytes_ex(libctx, &c, 1) <= 0)
goto err;
if (c >= 128 && i > 0)
buf[i] = buf[i - 1];
{
return bnrand(NORMAL, rnd, bits, top, bottom, ctx);
}
-#ifndef FIPS_MODE
+#ifndef FIPS_MODULE
int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
{
return bnrand(NORMAL, rnd, bits, top, bottom, NULL);
return bnrand(PRIVATE, rnd, bits, top, bottom, ctx);
}
-#ifndef FIPS_MODE
+#ifndef FIPS_MODULE
int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom)
{
return bnrand(PRIVATE, rnd, bits, top, bottom, NULL);
return bnrand_range(NORMAL, r, range, ctx);
}
-#ifndef FIPS_MODE
+#ifndef FIPS_MODULE
int BN_rand_range(BIGNUM *r, const BIGNUM *range)
{
return bnrand_range(NORMAL, r, range, NULL);
return bnrand_range(PRIVATE, r, range, ctx);
}
-#ifndef FIPS_MODE
+#ifndef FIPS_MODULE
int BN_priv_rand_range(BIGNUM *r, const BIGNUM *range)
{
return bnrand_range(PRIVATE, r, range, NULL);
goto err;
/* We copy |priv| into a local buffer to avoid exposing its length. */
- todo = sizeof(priv->d[0]) * priv->top;
- if (todo > sizeof(private_bytes)) {
+ if (BN_bn2binpad(priv, private_bytes, sizeof(private_bytes)) < 0) {
/*
* No reasonable DSA or ECDSA key should have a private key this
* large and we don't handle this case in order to avoid leaking the
BNerr(BN_F_BN_GENERATE_DSA_NONCE, BN_R_PRIVATE_KEY_TOO_LARGE);
goto err;
}
- memcpy(private_bytes, priv->d, todo);
- memset(private_bytes + todo, 0, sizeof(private_bytes) - todo);
md = EVP_MD_fetch(libctx, "SHA512", NULL);
if (md == NULL) {
goto err;
}
for (done = 0; done < num_k_bytes;) {
- if (!rand_priv_bytes_ex(libctx, random_bytes, sizeof(random_bytes)))
+ if (!RAND_priv_bytes_ex(libctx, random_bytes, sizeof(random_bytes)))
goto err;
if (!EVP_DigestInit_ex(mdctx, md, NULL)
err:
EVP_MD_CTX_free(mdctx);
- EVP_MD_meth_free(md);
+ EVP_MD_free(md);
OPENSSL_free(k_bytes);
OPENSSL_cleanse(private_bytes, sizeof(private_bytes));
return ret;