NEWS.stable: log cherry-pick [8b18afa]->[c948e19] sys_select: Avoid a syntax error...
[gnulib.git] / lib / gc-gnulib.c
1 /* gc-gnulib.c --- Common gnulib internal crypto interface functions
2  * Copyright (C) 2002-2011 Free Software Foundation, Inc.
3  *
4  * This file is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2, 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 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 internal functions. */
22
23 #include <config.h>
24
25 /* Get prototype. */
26 #include "gc.h"
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 /* For randomize. */
32 #ifdef GNULIB_GC_RANDOM
33 # include <unistd.h>
34 # include <sys/types.h>
35 # include <sys/stat.h>
36 # include <fcntl.h>
37 # include <errno.h>
38 #endif
39
40 /* Hashes. */
41 #ifdef GNULIB_GC_MD2
42 # include "md2.h"
43 #endif
44 #ifdef GNULIB_GC_MD4
45 # include "md4.h"
46 #endif
47 #ifdef GNULIB_GC_MD5
48 # include "md5.h"
49 #endif
50 #ifdef GNULIB_GC_SHA1
51 # include "sha1.h"
52 #endif
53 #if defined(GNULIB_GC_HMAC_MD5) || defined(GNULIB_GC_HMAC_SHA1)
54 # include "hmac.h"
55 #endif
56
57 /* Ciphers. */
58 #ifdef GNULIB_GC_ARCFOUR
59 # include "arcfour.h"
60 #endif
61 #ifdef GNULIB_GC_ARCTWO
62 # include "arctwo.h"
63 #endif
64 #ifdef GNULIB_GC_DES
65 # include "des.h"
66 #endif
67 #ifdef GNULIB_GC_RIJNDAEL
68 # include "rijndael-api-fst.h"
69 #endif
70
71 /* The results of open() in this file are not used with fchdir,
72    therefore save some unnecessary work in fchdir.c.  */
73 #undef open
74 #undef close
75
76 #ifdef GNULIB_GC_RANDOM
77 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
78 #  include <windows.h>
79 #  include <wincrypt.h>
80 HCRYPTPROV g_hProv = 0;
81 #  ifndef PROV_INTEL_SEC
82 #   define PROV_INTEL_SEC 22
83 #  endif
84 #  ifndef CRYPT_VERIFY_CONTEXT
85 #   define CRYPT_VERIFY_CONTEXT 0xF0000000
86 #  endif
87 # endif
88 #endif
89
90 Gc_rc
91 gc_init (void)
92 {
93 #ifdef GNULIB_GC_RANDOM
94 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
95   if (g_hProv)
96     CryptReleaseContext (g_hProv, 0);
97
98   /* There is no need to create a container for just random data, so
99      we can use CRYPT_VERIFY_CONTEXT (one call) see:
100      http://blogs.msdn.com/dangriff/archive/2003/11/19/51709.aspx */
101
102   /* We first try to use the Intel PIII RNG if drivers are present */
103   if (!CryptAcquireContext (&g_hProv, NULL, NULL,
104                             PROV_INTEL_SEC, CRYPT_VERIFY_CONTEXT))
105     {
106       /* not a PIII or no drivers available, use default RSA CSP */
107       if (!CryptAcquireContext (&g_hProv, NULL, NULL,
108                                 PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT))
109         return GC_RANDOM_ERROR;
110     }
111 # endif
112 #endif
113
114   return GC_OK;
115 }
116
117 void
118 gc_done (void)
119 {
120 #ifdef GNULIB_GC_RANDOM
121 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
122   if (g_hProv)
123     {
124       CryptReleaseContext (g_hProv, 0);
125       g_hProv = 0;
126     }
127 # endif
128 #endif
129
130   return;
131 }
132
133 #ifdef GNULIB_GC_RANDOM
134
135 /* Randomness. */
136
137 static Gc_rc
138 randomize (int level, char *data, size_t datalen)
139 {
140 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
141   if (!g_hProv)
142     return GC_RANDOM_ERROR;
143   CryptGenRandom (g_hProv, (DWORD) datalen, data);
144 #else
145   int fd;
146   const char *device;
147   size_t len = 0;
148   int rc;
149
150   switch (level)
151     {
152     case 0:
153       device = NAME_OF_NONCE_DEVICE;
154       break;
155
156     case 1:
157       device = NAME_OF_PSEUDO_RANDOM_DEVICE;
158       break;
159
160     default:
161       device = NAME_OF_RANDOM_DEVICE;
162       break;
163     }
164
165   if (strcmp (device, "no") == 0)
166     return GC_RANDOM_ERROR;
167
168   fd = open (device, O_RDONLY);
169   if (fd < 0)
170     return GC_RANDOM_ERROR;
171
172   do
173     {
174       ssize_t tmp;
175
176       tmp = read (fd, data, datalen);
177
178       if (tmp < 0)
179         {
180           int save_errno = errno;
181           close (fd);
182           errno = save_errno;
183           return GC_RANDOM_ERROR;
184         }
185
186       len += tmp;
187     }
188   while (len < datalen);
189
190   rc = close (fd);
191   if (rc < 0)
192     return GC_RANDOM_ERROR;
193 #endif
194
195   return GC_OK;
196 }
197
198 Gc_rc
199 gc_nonce (char *data, size_t datalen)
200 {
201   return randomize (0, data, datalen);
202 }
203
204 Gc_rc
205 gc_pseudo_random (char *data, size_t datalen)
206 {
207   return randomize (1, data, datalen);
208 }
209
210 Gc_rc
211 gc_random (char *data, size_t datalen)
212 {
213   return randomize (2, data, datalen);
214 }
215
216 #endif
217
218 /* Memory allocation. */
219
220 void
221 gc_set_allocators (gc_malloc_t func_malloc,
222                    gc_malloc_t secure_malloc,
223                    gc_secure_check_t secure_check,
224                    gc_realloc_t func_realloc, gc_free_t func_free)
225 {
226   return;
227 }
228
229 /* Ciphers. */
230
231 typedef struct _gc_cipher_ctx
232 {
233   Gc_cipher alg;
234   Gc_cipher_mode mode;
235 #ifdef GNULIB_GC_ARCTWO
236   arctwo_context arctwoContext;
237   char arctwoIV[ARCTWO_BLOCK_SIZE];
238 #endif
239 #ifdef GNULIB_GC_ARCFOUR
240   arcfour_context arcfourContext;
241 #endif
242 #ifdef GNULIB_GC_DES
243   gl_des_ctx desContext;
244 #endif
245 #ifdef GNULIB_GC_RIJNDAEL
246   rijndaelKeyInstance aesEncKey;
247   rijndaelKeyInstance aesDecKey;
248   rijndaelCipherInstance aesContext;
249 #endif
250 } _gc_cipher_ctx;
251
252 Gc_rc
253 gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
254                 gc_cipher_handle * outhandle)
255 {
256   _gc_cipher_ctx *ctx;
257   Gc_rc rc = GC_OK;
258
259   ctx = calloc (sizeof (*ctx), 1);
260   if (!ctx)
261     return GC_MALLOC_ERROR;
262
263   ctx->alg = alg;
264   ctx->mode = mode;
265
266   switch (alg)
267     {
268 #ifdef GNULIB_GC_ARCTWO
269     case GC_ARCTWO40:
270       switch (mode)
271         {
272         case GC_ECB:
273         case GC_CBC:
274           break;
275
276         default:
277           rc = GC_INVALID_CIPHER;
278         }
279       break;
280 #endif
281
282 #ifdef GNULIB_GC_ARCFOUR
283     case GC_ARCFOUR128:
284     case GC_ARCFOUR40:
285       switch (mode)
286         {
287         case GC_STREAM:
288           break;
289
290         default:
291           rc = GC_INVALID_CIPHER;
292         }
293       break;
294 #endif
295
296 #ifdef GNULIB_GC_DES
297     case GC_DES:
298       switch (mode)
299         {
300         case GC_ECB:
301           break;
302
303         default:
304           rc = GC_INVALID_CIPHER;
305         }
306       break;
307 #endif
308
309 #ifdef GNULIB_GC_RIJNDAEL
310     case GC_AES128:
311     case GC_AES192:
312     case GC_AES256:
313       switch (mode)
314         {
315         case GC_ECB:
316         case GC_CBC:
317           break;
318
319         default:
320           rc = GC_INVALID_CIPHER;
321         }
322       break;
323 #endif
324
325     default:
326       rc = GC_INVALID_CIPHER;
327     }
328
329   if (rc == GC_OK)
330     *outhandle = ctx;
331   else
332     free (ctx);
333
334   return rc;
335 }
336
337 Gc_rc
338 gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
339 {
340   _gc_cipher_ctx *ctx = handle;
341
342   switch (ctx->alg)
343     {
344 #ifdef GNULIB_GC_ARCTWO
345     case GC_ARCTWO40:
346       arctwo_setkey (&ctx->arctwoContext, keylen, key);
347       break;
348 #endif
349
350 #ifdef GNULIB_GC_ARCFOUR
351     case GC_ARCFOUR128:
352     case GC_ARCFOUR40:
353       arcfour_setkey (&ctx->arcfourContext, key, keylen);
354       break;
355 #endif
356
357 #ifdef GNULIB_GC_DES
358     case GC_DES:
359       if (keylen != 8)
360         return GC_INVALID_CIPHER;
361       gl_des_setkey (&ctx->desContext, key);
362       break;
363 #endif
364
365 #ifdef GNULIB_GC_RIJNDAEL
366     case GC_AES128:
367     case GC_AES192:
368     case GC_AES256:
369       {
370         rijndael_rc rc;
371         size_t i;
372         char keyMaterial[RIJNDAEL_MAX_KEY_SIZE + 1];
373
374         for (i = 0; i < keylen; i++)
375           sprintf (&keyMaterial[2 * i], "%02x", key[i] & 0xFF);
376
377         rc = rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT,
378                               keylen * 8, keyMaterial);
379         if (rc < 0)
380           return GC_INVALID_CIPHER;
381
382         rc = rijndaelMakeKey (&ctx->aesDecKey, RIJNDAEL_DIR_DECRYPT,
383                               keylen * 8, keyMaterial);
384         if (rc < 0)
385           return GC_INVALID_CIPHER;
386
387         rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_ECB, NULL);
388         if (rc < 0)
389           return GC_INVALID_CIPHER;
390       }
391       break;
392 #endif
393
394     default:
395       return GC_INVALID_CIPHER;
396     }
397
398   return GC_OK;
399 }
400
401 Gc_rc
402 gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
403 {
404   _gc_cipher_ctx *ctx = handle;
405
406   switch (ctx->alg)
407     {
408 #ifdef GNULIB_GC_ARCTWO
409     case GC_ARCTWO40:
410       if (ivlen != ARCTWO_BLOCK_SIZE)
411         return GC_INVALID_CIPHER;
412       memcpy (ctx->arctwoIV, iv, ivlen);
413       break;
414 #endif
415
416 #ifdef GNULIB_GC_RIJNDAEL
417     case GC_AES128:
418     case GC_AES192:
419     case GC_AES256:
420       switch (ctx->mode)
421         {
422         case GC_ECB:
423           /* Doesn't use IV. */
424           break;
425
426         case GC_CBC:
427           {
428             rijndael_rc rc;
429             size_t i;
430             char ivMaterial[2 * RIJNDAEL_MAX_IV_SIZE + 1];
431
432             for (i = 0; i < ivlen; i++)
433               sprintf (&ivMaterial[2 * i], "%02x", iv[i] & 0xFF);
434
435             rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC,
436                                      ivMaterial);
437             if (rc < 0)
438               return GC_INVALID_CIPHER;
439           }
440           break;
441
442         default:
443           return GC_INVALID_CIPHER;
444         }
445       break;
446 #endif
447
448     default:
449       return GC_INVALID_CIPHER;
450     }
451
452   return GC_OK;
453 }
454
455 Gc_rc
456 gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
457 {
458   _gc_cipher_ctx *ctx = handle;
459
460   switch (ctx->alg)
461     {
462 #ifdef GNULIB_GC_ARCTWO
463     case GC_ARCTWO40:
464       switch (ctx->mode)
465         {
466         case GC_ECB:
467           arctwo_encrypt (&ctx->arctwoContext, data, data, len);
468           break;
469
470         case GC_CBC:
471           for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE,
472                data += ARCTWO_BLOCK_SIZE)
473             {
474               size_t i;
475               for (i = 0; i < ARCTWO_BLOCK_SIZE; i++)
476                 data[i] ^= ctx->arctwoIV[i];
477               arctwo_encrypt (&ctx->arctwoContext, data, data,
478                               ARCTWO_BLOCK_SIZE);
479               memcpy (ctx->arctwoIV, data, ARCTWO_BLOCK_SIZE);
480             }
481           break;
482
483         default:
484           return GC_INVALID_CIPHER;
485         }
486       break;
487 #endif
488
489 #ifdef GNULIB_GC_ARCFOUR
490     case GC_ARCFOUR128:
491     case GC_ARCFOUR40:
492       arcfour_stream (&ctx->arcfourContext, data, data, len);
493       break;
494 #endif
495
496 #ifdef GNULIB_GC_DES
497     case GC_DES:
498       for (; len >= 8; len -= 8, data += 8)
499         gl_des_ecb_encrypt (&ctx->desContext, data, data);
500       break;
501 #endif
502
503 #ifdef GNULIB_GC_RIJNDAEL
504     case GC_AES128:
505     case GC_AES192:
506     case GC_AES256:
507       {
508         int nblocks;
509
510         nblocks = rijndaelBlockEncrypt (&ctx->aesContext, &ctx->aesEncKey,
511                                         data, 8 * len, data);
512         if (nblocks < 0)
513           return GC_INVALID_CIPHER;
514       }
515       break;
516 #endif
517
518     default:
519       return GC_INVALID_CIPHER;
520     }
521
522   return GC_OK;
523 }
524
525 Gc_rc
526 gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
527 {
528   _gc_cipher_ctx *ctx = handle;
529
530   switch (ctx->alg)
531     {
532 #ifdef GNULIB_GC_ARCTWO
533     case GC_ARCTWO40:
534       switch (ctx->mode)
535         {
536         case GC_ECB:
537           arctwo_decrypt (&ctx->arctwoContext, data, data, len);
538           break;
539
540         case GC_CBC:
541           for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE,
542                data += ARCTWO_BLOCK_SIZE)
543             {
544               char tmpIV[ARCTWO_BLOCK_SIZE];
545               size_t i;
546               memcpy (tmpIV, data, ARCTWO_BLOCK_SIZE);
547               arctwo_decrypt (&ctx->arctwoContext, data, data,
548                               ARCTWO_BLOCK_SIZE);
549               for (i = 0; i < ARCTWO_BLOCK_SIZE; i++)
550                 data[i] ^= ctx->arctwoIV[i];
551               memcpy (ctx->arctwoIV, tmpIV, ARCTWO_BLOCK_SIZE);
552             }
553           break;
554
555         default:
556           return GC_INVALID_CIPHER;
557         }
558       break;
559 #endif
560
561 #ifdef GNULIB_GC_ARCFOUR
562     case GC_ARCFOUR128:
563     case GC_ARCFOUR40:
564       arcfour_stream (&ctx->arcfourContext, data, data, len);
565       break;
566 #endif
567
568 #ifdef GNULIB_GC_DES
569     case GC_DES:
570       for (; len >= 8; len -= 8, data += 8)
571         gl_des_ecb_decrypt (&ctx->desContext, data, data);
572       break;
573 #endif
574
575 #ifdef GNULIB_GC_RIJNDAEL
576     case GC_AES128:
577     case GC_AES192:
578     case GC_AES256:
579       {
580         int nblocks;
581
582         nblocks = rijndaelBlockDecrypt (&ctx->aesContext, &ctx->aesDecKey,
583                                         data, 8 * len, data);
584         if (nblocks < 0)
585           return GC_INVALID_CIPHER;
586       }
587       break;
588 #endif
589
590     default:
591       return GC_INVALID_CIPHER;
592     }
593
594   return GC_OK;
595 }
596
597 Gc_rc
598 gc_cipher_close (gc_cipher_handle handle)
599 {
600   _gc_cipher_ctx *ctx = handle;
601
602   free (ctx);
603
604   return GC_OK;
605 }
606
607 /* Hashes. */
608
609 #define MAX_DIGEST_SIZE 20
610
611 typedef struct _gc_hash_ctx
612 {
613   Gc_hash alg;
614   Gc_hash_mode mode;
615   char hash[MAX_DIGEST_SIZE];
616 #ifdef GNULIB_GC_MD2
617   struct md2_ctx md2Context;
618 #endif
619 #ifdef GNULIB_GC_MD4
620   struct md4_ctx md4Context;
621 #endif
622 #ifdef GNULIB_GC_MD5
623   struct md5_ctx md5Context;
624 #endif
625 #ifdef GNULIB_GC_SHA1
626   struct sha1_ctx sha1Context;
627 #endif
628 } _gc_hash_ctx;
629
630 Gc_rc
631 gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
632 {
633   _gc_hash_ctx *ctx;
634   Gc_rc rc = GC_OK;
635
636   ctx = calloc (sizeof (*ctx), 1);
637   if (!ctx)
638     return GC_MALLOC_ERROR;
639
640   ctx->alg = hash;
641   ctx->mode = mode;
642
643   switch (hash)
644     {
645 #ifdef GNULIB_GC_MD2
646     case GC_MD2:
647       md2_init_ctx (&ctx->md2Context);
648       break;
649 #endif
650
651 #ifdef GNULIB_GC_MD4
652     case GC_MD4:
653       md4_init_ctx (&ctx->md4Context);
654       break;
655 #endif
656
657 #ifdef GNULIB_GC_MD5
658     case GC_MD5:
659       md5_init_ctx (&ctx->md5Context);
660       break;
661 #endif
662
663 #ifdef GNULIB_GC_SHA1
664     case GC_SHA1:
665       sha1_init_ctx (&ctx->sha1Context);
666       break;
667 #endif
668
669     default:
670       rc = GC_INVALID_HASH;
671       break;
672     }
673
674   switch (mode)
675     {
676     case 0:
677       break;
678
679     default:
680       rc = GC_INVALID_HASH;
681       break;
682     }
683
684   if (rc == GC_OK)
685     *outhandle = ctx;
686   else
687     free (ctx);
688
689   return rc;
690 }
691
692 Gc_rc
693 gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
694 {
695   _gc_hash_ctx *in = handle;
696   _gc_hash_ctx *out;
697
698   *outhandle = out = calloc (sizeof (*out), 1);
699   if (!out)
700     return GC_MALLOC_ERROR;
701
702   memcpy (out, in, sizeof (*out));
703
704   return GC_OK;
705 }
706
707 size_t
708 gc_hash_digest_length (Gc_hash hash)
709 {
710   size_t len;
711
712   switch (hash)
713     {
714     case GC_MD2:
715       len = GC_MD2_DIGEST_SIZE;
716       break;
717
718     case GC_MD4:
719       len = GC_MD4_DIGEST_SIZE;
720       break;
721
722     case GC_MD5:
723       len = GC_MD5_DIGEST_SIZE;
724       break;
725
726     case GC_RMD160:
727       len = GC_RMD160_DIGEST_SIZE;
728       break;
729
730     case GC_SHA1:
731       len = GC_SHA1_DIGEST_SIZE;
732       break;
733
734     default:
735       return 0;
736     }
737
738   return len;
739 }
740
741 void
742 gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
743 {
744   _gc_hash_ctx *ctx = handle;
745
746   switch (ctx->alg)
747     {
748 #ifdef GNULIB_GC_MD2
749     case GC_MD2:
750       md2_process_bytes (data, len, &ctx->md2Context);
751       break;
752 #endif
753
754 #ifdef GNULIB_GC_MD4
755     case GC_MD4:
756       md4_process_bytes (data, len, &ctx->md4Context);
757       break;
758 #endif
759
760 #ifdef GNULIB_GC_MD5
761     case GC_MD5:
762       md5_process_bytes (data, len, &ctx->md5Context);
763       break;
764 #endif
765
766 #ifdef GNULIB_GC_SHA1
767     case GC_SHA1:
768       sha1_process_bytes (data, len, &ctx->sha1Context);
769       break;
770 #endif
771
772     default:
773       break;
774     }
775 }
776
777 const char *
778 gc_hash_read (gc_hash_handle handle)
779 {
780   _gc_hash_ctx *ctx = handle;
781   const char *ret = NULL;
782
783   switch (ctx->alg)
784     {
785 #ifdef GNULIB_GC_MD2
786     case GC_MD2:
787       md2_finish_ctx (&ctx->md2Context, ctx->hash);
788       ret = ctx->hash;
789       break;
790 #endif
791
792 #ifdef GNULIB_GC_MD4
793     case GC_MD4:
794       md4_finish_ctx (&ctx->md4Context, ctx->hash);
795       ret = ctx->hash;
796       break;
797 #endif
798
799 #ifdef GNULIB_GC_MD5
800     case GC_MD5:
801       md5_finish_ctx (&ctx->md5Context, ctx->hash);
802       ret = ctx->hash;
803       break;
804 #endif
805
806 #ifdef GNULIB_GC_SHA1
807     case GC_SHA1:
808       sha1_finish_ctx (&ctx->sha1Context, ctx->hash);
809       ret = ctx->hash;
810       break;
811 #endif
812
813     default:
814       return NULL;
815     }
816
817   return ret;
818 }
819
820 void
821 gc_hash_close (gc_hash_handle handle)
822 {
823   _gc_hash_ctx *ctx = handle;
824
825   free (ctx);
826 }
827
828 Gc_rc
829 gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
830 {
831   switch (hash)
832     {
833 #ifdef GNULIB_GC_MD2
834     case GC_MD2:
835       md2_buffer (in, inlen, resbuf);
836       break;
837 #endif
838
839 #ifdef GNULIB_GC_MD4
840     case GC_MD4:
841       md4_buffer (in, inlen, resbuf);
842       break;
843 #endif
844
845 #ifdef GNULIB_GC_MD5
846     case GC_MD5:
847       md5_buffer (in, inlen, resbuf);
848       break;
849 #endif
850
851 #ifdef GNULIB_GC_SHA1
852     case GC_SHA1:
853       sha1_buffer (in, inlen, resbuf);
854       break;
855 #endif
856
857     default:
858       return GC_INVALID_HASH;
859     }
860
861   return GC_OK;
862 }
863
864 #ifdef GNULIB_GC_MD2
865 Gc_rc
866 gc_md2 (const void *in, size_t inlen, void *resbuf)
867 {
868   md2_buffer (in, inlen, resbuf);
869   return GC_OK;
870 }
871 #endif
872
873 #ifdef GNULIB_GC_MD4
874 Gc_rc
875 gc_md4 (const void *in, size_t inlen, void *resbuf)
876 {
877   md4_buffer (in, inlen, resbuf);
878   return GC_OK;
879 }
880 #endif
881
882 #ifdef GNULIB_GC_MD5
883 Gc_rc
884 gc_md5 (const void *in, size_t inlen, void *resbuf)
885 {
886   md5_buffer (in, inlen, resbuf);
887   return GC_OK;
888 }
889 #endif
890
891 #ifdef GNULIB_GC_SHA1
892 Gc_rc
893 gc_sha1 (const void *in, size_t inlen, void *resbuf)
894 {
895   sha1_buffer (in, inlen, resbuf);
896   return GC_OK;
897 }
898 #endif
899
900 #ifdef GNULIB_GC_HMAC_MD5
901 Gc_rc
902 gc_hmac_md5 (const void *key, size_t keylen,
903              const void *in, size_t inlen, char *resbuf)
904 {
905   hmac_md5 (key, keylen, in, inlen, resbuf);
906   return GC_OK;
907 }
908 #endif
909
910 #ifdef GNULIB_GC_HMAC_SHA1
911 Gc_rc
912 gc_hmac_sha1 (const void *key, size_t keylen,
913               const void *in, size_t inlen, char *resbuf)
914 {
915   hmac_sha1 (key, keylen, in, inlen, resbuf);
916   return GC_OK;
917 }
918 #endif