diff options
author | lv-426 <oxcafebaby@yahoo.com> | 2008-06-22 18:20:35 +0000 |
---|---|---|
committer | lv-426 <oxcafebaby@yahoo.com> | 2008-06-22 18:20:35 +0000 |
commit | a0339d2458867dbe9485499265641ff205063445 (patch) | |
tree | 055b38828b3696520408a32edf81df5bb37400f0 /src/daemon/https/lgl/gc-libgcrypt.c | |
parent | 97c026da05495b83f1511906c2ca027e12ef6cf7 (diff) | |
download | libmicrohttpd-a0339d2458867dbe9485499265641ff205063445.tar.gz libmicrohttpd-a0339d2458867dbe9485499265641ff205063445.zip |
initial GNU TLS import - this should reduce in size considerable
Diffstat (limited to 'src/daemon/https/lgl/gc-libgcrypt.c')
-rw-r--r-- | src/daemon/https/lgl/gc-libgcrypt.c | 627 |
1 files changed, 627 insertions, 0 deletions
diff --git a/src/daemon/https/lgl/gc-libgcrypt.c b/src/daemon/https/lgl/gc-libgcrypt.c new file mode 100644 index 00000000..da9c5e16 --- /dev/null +++ b/src/daemon/https/lgl/gc-libgcrypt.c | |||
@@ -0,0 +1,627 @@ | |||
1 | /* gc-libgcrypt.c --- Crypto wrappers around Libgcrypt for GC. | ||
2 | * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Simon Josefsson | ||
3 | * | ||
4 | * This file is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU Lesser General Public License as published | ||
6 | * by the Free Software Foundation; either version 2.1, or (at your | ||
7 | * option) any later version. | ||
8 | * | ||
9 | * This file is distributed in the hope that it will be useful, but | ||
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this file; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | * 02110-1301, USA. | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | /* Note: This file is only built if GC uses Libgcrypt. */ | ||
22 | |||
23 | #include "config.h" | ||
24 | |||
25 | /* Get prototype. */ | ||
26 | #include "gc.h" | ||
27 | |||
28 | #include <stdlib.h> | ||
29 | #include <string.h> | ||
30 | |||
31 | /* Get libgcrypt API. */ | ||
32 | #include <gcrypt.h> | ||
33 | |||
34 | #include <assert.h> | ||
35 | |||
36 | /* Initialization. */ | ||
37 | |||
38 | Gc_rc gc_init(void) | ||
39 | { | ||
40 | gcry_error_t err; | ||
41 | |||
42 | err = gcry_control(GCRYCTL_ANY_INITIALIZATION_P); | ||
43 | if (err == GPG_ERR_NO_ERROR) | ||
44 | { | ||
45 | if (gcry_check_version(GCRYPT_VERSION) == NULL) | ||
46 | return GC_INIT_ERROR; | ||
47 | |||
48 | err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED, NULL, 0); | ||
49 | if (err != GPG_ERR_NO_ERROR) | ||
50 | return GC_INIT_ERROR; | ||
51 | } | ||
52 | return GC_OK; | ||
53 | } | ||
54 | |||
55 | void gc_done(void) | ||
56 | { | ||
57 | return; | ||
58 | } | ||
59 | |||
60 | #ifdef GNULIB_GC_RANDOM | ||
61 | |||
62 | /* Randomness. */ | ||
63 | |||
64 | Gc_rc | ||
65 | gc_nonce (char *data, size_t datalen) | ||
66 | { | ||
67 | gcry_create_nonce ((unsigned char *) data, datalen); | ||
68 | return GC_OK; | ||
69 | } | ||
70 | |||
71 | Gc_rc | ||
72 | gc_pseudo_random (char *data, size_t datalen) | ||
73 | { | ||
74 | gcry_randomize ((unsigned char *) data, datalen, GCRY_STRONG_RANDOM); | ||
75 | return GC_OK; | ||
76 | } | ||
77 | |||
78 | Gc_rc | ||
79 | gc_random (char *data, size_t datalen) | ||
80 | { | ||
81 | gcry_randomize ((unsigned char *) data, datalen, GCRY_VERY_STRONG_RANDOM); | ||
82 | return GC_OK; | ||
83 | } | ||
84 | |||
85 | #endif | ||
86 | |||
87 | /* Memory allocation. */ | ||
88 | |||
89 | void gc_set_allocators(gc_malloc_t func_malloc, | ||
90 | gc_malloc_t secure_malloc, | ||
91 | gc_secure_check_t secure_check, | ||
92 | gc_realloc_t func_realloc, | ||
93 | gc_free_t func_free) | ||
94 | { | ||
95 | gcry_set_allocation_handler(func_malloc, secure_malloc, secure_check, | ||
96 | func_realloc, func_free); | ||
97 | } | ||
98 | |||
99 | /* Ciphers. */ | ||
100 | |||
101 | Gc_rc gc_cipher_open(Gc_cipher alg, | ||
102 | Gc_cipher_mode mode, | ||
103 | gc_cipher_handle * outhandle) | ||
104 | { | ||
105 | int gcryalg, gcrymode; | ||
106 | gcry_error_t err; | ||
107 | |||
108 | switch (alg) | ||
109 | { | ||
110 | case GC_AES128: | ||
111 | gcryalg = GCRY_CIPHER_RIJNDAEL; | ||
112 | break; | ||
113 | |||
114 | case GC_AES192: | ||
115 | gcryalg = GCRY_CIPHER_RIJNDAEL; | ||
116 | break; | ||
117 | |||
118 | case GC_AES256: | ||
119 | gcryalg = GCRY_CIPHER_RIJNDAEL256; | ||
120 | break; | ||
121 | |||
122 | case GC_3DES: | ||
123 | gcryalg = GCRY_CIPHER_3DES; | ||
124 | break; | ||
125 | |||
126 | case GC_DES: | ||
127 | gcryalg = GCRY_CIPHER_DES; | ||
128 | break; | ||
129 | |||
130 | case GC_ARCFOUR128: | ||
131 | case GC_ARCFOUR40: | ||
132 | gcryalg = GCRY_CIPHER_ARCFOUR; | ||
133 | break; | ||
134 | |||
135 | case GC_ARCTWO40: | ||
136 | gcryalg = GCRY_CIPHER_RFC2268_40; | ||
137 | break; | ||
138 | |||
139 | #ifdef ENABLE_CAMELLIA | ||
140 | case GC_CAMELLIA128: | ||
141 | gcryalg = GCRY_CIPHER_CAMELLIA128; | ||
142 | break; | ||
143 | |||
144 | case GC_CAMELLIA256: | ||
145 | gcryalg = GCRY_CIPHER_CAMELLIA256; | ||
146 | break; | ||
147 | #endif | ||
148 | |||
149 | default: | ||
150 | return GC_INVALID_CIPHER; | ||
151 | } | ||
152 | |||
153 | switch (mode) | ||
154 | { | ||
155 | case GC_ECB: | ||
156 | gcrymode = GCRY_CIPHER_MODE_ECB; | ||
157 | break; | ||
158 | |||
159 | case GC_CBC: | ||
160 | gcrymode = GCRY_CIPHER_MODE_CBC; | ||
161 | break; | ||
162 | |||
163 | case GC_STREAM: | ||
164 | gcrymode = GCRY_CIPHER_MODE_STREAM; | ||
165 | break; | ||
166 | |||
167 | default: | ||
168 | return GC_INVALID_CIPHER; | ||
169 | } | ||
170 | |||
171 | err = gcry_cipher_open((gcry_cipher_hd_t *) outhandle, gcryalg, gcrymode, 0); | ||
172 | if (gcry_err_code(err)) | ||
173 | return GC_INVALID_CIPHER; | ||
174 | |||
175 | return GC_OK; | ||
176 | } | ||
177 | |||
178 | Gc_rc gc_cipher_setkey(gc_cipher_handle handle, | ||
179 | size_t keylen, | ||
180 | const char *key) | ||
181 | { | ||
182 | gcry_error_t err; | ||
183 | |||
184 | err = gcry_cipher_setkey ((gcry_cipher_hd_t) handle, key, keylen); | ||
185 | if (gcry_err_code(err)) | ||
186 | return GC_INVALID_CIPHER; | ||
187 | |||
188 | return GC_OK; | ||
189 | } | ||
190 | |||
191 | Gc_rc gc_cipher_setiv(gc_cipher_handle handle, | ||
192 | size_t ivlen, | ||
193 | const char *iv) | ||
194 | { | ||
195 | gcry_error_t err; | ||
196 | |||
197 | err = gcry_cipher_setiv ((gcry_cipher_hd_t) handle, iv, ivlen); | ||
198 | if (gcry_err_code(err)) | ||
199 | return GC_INVALID_CIPHER; | ||
200 | |||
201 | return GC_OK; | ||
202 | } | ||
203 | |||
204 | Gc_rc gc_cipher_encrypt_inline(gc_cipher_handle handle, | ||
205 | size_t len, | ||
206 | char *data) | ||
207 | { | ||
208 | if (gcry_cipher_encrypt((gcry_cipher_hd_t) handle, data, len, NULL, len) != 0) | ||
209 | return GC_INVALID_CIPHER; | ||
210 | |||
211 | return GC_OK; | ||
212 | } | ||
213 | |||
214 | Gc_rc gc_cipher_decrypt_inline(gc_cipher_handle handle, | ||
215 | size_t len, | ||
216 | char *data) | ||
217 | { | ||
218 | if (gcry_cipher_decrypt((gcry_cipher_hd_t) handle, data, len, NULL, len) != 0) | ||
219 | return GC_INVALID_CIPHER; | ||
220 | |||
221 | return GC_OK; | ||
222 | } | ||
223 | |||
224 | Gc_rc gc_cipher_close(gc_cipher_handle handle) | ||
225 | { | ||
226 | gcry_cipher_close(handle); | ||
227 | |||
228 | return GC_OK; | ||
229 | } | ||
230 | |||
231 | /* Hashes. */ | ||
232 | |||
233 | typedef struct _gc_hash_ctx | ||
234 | { | ||
235 | Gc_hash alg; | ||
236 | Gc_hash_mode mode; | ||
237 | gcry_md_hd_t gch; | ||
238 | } _gc_hash_ctx; | ||
239 | |||
240 | Gc_rc gc_hash_open(Gc_hash hash, | ||
241 | Gc_hash_mode mode, | ||
242 | gc_hash_handle * outhandle) | ||
243 | { | ||
244 | _gc_hash_ctx *ctx; | ||
245 | int gcryalg = 0, gcrymode = 0; | ||
246 | gcry_error_t err; | ||
247 | Gc_rc rc = GC_OK; | ||
248 | |||
249 | ctx = calloc(sizeof (*ctx), 1); | ||
250 | if (!ctx) | ||
251 | return GC_MALLOC_ERROR; | ||
252 | |||
253 | ctx->alg = hash; | ||
254 | ctx->mode = mode; | ||
255 | |||
256 | switch (hash) | ||
257 | { | ||
258 | case GC_MD2: | ||
259 | gcryalg = GCRY_MD_NONE; | ||
260 | break; | ||
261 | |||
262 | case GC_MD4: | ||
263 | gcryalg = GCRY_MD_MD4; | ||
264 | break; | ||
265 | |||
266 | case GC_MD5: | ||
267 | gcryalg = GCRY_MD_MD5; | ||
268 | break; | ||
269 | |||
270 | case GC_SHA1: | ||
271 | gcryalg = GCRY_MD_SHA1; | ||
272 | break; | ||
273 | |||
274 | case GC_SHA256: | ||
275 | gcryalg = GCRY_MD_SHA256; | ||
276 | break; | ||
277 | |||
278 | case GC_SHA384: | ||
279 | gcryalg = GCRY_MD_SHA384; | ||
280 | break; | ||
281 | |||
282 | case GC_SHA512: | ||
283 | gcryalg = GCRY_MD_SHA512; | ||
284 | break; | ||
285 | |||
286 | case GC_RMD160: | ||
287 | gcryalg = GCRY_MD_RMD160; | ||
288 | break; | ||
289 | |||
290 | default: | ||
291 | rc = GC_INVALID_HASH; | ||
292 | } | ||
293 | |||
294 | switch (mode) | ||
295 | { | ||
296 | case 0: | ||
297 | gcrymode = 0; | ||
298 | break; | ||
299 | |||
300 | case GC_HMAC: | ||
301 | gcrymode = GCRY_MD_FLAG_HMAC; | ||
302 | break; | ||
303 | |||
304 | default: | ||
305 | rc = GC_INVALID_HASH; | ||
306 | } | ||
307 | |||
308 | if (rc == GC_OK && gcryalg != GCRY_MD_NONE) | ||
309 | { | ||
310 | err = gcry_md_open(&ctx->gch, gcryalg, gcrymode); | ||
311 | if (gcry_err_code(err)) | ||
312 | rc = GC_INVALID_HASH; | ||
313 | } | ||
314 | |||
315 | if (rc == GC_OK) | ||
316 | *outhandle = ctx; | ||
317 | else | ||
318 | free(ctx); | ||
319 | |||
320 | return rc; | ||
321 | } | ||
322 | |||
323 | Gc_rc gc_hash_clone(gc_hash_handle handle, | ||
324 | gc_hash_handle * outhandle) | ||
325 | { | ||
326 | _gc_hash_ctx *in = handle; | ||
327 | _gc_hash_ctx *out; | ||
328 | int err; | ||
329 | |||
330 | *outhandle = out = calloc(sizeof (*out), 1); | ||
331 | if (!out) | ||
332 | return GC_MALLOC_ERROR; | ||
333 | |||
334 | memcpy(out, in, sizeof (*out)); | ||
335 | |||
336 | err = gcry_md_copy(&out->gch, in->gch); | ||
337 | if (err) | ||
338 | { | ||
339 | free(out); | ||
340 | return GC_INVALID_HASH; | ||
341 | } | ||
342 | |||
343 | return GC_OK; | ||
344 | } | ||
345 | |||
346 | size_t gc_hash_digest_length(Gc_hash hash) | ||
347 | { | ||
348 | size_t len; | ||
349 | |||
350 | switch (hash) | ||
351 | { | ||
352 | case GC_MD2: | ||
353 | len = GC_MD2_DIGEST_SIZE; | ||
354 | break; | ||
355 | |||
356 | case GC_MD4: | ||
357 | len = GC_MD4_DIGEST_SIZE; | ||
358 | break; | ||
359 | |||
360 | case GC_MD5: | ||
361 | len = GC_MD5_DIGEST_SIZE; | ||
362 | break; | ||
363 | |||
364 | case GC_RMD160: | ||
365 | len = GC_RMD160_DIGEST_SIZE; | ||
366 | break; | ||
367 | |||
368 | case GC_SHA1: | ||
369 | len = GC_SHA1_DIGEST_SIZE; | ||
370 | break; | ||
371 | |||
372 | case GC_SHA256: | ||
373 | len = GC_SHA256_DIGEST_SIZE; | ||
374 | break; | ||
375 | |||
376 | case GC_SHA384: | ||
377 | len = GC_SHA384_DIGEST_SIZE; | ||
378 | break; | ||
379 | |||
380 | case GC_SHA512: | ||
381 | len = GC_SHA512_DIGEST_SIZE; | ||
382 | break; | ||
383 | |||
384 | default: | ||
385 | return 0; | ||
386 | } | ||
387 | |||
388 | return len; | ||
389 | } | ||
390 | |||
391 | void gc_hash_hmac_setkey(gc_hash_handle handle, | ||
392 | size_t len, | ||
393 | const char *key) | ||
394 | { | ||
395 | _gc_hash_ctx *ctx = handle; | ||
396 | gcry_md_setkey(ctx->gch, key, len); | ||
397 | } | ||
398 | |||
399 | void gc_hash_write(gc_hash_handle handle, | ||
400 | size_t len, | ||
401 | const char *data) | ||
402 | { | ||
403 | _gc_hash_ctx *ctx = handle; | ||
404 | gcry_md_write(ctx->gch, data, len); | ||
405 | } | ||
406 | |||
407 | const char * gc_hash_read(gc_hash_handle handle) | ||
408 | { | ||
409 | _gc_hash_ctx *ctx = handle; | ||
410 | const char *digest; | ||
411 | { | ||
412 | gcry_md_final (ctx->gch); | ||
413 | digest = gcry_md_read(ctx->gch, 0); | ||
414 | } | ||
415 | |||
416 | return digest; | ||
417 | } | ||
418 | |||
419 | void gc_hash_close(gc_hash_handle handle) | ||
420 | { | ||
421 | _gc_hash_ctx *ctx = handle; | ||
422 | |||
423 | gcry_md_close(ctx->gch); | ||
424 | |||
425 | free(ctx); | ||
426 | } | ||
427 | |||
428 | Gc_rc gc_hash_buffer(Gc_hash hash, | ||
429 | const void *in, | ||
430 | size_t inlen, | ||
431 | char *resbuf) | ||
432 | { | ||
433 | int gcryalg; | ||
434 | |||
435 | switch (hash) | ||
436 | { | ||
437 | #ifdef GNULIB_GC_MD5 | ||
438 | case GC_MD5: | ||
439 | gcryalg = GCRY_MD_MD5; | ||
440 | break; | ||
441 | #endif | ||
442 | |||
443 | #ifdef GNULIB_GC_SHA1 | ||
444 | case GC_SHA1: | ||
445 | gcryalg = GCRY_MD_SHA1; | ||
446 | break; | ||
447 | #endif | ||
448 | |||
449 | #ifdef GNULIB_GC_SHA256 | ||
450 | case GC_SHA256: | ||
451 | gcryalg = GCRY_MD_SHA256; | ||
452 | break; | ||
453 | #endif | ||
454 | |||
455 | #ifdef GNULIB_GC_SHA384 | ||
456 | case GC_SHA384: | ||
457 | gcryalg = GCRY_MD_SHA384; | ||
458 | break; | ||
459 | #endif | ||
460 | |||
461 | #ifdef GNULIB_GC_SHA512 | ||
462 | case GC_SHA512: | ||
463 | gcryalg = GCRY_MD_SHA512; | ||
464 | break; | ||
465 | #endif | ||
466 | |||
467 | #ifdef GNULIB_GC_RMD160 | ||
468 | case GC_RMD160: | ||
469 | gcryalg = GCRY_MD_RMD160; | ||
470 | break; | ||
471 | #endif | ||
472 | |||
473 | default: | ||
474 | return GC_INVALID_HASH; | ||
475 | } | ||
476 | |||
477 | gcry_md_hash_buffer(gcryalg, resbuf, in, inlen); | ||
478 | |||
479 | return GC_OK; | ||
480 | } | ||
481 | |||
482 | /* One-call interface. */ | ||
483 | #ifdef GNULIB_GC_MD5 | ||
484 | Gc_rc | ||
485 | gc_md5 (const void *in, size_t inlen, void *resbuf) | ||
486 | { | ||
487 | size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD5); | ||
488 | gcry_md_hd_t hd; | ||
489 | gpg_error_t err; | ||
490 | unsigned char *p; | ||
491 | |||
492 | assert (outlen == GC_MD5_DIGEST_SIZE); | ||
493 | |||
494 | err = gcry_md_open (&hd, GCRY_MD_MD5, 0); | ||
495 | if (err != GPG_ERR_NO_ERROR) | ||
496 | return GC_INVALID_HASH; | ||
497 | |||
498 | gcry_md_write (hd, in, inlen); | ||
499 | |||
500 | p = gcry_md_read (hd, GCRY_MD_MD5); | ||
501 | if (p == NULL) | ||
502 | { | ||
503 | gcry_md_close (hd); | ||
504 | return GC_INVALID_HASH; | ||
505 | } | ||
506 | |||
507 | memcpy (resbuf, p, outlen); | ||
508 | |||
509 | gcry_md_close (hd); | ||
510 | |||
511 | return GC_OK; | ||
512 | } | ||
513 | #endif | ||
514 | |||
515 | #ifdef GNULIB_GC_SHA1 | ||
516 | Gc_rc | ||
517 | gc_sha1 (const void *in, size_t inlen, void *resbuf) | ||
518 | { | ||
519 | size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1); | ||
520 | gcry_md_hd_t hd; | ||
521 | gpg_error_t err; | ||
522 | unsigned char *p; | ||
523 | |||
524 | assert (outlen == GC_SHA1_DIGEST_SIZE); | ||
525 | |||
526 | err = gcry_md_open (&hd, GCRY_MD_SHA1, 0); | ||
527 | if (err != GPG_ERR_NO_ERROR) | ||
528 | return GC_INVALID_HASH; | ||
529 | |||
530 | gcry_md_write (hd, in, inlen); | ||
531 | |||
532 | p = gcry_md_read (hd, GCRY_MD_SHA1); | ||
533 | if (p == NULL) | ||
534 | { | ||
535 | gcry_md_close (hd); | ||
536 | return GC_INVALID_HASH; | ||
537 | } | ||
538 | |||
539 | memcpy (resbuf, p, outlen); | ||
540 | |||
541 | gcry_md_close (hd); | ||
542 | |||
543 | return GC_OK; | ||
544 | } | ||
545 | #endif | ||
546 | |||
547 | #ifdef GNULIB_GC_HMAC_MD5 | ||
548 | Gc_rc | ||
549 | gc_hmac_md5 (const void *key, size_t keylen, | ||
550 | const void *in, size_t inlen, char *resbuf) | ||
551 | { | ||
552 | size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_MD5); | ||
553 | gcry_md_hd_t mdh; | ||
554 | unsigned char *hash; | ||
555 | gpg_error_t err; | ||
556 | |||
557 | assert (hlen == 16); | ||
558 | |||
559 | err = gcry_md_open (&mdh, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC); | ||
560 | if (err != GPG_ERR_NO_ERROR) | ||
561 | return GC_INVALID_HASH; | ||
562 | |||
563 | err = gcry_md_setkey (mdh, key, keylen); | ||
564 | if (err != GPG_ERR_NO_ERROR) | ||
565 | { | ||
566 | gcry_md_close (mdh); | ||
567 | return GC_INVALID_HASH; | ||
568 | } | ||
569 | |||
570 | gcry_md_write (mdh, in, inlen); | ||
571 | |||
572 | hash = gcry_md_read (mdh, GCRY_MD_MD5); | ||
573 | if (hash == NULL) | ||
574 | { | ||
575 | gcry_md_close (mdh); | ||
576 | return GC_INVALID_HASH; | ||
577 | } | ||
578 | |||
579 | memcpy (resbuf, hash, hlen); | ||
580 | |||
581 | gcry_md_close (mdh); | ||
582 | |||
583 | return GC_OK; | ||
584 | } | ||
585 | #endif | ||
586 | |||
587 | #ifdef GNULIB_GC_HMAC_SHA1 | ||
588 | Gc_rc gc_hmac_sha1(const void *key, | ||
589 | size_t keylen, | ||
590 | const void *in, | ||
591 | size_t inlen, | ||
592 | char *resbuf) | ||
593 | { | ||
594 | size_t hlen = gcry_md_get_algo_dlen(GCRY_MD_SHA1); | ||
595 | gcry_md_hd_t mdh; | ||
596 | unsigned char *hash; | ||
597 | gpg_error_t err; | ||
598 | |||
599 | assert (hlen == GC_SHA1_DIGEST_SIZE); | ||
600 | |||
601 | err = gcry_md_open(&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC); | ||
602 | if (err != GPG_ERR_NO_ERROR) | ||
603 | return GC_INVALID_HASH; | ||
604 | |||
605 | err = gcry_md_setkey(mdh, key, keylen); | ||
606 | if (err != GPG_ERR_NO_ERROR) | ||
607 | { | ||
608 | gcry_md_close(mdh); | ||
609 | return GC_INVALID_HASH; | ||
610 | } | ||
611 | |||
612 | gcry_md_write(mdh, in, inlen); | ||
613 | |||
614 | hash = gcry_md_read(mdh, GCRY_MD_SHA1); | ||
615 | if (hash == NULL) | ||
616 | { | ||
617 | gcry_md_close(mdh); | ||
618 | return GC_INVALID_HASH; | ||
619 | } | ||
620 | |||
621 | memcpy(resbuf, hash, hlen); | ||
622 | |||
623 | gcry_md_close(mdh); | ||
624 | |||
625 | return GC_OK; | ||
626 | } | ||
627 | #endif | ||