Skip to content

Commit 332f66d

Browse files
authored
Merge pull request #452 from libtom/pr/wycheproof-ccm
Wycheproof failing CCM test - invalid tag len
2 parents 983fd25 + 9a0df8d commit 332f66d

File tree

5 files changed

+2142
-342
lines changed

5 files changed

+2142
-342
lines changed

demos/tv_gen.c

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,12 @@ static void ocb3_gen(void)
507507
static void ccm_gen(void)
508508
{
509509
int err, kl, x, y1, z;
510+
unsigned int t;
510511
FILE *out;
511512
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
512-
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
513+
plaintext[MAXBLOCKSIZE*2], tag[16];
513514
unsigned long len;
515+
const unsigned int taglen[] = {4, 6, 8, 10, 12, 14, 16};
514516

515517
out = fopen("ccm_tv.txt", "w");
516518
fprintf(out, "CCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n"
@@ -538,32 +540,34 @@ static void ccm_gen(void)
538540
nonce[z] = z;
539541
}
540542

541-
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
542-
for (z = 0; z < y1; z++) {
543-
plaintext[z] = (unsigned char)(z & 255);
544-
}
545-
len = sizeof(tag);
546-
if ((err = ccm_memory(x, key, kl, NULL, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) {
547-
printf("Error CCM'ing: %s\n", error_to_string(err));
548-
exit(EXIT_FAILURE);
549-
}
550-
if (len == 0) {
551-
printf("Error CCM'ing: zero length\n");
552-
exit(EXIT_FAILURE);
553-
}
554-
fprintf(out, "%3d: ", y1);
555-
for (z = 0; z < y1; z++) {
556-
fprintf(out, "%02X", plaintext[z]);
557-
}
558-
fprintf(out, ", ");
559-
for (z = 0; z <(int)len; z++) {
560-
fprintf(out, "%02X", tag[z]);
561-
}
562-
fprintf(out, "\n");
563-
564-
/* forward the key */
565-
for (z = 0; z < kl; z++) {
566-
key[z] = tag[z % len];
543+
for (t = 0; t < sizeof(taglen)/sizeof(taglen[0]); ++t) {
544+
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
545+
for (z = 0; z < y1; z++) {
546+
plaintext[z] = (unsigned char)(z & 255);
547+
}
548+
len = taglen[t];
549+
if ((err = ccm_memory(x, key, kl, NULL, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) {
550+
printf("Error CCM'ing: %s\n", error_to_string(err));
551+
exit(EXIT_FAILURE);
552+
}
553+
if (len == 0) {
554+
printf("Error CCM'ing: zero length\n");
555+
exit(EXIT_FAILURE);
556+
}
557+
fprintf(out, "%3d: ", y1);
558+
for (z = 0; z < y1; z++) {
559+
fprintf(out, "%02X", plaintext[z]);
560+
}
561+
fprintf(out, ", ");
562+
for (z = 0; z <(int)len; z++) {
563+
fprintf(out, "%02X", tag[z]);
564+
}
565+
fprintf(out, "\n");
566+
567+
/* forward the key */
568+
for (z = 0; z < kl; z++) {
569+
key[z] = tag[z % len];
570+
}
567571
}
568572
}
569573
fprintf(out, "\n");

0 commit comments

Comments
 (0)