2 * Copyright (C) 2005, 2010-2017 Free Software Foundation, Inc.
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 3 of the License, or
8 * (at your option) any later version.
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, see <https://www.gnu.org/licenses/>. */
22 #include "rijndael-api-fst.h"
25 main (int argc
, char *argv
[])
28 rijndaelKeyInstance key
;
29 rijndaelCipherInstance cipher
;
30 char in
[RIJNDAEL_BITSPERBLOCK
/ 8];
31 char out
[RIJNDAEL_BITSPERBLOCK
/ 8];
32 char pt
[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
33 "\x00\x00\x00\x00\x00\x00\x00\x00";
34 char ct
[] = "\xC3\x4C\x05\x2C\xC0\xDA\x8D\x73"
35 "\x45\x1A\xFE\x5F\x03\xBE\x29\x7F";
38 rc
= rijndaelMakeKey (&key
, RIJNDAEL_DIR_ENCRYPT
,
39 128, "00000000000000000000000000000000");
41 printf ("makeKey failed %d\n", rc
);
43 rc
= rijndaelCipherInit (&cipher
, RIJNDAEL_MODE_ECB
, NULL
);
45 printf ("cipherInit failed %d\n", rc
);
47 memset (in
, 0, RIJNDAEL_BITSPERBLOCK
/ 8);
49 for (i
= 0; i
< 10000; i
++)
51 rc
= rijndaelBlockEncrypt (&cipher
, &key
, in
, 128, out
);
53 printf ("blockEncrypt failed %d\n", rc
);
55 memcpy (in
, out
, RIJNDAEL_BITSPERBLOCK
/ 8);
58 if (memcmp (out
, ct
, RIJNDAEL_BITSPERBLOCK
/ 8) != 0)
61 printf ("expected:\n");
62 for (i
= 0; i
< RIJNDAEL_BITSPERBLOCK
/ 8; i
++)
63 printf ("%02x ", ct
[i
] & 0xFF);
64 printf ("\ncomputed:\n");
65 for (i
= 0; i
< RIJNDAEL_BITSPERBLOCK
/ 8; i
++)
66 printf ("%02x ", out
[i
] & 0xFF);
71 rc
= rijndaelMakeKey (&key
, RIJNDAEL_DIR_DECRYPT
,
72 128, "00000000000000000000000000000000");
74 printf ("makeKey failed %d\n", rc
);
76 rc
= rijndaelCipherInit (&cipher
, RIJNDAEL_MODE_ECB
, NULL
);
78 printf ("cipherInit failed %d\n", rc
);
80 for (i
= 0; i
< 10000; i
++)
82 memcpy (in
, out
, RIJNDAEL_BITSPERBLOCK
/ 8);
84 rc
= rijndaelBlockDecrypt (&cipher
, &key
, in
, 128, out
);
86 printf ("blockEncrypt failed %d\n", rc
);
89 if (memcmp (out
, pt
, RIJNDAEL_BITSPERBLOCK
/ 8) != 0)
92 printf ("expected:\n");
93 for (i
= 0; i
< RIJNDAEL_BITSPERBLOCK
/ 8; i
++)
94 printf ("%02x ", pt
[i
] & 0xFF);
95 printf ("\ncomputed:\n");
96 for (i
= 0; i
< RIJNDAEL_BITSPERBLOCK
/ 8; i
++)
97 printf ("%02x ", out
[i
] & 0xFF);