diff options
author | jsing <> | 2025-08-05 15:15:54 +0000 |
---|---|---|
committer | jsing <> | 2025-08-05 15:15:54 +0000 |
commit | 663575bfacd1335c77f987bf10ce0f5195ac5a1f (patch) | |
tree | f00be69d309209afd93c3f3e132e9f40afd88602 /src | |
parent | 9a2cdc6743d4f6ee8d7ecd440dbf7c83790d9466 (diff) | |
download | openbsd-663575bfacd1335c77f987bf10ce0f5195ac5a1f.tar.gz openbsd-663575bfacd1335c77f987bf10ce0f5195ac5a1f.tar.bz2 openbsd-663575bfacd1335c77f987bf10ce0f5195ac5a1f.zip |
Speed up bn_{mod,sqr}_mul_words() for specific inputs.
Use bn_{mul,sqr}_comba{4,6,8}() and bn_montgomery_reduce_words() for
specific input sizes. This is significantly faster than using
bn_montgomery_multiply_words().
ok tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_mod_words.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_mod_words.c b/src/lib/libcrypto/bn/bn_mod_words.c index 4cc41717b4..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.2 2025/08/02 16:20:00 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,7 +73,18 @@ 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 | } | ||
77 | } | 88 | } |
78 | #endif | 89 | #endif |
79 | 90 | ||
@@ -87,6 +98,17 @@ void | |||
87 | bn_mod_sqr_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *m, | 98 | 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) | 99 | BN_ULONG *t, BN_ULONG m0, size_t n) |
89 | { | 100 | { |
90 | bn_montgomery_multiply_words(r, a, a, m, t, m0, n); | 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 | } | ||
91 | } | 113 | } |
92 | #endif | 114 | #endif |