Signed-off-by: Steffen Jaeckel <[email protected]>
@@ -726,5 +726,11 @@ int ECB_KS(int *keysize)
return CRYPT_OK;
}
-#endif
+#undef SETUP
+#undef ECB_ENC
+#undef ECB_DEC
+#undef ECB_DONE
+#undef ECB_TEST
+#undef ECB_KS
+#endif
@@ -26,6 +26,14 @@ const struct ltc_cipher_descriptor anubis_desc = {
#define MAX_N 10
+
+#define T0 anubis_T0
+#define T1 anubis_T1
+#define T2 anubis_T2
+#define T3 anubis_T3
+#define T4 anubis_T4
+#define T5 anubis_T5
+#define rc anubis_rc
/*
* Though Anubis is endianness-neutral, the encryption tables are listed
* in BIG-ENDIAN format, which is adopted throughout this implementation
@@ -1546,5 +1554,14 @@ int anubis_keysize(int *keysize)
+#undef MAX_N
+#undef T0
+#undef T1
+#undef T2
+#undef T3
+#undef T4
+#undef T5
+#undef rc
#endif
@@ -654,5 +654,7 @@ int blowfish_keysize(int *keysize)
+#undef F
@@ -717,4 +717,6 @@ int camellia_keysize(int *keysize)
+#undef loc
@@ -491,6 +491,7 @@ int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
+#define FI cast5_FI
LTC_INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
{
ulong32 I;
@@ -702,4 +703,7 @@ int cast5_keysize(int *keysize)
+#undef GB
+#undef FI
@@ -2238,5 +2238,8 @@ int des3_keysize(int *keysize)
+#undef EN0
+#undef DE1
@@ -66,6 +66,7 @@ static ushort16 s_add_inv(ushort16 x)
return LOW16(0 - x);
+#define s_setup_key s_idea_setup_key
static int s_setup_key(const unsigned char *key, symmetric_key *skey)
int i, j;
@@ -247,4 +248,11 @@ int idea_test(void)
+#undef LOW16
+#undef HIGH16
+#undef MUL
+#undef STORE16
+#undef LOAD16
+#undef s_setup_key
@@ -28,6 +28,7 @@ const struct ltc_cipher_descriptor kasumi_desc = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
+#define FI kasumi_FI
static u16 FI( u16 in, u16 subkey )
u16 nine, seven;
@@ -304,4 +305,7 @@ int kasumi_test(void)
+#undef ROL16
@@ -837,4 +837,6 @@ int khazad_keysize(int *keysize)
return CRYPT_INVALID_KEYSIZE;
+#undef R
@@ -363,4 +363,7 @@ int kseed_keysize(int *keysize)
+#undef G
@@ -313,5 +313,12 @@ int noekeon_keysize(int *keysize)
+#undef kTHETA
+#undef THETA
+#undef GAMMA
+#undef PI1
+#undef PI2
+#undef ROUND
@@ -24,6 +24,7 @@ const struct ltc_cipher_descriptor rc5_desc =
+#define stab rc5_stab
static const ulong32 stab[50] = {
0xb7e15163UL, 0x5618cb1cUL, 0xf45044d5UL, 0x9287be8eUL, 0x30bf3847UL, 0xcef6b200UL, 0x6d2e2bb9UL, 0x0b65a572UL,
0xa99d1f2bUL, 0x47d498e4UL, 0xe60c129dUL, 0x84438c56UL, 0x227b060fUL, 0xc0b27fc8UL, 0x5ee9f981UL, 0xfd21733aUL,
@@ -317,6 +318,8 @@ int rc5_keysize(int *keysize)
+#undef stab
@@ -23,6 +23,7 @@ const struct ltc_cipher_descriptor rc6_desc =
+#define stab rc6_stab
static const ulong32 stab[44] = {
@@ -319,6 +320,7 @@ int rc6_keysize(int *keysize)
-#endif /*LTC_RC6*/
-
+#undef RND
+#endif /*LTC_RC6*/
@@ -24,8 +24,10 @@
#ifdef LTC_SAFER
+#ifndef LTC_SAFER_TAB_C
#define LTC_SAFER_TAB_C
#include "safer_tab.c"
const struct ltc_cipher_descriptor safer_k64_desc = {
"safer-k64",
@@ -478,7 +480,10 @@ int safer_sk128_test(void)
+#undef ROL8
+#undef EXP
+#undef LOG
+#undef PHT
+#undef IPHT
@@ -9,8 +9,10 @@
#ifdef LTC_SAFERP
const struct ltc_cipher_descriptor saferp_desc =
@@ -562,6 +564,13 @@ int saferp_keysize(int *keysize)
+#undef iROUND
+#undef iPHT
+#undef SHUF
+#undef iSHUF
+#undef LT
+#undef iLT
@@ -443,6 +443,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
k[(8-r)*4 + 7] = d; \
+#define s_setup_key s_serpent_setup_key
static int s_setup_key(const unsigned char *key, int keylen, int rounds, ulong32 *k)
int i;
@@ -714,4 +715,45 @@ int serpent_test(void)
+#undef s_lt
+#undef s_ilt
+#undef s_beforeS0
+#undef s_afterS0
+#undef s_afterS1
+#undef s_afterS2
+#undef s_afterS3
+#undef s_afterS4
+#undef s_afterS5
+#undef s_afterS6
+#undef s_afterS7
+#undef s_beforeI7
+#undef s_afterI7
+#undef s_afterI6
+#undef s_afterI5
+#undef s_afterI4
+#undef s_afterI3
+#undef s_afterI2
+#undef s_afterI1
+#undef s_afterI0
+#undef s_s0
+#undef s_i0
+#undef s_s1
+#undef s_i1
+#undef s_s2
+#undef s_i2
+#undef s_s3
+#undef s_i3
+#undef s_s4
+#undef s_i4
+#undef s_s5
+#undef s_i5
+#undef s_s6
+#undef s_i6
+#undef s_s7
+#undef s_i7
+#undef s_kx
+#undef s_lk
+#undef s_sk
@@ -331,4 +331,9 @@ int skipjack_keysize(int *keysize)
+#undef RULE_A
+#undef RULE_B
+#undef RULE_A1
+#undef RULE_B1
@@ -205,5 +205,8 @@ int tea_keysize(int *keysize)
+#undef DELTA
+#undef SUM
@@ -702,5 +702,16 @@ int twofish_keysize(int *keysize)
+#undef MDS_POLY
+#undef RS_POLY
+#undef sbox
+#undef mds_column_mult
+#undef S1
+#undef S2
+#undef S3
+#undef S4
+#undef g_func
+#undef g1_func
@@ -203,6 +203,10 @@ void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *
+#undef M
+#undef BPD
+#undef WPV
@@ -9,6 +9,7 @@
#ifdef LTC_OCB_MODE
+#define polys ocb_polys
static const struct {
int len;
unsigned char poly_div[MAXBLOCKSIZE],
@@ -126,4 +127,6 @@ int ocb_init(ocb_state *ocb, int cipher,
+#undef polys
@@ -54,6 +54,7 @@ static void s_ocb3_int_calc_offset_zero(ocb3_state *ocb, const unsigned char *no
+#define polys ocb3_polys
unsigned char poly_mul[MAXBLOCKSIZE];
@@ -183,4 +184,6 @@ int ocb3_init(ocb3_state *ocb, int cipher,
@@ -32,18 +32,18 @@ enum blake2b_constant {
/* param offsets */
enum {
- O_DIGEST_LENGTH = 0,
- O_KEY_LENGTH = 1,
- O_FANOUT = 2,
- O_DEPTH = 3,
- O_LEAF_LENGTH = 4,
- O_NODE_OFFSET = 8,
- O_XOF_LENGTH = 12,
- O_NODE_DEPTH = 16,
- O_INNER_LENGTH = 17,
- O_RESERVED = 18,
- O_SALT = 32,
- O_PERSONAL = 48
+ BLAKE2B_O_DIGEST_LENGTH = 0,
+ BLAKE2B_O_KEY_LENGTH = 1,
+ BLAKE2B_O_FANOUT = 2,
+ BLAKE2B_O_DEPTH = 3,
+ BLAKE2B_O_LEAF_LENGTH = 4,
+ BLAKE2B_O_NODE_OFFSET = 8,
+ BLAKE2B_O_XOF_LENGTH = 12,
+ BLAKE2B_O_NODE_DEPTH = 16,
+ BLAKE2B_O_INNER_LENGTH = 17,
+ BLAKE2B_O_RESERVED = 18,
+ BLAKE2B_O_SALT = 32,
+ BLAKE2B_O_PERSONAL = 48
@@ -190,7 +190,7 @@ static int s_blake2b_init_param(hash_state *md, const unsigned char *P)
md->blake2b.h[i] ^= tmp;
- md->blake2b.outlen = P[O_DIGEST_LENGTH];
+ md->blake2b.outlen = P[BLAKE2B_O_DIGEST_LENGTH];
@@ -223,10 +223,10 @@ int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key,
XMEMSET(P, 0, sizeof(P));
- P[O_DIGEST_LENGTH] = (unsigned char)outlen;
- P[O_KEY_LENGTH] = (unsigned char)keylen;
- P[O_FANOUT] = 1;
- P[O_DEPTH] = 1;
+ P[BLAKE2B_O_DIGEST_LENGTH] = (unsigned char)outlen;
+ P[BLAKE2B_O_KEY_LENGTH] = (unsigned char)keylen;
+ P[BLAKE2B_O_FANOUT] = 1;
+ P[BLAKE2B_O_DEPTH] = 1;
err = s_blake2b_init_param(md, P);
if (err != CRYPT_OK) return err;
@@ -32,17 +32,17 @@ enum blake2s_constant {
- O_NODE_DEPTH = 14,
- O_INNER_LENGTH = 15,
- O_SALT = 16,
- O_PERSONAL = 24
+ BLAKE2S_O_DIGEST_LENGTH = 0,
+ BLAKE2S_O_KEY_LENGTH = 1,
+ BLAKE2S_O_FANOUT = 2,
+ BLAKE2S_O_DEPTH = 3,
+ BLAKE2S_O_LEAF_LENGTH = 4,
+ BLAKE2S_O_NODE_OFFSET = 8,
+ BLAKE2S_O_XOF_LENGTH = 12,
+ BLAKE2S_O_NODE_DEPTH = 14,
+ BLAKE2S_O_INNER_LENGTH = 15,
+ BLAKE2S_O_SALT = 16,
+ BLAKE2S_O_PERSONAL = 24
@@ -184,7 +184,7 @@ static int s_blake2s_init_param(hash_state *md, const unsigned char *P)
md->blake2s.h[i] ^= tmp;
- md->blake2s.outlen = P[O_DIGEST_LENGTH];
+ md->blake2s.outlen = P[BLAKE2S_O_DIGEST_LENGTH];
@@ -217,10 +217,10 @@ int blake2s_init(hash_state *md, unsigned long outlen, const unsigned char *key,
+ P[BLAKE2S_O_DIGEST_LENGTH] = (unsigned char)outlen;
+ P[BLAKE2S_O_KEY_LENGTH] = (unsigned char)keylen;
+ P[BLAKE2S_O_FANOUT] = 1;
+ P[BLAKE2S_O_DEPTH] = 1;
err = s_blake2s_init_param(md, P);
@@ -291,6 +291,26 @@ int md4_test(void)
+#undef H
+#undef FF
+#undef GG
+#undef HH
+#undef S11
+#undef S12
+#undef S13
+#undef S14
+#undef S21
+#undef S22
+#undef S23
+#undef S24
+#undef S31
+#undef S32
+#undef S33
+#undef S34
+#undef ROTATE_LEFT
@@ -351,6 +351,13 @@ int md5_test(void)
+#undef I
+#undef II
@@ -392,5 +392,17 @@ int rmd128_test(void)
+#undef FFF
+#undef GGG
+#undef HHH
+#undef III
@@ -451,5 +451,20 @@ int rmd160_test(void)
+#undef J
+#undef JJ
+#undef JJJ
@@ -417,4 +417,17 @@ int rmd256_test(void)
@@ -482,4 +482,20 @@ int rmd320_test(void)
@@ -271,6 +271,15 @@ int sha1_test(void)
+#undef F0
+#undef F1
+#undef F2
+#undef F3
+#undef FF0
+#undef FF1
+#undef FF2
+#undef FF3
@@ -317,6 +317,15 @@ int sha256_test(void)
+#undef Ch
+#undef Maj
+#undef S
+#undef Sigma0
+#undef Sigma1
+#undef Gamma0
+#undef Gamma1
@@ -297,7 +297,13 @@ int sha512_test(void)
@@ -888,6 +888,11 @@ int tiger2_test(void)
return s_tiger_test(1);
+#undef t1
+#undef t2
+#undef t3
+#undef t4
@@ -291,6 +291,8 @@ int whirlpool_test(void)
+#undef theta_pi_gamma
@@ -9,10 +9,12 @@
#ifdef LTC_PELICAN
+#ifndef LTC_AES_TAB_C
#define LTC_AES_TAB_C
#define ENCRYPT_ONLY
#define PELI_TAB
#include "../../ciphers/aes/aes_tab.c"
/**
Initialize a Pelican state
#ifdef LTC_PMAC
+#define polys pmac_polys
@@ -135,4 +136,6 @@ error:
return err;
@@ -9,6 +9,8 @@
#ifdef LTC_CFB_MODE
+#ifndef LTC_CFB_SHIFT1LEFT
+#define LTC_CFB_SHIFT1LEFT
static LTC_INLINE void s_shift1left_64(unsigned char *b, unsigned char v)
ulong64 bval;
@@ -30,6 +32,7 @@ static LTC_INLINE void s_shift1left_128(unsigned char *b, unsigned char v)
STORE64H(bval[0], b);
STORE64H(bval[1], b + 8);
+#endif /* LTC_CFB_SHIFT1LEFT */
CFB decrypt
CFB encrypt
@@ -10,7 +10,9 @@
#ifdef LTC_DER
-static int s_char_to_int(unsigned char x)
+#ifndef LTC_DER_CHAR_TO_INT
+#define LTC_DER_CHAR_TO_INT
+static LTC_INLINE int s_char_to_int(unsigned char x)
switch (x) {
case '0': return 0;
@@ -26,6 +28,7 @@ static int s_char_to_int(unsigned char x)
default: return 100;
#define DECODE_V(y, max) do {\
y = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
@@ -132,4 +135,7 @@ YYYYMMDDhhmmss.fs-hh'mm'
return CRYPT_INVALID_PACKET;
+#undef DECODE_V
+#undef DECODE_V4
@@ -10,8 +10,6 @@
-static const char * const baseten = "0123456789";
#define STORE_V(y) do {\
out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
out[x++] = der_ia5_char_encode(baseten[y % 10]); \
@@ -34,6 +32,7 @@ static const char * const baseten = "0123456789";
int der_encode_generalizedtime(const ltc_generalizedtime *gtime,
unsigned char *out, unsigned long *outlen)
+ const char * const baseten = "0123456789";
unsigned long x, tmplen;
int err;
@@ -95,4 +94,7 @@ int der_encode_generalizedtime(const ltc_generalizedtime *gtime,
+#undef STORE_V
+#undef STORE_V4
@@ -15,7 +15,7 @@ static int s_ltc_to_asn1(ltc_asn1_type v)
return der_asn1_type_to_identifier_map[v];
+#define s_qsort_helper s_set_qsort_helper
static int s_qsort_helper(const void *a, const void *b)
ltc_asn1_list *A = (ltc_asn1_list *)a, *B = (ltc_asn1_list *)b;
@@ -70,5 +70,6 @@ int der_encode_set(const ltc_asn1_list *list, unsigned long inlen,
+#undef s_qsort_helper
@@ -14,6 +14,7 @@ struct edge {
unsigned long size;
+#define s_qsort_helper s_setof_qsort_helper
struct edge *A = (struct edge *)a, *B = (struct edge *)b;
@@ -148,4 +149,6 @@ int der_encode_setof(const ltc_asn1_list *list, unsigned long inlen,
@@ -9,7 +9,9 @@
@@ -25,6 +27,7 @@ static int s_char_to_int(unsigned char x)
#define DECODE_V(y, max) \
@@ -113,4 +116,6 @@ YYMMDDhhmmss-hh'mm'
@@ -9,8 +9,6 @@
#define STORE_V(y) \
out[x++] = der_ia5_char_encode(baseten[y % 10]);
@@ -25,6 +23,7 @@ static const char * const baseten = "0123456789";
int der_encode_utctime(const ltc_utctime *utctime,
@@ -68,4 +67,6 @@ int der_encode_utctime(const ltc_utctime *utctime,
@@ -4,6 +4,7 @@
/* automatically generated file, do not edit */
+#define add tnacl_add
#define FOR(i,n) for (i = 0;i < n;++i)
#define sv static void
@@ -489,3 +490,7 @@ int tweetnacl_crypto_ph(u8 *out,const u8 *msg,u64 msglen)
return tweetnacl_crypto_hash(out, msg, msglen);
+#undef add
+#undef FOR
+#undef sv
@@ -88,4 +88,6 @@ int chacha_crypt(chacha_state *st, const unsigned char *in, unsigned long inlen,
+#undef QUARTERROUND
@@ -10,9 +10,6 @@
#ifdef LTC_CHACHA
-static const char * const sigma = "expand 32-byte k";
-static const char * const tau = "expand 16-byte k";
Initialize an ChaCha context (only the key)
@param st [out] The destination of the ChaCha state
@@ -23,6 +20,8 @@ static const char * const tau = "expand 16-byte k";
*/
int chacha_setup(chacha_state *st, const unsigned char *key, unsigned long keylen, int rounds)
+ const char * const sigma = "expand 32-byte k";
+ const char * const tau = "expand 16-byte k";
const char *constants;
LTC_ARGCHK(st != NULL);
@@ -83,4 +83,6 @@ int salsa20_crypt(salsa20_state *st, const unsigned char *in, unsigned long inle
@@ -11,9 +11,6 @@
#ifdef LTC_SALSA20
Initialize an Salsa20 context (only the key)
@param st [out] The destination of the Salsa20 state
@@ -24,6 +21,8 @@ static const char * const tau = "expand 16-byte k";
int salsa20_setup(salsa20_state *st, const unsigned char *key, unsigned long keylen, int rounds)
@@ -12,8 +12,6 @@
#ifdef LTC_XSALSA20
-static const char * const constants = "expand 32-byte k";
#define QUARTERROUND(a,b,c,d) \
x[b] ^= (ROL((x[a] + x[d]), 7)); \
x[c] ^= (ROL((x[b] + x[a]), 9)); \
@@ -55,6 +53,7 @@ int xsalsa20_setup(salsa20_state *st, const unsigned char *key, unsigned long ke
const unsigned char *nonce, unsigned long noncelen,
int rounds)
+ const char * const constants = "expand 32-byte k";
const int sti[] = {0, 5, 10, 15, 6, 7, 8, 9}; /* indices used to build subkey fm x */
ulong32 x[64]; /* input to & output fm doubleround */
unsigned char subkey[32];
@@ -330,4 +330,16 @@ int sober128_stream_done(sober128_state *st)
+#undef N
+#undef INITKONST
+#undef KEYP
+#undef FOLDP
+#undef OFF
+#undef STEP
+#undef NLFUNC
+#undef ADDKEY
+#undef XORNL
+#undef DROUND
+#undef SROUND