1 /* 2 * blapii.h - private data structures and prototypes for the freebl library 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #ifndef _BLAPII_H_ 9 #define _BLAPII_H_ 10 11 #include "blapit.h" 12 #include "mpi.h" 13 14 /* max block size of supported block ciphers */ 15 #define MAX_BLOCK_SIZE 16 16 17 typedef SECStatus (*freeblCipherFunc)(void *cx, unsigned char *output, 18 unsigned int *outputLen, unsigned int maxOutputLen, 19 const unsigned char *input, unsigned int inputLen, 20 unsigned int blocksize); 21 typedef SECStatus (*freeblAeadFunc)(void *cx, unsigned char *output, 22 unsigned int *outputLen, unsigned int maxOutputLen, 23 const unsigned char *input, unsigned int inputLen, 24 void *params, unsigned int paramsLen, 25 const unsigned char *aad, unsigned int aadLen, 26 unsigned int blocksize); 27 typedef void (*freeblDestroyFunc)(void *cx, PRBool freeit); 28 29 SEC_BEGIN_PROTOS 30 31 #ifndef NSS_FIPS_DISABLED 32 SECStatus BL_FIPSEntryOK(PRBool freeblOnly); 33 PRBool BL_POSTRan(PRBool freeblOnly); 34 #endif 35 36 #if defined(XP_UNIX) && !defined(NO_FORK_CHECK) 37 38 extern PRBool bl_parentForkedAfterC_Initialize; 39 40 #define SKIP_AFTER_FORK(x) \ 41 if (!bl_parentForkedAfterC_Initialize) \ 42 x 43 44 #else 45 46 #define SKIP_AFTER_FORK(x) x 47 48 #endif 49 50 SEC_END_PROTOS 51 52 #if defined(NSS_X86_OR_X64) 53 #define HAVE_UNALIGNED_ACCESS 1 54 #endif 55 56 #if defined(__clang__) 57 #define HAVE_NO_SANITIZE_ATTR __has_attribute(no_sanitize) 58 #else 59 #define HAVE_NO_SANITIZE_ATTR 0 60 #endif 61 62 /* Alignment helpers. */ 63 #if defined(_MSC_VER) 64 #define pre_align __declspec(align(16)) 65 #define post_align 66 #elif defined(__GNUC__) 67 #define pre_align 68 #define post_align __attribute__((aligned(16))) 69 #else 70 #define pre_align 71 #define post_align 72 #endif 73 74 #if defined(HAVE_UNALIGNED_ACCESS) && HAVE_NO_SANITIZE_ATTR 75 #define NO_SANITIZE_ALIGNMENT __attribute__((no_sanitize("alignment"))) 76 #else 77 #define NO_SANITIZE_ALIGNMENT 78 #endif 79 80 #undef HAVE_NO_SANITIZE_ATTR 81 82 SECStatus RSA_Init(); 83 SECStatus generate_prime(mp_int *prime, int primeLen); 84 85 /* Freebl state. */ 86 PRBool aesni_support(); 87 PRBool clmul_support(); 88 PRBool sha_support(); 89 PRBool avx_support(); 90 PRBool avx2_support(); 91 PRBool ssse3_support(); 92 PRBool sse4_1_support(); 93 PRBool sse4_2_support(); 94 PRBool arm_neon_support(); 95 PRBool arm_aes_support(); 96 PRBool arm_pmull_support(); 97 PRBool arm_sha1_support(); 98 PRBool arm_sha2_support(); 99 PRBool ppc_crypto_support(); 100 101 #ifdef NSS_FIPS_DISABLED 102 #define BLAPI_CLEAR_STACK(stack_size) 103 #else 104 #define BLAPI_CLEAR_STACK(stack_size) \ 105 { \ 106 volatile char _stkclr[stack_size]; \ 107 PORT_Memset((void *)&_stkclr[0], 0, stack_size); \ 108 } 109 #endif 110 111 #endif /* _BLAPII_H_ */ 112