Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universal abi used in amm functions, no need for OS differentiation #1869

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions crypto/fipsmodule/bn/bn_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3026,32 +3026,60 @@ TEST_F(BNTest, RSAZABI) {

#ifdef RSAZ_512_ENABLED
if (CRYPTO_is_AVX512IFMA_capable()) {
uint64_t res = 0;

#define TWOK (40 * 2)
#define TWOK_TABLE (2 * 20 * (1<<5))
#define THREEK (64 * 2)
#define THREEK_TABLE (2 * 32 * (1<<5))
#define FOURK (80 * 2)
#define FOURK_TABLE (2 * 40 * (1<<5))

int storage_bytes =
((TWOK * 2) + // res2 / red_y2
TWOK_TABLE + // red_table2k
(THREEK * 2) + // res3 / red_y3
THREEK_TABLE + // red_table3k
(FOURK * 2) + // res4 / red_y4
FOURK_TABLE) * // red_table4k
sizeof(uint64_t);

uint64_t *storage = (uint64_t*)OPENSSL_malloc(storage_bytes);

uint64_t *res2, *res3, *res4,
*red_y2, *red_y3, *red_y4,
*red_table2k, *red_table3k, *red_table4k;

res2 = storage;
red_y2 = storage + TWOK;
red_table2k = red_y2 + TWOK;
res3 = red_table2k + TWOK_TABLE;
red_y3 = res3 + THREEK;
red_table3k = red_y3 + THREEK;
res4 = red_table3k + THREEK_TABLE;
red_y4 = res4 + FOURK;
red_table4k = red_y4 + FOURK;

uint64_t a = 0;
uint64_t b = 0;
uint64_t m = 0;
uint64_t k0 = 0;
uint64_t k2[2] = {0};

uint64_t red_Y = 0;
int idx1 = 0;
int idx2 = 0;

uint64_t red_table2k[2*20*(1<<5)] = {0};
uint64_t red_table3k[2*32*(1<<5)] = {0};
uint64_t red_table4k[2*40*(1<<5)] = {0};
CHECK_ABI(rsaz_amm52x20_x1_ifma256, res2, &a, &b, &m, k0);
CHECK_ABI(rsaz_amm52x20_x2_ifma256, res2, &a, &b, &m, k2);
CHECK_ABI(extract_multiplier_2x20_win5, red_y2, red_table2k, idx1, idx2);

CHECK_ABI(rsaz_amm52x20_x1_ifma256, &res, &a, &b, &m, k0);
CHECK_ABI(rsaz_amm52x20_x2_ifma256, &res, &a, &b, &m, k2);
CHECK_ABI(extract_multiplier_2x20_win5, &red_Y, red_table2k, idx1, idx2);
CHECK_ABI(rsaz_amm52x30_x1_ifma256, res3, &a, &b, &m, k0);
CHECK_ABI(rsaz_amm52x30_x2_ifma256, res3, &a, &b, &m, k2);
CHECK_ABI(extract_multiplier_2x30_win5, red_y3, red_table3k, idx1, idx2);

CHECK_ABI(rsaz_amm52x30_x1_ifma256, &res, &a, &b, &m, k0);
CHECK_ABI(rsaz_amm52x30_x2_ifma256, &res, &a, &b, &m, k2);
CHECK_ABI(extract_multiplier_2x30_win5, &red_Y, red_table3k, idx1, idx2);
CHECK_ABI(rsaz_amm52x40_x1_ifma256, res4, &a, &b, &m, k0);
CHECK_ABI(rsaz_amm52x40_x2_ifma256, res4, &a, &b, &m, k2);
CHECK_ABI(extract_multiplier_2x40_win5, red_y4, red_table4k, idx1, idx2);

CHECK_ABI(rsaz_amm52x40_x1_ifma256, &res, &a, &b, &m, k0);
CHECK_ABI(rsaz_amm52x40_x2_ifma256, &res, &a, &b, &m, k2);
CHECK_ABI(extract_multiplier_2x40_win5, &red_Y, red_table4k, idx1, idx2);
OPENSSL_free(storage);
}
#endif // RSAZ_512_ENABLED
}
Expand Down
4 changes: 0 additions & 4 deletions crypto/fipsmodule/cpucap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,8 @@ OPENSSL_INLINE int CRYPTO_is_VPCLMULQDQ_capable(void) {
// 1100_0000_0010_0011_0000_0000_0000_0000
#define CPU_CAP_AVX512IFMA_BITFLAGS 0xC0230000
OPENSSL_INLINE int CRYPTO_is_AVX512IFMA_capable(void) {
#if defined(OPENSSL_WINDOWS)
return 0;
#else
return (OPENSSL_ia32cap_get()[2] & CPU_CAP_AVX512IFMA_BITFLAGS) ==
CPU_CAP_AVX512IFMA_BITFLAGS;
#endif
}

OPENSSL_INLINE int CRYPTO_is_VBMI2_capable(void) {
Expand Down
Loading