diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_mod_words.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_mod_words.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn_mod_words.c b/src/lib/libcrypto/bn/bn_mod_words.c index 8971f9f306..d9aee8701a 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.3 2025/08/05 15:15:54 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -73,6 +73,42 @@ void | |||
73 | bn_mod_mul_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | 73 | bn_mod_mul_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, |
74 | const BN_ULONG *m, BN_ULONG *t, BN_ULONG m0, size_t n) | 74 | const BN_ULONG *m, BN_ULONG *t, BN_ULONG m0, size_t n) |
75 | { | 75 | { |
76 | bn_montgomery_multiply_words(r, a, b, m, t, m0, n); | 76 | if (n == 4) { |
77 | bn_mul_comba4(t, a, b); | ||
78 | bn_montgomery_reduce_words(r, t, m, m0, n); | ||
79 | } else if (n == 6) { | ||
80 | bn_mul_comba6(t, a, b); | ||
81 | bn_montgomery_reduce_words(r, t, m, m0, n); | ||
82 | } else if (n == 8) { | ||
83 | bn_mul_comba8(t, a, b); | ||
84 | bn_montgomery_reduce_words(r, t, m, m0, n); | ||
85 | } else { | ||
86 | bn_montgomery_multiply_words(r, a, b, m, t, m0, n); | ||
87 | } | ||
88 | } | ||
89 | #endif | ||
90 | |||
91 | /* | ||
92 | * bn_mod_sqr_words() computes r[] = (a[] * a[]) mod m[], where a, r and | ||
93 | * m are arrays of words with length n (r may be the same as a) in the | ||
94 | * Montgomery domain. The result remains in the Montgomery domain. | ||
95 | */ | ||
96 | #ifndef HAVE_BN_MOD_SQR_WORDS | ||
97 | void | ||
98 | bn_mod_sqr_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *m, | ||
99 | BN_ULONG *t, BN_ULONG m0, size_t n) | ||
100 | { | ||
101 | if (n == 4) { | ||
102 | bn_sqr_comba4(t, a); | ||
103 | bn_montgomery_reduce_words(r, t, m, m0, n); | ||
104 | } else if (n == 6) { | ||
105 | bn_sqr_comba6(t, a); | ||
106 | bn_montgomery_reduce_words(r, t, m, m0, n); | ||
107 | } else if (n == 8) { | ||
108 | bn_sqr_comba8(t, a); | ||
109 | bn_montgomery_reduce_words(r, t, m, m0, n); | ||
110 | } else { | ||
111 | bn_montgomery_multiply_words(r, a, a, m, t, m0, n); | ||
112 | } | ||
77 | } | 113 | } |
78 | #endif | 114 | #endif |