exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / gc-gnulib.c
blobb2e92da54bbd5724b7cfc4d232863e807f083f1a
1 /* gc-gnulib.c --- Common gnulib internal crypto interface functions
2 * Copyright (C) 2002-2024 Free Software Foundation, Inc.
4 * This file is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1 of the
7 * License, or (at your option) any later version.
9 * This file is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 /* Note: This file is only built if GC uses internal functions. */
21 #include <config.h>
23 /* Get prototype. */
24 #include "gc.h"
26 #include <stdlib.h>
27 #include <string.h>
29 /* For randomize. */
30 #if GNULIB_GC_RANDOM
31 #include <unistd.h>
32 #include <errno.h>
33 #include <sys/random.h>
34 #endif
36 /* Hashes. */
37 #if GNULIB_GC_MD2
38 # include "md2.h"
39 #endif
40 #if GNULIB_GC_MD4
41 # include "md4.h"
42 #endif
43 #if GNULIB_GC_MD5
44 # include "md5.h"
45 #endif
46 #if GNULIB_GC_SHA1
47 # include "sha1.h"
48 #endif
49 #if GNULIB_GC_SHA256
50 # include "sha256.h"
51 #endif
52 #if GNULIB_GC_SHA512
53 # include "sha512.h"
54 #endif
55 #if GNULIB_GC_SM3
56 # include "sm3.h"
57 #endif
58 #if GNULIB_GC_HMAC_MD5 || GNULIB_GC_HMAC_SHA1 || GNULIB_GC_HMAC_SHA256 || GNULIB_GC_HMAC_SHA512
59 # include "hmac.h"
60 #endif
62 /* Ciphers. */
63 #if GNULIB_GC_ARCFOUR
64 # include "arcfour.h"
65 #endif
66 #if GNULIB_GC_ARCTWO
67 # include "arctwo.h"
68 #endif
69 #if GNULIB_GC_DES
70 # include "des.h"
71 #endif
72 #if GNULIB_GC_RIJNDAEL
73 # include "rijndael-api-fst.h"
74 #endif
76 Gc_rc
77 gc_init (void)
79 return GC_OK;
82 void
83 gc_done (void)
85 return;
88 #if GNULIB_GC_RANDOM
90 /* Overwrite BUFFER with random data, under the control of getrandom
91 FLAGS. BUFFER contains LENGTH bytes. Inspired by getentropy,
92 however LENGTH is not restricted to 256. Return 0 on success, -1
93 (setting errno) on failure. */
94 static int
95 randomize (void *buffer, size_t length, unsigned int flags)
97 char *buf = buffer;
99 for (;;)
101 ssize_t bytes;
102 if (length == 0)
103 return GC_OK;
104 while ((bytes = getrandom (buf, length, flags)) < 0)
105 if (errno != EINTR)
106 return GC_RANDOM_ERROR;
107 if (bytes == 0)
108 break;
109 buf += bytes;
110 length -= bytes;
113 return GC_RANDOM_ERROR;
116 Gc_rc
117 gc_nonce (char *data, size_t datalen)
119 return randomize (data, datalen, 0);
122 Gc_rc
123 gc_pseudo_random (char *data, size_t datalen)
125 return randomize (data, datalen, 0);
128 Gc_rc
129 gc_random (char *data, size_t datalen)
131 return randomize (data, datalen, GRND_RANDOM);
134 #endif
136 /* Memory allocation. */
138 void
139 gc_set_allocators (gc_malloc_t func_malloc,
140 gc_malloc_t secure_malloc,
141 gc_secure_check_t secure_check,
142 gc_realloc_t func_realloc, gc_free_t func_free)
144 return;
147 /* Ciphers. */
149 typedef struct _gc_cipher_ctx
151 Gc_cipher alg;
152 Gc_cipher_mode mode;
153 #if GNULIB_GC_ARCTWO
154 arctwo_context arctwoContext;
155 char arctwoIV[ARCTWO_BLOCK_SIZE];
156 #endif
157 #if GNULIB_GC_ARCFOUR
158 arcfour_context arcfourContext;
159 #endif
160 #if GNULIB_GC_DES
161 gl_des_ctx desContext;
162 #endif
163 #if GNULIB_GC_RIJNDAEL
164 rijndaelKeyInstance aesEncKey;
165 rijndaelKeyInstance aesDecKey;
166 rijndaelCipherInstance aesContext;
167 #endif
168 } _gc_cipher_ctx;
170 Gc_rc
171 gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
172 gc_cipher_handle * outhandle)
174 _gc_cipher_ctx *ctx;
175 Gc_rc rc = GC_OK;
177 ctx = calloc (sizeof (*ctx), 1);
178 if (!ctx)
179 return GC_MALLOC_ERROR;
181 ctx->alg = alg;
182 ctx->mode = mode;
184 switch (alg)
186 #if GNULIB_GC_ARCTWO
187 case GC_ARCTWO40:
188 switch (mode)
190 case GC_ECB:
191 case GC_CBC:
192 break;
194 default:
195 rc = GC_INVALID_CIPHER;
197 break;
198 #endif
200 #if GNULIB_GC_ARCFOUR
201 case GC_ARCFOUR128:
202 case GC_ARCFOUR40:
203 switch (mode)
205 case GC_STREAM:
206 break;
208 default:
209 rc = GC_INVALID_CIPHER;
211 break;
212 #endif
214 #if GNULIB_GC_DES
215 case GC_DES:
216 switch (mode)
218 case GC_ECB:
219 break;
221 default:
222 rc = GC_INVALID_CIPHER;
224 break;
225 #endif
227 #if GNULIB_GC_RIJNDAEL
228 case GC_AES128:
229 case GC_AES192:
230 case GC_AES256:
231 switch (mode)
233 case GC_ECB:
234 case GC_CBC:
235 break;
237 default:
238 rc = GC_INVALID_CIPHER;
240 break;
241 #endif
243 default:
244 rc = GC_INVALID_CIPHER;
247 if (rc == GC_OK)
248 *outhandle = ctx;
249 else
250 free (ctx);
252 return rc;
255 Gc_rc
256 gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
258 _gc_cipher_ctx *ctx = handle;
260 switch (ctx->alg)
262 #if GNULIB_GC_ARCTWO
263 case GC_ARCTWO40:
264 arctwo_setkey (&ctx->arctwoContext, keylen, key);
265 break;
266 #endif
268 #if GNULIB_GC_ARCFOUR
269 case GC_ARCFOUR128:
270 case GC_ARCFOUR40:
271 arcfour_setkey (&ctx->arcfourContext, key, keylen);
272 break;
273 #endif
275 #if GNULIB_GC_DES
276 case GC_DES:
277 if (keylen != 8)
278 return GC_INVALID_CIPHER;
279 gl_des_setkey (&ctx->desContext, key);
280 break;
281 #endif
283 #if GNULIB_GC_RIJNDAEL
284 case GC_AES128:
285 case GC_AES192:
286 case GC_AES256:
288 rijndael_rc rc;
289 size_t i;
290 char keyMaterial[RIJNDAEL_MAX_KEY_SIZE + 1];
292 for (i = 0; i < keylen; i++)
293 sprintf (&keyMaterial[2 * i], "%02x", key[i] & 0xFF);
295 rc = rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT,
296 keylen * 8, keyMaterial);
297 if (rc < 0)
298 return GC_INVALID_CIPHER;
300 rc = rijndaelMakeKey (&ctx->aesDecKey, RIJNDAEL_DIR_DECRYPT,
301 keylen * 8, keyMaterial);
302 if (rc < 0)
303 return GC_INVALID_CIPHER;
305 rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_ECB, NULL);
306 if (rc < 0)
307 return GC_INVALID_CIPHER;
309 break;
310 #endif
312 default:
313 return GC_INVALID_CIPHER;
316 return GC_OK;
319 Gc_rc
320 gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
322 _gc_cipher_ctx *ctx = handle;
324 switch (ctx->alg)
326 #if GNULIB_GC_ARCTWO
327 case GC_ARCTWO40:
328 if (ivlen != ARCTWO_BLOCK_SIZE)
329 return GC_INVALID_CIPHER;
330 memcpy (ctx->arctwoIV, iv, ivlen);
331 break;
332 #endif
334 #if GNULIB_GC_RIJNDAEL
335 case GC_AES128:
336 case GC_AES192:
337 case GC_AES256:
338 switch (ctx->mode)
340 case GC_ECB:
341 /* Doesn't use IV. */
342 break;
344 case GC_CBC:
346 rijndael_rc rc;
347 size_t i;
348 char ivMaterial[2 * RIJNDAEL_MAX_IV_SIZE + 1];
350 for (i = 0; i < ivlen; i++)
351 sprintf (&ivMaterial[2 * i], "%02x", iv[i] & 0xFF);
353 rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC,
354 ivMaterial);
355 if (rc < 0)
356 return GC_INVALID_CIPHER;
358 break;
360 default:
361 return GC_INVALID_CIPHER;
363 break;
364 #endif
366 default:
367 return GC_INVALID_CIPHER;
370 return GC_OK;
373 Gc_rc
374 gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
376 _gc_cipher_ctx *ctx = handle;
378 switch (ctx->alg)
380 #if GNULIB_GC_ARCTWO
381 case GC_ARCTWO40:
382 switch (ctx->mode)
384 case GC_ECB:
385 arctwo_encrypt (&ctx->arctwoContext, data, data, len);
386 break;
388 case GC_CBC:
389 for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE,
390 data += ARCTWO_BLOCK_SIZE)
392 size_t i;
393 for (i = 0; i < ARCTWO_BLOCK_SIZE; i++)
394 data[i] ^= ctx->arctwoIV[i];
395 arctwo_encrypt (&ctx->arctwoContext, data, data,
396 ARCTWO_BLOCK_SIZE);
397 memcpy (ctx->arctwoIV, data, ARCTWO_BLOCK_SIZE);
399 break;
401 default:
402 return GC_INVALID_CIPHER;
404 break;
405 #endif
407 #if GNULIB_GC_ARCFOUR
408 case GC_ARCFOUR128:
409 case GC_ARCFOUR40:
410 arcfour_stream (&ctx->arcfourContext, data, data, len);
411 break;
412 #endif
414 #if GNULIB_GC_DES
415 case GC_DES:
416 for (; len >= 8; len -= 8, data += 8)
417 gl_des_ecb_encrypt (&ctx->desContext, data, data);
418 break;
419 #endif
421 #if GNULIB_GC_RIJNDAEL
422 case GC_AES128:
423 case GC_AES192:
424 case GC_AES256:
426 int nblocks;
428 nblocks = rijndaelBlockEncrypt (&ctx->aesContext, &ctx->aesEncKey,
429 data, 8 * len, data);
430 if (nblocks < 0)
431 return GC_INVALID_CIPHER;
433 break;
434 #endif
436 default:
437 return GC_INVALID_CIPHER;
440 return GC_OK;
443 Gc_rc
444 gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
446 _gc_cipher_ctx *ctx = handle;
448 switch (ctx->alg)
450 #if GNULIB_GC_ARCTWO
451 case GC_ARCTWO40:
452 switch (ctx->mode)
454 case GC_ECB:
455 arctwo_decrypt (&ctx->arctwoContext, data, data, len);
456 break;
458 case GC_CBC:
459 for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE,
460 data += ARCTWO_BLOCK_SIZE)
462 char tmpIV[ARCTWO_BLOCK_SIZE];
463 size_t i;
464 memcpy (tmpIV, data, ARCTWO_BLOCK_SIZE);
465 arctwo_decrypt (&ctx->arctwoContext, data, data,
466 ARCTWO_BLOCK_SIZE);
467 for (i = 0; i < ARCTWO_BLOCK_SIZE; i++)
468 data[i] ^= ctx->arctwoIV[i];
469 memcpy (ctx->arctwoIV, tmpIV, ARCTWO_BLOCK_SIZE);
471 break;
473 default:
474 return GC_INVALID_CIPHER;
476 break;
477 #endif
479 #if GNULIB_GC_ARCFOUR
480 case GC_ARCFOUR128:
481 case GC_ARCFOUR40:
482 arcfour_stream (&ctx->arcfourContext, data, data, len);
483 break;
484 #endif
486 #if GNULIB_GC_DES
487 case GC_DES:
488 for (; len >= 8; len -= 8, data += 8)
489 gl_des_ecb_decrypt (&ctx->desContext, data, data);
490 break;
491 #endif
493 #if GNULIB_GC_RIJNDAEL
494 case GC_AES128:
495 case GC_AES192:
496 case GC_AES256:
498 int nblocks;
500 nblocks = rijndaelBlockDecrypt (&ctx->aesContext, &ctx->aesDecKey,
501 data, 8 * len, data);
502 if (nblocks < 0)
503 return GC_INVALID_CIPHER;
505 break;
506 #endif
508 default:
509 return GC_INVALID_CIPHER;
512 return GC_OK;
515 Gc_rc
516 gc_cipher_close (gc_cipher_handle handle)
518 _gc_cipher_ctx *ctx = handle;
520 free (ctx);
522 return GC_OK;
525 /* Hashes. */
527 #define MAX_DIGEST_SIZE 64
529 typedef struct _gc_hash_ctx
531 Gc_hash alg;
532 Gc_hash_mode mode;
533 char hash[MAX_DIGEST_SIZE];
534 #if GNULIB_GC_MD2
535 struct md2_ctx md2Context;
536 #endif
537 #if GNULIB_GC_MD4
538 struct md4_ctx md4Context;
539 #endif
540 #if GNULIB_GC_MD5
541 struct md5_ctx md5Context;
542 #endif
543 #if GNULIB_GC_SHA1
544 struct sha1_ctx sha1Context;
545 #endif
546 #if GNULIB_GC_SHA256
547 struct sha256_ctx sha256Context;
548 #endif
549 #if GNULIB_GC_SHA512
550 struct sha512_ctx sha512Context;
551 #endif
552 #if GNULIB_GC_SM3
553 struct sm3_ctx sm3Context;
554 #endif
555 } _gc_hash_ctx;
557 Gc_rc
558 gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
560 _gc_hash_ctx *ctx;
561 Gc_rc rc = GC_OK;
563 if (mode != 0)
564 return GC_INVALID_HASH;
566 ctx = calloc (sizeof (*ctx), 1);
567 if (!ctx)
568 return GC_MALLOC_ERROR;
570 ctx->alg = hash;
571 ctx->mode = mode;
573 switch (hash)
575 #if GNULIB_GC_MD2
576 case GC_MD2:
577 /* Not needed, because ctx is already zero-initialized. */
578 /*md2_init_ctx (&ctx->md2Context);*/
579 break;
580 #endif
582 #if GNULIB_GC_MD4
583 case GC_MD4:
584 md4_init_ctx (&ctx->md4Context);
585 break;
586 #endif
588 #if GNULIB_GC_MD5
589 case GC_MD5:
590 md5_init_ctx (&ctx->md5Context);
591 break;
592 #endif
594 #if GNULIB_GC_SHA1
595 case GC_SHA1:
596 sha1_init_ctx (&ctx->sha1Context);
597 break;
598 #endif
600 #if GNULIB_GC_SHA256
601 case GC_SHA256:
602 sha256_init_ctx (&ctx->sha256Context);
603 break;
604 #endif
606 #if GNULIB_GC_SHA512
607 case GC_SHA512:
608 sha512_init_ctx (&ctx->sha512Context);
609 break;
610 #endif
612 #if GNULIB_GC_SM3
613 case GC_SM3:
614 sm3_init_ctx (&ctx->sm3Context);
615 break;
616 #endif
618 default:
619 rc = GC_INVALID_HASH;
620 break;
623 if (rc == GC_OK)
624 *outhandle = ctx;
625 else
626 free (ctx);
628 return rc;
631 Gc_rc
632 gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
634 _gc_hash_ctx *in = handle;
635 _gc_hash_ctx *out;
637 *outhandle = out = calloc (sizeof (*out), 1);
638 if (!out)
639 return GC_MALLOC_ERROR;
641 memcpy (out, in, sizeof (*out));
643 return GC_OK;
646 size_t
647 gc_hash_digest_length (Gc_hash hash)
649 size_t len;
651 switch (hash)
653 case GC_MD2:
654 len = GC_MD2_DIGEST_SIZE;
655 break;
657 case GC_MD4:
658 len = GC_MD4_DIGEST_SIZE;
659 break;
661 case GC_MD5:
662 len = GC_MD5_DIGEST_SIZE;
663 break;
665 case GC_RMD160:
666 len = GC_RMD160_DIGEST_SIZE;
667 break;
669 case GC_SHA1:
670 len = GC_SHA1_DIGEST_SIZE;
671 break;
673 case GC_SHA256:
674 len = GC_SHA256_DIGEST_SIZE;
675 break;
677 case GC_SHA512:
678 len = GC_SHA512_DIGEST_SIZE;
679 break;
681 case GC_SM3:
682 len = GC_SM3_DIGEST_SIZE;
683 break;
685 default:
686 return 0;
689 return len;
692 void
693 gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
695 _gc_hash_ctx *ctx = handle;
697 switch (ctx->alg)
699 #if GNULIB_GC_MD2
700 case GC_MD2:
701 md2_process_bytes (data, len, &ctx->md2Context);
702 break;
703 #endif
705 #if GNULIB_GC_MD4
706 case GC_MD4:
707 md4_process_bytes (data, len, &ctx->md4Context);
708 break;
709 #endif
711 #if GNULIB_GC_MD5
712 case GC_MD5:
713 md5_process_bytes (data, len, &ctx->md5Context);
714 break;
715 #endif
717 #if GNULIB_GC_SHA1
718 case GC_SHA1:
719 sha1_process_bytes (data, len, &ctx->sha1Context);
720 break;
721 #endif
723 #if GNULIB_GC_SHA256
724 case GC_SHA256:
725 sha256_process_bytes (data, len, &ctx->sha256Context);
726 break;
727 #endif
729 #if GNULIB_GC_SHA512
730 case GC_SHA512:
731 sha512_process_bytes (data, len, &ctx->sha512Context);
732 break;
733 #endif
735 #if GNULIB_GC_SM3
736 case GC_SM3:
737 sm3_process_bytes (data, len, &ctx->sm3Context);
738 break;
739 #endif
741 default:
742 break;
746 const char *
747 gc_hash_read (gc_hash_handle handle)
749 _gc_hash_ctx *ctx = handle;
750 const char *ret = NULL;
752 switch (ctx->alg)
754 #if GNULIB_GC_MD2
755 case GC_MD2:
756 md2_finish_ctx (&ctx->md2Context, ctx->hash);
757 ret = ctx->hash;
758 break;
759 #endif
761 #if GNULIB_GC_MD4
762 case GC_MD4:
763 md4_finish_ctx (&ctx->md4Context, ctx->hash);
764 ret = ctx->hash;
765 break;
766 #endif
768 #if GNULIB_GC_MD5
769 case GC_MD5:
770 md5_finish_ctx (&ctx->md5Context, ctx->hash);
771 ret = ctx->hash;
772 break;
773 #endif
775 #if GNULIB_GC_SHA1
776 case GC_SHA1:
777 sha1_finish_ctx (&ctx->sha1Context, ctx->hash);
778 ret = ctx->hash;
779 break;
780 #endif
782 #if GNULIB_GC_SHA256
783 case GC_SHA256:
784 sha256_finish_ctx (&ctx->sha256Context, ctx->hash);
785 ret = ctx->hash;
786 break;
787 #endif
789 #if GNULIB_GC_SHA512
790 case GC_SHA512:
791 sha512_finish_ctx (&ctx->sha512Context, ctx->hash);
792 ret = ctx->hash;
793 break;
794 #endif
796 #if GNULIB_GC_SM3
797 case GC_SM3:
798 sm3_finish_ctx (&ctx->sm3Context, ctx->hash);
799 ret = ctx->hash;
800 break;
801 #endif
803 default:
804 return NULL;
807 return ret;
810 void
811 gc_hash_close (gc_hash_handle handle)
813 _gc_hash_ctx *ctx = handle;
815 free (ctx);
818 Gc_rc
819 gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
821 switch (hash)
823 #if GNULIB_GC_MD2
824 case GC_MD2:
825 md2_buffer (in, inlen, resbuf);
826 break;
827 #endif
829 #if GNULIB_GC_MD4
830 case GC_MD4:
831 md4_buffer (in, inlen, resbuf);
832 break;
833 #endif
835 #if GNULIB_GC_MD5
836 case GC_MD5:
837 md5_buffer (in, inlen, resbuf);
838 break;
839 #endif
841 #if GNULIB_GC_SHA1
842 case GC_SHA1:
843 sha1_buffer (in, inlen, resbuf);
844 break;
845 #endif
847 #if GNULIB_GC_SHA256
848 case GC_SHA256:
849 sha256_buffer (in, inlen, resbuf);
850 break;
851 #endif
853 #if GNULIB_GC_SHA512
854 case GC_SHA512:
855 sha512_buffer (in, inlen, resbuf);
856 break;
857 #endif
859 #if GNULIB_GC_SM3
860 case GC_SM3:
861 sm3_buffer (in, inlen, resbuf);
862 break;
863 #endif
865 default:
866 return GC_INVALID_HASH;
869 return GC_OK;
872 #if GNULIB_GC_MD2
873 Gc_rc
874 gc_md2 (const void *in, size_t inlen, void *resbuf)
876 md2_buffer (in, inlen, resbuf);
877 return GC_OK;
879 #endif
881 #if GNULIB_GC_MD4
882 Gc_rc
883 gc_md4 (const void *in, size_t inlen, void *resbuf)
885 md4_buffer (in, inlen, resbuf);
886 return GC_OK;
888 #endif
890 #if GNULIB_GC_MD5
891 Gc_rc
892 gc_md5 (const void *in, size_t inlen, void *resbuf)
894 md5_buffer (in, inlen, resbuf);
895 return GC_OK;
897 #endif
899 #if GNULIB_GC_SHA1
900 Gc_rc
901 gc_sha1 (const void *in, size_t inlen, void *resbuf)
903 sha1_buffer (in, inlen, resbuf);
904 return GC_OK;
906 #endif
908 #if GNULIB_GC_SHA256
909 Gc_rc
910 gc_sha256 (const void *in, size_t inlen, void *resbuf)
912 sha256_buffer (in, inlen, resbuf);
913 return GC_OK;
915 #endif
917 #if GNULIB_GC_SHA512
918 Gc_rc
919 gc_sha512 (const void *in, size_t inlen, void *resbuf)
921 sha512_buffer (in, inlen, resbuf);
922 return GC_OK;
924 #endif
926 #if GNULIB_GC_SM3
927 Gc_rc
928 gc_sm3 (const void *in, size_t inlen, void *resbuf)
930 sm3_buffer (in, inlen, resbuf);
931 return GC_OK;
933 #endif
935 #if GNULIB_GC_HMAC_MD5
936 Gc_rc
937 gc_hmac_md5 (const void *key, size_t keylen,
938 const void *in, size_t inlen, char *resbuf)
940 hmac_md5 (key, keylen, in, inlen, resbuf);
941 return GC_OK;
943 #endif
945 #if GNULIB_GC_HMAC_SHA1
946 Gc_rc
947 gc_hmac_sha1 (const void *key, size_t keylen,
948 const void *in, size_t inlen, char *resbuf)
950 hmac_sha1 (key, keylen, in, inlen, resbuf);
951 return GC_OK;
953 #endif
955 #if GNULIB_GC_HMAC_SHA256
956 Gc_rc
957 gc_hmac_sha256 (const void *key, size_t keylen,
958 const void *in, size_t inlen, char *resbuf)
960 hmac_sha256 (key, keylen, in, inlen, resbuf);
961 return GC_OK;
963 #endif
965 #if GNULIB_GC_HMAC_SHA512
966 Gc_rc
967 gc_hmac_sha512 (const void *key, size_t keylen,
968 const void *in, size_t inlen, char *resbuf)
970 hmac_sha512 (key, keylen, in, inlen, resbuf);
971 return GC_OK;
973 #endif