2 * Copyright (C) 2005 Free Software Foundation
3 * Written by Simon Josefsson
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "rijndael-api-fst.h"
27 main (int argc, char *argv[])
30 rijndaelKeyInstance key;
31 rijndaelCipherInstance cipher;
32 char in[RIJNDAEL_BITSPERBLOCK / 8];
33 char out[RIJNDAEL_BITSPERBLOCK / 8];
34 char pt[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
35 "\x00\x00\x00\x00\x00\x00\x00\x00";
36 char ct[] = "\xC3\x4C\x05\x2C\xC0\xDA\x8D\x73"
37 "\x45\x1A\xFE\x5F\x03\xBE\x29\x7F";
40 rc = rijndaelMakeKey (&key, RIJNDAEL_DIR_ENCRYPT,
41 128, "00000000000000000000000000000000");
43 printf ("makeKey failed %d\n", rc);
45 rc = rijndaelCipherInit (&cipher, RIJNDAEL_MODE_ECB, NULL);
47 printf ("cipherInit failed %d\n", rc);
49 memset (in, 0, RIJNDAEL_BITSPERBLOCK / 8);
51 for (i = 0; i < 10000; i++)
53 rc = rijndaelBlockEncrypt (&cipher, &key, in, 128, out);
55 printf ("blockEncrypt failed %d\n", rc);
57 memcpy (in, out, RIJNDAEL_BITSPERBLOCK / 8);
60 if (memcmp (out, ct, RIJNDAEL_BITSPERBLOCK / 8) != 0)
63 printf ("expected:\n");
64 for (i = 0; i < RIJNDAEL_BITSPERBLOCK / 8; i++)
65 printf ("%02x ", ct[i] & 0xFF);
66 printf ("\ncomputed:\n");
67 for (i = 0; i < RIJNDAEL_BITSPERBLOCK / 8; i++)
68 printf ("%02x ", out[i] & 0xFF);
73 rc = rijndaelMakeKey (&key, RIJNDAEL_DIR_DECRYPT,
74 128, "00000000000000000000000000000000");
76 printf ("makeKey failed %d\n", rc);
78 rc = rijndaelCipherInit (&cipher, RIJNDAEL_MODE_ECB, NULL);
80 printf ("cipherInit failed %d\n", rc);
82 for (i = 0; i < 10000; i++)
84 memcpy (in, out, RIJNDAEL_BITSPERBLOCK / 8);
86 rc = rijndaelBlockDecrypt (&cipher, &key, in, 128, out);
88 printf ("blockEncrypt failed %d\n", rc);
91 if (memcmp (out, pt, RIJNDAEL_BITSPERBLOCK / 8) != 0)
94 printf ("expected:\n");
95 for (i = 0; i < RIJNDAEL_BITSPERBLOCK / 8; i++)
96 printf ("%02x ", pt[i] & 0xFF);
97 printf ("\ncomputed:\n");
98 for (i = 0; i < RIJNDAEL_BITSPERBLOCK / 8; i++)
99 printf ("%02x ", out[i] & 0xFF);