summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2021-12-04 16:05:47 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2021-12-04 16:05:47 +0000
commitaf57d9704118eb573eaab2f25cd28f474d903f8e (patch)
tree2d8dd771149c0c0cf3ae3e9e9ded498685db7a43
parentd593164b5531ff8e7e77f8cb66f88c808a7ba200 (diff)
Implement the BN_to_montgomery() macro as a function
ok inoguchi jsing
-rw-r--r--lib/libcrypto/bn/bn.h7
-rw-r--r--lib/libcrypto/bn/bn_mont.c8
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/libcrypto/bn/bn.h b/lib/libcrypto/bn/bn.h
index 4bfb81d32e0..af4dd41bd5f 100644
--- a/lib/libcrypto/bn/bn.h
+++ b/lib/libcrypto/bn/bn.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn.h,v 1.48 2021/12/04 16:02:44 tb Exp $ */
+/* $OpenBSD: bn.h,v 1.49 2021/12/04 16:05:46 tb Exp $ */
/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -609,8 +609,13 @@ BN_MONT_CTX *BN_MONT_CTX_new(void );
void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
BN_MONT_CTX *mont, BN_CTX *ctx);
+#if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL)
+int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,
+ BN_CTX *ctx);
+#else
#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
(r),(a),&((mont)->RR),(mont),(ctx))
+#endif
int BN_from_montgomery(BIGNUM *r, const BIGNUM *a,
BN_MONT_CTX *mont, BN_CTX *ctx);
void BN_MONT_CTX_free(BN_MONT_CTX *mont);
diff --git a/lib/libcrypto/bn/bn_mont.c b/lib/libcrypto/bn/bn_mont.c
index eeac046826e..45e312a3a6d 100644
--- a/lib/libcrypto/bn/bn_mont.c
+++ b/lib/libcrypto/bn/bn_mont.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn_mont.c,v 1.26 2017/01/21 11:00:46 beck Exp $ */
+/* $OpenBSD: bn_mont.c,v 1.27 2021/12/04 16:05:46 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -175,6 +175,12 @@ err:
return (ret);
}
+int
+BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, BN_CTX *ctx)
+{
+ return BN_mod_mul_montgomery(r, a, &mont->RR, mont, ctx);
+}
+
#ifdef MONT_WORD
static int
BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)