Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/tomcrypt/src/headers/tomcrypt_custom.h
5971 views
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
10
#ifndef TOMCRYPT_CUSTOM_H_
11
#define TOMCRYPT_CUSTOM_H_
12
13
/* macros for various libc functions you can change for embedded targets */
14
#ifndef XMALLOC
15
#define XMALLOC malloc
16
#endif
17
#ifndef XREALLOC
18
#define XREALLOC realloc
19
#endif
20
#ifndef XCALLOC
21
#define XCALLOC calloc
22
#endif
23
#ifndef XFREE
24
#define XFREE free
25
#endif
26
27
#ifndef XMEMSET
28
#define XMEMSET memset
29
#endif
30
#ifndef XMEMCPY
31
#define XMEMCPY memcpy
32
#endif
33
#ifndef XMEMMOVE
34
#define XMEMMOVE memmove
35
#endif
36
#ifndef XMEMCMP
37
#define XMEMCMP memcmp
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
45
#ifndef XSTRCMP
46
#define XSTRCMP strcmp
47
#endif
48
49
#ifndef XCLOCK
50
#define XCLOCK clock
51
#endif
52
53
#ifndef XQSORT
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
101
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
110
#define LTC_NO_PK
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
/* #define LTC_SMALL_CODE */
142
143
/* clean the stack of functions which put private information on stack */
144
/* #define LTC_CLEAN_STACK */
145
146
/* disable all file related functions */
147
#define LTC_NO_FILE
148
149
/* disable all forms of ASM */
150
/* #define LTC_NO_ASM */
151
152
/* disable FAST mode */
153
/* #define LTC_NO_FAST */
154
155
/* disable BSWAP on x86 */
156
/* #define LTC_NO_BSWAP */
157
158
/* ---> math provider? <--- */
159
#ifndef LTC_NO_MATH
160
161
/* LibTomMath */
162
#define LTM_DESC
163
164
/* TomsFastMath */
165
/* #define TFM_DESC */
166
167
/* GNU Multiple Precision Arithmetic Library */
168
/* #define GMP_DESC */
169
170
#endif /* LTC_NO_MATH */
171
172
/* ---> Symmetric Block Ciphers <--- */
173
#ifndef LTC_NO_CIPHERS
174
175
#define LTC_BLOWFISH
176
#define LTC_RC2
177
#define LTC_RC5
178
#define LTC_RC6
179
#define LTC_SAFERP
180
#define LTC_RIJNDAEL
181
#define LTC_XTEA
182
/* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
183
* (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
184
#define LTC_TWOFISH
185
#ifndef LTC_NO_TABLES
186
#define LTC_TWOFISH_TABLES
187
/* #define LTC_TWOFISH_ALL_TABLES */
188
#else
189
#define LTC_TWOFISH_SMALL
190
#endif
191
/* #define LTC_TWOFISH_SMALL */
192
/* LTC_DES includes EDE triple-DES */
193
#define LTC_DES
194
#define LTC_CAST5
195
#define LTC_NOEKEON
196
#define LTC_SKIPJACK
197
#define LTC_SAFER
198
#define LTC_KHAZAD
199
#define LTC_ANUBIS
200
#define LTC_ANUBIS_TWEAK
201
#define LTC_KSEED
202
#define LTC_KASUMI
203
#define LTC_MULTI2
204
#define LTC_CAMELLIA
205
206
/* stream ciphers */
207
#define LTC_CHACHA
208
#define LTC_RC4_STREAM
209
#define LTC_SOBER128_STREAM
210
211
#endif /* LTC_NO_CIPHERS */
212
213
214
/* ---> Block Cipher Modes of Operation <--- */
215
#ifndef LTC_NO_MODES
216
217
#define LTC_CFB_MODE
218
#define LTC_OFB_MODE
219
#define LTC_ECB_MODE
220
#define LTC_CBC_MODE
221
#define LTC_CTR_MODE
222
223
/* F8 chaining mode */
224
#define LTC_F8_MODE
225
226
/* LRW mode */
227
#define LTC_LRW_MODE
228
#ifndef LTC_NO_TABLES
229
/* like GCM mode this will enable 16 8x128 tables [64KB] that make
230
* seeking very fast.
231
*/
232
#define LTC_LRW_TABLES
233
#endif
234
235
/* XTS mode */
236
#define LTC_XTS_MODE
237
238
#endif /* LTC_NO_MODES */
239
240
/* ---> One-Way Hash Functions <--- */
241
#ifndef LTC_NO_HASHES
242
243
#define LTC_CHC_HASH
244
#define LTC_WHIRLPOOL
245
#define LTC_SHA3
246
#define LTC_SHA512
247
#define LTC_SHA512_256
248
#define LTC_SHA512_224
249
#define LTC_SHA384
250
#define LTC_SHA256
251
#define LTC_SHA224
252
#define LTC_TIGER
253
#define LTC_SHA1
254
#define LTC_MD5
255
#define LTC_MD4
256
#define LTC_MD2
257
#define LTC_RIPEMD128
258
#define LTC_RIPEMD160
259
#define LTC_RIPEMD256
260
#define LTC_RIPEMD320
261
#define LTC_BLAKE2S
262
#define LTC_BLAKE2B
263
264
#define LTC_HASH_HELPERS
265
266
#endif /* LTC_NO_HASHES */
267
268
269
/* ---> MAC functions <--- */
270
#ifndef LTC_NO_MACS
271
272
#define LTC_HMAC
273
#define LTC_OMAC
274
#define LTC_PMAC
275
#define LTC_XCBC
276
#define LTC_F9_MODE
277
#define LTC_PELICAN
278
#define LTC_POLY1305
279
#define LTC_BLAKE2SMAC
280
#define LTC_BLAKE2BMAC
281
282
/* ---> Encrypt + Authenticate Modes <--- */
283
284
#define LTC_EAX_MODE
285
286
#define LTC_OCB_MODE
287
#define LTC_OCB3_MODE
288
#define LTC_CCM_MODE
289
#define LTC_GCM_MODE
290
#define LTC_CHACHA20POLY1305_MODE
291
292
/* Use 64KiB tables */
293
#ifndef LTC_NO_TABLES
294
#define LTC_GCM_TABLES
295
#endif
296
297
/* USE SSE2? requires GCC works on x86_32 and x86_64*/
298
#ifdef LTC_GCM_TABLES
299
/* #define LTC_GCM_TABLES_SSE2 */
300
#endif
301
302
#endif /* LTC_NO_MACS */
303
304
305
/* --> Pseudo Random Number Generators <--- */
306
#ifndef LTC_NO_PRNGS
307
308
/* Yarrow */
309
#define LTC_YARROW
310
311
/* a PRNG that simply reads from an available system source */
312
#define LTC_SPRNG
313
314
/* The RC4 stream cipher based PRNG */
315
#define LTC_RC4
316
317
/* The ChaCha20 stream cipher based PRNG */
318
#define LTC_CHACHA20_PRNG
319
320
/* Fortuna PRNG */
321
#define LTC_FORTUNA
322
323
/* Greg's SOBER128 stream cipher based PRNG */
324
#define LTC_SOBER128
325
326
/* the *nix style /dev/random device */
327
#define LTC_DEVRANDOM
328
/* try /dev/urandom before trying /dev/random
329
* are you sure you want to disable this? http://www.2uo.de/myths-about-urandom/ */
330
#define LTC_TRY_URANDOM_FIRST
331
/* rng_get_bytes() */
332
#define LTC_RNG_GET_BYTES
333
/* rng_make_prng() */
334
#define LTC_RNG_MAKE_PRNG
335
336
/* enable the ltc_rng hook to integrate e.g. embedded hardware RNG's easily */
337
/* #define LTC_PRNG_ENABLE_LTC_RNG */
338
339
#endif /* LTC_NO_PRNGS */
340
341
#ifdef LTC_YARROW
342
343
/* which descriptor of AES to use? */
344
/* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
345
#ifdef ENCRYPT_ONLY
346
#define LTC_YARROW_AES 0
347
#else
348
#define LTC_YARROW_AES 2
349
#endif
350
351
#endif
352
353
#ifdef LTC_FORTUNA
354
355
#ifndef LTC_FORTUNA_WD
356
/* reseed every N calls to the read function */
357
#define LTC_FORTUNA_WD 10
358
#endif
359
360
#ifndef LTC_FORTUNA_POOLS
361
/* number of pools (4..32) can save a bit of ram by lowering the count */
362
#define LTC_FORTUNA_POOLS 32
363
#endif
364
365
#endif /* LTC_FORTUNA */
366
367
368
/* ---> Public Key Crypto <--- */
369
#ifndef LTC_NO_PK
370
371
/* Include RSA support */
372
#define LTC_MRSA
373
374
/* Include Diffie-Hellman support */
375
/* is_prime fails for GMP */
376
#define LTC_MDH
377
/* Supported Key Sizes */
378
#define LTC_DH768
379
#define LTC_DH1024
380
#define LTC_DH1536
381
#define LTC_DH2048
382
383
#ifndef TFM_DESC
384
/* tfm has a problem in fp_isprime for larger key sizes */
385
#define LTC_DH3072
386
#define LTC_DH4096
387
#define LTC_DH6144
388
#define LTC_DH8192
389
#endif
390
391
/* Include Katja (a Rabin variant like RSA) */
392
/* #define LTC_MKAT */
393
394
/* Digital Signature Algorithm */
395
#define LTC_MDSA
396
397
/* ECC */
398
#define LTC_MECC
399
400
/* use Shamir's trick for point mul (speeds up signature verification) */
401
#define LTC_ECC_SHAMIR
402
403
#if defined(TFM_DESC) && defined(LTC_MECC)
404
#define LTC_MECC_ACCEL
405
#endif
406
407
/* do we want fixed point ECC */
408
/* #define LTC_MECC_FP */
409
410
#endif /* LTC_NO_PK */
411
412
#if defined(LTC_MRSA) && !defined(LTC_NO_RSA_BLINDING)
413
/* Enable RSA blinding when doing private key operations by default */
414
#define LTC_RSA_BLINDING
415
#endif /* LTC_NO_RSA_BLINDING */
416
417
#if defined(LTC_MRSA) && !defined(LTC_NO_RSA_CRT_HARDENING)
418
/* Enable RSA CRT hardening when doing private key operations by default */
419
#define LTC_RSA_CRT_HARDENING
420
#endif /* LTC_NO_RSA_CRT_HARDENING */
421
422
#if defined(LTC_MECC) && !defined(LTC_NO_ECC_TIMING_RESISTANT)
423
/* Enable ECC timing resistant version by default */
424
#define LTC_ECC_TIMING_RESISTANT
425
#endif
426
427
/* PKCS #1 (RSA) and #5 (Password Handling) stuff */
428
#ifndef LTC_NO_PKCS
429
430
#define LTC_PKCS_1
431
#define LTC_PKCS_5
432
433
/* Include ASN.1 DER (required by DSA/RSA) */
434
#define LTC_DER
435
436
#endif /* LTC_NO_PKCS */
437
438
/* misc stuff */
439
#ifndef LTC_NO_MISC
440
441
/* Various tidbits of modern neatoness */
442
#define LTC_BASE64
443
/* ... and it's URL safe version */
444
#define LTC_BASE64_URL
445
446
/* Keep LTC_NO_HKDF for compatibility reasons
447
* superseeded by LTC_NO_MISC*/
448
#ifndef LTC_NO_HKDF
449
/* HKDF Key Derivation/Expansion stuff */
450
#define LTC_HKDF
451
#endif /* LTC_NO_HKDF */
452
453
#define LTC_ADLER32
454
455
#define LTC_CRC32
456
457
#endif /* LTC_NO_MISC */
458
459
/* cleanup */
460
461
#ifdef LTC_MECC
462
/* Supported ECC Key Sizes */
463
#ifndef LTC_NO_CURVES
464
#define LTC_ECC112
465
#define LTC_ECC128
466
#define LTC_ECC160
467
#define LTC_ECC192
468
#define LTC_ECC224
469
#define LTC_ECC256
470
#define LTC_ECC384
471
#define LTC_ECC521
472
#endif
473
#endif
474
475
#if defined(LTC_DER)
476
#ifndef LTC_DER_MAX_RECURSION
477
/* Maximum recursion limit when processing nested ASN.1 types. */
478
#define LTC_DER_MAX_RECURSION 30
479
#endif
480
#endif
481
482
#if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_MKAT)
483
/* Include the MPI functionality? (required by the PK algorithms) */
484
#define LTC_MPI
485
486
#ifndef LTC_PK_MAX_RETRIES
487
/* iterations limit for retry-loops */
488
#define LTC_PK_MAX_RETRIES 20
489
#endif
490
#endif
491
492
#ifdef LTC_MRSA
493
#define LTC_PKCS_1
494
#endif
495
496
#if defined(LTC_PELICAN) && !defined(LTC_RIJNDAEL)
497
#error Pelican-MAC requires LTC_RIJNDAEL
498
#endif
499
500
#if defined(LTC_EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(LTC_OMAC))
501
#error LTC_EAX_MODE requires CTR and LTC_OMAC mode
502
#endif
503
504
#if defined(LTC_YARROW) && !defined(LTC_CTR_MODE)
505
#error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined!
506
#endif
507
508
#if defined(LTC_DER) && !defined(LTC_MPI)
509
#error ASN.1 DER requires MPI functionality
510
#endif
511
512
#if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC) || defined(LTC_MKAT)) && !defined(LTC_DER)
513
#error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
514
#endif
515
516
#if defined(LTC_CHACHA20POLY1305_MODE) && (!defined(LTC_CHACHA) || !defined(LTC_POLY1305))
517
#error LTC_CHACHA20POLY1305_MODE requires LTC_CHACHA + LTC_POLY1305
518
#endif
519
520
#if defined(LTC_CHACHA20_PRNG) && !defined(LTC_CHACHA)
521
#error LTC_CHACHA20_PRNG requires LTC_CHACHA
522
#endif
523
524
#if defined(LTC_RC4) && !defined(LTC_RC4_STREAM)
525
#error LTC_RC4 requires LTC_RC4_STREAM
526
#endif
527
528
#if defined(LTC_SOBER128) && !defined(LTC_SOBER128_STREAM)
529
#error LTC_SOBER128 requires LTC_SOBER128_STREAM
530
#endif
531
532
#if defined(LTC_BLAKE2SMAC) && !defined(LTC_BLAKE2S)
533
#error LTC_BLAKE2SMAC requires LTC_BLAKE2S
534
#endif
535
536
#if defined(LTC_BLAKE2BMAC) && !defined(LTC_BLAKE2B)
537
#error LTC_BLAKE2BMAC requires LTC_BLAKE2B
538
#endif
539
540
#if defined(LTC_SPRNG) && !defined(LTC_RNG_GET_BYTES)
541
#error LTC_SPRNG requires LTC_RNG_GET_BYTES
542
#endif
543
544
#if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC))
545
#error LTC_NO_MATH defined, but also a math descriptor
546
#endif
547
548
/* THREAD management */
549
#ifdef LTC_PTHREAD
550
551
#include <pthread.h>
552
553
#define LTC_MUTEX_GLOBAL(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
554
#define LTC_MUTEX_PROTO(x) extern pthread_mutex_t x;
555
#define LTC_MUTEX_TYPE(x) pthread_mutex_t x;
556
#define LTC_MUTEX_INIT(x) LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0);
557
#define LTC_MUTEX_LOCK(x) LTC_ARGCHK(pthread_mutex_lock(x) == 0);
558
#define LTC_MUTEX_UNLOCK(x) LTC_ARGCHK(pthread_mutex_unlock(x) == 0);
559
#define LTC_MUTEX_DESTROY(x) LTC_ARGCHK(pthread_mutex_destroy(x) == 0);
560
561
#else
562
563
/* default no functions */
564
#define LTC_MUTEX_GLOBAL(x)
565
#define LTC_MUTEX_PROTO(x)
566
#define LTC_MUTEX_TYPE(x)
567
#define LTC_MUTEX_INIT(x)
568
#define LTC_MUTEX_LOCK(x)
569
#define LTC_MUTEX_UNLOCK(x)
570
#define LTC_MUTEX_DESTROY(x)
571
572
#endif
573
574
/* Debuggers */
575
576
/* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */
577
/* #define LTC_VALGRIND */
578
579
#endif
580
581
#ifndef LTC_NO_FILE
582
/* buffer size for reading from a file via fread(..) */
583
#ifndef LTC_FILE_READ_BUFSIZE
584
#define LTC_FILE_READ_BUFSIZE 8192
585
#endif
586
#endif
587
588