This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20 #include "rijndael-api-fst.h"
21
22 #include <stdio.h>
23 #include <string.h>
24
25 int
26 main (int argc, char *argv[])
27 {
28 int rc;
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";
37 size_t i;
38
39 rc = rijndaelMakeKey (&key, RIJNDAEL_DIR_ENCRYPT,
40 128, "00000000000000000000000000000000");
41 if (rc != 0)
42 printf ("makeKey failed %d\n", rc);
43
44 rc = rijndaelCipherInit (&cipher, RIJNDAEL_MODE_ECB, NULL);
45 if (rc != 0)
46 printf ("cipherInit failed %d\n", rc);
47
48 memset (in, 0, RIJNDAEL_BITSPERBLOCK / 8);
49
50 for (i = 0; i < 10000; i++)
51 {
52 rc = rijndaelBlockEncrypt (&cipher, &key, in, 128, out);
53 if (rc < 0)
54 printf ("blockEncrypt failed %d\n", rc);
55
56 memcpy (in, out, RIJNDAEL_BITSPERBLOCK / 8);
57 }
58
59 if (memcmp (out, ct, RIJNDAEL_BITSPERBLOCK / 8) != 0)
60 {
61 size_t i;
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);
68 printf ("\n");
69 return 1;
70 }
71
72 rc = rijndaelMakeKey (&key, RIJNDAEL_DIR_DECRYPT,
73 128, "00000000000000000000000000000000");
74 if (rc != 0)
75 printf ("makeKey failed %d\n", rc);
76
77 rc = rijndaelCipherInit (&cipher, RIJNDAEL_MODE_ECB, NULL);
78 if (rc != 0)
79 printf ("cipherInit failed %d\n", rc);
80
81 for (i = 0; i < 10000; i++)
82 {
83 memcpy (in, out, RIJNDAEL_BITSPERBLOCK / 8);
84
85 rc = rijndaelBlockDecrypt (&cipher, &key, in, 128, out);
86 if (rc < 0)
87 printf ("blockEncrypt failed %d\n", rc);
88 }
89
90 if (memcmp (out, pt, RIJNDAEL_BITSPERBLOCK / 8) != 0)
91 {
92 size_t i;
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);
99 printf ("\n");
100 return 1;
101 }
102
103 return 0;
104 }