tls: added AES code and made it compile. not used yet
[oweals/busybox.git] / networking / tls.h
1 /*
2  * Copyright (C) 2017 Denys Vlasenko
3  *
4  * Licensed under GPLv2, see file LICENSE in this source tree.
5  */
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,
9  * defines, types, etc.
10  */
11 #include "libbb.h"
12
13
14 /* Config tweaks */
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 /* pstm: multiprecision numbers */
28 #undef  DISABLE_PSTM
29 #if defined(__GNUC__) && defined(__i386__)
30 # define PSTM_32BIT
31 # define PSTM_X86
32 #endif
33 //test this before enabling:
34 //#if defined(__GNUC__) && defined(__x86_64__)
35 //# define PSTM_64BIT
36 //# define PSTM_X86_64
37 //#endif
38 //#if SOME_COND #define PSTM_MIPS, #define PSTM_32BIT
39 //#if SOME_COND #define PSTM_ARM,  #define PSTM_32BIT
40
41
42 #define PS_SUCCESS              0
43 #define PS_FAILURE              -1
44 #define PS_ARG_FAIL             -6      /* Failure due to bad function param */
45 #define PS_PLATFORM_FAIL        -7      /* Failure as a result of system call error */
46 #define PS_MEM_FAIL             -8      /* Failure to allocate requested memory */
47 #define PS_LIMIT_FAIL           -9      /* Failure on sanity/limit tests */
48
49 #define PS_TRUE         1
50 #define PS_FALSE        0
51
52 #if BB_BIG_ENDIAN
53 # define ENDIAN_BIG     1
54 # undef  ENDIAN_LITTLE
55 //#????  ENDIAN_32BITWORD
56 // controls only STORE32L, which we don't use
57 #else
58 # define ENDIAN_LITTLE  1
59 # undef  ENDIAN_BIG
60 #endif
61
62 typedef uint64_t uint64;
63 typedef  int64_t  int64;
64 typedef uint32_t uint32;
65 typedef  int32_t  int32;
66 typedef uint16_t uint16;
67 typedef  int16_t  int16;
68
69 //FIXME
70 typedef char psPool_t;
71
72 //#ifdef PS_PUBKEY_OPTIMIZE_FOR_SMALLER_RAM
73 #define PS_EXPTMOD_WINSIZE   3
74 //#ifdef PS_PUBKEY_OPTIMIZE_FOR_FASTER_SPEED
75 //#define PS_EXPTMOD_WINSIZE 5
76
77 #define PUBKEY_TYPE     0x01
78 #define PRIVKEY_TYPE    0x02
79
80 void tls_get_random(void *buf, unsigned len);
81
82 #define matrixCryptoGetPrngData(buf, len, userPtr) (tls_get_random(buf, len), PS_SUCCESS)
83
84 #define psFree(p, pool)    free(p)
85 #define psTraceCrypto(...) bb_error_msg_and_die(__VA_ARGS__)
86
87 /* Secure zerofill */
88 #define memset_s(A,B,C,D) memset((A),(C),(D))
89 /* Constant time memory comparison */
90 #define memcmpct(s1, s2, len) memcmp((s1), (s2), (len))
91 #undef  min
92 #define min(x, y) ((x) < (y) ? (x) : (y))
93
94
95 #include "tls_pstm.h"
96 #include "tls_rsa.h"
97 #include "tls_symmetric.h"
98 #include "tls_aes.h"