1 /* gc-gl-common.c --- Common gnulib internal crypto interface functions
2 * Copyright (C) 2002, 2003, 2004, 2005 Simon Josefsson
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.
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.
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
21 /* Note: This file is only built if GC uses internal functions. */
34 #include <sys/types.h>
56 randomize (int level, char *data, size_t datalen)
66 device = NAME_OF_NONCE_DEVICE;
70 device = NAME_OF_PSEUDO_RANDOM_DEVICE;
74 device = NAME_OF_RANDOM_DEVICE;
78 fd = open (device, O_RDONLY);
80 return GC_RANDOM_ERROR;
86 tmp = read (fd, data, datalen);
90 int save_errno = errno;
93 return GC_RANDOM_ERROR;
98 while (len < datalen);
102 return GC_RANDOM_ERROR;
108 gc_nonce (char *data, size_t datalen)
110 return randomize (0, data, datalen);
114 gc_pseudo_random (char *data, size_t datalen)
116 return randomize (1, data, datalen);
120 gc_random (char *data, size_t datalen)
122 return randomize (2, data, datalen);
125 /* Memory allocation. */
128 gc_set_allocators (gc_malloc_t func_malloc,
129 gc_malloc_t secure_malloc,
130 gc_secure_check_t secure_check,
131 gc_realloc_t func_realloc, gc_free_t func_free)
139 gc_md5 (const void *in, size_t inlen, void *resbuf)
141 md5_buffer (in, inlen, resbuf);
148 gc_hmac_md5 (const void *key, size_t keylen,
149 const void *in, size_t inlen, char *resbuf)
151 hmac_md5 (key, keylen, in, inlen, resbuf);