1
2
3
4
5
6
7
8
9
10
11#include "libbb.h"
12
13
14
15#define HAVE_NATIVE_INT64
16#undef USE_1024_KEY_SPEED_OPTIMIZATIONS
17#undef USE_2048_KEY_SPEED_OPTIMIZATIONS
18#define USE_AES
19#undef USE_AES_CBC_EXTERNAL
20#undef USE_AES_CCM
21#undef USE_AES_GCM
22#undef USE_3DES
23#undef USE_ARC4
24#undef USE_IDEA
25#undef USE_RC2
26#undef USE_SEED
27
28#undef DISABLE_PSTM
29#if defined(__GNUC__) && defined(__i386__)
30
31# define PSTM_32BIT
32# define PSTM_X86
33#endif
34
35
36
37
38
39
40
41
42
43
44#define PS_SUCCESS 0
45#define PS_FAILURE -1
46#define PS_ARG_FAIL -6
47#define PS_PLATFORM_FAIL -7
48#define PS_MEM_FAIL -8
49#define PS_LIMIT_FAIL -9
50
51#define PS_TRUE 1
52#define PS_FALSE 0
53
54#if BB_BIG_ENDIAN
55# define ENDIAN_BIG 1
56# undef ENDIAN_LITTLE
57
58
59#else
60# define ENDIAN_LITTLE 1
61# undef ENDIAN_BIG
62#endif
63
64typedef uint64_t uint64;
65typedef int64_t int64;
66typedef uint32_t uint32;
67typedef int32_t int32;
68typedef uint16_t uint16;
69typedef int16_t int16;
70
71
72
73
74#define PS_EXPTMOD_WINSIZE 3
75
76
77
78#define PUBKEY_TYPE 0x01
79#define PRIVKEY_TYPE 0x02
80
81#define AES_BLOCK_SIZE 16
82
83void tls_get_random(void *buf, unsigned len) FAST_FUNC;
84
85void xorbuf(void* buf, const void* mask, unsigned count) FAST_FUNC;
86
87#define ALIGNED_long ALIGNED(sizeof(long))
88void xorbuf_aligned_AES_BLOCK_SIZE(void* buf, const void* mask) FAST_FUNC;
89
90#define matrixCryptoGetPrngData(buf, len, userPtr) (tls_get_random(buf, len), PS_SUCCESS)
91
92#define psFree(p, pool) free(p)
93#define psTraceCrypto(msg) bb_simple_error_msg_and_die(msg)
94
95
96#define memset_s(A,B,C,D) memset((A),(C),(D))
97
98#define memcmpct(s1, s2, len) memcmp((s1), (s2), (len))
99#undef min
100#define min(x, y) ((x) < (y) ? (x) : (y))
101
102
103#include "tls_pstm.h"
104#include "tls_symmetric.h"
105#include "tls_aes.h"
106#include "tls_aesgcm.h"
107#include "tls_rsa.h"
108
109#define EC_CURVE_KEYSIZE 32
110#define P256_KEYSIZE 32
111#define CURVE25519_KEYSIZE 32
112
113void curve_x25519_compute_pubkey_and_premaster(
114 uint8_t *pubkey32, uint8_t *premaster32,
115 const uint8_t *peerkey32) FAST_FUNC;
116
117void curve_P256_compute_pubkey_and_premaster(
118 uint8_t *pubkey2x32, uint8_t *premaster32,
119 const uint8_t *peerkey2x32) FAST_FUNC;
120