Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-gc-arctwo.c @ 6402:31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
author | Simon Josefsson <simon@josefsson.org> |
---|---|
date | Fri, 21 Oct 2005 12:03:17 +0000 |
parents | |
children | 633babea5f62 |
rev | line source |
---|---|
6402
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
1 /* |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
2 * Copyright (C) 2005 Free Software Foundation |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
3 * Written by Simon Josefsson |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
4 * |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
7 * the Free Software Foundation; either version 2, or (at your option) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
8 * any later version. |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
9 * |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
14 * |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
18 * 02110-1301, USA. */ |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
19 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
20 #ifdef HAVE_CONFIG_H |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
21 # include <config.h> |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
22 #endif |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
23 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
24 #include <stdio.h> |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
25 #include <string.h> |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
26 #include "gc.h" |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
27 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
28 int |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
29 main (int argc, char *argv[]) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
30 { |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
31 gc_cipher_handle ctx; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
32 /* Test vectors from RFC 2268. */ |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
33 static char key[8] = "\xff\xff\xff\xff\xff\xff\xff\xff"; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
34 static char plaintext[8] = "\xff\xff\xff\xff\xff\xff\xff\xff"; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
35 static const char ciphertext[8] = "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49"; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
36 char scratch[16]; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
37 Gc_rc rc; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
38 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
39 rc = gc_init (); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
40 if (rc != GC_OK) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
41 { |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
42 printf ("gc_init() failed\n"); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
43 return 1; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
44 } |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
45 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
46 rc = gc_cipher_open (GC_ARCTWO40, GC_ECB, &ctx); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
47 if (rc != GC_OK) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
48 return 1; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
49 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
50 rc = gc_cipher_setkey (ctx, sizeof (key), key); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
51 if (rc != GC_OK) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
52 return 1; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
53 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
54 memcpy (scratch, plaintext, sizeof (plaintext)); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
55 rc = gc_cipher_encrypt_inline (ctx, sizeof (plaintext), scratch); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
56 if (rc != GC_OK) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
57 return 1; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
58 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
59 if (memcmp (scratch, ciphertext, sizeof (ciphertext))) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
60 { |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
61 size_t i; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
62 printf ("expected:\n"); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
63 for (i = 0; i < 5; i++) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
64 printf ("%02x ", scratch[i] & 0xFF); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
65 printf ("\ncomputed:\n"); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
66 for (i = 0; i < 5; i++) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
67 printf ("%02x ", ciphertext[i] & 0xFF); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
68 printf ("\n"); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
69 return 1; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
70 } |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
71 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
72 /* decrypt */ |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
73 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
74 rc = gc_cipher_setkey (ctx, sizeof (key), key); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
75 if (rc != GC_OK) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
76 return 1; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
77 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
78 rc = gc_cipher_decrypt_inline (ctx, sizeof (plaintext), scratch); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
79 if (rc != GC_OK) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
80 return 1; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
81 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
82 if (memcmp (scratch, plaintext, sizeof (plaintext))) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
83 { |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
84 size_t i; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
85 printf ("expected:\n"); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
86 for (i = 0; i < 5; i++) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
87 printf ("%02x ", plaintext[i] & 0xFF); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
88 printf ("\ncomputed:\n"); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
89 for (i = 0; i < 5; i++) |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
90 printf ("%02x ", scratch[i] & 0xFF); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
91 printf ("\n"); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
92 return 1; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
93 } |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
94 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
95 gc_done (); |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
96 |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
97 return 0; |
31fd570c5ac0
Add arctwo, arctwo-tests, gc-arctwo, gc-arctwo-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
98 } |