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