fe_448.h (4152B)
1 /* fe448_448.h 2 * 3 * Copyright (C) 2006-2025 wolfSSL Inc. 4 * 5 * This file is part of wolfSSL. 6 * 7 * wolfSSL is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * wolfSSL is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 */ 21 22 23 #ifndef WOLF_CRYPT_FE_448_H 24 #define WOLF_CRYPT_FE_448_H 25 26 #include <wolfssl/wolfcrypt/settings.h> 27 28 #if defined(HAVE_CURVE448) || defined(HAVE_ED448) 29 30 #include <wolfssl/wolfcrypt/types.h> 31 32 #if defined(HAVE___UINT128_T) && !defined(NO_CURVED448_128BIT) && \ 33 !defined(NO_INT128) 34 #define CURVED448_128BIT 35 #endif 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 /* default to be faster but take more memory */ 42 #if !defined(CURVE448_SMALL) && !defined(ED448_SMALL) 43 44 #if defined(CURVED448_128BIT) 45 typedef sword64 fe448; 46 #ifndef WOLFSSL_UINT128_T_DEFINED 47 #ifdef __SIZEOF_INT128__ 48 typedef __uint128_t uint128_t; 49 typedef __int128_t int128_t; 50 typedef __uint128_t word128; 51 typedef __int128_t sword128; 52 #else 53 typedef unsigned long uint128_t __attribute__ ((mode(TI))); 54 typedef long int128_t __attribute__ ((mode(TI))); 55 typedef uint128_t word128; 56 typedef int128_t sword128; 57 #endif 58 #define WOLFSSL_UINT128_T_DEFINED 59 #endif 60 #else 61 typedef sword32 fe448; 62 #endif 63 64 WOLFSSL_LOCAL void fe448_init(void); 65 WOLFSSL_LOCAL int curve448(byte* r, const byte* n, const byte* a); 66 67 #if !defined(CURVED448_128BIT) 68 WOLFSSL_LOCAL void fe448_reduce(fe448*); 69 #else 70 #define fe448_reduce(a) WC_DO_NOTHING 71 #endif 72 WOLFSSL_LOCAL void fe448_neg(fe448* r, const fe448* a); 73 WOLFSSL_LOCAL void fe448_add(fe448* r, const fe448* a, const fe448* b); 74 WOLFSSL_LOCAL void fe448_sub(fe448* r, const fe448* a, const fe448* b); 75 WOLFSSL_LOCAL void fe448_mul(fe448* r, const fe448* a, const fe448* b); 76 WOLFSSL_LOCAL void fe448_sqr(fe448* r, const fe448* a); 77 WOLFSSL_LOCAL void fe448_mul39081(fe448* r, const fe448* a); 78 WOLFSSL_LOCAL void fe448_invert(fe448* r, const fe448* a); 79 80 WOLFSSL_LOCAL void fe448_0(fe448* a); 81 WOLFSSL_LOCAL void fe448_1(fe448* a); 82 WOLFSSL_LOCAL void fe448_copy(fe448* d, const fe448* a); 83 WOLFSSL_LOCAL int fe448_isnonzero(const fe448* a); 84 WOLFSSL_LOCAL int fe448_isnegative(const fe448* a); 85 86 WOLFSSL_LOCAL void fe448_from_bytes(fe448* r, const unsigned char* b); 87 WOLFSSL_LOCAL void fe448_to_bytes(unsigned char* b, const fe448* a); 88 89 WOLFSSL_LOCAL void fe448_cmov(fe448* a, const fe448* b, int c); 90 WOLFSSL_LOCAL void fe448_pow_2_446_222_1(fe448* r, const fe448* a); 91 92 #else 93 94 WOLFSSL_LOCAL void fe448_init(void); 95 WOLFSSL_LOCAL int curve448(byte* r, const byte* n, const byte* a); 96 97 #define fe448_reduce(a) WC_DO_NOTHING 98 99 WOLFSSL_LOCAL void fe448_neg(word8* r, const word8* a); 100 WOLFSSL_LOCAL void fe448_add(word8* r, const word8* a, const word8* b); 101 WOLFSSL_LOCAL void fe448_sub(word8* r, const word8* a, const word8* b); 102 WOLFSSL_LOCAL void fe448_mul(word8* r, const word8* a, const word8* b); 103 WOLFSSL_LOCAL void fe448_sqr(word8* r, const word8* a); 104 WOLFSSL_LOCAL void fe448_mul39081(word8* r, const word8* a); 105 WOLFSSL_LOCAL void fe448_invert(word8* r, const word8* a); 106 107 WOLFSSL_LOCAL void fe448_norm(byte *a); 108 WOLFSSL_LOCAL void fe448_copy(word8* d, const word8* a); 109 WOLFSSL_LOCAL int fe448_isnonzero(const word8* a); 110 111 WOLFSSL_LOCAL void fe448_cmov(word8* a, const word8* b, int c); 112 WOLFSSL_LOCAL void fe448_pow_2_446_222_1(word8* r, const word8* a); 113 114 #endif /* !CURVE448_SMALL || !ED448_SMALL */ 115 116 #ifdef __cplusplus 117 } /* extern "C" */ 118 #endif 119 120 #endif /* HAVE_CURVE448 || HAVE_ED448 */ 121 122 #endif /* WOLF_CRYPT_FE_448_H */