| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef OPENSSL_HEADER_CRYPTO_HRSS_INTERNAL_H |
| 16 | #define OPENSSL_HEADER_CRYPTO_HRSS_INTERNAL_H |
| 17 |
| 18 | #include <openssl/base.h> |
| 19 | #include "../internal.h" |
| 20 |
| 21 | #if defined(__cplusplus) |
| 22 | extern "C" { |
| 23 | #endif |
| 24 |
| 25 |
| 26 | #define N 701 |
| 27 | #define BITS_PER_WORD (sizeof(crypto_word_t) * 8) |
| 28 | #define WORDS_PER_POLY ((N + BITS_PER_WORD - 1) / BITS_PER_WORD) |
| 29 | #define BITS_IN_LAST_WORD (N % BITS_PER_WORD) |
| 30 |
| 31 | struct poly2 { |
| 32 | crypto_word_t v[WORDS_PER_POLY]; |
| 33 | }; |
| 34 |
| 35 | struct poly3 { |
| 36 | struct poly2 s, a; |
| 37 | }; |
| 38 |
| 39 | OPENSSL_EXPORT void HRSS_poly3_mul(struct poly3 *out, const struct poly3 *x, |
| 40 | const struct poly3 *y); |
| 41 | OPENSSL_EXPORT void HRSS_poly3_invert(struct poly3 *out, |
| 42 | const struct poly3 *in); |
| 43 |
| 44 | // On x86-64, we can use the AVX2 code from [HRSS]. (The authors have given |
| 45 | // explicit permission for this and signed a CLA.) However it's 57KB of object |
| 46 | // code, so it's not used if |OPENSSL_SMALL| is defined. |
| 47 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_SMALL) && \ |
| 48 | defined(OPENSSL_X86_64) && defined(OPENSSL_LINUX) |
| 49 | #define POLY_RQ_MUL_ASM |
| 50 | // POLY_MUL_RQ_SCRATCH_SPACE is the number of bytes of scratch space needed |
| 51 | // by the assembly function poly_Rq_mul. |
| 52 | #define POLY_MUL_RQ_SCRATCH_SPACE (6144 + 6144 + 12288 + 512 + 9408 + 32) |
| 53 |
| 54 | // poly_Rq_mul is defined in assembly. Inputs and outputs must be 16-byte- |
| 55 | // aligned. |
| 56 | extern void poly_Rq_mul( |
| 57 | uint16_t r[N + 3], const uint16_t a[N + 3], const uint16_t b[N + 3], |
| 58 | // The following should be `scratch[POLY_MUL_RQ_SCRATCH_SPACE]` but |
| 59 | // GCC 11.1 has a bug with unions that breaks that. |
| 60 | uint8_t scratch[]); |
| 61 | #endif |
| 62 |
| 63 |
| 64 | #if defined(__cplusplus) |
| 65 | } // extern "C" |
| 66 | #endif |
| 67 |
| 68 | #endif // !OPENSSL_HEADER_CRYPTO_HRSS_INTERNAL_H |
| 69 |