2 * Copyright (C) 2005, 2010-2020 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/>. */
20 #include "rijndael-api-fst.h"
26 main (int argc
, char *argv
[])
29 rijndaelKeyInstance key
;
30 rijndaelCipherInstance cipher
;
31 char in
[RIJNDAEL_BITSPERBLOCK
/ 8];
32 char out
[RIJNDAEL_BITSPERBLOCK
/ 8];
33 char pt
[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
34 "\x00\x00\x00\x00\x00\x00\x00\x00";
35 char ct
[] = "\xC3\x4C\x05\x2C\xC0\xDA\x8D\x73"
36 "\x45\x1A\xFE\x5F\x03\xBE\x29\x7F";
39 rc
= rijndaelMakeKey (&key
, RIJNDAEL_DIR_ENCRYPT
,
40 128, "00000000000000000000000000000000");
42 printf ("makeKey failed %d\n", rc
);
44 rc
= rijndaelCipherInit (&cipher
, RIJNDAEL_MODE_ECB
, NULL
);
46 printf ("cipherInit failed %d\n", rc
);
48 memset (in
, 0, RIJNDAEL_BITSPERBLOCK
/ 8);
50 for (i
= 0; i
< 10000; i
++)
52 rc
= rijndaelBlockEncrypt (&cipher
, &key
, in
, 128, out
);
54 printf ("blockEncrypt failed %d\n", rc
);
56 memcpy (in
, out
, RIJNDAEL_BITSPERBLOCK
/ 8);
59 if (memcmp (out
, ct
, RIJNDAEL_BITSPERBLOCK
/ 8) != 0)
62 printf ("expected:\n");
63 for (i
= 0; i
< RIJNDAEL_BITSPERBLOCK
/ 8; i
++)
64 printf ("%02x ", ct
[i
] & 0xFF);
65 printf ("\ncomputed:\n");
66 for (i
= 0; i
< RIJNDAEL_BITSPERBLOCK
/ 8; i
++)
67 printf ("%02x ", out
[i
] & 0xFF);
72 rc
= rijndaelMakeKey (&key
, RIJNDAEL_DIR_DECRYPT
,
73 128, "00000000000000000000000000000000");
75 printf ("makeKey failed %d\n", rc
);
77 rc
= rijndaelCipherInit (&cipher
, RIJNDAEL_MODE_ECB
, NULL
);
79 printf ("cipherInit failed %d\n", rc
);
81 for (i
= 0; i
< 10000; i
++)
83 memcpy (in
, out
, RIJNDAEL_BITSPERBLOCK
/ 8);
85 rc
= rijndaelBlockDecrypt (&cipher
, &key
, in
, 128, out
);
87 printf ("blockEncrypt failed %d\n", rc
);
90 if (memcmp (out
, pt
, RIJNDAEL_BITSPERBLOCK
/ 8) != 0)
93 printf ("expected:\n");
94 for (i
= 0; i
< RIJNDAEL_BITSPERBLOCK
/ 8; i
++)
95 printf ("%02x ", pt
[i
] & 0xFF);
96 printf ("\ncomputed:\n");
97 for (i
= 0; i
< RIJNDAEL_BITSPERBLOCK
/ 8; i
++)
98 printf ("%02x ", out
[i
] & 0xFF);