Fix whitespace changes vs upstream libtomcrypt

This commit is contained in:
Matt Johnston 2020-06-10 23:01:33 +08:00
parent 6b823d617c
commit 615885be01
11 changed files with 1213 additions and 1213 deletions

View File

@ -675,11 +675,11 @@ int ECB_TEST(void)
} }
}; };
symmetric_key key; symmetric_key key;
unsigned char tmp[2][16]; unsigned char tmp[2][16];
int i, y; int i, y;
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) { for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
zeromem(&key, sizeof(key)); zeromem(&key, sizeof(key));
if ((err = rijndael_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) { if ((err = rijndael_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
return err; return err;
@ -692,13 +692,13 @@ int ECB_TEST(void)
return CRYPT_FAIL_TESTVECTOR; return CRYPT_FAIL_TESTVECTOR;
} }
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
for (y = 0; y < 16; y++) tmp[0][y] = 0; for (y = 0; y < 16; y++) tmp[0][y] = 0;
for (y = 0; y < 1000; y++) rijndael_ecb_encrypt(tmp[0], tmp[0], &key); for (y = 0; y < 1000; y++) rijndael_ecb_encrypt(tmp[0], tmp[0], &key);
for (y = 0; y < 1000; y++) rijndael_ecb_decrypt(tmp[0], tmp[0], &key); for (y = 0; y < 1000; y++) rijndael_ecb_decrypt(tmp[0], tmp[0], &key);
for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR; for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
} }
return CRYPT_OK; return CRYPT_OK;
#endif #endif
} }

View File

@ -1450,9 +1450,9 @@ static void _desfunc(ulong32 *block, const ulong32 *keys)
for (cur_round = 0; cur_round < 8; cur_round++) { for (cur_round = 0; cur_round < 8; cur_round++) {
work = RORc(right, 4) ^ *keys++; work = RORc(right, 4) ^ *keys++;
leftt ^= SP7[work & 0x3fL] leftt ^= SP7[work & 0x3fL]
^ SP5[(work >> 8) & 0x3fL] ^ SP5[(work >> 8) & 0x3fL]
^ SP3[(work >> 16) & 0x3fL] ^ SP3[(work >> 16) & 0x3fL]
^ SP1[(work >> 24) & 0x3fL]; ^ SP1[(work >> 24) & 0x3fL];
work = right ^ *keys++; work = right ^ *keys++;
leftt ^= SP8[ work & 0x3fL] leftt ^= SP8[ work & 0x3fL]
^ SP6[(work >> 8) & 0x3fL] ^ SP6[(work >> 8) & 0x3fL]
@ -1571,7 +1571,7 @@ int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
deskey(key, EN0, skey->des3.ek[0]); deskey(key, EN0, skey->des3.ek[0]);
deskey(key+8, DE1, skey->des3.ek[1]); deskey(key+8, DE1, skey->des3.ek[1]);
if (keylen == 24) { if (keylen == 24) {
deskey(key+16, EN0, skey->des3.ek[2]); deskey(key+16, EN0, skey->des3.ek[2]);
} else { } else {
/* two-key 3DES: K3=K1 */ /* two-key 3DES: K3=K1 */
deskey(key, EN0, skey->des3.ek[2]); deskey(key, EN0, skey->des3.ek[2]);
@ -1580,7 +1580,7 @@ int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
deskey(key, DE1, skey->des3.dk[2]); deskey(key, DE1, skey->des3.dk[2]);
deskey(key+8, EN0, skey->des3.dk[1]); deskey(key+8, EN0, skey->des3.dk[1]);
if (keylen == 24) { if (keylen == 24) {
deskey(key+16, DE1, skey->des3.dk[0]); deskey(key+16, DE1, skey->des3.dk[0]);
} else { } else {
/* two-key 3DES: K3=K1 */ /* two-key 3DES: K3=K1 */
deskey(key, DE1, skey->des3.dk[0]); deskey(key, DE1, skey->des3.dk[0]);
@ -1988,11 +1988,11 @@ int des_test(void)
return CRYPT_FAIL_TESTVECTOR; return CRYPT_FAIL_TESTVECTOR;
} }
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
for (y = 0; y < 8; y++) tmp[y] = 0; for (y = 0; y < 8; y++) tmp[y] = 0;
for (y = 0; y < 1000; y++) des_ecb_encrypt(tmp, tmp, &des); for (y = 0; y < 1000; y++) des_ecb_encrypt(tmp, tmp, &des);
for (y = 0; y < 1000; y++) des_ecb_decrypt(tmp, tmp, &des); for (y = 0; y < 1000; y++) des_ecb_decrypt(tmp, tmp, &des);
for (y = 0; y < 8; y++) if (tmp[y] != 0) return CRYPT_FAIL_TESTVECTOR; for (y = 0; y < 8; y++) if (tmp[y] != 0) return CRYPT_FAIL_TESTVECTOR;
} }
return CRYPT_OK; return CRYPT_OK;

View File

@ -243,7 +243,7 @@ static void h_func(const unsigned char *in, unsigned char *out, unsigned char *M
unsigned char y[4]; unsigned char y[4];
for (x = 0; x < 4; x++) { for (x = 0; x < 4; x++) {
y[x] = in[x]; y[x] = in[x];
} }
switch (k) { switch (k) {
case 4: case 4:
y[0] = (unsigned char)(sbox(1, (ulong32)y[0]) ^ M[4 * (6 + offset) + 0]); y[0] = (unsigned char)(sbox(1, (ulong32)y[0]) ^ M[4 * (6 + offset) + 0]);
@ -505,7 +505,7 @@ int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ke
a = RORc(a ^ (t1 + k[2]), 1); a = RORc(a ^ (t1 + k[2]), 1);
b = ROLc(b, 1) ^ (t2 + t1 + k[3]); b = ROLc(b, 1) ^ (t2 + t1 + k[3]);
k += 4; k += 4;
} }
/* output with "undo last swap" */ /* output with "undo last swap" */
ta = c ^ skey->twofish.K[4]; ta = c ^ skey->twofish.K[4];
@ -647,11 +647,11 @@ int twofish_test(void)
}; };
symmetric_key key; symmetric_key key;
unsigned char tmp[2][16]; unsigned char tmp[2][16];
int err, i, y; int err, i, y;
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) { for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
if ((err = twofish_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) { if ((err = twofish_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
return err; return err;
} }
@ -661,13 +661,13 @@ int twofish_test(void)
compare_testvector(tmp[1], 16, tests[i].pt, 16, "Twofish Decrypt", i) != 0) { compare_testvector(tmp[1], 16, tests[i].pt, 16, "Twofish Decrypt", i) != 0) {
return CRYPT_FAIL_TESTVECTOR; return CRYPT_FAIL_TESTVECTOR;
} }
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
for (y = 0; y < 16; y++) tmp[0][y] = 0; for (y = 0; y < 16; y++) tmp[0][y] = 0;
for (y = 0; y < 1000; y++) twofish_ecb_encrypt(tmp[0], tmp[0], &key); for (y = 0; y < 1000; y++) twofish_ecb_encrypt(tmp[0], tmp[0], &key);
for (y = 0; y < 1000; y++) twofish_ecb_decrypt(tmp[0], tmp[0], &key); for (y = 0; y < 1000; y++) twofish_ecb_decrypt(tmp[0], tmp[0], &key);
for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR; for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
} }
return CRYPT_OK; return CRYPT_OK;
#endif #endif
} }

View File

@ -57,8 +57,8 @@ int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outle
} }
} while (x == LTC_FILE_READ_BUFSIZE); } while (x == LTC_FILE_READ_BUFSIZE);
if ((err = hash_descriptor[hash].done(&md, out)) == CRYPT_OK) { if ((err = hash_descriptor[hash].done(&md, out)) == CRYPT_OK) {
*outlen = hash_descriptor[hash].hashsize; *outlen = hash_descriptor[hash].hashsize;
} }
LBL_CLEANBUF: LBL_CLEANBUF:
zeromem(buf, LTC_FILE_READ_BUFSIZE); zeromem(buf, LTC_FILE_READ_BUFSIZE);

View File

@ -74,8 +74,8 @@
#define LTC_NO_MODES #define LTC_NO_MODES
#define LTC_NO_HASHES #define LTC_NO_HASHES
#define LTC_NO_MACS #define LTC_NO_MACS
#define LTC_NO_PRNGS #define LTC_NO_PRNGS
#define LTC_NO_PK #define LTC_NO_PK
#define LTC_NO_PKCS #define LTC_NO_PKCS
#define LTC_NO_MISC #define LTC_NO_MISC
#endif /* LTC_NOTHING */ #endif /* LTC_NOTHING */

View File

@ -64,9 +64,9 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
XMEMCPY(hmac->key, key, (size_t)keylen); XMEMCPY(hmac->key, key, (size_t)keylen);
} }
if(keylen < LTC_HMAC_BLOCKSIZE) { if(keylen < LTC_HMAC_BLOCKSIZE) {
zeromem((hmac->key) + keylen, (size_t)(LTC_HMAC_BLOCKSIZE - keylen)); zeromem((hmac->key) + keylen, (size_t)(LTC_HMAC_BLOCKSIZE - keylen));
} }
/* Create the initialization vector for step (3) */ /* Create the initialization vector for step (3) */
for(i=0; i < LTC_HMAC_BLOCKSIZE; i++) { for(i=0; i < LTC_HMAC_BLOCKSIZE; i++) {

View File

@ -17,7 +17,7 @@
*/ */
static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen, static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
prng_state *prng, int wprng, ecc_key *key, int sigformat) prng_state *prng, int wprng, ecc_key *key, int sigformat)
{ {
ecc_key pubkey; ecc_key pubkey;
@ -49,7 +49,7 @@ static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen,
if ((err = mp_init_multi(&r, &s, &p, &e, NULL)) != CRYPT_OK) { if ((err = mp_init_multi(&r, &s, &p, &e, NULL)) != CRYPT_OK) {
return err; return err;
} }
if ((err = mp_read_radix(p, (char *)key->dp->order, 16)) != CRYPT_OK) { goto errnokey; } if ((err = mp_read_radix(p, (char *)key->dp->order, 16)) != CRYPT_OK) { goto errnokey; }
/* get the hash and load it as a bignum into 'e' */ /* get the hash and load it as a bignum into 'e' */
pbits = mp_count_bits(p); pbits = mp_count_bits(p);
@ -77,21 +77,21 @@ static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen,
} }
/* find r = x1 mod n */ /* find r = x1 mod n */
if ((err = mp_mod(pubkey.pubkey.x, p, r)) != CRYPT_OK) { goto error; } if ((err = mp_mod(pubkey.pubkey.x, p, r)) != CRYPT_OK) { goto error; }
if (mp_iszero(r) == LTC_MP_YES) { if (mp_iszero(r) == LTC_MP_YES) {
ecc_free(&pubkey); ecc_free(&pubkey);
} else { } else {
/* find s = (e + xr)/k */ /* find s = (e + xr)/k */
if ((err = mp_invmod(pubkey.k, p, pubkey.k)) != CRYPT_OK) { goto error; } /* k = 1/k */ if ((err = mp_invmod(pubkey.k, p, pubkey.k)) != CRYPT_OK) { goto error; } /* k = 1/k */
if ((err = mp_mulmod(key->k, r, p, s)) != CRYPT_OK) { goto error; } /* s = xr */ if ((err = mp_mulmod(key->k, r, p, s)) != CRYPT_OK) { goto error; } /* s = xr */
if ((err = mp_add(e, s, s)) != CRYPT_OK) { goto error; } /* s = e + xr */ if ((err = mp_add(e, s, s)) != CRYPT_OK) { goto error; } /* s = e + xr */
if ((err = mp_mod(s, p, s)) != CRYPT_OK) { goto error; } /* s = e + xr */ if ((err = mp_mod(s, p, s)) != CRYPT_OK) { goto error; } /* s = e + xr */
if ((err = mp_mulmod(s, pubkey.k, p, s)) != CRYPT_OK) { goto error; } /* s = (e + xr)/k */ if ((err = mp_mulmod(s, pubkey.k, p, s)) != CRYPT_OK) { goto error; } /* s = (e + xr)/k */
ecc_free(&pubkey); ecc_free(&pubkey);
if (mp_iszero(s) == LTC_MP_NO) { if (mp_iszero(s) == LTC_MP_NO) {
break; break;
} }
} }
} while (--max_iterations > 0); } while (--max_iterations > 0);
@ -112,10 +112,10 @@ static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen,
} }
else { else {
/* store as ASN.1 SEQUENCE { r, s -- integer } */ /* store as ASN.1 SEQUENCE { r, s -- integer } */
err = der_encode_sequence_multi(out, outlen, err = der_encode_sequence_multi(out, outlen,
LTC_ASN1_INTEGER, 1UL, r, LTC_ASN1_INTEGER, 1UL, r,
LTC_ASN1_INTEGER, 1UL, s, LTC_ASN1_INTEGER, 1UL, s,
LTC_ASN1_EOL, 0UL, NULL); LTC_ASN1_EOL, 0UL, NULL);
} }
goto errnokey; goto errnokey;
error: error:

View File

@ -17,7 +17,7 @@
*/ */
static int _ecc_verify_hash(const unsigned char *sig, unsigned long siglen, static int _ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
const unsigned char *hash, unsigned long hashlen, const unsigned char *hash, unsigned long hashlen,
int *stat, ecc_key *key, int sigformat) int *stat, ecc_key *key, int sigformat)
{ {
ecc_point *mG, *mQ; ecc_point *mG, *mQ;
@ -66,9 +66,9 @@ static int _ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
} }
else { else {
/* ASN.1 format */ /* ASN.1 format */
if ((err = der_decode_sequence_multi(sig, siglen, if ((err = der_decode_sequence_multi(sig, siglen,
LTC_ASN1_INTEGER, 1UL, r, LTC_ASN1_INTEGER, 1UL, r,
LTC_ASN1_INTEGER, 1UL, s, LTC_ASN1_INTEGER, 1UL, s,
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { goto error; } LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { goto error; }
} }

View File

@ -59,8 +59,8 @@ int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map)
return err; return err;
} }
/* alloc ram for window temps */ /* alloc ram for window temps */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
M[i] = ltc_ecc_new_point(); M[i] = ltc_ecc_new_point();
if (M[i] == NULL) { if (M[i] == NULL) {
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
@ -70,7 +70,7 @@ int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map)
mp_montgomery_free(mp); mp_montgomery_free(mp);
return CRYPT_MEM; return CRYPT_MEM;
} }
} }
/* make a copy of G incase R==G */ /* make a copy of G incase R==G */
tG = ltc_ecc_new_point(); tG = ltc_ecc_new_point();