summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2018-07-23 18:14:32 +0000
committertb <>2018-07-23 18:14:32 +0000
commitce83f868728bea42458168feadca75b7580a116d (patch)
tree68059b6faefa6c0c40883f02020ccf3384a4dc24 /src
parent6549dc05f9ea0cb21d1e921b85864d1ce4646e0c (diff)
downloadopenbsd-ce83f868728bea42458168feadca75b7580a116d.tar.gz
openbsd-ce83f868728bea42458168feadca75b7580a116d.tar.bz2
openbsd-ce83f868728bea42458168feadca75b7580a116d.zip
Use a size_t instead of an int for the byte count in BN_swap_ct().
Since bignums use ints for the same purpose, this still uses an int internally after an overflow check. Suggested by and discussed with jsing. ok inoguchi, jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h4
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c15
2 files changed, 11 insertions, 8 deletions
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h
index ad9427fddc..b8319dd700 100644
--- a/src/lib/libcrypto/bn/bn_lcl.h
+++ b/src/lib/libcrypto/bn/bn_lcl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lcl.h,v 1.28 2018/07/10 21:52:07 tb Exp $ */ 1/* $OpenBSD: bn_lcl.h,v 1.29 2018/07/23 18:14:32 tb 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 *
@@ -606,7 +606,7 @@ BIGNUM *BN_mod_inverse_nonct(BIGNUM *ret, const BIGNUM *a, const BIGNUM *n,
606int BN_gcd_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 606int BN_gcd_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
607int BN_gcd_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 607int BN_gcd_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
608 608
609int BN_swap_ct(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords); 609int BN_swap_ct(BN_ULONG swap, BIGNUM *a, BIGNUM *b, size_t nwords);
610 610
611__END_HIDDEN_DECLS 611__END_HIDDEN_DECLS
612#endif 612#endif
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 3a468a1285..0b79a87413 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.44 2018/07/13 08:43:31 tb Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.45 2018/07/23 18:14:32 tb 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 *
@@ -897,16 +897,19 @@ BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
897 * nwords is the number of words to swap. 897 * nwords is the number of words to swap.
898 */ 898 */
899int 899int
900BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords) 900BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, size_t nwords)
901{ 901{
902 BN_ULONG t; 902 BN_ULONG t;
903 int i; 903 int i, words;
904 904
905 if (a == b) 905 if (a == b)
906 return 1; 906 return 1;
907 if (bn_wexpand(a, nwords) == NULL || bn_wexpand(b, nwords) == NULL) 907 if (nwords > INT_MAX)
908 return 0;
909 words = (int)nwords;
910 if (bn_wexpand(a, words) == NULL || bn_wexpand(b, words) == NULL)
908 return 0; 911 return 0;
909 if (a->top > nwords || b->top > nwords) { 912 if (a->top > words || b->top > words) {
910 BNerror(BN_R_INVALID_LENGTH); 913 BNerror(BN_R_INVALID_LENGTH);
911 return 0; 914 return 0;
912 } 915 }
@@ -930,7 +933,7 @@ BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
930 b->flags ^= t; 933 b->flags ^= t;
931 934
932 /* swap the data */ 935 /* swap the data */
933 for (i = 0; i < nwords; i++) { 936 for (i = 0; i < words; i++) {
934 t = (a->d[i] ^ b->d[i]) & condition; 937 t = (a->d[i] ^ b->d[i]) & condition;
935 a->d[i] ^= t; 938 a->d[i] ^= t;
936 b->d[i] ^= t; 939 b->d[i] ^= t;