diff options
Diffstat (limited to 'linden/indra/libgcrypt/libgcrypt-1.2.2/tests/ac.c')
-rw-r--r--[-rwxr-xr-x] | linden/indra/libgcrypt/libgcrypt-1.2.2/tests/ac.c | 314 |
1 files changed, 157 insertions, 157 deletions
diff --git a/linden/indra/libgcrypt/libgcrypt-1.2.2/tests/ac.c b/linden/indra/libgcrypt/libgcrypt-1.2.2/tests/ac.c index 31d393b..de37a2c 100755..100644 --- a/linden/indra/libgcrypt/libgcrypt-1.2.2/tests/ac.c +++ b/linden/indra/libgcrypt/libgcrypt-1.2.2/tests/ac.c | |||
@@ -1,157 +1,157 @@ | |||
1 | /* pubkey.c - Public key encryption/decryption tests | 1 | /* pubkey.c - Public key encryption/decryption tests |
2 | * Copyright (C) 2003 Free Software Foundation, Inc. | 2 | * Copyright (C) 2003 Free Software Foundation, Inc. |
3 | * | 3 | * |
4 | * This file is part of Libgcrypt. | 4 | * This file is part of Libgcrypt. |
5 | * | 5 | * |
6 | * Libgcrypt is free software; you can redistribute it and/or modify | 6 | * Libgcrypt is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as | 7 | * it under the terms of the GNU Lesser General Public License as |
8 | * published by the Free Software Foundation; either version 2.1 of | 8 | * published by the Free Software Foundation; either version 2.1 of |
9 | * the License, or (at your option) any later version. | 9 | * the License, or (at your option) any later version. |
10 | * | 10 | * |
11 | * Libgcrypt is distributed in the hope that it will be useful, | 11 | * Libgcrypt is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU Lesser General Public License for more details. | 14 | * GNU Lesser General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this program; if not, write to the Free Software | 17 | * License along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <stdarg.h> | 21 | #include <stdarg.h> |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <assert.h> | 25 | #include <assert.h> |
26 | 26 | ||
27 | #include "../src/gcrypt.h" | 27 | #include "../src/gcrypt.h" |
28 | 28 | ||
29 | static int verbose; | 29 | static int verbose; |
30 | 30 | ||
31 | static void | 31 | static void |
32 | die (const char *format, ...) | 32 | die (const char *format, ...) |
33 | { | 33 | { |
34 | va_list arg_ptr ; | 34 | va_list arg_ptr ; |
35 | 35 | ||
36 | va_start( arg_ptr, format ) ; | 36 | va_start( arg_ptr, format ) ; |
37 | vfprintf (stderr, format, arg_ptr ); | 37 | vfprintf (stderr, format, arg_ptr ); |
38 | va_end(arg_ptr); | 38 | va_end(arg_ptr); |
39 | exit (1); | 39 | exit (1); |
40 | } | 40 | } |
41 | 41 | ||
42 | void | 42 | void |
43 | key_copy (gcry_ac_handle_t handle, | 43 | key_copy (gcry_ac_handle_t handle, |
44 | gcry_ac_key_type_t type, | 44 | gcry_ac_key_type_t type, |
45 | gcry_ac_key_t *key_cp, gcry_ac_key_t key) | 45 | gcry_ac_key_t *key_cp, gcry_ac_key_t key) |
46 | { | 46 | { |
47 | gcry_error_t err = 0; | 47 | gcry_error_t err = 0; |
48 | 48 | ||
49 | err = gcry_ac_key_init (key_cp, handle, type, | 49 | err = gcry_ac_key_init (key_cp, handle, type, |
50 | gcry_ac_key_data_get (key)); | 50 | gcry_ac_key_data_get (key)); |
51 | 51 | ||
52 | assert (! err); | 52 | assert (! err); |
53 | } | 53 | } |
54 | 54 | ||
55 | void | 55 | void |
56 | check_one (gcry_mpi_t x) | 56 | check_one (gcry_mpi_t x) |
57 | { | 57 | { |
58 | gcry_ac_handle_t handle; | 58 | gcry_ac_handle_t handle; |
59 | gcry_ac_key_pair_t key_pair; | 59 | gcry_ac_key_pair_t key_pair; |
60 | gcry_ac_key_t key_sec, key_sec_cp, key_pub, key_pub_cp; | 60 | gcry_ac_key_t key_sec, key_sec_cp, key_pub, key_pub_cp; |
61 | gcry_error_t err = 0; | 61 | gcry_error_t err = 0; |
62 | gcry_mpi_t x2; | 62 | gcry_mpi_t x2; |
63 | gcry_ac_data_t data, data2; | 63 | gcry_ac_data_t data, data2; |
64 | gcry_ac_key_spec_rsa_t rsa_spec; | 64 | gcry_ac_key_spec_rsa_t rsa_spec; |
65 | 65 | ||
66 | rsa_spec.e = gcry_mpi_new (0); | 66 | rsa_spec.e = gcry_mpi_new (0); |
67 | gcry_mpi_set_ui (rsa_spec.e, 1); | 67 | gcry_mpi_set_ui (rsa_spec.e, 1); |
68 | 68 | ||
69 | err = gcry_ac_open (&handle, GCRY_AC_RSA, 0); | 69 | err = gcry_ac_open (&handle, GCRY_AC_RSA, 0); |
70 | assert (! err); | 70 | assert (! err); |
71 | 71 | ||
72 | err = gcry_ac_key_pair_generate (handle, 1024, &rsa_spec, &key_pair, NULL); | 72 | err = gcry_ac_key_pair_generate (handle, 1024, &rsa_spec, &key_pair, NULL); |
73 | assert (! err); | 73 | assert (! err); |
74 | 74 | ||
75 | key_sec = gcry_ac_key_pair_extract (key_pair, GCRY_AC_KEY_SECRET); | 75 | key_sec = gcry_ac_key_pair_extract (key_pair, GCRY_AC_KEY_SECRET); |
76 | key_copy (handle, GCRY_AC_KEY_SECRET, &key_sec_cp, key_sec); | 76 | key_copy (handle, GCRY_AC_KEY_SECRET, &key_sec_cp, key_sec); |
77 | 77 | ||
78 | key_pub = gcry_ac_key_pair_extract (key_pair, GCRY_AC_KEY_PUBLIC); | 78 | key_pub = gcry_ac_key_pair_extract (key_pair, GCRY_AC_KEY_PUBLIC); |
79 | key_copy (handle, GCRY_AC_KEY_PUBLIC, &key_pub_cp, key_pub); | 79 | key_copy (handle, GCRY_AC_KEY_PUBLIC, &key_pub_cp, key_pub); |
80 | 80 | ||
81 | err = gcry_ac_data_encrypt (handle, GCRY_AC_FLAG_NO_BLINDING, key_pub_cp, x, &data); | 81 | err = gcry_ac_data_encrypt (handle, GCRY_AC_FLAG_NO_BLINDING, key_pub_cp, x, &data); |
82 | assert (! err); | 82 | assert (! err); |
83 | 83 | ||
84 | err = gcry_ac_data_decrypt (handle, GCRY_AC_FLAG_NO_BLINDING, key_sec_cp, &x2, data); | 84 | err = gcry_ac_data_decrypt (handle, GCRY_AC_FLAG_NO_BLINDING, key_sec_cp, &x2, data); |
85 | assert (! err); | 85 | assert (! err); |
86 | 86 | ||
87 | assert (! gcry_mpi_cmp (x, x2)); | 87 | assert (! gcry_mpi_cmp (x, x2)); |
88 | 88 | ||
89 | gcry_ac_data_destroy (data); | 89 | gcry_ac_data_destroy (data); |
90 | 90 | ||
91 | err = gcry_ac_data_sign (handle, key_sec, x, &data); | 91 | err = gcry_ac_data_sign (handle, key_sec, x, &data); |
92 | assert (! err); | 92 | assert (! err); |
93 | err = gcry_ac_data_copy (&data2, data); | 93 | err = gcry_ac_data_copy (&data2, data); |
94 | assert (! err); | 94 | assert (! err); |
95 | gcry_ac_data_destroy (data); | 95 | gcry_ac_data_destroy (data); |
96 | err = gcry_ac_data_copy (&data, data2); | 96 | err = gcry_ac_data_copy (&data, data2); |
97 | assert (! err); | 97 | assert (! err); |
98 | gcry_ac_data_destroy (data2); | 98 | gcry_ac_data_destroy (data2); |
99 | 99 | ||
100 | err = gcry_ac_data_verify (handle, key_pub, x, data); | 100 | err = gcry_ac_data_verify (handle, key_pub, x, data); |
101 | assert (! err); | 101 | assert (! err); |
102 | 102 | ||
103 | gcry_ac_data_destroy (data); | 103 | gcry_ac_data_destroy (data); |
104 | 104 | ||
105 | err = gcry_ac_data_sign (handle, key_sec, x, &data); | 105 | err = gcry_ac_data_sign (handle, key_sec, x, &data); |
106 | assert (! err); | 106 | assert (! err); |
107 | { | 107 | { |
108 | const char *label; | 108 | const char *label; |
109 | gcry_mpi_t y; | 109 | gcry_mpi_t y; |
110 | 110 | ||
111 | err = gcry_ac_data_get_index (data, 0, 0, &label, &y); | 111 | err = gcry_ac_data_get_index (data, 0, 0, &label, &y); |
112 | assert (! err); | 112 | assert (! err); |
113 | gcry_mpi_add_ui (y, y, 1); | 113 | gcry_mpi_add_ui (y, y, 1); |
114 | 114 | ||
115 | err = gcry_ac_data_verify (handle, key_pub, x, data); | 115 | err = gcry_ac_data_verify (handle, key_pub, x, data); |
116 | assert (gcry_err_code (err) == GPG_ERR_BAD_SIGNATURE); | 116 | assert (gcry_err_code (err) == GPG_ERR_BAD_SIGNATURE); |
117 | } | 117 | } |
118 | 118 | ||
119 | gcry_ac_close (handle); | 119 | gcry_ac_close (handle); |
120 | } | 120 | } |
121 | 121 | ||
122 | void | 122 | void |
123 | check_run (void) | 123 | check_run (void) |
124 | { | 124 | { |
125 | /*const char *s = "All Hail Discordia."; -- not used */ | 125 | /*const char *s = "All Hail Discordia."; -- not used */ |
126 | unsigned int a = 0x4223; | 126 | unsigned int a = 0x4223; |
127 | gcry_mpi_t x; | 127 | gcry_mpi_t x; |
128 | 128 | ||
129 | x = gcry_mpi_new (0); | 129 | x = gcry_mpi_new (0); |
130 | gcry_mpi_set_ui (x, a); | 130 | gcry_mpi_set_ui (x, a); |
131 | check_one (x); | 131 | check_one (x); |
132 | gcry_mpi_release (x); | 132 | gcry_mpi_release (x); |
133 | } | 133 | } |
134 | 134 | ||
135 | int | 135 | int |
136 | main (int argc, char **argv) | 136 | main (int argc, char **argv) |
137 | { | 137 | { |
138 | int debug = 0; | 138 | int debug = 0; |
139 | int i = 1; | 139 | int i = 1; |
140 | 140 | ||
141 | if (argc > 1 && !strcmp (argv[1], "--verbose")) | 141 | if (argc > 1 && !strcmp (argv[1], "--verbose")) |
142 | verbose = 1; | 142 | verbose = 1; |
143 | else if (argc > 1 && !strcmp (argv[1], "--debug")) | 143 | else if (argc > 1 && !strcmp (argv[1], "--debug")) |
144 | verbose = debug = 1; | 144 | verbose = debug = 1; |
145 | 145 | ||
146 | gcry_control (GCRYCTL_DISABLE_SECMEM, 0); | 146 | gcry_control (GCRYCTL_DISABLE_SECMEM, 0); |
147 | if (!gcry_check_version (GCRYPT_VERSION)) | 147 | if (!gcry_check_version (GCRYPT_VERSION)) |
148 | die ("version mismatch\n"); | 148 | die ("version mismatch\n"); |
149 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 149 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
150 | if (debug) | 150 | if (debug) |
151 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); | 151 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); |
152 | 152 | ||
153 | for (; i > 0; i--) | 153 | for (; i > 0; i--) |
154 | check_run (); | 154 | check_run (); |
155 | 155 | ||
156 | return 0; | 156 | return 0; |
157 | } | 157 | } |