Bump versions, for 0.0.30.
[shishi.git] / tests / rijndael.c
blob94a9864834f7e87ad2dd71166e8bead82d799ac1
1 /* rijndael.c --- Shishi AES crypto self tests.
2 * Copyright (C) 2002, 2003, 2004 Simon Josefsson
4 * This file is part of Shishi.
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 2 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "utils.c"
24 #define IVLEN 16
26 #define KEY "chicken teriyaki"
27 #define IN "I would like the General Gau's Chicken, please, and wonton soup."
28 #define ZERO "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
30 static struct
32 const char *key;
33 size_t keylen;
34 const char *iv;
35 const char *in;
36 size_t inlen;
37 const char *out;
38 size_t outlen;
39 const char *nextiv;
40 } tv[] =
43 KEY, 16,
44 ZERO,
45 IN, 17,
46 "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f\x97",
47 17, "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"},
49 KEY, 16,
50 ZERO,
51 IN, 31,
52 "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
53 "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5", 31,
54 "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"},
56 KEY, 16,
57 ZERO,
58 IN, 32,
59 "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
60 "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
61 32, "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"},
63 KEY, 16,
64 ZERO,
65 IN, 47,
66 "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
67 "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
68 "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5", 47,
69 "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"},
71 KEY, 16,
72 ZERO,
73 IN, 48,
74 "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
75 "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
76 "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
77 48, "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"},
79 KEY, 16,
80 ZERO,
81 IN, 64,
82 "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
83 "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
84 "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
85 "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
86 64, "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"}
89 void
90 test (Shishi * handle)
92 char *out, *ivout;
93 size_t i;
94 int err;
96 if (debug)
97 shishi_cfg (handle, strdup ("verbose-crypto"));
99 for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
101 err = shishi_aes_cts (handle, 0,
102 tv[i].key, tv[i].keylen,
103 tv[i].iv, &ivout, tv[i].in, tv[i].inlen, &out);
105 if (debug)
107 printf ("input:\n");
108 hexprint (tv[i].in, tv[i].inlen);
109 printf ("output:\n");
110 hexprint (out, tv[i].inlen);
111 if (memcmp (out, tv[i].out, tv[i].outlen) != 0)
113 printf ("expected output:\n");
114 hexprint (tv[i].out, tv[i].outlen);
116 printf ("iv out:\n");
117 hexprint (ivout, IVLEN);
118 if (memcmp (ivout, tv[i].nextiv, IVLEN) != 0)
120 printf ("expected iv out:\n");
121 hexprint (tv[i].nextiv, IVLEN);
125 if (err)
126 fail ("shishi_aes_cts(%d) failed: %d\n", i, err);
127 else
129 if (memcmp (out, tv[i].out, tv[i].outlen) == 0)
130 success ("shishi_aes_cts(%d) OK\n", i);
131 else
132 fail ("shishi_aes_cts(%d) failure\n", i);
134 if (memcmp (ivout, tv[i].nextiv, IVLEN) == 0)
135 success ("shishi_aes_cts(%d) IV OK\n", i);
136 else
137 fail ("shishi_aes_cts(%d) failure IV\n", i);
139 free (out);
140 free (ivout);