From eedb90ca011716f7307e2faa18bc5acff262c3d3 Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Fri, 4 Mar 2016 16:23:30 +0000 Subject: graduate bn_expand() to a real function. the openssl version of this uses a macro with multiple-evaluations of arguments (different amount than the previous version..), but doug/bcook's inline version makes BIGNUM not opaque [problem spotted by naddy] ok doug --- src/lib/libcrypto/bn/bn.h | 6 +++--- src/lib/libcrypto/bn/bn_lib.c | 14 +++++++++++++- src/lib/libssl/src/crypto/bn/bn.h | 6 +++--- src/lib/libssl/src/crypto/bn/bn_lib.c | 14 +++++++++++++- 4 files changed, 32 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index 7d11a049d0..4ae6a8195d 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn.h,v 1.30 2016/03/04 16:06:38 doug Exp $ */ +/* $OpenBSD: bn.h,v 1.31 2016/03/04 16:23:30 deraadt Exp $ */ /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -619,10 +619,10 @@ const BIGNUM *BN_get0_nist_prime_521(void); /* library internal functions */ -#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\ - (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2)) #define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words))) BIGNUM *bn_expand2(BIGNUM *a, int words); +BIGNUM *bn_expand(BIGNUM *a, int bits); + #ifndef OPENSSL_NO_DEPRECATED BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */ #endif diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index 7cc76c1e85..311ec2044d 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_lib.c,v 1.34 2015/09/10 15:56:25 jsing Exp $ */ +/* $OpenBSD: bn_lib.c,v 1.35 2016/03/04 16:23:30 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -550,6 +550,18 @@ BN_get_word(const BIGNUM *a) return 0; } +BIGNUM * +bn_expand(BIGNUM *a, int bits) +{ + if (bits > (INT_MAX - BN_BITS2 + 1)) + return (NULL); + + if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax) + return (a); + + return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2); +} + int BN_set_word(BIGNUM *a, BN_ULONG w) { diff --git a/src/lib/libssl/src/crypto/bn/bn.h b/src/lib/libssl/src/crypto/bn/bn.h index 7d11a049d0..4ae6a8195d 100644 --- a/src/lib/libssl/src/crypto/bn/bn.h +++ b/src/lib/libssl/src/crypto/bn/bn.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn.h,v 1.30 2016/03/04 16:06:38 doug Exp $ */ +/* $OpenBSD: bn.h,v 1.31 2016/03/04 16:23:30 deraadt Exp $ */ /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -619,10 +619,10 @@ const BIGNUM *BN_get0_nist_prime_521(void); /* library internal functions */ -#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\ - (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2)) #define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words))) BIGNUM *bn_expand2(BIGNUM *a, int words); +BIGNUM *bn_expand(BIGNUM *a, int bits); + #ifndef OPENSSL_NO_DEPRECATED BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */ #endif diff --git a/src/lib/libssl/src/crypto/bn/bn_lib.c b/src/lib/libssl/src/crypto/bn/bn_lib.c index 7cc76c1e85..311ec2044d 100644 --- a/src/lib/libssl/src/crypto/bn/bn_lib.c +++ b/src/lib/libssl/src/crypto/bn/bn_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_lib.c,v 1.34 2015/09/10 15:56:25 jsing Exp $ */ +/* $OpenBSD: bn_lib.c,v 1.35 2016/03/04 16:23:30 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -550,6 +550,18 @@ BN_get_word(const BIGNUM *a) return 0; } +BIGNUM * +bn_expand(BIGNUM *a, int bits) +{ + if (bits > (INT_MAX - BN_BITS2 + 1)) + return (NULL); + + if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax) + return (a); + + return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2); +} + int BN_set_word(BIGNUM *a, BN_ULONG w) { -- cgit v1.2.3-55-g6feb