Branch data Line data Source code
1 : : /* rijndael.c --- Shishi AES crypto self tests.
2 : : * Copyright (C) 2002, 2003, 2004, 2007 Simon Josefsson
3 : : *
4 : : * This file is part of Shishi.
5 : : *
6 : : * Shishi is free software; you can redistribute it and/or modify
7 : : * it under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation; either version 3 of the License, or
9 : : * (at your option) any later version.
10 : : *
11 : : * Shishi is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 : : * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 : : * Floor, Boston, MA 02110-1301, USA
20 : : *
21 : : */
22 : :
23 : : #include "utils.c"
24 : :
25 : : #define IVLEN 16
26 : :
27 : : #define KEY "chicken teriyaki"
28 : : #define IN "I would like the General Gau's Chicken, please, and wonton soup."
29 : : #define ZERO "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
30 : :
31 : : static struct
32 : : {
33 : : const char *key;
34 : : size_t keylen;
35 : : const char *iv;
36 : : const char *in;
37 : : size_t inlen;
38 : : const char *out;
39 : : size_t outlen;
40 : : const char *nextiv;
41 : : } tv[] =
42 : : {
43 : : {
44 : : KEY, 16,
45 : : ZERO,
46 : : IN, 17,
47 : : "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f\x97",
48 : : 17, "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"},
49 : : {
50 : : KEY, 16,
51 : : ZERO,
52 : : IN, 31,
53 : : "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
54 : : "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5", 31,
55 : : "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"},
56 : : {
57 : : KEY, 16,
58 : : ZERO,
59 : : IN, 32,
60 : : "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
61 : : "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
62 : : 32, "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"},
63 : : {
64 : : KEY, 16,
65 : : ZERO,
66 : : IN, 47,
67 : : "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
68 : : "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
69 : : "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5", 47,
70 : : "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"},
71 : : {
72 : : KEY, 16,
73 : : ZERO,
74 : : IN, 48,
75 : : "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
76 : : "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
77 : : "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
78 : : 48, "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"},
79 : : {
80 : : KEY, 16,
81 : : ZERO,
82 : : IN, 64,
83 : : "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
84 : : "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
85 : : "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
86 : : "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
87 : : 64, "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"}
88 : : };
89 : :
90 : : void
91 : 1 : test (Shishi * handle)
92 : : {
93 : : char *out, *ivout;
94 : : size_t i;
95 : : int err;
96 : :
97 [ - + ]: 1 : if (debug)
98 : 0 : shishi_cfg (handle, strdup ("verbose-crypto"));
99 : :
100 [ + + ]: 7 : for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
101 : : {
102 : 6 : err = shishi_aes_cts (handle, 0,
103 : : tv[i].key, tv[i].keylen,
104 : : tv[i].iv, &ivout, tv[i].in, tv[i].inlen, &out);
105 : :
106 [ - + ]: 6 : if (debug)
107 : : {
108 : 0 : printf ("input:\n");
109 : 0 : hexprint (tv[i].in, tv[i].inlen);
110 : 0 : printf ("output:\n");
111 : 0 : hexprint (out, tv[i].inlen);
112 [ # # ]: 0 : if (memcmp (out, tv[i].out, tv[i].outlen) != 0)
113 : : {
114 : 0 : printf ("expected output:\n");
115 : 0 : hexprint (tv[i].out, tv[i].outlen);
116 : : }
117 : 0 : printf ("iv out:\n");
118 : 0 : hexprint (ivout, IVLEN);
119 [ # # ]: 0 : if (memcmp (ivout, tv[i].nextiv, IVLEN) != 0)
120 : : {
121 : 0 : printf ("expected iv out:\n");
122 : 0 : hexprint (tv[i].nextiv, IVLEN);
123 : : }
124 : : }
125 : :
126 [ - + ]: 6 : if (err)
127 : 0 : fail ("shishi_aes_cts(%d) failed: %d\n", i, err);
128 : : else
129 : : {
130 [ + - ]: 6 : if (memcmp (out, tv[i].out, tv[i].outlen) == 0)
131 : 6 : success ("shishi_aes_cts(%d) OK\n", i);
132 : : else
133 : 0 : fail ("shishi_aes_cts(%d) failure\n", i);
134 : :
135 [ + - ]: 6 : if (memcmp (ivout, tv[i].nextiv, IVLEN) == 0)
136 : 6 : success ("shishi_aes_cts(%d) IV OK\n", i);
137 : : else
138 : 0 : fail ("shishi_aes_cts(%d) failure IV\n", i);
139 : :
140 : 6 : free (out);
141 : 6 : free (ivout);
142 : : }
143 : : }
144 : 1 : }
|