1 /* Copyright (c) 2018, Google Inc. 2 * 3 * Permission to use, copy, modify, and/or distribute this software for any 4 * purpose with or without fee is hereby granted, provided that the above 5 * copyright notice and this permission notice appear in all copies. 6 * 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 15 #ifndef OPENSSL_HEADER_HRSS_INTERNAL_H 16 #define OPENSSL_HEADER_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_poly2_rotr_consttime(struct poly2 *p, size_t bits); 40 OPENSSL_EXPORT void HRSS_poly3_mul(struct poly3 *out, const struct poly3 *x, 41 const struct poly3 *y); 42 OPENSSL_EXPORT void HRSS_poly3_invert(struct poly3 *out, 43 const struct poly3 *in); 44 45 // On x86-64, we can use the AVX2 code from [HRSS]. (The authors have given 46 // explicit permission for this and signed a CLA.) However it's 57KB of object 47 // code, so it's not used if |OPENSSL_SMALL| is defined. 48 #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_SMALL) && \ 49 defined(OPENSSL_X86_64) && defined(OPENSSL_LINUX) 50 #define POLY_RQ_MUL_ASM 51 // poly_Rq_mul is defined in assembly. Inputs and outputs must be 16-byte- 52 // aligned. 53 extern void poly_Rq_mul(uint16_t r[N + 3], const uint16_t a[N + 3], 54 const uint16_t b[N + 3]); 55 #endif 56 57 58 #if defined(__cplusplus) 59 } // extern "C" 60 #endif 61 62 #endif // !OPENSSL_HEADER_HRSS_INTERNAL_H 63