summaryrefslogtreecommitdiff
path: root/lib/libcrypto/bn
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2024-04-16 13:07:15 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2024-04-16 13:07:15 +0000
commit6a02cf6846fbac3d44e5f6054cbba29dc26fb5eb (patch)
treef135909ae9a5cc0a88e89e313b223a106b7c8917 /lib/libcrypto/bn
parent87f395e4a05e2146d6c3f7ac28621bd33d62e95c (diff)
Provide bn_expand_bytes().
This will be used in an upcoming change. ok tb@
Diffstat (limited to 'lib/libcrypto/bn')
-rw-r--r--lib/libcrypto/bn/bn_lib.c15
-rw-r--r--lib/libcrypto/bn/bn_local.h3
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c
index 6988a70f3b5..72b988650cc 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.92 2024/04/16 13:04:05 jsing Exp $ */
+/* $OpenBSD: bn_lib.c,v 1.93 2024/04/16 13:07:14 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -232,6 +232,19 @@ bn_expand_bits(BIGNUM *bn, size_t bits)
}
int
+bn_expand_bytes(BIGNUM *bn, size_t bytes)
+{
+ int words;
+
+ if (bytes > (INT_MAX - BN_BYTES + 1))
+ return 0;
+
+ words = (bytes + BN_BYTES - 1) / BN_BYTES;
+
+ return bn_wexpand(bn, words);
+}
+
+int
bn_wexpand(BIGNUM *bn, int words)
{
if (words < 0)
diff --git a/lib/libcrypto/bn/bn_local.h b/lib/libcrypto/bn/bn_local.h
index cffc5a2ea1a..58b5d549034 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.42 2024/04/16 13:04:05 jsing Exp $ */
+/* $OpenBSD: bn_local.h,v 1.43 2024/04/16 13:07:14 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -260,6 +260,7 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
void bn_correct_top(BIGNUM *a);
int bn_expand_bits(BIGNUM *a, size_t bits);
+int bn_expand_bytes(BIGNUM *a, size_t bytes);
int bn_wexpand(BIGNUM *a, int words);
BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,