diff options
| -rw-r--r-- | src/lib/libcrypto/bn/arch/amd64/bn_arch.c | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.c b/src/lib/libcrypto/bn/arch/amd64/bn_arch.c index b8ddae6e52..9ff8920ca2 100644 --- a/src/lib/libcrypto/bn/arch/amd64/bn_arch.c +++ b/src/lib/libcrypto/bn/arch/amd64/bn_arch.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_arch.c,v 1.11 2025/08/14 15:22:54 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.c,v 1.12 2025/08/14 15:29:17 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -19,6 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | #include "bn_arch.h" | 20 | #include "bn_arch.h" |
| 21 | #include "bn_local.h" | 21 | #include "bn_local.h" |
| 22 | #include "crypto_arch.h" | ||
| 22 | #include "s2n_bignum.h" | 23 | #include "s2n_bignum.h" |
| 23 | 24 | ||
| 24 | #ifdef HAVE_BN_ADD | 25 | #ifdef HAVE_BN_ADD |
| @@ -100,8 +101,14 @@ bn_mul_words(BN_ULONG *rd, const BN_ULONG *ad, int num, BN_ULONG w) | |||
| 100 | void | 101 | void |
| 101 | bn_mul_comba4(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) | 102 | bn_mul_comba4(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) |
| 102 | { | 103 | { |
| 103 | /* XXX - consider using non-alt on CPUs that have the ADX extension. */ | 104 | if ((crypto_cpu_caps_amd64 & CRYPTO_CPU_CAPS_AMD64_ADX) != 0) { |
| 104 | bignum_mul_4_8_alt((uint64_t *)rd, (const uint64_t *)ad, (const uint64_t *)bd); | 105 | bignum_mul_4_8((uint64_t *)rd, (const uint64_t *)ad, |
| 106 | (const uint64_t *)bd); | ||
| 107 | return; | ||
| 108 | } | ||
| 109 | |||
| 110 | bignum_mul_4_8_alt((uint64_t *)rd, (const uint64_t *)ad, | ||
| 111 | (const uint64_t *)bd); | ||
| 105 | } | 112 | } |
| 106 | #endif | 113 | #endif |
| 107 | 114 | ||
| @@ -109,8 +116,14 @@ bn_mul_comba4(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) | |||
| 109 | void | 116 | void |
| 110 | bn_mul_comba6(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) | 117 | bn_mul_comba6(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) |
| 111 | { | 118 | { |
| 112 | /* XXX - consider using non-alt on CPUs that have the ADX extension. */ | 119 | if ((crypto_cpu_caps_amd64 & CRYPTO_CPU_CAPS_AMD64_ADX) != 0) { |
| 113 | bignum_mul_6_12_alt((uint64_t *)rd, (const uint64_t *)ad, (const uint64_t *)bd); | 120 | bignum_mul_6_12((uint64_t *)rd, (const uint64_t *)ad, |
| 121 | (const uint64_t *)bd); | ||
| 122 | return; | ||
| 123 | } | ||
| 124 | |||
| 125 | bignum_mul_6_12_alt((uint64_t *)rd, (const uint64_t *)ad, | ||
| 126 | (const uint64_t *)bd); | ||
| 114 | } | 127 | } |
| 115 | #endif | 128 | #endif |
| 116 | 129 | ||
| @@ -118,8 +131,14 @@ bn_mul_comba6(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) | |||
| 118 | void | 131 | void |
| 119 | bn_mul_comba8(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) | 132 | bn_mul_comba8(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) |
| 120 | { | 133 | { |
| 121 | /* XXX - consider using non-alt on CPUs that have the ADX extension. */ | 134 | if ((crypto_cpu_caps_amd64 & CRYPTO_CPU_CAPS_AMD64_ADX) != 0) { |
| 122 | bignum_mul_8_16_alt((uint64_t *)rd, (const uint64_t *)ad, (const uint64_t *)bd); | 135 | bignum_mul_8_16((uint64_t *)rd, (const uint64_t *)ad, |
| 136 | (const uint64_t *)bd); | ||
| 137 | return; | ||
| 138 | } | ||
| 139 | |||
| 140 | bignum_mul_8_16_alt((uint64_t *)rd, (const uint64_t *)ad, | ||
| 141 | (const uint64_t *)bd); | ||
| 123 | } | 142 | } |
| 124 | #endif | 143 | #endif |
| 125 | 144 | ||
| @@ -137,7 +156,11 @@ bn_sqr(BIGNUM *r, const BIGNUM *a, int r_len, BN_CTX *ctx) | |||
| 137 | void | 156 | void |
| 138 | bn_sqr_comba4(BN_ULONG *rd, const BN_ULONG *ad) | 157 | bn_sqr_comba4(BN_ULONG *rd, const BN_ULONG *ad) |
| 139 | { | 158 | { |
| 140 | /* XXX - consider using non-alt on CPUs that have the ADX extension. */ | 159 | if ((crypto_cpu_caps_amd64 & CRYPTO_CPU_CAPS_AMD64_ADX) != 0) { |
| 160 | bignum_sqr_4_8((uint64_t *)rd, (const uint64_t *)ad); | ||
| 161 | return; | ||
| 162 | } | ||
| 163 | |||
| 141 | bignum_sqr_4_8_alt((uint64_t *)rd, (const uint64_t *)ad); | 164 | bignum_sqr_4_8_alt((uint64_t *)rd, (const uint64_t *)ad); |
| 142 | } | 165 | } |
| 143 | #endif | 166 | #endif |
| @@ -146,7 +169,11 @@ bn_sqr_comba4(BN_ULONG *rd, const BN_ULONG *ad) | |||
| 146 | void | 169 | void |
| 147 | bn_sqr_comba6(BN_ULONG *rd, const BN_ULONG *ad) | 170 | bn_sqr_comba6(BN_ULONG *rd, const BN_ULONG *ad) |
| 148 | { | 171 | { |
| 149 | /* XXX - consider using non-alt on CPUs that have the ADX extension. */ | 172 | if ((crypto_cpu_caps_amd64 & CRYPTO_CPU_CAPS_AMD64_ADX) != 0) { |
| 173 | bignum_sqr_6_12((uint64_t *)rd, (const uint64_t *)ad); | ||
| 174 | return; | ||
| 175 | } | ||
| 176 | |||
| 150 | bignum_sqr_6_12_alt((uint64_t *)rd, (const uint64_t *)ad); | 177 | bignum_sqr_6_12_alt((uint64_t *)rd, (const uint64_t *)ad); |
| 151 | } | 178 | } |
| 152 | #endif | 179 | #endif |
| @@ -155,7 +182,11 @@ bn_sqr_comba6(BN_ULONG *rd, const BN_ULONG *ad) | |||
| 155 | void | 182 | void |
| 156 | bn_sqr_comba8(BN_ULONG *rd, const BN_ULONG *ad) | 183 | bn_sqr_comba8(BN_ULONG *rd, const BN_ULONG *ad) |
| 157 | { | 184 | { |
| 158 | /* XXX - consider using non-alt on CPUs that have the ADX extension. */ | 185 | if ((crypto_cpu_caps_amd64 & CRYPTO_CPU_CAPS_AMD64_ADX) != 0) { |
| 186 | bignum_sqr_8_16((uint64_t *)rd, (const uint64_t *)ad); | ||
| 187 | return; | ||
| 188 | } | ||
| 189 | |||
| 159 | bignum_sqr_8_16_alt((uint64_t *)rd, (const uint64_t *)ad); | 190 | bignum_sqr_8_16_alt((uint64_t *)rd, (const uint64_t *)ad); |
| 160 | } | 191 | } |
| 161 | #endif | 192 | #endif |
