diff options
-rw-r--r-- | src/lib/libcrypto/bn/bn_internal.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_mod_words.c | 16 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_field.c | 4 |
3 files changed, 20 insertions, 4 deletions
diff --git a/src/lib/libcrypto/bn/bn_internal.h b/src/lib/libcrypto/bn/bn_internal.h index a1f1515b57..8b5145e225 100644 --- a/src/lib/libcrypto/bn/bn_internal.h +++ b/src/lib/libcrypto/bn/bn_internal.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_internal.h,v 1.19 2025/05/25 05:12:05 jsing Exp $ */ | 1 | /* $OpenBSD: bn_internal.h,v 1.20 2025/08/02 16:20:00 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -41,6 +41,8 @@ void bn_mod_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | |||
41 | const BN_ULONG *m, size_t n); | 41 | const BN_ULONG *m, size_t n); |
42 | void bn_mod_mul_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | 42 | void bn_mod_mul_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, |
43 | const BN_ULONG *m, BN_ULONG *t, BN_ULONG m0, size_t n); | 43 | const BN_ULONG *m, BN_ULONG *t, BN_ULONG m0, size_t n); |
44 | void bn_mod_sqr_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *m, | ||
45 | BN_ULONG *t, BN_ULONG m0, size_t n); | ||
44 | 46 | ||
45 | void bn_montgomery_multiply_words(BN_ULONG *rp, const BN_ULONG *ap, | 47 | void bn_montgomery_multiply_words(BN_ULONG *rp, const BN_ULONG *ap, |
46 | const BN_ULONG *bp, const BN_ULONG *np, BN_ULONG *tp, BN_ULONG n0, | 48 | const BN_ULONG *bp, const BN_ULONG *np, BN_ULONG *tp, BN_ULONG n0, |
diff --git a/src/lib/libcrypto/bn/bn_mod_words.c b/src/lib/libcrypto/bn/bn_mod_words.c index 8971f9f306..4cc41717b4 100644 --- a/src/lib/libcrypto/bn/bn_mod_words.c +++ b/src/lib/libcrypto/bn/bn_mod_words.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_mod_words.c,v 1.1 2025/05/25 04:58:32 jsing Exp $ */ | 1 | /* $OpenBSD: bn_mod_words.c,v 1.2 2025/08/02 16:20:00 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -76,3 +76,17 @@ bn_mod_mul_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | |||
76 | bn_montgomery_multiply_words(r, a, b, m, t, m0, n); | 76 | bn_montgomery_multiply_words(r, a, b, m, t, m0, n); |
77 | } | 77 | } |
78 | #endif | 78 | #endif |
79 | |||
80 | /* | ||
81 | * bn_mod_sqr_words() computes r[] = (a[] * a[]) mod m[], where a, r and | ||
82 | * m are arrays of words with length n (r may be the same as a) in the | ||
83 | * Montgomery domain. The result remains in the Montgomery domain. | ||
84 | */ | ||
85 | #ifndef HAVE_BN_MOD_SQR_WORDS | ||
86 | void | ||
87 | bn_mod_sqr_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *m, | ||
88 | BN_ULONG *t, BN_ULONG m0, size_t n) | ||
89 | { | ||
90 | bn_montgomery_multiply_words(r, a, a, m, t, m0, n); | ||
91 | } | ||
92 | #endif | ||
diff --git a/src/lib/libcrypto/ec/ec_field.c b/src/lib/libcrypto/ec/ec_field.c index 0513b9f410..6576526e77 100644 --- a/src/lib/libcrypto/ec/ec_field.c +++ b/src/lib/libcrypto/ec/ec_field.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_field.c,v 1.2 2025/08/02 15:44:09 jsing Exp $ */ | 1 | /* $OpenBSD: ec_field.c,v 1.3 2025/08/02 16:20:00 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -198,5 +198,5 @@ ec_field_element_sqr(const EC_FIELD_MODULUS *m, EC_FIELD_ELEMENT *r, | |||
198 | { | 198 | { |
199 | BN_ULONG t[EC_FIELD_ELEMENT_MAX_WORDS * 2 + 2]; | 199 | BN_ULONG t[EC_FIELD_ELEMENT_MAX_WORDS * 2 + 2]; |
200 | 200 | ||
201 | bn_mod_mul_words(r->w, a->w, a->w, m->m.w, t, m->minv0, m->n); | 201 | bn_mod_sqr_words(r->w, a->w, m->m.w, t, m->minv0, m->n); |
202 | } | 202 | } |