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