/*1* Copyright (c) 2016 Thomas Pornin <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining4* a copy of this software and associated documentation files (the5* "Software"), to deal in the Software without restriction, including6* without limitation the rights to use, copy, modify, merge, publish,7* distribute, sublicense, and/or sell copies of the Software, and to8* permit persons to whom the Software is furnished to do so, subject to9* the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#ifndef CONFIG_H__25#define CONFIG_H__2627/*28* This file contains compile-time flags that can override the29* autodetection performed in relevant files. Each flag is a macro; it30* deactivates the feature if defined to 0, activates it if defined to a31* non-zero integer (normally 1). If the macro is not defined, then32* autodetection applies.33*/3435/*36* When BR_64 is enabled, 64-bit integer types are assumed to be37* efficient (i.e. the architecture has 64-bit registers and can38* do 64-bit operations as fast as 32-bit operations).39*40#define BR_64 141*/4243/*44* When BR_LOMUL is enabled, then multiplications of 32-bit values whose45* result are truncated to the low 32 bits are assumed to be46* substantially more efficient than 32-bit multiplications that yield47* 64-bit results. This is typically the case on low-end ARM Cortex M48* systems (M0, M0+, M1, and arguably M3 and M4 as well).49*50#define BR_LOMUL 151*/5253/*54* When BR_SLOW_MUL is enabled, multiplications are assumed to be55* substantially slow with regards to other integer operations, thus56* making it worth to make more operations for a given task if it allows57* using less multiplications.58*59#define BR_SLOW_MUL 160*/6162/*63* When BR_SLOW_MUL15 is enabled, short multplications (on 15-bit words)64* are assumed to be substantially slow with regards to other integer65* operations, thus making it worth to make more integer operations if66* it allows using less multiplications.67*68#define BR_SLOW_MUL15 169*/7071/*72* When BR_CT_MUL31 is enabled, multiplications of 31-bit values (used73* in the "i31" big integer implementation) use an alternate implementation74* which is slower and larger than the normal multiplication, but should75* ensure constant-time multiplications even on architectures where the76* multiplication opcode takes a variable number of cycles to complete.77*78#define BR_CT_MUL31 179*/8081/*82* When BR_CT_MUL15 is enabled, multiplications of 15-bit values (held83* in 32-bit words) use an alternate implementation which is slower and84* larger than the normal multiplication, but should ensure85* constant-time multiplications on most/all architectures where the86* basic multiplication is not constant-time.87#define BR_CT_MUL15 188*/8990/*91* When BR_NO_ARITH_SHIFT is enabled, arithmetic right shifts (with sign92* extension) are performed with a sequence of operations which is bigger93* and slower than a simple right shift on a signed value. This avoids94* relying on an implementation-defined behaviour. However, most if not95* all C compilers use sign extension for right shifts on signed values,96* so this alternate macro is disabled by default.97#define BR_NO_ARITH_SHIFT 198*/99100/*101* When BR_RDRAND is enabled, the SSL engine will use the RDRAND opcode102* to automatically obtain quality randomness for seeding its internal103* PRNG. Since that opcode is present only in recent x86 CPU, its104* support is dynamically tested; if the current CPU does not support105* it, then another random source will be used, such as /dev/urandom or106* CryptGenRandom().107*108#define BR_RDRAND 1109*/110111/*112* When BR_USE_GETENTROPY is enabled, the SSL engine will use the113* getentropy() function to obtain quality randomness for seeding its114* internal PRNG. On Linux and FreeBSD, getentropy() is implemented by115* the standard library with the system call getrandom(); on OpenBSD,116* getentropy() is the system call, and there is no getrandom() wrapper,117* hence the use of the getentropy() function for maximum portability.118*119* If the getentropy() call fails, and BR_USE_URANDOM is not explicitly120* disabled, then /dev/urandom will be used as a fallback mechanism. On121* FreeBSD and OpenBSD, this does not change much, since /dev/urandom122* will block if not enough entropy has been obtained since last boot.123* On Linux, /dev/urandom might not block, which can be troublesome in124* early boot stages, which is why getentropy() is preferred.125*126#define BR_USE_GETENTROPY 1127*/128129/*130* When BR_USE_URANDOM is enabled, the SSL engine will use /dev/urandom131* to automatically obtain quality randomness for seeding its internal132* PRNG.133*134#define BR_USE_URANDOM 1135*/136137/*138* When BR_USE_WIN32_RAND is enabled, the SSL engine will use the Win32139* (CryptoAPI) functions (CryptAcquireContext(), CryptGenRandom()...) to140* automatically obtain quality randomness for seeding its internal PRNG.141*142* Note: if both BR_USE_URANDOM and BR_USE_WIN32_RAND are defined, the143* former takes precedence.144*145#define BR_USE_WIN32_RAND 1146*/147148/*149* When BR_USE_UNIX_TIME is enabled, the X.509 validation engine obtains150* the current time from the OS by calling time(), and assuming that the151* returned value (a 'time_t') is an integer that counts time in seconds152* since the Unix Epoch (Jan 1st, 1970, 00:00 UTC).153*154#define BR_USE_UNIX_TIME 1155*/156157/*158* When BR_USE_WIN32_TIME is enabled, the X.509 validation engine obtains159* the current time from the OS by calling the Win32 function160* GetSystemTimeAsFileTime().161*162* Note: if both BR_USE_UNIX_TIME and BR_USE_WIN32_TIME are defined, the163* former takes precedence.164*165#define BR_USE_WIN32_TIME 1166*/167168/*169* When BR_ARMEL_CORTEXM_GCC is enabled, some operations are replaced with170* inline assembly which is shorter and/or faster. This should be used171* only when all of the following are true:172* - target architecture is ARM in Thumb mode173* - target endianness is little-endian174* - compiler is GCC (or GCC-compatible for inline assembly syntax)175*176* This is meant for the low-end cores (Cortex M0, M0+, M1, M3).177* Note: if BR_LOMUL is not explicitly enabled or disabled, then178* enabling BR_ARMEL_CORTEXM_GCC also enables BR_LOMUL.179*180#define BR_ARMEL_CORTEXM_GCC 1181*/182183/*184* When BR_AES_X86NI is enabled, the AES implementation using the x86 "NI"185* instructions (dedicated AES opcodes) will be compiled. If this is not186* enabled explicitly, then that AES implementation will be compiled only187* if a compatible compiler is detected. If set explicitly to 0, the188* implementation will not be compiled at all.189*190#define BR_AES_X86NI 1191*/192193/*194* When BR_SSE2 is enabled, SSE2 intrinsics will be used for some195* algorithm implementations that use them (e.g. chacha20_sse2). If this196* is not enabled explicitly, then support for SSE2 intrinsics will be197* automatically detected. If set explicitly to 0, then SSE2 code will198* not be compiled at all.199*200#define BR_SSE2 1201*/202203/*204* When BR_POWER8 is enabled, the AES implementation using the POWER ISA205* 2.07 opcodes (available on POWER8 processors and later) is compiled.206* If this is not enabled explicitly, then that implementation will be207* compiled only if a compatible compiler is detected, _and_ the target208* architecture is POWER8 or later.209*210#define BR_POWER8 1211*/212213/*214* When BR_INT128 is enabled, then code using the 'unsigned __int64'215* and 'unsigned __int128' types will be used to leverage 64x64->128216* unsigned multiplications. This should work with GCC and compatible217* compilers on 64-bit architectures.218*219#define BR_INT128 1220*/221222/*223* When BR_UMUL128 is enabled, then code using the '_umul128()' and224* '_addcarry_u64()' intrinsics will be used to implement 64x64->128225* unsigned multiplications. This should work on Visual C on x64 systems.226*227#define BR_UMUL128 1228*/229230/*231* When BR_LE_UNALIGNED is enabled, then the current architecture is232* assumed to use little-endian encoding for integers, and to tolerate233* unaligned accesses with no or minimal time penalty.234*235#define BR_LE_UNALIGNED 1236*/237238/*239* When BR_BE_UNALIGNED is enabled, then the current architecture is240* assumed to use big-endian encoding for integers, and to tolerate241* unaligned accesses with no or minimal time penalty.242*243#define BR_BE_UNALIGNED 1244*/245246#endif247248249