summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_exp.c
diff options
context:
space:
mode:
authortb <>2025-01-22 12:53:16 +0000
committertb <>2025-01-22 12:53:16 +0000
commit9265252033e95a736d43b21bf2437b3629938ed4 (patch)
tree2b47411c7eb51d58cdc8980be3dbed8393083da5 /src/lib/libcrypto/bn/bn_exp.c
parent24c9cd684d5ef027d5484a39a092c8018d6936a5 (diff)
downloadopenbsd-9265252033e95a736d43b21bf2437b3629938ed4.tar.gz
openbsd-9265252033e95a736d43b21bf2437b3629938ed4.tar.bz2
openbsd-9265252033e95a736d43b21bf2437b3629938ed4.zip
bn_recp: Avoid complication for negative moduli
Instead of doing a weird dance, set the sign on N in BN_RECP_CTX_create(). Since we're not exposing a general purpose calculator API, we can simplify. ok jsing
Diffstat (limited to 'src/lib/libcrypto/bn/bn_exp.c')
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index 129c12495c..2aa41f8658 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_exp.c,v 1.55 2025/01/22 10:08:10 tb Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.56 2025/01/22 12:53:16 tb 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 *
@@ -1000,17 +1000,8 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
1000 if ((val[0] = BN_CTX_get(ctx)) == NULL) 1000 if ((val[0] = BN_CTX_get(ctx)) == NULL)
1001 goto err; 1001 goto err;
1002 1002
1003 if (m->neg) { 1003 if ((recp = BN_RECP_CTX_create(m)) == NULL)
1004 /* ignore sign of 'm' */ 1004 goto err;
1005 if (!bn_copy(aa, m))
1006 goto err;
1007 aa->neg = 0;
1008 if ((recp = BN_RECP_CTX_create(aa)) == 0)
1009 goto err;
1010 } else {
1011 if ((recp = BN_RECP_CTX_create(m)) == 0)
1012 goto err;
1013 }
1014 1005
1015 if (!BN_nnmod(val[0], a, m, ctx)) 1006 if (!BN_nnmod(val[0], a, m, ctx))
1016 goto err; 1007 goto err;