summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2025-01-22 12:53:16 +0000
committertb <>2025-01-22 12:53:16 +0000
commit9265252033e95a736d43b21bf2437b3629938ed4 (patch)
tree2b47411c7eb51d58cdc8980be3dbed8393083da5
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
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c15
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c3
2 files changed, 5 insertions, 13 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;
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
index 6277b06dab..8f917e95db 100644
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ b/src/lib/libcrypto/bn/bn_recp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_recp.c,v 1.29 2025/01/22 10:12:01 tb Exp $ */ 1/* $OpenBSD: bn_recp.c,v 1.30 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 *
@@ -79,6 +79,7 @@ BN_RECP_CTX_create(const BIGNUM *N)
79 79
80 if ((recp->N = BN_dup(N)) == NULL) 80 if ((recp->N = BN_dup(N)) == NULL)
81 goto err; 81 goto err;
82 BN_set_negative(recp->N, 0);
82 recp->num_bits = BN_num_bits(recp->N); 83 recp->num_bits = BN_num_bits(recp->N);
83 84
84 if ((recp->Nr = BN_new()) == NULL) 85 if ((recp->Nr = BN_new()) == NULL)