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