| 1 |
// Copyright (c) 2018, Google Inc. |
| 2 |
// SPDX-License-Identifier: ISC |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_HRSS_INTERNAL_H |
| 5 |
#define OPENSSL_HEADER_HRSS_INTERNAL_H |
| 6 |
|
| 7 |
#include <openssl/base.h> |
| 8 |
#include "../internal.h" |
| 9 |
#include "../fipsmodule/cpucap/internal.h" |
| 10 |
|
| 11 |
#if defined(__cplusplus) |
| 12 |
extern "C" { |
| 13 |
#endif |
| 14 |
|
| 15 |
|
| 16 |
#define N 701 |
| 17 |
#define BITS_PER_WORD (sizeof(crypto_word_t) * 8) |
| 18 |
#define WORDS_PER_POLY ((N + BITS_PER_WORD - 1) / BITS_PER_WORD) |
| 19 |
#define BITS_IN_LAST_WORD (N % BITS_PER_WORD) |
| 20 |
|
| 21 |
struct poly2 { |
| 22 |
crypto_word_t v[WORDS_PER_POLY]; |
| 23 |
}; |
| 24 |
|
| 25 |
struct poly3 { |
| 26 |
struct poly2 s, a; |
| 27 |
}; |
| 28 |
|
| 29 |
OPENSSL_EXPORT void HRSS_poly3_mul(struct poly3 *out, const struct poly3 *x, |
| 30 |
const struct poly3 *y); |
| 31 |
OPENSSL_EXPORT void HRSS_poly3_invert(struct poly3 *out, |
| 32 |
const struct poly3 *in); |
| 33 |
|
| 34 |
// On x86-64, we can use the AVX2 code from [HRSS]. (The authors have given |
| 35 |
// explicit permission for this and signed a CLA.) However it's 57KB of object |
| 36 |
// code, so it's not used if |OPENSSL_SMALL| is defined. |
| 37 |
#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_SMALL) && \ |
| 38 |
defined(OPENSSL_X86_64) && defined(OPENSSL_LINUX) && \ |
| 39 |
!defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX) |
| 40 |
#define POLY_RQ_MUL_ASM |
| 41 |
// POLY_MUL_RQ_SCRATCH_SPACE is the number of bytes of scratch space needed |
| 42 |
// by the assembly function poly_Rq_mul. |
| 43 |
#define POLY_MUL_RQ_SCRATCH_SPACE (6144 + 6144 + 12288 + 512 + 9408 + 32) |
| 44 |
|
| 45 |
// poly_Rq_mul is defined in assembly. Inputs and outputs must be 16-byte- |
| 46 |
// aligned. |
| 47 |
extern void poly_Rq_mul( |
| 48 |
uint16_t r[N + 3], const uint16_t a[N + 3], const uint16_t b[N + 3], |
| 49 |
// The following should be `scratch[POLY_MUL_RQ_SCRATCH_SPACE]` but |
| 50 |
// GCC 11.1 has a bug with unions that breaks that. |
| 51 |
uint8_t scratch[]); |
| 52 |
#endif |
| 53 |
|
| 54 |
|
| 55 |
#if defined(__cplusplus) |
| 56 |
} // extern "C" |
| 57 |
#endif |
| 58 |
|
| 59 |
#endif // !OPENSSL_HEADER_HRSS_INTERNAL_H |