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 "gc.h"
21
22 #include <stdio.h>
23 #include <string.h>
24
25 int
26 main (int argc, char *argv[])
27 {
28 gc_cipher_handle ctx;
29
30
31 static char key_1[] = { 0x61, 0x8A, 0x63, 0xD2, 0xFB };
32 static char plaintext_1[] = { 0xDC, 0xEE, 0x4C, 0xF9, 0x2C };
33 static const char ciphertext_1[] = { 0xF1, 0x38, 0x29, 0xC9, 0xDE };
34 char scratch[16];
35 Gc_rc rc;
36
37 rc = gc_init ();
38 if (rc != GC_OK)
39 {
40 printf ("gc_init() failed\n");
41 return 1;
42 }
43
44 rc = gc_cipher_open (GC_ARCFOUR40, GC_STREAM, &ctx);
45 if (rc != GC_OK)
46 return 1;
47
48 rc = gc_cipher_setkey (ctx, sizeof (key_1), key_1);
49 if (rc != GC_OK)
50 return 1;
51
52 memcpy (scratch, plaintext_1, sizeof (plaintext_1));
53 rc = gc_cipher_encrypt_inline (ctx, sizeof (plaintext_1), scratch);
54 if (rc != GC_OK)
55 return 1;
56
57 if (memcmp (scratch, ciphertext_1, sizeof (ciphertext_1)))
58 {
59 size_t i;
60 printf ("expected:\n");
61 for (i = 0; i < 5; i++)
62 printf ("%02x ", scratch[i] & 0xFF);
63 printf ("\ncomputed:\n");
64 for (i = 0; i < 5; i++)
65 printf ("%02x ", ciphertext_1[i] & 0xFF);
66 printf ("\n");
67 return 1;
68 }
69
70
71
72 rc = gc_cipher_setkey (ctx, sizeof (key_1), key_1);
73 if (rc != GC_OK)
74 return 1;
75
76 rc = gc_cipher_decrypt_inline (ctx, sizeof (plaintext_1), scratch);
77 if (rc != GC_OK)
78 return 1;
79
80 if (memcmp (scratch, plaintext_1, sizeof (plaintext_1)))
81 {
82 size_t i;
83 printf ("expected:\n");
84 for (i = 0; i < 5; i++)
85 printf ("%02x ", plaintext_1[i] & 0xFF);
86 printf ("\ncomputed:\n");
87 for (i = 0; i < 5; i++)
88 printf ("%02x ", scratch[i] & 0xFF);
89 printf ("\n");
90 return 1;
91 }
92
93 gc_cipher_close (ctx);
94
95 gc_done ();
96
97 return 0;
98 }