fix indentation

This commit is contained in:
Francois Perrad 2018-10-29 18:55:32 +01:00
parent f413335b2a
commit acf3fcda84

View File

@ -111,140 +111,140 @@ int ccm_test(void)
}, },
}; };
unsigned long taglen, x, y; unsigned long taglen, x, y;
unsigned char buf[64], buf2[64], tag[16], tag2[16], tag3[16], zero[64]; unsigned char buf[64], buf2[64], tag[16], tag2[16], tag3[16], zero[64];
int err, idx; int err, idx;
symmetric_key skey; symmetric_key skey;
ccm_state ccm; ccm_state ccm;
zeromem(zero, 64); zeromem(zero, 64);
idx = find_cipher("aes"); idx = find_cipher("aes");
if (idx == -1) { if (idx == -1) {
idx = find_cipher("rijndael"); idx = find_cipher("rijndael");
if (idx == -1) { if (idx == -1) {
return CRYPT_NOP; return CRYPT_NOP;
}
}
for (x = 0; x < (sizeof(tests)/sizeof(tests[0])); x++) {
for (y = 0; y < 2; y++) {
taglen = tests[x].taglen;
if (y == 0) {
if ((err = cipher_descriptor[idx].setup(tests[x].key, 16, 0, &skey)) != CRYPT_OK) {
return err;
}
if ((err = ccm_memory(idx,
tests[x].key, 16,
&skey,
tests[x].nonce, tests[x].noncelen,
tests[x].header, tests[x].headerlen,
(unsigned char*)tests[x].pt, tests[x].ptlen,
buf,
tag, &taglen, 0)) != CRYPT_OK) {
return err;
}
/* run a second time to make sure skey is not touched */
if ((err = ccm_memory(idx,
tests[x].key, 16,
&skey,
tests[x].nonce, tests[x].noncelen,
tests[x].header, tests[x].headerlen,
(unsigned char*)tests[x].pt, tests[x].ptlen,
buf,
tag, &taglen, 0)) != CRYPT_OK) {
return err;
}
} else {
if ((err = ccm_init(&ccm, idx, tests[x].key, 16, tests[x].ptlen, tests[x].taglen, tests[x].headerlen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_add_nonce(&ccm, tests[x].nonce, tests[x].noncelen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_add_aad(&ccm, tests[x].header, tests[x].headerlen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_process(&ccm, (unsigned char*)tests[x].pt, tests[x].ptlen, buf, CCM_ENCRYPT)) != CRYPT_OK) {
return err;
}
if ((err = ccm_done(&ccm, tag, &taglen)) != CRYPT_OK) {
return err;
}
} }
}
if (compare_testvector(buf, tests[x].ptlen, tests[x].ct, tests[x].ptlen, "CCM encrypt data", x)) { for (x = 0; x < (sizeof(tests)/sizeof(tests[0])); x++) {
return CRYPT_FAIL_TESTVECTOR; for (y = 0; y < 2; y++) {
}
if (compare_testvector(tag, taglen, tests[x].tag, tests[x].taglen, "CCM encrypt tag", x)) {
return CRYPT_FAIL_TESTVECTOR;
}
if (y == 0) {
XMEMCPY(tag3, tests[x].tag, tests[x].taglen);
taglen = tests[x].taglen; taglen = tests[x].taglen;
if ((err = ccm_memory(idx, if (y == 0) {
tests[x].key, 16, if ((err = cipher_descriptor[idx].setup(tests[x].key, 16, 0, &skey)) != CRYPT_OK) {
NULL, return err;
tests[x].nonce, tests[x].noncelen, }
tests[x].header, tests[x].headerlen,
buf2, tests[x].ptlen, if ((err = ccm_memory(idx,
buf, tests[x].key, 16,
tag3, &taglen, 1 )) != CRYPT_OK) { &skey,
return err; tests[x].nonce, tests[x].noncelen,
tests[x].header, tests[x].headerlen,
(unsigned char*)tests[x].pt, tests[x].ptlen,
buf,
tag, &taglen, 0)) != CRYPT_OK) {
return err;
}
/* run a second time to make sure skey is not touched */
if ((err = ccm_memory(idx,
tests[x].key, 16,
&skey,
tests[x].nonce, tests[x].noncelen,
tests[x].header, tests[x].headerlen,
(unsigned char*)tests[x].pt, tests[x].ptlen,
buf,
tag, &taglen, 0)) != CRYPT_OK) {
return err;
}
} else {
if ((err = ccm_init(&ccm, idx, tests[x].key, 16, tests[x].ptlen, tests[x].taglen, tests[x].headerlen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_add_nonce(&ccm, tests[x].nonce, tests[x].noncelen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_add_aad(&ccm, tests[x].header, tests[x].headerlen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_process(&ccm, (unsigned char*)tests[x].pt, tests[x].ptlen, buf, CCM_ENCRYPT)) != CRYPT_OK) {
return err;
}
if ((err = ccm_done(&ccm, tag, &taglen)) != CRYPT_OK) {
return err;
}
} }
} else {
if ((err = ccm_init(&ccm, idx, tests[x].key, 16, tests[x].ptlen, tests[x].taglen, tests[x].headerlen)) != CRYPT_OK) { if (compare_testvector(buf, tests[x].ptlen, tests[x].ct, tests[x].ptlen, "CCM encrypt data", x)) {
return err; return CRYPT_FAIL_TESTVECTOR;
} }
if ((err = ccm_add_nonce(&ccm, tests[x].nonce, tests[x].noncelen)) != CRYPT_OK) { if (compare_testvector(tag, taglen, tests[x].tag, tests[x].taglen, "CCM encrypt tag", x)) {
return err; return CRYPT_FAIL_TESTVECTOR;
} }
if ((err = ccm_add_aad(&ccm, tests[x].header, tests[x].headerlen)) != CRYPT_OK) {
return err; if (y == 0) {
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,
tests[x].header, tests[x].headerlen,
buf2, tests[x].ptlen,
buf,
tag3, &taglen, 1 )) != CRYPT_OK) {
return err;
}
} else {
if ((err = ccm_init(&ccm, idx, tests[x].key, 16, tests[x].ptlen, tests[x].taglen, tests[x].headerlen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_add_nonce(&ccm, tests[x].nonce, tests[x].noncelen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_add_aad(&ccm, tests[x].header, tests[x].headerlen)) != CRYPT_OK) {
return err;
}
if ((err = ccm_process(&ccm, buf2, tests[x].ptlen, buf, CCM_DECRYPT)) != CRYPT_OK) {
return err;
}
if ((err = ccm_done(&ccm, tag2, &taglen)) != CRYPT_OK) {
return err;
}
} }
if ((err = ccm_process(&ccm, buf2, tests[x].ptlen, buf, CCM_DECRYPT)) != CRYPT_OK) {
return err;
}
if ((err = ccm_done(&ccm, tag2, &taglen)) != CRYPT_OK) {
return err;
}
}
if (compare_testvector(buf2, tests[x].ptlen, tests[x].pt, tests[x].ptlen, "CCM decrypt data", x)) { if (compare_testvector(buf2, tests[x].ptlen, tests[x].pt, tests[x].ptlen, "CCM decrypt data", x)) {
return CRYPT_FAIL_TESTVECTOR; return CRYPT_FAIL_TESTVECTOR;
} }
if (y == 0) { if (y == 0) {
/* check if decryption with the wrong tag does not reveal the plaintext */ /* check if decryption with the wrong tag does not reveal the plaintext */
XMEMCPY(tag3, tests[x].tag, tests[x].taglen); XMEMCPY(tag3, tests[x].tag, tests[x].taglen);
tag3[0] ^= 0xff; /* set the tag to the wrong value */ tag3[0] ^= 0xff; /* set the tag to the wrong value */
taglen = tests[x].taglen; taglen = tests[x].taglen;
if ((err = ccm_memory(idx, if ((err = ccm_memory(idx,
tests[x].key, 16, tests[x].key, 16,
NULL, NULL,
tests[x].nonce, tests[x].noncelen, tests[x].nonce, tests[x].noncelen,
tests[x].header, tests[x].headerlen, tests[x].header, tests[x].headerlen,
buf2, tests[x].ptlen, buf2, tests[x].ptlen,
buf, buf,
tag3, &taglen, 1 )) != CRYPT_ERROR) { tag3, &taglen, 1 )) != CRYPT_ERROR) {
return CRYPT_FAIL_TESTVECTOR; return CRYPT_FAIL_TESTVECTOR;
} }
if (compare_testvector(buf2, tests[x].ptlen, zero, tests[x].ptlen, "CCM decrypt wrong tag", x)) { if (compare_testvector(buf2, tests[x].ptlen, zero, tests[x].ptlen, "CCM decrypt wrong tag", x)) {
return CRYPT_FAIL_TESTVECTOR; return CRYPT_FAIL_TESTVECTOR;
} }
} else { } else {
if (compare_testvector(tag2, taglen, tests[x].tag, tests[x].taglen, "CCM decrypt tag", x)) { if (compare_testvector(tag2, taglen, tests[x].tag, tests[x].taglen, "CCM decrypt tag", x)) {
return CRYPT_FAIL_TESTVECTOR; return CRYPT_FAIL_TESTVECTOR;
} }
} }
if (y == 0) { if (y == 0) {
cipher_descriptor[idx].done(&skey); cipher_descriptor[idx].done(&skey);
}
} }
} }
}
/* wycheproof failing test - https://github.com/libtom/libtomcrypt/pull/452 */ /* wycheproof failing test - https://github.com/libtom/libtomcrypt/pull/452 */
{ {
@ -273,7 +273,7 @@ int ccm_test(void)
} }
} }
return CRYPT_OK; return CRYPT_OK;
#endif #endif
} }