summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>2016-03-04 16:23:30 +0000
committerderaadt <>2016-03-04 16:23:30 +0000
commiteedb90ca011716f7307e2faa18bc5acff262c3d3 (patch)
tree00955abc6574e6b918442044ff6d1efdfd9d65d8 /src
parentaf37e0cd640a36968c4e3b6c009e96ba25b3e51c (diff)
downloadopenbsd-eedb90ca011716f7307e2faa18bc5acff262c3d3.tar.gz
openbsd-eedb90ca011716f7307e2faa18bc5acff262c3d3.tar.bz2
openbsd-eedb90ca011716f7307e2faa18bc5acff262c3d3.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/bn.h6
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c14
-rw-r--r--src/lib/libssl/src/crypto/bn/bn.h6
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_lib.c14
4 files changed, 32 insertions, 8 deletions
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 @@
1/* $OpenBSD: bn.h,v 1.30 2016/03/04 16:06:38 doug Exp $ */ 1/* $OpenBSD: bn.h,v 1.31 2016/03/04 16:23:30 deraadt Exp $ */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -619,10 +619,10 @@ const BIGNUM *BN_get0_nist_prime_521(void);
619 619
620/* library internal functions */ 620/* library internal functions */
621 621
622#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
623 (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2))
624#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words))) 622#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))
625BIGNUM *bn_expand2(BIGNUM *a, int words); 623BIGNUM *bn_expand2(BIGNUM *a, int words);
624BIGNUM *bn_expand(BIGNUM *a, int bits);
625
626#ifndef OPENSSL_NO_DEPRECATED 626#ifndef OPENSSL_NO_DEPRECATED
627BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */ 627BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */
628#endif 628#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 @@
1/* $OpenBSD: bn_lib.c,v 1.34 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.35 2016/03/04 16:23:30 deraadt Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -550,6 +550,18 @@ BN_get_word(const BIGNUM *a)
550 return 0; 550 return 0;
551} 551}
552 552
553BIGNUM *
554bn_expand(BIGNUM *a, int bits)
555{
556 if (bits > (INT_MAX - BN_BITS2 + 1))
557 return (NULL);
558
559 if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax)
560 return (a);
561
562 return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2);
563}
564
553int 565int
554BN_set_word(BIGNUM *a, BN_ULONG w) 566BN_set_word(BIGNUM *a, BN_ULONG w)
555{ 567{
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 @@
1/* $OpenBSD: bn.h,v 1.30 2016/03/04 16:06:38 doug Exp $ */ 1/* $OpenBSD: bn.h,v 1.31 2016/03/04 16:23:30 deraadt Exp $ */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -619,10 +619,10 @@ const BIGNUM *BN_get0_nist_prime_521(void);
619 619
620/* library internal functions */ 620/* library internal functions */
621 621
622#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
623 (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2))
624#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words))) 622#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))
625BIGNUM *bn_expand2(BIGNUM *a, int words); 623BIGNUM *bn_expand2(BIGNUM *a, int words);
624BIGNUM *bn_expand(BIGNUM *a, int bits);
625
626#ifndef OPENSSL_NO_DEPRECATED 626#ifndef OPENSSL_NO_DEPRECATED
627BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */ 627BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */
628#endif 628#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 @@
1/* $OpenBSD: bn_lib.c,v 1.34 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.35 2016/03/04 16:23:30 deraadt Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -550,6 +550,18 @@ BN_get_word(const BIGNUM *a)
550 return 0; 550 return 0;
551} 551}
552 552
553BIGNUM *
554bn_expand(BIGNUM *a, int bits)
555{
556 if (bits > (INT_MAX - BN_BITS2 + 1))
557 return (NULL);
558
559 if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax)
560 return (a);
561
562 return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2);
563}
564
553int 565int
554BN_set_word(BIGNUM *a, BN_ULONG w) 566BN_set_word(BIGNUM *a, BN_ULONG w)
555{ 567{