comparison libtomcrypt/src/headers/tomcrypt_custom.h @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children 8305ebe45940
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9
1 #ifndef TOMCRYPT_CUSTOM_H_ 10 #ifndef TOMCRYPT_CUSTOM_H_
2 #define TOMCRYPT_CUSTOM_H_ 11 #define TOMCRYPT_CUSTOM_H_
3 12
4 /* compile options depend on Dropbear options.h */
5 #include "options.h"
6
7 /* macros for various libc functions you can change for embedded targets */ 13 /* macros for various libc functions you can change for embedded targets */
8 #ifndef XMALLOC 14 #ifndef XMALLOC
9 #ifdef malloc
10 #define LTC_NO_PROTOTYPES
11 #endif
12 #define XMALLOC malloc 15 #define XMALLOC malloc
13 #endif 16 #endif
14 #ifndef XREALLOC 17 #ifndef XREALLOC
15 #ifdef realloc
16 #define LTC_NO_PROTOTYPES
17 #endif
18 #define XREALLOC realloc 18 #define XREALLOC realloc
19 #endif 19 #endif
20 #ifndef XCALLOC 20 #ifndef XCALLOC
21 #ifdef calloc
22 #define LTC_NO_PROTOTYPES
23 #endif
24 #define XCALLOC calloc 21 #define XCALLOC calloc
25 #endif 22 #endif
26 #ifndef XFREE 23 #ifndef XFREE
27 #ifdef free
28 #define LTC_NO_PROTOTYPES
29 #endif
30 #define XFREE free 24 #define XFREE free
31 #endif 25 #endif
32 26
33 #ifndef XMEMSET 27 #ifndef XMEMSET
34 #ifdef memset
35 #define LTC_NO_PROTOTYPES
36 #endif
37 #define XMEMSET memset 28 #define XMEMSET memset
38 #endif 29 #endif
39 #ifndef XMEMCPY 30 #ifndef XMEMCPY
40 #ifdef memcpy
41 #define LTC_NO_PROTOTYPES
42 #endif
43 #define XMEMCPY memcpy 31 #define XMEMCPY memcpy
44 #endif 32 #endif
33 #ifndef XMEMMOVE
34 #define XMEMMOVE memmove
35 #endif
45 #ifndef XMEMCMP 36 #ifndef XMEMCMP
46 #ifdef memcmp
47 #define LTC_NO_PROTOTYPES
48 #endif
49 #define XMEMCMP memcmp 37 #define XMEMCMP memcmp
50 #endif 38 #endif
39 /* A memory compare function that has to run in constant time,
40 * c.f. mem_neq() API summary.
41 */
42 #ifndef XMEM_NEQ
43 #define XMEM_NEQ mem_neq
44 #endif
51 #ifndef XSTRCMP 45 #ifndef XSTRCMP
52 #ifdef strcmp
53 #define LTC_NO_PROTOTYPES
54 #endif
55 #define XSTRCMP strcmp 46 #define XSTRCMP strcmp
56 #endif 47 #endif
57 48
58 #ifndef XCLOCK 49 #ifndef XCLOCK
59 #define XCLOCK clock 50 #define XCLOCK clock
60 #endif 51 #endif
61 #ifndef XCLOCKS_PER_SEC 52
62 #define XCLOCKS_PER_SEC CLOCKS_PER_SEC 53 #ifndef XQSORT
63 #endif 54 #define XQSORT qsort
55 #endif
56
57 #if ( defined(malloc) || defined(realloc) || defined(calloc) || defined(free) || \
58 defined(memset) || defined(memcpy) || defined(memcmp) || defined(strcmp) || \
59 defined(clock) || defined(qsort) ) && !defined(LTC_NO_PROTOTYPES)
60 #define LTC_NO_PROTOTYPES
61 #endif
62
63 /* shortcut to disable automatic inclusion */
64 #if defined LTC_NOTHING && !defined LTC_EASY
65 #define LTC_NO_CIPHERS
66 #define LTC_NO_MODES
67 #define LTC_NO_HASHES
68 #define LTC_NO_MACS
69 #define LTC_NO_PRNGS
70 #define LTC_NO_PK
71 #define LTC_NO_PKCS
72 #define LTC_NO_MISC
73 #endif /* LTC_NOTHING */
74
75 /* Easy button? */
76 #ifdef LTC_EASY
77 #define LTC_NO_CIPHERS
78 #define LTC_RIJNDAEL
79 #define LTC_BLOWFISH
80 #define LTC_DES
81 #define LTC_CAST5
82
83 #define LTC_NO_MODES
84 #define LTC_ECB_MODE
85 #define LTC_CBC_MODE
86 #define LTC_CTR_MODE
87
88 #define LTC_NO_HASHES
89 #define LTC_SHA1
90 #define LTC_SHA3
91 #define LTC_SHA512
92 #define LTC_SHA384
93 #define LTC_SHA256
94 #define LTC_SHA224
95 #define LTC_HASH_HELPERS
96
97 #define LTC_NO_MACS
98 #define LTC_HMAC
99 #define LTC_OMAC
100 #define LTC_CCM_MODE
64 101
65 #define LTC_NO_PRNGS 102 #define LTC_NO_PRNGS
103 #define LTC_SPRNG
104 #define LTC_YARROW
105 #define LTC_DEVRANDOM
106 #define LTC_TRY_URANDOM_FIRST
107 #define LTC_RNG_GET_BYTES
108 #define LTC_RNG_MAKE_PRNG
109
66 #define LTC_NO_PK 110 #define LTC_NO_PK
67 #ifdef DROPBEAR_SMALL_CODE 111 #define LTC_MRSA
112 #define LTC_MECC
113
114 #define LTC_NO_MISC
115 #define LTC_BASE64
116 #endif
117
118 /* The minimal set of functionality to run the tests */
119 #ifdef LTC_MINIMAL
120 #define LTC_RIJNDAEL
121 #define LTC_SHA256
122 #define LTC_YARROW
123 #define LTC_CTR_MODE
124
125 #define LTC_RNG_MAKE_PRNG
126 #define LTC_RNG_GET_BYTES
127 #define LTC_DEVRANDOM
128 #define LTC_TRY_URANDOM_FIRST
129
130 #undef LTC_NO_FILE
131 #endif
132
133 /* Enable self-test test vector checking */
134 #ifndef LTC_NO_TEST
135 #define LTC_TEST
136 #endif
137 /* Enable extended self-tests */
138 /* #define LTC_TEST_EXT */
139
140 /* Use small code where possible */
141 #if DROPBEAR_SMALL_CODE
68 #define LTC_SMALL_CODE 142 #define LTC_SMALL_CODE
69 #endif 143 #endif
70 /* These spit out warnings etc */
71 #define LTC_NO_ROLC
72 #ifndef XQSORT
73 #ifdef qsort
74 #define LTC_NO_PROTOTYPES
75 #endif
76 #define XQSORT qsort
77 #endif
78
79
80 /* Enable self-test test vector checking */
81 /* Not for dropbear */
82 /*#define LTC_TEST*/
83 144
84 /* clean the stack of functions which put private information on stack */ 145 /* clean the stack of functions which put private information on stack */
85 /* #define LTC_CLEAN_STACK */ 146 /* #define LTC_CLEAN_STACK */
86 147
87 /* disable all file related functions */ 148 /* disable all file related functions */
88 #define LTC_NO_FILE 149 /* #define LTC_NO_FILE */
89 150
90 /* disable all forms of ASM */ 151 /* disable all forms of ASM */
91 /* #define LTC_NO_ASM */ 152 /* #define LTC_NO_ASM */
92 153
93 /* disable FAST mode */ 154 /* disable FAST mode */
94 /* #define LTC_NO_FAST */ 155 /* #define LTC_NO_FAST */
95 156
96 /* disable BSWAP on x86 */ 157 /* disable BSWAP on x86 */
97 /* #define LTC_NO_BSWAP */ 158 /* #define LTC_NO_BSWAP */
98 159
99 160 /* ---> math provider? <--- */
100 #ifdef DROPBEAR_BLOWFISH 161 #ifndef LTC_NO_MATH
162
163 /* LibTomMath */
164 /* #define LTM_DESC */
165
166 /* TomsFastMath */
167 /* #define TFM_DESC */
168
169 /* GNU Multiple Precision Arithmetic Library */
170 /* #define GMP_DESC */
171
172 #endif /* LTC_NO_MATH */
173
174 /* ---> Symmetric Block Ciphers <--- */
175 #ifndef LTC_NO_CIPHERS
176
177 #if DROPBEAR_BLOWFISH
101 #define LTC_BLOWFISH 178 #define LTC_BLOWFISH
102 #endif 179 #endif
103 180 #if DROPBEAR_AES
104 #ifdef DROPBEAR_AES
105 #define LTC_RIJNDAEL 181 #define LTC_RIJNDAEL
106 #endif 182 #endif
107
108 #ifdef DROPBEAR_TWOFISH
109 #define LTC_TWOFISH
110
111 /* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format 183 /* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
112 * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */ 184 * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
113 /* enabling just TWOFISH_SMALL will make the binary ~1kB smaller, turning on 185 #if DROPBEAR_TWOFISH
114 * TWOFISH_TABLES will make it a few kB bigger, but perhaps reduces runtime 186 #define LTC_TWOFISH
115 * memory usage? */
116 #define LTC_TWOFISH_SMALL 187 #define LTC_TWOFISH_SMALL
117 /*#define LTC_TWOFISH_TABLES*/ 188 #endif
118 #endif 189
119 190 #if DROPBEAR_3DES
120 #ifdef DROPBEAR_3DES
121 #define LTC_DES 191 #define LTC_DES
122 #endif 192 #endif
123 193
194 /* stream ciphers */
195
196 #endif /* LTC_NO_CIPHERS */
197
198
199 /* ---> Block Cipher Modes of Operation <--- */
200 #ifndef LTC_NO_MODES
201
202 #if DROPBEAR_ENABLE_CTR_MODE
124 #define LTC_CBC_MODE 203 #define LTC_CBC_MODE
125 204 #endif
126 #ifdef DROPBEAR_ENABLE_CTR_MODE 205
206 #if DROPBEAR_ENABLE_CTR_MODE
127 #define LTC_CTR_MODE 207 #define LTC_CTR_MODE
128 #endif 208 #endif
129 209
210 #endif /* LTC_NO_MODES */
211
212 /* ---> One-Way Hash Functions <--- */
213 #ifndef LTC_NO_HASHES
214
215 #if DROPBEAR_SHA512
216 #define LTC_SHA512
217 #endif
218
219 #if DROPBEAR_SHA384
220 #define LTC_SHA384
221 #endif
222
223 #if DROPBEAR_SHA256
224 #define LTC_SHA256
225 #endif
226
130 #define LTC_SHA1 227 #define LTC_SHA1
131 228
132 #ifdef DROPBEAR_MD5 229 #if DROPBEAR_MD5
133 #define LTC_MD5 230 #define LTC_MD5
134 #endif 231 #endif
135 232
136 #ifdef DROPBEAR_SHA256 233 #endif /* LTC_NO_HASHES */
137 #define LTC_SHA256 234
138 #endif 235
139 #ifdef DROPBEAR_SHA384 236 /* ---> MAC functions <--- */
140 #define LTC_SHA384 237 #ifndef LTC_NO_MACS
141 #endif
142 #ifdef DROPBEAR_SHA512
143 #define LTC_SHA512
144 #endif
145 238
146 #define LTC_HMAC 239 #define LTC_HMAC
147 240
148 #ifdef DROPBEAR_ECC 241 /* ---> Encrypt + Authenticate Modes <--- */
242
243 /* Use 64KiB tables */
244 #ifndef LTC_NO_TABLES
245 #define LTC_GCM_TABLES
246 #endif
247
248 /* USE SSE2? requires GCC works on x86_32 and x86_64*/
249 #ifdef LTC_GCM_TABLES
250 /* #define LTC_GCM_TABLES_SSE2 */
251 #endif
252
253 #endif /* LTC_NO_MACS */
254
255
256 /* --> Pseudo Random Number Generators <--- */
257 #ifndef LTC_NO_PRNGS
258
259 /* try /dev/urandom before trying /dev/random
260 * are you sure you want to disable this? http://www.2uo.de/myths-about-urandom/ */
261 #define LTC_TRY_URANDOM_FIRST
262 /* rng_get_bytes() */
263 #define LTC_RNG_GET_BYTES
264 /* rng_make_prng() */
265 #define LTC_RNG_MAKE_PRNG
266
267 /* enable the ltc_rng hook to integrate e.g. embedded hardware RNG's easily */
268 /* #define LTC_PRNG_ENABLE_LTC_RNG */
269
270 #endif /* LTC_NO_PRNGS */
271
272 #ifdef LTC_YARROW
273
274 /* which descriptor of AES to use? */
275 /* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
276 #ifdef ENCRYPT_ONLY
277 #define LTC_YARROW_AES 0
278 #else
279 #define LTC_YARROW_AES 2
280 #endif
281
282 #endif
283
284 #ifdef LTC_FORTUNA
285
286 #ifndef LTC_FORTUNA_WD
287 /* reseed every N calls to the read function */
288 #define LTC_FORTUNA_WD 10
289 #endif
290
291 #ifndef LTC_FORTUNA_POOLS
292 /* number of pools (4..32) can save a bit of ram by lowering the count */
293 #define LTC_FORTUNA_POOLS 0
294 #endif
295
296 #endif /* LTC_FORTUNA */
297
298
299 /* ---> Public Key Crypto <--- */
300 #ifndef LTC_NO_PK
301
302 /* Include Katja (a Rabin variant like RSA) */
303 /* #define LTC_MKAT */
304
305 /* ECC */
306 #if DROPBEAR_ECC
149 #define LTC_MECC 307 #define LTC_MECC
308 #define LTM_DESC
309
310 /* use Shamir's trick for point mul (speeds up signature verification) */
150 #define LTC_ECC_SHAMIR 311 #define LTC_ECC_SHAMIR
312
313 #if DROPBEAR_ECC_256
314 #define ECC256
315 #endif
316 #if DROPBEAR_ECC_384
317 #define ECC384
318 #endif
319 #if DROPBEAR_ECC_521
320 #define ECC521
321 #endif
322
323 #endif /* DROPBEAR_ECC */
324
325 #if defined(TFM_DESC) && defined(LTC_MECC)
326 #define LTC_MECC_ACCEL
327 #endif
328
329 /* do we want fixed point ECC */
330 /* #define LTC_MECC_FP */
331
332 #endif /* LTC_NO_PK */
333
334 #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_BLINDING)
335 /* Enable RSA blinding when doing private key operations by default */
336 #define LTC_RSA_BLINDING
337 #endif /* LTC_NO_RSA_BLINDING */
338
339 #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_CRT_HARDENING)
340 /* Enable RSA CRT hardening when doing private key operations by default */
341 #define LTC_RSA_CRT_HARDENING
342 #endif /* LTC_NO_RSA_CRT_HARDENING */
343
344 #if defined(LTC_MECC) && !defined(LTC_NO_ECC_TIMING_RESISTANT)
345 /* Enable ECC timing resistant version by default */
151 #define LTC_ECC_TIMING_RESISTANT 346 #define LTC_ECC_TIMING_RESISTANT
152 #define MPI 347 #endif
153 #define LTM_DESC 348
154 #ifdef DROPBEAR_ECC_256 349 /* PKCS #1 (RSA) and #5 (Password Handling) stuff */
155 #define ECC256 350 #ifndef LTC_NO_PKCS
156 #endif 351
157 #ifdef DROPBEAR_ECC_384 352 #define LTC_PKCS_1
158 #define ECC384 353 #define LTC_PKCS_5
159 #endif 354
160 #ifdef DROPBEAR_ECC_521 355 /* Include ASN.1 DER (required by DSA/RSA) */
161 #define ECC521 356 #define LTC_DER
162 #endif 357
163 #endif 358 #endif /* LTC_NO_PKCS */
359
360 /* misc stuff */
361 #ifndef LTC_NO_MISC
164 362
165 /* Various tidbits of modern neatoness */ 363 /* Various tidbits of modern neatoness */
166 #define LTC_BASE64 364 #define LTC_BASE64
167 365
168 /* default no pthread functions */ 366 /* Keep LTC_NO_HKDF for compatibility reasons
367 * superseeded by LTC_NO_MISC*/
368 #ifndef LTC_NO_HKDF
369 /* HKDF Key Derivation/Expansion stuff */
370 #define LTC_HKDF
371 #endif /* LTC_NO_HKDF */
372
373 #define LTC_ADLER32
374
375 #define LTC_CRC32
376
377 #endif /* LTC_NO_MISC */
378
379 /* cleanup */
380
381 #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_MKAT)
382 /* Include the MPI functionality? (required by the PK algorithms) */
383 #define LTC_MPI
384
385 #ifndef LTC_PK_MAX_RETRIES
386 /* iterations limit for retry-loops */
387 #define LTC_PK_MAX_RETRIES 20
388 #endif
389 #endif
390
391 #ifdef LTC_MRSA
392 #define LTC_PKCS_1
393 #endif
394
395 #if defined(LTC_PELICAN) && !defined(LTC_RIJNDAEL)
396 #error Pelican-MAC requires LTC_RIJNDAEL
397 #endif
398
399 #if defined(LTC_EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(LTC_OMAC))
400 #error LTC_EAX_MODE requires CTR and LTC_OMAC mode
401 #endif
402
403 #if defined(LTC_YARROW) && !defined(LTC_CTR_MODE)
404 #error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined!
405 #endif
406
407 #if defined(LTC_DER) && !defined(LTC_MPI)
408 #error ASN.1 DER requires MPI functionality
409 #endif
410
411 #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC) || defined(LTC_MKAT)) && !defined(LTC_DER)
412 #error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
413 #endif
414
415 #if defined(LTC_CHACHA20POLY1305_MODE) && (!defined(LTC_CHACHA) || !defined(LTC_POLY1305))
416 #error LTC_CHACHA20POLY1305_MODE requires LTC_CHACHA + LTC_POLY1305
417 #endif
418
419 #if defined(LTC_CHACHA20_PRNG) && !defined(LTC_CHACHA)
420 #error LTC_CHACHA20_PRNG requires LTC_CHACHA
421 #endif
422
423 #if defined(LTC_RC4) && !defined(LTC_RC4_STREAM)
424 #error LTC_RC4 requires LTC_RC4_STREAM
425 #endif
426
427 #if defined(LTC_SOBER128) && !defined(LTC_SOBER128_STREAM)
428 #error LTC_SOBER128 requires LTC_SOBER128_STREAM
429 #endif
430
431 #if defined(LTC_BLAKE2SMAC) && !defined(LTC_BLAKE2S)
432 #error LTC_BLAKE2SMAC requires LTC_BLAKE2S
433 #endif
434
435 #if defined(LTC_BLAKE2BMAC) && !defined(LTC_BLAKE2B)
436 #error LTC_BLAKE2BMAC requires LTC_BLAKE2B
437 #endif
438
439 #if defined(LTC_SPRNG) && !defined(LTC_RNG_GET_BYTES)
440 #error LTC_SPRNG requires LTC_RNG_GET_BYTES
441 #endif
442
443 #if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC))
444 #error LTC_NO_MATH defined, but also a math descriptor
445 #endif
446
447 /* THREAD management */
448 #ifdef LTC_PTHREAD
449
450 #include <pthread.h>
451
452 #define LTC_MUTEX_GLOBAL(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
453 #define LTC_MUTEX_PROTO(x) extern pthread_mutex_t x;
454 #define LTC_MUTEX_TYPE(x) pthread_mutex_t x;
455 #define LTC_MUTEX_INIT(x) LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0);
456 #define LTC_MUTEX_LOCK(x) LTC_ARGCHK(pthread_mutex_lock(x) == 0);
457 #define LTC_MUTEX_UNLOCK(x) LTC_ARGCHK(pthread_mutex_unlock(x) == 0);
458 #define LTC_MUTEX_DESTROY(x) LTC_ARGCHK(pthread_mutex_destroy(x) == 0);
459
460 #else
461
462 /* default no functions */
169 #define LTC_MUTEX_GLOBAL(x) 463 #define LTC_MUTEX_GLOBAL(x)
170 #define LTC_MUTEX_PROTO(x) 464 #define LTC_MUTEX_PROTO(x)
171 #define LTC_MUTEX_TYPE(x) 465 #define LTC_MUTEX_TYPE(x)
172 #define LTC_MUTEX_INIT(x) 466 #define LTC_MUTEX_INIT(x)
173 #define LTC_MUTEX_LOCK(x) 467 #define LTC_MUTEX_LOCK(x)
174 #define LTC_MUTEX_UNLOCK(x) 468 #define LTC_MUTEX_UNLOCK(x)
175 #define FORTUNA_POOLS 0 469 #define LTC_MUTEX_DESTROY(x)
470
471 #endif
176 472
177 /* Debuggers */ 473 /* Debuggers */
178 474
179 /* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and LTC_RC4 work (see the code) */ 475 /* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */
180 /* #define LTC_VALGRIND */ 476 /* #define LTC_VALGRIND */
181 477
182 #endif 478 #endif
183 479
184 480 #ifndef LTC_NO_FILE
185 481 /* buffer size for reading from a file via fread(..) */
186 /* $Source$ */ 482 #ifndef LTC_FILE_READ_BUFSIZE
187 /* $Revision$ */ 483 #define LTC_FILE_READ_BUFSIZE 8192
188 /* $Date$ */ 484 #endif
485 #endif
486
487 /* ref: $Format:%D$ */
488 /* git commit: $Format:%H$ */
489 /* commit time: $Format:%ai$ */