summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2024-04-16 13:07:14 +0000
committerjsing <>2024-04-16 13:07:14 +0000
commitdb66035fd51044e8930ad8523d3210f358a39b32 (patch)
tree28030f92b2cde00057efbea070cb5b2e1940e42a
parente03bf717d1c2f2ba657a6fdd6993fa1299c5cef6 (diff)
downloadopenbsd-db66035fd51044e8930ad8523d3210f358a39b32.tar.gz
openbsd-db66035fd51044e8930ad8523d3210f358a39b32.tar.bz2
openbsd-db66035fd51044e8930ad8523d3210f358a39b32.zip
Provide bn_expand_bytes().
This will be used in an upcoming change. ok tb@
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c15
-rw-r--r--src/lib/libcrypto/bn/bn_local.h3
2 files changed, 16 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 6988a70f3b..72b988650c 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.92 2024/04/16 13:04:05 jsing Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.93 2024/04/16 13:07:14 jsing 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 *
@@ -232,6 +232,19 @@ bn_expand_bits(BIGNUM *bn, size_t bits)
232} 232}
233 233
234int 234int
235bn_expand_bytes(BIGNUM *bn, size_t bytes)
236{
237 int words;
238
239 if (bytes > (INT_MAX - BN_BYTES + 1))
240 return 0;
241
242 words = (bytes + BN_BYTES - 1) / BN_BYTES;
243
244 return bn_wexpand(bn, words);
245}
246
247int
235bn_wexpand(BIGNUM *bn, int words) 248bn_wexpand(BIGNUM *bn, int words)
236{ 249{
237 if (words < 0) 250 if (words < 0)
diff --git a/src/lib/libcrypto/bn/bn_local.h b/src/lib/libcrypto/bn/bn_local.h
index cffc5a2ea1..58b5d54903 100644
--- a/src/lib/libcrypto/bn/bn_local.h
+++ b/src/lib/libcrypto/bn/bn_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_local.h,v 1.42 2024/04/16 13:04:05 jsing Exp $ */ 1/* $OpenBSD: bn_local.h,v 1.43 2024/04/16 13:07:14 jsing 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 *
@@ -260,6 +260,7 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
260 260
261void bn_correct_top(BIGNUM *a); 261void bn_correct_top(BIGNUM *a);
262int bn_expand_bits(BIGNUM *a, size_t bits); 262int bn_expand_bits(BIGNUM *a, size_t bits);
263int bn_expand_bytes(BIGNUM *a, size_t bytes);
263int bn_wexpand(BIGNUM *a, int words); 264int bn_wexpand(BIGNUM *a, int words);
264 265
265BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, 266BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,