2 * Copyright (C) 2005, 2010-2013 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, 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, see <http://www.gnu.org/licenses/>. */
25 main (int argc, char *argv[])
32 printf ("gc_init() failed\n");
38 char key[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
39 "\x00\x00\x00\x00\x00\x00\x00\x00";
40 char pt[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
41 "\x00\x00\x00\x00\x00\x00\x00\x00";
42 char ct[] = "\xC3\x4C\x05\x2C\xC0\xDA\x8D\x73"
43 "\x45\x1A\xFE\x5F\x03\xBE\x29\x7F";
47 rc = gc_cipher_open (GC_AES128, GC_ECB, &ctx);
51 rc = gc_cipher_setkey (ctx, 16, key);
57 for (i = 0; i < 10000; i++)
59 rc = gc_cipher_encrypt_inline (ctx, 16, buf);
62 printf ("encrypt failed %d\n", rc);
67 if (memcmp (buf, ct, 16) != 0)
70 printf ("expected:\n");
71 for (i = 0; i < 16; i++)
72 printf ("%02x ", ct[i] & 0xFF);
73 printf ("\ncomputed:\n");
74 for (i = 0; i < 16; i++)
75 printf ("%02x ", buf[i] & 0xFF);
80 for (i = 0; i < 10000; i++)
82 rc = gc_cipher_decrypt_inline (ctx, 16, buf);
85 printf ("decrypt failed %d\n", rc);
90 if (memcmp (buf, pt, 16) != 0)
93 printf ("expected:\n");
94 for (i = 0; i < 16; i++)
95 printf ("%02x ", pt[i] & 0xFF);
96 printf ("\ncomputed:\n");
97 for (i = 0; i < 16; i++)
98 printf ("%02x ", buf[i] & 0xFF);
103 gc_cipher_close (ctx);
109 char iv[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
110 "\x00\x00\x00\x00\x00\x00\x00\x00";
111 char key[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
112 "\x00\x00\x00\x00\x00\x00\x00\x00";
113 char pt[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
114 "\x00\x00\x00\x00\x00\x00\x00\x00";
115 char ct[] = "\x66\xe9\x4b\xd4\xef\x8a\x2c\x3b"
116 "\x88\x4c\xfa\x59\xca\x34\x2b\x2e";
117 gc_cipher_handle ctx;
120 rc = gc_cipher_open (GC_AES128, GC_CBC, &ctx);
124 rc = gc_cipher_setkey (ctx, 16, key);
128 rc = gc_cipher_setiv (ctx, 16, iv);
132 memcpy (buf, pt, 16);
134 for (i = 0; i < 10000; i++)
136 rc = gc_cipher_encrypt_inline (ctx, 16, buf);
139 printf ("encrypt failed %d\n", rc);
144 if (memcmp (buf, ct, 16) != 0)
147 printf ("expected:\n");
148 for (i = 0; i < 16; i++)
149 printf ("%02x ", ct[i] & 0xFF);
150 printf ("\ncomputed:\n");
151 for (i = 0; i < 16; i++)
152 printf ("%02x ", buf[i] & 0xFF);
157 gc_cipher_close (ctx);