#include <gtest/gtest.h>
#include <openssl/hrss.h>
#include <openssl/rand.h>
#include "../internal.h"
#include "../test/abi_test.h"
#include "../test/test_util.h"
#include "internal.h"
static void poly3_rand(poly3 *p) { … }
static void poly3_word_add(crypto_word_t *s1, crypto_word_t *a1,
const crypto_word_t s2, const crypto_word_t a2) { … }
TEST(HRSS, Poly3Invert) { … }
TEST(HRSS, Poly3UnreducedInput) { … }
TEST(HRSS, Basic) { … }
TEST(HRSS, Random) { … }
TEST(HRSS, NoWritesToConstData) { … }
TEST(HRSS, Golden) { … }
#if defined(POLY_RQ_MUL_ASM) && defined(SUPPORTS_ABI_TEST)
TEST(HRSS, ABI) {
if (!CRYPTO_is_AVX2_capable()) {
fprintf(stderr, "Skipping ABI test due to lack of AVX2 support.\n");
return;
}
alignas(16) uint16_t r[N + 3];
alignas(16) uint16_t a[N + 3] = {0};
alignas(16) uint16_t b[N + 3] = {0};
uint8_t kCanary[256];
static_assert(sizeof(kCanary) % 32 == 0, "needed for alignment");
memset(kCanary, 42, sizeof(kCanary));
auto scratch_buf = std::make_unique<uint8_t[]>(
32 + sizeof(kCanary) + POLY_MUL_RQ_SCRATCH_SPACE + sizeof(kCanary));
uint8_t *scratch =
static_cast<uint8_t *>(align_pointer(scratch_buf.get(), 32));
OPENSSL_memcpy(scratch, kCanary, sizeof(kCanary));
OPENSSL_memcpy(scratch + sizeof(kCanary) + POLY_MUL_RQ_SCRATCH_SPACE, kCanary,
sizeof(kCanary));
CHECK_ABI(poly_Rq_mul, r, a, b, &scratch[sizeof(kCanary)]);
EXPECT_EQ(Bytes(scratch, sizeof(kCanary)), Bytes(kCanary));
EXPECT_EQ(Bytes(scratch + sizeof(kCanary) + POLY_MUL_RQ_SCRATCH_SPACE,
sizeof(kCanary)),
Bytes(kCanary));
}
#endif