annotate demos/tv_gen.c @ 191:1c15b283127b libtomcrypt-orig

Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 13:23:02 +0000
parents 5d99163f7e32
children 39d5d58461d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
1 #include <tomcrypt.h>
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 void reg_algs(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 {
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
5 int err;
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
6
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 #ifdef RIJNDAEL
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 register_cipher (&aes_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 #ifdef BLOWFISH
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 register_cipher (&blowfish_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 #ifdef XTEA
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 register_cipher (&xtea_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 #ifdef RC5
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 register_cipher (&rc5_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 #ifdef RC6
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 register_cipher (&rc6_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 #ifdef SAFERP
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 register_cipher (&saferp_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #ifdef TWOFISH
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 register_cipher (&twofish_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #ifdef SAFER
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 register_cipher (&safer_k64_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 register_cipher (&safer_sk64_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 register_cipher (&safer_k128_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 register_cipher (&safer_sk128_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 #ifdef RC2
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 register_cipher (&rc2_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 #ifdef DES
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 register_cipher (&des_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 register_cipher (&des3_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 #ifdef CAST5
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 register_cipher (&cast5_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 #ifdef NOEKEON
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 register_cipher (&noekeon_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 #ifdef SKIPJACK
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 register_cipher (&skipjack_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 #endif
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
50 #ifdef ANUBIS
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
51 register_cipher (&anubis_desc);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
52 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
53 #ifdef KHAZAD
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
54 register_cipher (&khazad_desc);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
55 #endif
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 #ifdef TIGER
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 register_hash (&tiger_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 #ifdef MD2
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 register_hash (&md2_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 #ifdef MD4
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 register_hash (&md4_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 #ifdef MD5
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 register_hash (&md5_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 #ifdef SHA1
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 register_hash (&sha1_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 #ifdef SHA224
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 register_hash (&sha224_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 #ifdef SHA256
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 register_hash (&sha256_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 #ifdef SHA384
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 register_hash (&sha384_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 #ifdef SHA512
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 register_hash (&sha512_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 #ifdef RIPEMD128
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 register_hash (&rmd128_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 #ifdef RIPEMD160
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 register_hash (&rmd160_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 #endif
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 #ifdef WHIRLPOOL
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 register_hash (&whirlpool_desc);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 #endif
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
93 #ifdef CHC_HASH
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
94 register_hash(&chc_desc);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
95 if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
96 printf("chc_register error: %s\n", error_to_string(err));
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
97 exit(EXIT_FAILURE);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
98 }
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
99 #endif
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
100
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 void hash_gen(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 {
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
105 unsigned char md[MAXBLOCKSIZE], *buf;
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 unsigned long outlen, x, y, z;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 FILE *out;
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
108 int err;
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 out = fopen("hash_tv.txt", "w");
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
111 if (out == NULL) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
112 perror("can't open hash_tv");
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
113 }
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 fprintf(out, "Hash Test Vectors:\n\nThese are the hashes of nn bytes '00 01 02 03 .. (nn-1)'\n\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 for (x = 0; hash_descriptor[x].name != NULL; x++) {
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
117 buf = XMALLOC(2 * hash_descriptor[x].blocksize + 1);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
118 if (buf == NULL) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
119 perror("can't alloc mem");
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
120 exit(EXIT_FAILURE);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
121 }
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 fprintf(out, "Hash: %s\n", hash_descriptor[x].name);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 for (y = 0; y <= (hash_descriptor[x].blocksize * 2); y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 for (z = 0; z < y; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 buf[z] = (unsigned char)(z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 outlen = sizeof(md);
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
128 if ((err = hash_memory(x, buf, y, md, &outlen)) != CRYPT_OK) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
129 printf("hash_memory error: %s\n", error_to_string(err));
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
130 exit(EXIT_FAILURE);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
131 }
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 fprintf(out, "%3lu: ", y);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 for (z = 0; z < outlen; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 fprintf(out, "%02X", md[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 fprintf(out, "\n");
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
139 XFREE(buf);
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 fclose(out);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 void cipher_gen(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 {
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
146 unsigned char *key, pt[MAXBLOCKSIZE];
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 unsigned long x, y, z, w;
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
148 int err, kl, lastkl;
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 FILE *out;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 symmetric_key skey;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 out = fopen("cipher_tv.txt", "w");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 fprintf(out,
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 "Cipher Test Vectors\n\nThese are test encryptions with key of nn bytes '00 01 02 03 .. (nn-1)' and original PT of the same style.\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 "The output of step N is used as the key and plaintext for step N+1 (key bytes repeated as required to fill the key)\n\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 fprintf(out, "Cipher: %s\n", cipher_descriptor[x].name);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 /* three modes, smallest, medium, large keys */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 lastkl = 10000;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 for (y = 0; y < 3; y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 switch (y) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 case 0: kl = cipher_descriptor[x].min_key_length; break;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 case 1: kl = (cipher_descriptor[x].min_key_length + cipher_descriptor[x].max_key_length)/2; break;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 case 2: kl = cipher_descriptor[x].max_key_length; break;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 }
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
169 if ((err = cipher_descriptor[x].keysize(&kl)) != CRYPT_OK) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
170 printf("keysize error: %s\n", error_to_string(err));
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
171 exit(EXIT_FAILURE);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
172 }
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 if (kl == lastkl) break;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 lastkl = kl;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 fprintf(out, "Key Size: %d bytes\n", kl);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
177 key = XMALLOC(kl);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
178 if (key == NULL) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
179 perror("can't malloc memory");
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
180 exit(EXIT_FAILURE);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
181 }
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
182
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 for (z = 0; (int)z < kl; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184 key[z] = (unsigned char)z;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 }
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
186 if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
187 printf("setup error: %s\n", error_to_string(err));
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
188 exit(EXIT_FAILURE);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
189 }
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 pt[z] = (unsigned char)z;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 for (w = 0; w < 50; w++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 cipher_descriptor[x].ecb_encrypt(pt, pt, &skey);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196 fprintf(out, "%2lu: ", w);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197 for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 fprintf(out, "%02X", pt[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 /* reschedule a new key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203 for (z = 0; z < (unsigned long)kl; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 key[z] = pt[z % cipher_descriptor[x].block_length];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 }
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
206 if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
207 printf("cipher setup2 error: %s\n", error_to_string(err));
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
208 exit(EXIT_FAILURE);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
209 }
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211 fprintf(out, "\n");
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
212 XFREE(key);
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216 fclose(out);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
218
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219 void hmac_gen(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220 {
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
221 unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], *input;
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
222 int x, y, z, err;
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223 FILE *out;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
224 unsigned long len;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
225
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
226 out = fopen("hmac_tv.txt", "w");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228 fprintf(out,
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 "HMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are HMACed. The initial key is\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230 "of the same format (the same length as the HASH output size). The HMAC key in step N+1 is the HMAC output of\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 "step N.\n\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 for (x = 0; hash_descriptor[x].name != NULL; x++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234 fprintf(out, "HMAC-%s\n", hash_descriptor[x].name);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236 /* initial key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 for (y = 0; y < (int)hash_descriptor[x].hashsize; y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 key[y] = (y&255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239 }
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
240
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
241 input = XMALLOC(hash_descriptor[x].blocksize * 2 + 1);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
242 if (input == NULL) {
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
243 perror("Can't malloc memory");
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
244 exit(EXIT_FAILURE);
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
245 }
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247 for (y = 0; y <= (int)(hash_descriptor[x].blocksize * 2); y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248 for (z = 0; z < y; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 input[z] = (unsigned char)(z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
251 len = sizeof(output);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252 if ((err = hmac_memory(x, key, hash_descriptor[x].hashsize, input, y, output, &len)) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 printf("Error hmacing: %s\n", error_to_string(err));
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 exit(EXIT_FAILURE);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 fprintf(out, "%3d: ", y);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 for (z = 0; z <(int) len; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258 fprintf(out, "%02X", output[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262 /* forward the key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263 memcpy(key, output, hash_descriptor[x].hashsize);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
264 }
143
5d99163f7e32 import of libtomcrypt 0.99
Matt Johnston <matt@ucc.asn.au>
parents: 3
diff changeset
265 XFREE(input);
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
267 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
268 fclose(out);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
269 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
271 void omac_gen(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
272 {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273 unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
274 int err, x, y, z, kl;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275 FILE *out;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276 unsigned long len;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
277
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
278 out = fopen("omac_tv.txt", "w");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
279
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280 fprintf(out,
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
281 "OMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are OMAC'ed. The initial key is\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282 "of the same format (length specified per cipher). The OMAC key in step N+1 is the OMAC output of\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 "step N (repeated as required to fill the array).\n\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286 kl = cipher_descriptor[x].block_length;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
288 /* skip ciphers which do not have 64 or 128 bit block sizes */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289 if (kl != 8 && kl != 16) continue;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
292 kl = cipher_descriptor[x].max_key_length;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
293 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
294 fprintf(out, "OMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296 /* initial key/block */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
297 for (y = 0; y < kl; y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
298 key[y] = (y & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
301 for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302 for (z = 0; z < y; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
303 input[z] = (unsigned char)(z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
304 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
305 len = sizeof(output);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 if ((err = omac_memory(x, key, kl, input, y, output, &len)) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307 printf("Error omacing: %s\n", error_to_string(err));
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
308 exit(EXIT_FAILURE);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
309 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310 fprintf(out, "%3d: ", y);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
311 for (z = 0; z <(int)len; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
312 fprintf(out, "%02X", output[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316 /* forward the key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
317 for (z = 0; z < kl; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 key[z] = output[z % len];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323 fclose(out);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
324 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 void pmac_gen(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
327 {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
328 unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
329 int err, x, y, z, kl;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
330 FILE *out;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
331 unsigned long len;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
332
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
333 out = fopen("pmac_tv.txt", "w");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
334
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
335 fprintf(out,
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
336 "PMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are OMAC'ed. The initial key is\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
337 "of the same format (length specified per cipher). The OMAC key in step N+1 is the OMAC output of\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
338 "step N (repeated as required to fill the array).\n\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
339
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
340 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
341 kl = cipher_descriptor[x].block_length;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
342
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
343 /* skip ciphers which do not have 64 or 128 bit block sizes */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
344 if (kl != 8 && kl != 16) continue;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
345
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
346 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
347 kl = cipher_descriptor[x].max_key_length;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
348 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
349 fprintf(out, "PMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
350
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
351 /* initial key/block */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
352 for (y = 0; y < kl; y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
353 key[y] = (y & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
354 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
355
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356 for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
357 for (z = 0; z < y; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
358 input[z] = (unsigned char)(z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
359 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
360 len = sizeof(output);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
361 if ((err = pmac_memory(x, key, kl, input, y, output, &len)) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
362 printf("Error omacing: %s\n", error_to_string(err));
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
363 exit(EXIT_FAILURE);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
364 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
365 fprintf(out, "%3d: ", y);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
366 for (z = 0; z <(int)len; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
367 fprintf(out, "%02X", output[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
368 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
369 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
370
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
371 /* forward the key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
372 for (z = 0; z < kl; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
373 key[z] = output[z % len];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
374 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
375 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
376 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
377 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378 fclose(out);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
379 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
381 void eax_gen(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
382 {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
383 int err, kl, x, y1, z;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
384 FILE *out;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
385 unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2],
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386 plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
387 unsigned long len;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
389 out = fopen("eax_tv.txt", "w");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390 fprintf(out, "EAX Test Vectors. Uses the 00010203...NN-1 pattern for header/nonce/plaintext/key. The outputs\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
391 "are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
392 "step repeated sufficiently.\n\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
393
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
394 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
395 kl = cipher_descriptor[x].block_length;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
396
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
397 /* skip ciphers which do not have 64 or 128 bit block sizes */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
398 if (kl != 8 && kl != 16) continue;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
399
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
400 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
401 kl = cipher_descriptor[x].max_key_length;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
402 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
403 fprintf(out, "EAX-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
404
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
405 /* the key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406 for (z = 0; z < kl; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
407 key[z] = (z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
408 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
411 for (z = 0; z < y1; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412 plaintext[z] = (unsigned char)(z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413 nonce[z] = (unsigned char)(z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
414 header[z] = (unsigned char)(z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
416 len = sizeof(tag);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
417 if ((err = eax_encrypt_authenticate_memory(x, key, kl, nonce, y1, header, y1, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
418 printf("Error EAX'ing: %s\n", error_to_string(err));
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419 exit(EXIT_FAILURE);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
420 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
421 fprintf(out, "%3d: ", y1);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
422 for (z = 0; z < y1; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423 fprintf(out, "%02X", plaintext[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
424 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425 fprintf(out, ", ");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
426 for (z = 0; z <(int)len; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
427 fprintf(out, "%02X", tag[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
428 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
429 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
430
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
431 /* forward the key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
432 for (z = 0; z < kl; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
433 key[z] = tag[z % len];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
434 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
435 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
437 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
438 fclose(out);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
439 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
440
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441 void ocb_gen(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
442 {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
443 int err, kl, x, y1, z;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
444 FILE *out;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
445 unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
446 plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
447 unsigned long len;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
448
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
449 out = fopen("ocb_tv.txt", "w");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
450 fprintf(out, "OCB Test Vectors. Uses the 00010203...NN-1 pattern for nonce/plaintext/key. The outputs\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
451 "are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
452 "step repeated sufficiently. The nonce is fixed throughout.\n\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
453
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
454 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
455 kl = cipher_descriptor[x].block_length;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
456
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
457 /* skip ciphers which do not have 64 or 128 bit block sizes */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
458 if (kl != 8 && kl != 16) continue;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
459
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
460 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461 kl = cipher_descriptor[x].max_key_length;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
463 fprintf(out, "OCB-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
464
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
465 /* the key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
466 for (z = 0; z < kl; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
467 key[z] = (z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
468 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
469
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
470 /* fixed nonce */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
471 for (z = 0; z < cipher_descriptor[x].block_length; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472 nonce[z] = z;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
474
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
475 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
476 for (z = 0; z < y1; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
477 plaintext[z] = (unsigned char)(z & 255);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
478 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
479 len = sizeof(tag);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
480 if ((err = ocb_encrypt_authenticate_memory(x, key, kl, nonce, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
481 printf("Error OCB'ing: %s\n", error_to_string(err));
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
482 exit(EXIT_FAILURE);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
483 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
484 fprintf(out, "%3d: ", y1);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
485 for (z = 0; z < y1; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
486 fprintf(out, "%02X", plaintext[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
487 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
488 fprintf(out, ", ");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
489 for (z = 0; z <(int)len; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
490 fprintf(out, "%02X", tag[z]);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
491 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
492 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
493
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
494 /* forward the key */
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
495 for (z = 0; z < kl; z++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
496 key[z] = tag[z % len];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
497 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
498 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
499 fprintf(out, "\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
500 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
501 fclose(out);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
502 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
503
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
504
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
505 void ccm_gen(void)
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
506 {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
507 int err, kl, x, y1, z;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
508 FILE *out;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
509 unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
510 plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
511 unsigned long len;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
512
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
513 out = fopen("ccm_tv.txt", "w");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
514 fprintf(out, "CCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n"
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
515 "are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
516 "step repeated sufficiently. The nonce is fixed throughout at 13 bytes 000102...\n\n");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
517
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
518 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
519 kl = cipher_descriptor[x].block_length;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
520
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
521 /* skip ciphers which do not have 128 bit block sizes */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
522 if (kl != 16) continue;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
523
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
524 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
525 kl = cipher_descriptor[x].max_key_length;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
526 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
527 fprintf(out, "CCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
528
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
529 /* the key */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
530 for (z = 0; z < kl; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
531 key[z] = (z & 255);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
532 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
533
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
534 /* fixed nonce */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
535 for (z = 0; z < cipher_descriptor[x].block_length; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
536 nonce[z] = z;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
537 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
538
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
539 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
540 for (z = 0; z < y1; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
541 plaintext[z] = (unsigned char)(z & 255);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
542 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
543 len = sizeof(tag);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
544 if ((err = ccm_memory(x, key, kl, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
545 printf("Error CCM'ing: %s\n", error_to_string(err));
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
546 exit(EXIT_FAILURE);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
547 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
548 fprintf(out, "%3d: ", y1);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
549 for (z = 0; z < y1; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
550 fprintf(out, "%02X", plaintext[z]);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
551 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
552 fprintf(out, ", ");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
553 for (z = 0; z <(int)len; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
554 fprintf(out, "%02X", tag[z]);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
555 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
556 fprintf(out, "\n");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
557
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
558 /* forward the key */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
559 for (z = 0; z < kl; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
560 key[z] = tag[z % len];
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
561 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
562 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
563 fprintf(out, "\n");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
564 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
565 fclose(out);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
566 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
567
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
568 void gcm_gen(void)
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
569 {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
570 int err, kl, x, y1, z;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
571 FILE *out;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
572 unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
573 unsigned long len;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
574
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
575 out = fopen("gcm_tv.txt", "w");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
576 fprintf(out, "GCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n"
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
577 "are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
578 "step repeated sufficiently. The nonce is fixed throughout at 13 bytes 000102...\n\n");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
579
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
580 for (x = 0; cipher_descriptor[x].name != NULL; x++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
581 kl = cipher_descriptor[x].block_length;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
582
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
583 /* skip ciphers which do not have 128 bit block sizes */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
584 if (kl != 16) continue;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
585
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
586 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
587 kl = cipher_descriptor[x].max_key_length;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
588 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
589 fprintf(out, "GCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
590
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
591 /* the key */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
592 for (z = 0; z < kl; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
593 key[z] = (z & 255);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
594 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
595
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
596 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
597 for (z = 0; z < y1; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
598 plaintext[z] = (unsigned char)(z & 255);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
599 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
600 len = sizeof(tag);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
601 if ((err = gcm_memory(x, key, kl, plaintext, y1, plaintext, y1, plaintext, y1, plaintext, tag, &len, GCM_ENCRYPT)) != CRYPT_OK) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
602 printf("Error GCM'ing: %s\n", error_to_string(err));
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
603 exit(EXIT_FAILURE);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
604 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
605 fprintf(out, "%3d: ", y1);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
606 for (z = 0; z < y1; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
607 fprintf(out, "%02X", plaintext[z]);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
608 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
609 fprintf(out, ", ");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
610 for (z = 0; z <(int)len; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
611 fprintf(out, "%02X", tag[z]);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
612 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
613 fprintf(out, "\n");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
614
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
615 /* forward the key */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
616 for (z = 0; z < kl; z++) {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
617 key[z] = tag[z % len];
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
618 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
619 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
620 fprintf(out, "\n");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
621 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
622 fclose(out);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
623 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
624
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
625 void base64_gen(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
626 {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
627 FILE *out;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
628 unsigned char dst[256], src[32];
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
629 unsigned long x, y, len;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
630
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
631 out = fopen("base64_tv.txt", "w");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
632 fprintf(out, "Base64 vectors. These are the base64 encodings of the strings 00,01,02...NN-1\n\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
633 for (x = 0; x <= 32; x++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
634 for (y = 0; y < x; y++) {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
635 src[y] = y;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
636 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
637 len = sizeof(dst);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
638 base64_encode(src, x, dst, &len);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
639 fprintf(out, "%2lu: %s\n", x, dst);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
640 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
641 fclose(out);
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
642 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
643
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
644 int main(void)
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
645 {
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
646 reg_algs();
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
647 printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
648 printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
649 printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
650 printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
651 printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
652 printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
653 printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n");
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
654 printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n");
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents: 143
diff changeset
655 printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n");
3
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
656 printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n");
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
657 return 0;
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
658 }
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
659
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
660
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
661
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
662
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
663
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
664
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
665
7faae8f46238 Branch renaming
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
666