Bump to 1.14.1
[platform/upstream/augeas.git] / lib / gc-gnulib.c
1 /* gc-gnulib.c --- Common gnulib internal crypto interface functions
2  * Copyright (C) 2002-2016 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, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 /* Note: This file is only built if GC uses internal functions. */
20
21 #include <config.h>
22
23 /* Get prototype. */
24 #include "gc.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28
29 /* For randomize. */
30 #ifdef GNULIB_GC_RANDOM
31 # include <unistd.h>
32 # include <sys/types.h>
33 # include <sys/stat.h>
34 # include <fcntl.h>
35 # include <errno.h>
36 #endif
37
38 /* Hashes. */
39 #ifdef GNULIB_GC_MD2
40 # include "md2.h"
41 #endif
42 #ifdef GNULIB_GC_MD4
43 # include "md4.h"
44 #endif
45 #ifdef GNULIB_GC_MD5
46 # include "md5.h"
47 #endif
48 #ifdef GNULIB_GC_SHA1
49 # include "sha1.h"
50 #endif
51 #if defined(GNULIB_GC_HMAC_MD5) || defined(GNULIB_GC_HMAC_SHA1) || defined(GNULIB_GC_HMAC_SHA256) || defined(GNULIB_GC_HMAC_SHA512)
52 # include "hmac.h"
53 #endif
54
55 /* Ciphers. */
56 #ifdef GNULIB_GC_ARCFOUR
57 # include "arcfour.h"
58 #endif
59 #ifdef GNULIB_GC_ARCTWO
60 # include "arctwo.h"
61 #endif
62 #ifdef GNULIB_GC_DES
63 # include "des.h"
64 #endif
65 #ifdef GNULIB_GC_RIJNDAEL
66 # include "rijndael-api-fst.h"
67 #endif
68
69 #ifdef GNULIB_GC_RANDOM
70 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
71 #  include <windows.h>
72 #  include <wincrypt.h>
73 HCRYPTPROV g_hProv = 0;
74 #  ifndef PROV_INTEL_SEC
75 #   define PROV_INTEL_SEC 22
76 #  endif
77 #  ifndef CRYPT_VERIFY_CONTEXT
78 #   define CRYPT_VERIFY_CONTEXT 0xF0000000
79 #  endif
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
91   /* There is no need to create a container for just random data, so
92      we can use CRYPT_VERIFY_CONTEXT (one call) see:
93      http://blogs.msdn.com/dangriff/archive/2003/11/19/51709.aspx */
94
95   /* We first try to use the Intel PIII RNG if drivers are present */
96   if (!CryptAcquireContext (&g_hProv, NULL, NULL,
97                             PROV_INTEL_SEC, CRYPT_VERIFY_CONTEXT))
98     {
99       /* not a PIII or no drivers available, use default RSA CSP */
100       if (!CryptAcquireContext (&g_hProv, NULL, NULL,
101                                 PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT))
102         return GC_RANDOM_ERROR;
103     }
104 # endif
105 #endif
106
107   return GC_OK;
108 }
109
110 void
111 gc_done (void)
112 {
113 #ifdef GNULIB_GC_RANDOM
114 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
115   if (g_hProv)
116     {
117       CryptReleaseContext (g_hProv, 0);
118       g_hProv = 0;
119     }
120 # endif
121 #endif
122
123   return;
124 }
125
126 #ifdef GNULIB_GC_RANDOM
127
128 /* Randomness. */
129
130 static Gc_rc
131 randomize (int level, char *data, size_t datalen)
132 {
133 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
134   if (!g_hProv)
135     return GC_RANDOM_ERROR;
136   CryptGenRandom (g_hProv, (DWORD) datalen, data);
137 #else
138   int fd;
139   const char *device;
140   size_t len = 0;
141   int rc;
142
143   switch (level)
144     {
145     case 0:
146       device = NAME_OF_NONCE_DEVICE;
147       break;
148
149     case 1:
150       device = NAME_OF_PSEUDO_RANDOM_DEVICE;
151       break;
152
153     default:
154       device = NAME_OF_RANDOM_DEVICE;
155       break;
156     }
157
158   if (strcmp (device, "no") == 0)
159     return GC_RANDOM_ERROR;
160
161   fd = open (device, O_RDONLY);
162   if (fd < 0)
163     return GC_RANDOM_ERROR;
164
165   do
166     {
167       ssize_t tmp;
168
169       tmp = read (fd, data, datalen);
170
171       if (tmp < 0)
172         {
173           int save_errno = errno;
174           close (fd);
175           errno = save_errno;
176           return GC_RANDOM_ERROR;
177         }
178
179       len += tmp;
180     }
181   while (len < datalen);
182
183   rc = close (fd);
184   if (rc < 0)
185     return GC_RANDOM_ERROR;
186 #endif
187
188   return GC_OK;
189 }
190
191 Gc_rc
192 gc_nonce (char *data, size_t datalen)
193 {
194   return randomize (0, data, datalen);
195 }
196
197 Gc_rc
198 gc_pseudo_random (char *data, size_t datalen)
199 {
200   return randomize (1, data, datalen);
201 }
202
203 Gc_rc
204 gc_random (char *data, size_t datalen)
205 {
206   return randomize (2, data, datalen);
207 }
208
209 #endif
210
211 /* Memory allocation. */
212
213 void
214 gc_set_allocators (gc_malloc_t func_malloc,
215                    gc_malloc_t secure_malloc,
216                    gc_secure_check_t secure_check,
217                    gc_realloc_t func_realloc, gc_free_t func_free)
218 {
219   return;
220 }
221
222 /* Ciphers. */
223
224 typedef struct _gc_cipher_ctx
225 {
226   Gc_cipher alg;
227   Gc_cipher_mode mode;
228 #ifdef GNULIB_GC_ARCTWO
229   arctwo_context arctwoContext;
230   char arctwoIV[ARCTWO_BLOCK_SIZE];
231 #endif
232 #ifdef GNULIB_GC_ARCFOUR
233   arcfour_context arcfourContext;
234 #endif
235 #ifdef GNULIB_GC_DES
236   gl_des_ctx desContext;
237 #endif
238 #ifdef GNULIB_GC_RIJNDAEL
239   rijndaelKeyInstance aesEncKey;
240   rijndaelKeyInstance aesDecKey;
241   rijndaelCipherInstance aesContext;
242 #endif
243 } _gc_cipher_ctx;
244
245 Gc_rc
246 gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
247                 gc_cipher_handle * outhandle)
248 {
249   _gc_cipher_ctx *ctx;
250   Gc_rc rc = GC_OK;
251
252   ctx = calloc (sizeof (*ctx), 1);
253   if (!ctx)
254     return GC_MALLOC_ERROR;
255
256   ctx->alg = alg;
257   ctx->mode = mode;
258
259   switch (alg)
260     {
261 #ifdef GNULIB_GC_ARCTWO
262     case GC_ARCTWO40:
263       switch (mode)
264         {
265         case GC_ECB:
266         case GC_CBC:
267           break;
268
269         default:
270           rc = GC_INVALID_CIPHER;
271         }
272       break;
273 #endif
274
275 #ifdef GNULIB_GC_ARCFOUR
276     case GC_ARCFOUR128:
277     case GC_ARCFOUR40:
278       switch (mode)
279         {
280         case GC_STREAM:
281           break;
282
283         default:
284           rc = GC_INVALID_CIPHER;
285         }
286       break;
287 #endif
288
289 #ifdef GNULIB_GC_DES
290     case GC_DES:
291       switch (mode)
292         {
293         case GC_ECB:
294           break;
295
296         default:
297           rc = GC_INVALID_CIPHER;
298         }
299       break;
300 #endif
301
302 #ifdef GNULIB_GC_RIJNDAEL
303     case GC_AES128:
304     case GC_AES192:
305     case GC_AES256:
306       switch (mode)
307         {
308         case GC_ECB:
309         case GC_CBC:
310           break;
311
312         default:
313           rc = GC_INVALID_CIPHER;
314         }
315       break;
316 #endif
317
318     default:
319       rc = GC_INVALID_CIPHER;
320     }
321
322   if (rc == GC_OK)
323     *outhandle = ctx;
324   else
325     free (ctx);
326
327   return rc;
328 }
329
330 Gc_rc
331 gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
332 {
333   _gc_cipher_ctx *ctx = handle;
334
335   switch (ctx->alg)
336     {
337 #ifdef GNULIB_GC_ARCTWO
338     case GC_ARCTWO40:
339       arctwo_setkey (&ctx->arctwoContext, keylen, key);
340       break;
341 #endif
342
343 #ifdef GNULIB_GC_ARCFOUR
344     case GC_ARCFOUR128:
345     case GC_ARCFOUR40:
346       arcfour_setkey (&ctx->arcfourContext, key, keylen);
347       break;
348 #endif
349
350 #ifdef GNULIB_GC_DES
351     case GC_DES:
352       if (keylen != 8)
353         return GC_INVALID_CIPHER;
354       gl_des_setkey (&ctx->desContext, key);
355       break;
356 #endif
357
358 #ifdef GNULIB_GC_RIJNDAEL
359     case GC_AES128:
360     case GC_AES192:
361     case GC_AES256:
362       {
363         rijndael_rc rc;
364         size_t i;
365         char keyMaterial[RIJNDAEL_MAX_KEY_SIZE + 1];
366
367         for (i = 0; i < keylen; i++)
368           sprintf (&keyMaterial[2 * i], "%02x", key[i] & 0xFF);
369
370         rc = rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT,
371                               keylen * 8, keyMaterial);
372         if (rc < 0)
373           return GC_INVALID_CIPHER;
374
375         rc = rijndaelMakeKey (&ctx->aesDecKey, RIJNDAEL_DIR_DECRYPT,
376                               keylen * 8, keyMaterial);
377         if (rc < 0)
378           return GC_INVALID_CIPHER;
379
380         rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_ECB, NULL);
381         if (rc < 0)
382           return GC_INVALID_CIPHER;
383       }
384       break;
385 #endif
386
387     default:
388       return GC_INVALID_CIPHER;
389     }
390
391   return GC_OK;
392 }
393
394 Gc_rc
395 gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
396 {
397   _gc_cipher_ctx *ctx = handle;
398
399   switch (ctx->alg)
400     {
401 #ifdef GNULIB_GC_ARCTWO
402     case GC_ARCTWO40:
403       if (ivlen != ARCTWO_BLOCK_SIZE)
404         return GC_INVALID_CIPHER;
405       memcpy (ctx->arctwoIV, iv, ivlen);
406       break;
407 #endif
408
409 #ifdef GNULIB_GC_RIJNDAEL
410     case GC_AES128:
411     case GC_AES192:
412     case GC_AES256:
413       switch (ctx->mode)
414         {
415         case GC_ECB:
416           /* Doesn't use IV. */
417           break;
418
419         case GC_CBC:
420           {
421             rijndael_rc rc;
422             size_t i;
423             char ivMaterial[2 * RIJNDAEL_MAX_IV_SIZE + 1];
424
425             for (i = 0; i < ivlen; i++)
426               sprintf (&ivMaterial[2 * i], "%02x", iv[i] & 0xFF);
427
428             rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC,
429                                      ivMaterial);
430             if (rc < 0)
431               return GC_INVALID_CIPHER;
432           }
433           break;
434
435         default:
436           return GC_INVALID_CIPHER;
437         }
438       break;
439 #endif
440
441     default:
442       return GC_INVALID_CIPHER;
443     }
444
445   return GC_OK;
446 }
447
448 Gc_rc
449 gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
450 {
451   _gc_cipher_ctx *ctx = handle;
452
453   switch (ctx->alg)
454     {
455 #ifdef GNULIB_GC_ARCTWO
456     case GC_ARCTWO40:
457       switch (ctx->mode)
458         {
459         case GC_ECB:
460           arctwo_encrypt (&ctx->arctwoContext, data, data, len);
461           break;
462
463         case GC_CBC:
464           for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE,
465                data += ARCTWO_BLOCK_SIZE)
466             {
467               size_t i;
468               for (i = 0; i < ARCTWO_BLOCK_SIZE; i++)
469                 data[i] ^= ctx->arctwoIV[i];
470               arctwo_encrypt (&ctx->arctwoContext, data, data,
471                               ARCTWO_BLOCK_SIZE);
472               memcpy (ctx->arctwoIV, data, ARCTWO_BLOCK_SIZE);
473             }
474           break;
475
476         default:
477           return GC_INVALID_CIPHER;
478         }
479       break;
480 #endif
481
482 #ifdef GNULIB_GC_ARCFOUR
483     case GC_ARCFOUR128:
484     case GC_ARCFOUR40:
485       arcfour_stream (&ctx->arcfourContext, data, data, len);
486       break;
487 #endif
488
489 #ifdef GNULIB_GC_DES
490     case GC_DES:
491       for (; len >= 8; len -= 8, data += 8)
492         gl_des_ecb_encrypt (&ctx->desContext, data, data);
493       break;
494 #endif
495
496 #ifdef GNULIB_GC_RIJNDAEL
497     case GC_AES128:
498     case GC_AES192:
499     case GC_AES256:
500       {
501         int nblocks;
502
503         nblocks = rijndaelBlockEncrypt (&ctx->aesContext, &ctx->aesEncKey,
504                                         data, 8 * len, data);
505         if (nblocks < 0)
506           return GC_INVALID_CIPHER;
507       }
508       break;
509 #endif
510
511     default:
512       return GC_INVALID_CIPHER;
513     }
514
515   return GC_OK;
516 }
517
518 Gc_rc
519 gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
520 {
521   _gc_cipher_ctx *ctx = handle;
522
523   switch (ctx->alg)
524     {
525 #ifdef GNULIB_GC_ARCTWO
526     case GC_ARCTWO40:
527       switch (ctx->mode)
528         {
529         case GC_ECB:
530           arctwo_decrypt (&ctx->arctwoContext, data, data, len);
531           break;
532
533         case GC_CBC:
534           for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE,
535                data += ARCTWO_BLOCK_SIZE)
536             {
537               char tmpIV[ARCTWO_BLOCK_SIZE];
538               size_t i;
539               memcpy (tmpIV, data, ARCTWO_BLOCK_SIZE);
540               arctwo_decrypt (&ctx->arctwoContext, data, data,
541                               ARCTWO_BLOCK_SIZE);
542               for (i = 0; i < ARCTWO_BLOCK_SIZE; i++)
543                 data[i] ^= ctx->arctwoIV[i];
544               memcpy (ctx->arctwoIV, tmpIV, ARCTWO_BLOCK_SIZE);
545             }
546           break;
547
548         default:
549           return GC_INVALID_CIPHER;
550         }
551       break;
552 #endif
553
554 #ifdef GNULIB_GC_ARCFOUR
555     case GC_ARCFOUR128:
556     case GC_ARCFOUR40:
557       arcfour_stream (&ctx->arcfourContext, data, data, len);
558       break;
559 #endif
560
561 #ifdef GNULIB_GC_DES
562     case GC_DES:
563       for (; len >= 8; len -= 8, data += 8)
564         gl_des_ecb_decrypt (&ctx->desContext, data, data);
565       break;
566 #endif
567
568 #ifdef GNULIB_GC_RIJNDAEL
569     case GC_AES128:
570     case GC_AES192:
571     case GC_AES256:
572       {
573         int nblocks;
574
575         nblocks = rijndaelBlockDecrypt (&ctx->aesContext, &ctx->aesDecKey,
576                                         data, 8 * len, data);
577         if (nblocks < 0)
578           return GC_INVALID_CIPHER;
579       }
580       break;
581 #endif
582
583     default:
584       return GC_INVALID_CIPHER;
585     }
586
587   return GC_OK;
588 }
589
590 Gc_rc
591 gc_cipher_close (gc_cipher_handle handle)
592 {
593   _gc_cipher_ctx *ctx = handle;
594
595   free (ctx);
596
597   return GC_OK;
598 }
599
600 /* Hashes. */
601
602 #define MAX_DIGEST_SIZE 20
603
604 typedef struct _gc_hash_ctx
605 {
606   Gc_hash alg;
607   Gc_hash_mode mode;
608   char hash[MAX_DIGEST_SIZE];
609 #ifdef GNULIB_GC_MD2
610   struct md2_ctx md2Context;
611 #endif
612 #ifdef GNULIB_GC_MD4
613   struct md4_ctx md4Context;
614 #endif
615 #ifdef GNULIB_GC_MD5
616   struct md5_ctx md5Context;
617 #endif
618 #ifdef GNULIB_GC_SHA1
619   struct sha1_ctx sha1Context;
620 #endif
621 } _gc_hash_ctx;
622
623 Gc_rc
624 gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
625 {
626   _gc_hash_ctx *ctx;
627   Gc_rc rc = GC_OK;
628
629   if (mode != 0)
630     return GC_INVALID_HASH;
631
632   ctx = calloc (sizeof (*ctx), 1);
633   if (!ctx)
634     return GC_MALLOC_ERROR;
635
636   ctx->alg = hash;
637   ctx->mode = mode;
638
639   switch (hash)
640     {
641 #ifdef GNULIB_GC_MD2
642     case GC_MD2:
643       md2_init_ctx (&ctx->md2Context);
644       break;
645 #endif
646
647 #ifdef GNULIB_GC_MD4
648     case GC_MD4:
649       md4_init_ctx (&ctx->md4Context);
650       break;
651 #endif
652
653 #ifdef GNULIB_GC_MD5
654     case GC_MD5:
655       md5_init_ctx (&ctx->md5Context);
656       break;
657 #endif
658
659 #ifdef GNULIB_GC_SHA1
660     case GC_SHA1:
661       sha1_init_ctx (&ctx->sha1Context);
662       break;
663 #endif
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
905
906 #ifdef GNULIB_GC_HMAC_SHA256
907 Gc_rc
908 gc_hmac_sha256 (const void *key, size_t keylen,
909                 const void *in, size_t inlen, char *resbuf)
910 {
911   hmac_sha256 (key, keylen, in, inlen, resbuf);
912   return GC_OK;
913 }
914 #endif
915
916 #ifdef GNULIB_GC_HMAC_SHA512
917 Gc_rc
918 gc_hmac_sha512 (const void *key, size_t keylen,
919                 const void *in, size_t inlen, char *resbuf)
920 {
921   hmac_sha512 (key, keylen, in, inlen, resbuf);
922   return GC_OK;
923 }
924 #endif