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