From f89a836ad1734e271b7d920cdde1316cadb7f536 Mon Sep 17 00:00:00 2001 From: jsing Date: Tue, 16 Apr 2024 13:04:05 +0000 Subject: [PATCH] Rename bn_expand() to bn_expand_bits(). Also change the bits type from int to size_t, since that's what the callers are passing and we can avoid unnecessary input validation. ok tb@ --- lib/libcrypto/bn/bn_convert.c | 6 +++--- lib/libcrypto/bn/bn_lib.c | 7 ++----- lib/libcrypto/bn/bn_local.h | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/libcrypto/bn/bn_convert.c b/lib/libcrypto/bn/bn_convert.c index f09c9091e71..60075e53ed9 100644 --- a/lib/libcrypto/bn/bn_convert.c +++ b/lib/libcrypto/bn/bn_convert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_convert.c,v 1.15 2023/07/09 18:37:58 tb Exp $ */ +/* $OpenBSD: bn_convert.c,v 1.16 2024/04/16 13:04:05 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -431,7 +431,7 @@ bn_dec2bn_cbs(BIGNUM **bnp, CBS *cbs) bn = BN_new(); if (bn == NULL) goto err; - if (!bn_expand(bn, digits * 4)) + if (!bn_expand_bits(bn, digits * 4)) goto err; if ((d = digits % BN_DEC_NUM) == 0) @@ -628,7 +628,7 @@ bn_hex2bn_cbs(BIGNUM **bnp, CBS *cbs) bn = BN_new(); if (bn == NULL) goto err; - if (!bn_expand(bn, digits * 4)) + if (!bn_expand_bits(bn, digits * 4)) goto err; if (!CBS_get_bytes(cbs, cbs, digits)) diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c index b59e65a1e15..6988a70f3b5 100644 --- a/lib/libcrypto/bn/bn_lib.c +++ b/lib/libcrypto/bn/bn_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_lib.c,v 1.91 2024/04/15 14:35:25 jsing Exp $ */ +/* $OpenBSD: bn_lib.c,v 1.92 2024/04/16 13:04:05 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -219,13 +219,10 @@ bn_expand_internal(BIGNUM *bn, int words) } int -bn_expand(BIGNUM *bn, int bits) +bn_expand_bits(BIGNUM *bn, size_t bits) { int words; - if (bits < 0) - return 0; - if (bits > (INT_MAX - BN_BITS2 + 1)) return 0; diff --git a/lib/libcrypto/bn/bn_local.h b/lib/libcrypto/bn/bn_local.h index 2c82e323faa..cffc5a2ea1a 100644 --- a/lib/libcrypto/bn/bn_local.h +++ b/lib/libcrypto/bn/bn_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_local.h,v 1.41 2024/04/10 15:09:03 tb Exp $ */ +/* $OpenBSD: bn_local.h,v 1.42 2024/04/16 13:04:05 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -259,7 +259,7 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num); void bn_correct_top(BIGNUM *a); -int bn_expand(BIGNUM *a, int bits); +int bn_expand_bits(BIGNUM *a, size_t bits); int bn_wexpand(BIGNUM *a, int words); BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, -- 2.20.1