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