507
int err, kl, x, y1, z;
509
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
510
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
513
out = fopen("ccm_tv.txt", "w");
514
fprintf(out, "CCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n"
515
"are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
516
"step repeated sufficiently. The nonce is fixed throughout at 13 bytes 000102...\n\n");
518
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
519
kl = cipher_descriptor[x].block_length;
521
/* skip ciphers which do not have 128 bit block sizes */
522
if (kl != 16) continue;
524
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
525
kl = cipher_descriptor[x].max_key_length;
527
fprintf(out, "CCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
530
for (z = 0; z < kl; z++) {
535
for (z = 0; z < cipher_descriptor[x].block_length; z++) {
539
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
540
for (z = 0; z < y1; z++) {
541
plaintext[z] = (unsigned char)(z & 255);
544
if ((err = ccm_memory(x, key, kl, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) {
545
printf("Error CCM'ing: %s\n", error_to_string(err));
548
fprintf(out, "%3d: ", y1);
549
for (z = 0; z < y1; z++) {
550
fprintf(out, "%02X", plaintext[z]);
553
for (z = 0; z <(int)len; z++) {
554
fprintf(out, "%02X", tag[z]);
558
/* forward the key */
559
for (z = 0; z < kl; z++) {
560
key[z] = tag[z % len];
570
int err, kl, x, y1, z;
572
unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
575
out = fopen("gcm_tv.txt", "w");
576
fprintf(out, "GCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n"
577
"are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
578
"step repeated sufficiently. The nonce is fixed throughout at 13 bytes 000102...\n\n");
580
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
581
kl = cipher_descriptor[x].block_length;
583
/* skip ciphers which do not have 128 bit block sizes */
584
if (kl != 16) continue;
586
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
587
kl = cipher_descriptor[x].max_key_length;
589
fprintf(out, "GCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
592
for (z = 0; z < kl; z++) {
596
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
597
for (z = 0; z < y1; z++) {
598
plaintext[z] = (unsigned char)(z & 255);
601
if ((err = gcm_memory(x, key, kl, plaintext, y1, plaintext, y1, plaintext, y1, plaintext, tag, &len, GCM_ENCRYPT)) != CRYPT_OK) {
602
printf("Error GCM'ing: %s\n", error_to_string(err));
605
fprintf(out, "%3d: ", y1);
606
for (z = 0; z < y1; z++) {
607
fprintf(out, "%02X", plaintext[z]);
610
for (z = 0; z <(int)len; z++) {
611
fprintf(out, "%02X", tag[z]);
615
/* forward the key */
616
for (z = 0; z < kl; z++) {
617
key[z] = tag[z % len];
498
625
void base64_gen(void)