From 5d17dd64ccff0b6840a0b673df29c97ec05be448 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Mon, 30 Jun 2014 14:22:32 -0700 Subject: [PATCH] Very minor BN fixes. Fixes one comment that mentioned the wrong function name. Also causes two BN random functions to fail when the output is NULL. Previously they would silently do nothing. Change-Id: I89796ab855ea32787765c301a478352287e61190 --- crypto/bn/bn.h | 2 +- crypto/bn/random.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crypto/bn/bn.h b/crypto/bn/bn.h index 3ec88cd4f..1635aabd2 100644 --- a/crypto/bn/bn.h +++ b/crypto/bn/bn.h @@ -712,7 +712,7 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, * zero otherwise. */ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); -/* BN_exp sets |r| equal to |a|^{|p|} mod |m|. It does so with the best +/* BN_mod_exp sets |r| equal to |a|^{|p|} mod |m|. It does so with the best * algorithm for the values provided and can run in constant time if * |BN_FLG_CONSTTIME| is set for |p|. It returns one on success or zero * otherwise. */ diff --git a/crypto/bn/random.c b/crypto/bn/random.c index 06e4c0fde..924aad71d 100644 --- a/crypto/bn/random.c +++ b/crypto/bn/random.c @@ -117,6 +117,10 @@ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) { uint8_t *buf = NULL; int ret = 0, bit, bytes, mask; + if (rnd == NULL) { + return 0; + } + if (bits == 0) { BN_zero(rnd); return 1; @@ -252,6 +256,10 @@ int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range, const BIGNUM *priv, uint8_t *k_bytes = NULL; int ret = 0; + if (out == NULL) { + return 0; + } + if (BN_is_zero(range)) { OPENSSL_PUT_ERROR(BN, BN_generate_dsa_nonce, BN_R_DIV_BY_ZERO); goto err;