summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn.h
diff options
context:
space:
mode:
authordoug <>2016-03-02 06:16:11 +0000
committerdoug <>2016-03-02 06:16:11 +0000
commitab17e552504ef0a95a4e610ef038d76a7f3a34de (patch)
tree281c8cc8af8ee09d4488676b45944435b8f68b91 /src/lib/libcrypto/bn/bn.h
parent43ee3676b33314f3bcd9e058836959422b737ad4 (diff)
downloadopenbsd-ab17e552504ef0a95a4e610ef038d76a7f3a34de.tar.gz
openbsd-ab17e552504ef0a95a4e610ef038d76a7f3a34de.tar.bz2
openbsd-ab17e552504ef0a95a4e610ef038d76a7f3a34de.zip
Add bounds checking for BN_hex2bn/BN_dec2bn.
Need to make sure i * 4 won't overflow. Based on OpenSSL: commit 99ba9fd02fd481eb971023a3a0a251a37eb87e4c input + ok bcook@ ok beck@
Diffstat (limited to 'src/lib/libcrypto/bn/bn.h')
-rw-r--r--src/lib/libcrypto/bn/bn.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
index 2c648ba2ee..5efccd180b 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.28 2015/10/21 19:02:22 miod Exp $ */ 1/* $OpenBSD: bn.h,v 1.29 2016/03/02 06:16:11 doug 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 *
@@ -125,6 +125,7 @@
125#ifndef HEADER_BN_H 125#ifndef HEADER_BN_H
126#define HEADER_BN_H 126#define HEADER_BN_H
127 127
128#include <limits.h>
128#include <stdio.h> 129#include <stdio.h>
129#include <stdlib.h> 130#include <stdlib.h>
130 131
@@ -619,10 +620,20 @@ const BIGNUM *BN_get0_nist_prime_521(void);
619 620
620/* library internal functions */ 621/* library internal functions */
621 622
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))) 623#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))
625BIGNUM *bn_expand2(BIGNUM *a, int words); 624BIGNUM *bn_expand2(BIGNUM *a, int words);
625
626static inline BIGNUM *bn_expand(BIGNUM *a, int bits)
627{
628 if (bits > (INT_MAX - BN_BITS2 + 1))
629 return (NULL);
630
631 if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax)
632 return (a);
633
634 return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2);
635}
636
626#ifndef OPENSSL_NO_DEPRECATED 637#ifndef OPENSSL_NO_DEPRECATED
627BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */ 638BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */
628#endif 639#endif