datatypes.h
1 /** Constantine 2 * Copyright (c) 2018-2019 Status Research & Development GmbH 3 * Copyright (c) 2020-Present Mamy André-Ratsimbazafy 4 * Licensed and distributed under either of 5 * * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). 6 * * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). 7 * at your option. This file may not be copied, modified, or distributed except according to those terms. 8 */ 9 #ifndef __CTT_H_DATATYPES__ 10 #define __CTT_H_DATATYPES__ 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 // Basic Types 17 // ------------------------------------------------------------------------------------------------ 18 // If we can, we want zero dependencies 19 20 #if defined(__SIZE_TYPE__) && defined(__PTRDIFF_TYPE__) 21 typedef __SIZE_TYPE__ size_t; 22 typedef __PTRDIFF_TYPE__ ptrdiff_t; 23 #else 24 #include <stddef.h> 25 #endif 26 27 #if defined(__UINT8_TYPE__) && defined(__UINT32_TYPE__) && defined(__UINT64_TYPE__) 28 typedef __UINT8_TYPE__ uint8_t; 29 typedef __UINT32_TYPE__ uint32_t; 30 typedef __UINT64_TYPE__ uint64_t; 31 #else 32 #include <stdint.h> 33 #endif 34 35 // https://github.com/nim-lang/Nim/blob/v1.6.12/lib/nimbase.h#L318 36 #if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901 37 # define ctt_bool _Bool 38 #else 39 # define ctt_bool unsigned char 40 #endif 41 42 typedef size_t secret_word; 43 typedef size_t secret_bool; 44 typedef uint8_t byte; 45 46 // Sizes 47 // ------------------------------------------------------------------------------------------------ 48 49 #define CTT_WORD_BITWIDTH (sizeof(secret_word)*8) 50 #define CTT_WORDS_REQUIRED(bits) ((bits+CTT_WORD_BITWIDTH-1)/CTT_WORD_BITWIDTH) 51 52 // Attributes 53 // ------------------------------------------------------------------------------------------------ 54 55 #if defined(_MSC_VER) 56 # define ctt_align(x) __declspec(align(x)) 57 #else 58 # define ctt_align(x) __attribute__((aligned(x))) 59 #endif 60 61 // ------------------------------------------------------------------------------------------------ 62 63 #ifdef __cplusplus 64 } 65 #endif 66 67 #endif