Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/gc-libgcrypt.c @ 12559:c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Use the same procedure as for 2009, outlined in
http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/20081
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Fri, 01 Jan 2010 10:31:12 +0100 |
parents | e8d2c6fc33ad |
children | 52f20913a6c2 |
rev | line source |
---|---|
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
1 /* gc-libgcrypt.c --- Crypto wrappers around Libgcrypt for GC. |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
2 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free |
11757
21cbeec12201
gc-libgcrypt.c, gc-gnulib.c: Change copyright to FSF.
Simon Josefsson <simon@josefsson.org>
parents:
9817
diff
changeset
|
3 * Software Foundation, Inc. |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
4 * |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
5 * This file is free software; you can redistribute it and/or modify |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
7 * by the Free Software Foundation; either version 2, or (at your |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
8 * option) any later version. |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
9 * |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
10 * This file is distributed in the hope that it will be useful, but |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
11 * WITHOUT ANY WARRANTY; without even the implied warranty of |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
13 * General Public License for more details. |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
14 * |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
16 * along with this file; if not, write to the Free Software |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
18 * 02110-1301, USA. |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
19 * |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
20 */ |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
21 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
22 /* Note: This file is only built if GC uses Libgcrypt. */ |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
23 |
7584
a88f85e4728f
* lib/arcfour.c: Assume config.h.
Eric Blake <ebb9@byu.net>
parents:
6683
diff
changeset
|
24 #include <config.h> |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
25 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
26 /* Get prototype. */ |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
27 #include "gc.h" |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
28 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
29 #include <stdlib.h> |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
30 #include <string.h> |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
31 |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
32 /* Get libgcrypt API. */ |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
33 #include <gcrypt.h> |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
34 #ifdef GNULIB_GC_MD2 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
35 # include "md2.h" |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
36 #endif |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
37 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
38 #include <assert.h> |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
39 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
40 /* Initialization. */ |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
41 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
42 Gc_rc |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
43 gc_init (void) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
44 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
45 gcry_error_t err; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
46 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
47 err = gcry_control (GCRYCTL_ANY_INITIALIZATION_P); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
48 if (err == GPG_ERR_NO_ERROR) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
49 { |
9628
8b78449a7146
Disable secure memory in gc-libgcrypt.c.
Simon Josefsson <simon@josefsson.org>
parents:
9390
diff
changeset
|
50 if (gcry_control (GCRYCTL_DISABLE_SECMEM, NULL, 0)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
51 return GC_INIT_ERROR; |
9628
8b78449a7146
Disable secure memory in gc-libgcrypt.c.
Simon Josefsson <simon@josefsson.org>
parents:
9390
diff
changeset
|
52 |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
53 if (gcry_check_version (GCRYPT_VERSION) == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
54 return GC_INIT_ERROR; |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
55 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
56 err = gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL, 0); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
57 if (err != GPG_ERR_NO_ERROR) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
58 return GC_INIT_ERROR; |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
59 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
60 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
61 return GC_OK; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
62 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
63 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
64 void |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
65 gc_done (void) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
66 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
67 return; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
68 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
69 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
70 #ifdef GNULIB_GC_RANDOM |
6683
b834cf4a531f
Split off gc-random from gc, and only warn on missing devices.
Simon Josefsson <simon@josefsson.org>
parents:
6432
diff
changeset
|
71 |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
72 /* Randomness. */ |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
73 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
74 Gc_rc |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
75 gc_nonce (char *data, size_t datalen) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
76 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
77 gcry_create_nonce ((unsigned char *) data, datalen); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
78 return GC_OK; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
79 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
80 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
81 Gc_rc |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
82 gc_pseudo_random (char *data, size_t datalen) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
83 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
84 gcry_randomize ((unsigned char *) data, datalen, GCRY_STRONG_RANDOM); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
85 return GC_OK; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
86 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
87 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
88 Gc_rc |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
89 gc_random (char *data, size_t datalen) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
90 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
91 gcry_randomize ((unsigned char *) data, datalen, GCRY_VERY_STRONG_RANDOM); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
92 return GC_OK; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
93 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
94 |
6683
b834cf4a531f
Split off gc-random from gc, and only warn on missing devices.
Simon Josefsson <simon@josefsson.org>
parents:
6432
diff
changeset
|
95 #endif |
b834cf4a531f
Split off gc-random from gc, and only warn on missing devices.
Simon Josefsson <simon@josefsson.org>
parents:
6432
diff
changeset
|
96 |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
97 /* Memory allocation. */ |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
98 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
99 void |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
100 gc_set_allocators (gc_malloc_t func_malloc, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
101 gc_malloc_t secure_malloc, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
102 gc_secure_check_t secure_check, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
103 gc_realloc_t func_realloc, gc_free_t func_free) |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
104 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
105 gcry_set_allocation_handler (func_malloc, secure_malloc, secure_check, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
106 func_realloc, func_free); |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
107 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
108 |
6383 | 109 /* Ciphers. */ |
110 | |
111 Gc_rc | |
112 gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
113 gc_cipher_handle * outhandle) |
6383 | 114 { |
115 int gcryalg, gcrymode; | |
116 gcry_error_t err; | |
117 | |
118 switch (alg) | |
119 { | |
120 case GC_AES128: | |
121 gcryalg = GCRY_CIPHER_RIJNDAEL; | |
122 break; | |
123 | |
124 case GC_AES192: | |
125 gcryalg = GCRY_CIPHER_RIJNDAEL; | |
126 break; | |
127 | |
128 case GC_AES256: | |
129 gcryalg = GCRY_CIPHER_RIJNDAEL256; | |
130 break; | |
131 | |
132 case GC_3DES: | |
133 gcryalg = GCRY_CIPHER_3DES; | |
134 break; | |
135 | |
136 case GC_DES: | |
137 gcryalg = GCRY_CIPHER_DES; | |
138 break; | |
139 | |
140 case GC_ARCFOUR128: | |
141 case GC_ARCFOUR40: | |
142 gcryalg = GCRY_CIPHER_ARCFOUR; | |
143 break; | |
144 | |
145 case GC_ARCTWO40: | |
146 gcryalg = GCRY_CIPHER_RFC2268_40; | |
147 break; | |
148 | |
9390
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
149 #ifdef HAVE_CAMELLIA |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
150 case GC_CAMELLIA128: |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
151 gcryalg = GCRY_CIPHER_CAMELLIA128; |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
152 break; |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
153 |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
154 case GC_CAMELLIA256: |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
155 gcryalg = GCRY_CIPHER_CAMELLIA256; |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
156 break; |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
157 #endif |
e6944904022b
Add module 'gc-camellia'.
Simon Josefsson <simon@josefsson.org>
parents:
8696
diff
changeset
|
158 |
6383 | 159 default: |
160 return GC_INVALID_CIPHER; | |
161 } | |
162 | |
163 switch (mode) | |
164 { | |
6401
3679e6b8d7cf
* gc-libgcrypt.c (gc_cipher_open): Handle ECB.
Simon Josefsson <simon@josefsson.org>
parents:
6394
diff
changeset
|
165 case GC_ECB: |
3679e6b8d7cf
* gc-libgcrypt.c (gc_cipher_open): Handle ECB.
Simon Josefsson <simon@josefsson.org>
parents:
6394
diff
changeset
|
166 gcrymode = GCRY_CIPHER_MODE_ECB; |
3679e6b8d7cf
* gc-libgcrypt.c (gc_cipher_open): Handle ECB.
Simon Josefsson <simon@josefsson.org>
parents:
6394
diff
changeset
|
167 break; |
3679e6b8d7cf
* gc-libgcrypt.c (gc_cipher_open): Handle ECB.
Simon Josefsson <simon@josefsson.org>
parents:
6394
diff
changeset
|
168 |
6383 | 169 case GC_CBC: |
170 gcrymode = GCRY_CIPHER_MODE_CBC; | |
171 break; | |
172 | |
173 case GC_STREAM: | |
174 gcrymode = GCRY_CIPHER_MODE_STREAM; | |
175 break; | |
176 | |
177 default: | |
178 return GC_INVALID_CIPHER; | |
179 } | |
180 | |
181 err = gcry_cipher_open ((gcry_cipher_hd_t *) outhandle, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
182 gcryalg, gcrymode, 0); |
6383 | 183 if (gcry_err_code (err)) |
184 return GC_INVALID_CIPHER; | |
185 | |
186 return GC_OK; | |
187 } | |
188 | |
189 Gc_rc | |
190 gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key) | |
191 { | |
192 gcry_error_t err; | |
193 | |
194 err = gcry_cipher_setkey ((gcry_cipher_hd_t) handle, key, keylen); | |
195 if (gcry_err_code (err)) | |
196 return GC_INVALID_CIPHER; | |
197 | |
198 return GC_OK; | |
199 } | |
200 | |
201 Gc_rc | |
202 gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv) | |
203 { | |
204 gcry_error_t err; | |
205 | |
206 err = gcry_cipher_setiv ((gcry_cipher_hd_t) handle, iv, ivlen); | |
207 if (gcry_err_code (err)) | |
208 return GC_INVALID_CIPHER; | |
209 | |
210 return GC_OK; | |
211 } | |
212 | |
213 Gc_rc | |
214 gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data) | |
215 { | |
216 if (gcry_cipher_encrypt ((gcry_cipher_hd_t) handle, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
217 data, len, NULL, len) != 0) |
6383 | 218 return GC_INVALID_CIPHER; |
219 | |
220 return GC_OK; | |
221 } | |
222 | |
223 Gc_rc | |
224 gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data) | |
225 { | |
226 if (gcry_cipher_decrypt ((gcry_cipher_hd_t) handle, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
227 data, len, NULL, len) != 0) |
6383 | 228 return GC_INVALID_CIPHER; |
229 | |
230 return GC_OK; | |
231 } | |
232 | |
233 Gc_rc | |
234 gc_cipher_close (gc_cipher_handle handle) | |
235 { | |
236 gcry_cipher_close (handle); | |
237 | |
238 return GC_OK; | |
239 } | |
240 | |
6349
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
241 /* Hashes. */ |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
242 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
243 typedef struct _gc_hash_ctx { |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
244 Gc_hash alg; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
245 Gc_hash_mode mode; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
246 gcry_md_hd_t gch; |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
247 #ifdef GNULIB_GC_MD2 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
248 char hash[GC_MD2_DIGEST_SIZE]; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
249 struct md2_ctx md2Context; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
250 #endif |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
251 } _gc_hash_ctx; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
252 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
253 Gc_rc |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
254 gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
255 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
256 _gc_hash_ctx *ctx; |
8696
54215b13787d
2007-04-16 Simon Josefsson <simon@josefsson.org>
Simon Josefsson <simon@josefsson.org>
parents:
8109
diff
changeset
|
257 int gcryalg = 0, gcrymode = 0; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
258 gcry_error_t err; |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
259 Gc_rc rc = GC_OK; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
260 |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
261 ctx = calloc (sizeof (*ctx), 1); |
6432
13e8dcd2e4d7
* gc-gnulib.c, gc-libgcrypt.c: Check calloc return value.
Simon Josefsson <simon@josefsson.org>
parents:
6431
diff
changeset
|
262 if (!ctx) |
13e8dcd2e4d7
* gc-gnulib.c, gc-libgcrypt.c: Check calloc return value.
Simon Josefsson <simon@josefsson.org>
parents:
6431
diff
changeset
|
263 return GC_MALLOC_ERROR; |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
264 |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
265 ctx->alg = hash; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
266 ctx->mode = mode; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
267 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
268 switch (hash) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
269 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
270 case GC_MD2: |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
271 gcryalg = GCRY_MD_NONE; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
272 break; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
273 |
6394
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
274 case GC_MD4: |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
275 gcryalg = GCRY_MD_MD4; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
276 break; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
277 |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
278 case GC_MD5: |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
279 gcryalg = GCRY_MD_MD5; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
280 break; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
281 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
282 case GC_SHA1: |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
283 gcryalg = GCRY_MD_SHA1; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
284 break; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
285 |
8109
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
286 case GC_SHA256: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
287 gcryalg = GCRY_MD_SHA256; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
288 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
289 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
290 case GC_SHA384: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
291 gcryalg = GCRY_MD_SHA384; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
292 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
293 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
294 case GC_SHA512: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
295 gcryalg = GCRY_MD_SHA512; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
296 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
297 |
9817
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
298 case GC_SHA224: |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
299 gcryalg = GCRY_MD_SHA224; |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
300 break; |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
301 |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
302 case GC_RMD160: |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
303 gcryalg = GCRY_MD_RMD160; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
304 break; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
305 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
306 default: |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
307 rc = GC_INVALID_HASH; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
308 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
309 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
310 switch (mode) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
311 { |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
312 case 0: |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
313 gcrymode = 0; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
314 break; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
315 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
316 case GC_HMAC: |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
317 gcrymode = GCRY_MD_FLAG_HMAC; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
318 break; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
319 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
320 default: |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
321 rc = GC_INVALID_HASH; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
322 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
323 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
324 if (rc == GC_OK && gcryalg != GCRY_MD_NONE) |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
325 { |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
326 err = gcry_md_open (&ctx->gch, gcryalg, gcrymode); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
327 if (gcry_err_code (err)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
328 rc = GC_INVALID_HASH; |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
329 } |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
330 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
331 if (rc == GC_OK) |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
332 *outhandle = ctx; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
333 else |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
334 free (ctx); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
335 |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
336 return rc; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
337 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
338 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
339 Gc_rc |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
340 gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
341 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
342 _gc_hash_ctx *in = handle; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
343 _gc_hash_ctx *out; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
344 int err; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
345 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
346 *outhandle = out = calloc (sizeof (*out), 1); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
347 if (!out) |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
348 return GC_MALLOC_ERROR; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
349 |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
350 memcpy (out, in, sizeof (*out)); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
351 |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
352 err = gcry_md_copy (&out->gch, in->gch); |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
353 if (err) |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
354 { |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
355 free (out); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
356 return GC_INVALID_HASH; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
357 } |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
358 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
359 return GC_OK; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
360 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
361 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
362 size_t |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
363 gc_hash_digest_length (Gc_hash hash) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
364 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
365 size_t len; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
366 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
367 switch (hash) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
368 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
369 case GC_MD2: |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
370 len = GC_MD2_DIGEST_SIZE; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
371 break; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
372 |
6394
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
373 case GC_MD4: |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
374 len = GC_MD4_DIGEST_SIZE; |
6394
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
375 break; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
376 |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
377 case GC_MD5: |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
378 len = GC_MD5_DIGEST_SIZE; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
379 break; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
380 |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
381 case GC_RMD160: |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
382 len = GC_RMD160_DIGEST_SIZE; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
383 break; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
384 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
385 case GC_SHA1: |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
386 len = GC_SHA1_DIGEST_SIZE; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
387 break; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
388 |
8109
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
389 case GC_SHA256: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
390 len = GC_SHA256_DIGEST_SIZE; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
391 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
392 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
393 case GC_SHA384: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
394 len = GC_SHA384_DIGEST_SIZE; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
395 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
396 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
397 case GC_SHA512: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
398 len = GC_SHA512_DIGEST_SIZE; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
399 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
400 |
9817
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
401 case GC_SHA224: |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
402 len = GC_SHA224_DIGEST_SIZE; |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
403 break; |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
404 |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
405 default: |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
406 return 0; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
407 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
408 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
409 return len; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
410 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
411 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
412 void |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
413 gc_hash_hmac_setkey (gc_hash_handle handle, size_t len, const char *key) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
414 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
415 _gc_hash_ctx *ctx = handle; |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
416 #ifdef GNULIB_GC_MD2 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
417 if (ctx->alg != GC_MD2) |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
418 #endif |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
419 gcry_md_setkey (ctx->gch, key, len); |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
420 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
421 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
422 void |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
423 gc_hash_write (gc_hash_handle handle, size_t len, const char *data) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
424 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
425 _gc_hash_ctx *ctx = handle; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
426 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
427 #ifdef GNULIB_GC_MD2 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
428 if (ctx->alg == GC_MD2) |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
429 md2_process_bytes (data, len, &ctx->md2Context); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
430 else |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
431 #endif |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
432 gcry_md_write (ctx->gch, data, len); |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
433 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
434 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
435 const char * |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
436 gc_hash_read (gc_hash_handle handle) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
437 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
438 _gc_hash_ctx *ctx = handle; |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
439 const char *digest; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
440 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
441 #ifdef GNULIB_GC_MD2 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
442 if (ctx->alg == GC_MD2) |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
443 { |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
444 md2_finish_ctx (&ctx->md2Context, ctx->hash); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
445 digest = ctx->hash; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
446 } |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
447 else |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
448 #endif |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
449 { |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
450 gcry_md_final (ctx->gch); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
451 digest = gcry_md_read (ctx->gch, 0); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
452 } |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
453 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
454 return digest; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
455 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
456 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
457 void |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
458 gc_hash_close (gc_hash_handle handle) |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
459 { |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
460 _gc_hash_ctx *ctx = handle; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
461 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
462 #ifdef GNULIB_GC_MD2 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
463 if (ctx->alg != GC_MD2) |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
464 #endif |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
465 gcry_md_close (ctx->gch); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
466 |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
467 free (ctx); |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
468 } |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
469 |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
470 Gc_rc |
6362
2bcfc491052b
* gc-libgcrypt.c (gc_md5): Fix assert call.
Simon Josefsson <simon@josefsson.org>
parents:
6349
diff
changeset
|
471 gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf) |
6349
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
472 { |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
473 int gcryalg; |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
474 |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
475 switch (hash) |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
476 { |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
477 #ifdef GNULIB_GC_MD2 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
478 case GC_MD2: |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
479 md2_buffer (in, inlen, resbuf); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
480 return GC_OK; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
481 break; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
482 #endif |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
483 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
484 #ifdef GNULIB_GC_MD4 |
6394
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
485 case GC_MD4: |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
486 gcryalg = GCRY_MD_MD4; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
487 break; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
488 #endif |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
489 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
490 #ifdef GNULIB_GC_MD5 |
6349
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
491 case GC_MD5: |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
492 gcryalg = GCRY_MD_MD5; |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
493 break; |
6363
bae11f33bf3c
Split parts of the gc module into gc-md5 and gc-hmac-md5 modules.
Simon Josefsson <simon@josefsson.org>
parents:
6362
diff
changeset
|
494 #endif |
6349
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
495 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
496 #ifdef GNULIB_GC_SHA1 |
6365 | 497 case GC_SHA1: |
498 gcryalg = GCRY_MD_SHA1; | |
499 break; | |
500 #endif | |
501 | |
8109
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
502 #ifdef GNULIB_GC_SHA256 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
503 case GC_SHA256: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
504 gcryalg = GCRY_MD_SHA256; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
505 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
506 #endif |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
507 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
508 #ifdef GNULIB_GC_SHA384 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
509 case GC_SHA384: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
510 gcryalg = GCRY_MD_SHA384; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
511 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
512 #endif |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
513 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
514 #ifdef GNULIB_GC_SHA512 |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
515 case GC_SHA512: |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
516 gcryalg = GCRY_MD_SHA512; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
517 break; |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
518 #endif |
38b4f50a2b13
lib/gc.h, lib/gc-libgcrypt.c: Support SHA-256/384/512.
Simon Josefsson <simon@josefsson.org>
parents:
7796
diff
changeset
|
519 |
9817
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
520 #ifdef GNULIB_GC_SHA224 |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
521 case GC_SHA224: |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
522 gcryalg = GCRY_MD_SHA224; |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
523 break; |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
524 #endif |
8abe4cfb1a83
Support SHA-224 in gc.
Simon Josefsson <simon@josefsson.org>
parents:
9628
diff
changeset
|
525 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
526 #ifdef GNULIB_GC_RMD160 |
6384
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
527 case GC_RMD160: |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
528 gcryalg = GCRY_MD_RMD160; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
529 break; |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
530 #endif |
a4b7c6c3f5bc
Add more hash functions.
Simon Josefsson <simon@josefsson.org>
parents:
6383
diff
changeset
|
531 |
6349
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
532 default: |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
533 return GC_INVALID_HASH; |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
534 } |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
535 |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
536 gcry_md_hash_buffer (gcryalg, resbuf, in, inlen); |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
537 |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
538 return GC_OK; |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
539 } |
c195d0c75e25
2005-10-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
6348
diff
changeset
|
540 |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
541 /* One-call interface. */ |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
542 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
543 #ifdef GNULIB_GC_MD2 |
6431
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
544 Gc_rc |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
545 gc_md2 (const void *in, size_t inlen, void *resbuf) |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
546 { |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
547 md2_buffer (in, inlen, resbuf); |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
548 return GC_OK; |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
549 } |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
550 #endif |
076accb971ef
Add MD2 and hash fixes.
Simon Josefsson <simon@josefsson.org>
parents:
6401
diff
changeset
|
551 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
552 #ifdef GNULIB_GC_MD4 |
6394
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
553 Gc_rc |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
554 gc_md4 (const void *in, size_t inlen, void *resbuf) |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
555 { |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
556 size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD4); |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
557 gcry_md_hd_t hd; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
558 gpg_error_t err; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
559 unsigned char *p; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
560 |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
561 assert (outlen == GC_MD4_DIGEST_SIZE); |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
562 |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
563 err = gcry_md_open (&hd, GCRY_MD_MD4, 0); |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
564 if (err != GPG_ERR_NO_ERROR) |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
565 return GC_INVALID_HASH; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
566 |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
567 gcry_md_write (hd, in, inlen); |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
568 |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
569 p = gcry_md_read (hd, GCRY_MD_MD4); |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
570 if (p == NULL) |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
571 { |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
572 gcry_md_close (hd); |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
573 return GC_INVALID_HASH; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
574 } |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
575 |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
576 memcpy (resbuf, p, outlen); |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
577 |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
578 gcry_md_close (hd); |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
579 |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
580 return GC_OK; |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
581 } |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
582 #endif |
1ddc29532d18
Add gc-md4 and gc-md4-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
6387
diff
changeset
|
583 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
584 #ifdef GNULIB_GC_MD5 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
585 Gc_rc |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
586 gc_md5 (const void *in, size_t inlen, void *resbuf) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
587 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
588 size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD5); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
589 gcry_md_hd_t hd; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
590 gpg_error_t err; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
591 unsigned char *p; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
592 |
6362
2bcfc491052b
* gc-libgcrypt.c (gc_md5): Fix assert call.
Simon Josefsson <simon@josefsson.org>
parents:
6349
diff
changeset
|
593 assert (outlen == GC_MD5_DIGEST_SIZE); |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
594 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
595 err = gcry_md_open (&hd, GCRY_MD_MD5, 0); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
596 if (err != GPG_ERR_NO_ERROR) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
597 return GC_INVALID_HASH; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
598 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
599 gcry_md_write (hd, in, inlen); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
600 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
601 p = gcry_md_read (hd, GCRY_MD_MD5); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
602 if (p == NULL) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
603 { |
6362
2bcfc491052b
* gc-libgcrypt.c (gc_md5): Fix assert call.
Simon Josefsson <simon@josefsson.org>
parents:
6349
diff
changeset
|
604 gcry_md_close (hd); |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
605 return GC_INVALID_HASH; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
606 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
607 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
608 memcpy (resbuf, p, outlen); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
609 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
610 gcry_md_close (hd); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
611 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
612 return GC_OK; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
613 } |
6363
bae11f33bf3c
Split parts of the gc module into gc-md5 and gc-hmac-md5 modules.
Simon Josefsson <simon@josefsson.org>
parents:
6362
diff
changeset
|
614 #endif |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
615 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
616 #ifdef GNULIB_GC_SHA1 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
617 Gc_rc |
6365 | 618 gc_sha1 (const void *in, size_t inlen, void *resbuf) |
619 { | |
620 size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1); | |
621 gcry_md_hd_t hd; | |
622 gpg_error_t err; | |
623 unsigned char *p; | |
624 | |
625 assert (outlen == GC_SHA1_DIGEST_SIZE); | |
626 | |
627 err = gcry_md_open (&hd, GCRY_MD_SHA1, 0); | |
628 if (err != GPG_ERR_NO_ERROR) | |
629 return GC_INVALID_HASH; | |
630 | |
631 gcry_md_write (hd, in, inlen); | |
632 | |
633 p = gcry_md_read (hd, GCRY_MD_SHA1); | |
634 if (p == NULL) | |
635 { | |
636 gcry_md_close (hd); | |
637 return GC_INVALID_HASH; | |
638 } | |
639 | |
640 memcpy (resbuf, p, outlen); | |
641 | |
642 gcry_md_close (hd); | |
643 | |
644 return GC_OK; | |
645 } | |
646 #endif | |
647 | |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
648 #ifdef GNULIB_GC_HMAC_MD5 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
649 Gc_rc |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
650 gc_hmac_md5 (const void *key, size_t keylen, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
651 const void *in, size_t inlen, char *resbuf) |
6348
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
652 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
653 size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_MD5); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
654 gcry_md_hd_t mdh; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
655 unsigned char *hash; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
656 gpg_error_t err; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
657 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
658 assert (hlen == 16); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
659 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
660 err = gcry_md_open (&mdh, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
661 if (err != GPG_ERR_NO_ERROR) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
662 return GC_INVALID_HASH; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
663 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
664 err = gcry_md_setkey (mdh, key, keylen); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
665 if (err != GPG_ERR_NO_ERROR) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
666 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
667 gcry_md_close (mdh); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
668 return GC_INVALID_HASH; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
669 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
670 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
671 gcry_md_write (mdh, in, inlen); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
672 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
673 hash = gcry_md_read (mdh, GCRY_MD_MD5); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
674 if (hash == NULL) |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
675 { |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
676 gcry_md_close (mdh); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
677 return GC_INVALID_HASH; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
678 } |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
679 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
680 memcpy (resbuf, hash, hlen); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
681 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
682 gcry_md_close (mdh); |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
683 |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
684 return GC_OK; |
55961a93440c
Add generic crypto module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
685 } |
6363
bae11f33bf3c
Split parts of the gc module into gc-md5 and gc-hmac-md5 modules.
Simon Josefsson <simon@josefsson.org>
parents:
6362
diff
changeset
|
686 #endif |
6366 | 687 |
7796
1eae086746a0
Move module indicator macros from *.m4 files to the module descriptions.
Bruno Haible <bruno@clisp.org>
parents:
7584
diff
changeset
|
688 #ifdef GNULIB_GC_HMAC_SHA1 |
6367
69cadd43d0f4
* gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
Simon Josefsson <simon@josefsson.org>
parents:
6366
diff
changeset
|
689 Gc_rc |
6366 | 690 gc_hmac_sha1 (const void *key, size_t keylen, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11757
diff
changeset
|
691 const void *in, size_t inlen, char *resbuf) |
6366 | 692 { |
693 size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1); | |
694 gcry_md_hd_t mdh; | |
695 unsigned char *hash; | |
696 gpg_error_t err; | |
697 | |
6387
92889893ef1f
* gc-libgcrypt.c (gc_hmac_sha1): Fix assert.
Simon Josefsson <simon@josefsson.org>
parents:
6384
diff
changeset
|
698 assert (hlen == GC_SHA1_DIGEST_SIZE); |
6366 | 699 |
700 err = gcry_md_open (&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC); | |
701 if (err != GPG_ERR_NO_ERROR) | |
702 return GC_INVALID_HASH; | |
703 | |
704 err = gcry_md_setkey (mdh, key, keylen); | |
705 if (err != GPG_ERR_NO_ERROR) | |
706 { | |
707 gcry_md_close (mdh); | |
708 return GC_INVALID_HASH; | |
709 } | |
710 | |
711 gcry_md_write (mdh, in, inlen); | |
712 | |
713 hash = gcry_md_read (mdh, GCRY_MD_SHA1); | |
714 if (hash == NULL) | |
715 { | |
716 gcry_md_close (mdh); | |
717 return GC_INVALID_HASH; | |
718 } | |
719 | |
720 memcpy (resbuf, hash, hlen); | |
721 | |
722 gcry_md_close (mdh); | |
723 | |
724 return GC_OK; | |
725 } | |
726 #endif |