2 * Copyright (C) 2017 Denys Vlasenko
4 * Licensed under GPLv2, see file LICENSE in this source tree.
6 /* Interface glue between bbox code and minimally tweaked matrixssl
7 * code. All C files (matrixssl and bbox (ones which need TLS))
8 * include this file, and guaranteed to see a consistent API,
15 #define HAVE_NATIVE_INT64
16 #undef USE_1024_KEY_SPEED_OPTIMIZATIONS
17 #undef USE_2048_KEY_SPEED_OPTIMIZATIONS
19 #undef USE_AES_CBC_EXTERNAL
27 /* pstm: multiprecision numbers */
29 #if defined(__GNUC__) && defined(__i386__)
30 /* PSTM_X86 works correctly. +25 bytes. */
34 //#if defined(__GNUC__) && defined(__x86_64__)
35 // /* PSTM_X86_64 works correctly, but +782 bytes. */
36 // /* Looks like most of the growth is because of PSTM_64BIT. */
38 //# define PSTM_X86_64
40 //#if SOME_COND #define PSTM_MIPS, #define PSTM_32BIT
41 //#if SOME_COND #define PSTM_ARM, #define PSTM_32BIT
46 #define PS_ARG_FAIL -6 /* Failure due to bad function param */
47 #define PS_PLATFORM_FAIL -7 /* Failure as a result of system call error */
48 #define PS_MEM_FAIL -8 /* Failure to allocate requested memory */
49 #define PS_LIMIT_FAIL -9 /* Failure on sanity/limit tests */
57 //#???? ENDIAN_32BITWORD
58 // controls only STORE32L, which we don't use
60 # define ENDIAN_LITTLE 1
64 typedef uint64_t uint64;
65 typedef int64_t int64;
66 typedef uint32_t uint32;
67 typedef int32_t int32;
68 typedef uint16_t uint16;
69 typedef int16_t int16;
71 //typedef char psPool_t;
73 //#ifdef PS_PUBKEY_OPTIMIZE_FOR_SMALLER_RAM
74 #define PS_EXPTMOD_WINSIZE 3
75 //#ifdef PS_PUBKEY_OPTIMIZE_FOR_FASTER_SPEED
76 //#define PS_EXPTMOD_WINSIZE 5
78 #define PUBKEY_TYPE 0x01
79 #define PRIVKEY_TYPE 0x02
81 void tls_get_random(void *buf, unsigned len);
83 #define matrixCryptoGetPrngData(buf, len, userPtr) (tls_get_random(buf, len), PS_SUCCESS)
85 #define psFree(p, pool) free(p)
86 #define psTraceCrypto(...) bb_error_msg_and_die(__VA_ARGS__)
89 #define memset_s(A,B,C,D) memset((A),(C),(D))
90 /* Constant time memory comparison */
91 #define memcmpct(s1, s2, len) memcmp((s1), (s2), (len))
93 #define min(x, y) ((x) < (y) ? (x) : (y))
98 #include "tls_symmetric.h"