fix indentation

This commit is contained in:
Francois Perrad 2015-12-19 17:30:38 +01:00 committed by Karel Miko
parent ecb2402ba8
commit 7b48f4d5f7
37 changed files with 334 additions and 333 deletions

View File

@ -675,11 +675,11 @@ int ECB_TEST(void)
}
};
symmetric_key key;
unsigned char tmp[2][16];
int i, y;
symmetric_key key;
unsigned char tmp[2][16];
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));
if ((err = rijndael_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
return err;
@ -707,13 +707,13 @@ int ECB_TEST(void)
return CRYPT_FAIL_TESTVECTOR;
}
/* 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 < 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 < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
}
return CRYPT_OK;
/* 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 < 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 < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
}
return CRYPT_OK;
#endif
}

View File

@ -926,16 +926,16 @@ int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
return CRYPT_INVALID_ROUNDS;
}
/*
* map cipher key to initial key state (mu):
*/
for (i = 0, pos = 0; i < N; i++, pos += 4) {
/*
* map cipher key to initial key state (mu):
*/
for (i = 0, pos = 0; i < N; i++, pos += 4) {
kappa[i] =
(((ulong32)key[pos ]) << 24) ^
(((ulong32)key[pos + 1]) << 16) ^
(((ulong32)key[pos + 2]) << 8) ^
(((ulong32)key[pos + 3]) );
}
}
/*
* generate R + 1 round keys:

View File

@ -686,8 +686,8 @@ int camellia_test(void)
unsigned int x;
for (x = 0; x < sizeof(tests)/sizeof(tests[0]); x++) {
zeromem(&skey, sizeof(skey));
if ((err = camellia_setup(tests[x].key, tests[x].keylen, 0, &skey)) != CRYPT_OK) {
zeromem(&skey, sizeof(skey));
if ((err = camellia_setup(tests[x].key, tests[x].keylen, 0, &skey)) != CRYPT_OK) {
return err;
}
if ((err = camellia_ecb_encrypt(tests[x].pt, buf[0], &skey)) != CRYPT_OK) {

View File

@ -1983,12 +1983,12 @@ int des_test(void)
return CRYPT_FAIL_TESTVECTOR;
}
/* 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 < 1000; y++) des_ecb_encrypt(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;
}
/* 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 < 1000; y++) des_ecb_encrypt(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;
}
return CRYPT_OK;
#endif

View File

@ -201,41 +201,41 @@ static const ulong32 KCi[16] = {
*/
int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
int i;
ulong32 tmp, k1, k2, k3, k4;
int i;
ulong32 tmp, k1, k2, k3, k4;
if (keylen != 16) {
return CRYPT_INVALID_KEYSIZE;
}
if (keylen != 16) {
return CRYPT_INVALID_KEYSIZE;
}
if (num_rounds != 16 && num_rounds != 0) {
return CRYPT_INVALID_ROUNDS;
}
if (num_rounds != 16 && num_rounds != 0) {
return CRYPT_INVALID_ROUNDS;
}
/* load key */
LOAD32H(k1, key);
LOAD32H(k2, key+4);
LOAD32H(k3, key+8);
LOAD32H(k4, key+12);
/* load key */
LOAD32H(k1, key);
LOAD32H(k2, key+4);
LOAD32H(k3, key+8);
LOAD32H(k4, key+12);
for (i = 0; i < 16; i++) {
skey->kseed.K[2*i+0] = G(k1 + k3 - KCi[i]);
skey->kseed.K[2*i+1] = G(k2 - k4 + KCi[i]);
if (i&1) {
tmp = k3;
k3 = ((k3 << 8) | (k4 >> 24)) & 0xFFFFFFFF;
k4 = ((k4 << 8) | (tmp >> 24)) & 0xFFFFFFFF;
} else {
tmp = k1;
k1 = ((k1 >> 8) | (k2 << 24)) & 0xFFFFFFFF;
k2 = ((k2 >> 8) | (tmp << 24)) & 0xFFFFFFFF;
for (i = 0; i < 16; i++) {
skey->kseed.K[2*i+0] = G(k1 + k3 - KCi[i]);
skey->kseed.K[2*i+1] = G(k2 - k4 + KCi[i]);
if (i&1) {
tmp = k3;
k3 = ((k3 << 8) | (k4 >> 24)) & 0xFFFFFFFF;
k4 = ((k4 << 8) | (tmp >> 24)) & 0xFFFFFFFF;
} else {
tmp = k1;
k1 = ((k1 >> 8) | (k2 << 24)) & 0xFFFFFFFF;
k2 = ((k2 >> 8) | (tmp << 24)) & 0xFFFFFFFF;
}
/* reverse keys for decrypt */
skey->kseed.dK[2*(15-i)+0] = skey->kseed.K[2*i+0];
skey->kseed.dK[2*(15-i)+1] = skey->kseed.K[2*i+1];
}
}
return CRYPT_OK;
return CRYPT_OK;
}
static void rounds(ulong32 *P, ulong32 *K)

View File

@ -303,11 +303,11 @@ int noekeon_test(void)
return CRYPT_FAIL_TESTVECTOR;
}
/* 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 < 1000; y++) noekeon_ecb_encrypt(tmp[0], tmp[0], &key);
for (y = 0; y < 1000; y++) noekeon_ecb_decrypt(tmp[0], tmp[0], &key);
for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
/* 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 < 1000; y++) noekeon_ecb_encrypt(tmp[0], tmp[0], &key);
for (y = 0; y < 1000; y++) noekeon_ecb_decrypt(tmp[0], tmp[0], &key);
for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
}
return CRYPT_OK;
#endif

View File

@ -86,35 +86,35 @@ int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
}
for (i = 0; i < keylen; i++) {
tmp[i] = key[i] & 255;
tmp[i] = key[i] & 255;
}
/* Phase 1: Expand input key to 128 bytes */
if (keylen < 128) {
for (i = keylen; i < 128; i++) {
tmp[i] = permute[(tmp[i - 1] + tmp[i - keylen]) & 255];
}
}
/* Phase 1: Expand input key to 128 bytes */
if (keylen < 128) {
for (i = keylen; i < 128; i++) {
tmp[i] = permute[(tmp[i - 1] + tmp[i - keylen]) & 255];
}
}
/* Phase 2 - reduce effective key size to "bits" */
bits = keylen<<3;
T8 = (unsigned)(bits+7)>>3;
TM = (255 >> (unsigned)(7 & -bits));
tmp[128 - T8] = permute[tmp[128 - T8] & TM];
for (i = 127 - T8; i >= 0; i--) {
tmp[i] = permute[tmp[i + 1] ^ tmp[i + T8]];
}
/* Phase 2 - reduce effective key size to "bits" */
bits = keylen<<3;
T8 = (unsigned)(bits+7)>>3;
TM = (255 >> (unsigned)(7 & -bits));
tmp[128 - T8] = permute[tmp[128 - T8] & TM];
for (i = 127 - T8; i >= 0; i--) {
tmp[i] = permute[tmp[i + 1] ^ tmp[i + T8]];
}
/* Phase 3 - copy to xkey in little-endian order */
for (i = 0; i < 64; i++) {
xkey[i] = (unsigned)tmp[2*i] + ((unsigned)tmp[2*i+1] << 8);
}
/* Phase 3 - copy to xkey in little-endian order */
for (i = 0; i < 64; i++) {
xkey[i] = (unsigned)tmp[2*i] + ((unsigned)tmp[2*i+1] << 8);
}
#ifdef LTC_CLEAN_STACK
zeromem(tmp, sizeof(tmp));
zeromem(tmp, sizeof(tmp));
#endif
return CRYPT_OK;
return CRYPT_OK;
}
/**********************************************************************\

View File

@ -432,11 +432,11 @@ int safer_sk64_test(void)
return CRYPT_FAIL_TESTVECTOR;
}
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
for (y = 0; y < 8; y++) buf[0][y] = 0;
for (y = 0; y < 1000; y++) safer_ecb_encrypt(buf[0], buf[0], &skey);
for (y = 0; y < 1000; y++) safer_ecb_decrypt(buf[0], buf[0], &skey);
for (y = 0; y < 8; y++) if (buf[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
for (y = 0; y < 8; y++) buf[0][y] = 0;
for (y = 0; y < 1000; y++) safer_ecb_encrypt(buf[0], buf[0], &skey);
for (y = 0; y < 1000; y++) safer_ecb_decrypt(buf[0], buf[0], &skey);
for (y = 0; y < 8; y++) if (buf[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
return CRYPT_OK;
#endif
@ -475,12 +475,13 @@ int safer_sk128_test(void)
return CRYPT_FAIL_TESTVECTOR;
}
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
for (y = 0; y < 8; y++) buf[0][y] = 0;
for (y = 0; y < 1000; y++) safer_ecb_encrypt(buf[0], buf[0], &skey);
for (y = 0; y < 1000; y++) safer_ecb_decrypt(buf[0], buf[0], &skey);
for (y = 0; y < 8; y++) if (buf[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
return CRYPT_OK;
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
for (y = 0; y < 8; y++) buf[0][y] = 0;
for (y = 0; y < 1000; y++) safer_ecb_encrypt(buf[0], buf[0], &skey);
for (y = 0; y < 1000; y++) safer_ecb_decrypt(buf[0], buf[0], &skey);
for (y = 0; y < 8; y++) if (buf[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
return CRYPT_OK;
#endif
}

View File

@ -245,7 +245,7 @@ static void h_func(const unsigned char *in, unsigned char *out, unsigned char *M
unsigned char y[4];
for (x = 0; x < 4; x++) {
y[x] = in[x];
}
}
switch (k) {
case 4:
y[0] = (unsigned char)(sbox(1, (ulong32)y[0]) ^ M[4 * (6 + offset) + 0]);
@ -504,7 +504,7 @@ int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ke
a = RORc(a ^ (t1 + k[2]), 1);
b = ROLc(b, 1) ^ (t2 + t1 + k[3]);
k += 4;
}
}
/* output with "undo last swap" */
ta = c ^ skey->twofish.K[4];
@ -646,11 +646,11 @@ int twofish_test(void)
};
symmetric_key key;
unsigned char tmp[2][16];
int err, i, y;
symmetric_key key;
unsigned char tmp[2][16];
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) {
return err;
}
@ -662,13 +662,13 @@ int twofish_test(void)
#endif
return CRYPT_FAIL_TESTVECTOR;
}
/* 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 < 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 < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
}
return CRYPT_OK;
/* 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 < 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 < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
}
return CRYPT_OK;
#endif
}

View File

@ -283,8 +283,8 @@ int ccm_memory(int cipher,
goto error;
}
}
}
}
}
}
#endif
for (; y < ptlen; y++) {

View File

@ -190,9 +190,9 @@ int ccm_test(void)
}
if (y == 0) {
XMEMCPY(tag3, tests[x].tag, tests[x].taglen);
taglen = tests[x].taglen;
if ((err = ccm_memory(idx,
XMEMCPY(tag3, tests[x].tag, tests[x].taglen);
taglen = tests[x].taglen;
if ((err = ccm_memory(idx,
tests[x].key, 16,
NULL,
tests[x].nonce, tests[x].noncelen,

View File

@ -270,8 +270,8 @@ int eax_test(void)
return CRYPT_FAIL_TESTVECTOR;
}
}
return CRYPT_OK;
}
return CRYPT_OK;
#endif /* LTC_TEST */
}

View File

@ -104,9 +104,9 @@ int gcm_add_aad(gcm_state *gcm,
/* start adding AAD data to the state */
for (; x < adatalen; x++) {
gcm->X[gcm->buflen++] ^= *adata++;
gcm->X[gcm->buflen++] ^= *adata++;
if (gcm->buflen == 16) {
if (gcm->buflen == 16) {
/* GF mult it */
gcm_mult_h(gcm, gcm->X);
gcm->buflen = 0;

View File

@ -72,7 +72,7 @@ int gcm_add_iv(gcm_state *gcm,
for (; x < IVlen; x++) {
gcm->buf[gcm->buflen++] = *IV++;
if (gcm->buflen == 16) {
if (gcm->buflen == 16) {
/* GF mult it */
for (y = 0; y < 16; y++) {
gcm->X[y] ^= gcm->buf[y];

View File

@ -92,8 +92,8 @@ int gcm_init(gcm_state *gcm, int cipher,
}
gcm->PC[x][y][0] = gcm_shift_table[t<<1];
gcm->PC[x][y][1] ^= gcm_shift_table[(t<<1)+1];
}
}
}
}
#endif

View File

@ -118,7 +118,7 @@ int gcm_process(gcm_state *gcm,
return err;
}
}
}
}
}
#endif

View File

@ -106,32 +106,32 @@ int ocb_init(ocb_state *ocb, int cipher,
ocb->Ls[x][y] ^= polys[poly].poly_mul[y];
}
}
}
}
/* find Lr = L / x */
m = ocb->L[ocb->block_len-1] & 1;
/* find Lr = L / x */
m = ocb->L[ocb->block_len-1] & 1;
/* shift right */
for (x = ocb->block_len - 1; x > 0; x--) {
ocb->Lr[x] = ((ocb->L[x] >> 1) | (ocb->L[x-1] << 7)) & 255;
}
ocb->Lr[0] = ocb->L[0] >> 1;
/* shift right */
for (x = ocb->block_len - 1; x > 0; x--) {
ocb->Lr[x] = ((ocb->L[x] >> 1) | (ocb->L[x-1] << 7)) & 255;
}
ocb->Lr[0] = ocb->L[0] >> 1;
if (m == 1) {
for (x = 0; x < ocb->block_len; x++) {
ocb->Lr[x] ^= polys[poly].poly_div[x];
}
}
if (m == 1) {
for (x = 0; x < ocb->block_len; x++) {
ocb->Lr[x] ^= polys[poly].poly_div[x];
}
}
/* set Li, checksum */
zeromem(ocb->Li, ocb->block_len);
zeromem(ocb->checksum, ocb->block_len);
/* set Li, checksum */
zeromem(ocb->Li, ocb->block_len);
zeromem(ocb->checksum, ocb->block_len);
/* set other params */
ocb->block_index = 1;
ocb->cipher = cipher;
/* set other params */
ocb->block_index = 1;
ocb->cipher = cipher;
return CRYPT_OK;
return CRYPT_OK;
}
#endif

View File

@ -90,45 +90,45 @@ int ocb3_init(ocb3_state *ocb, int cipher,
/* compute L_$, L_0, L_1, ... */
for (x = -1; x < 32; x++) {
if (x == -1) { /* gonna compute: L_$ = double(L_*) */
if (x == -1) { /* gonna compute: L_$ = double(L_*) */
current = ocb->L_dollar;
previous = ocb->L_star;
}
else if (x == 0) { /* gonna compute: L_0 = double(L_$) */
}
else if (x == 0) { /* gonna compute: L_0 = double(L_$) */
current = ocb->L_[0];
previous = ocb->L_dollar;
}
else { /* gonna compute: L_i = double(L_{i-1}) for every integer i > 0 */
}
else { /* gonna compute: L_i = double(L_{i-1}) for every integer i > 0 */
current = ocb->L_[x];
previous = ocb->L_[x-1];
}
m = previous[0] >> 7;
for (y = 0; y < ocb->block_len-1; y++) {
current[y] = ((previous[y] << 1) | (previous[y+1] >> 7)) & 255;
}
current[ocb->block_len-1] = (previous[ocb->block_len-1] << 1) & 255;
if (m == 1) {
/* current[] = current[] XOR polys[poly].poly_mul[]*/
ocb3_int_xor_blocks(current, current, polys[poly].poly_mul, ocb->block_len);
}
}
}
m = previous[0] >> 7;
for (y = 0; y < ocb->block_len-1; y++) {
current[y] = ((previous[y] << 1) | (previous[y+1] >> 7)) & 255;
}
current[ocb->block_len-1] = (previous[ocb->block_len-1] << 1) & 255;
if (m == 1) {
/* current[] = current[] XOR polys[poly].poly_mul[]*/
ocb3_int_xor_blocks(current, current, polys[poly].poly_mul, ocb->block_len);
}
}
/* initialize ocb->Offset_current = Offset_0 */
ocb3_int_calc_offset_zero(ocb, nonce, noncelen);
/* initialize ocb->Offset_current = Offset_0 */
ocb3_int_calc_offset_zero(ocb, nonce, noncelen);
/* initialize checksum to all zeros */
zeromem(ocb->checksum, ocb->block_len);
/* initialize checksum to all zeros */
zeromem(ocb->checksum, ocb->block_len);
/* set block index */
ocb->block_index = 1;
/* set block index */
ocb->block_index = 1;
/* initialize AAD related stuff */
ocb->ablock_index = 1;
ocb->adata_buffer_bytes = 0;
zeromem(ocb->aOffset_current, ocb->block_len);
zeromem(ocb->aSum_current, ocb->block_len);
/* initialize AAD related stuff */
ocb->ablock_index = 1;
ocb->adata_buffer_bytes = 0;
zeromem(ocb->aOffset_current, ocb->block_len);
zeromem(ocb->aSum_current, ocb->block_len);
return CRYPT_OK;
return CRYPT_OK;
}
#endif

View File

@ -135,16 +135,16 @@ static int sha512_compress(hash_state * md, unsigned char *buf)
d += t0; \
h = t0 + t1;
for (i = 0; i < 80; i += 8) {
RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i+0);
RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],i+1);
RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],i+2);
RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],i+3);
RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],i+4);
RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],i+5);
RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],i+6);
RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],i+7);
}
for (i = 0; i < 80; i += 8) {
RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i+0);
RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],i+1);
RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],i+2);
RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],i+3);
RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],i+4);
RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],i+5);
RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],i+6);
RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],i+7);
}
#endif

View File

@ -53,21 +53,21 @@ int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen)
in += f9->blocksize;
inlen -= f9->blocksize;
}
}
}
#endif
while (inlen) {
if (f9->buflen == f9->blocksize) {
if (f9->buflen == f9->blocksize) {
cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
for (x = 0; x < f9->blocksize; x++) {
f9->ACC[x] ^= f9->IV[x];
}
f9->buflen = 0;
}
f9->IV[f9->buflen++] ^= *in++;
--inlen;
}
return CRYPT_OK;
}
f9->IV[f9->buflen++] ^= *in++;
--inlen;
}
return CRYPT_OK;
}
#endif

View File

@ -110,37 +110,37 @@ int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned l
}
}
/* find Lr = L / x */
m = L[pmac->block_len-1] & 1;
/* find Lr = L / x */
m = L[pmac->block_len-1] & 1;
/* shift right */
for (x = pmac->block_len - 1; x > 0; x--) {
pmac->Lr[x] = ((L[x] >> 1) | (L[x-1] << 7)) & 255;
}
pmac->Lr[0] = L[0] >> 1;
/* shift right */
for (x = pmac->block_len - 1; x > 0; x--) {
pmac->Lr[x] = ((L[x] >> 1) | (L[x-1] << 7)) & 255;
}
pmac->Lr[0] = L[0] >> 1;
if (m == 1) {
for (x = 0; x < pmac->block_len; x++) {
pmac->Lr[x] ^= polys[poly].poly_div[x];
}
}
if (m == 1) {
for (x = 0; x < pmac->block_len; x++) {
pmac->Lr[x] ^= polys[poly].poly_div[x];
}
}
/* zero buffer, counters, etc... */
pmac->block_index = 1;
pmac->cipher_idx = cipher;
pmac->buflen = 0;
zeromem(pmac->block, sizeof(pmac->block));
zeromem(pmac->Li, sizeof(pmac->Li));
zeromem(pmac->checksum, sizeof(pmac->checksum));
err = CRYPT_OK;
/* zero buffer, counters, etc... */
pmac->block_index = 1;
pmac->cipher_idx = cipher;
pmac->buflen = 0;
zeromem(pmac->block, sizeof(pmac->block));
zeromem(pmac->Li, sizeof(pmac->Li));
zeromem(pmac->checksum, sizeof(pmac->checksum));
err = CRYPT_OK;
error:
#ifdef LTC_CLEAN_STACK
zeromem(L, pmac->block_len);
zeromem(L, pmac->block_len);
#endif
XFREE(L);
XFREE(L);
return err;
return err;
}
#endif

View File

@ -150,8 +150,8 @@ int pmac_test(void)
#endif
return CRYPT_FAIL_TESTVECTOR;
}
}
return CRYPT_OK;
}
return CRYPT_OK;
#endif /* LTC_TEST */
}

View File

@ -53,18 +53,18 @@ int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen)
in += xcbc->blocksize;
inlen -= xcbc->blocksize;
}
}
}
#endif
while (inlen) {
if (xcbc->buflen == xcbc->blocksize) {
if (xcbc->buflen == xcbc->blocksize) {
cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);
xcbc->buflen = 0;
}
xcbc->IV[xcbc->buflen++] ^= *in++;
--inlen;
}
return CRYPT_OK;
}
xcbc->IV[xcbc->buflen++] ^= *in++;
--inlen;
}
return CRYPT_OK;
}
#endif

View File

@ -69,17 +69,17 @@ int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
/* xor IV against plaintext */
#if defined(LTC_FAST)
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
tmpy = *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^ *((LTC_FAST_TYPE*)((unsigned char *)tmp + x));
*((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
*((LTC_FAST_TYPE*)((unsigned char *)pt + x)) = tmpy;
}
*((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
*((LTC_FAST_TYPE*)((unsigned char *)pt + x)) = tmpy;
}
#else
for (x = 0; x < cbc->blocklen; x++) {
tmpy = tmp[x] ^ cbc->IV[x];
cbc->IV[x] = ct[x];
pt[x] = tmpy;
}
for (x = 0; x < cbc->blocklen; x++) {
tmpy = tmp[x] ^ cbc->IV[x];
cbc->IV[x] = ct[x];
pt[x] = tmpy;
}
#endif
ct += cbc->blocklen;

View File

@ -58,13 +58,13 @@ int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
while (len) {
/* xor IV against plaintext */
#if defined(LTC_FAST)
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
*((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^= *((LTC_FAST_TYPE*)((unsigned char *)pt + x));
}
}
#else
for (x = 0; x < cbc->blocklen; x++) {
cbc->IV[x] ^= pt[x];
}
for (x = 0; x < cbc->blocklen; x++) {
cbc->IV[x] ^= pt[x];
}
#endif
/* encrypt */
@ -72,21 +72,21 @@ int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
return err;
}
/* store IV [ciphertext] for a future block */
/* store IV [ciphertext] for a future block */
#if defined(LTC_FAST)
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
*((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
}
}
#else
for (x = 0; x < cbc->blocklen; x++) {
cbc->IV[x] = ct[x];
}
for (x = 0; x < cbc->blocklen; x++) {
cbc->IV[x] = ct[x];
}
#endif
ct += cbc->blocklen;
pt += cbc->blocklen;
len -= cbc->blocklen;
}
ct += cbc->blocklen;
pt += cbc->blocklen;
len -= cbc->blocklen;
}
}
return CRYPT_OK;
}

View File

@ -41,10 +41,10 @@ int lrw_start( int cipher,
int x, y, z, t;
#endif
LTC_ARGCHK(IV != NULL);
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(tweak != NULL);
LTC_ARGCHK(lrw != NULL);
LTC_ARGCHK(IV != NULL);
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(tweak != NULL);
LTC_ARGCHK(lrw != NULL);
#ifdef LTC_FAST
if (16 % sizeof(LTC_FAST_TYPE)) {
@ -88,8 +88,8 @@ int lrw_start( int cipher,
}
lrw->PC[x][y][0] = gcm_shift_table[t<<1];
lrw->PC[x][y][1] ^= gcm_shift_table[(t<<1)+1];
}
}
}
}
#endif
/* generate first pad */

View File

@ -122,8 +122,8 @@ int lrw_test(void)
if ((err = lrw_done(&lrw)) != CRYPT_OK) {
return err;
}
}
return CRYPT_OK;
}
return CRYPT_OK;
#endif
}

View File

@ -45,8 +45,8 @@ int der_decode_bit_string(const unsigned char *in, unsigned long inlen,
return CRYPT_INVALID_PACKET;
}
/* offset in the data */
x = 1;
/* offset in the data */
x = 1;
/* get the length of the data */
if (in[x] & 0x80) {

View File

@ -47,8 +47,8 @@ int der_decode_raw_bit_string(const unsigned char *in, unsigned long inlen,
return CRYPT_INVALID_PACKET;
}
/* offset in the data */
x = 1;
/* offset in the data */
x = 1;
/* get the length of the data */
if (in[x] & 0x80) {

View File

@ -53,14 +53,14 @@ int der_decode_object_identifier(const unsigned char *in, unsigned long inle
if (in[x] < 128) {
len = in[x++];
} else {
if (in[x] < 0x81 || in[x] > 0x82) {
return CRYPT_INVALID_PACKET;
}
y = in[x++] & 0x7F;
len = 0;
while (y--) {
len = (len << 8) | (unsigned long)in[x++];
}
if (in[x] < 0x81 || in[x] > 0x82) {
return CRYPT_INVALID_PACKET;
}
y = in[x++] & 0x7F;
len = 0;
while (y--) {
len = (len << 8) | (unsigned long)in[x++];
}
}
if (len < 1 || (len + x) > inlen) {
@ -71,21 +71,21 @@ int der_decode_object_identifier(const unsigned char *in, unsigned long inle
y = 0;
t = 0;
while (len--) {
t = (t << 7) | (in[x] & 0x7F);
if (!(in[x++] & 0x80)) {
/* store t */
if (y >= *outlen) {
return CRYPT_BUFFER_OVERFLOW;
}
if (y == 0) {
words[0] = t / 40;
words[1] = t % 40;
y = 2;
} else {
words[y++] = t;
t = (t << 7) | (in[x] & 0x7F);
if (!(in[x++] & 0x80)) {
/* store t */
if (y >= *outlen) {
return CRYPT_BUFFER_OVERFLOW;
}
if (y == 0) {
words[0] = t / 40;
words[1] = t % 40;
y = 2;
} else {
words[y++] = t;
}
t = 0;
}
t = 0;
}
}
*outlen = y;

View File

@ -71,33 +71,33 @@ int der_encode_object_identifier(unsigned long *words, unsigned long nwords,
}
/* store first byte */
wordbuf = words[0] * 40 + words[1];
for (i = 1; i < nwords; i++) {
/* store 7 bit words in little endian */
t = wordbuf & 0xFFFFFFFF;
if (t) {
y = x;
mask = 0;
while (t) {
out[x++] = (unsigned char)((t & 0x7F) | mask);
t >>= 7;
mask |= 0x80; /* upper bit is set on all but the last byte */
}
/* now swap bytes y...x-1 */
z = x - 1;
while (y < z) {
t = out[y]; out[y] = out[z]; out[z] = (unsigned char)t;
++y;
--z;
}
} else {
/* zero word */
out[x++] = 0x00;
}
wordbuf = words[0] * 40 + words[1];
for (i = 1; i < nwords; i++) {
/* store 7 bit words in little endian */
t = wordbuf & 0xFFFFFFFF;
if (t) {
y = x;
mask = 0;
while (t) {
out[x++] = (unsigned char)((t & 0x7F) | mask);
t >>= 7;
mask |= 0x80; /* upper bit is set on all but the last byte */
}
/* now swap bytes y...x-1 */
z = x - 1;
while (y < z) {
t = out[y]; out[y] = out[z]; out[z] = (unsigned char)t;
++y;
--z;
}
} else {
/* zero word */
out[x++] = 0x00;
}
if (i < nwords - 1) {
wordbuf = words[i + 1];
}
if (i < nwords - 1) {
wordbuf = words[i + 1];
}
}
*outlen = x;

View File

@ -72,19 +72,19 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
while (y--) {
blksize = (blksize << 8) | (unsigned long)in[x++];
}
}
}
/* would this blksize overflow? */
if (x + blksize > inlen) {
return CRYPT_INVALID_PACKET;
}
/* would this blksize overflow? */
if (x + blksize > inlen) {
return CRYPT_INVALID_PACKET;
}
/* mark all as unused */
for (i = 0; i < (int)outlen; i++) {
list[i].used = 0;
}
/* ok read data */
/* ok read data */
inlen = blksize;
for (i = 0; i < (int)outlen; i++) {
z = 0;
@ -105,8 +105,8 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
}
if ((err = der_length_boolean(&z)) != CRYPT_OK) {
goto LBL_ERR;
}
break;
}
break;
case LTC_ASN1_INTEGER:
z = inlen;

View File

@ -94,16 +94,16 @@ int der_encode_setof(ltc_asn1_list *list, unsigned long inlen,
}
/* skip header */
ptr = buf + 1;
ptr = buf + 1;
/* now skip length data */
x = *ptr++;
if (x >= 0x80) {
ptr += (x & 0x7F);
}
/* now skip length data */
x = *ptr++;
if (x >= 0x80) {
ptr += (x & 0x7F);
}
/* get the size of the static header */
hdrlen = ptr - buf;
/* get the size of the static header */
hdrlen = ptr - buf;
/* scan for edges */

View File

@ -95,8 +95,8 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
tmpbuf = XCALLOC(1, tmpbuf_len);
if (tmpbuf == NULL) {
err = CRYPT_MEM;
goto LBL_ERR;
err = CRYPT_MEM;
goto LBL_ERR;
}
err = der_decode_subject_public_key_info(in, inlen,
@ -112,7 +112,7 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
XFREE(tmpbuf);
key->type = PK_PUBLIC;
}
}
LBL_OK:
key->qord = mp_unsigned_bin_size(key->q);

View File

@ -93,16 +93,16 @@ int ltc_ecc_mul2add(ecc_point *A, void *kA,
}
}
/* init montgomery reduction */
if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) {
/* init montgomery reduction */
if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) {
goto ERR_P;
}
if ((err = mp_init(&mu)) != CRYPT_OK) {
}
if ((err = mp_init(&mu)) != CRYPT_OK) {
goto ERR_MP;
}
if ((err = mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
}
if ((err = mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
goto ERR_MU;
}
}
/* copy ones ... */
if ((err = mp_mulmod(A->x, mu, modulus, precomp[1]->x)) != CRYPT_OK) { goto ERR_MU; }

View File

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

View File

@ -311,8 +311,8 @@ unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state
}
#ifndef LTC_SMALL_CODE
/* do lots at a time, if there's enough to do */
while (outlen >= N*4) {
/* do lots at a time, if there's enough to do */
while (outlen >= N*4) {
SROUND(0);
SROUND(1);
SROUND(2);
@ -332,20 +332,20 @@ unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state
SROUND(16);
out += 4*N;
outlen -= 4*N;
}
}
#endif
/* do small or odd size buffers the slow way */
while (4 <= outlen) {
/* do small or odd size buffers the slow way */
while (4 <= outlen) {
cycle(c->R);
t = nltap(c);
XORWORD(t, out);
out += 4;
outlen -= 4;
}
}
/* handle any trailing bytes */
if (outlen != 0) {
/* handle any trailing bytes */
if (outlen != 0) {
cycle(c->R);
c->sbuf = nltap(c);
c->nbuf = 32;
@ -355,9 +355,9 @@ unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state
c->nbuf -= 8;
--outlen;
}
}
}
return tlen;
return tlen;
}
/**