1 /* gcrypt.h - GNU digital encryption library interface
2 * Copyright (C) 1998,1999,2000,2001,2002 Free Software Foundation, Inc.
4 * This file is part of Libgcrypt.
6 * Libgcrypt is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * Libgcrypt is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
31 * The version of this header should match the one of the library
32 * It should not be used by a program because gcry_check_version()
33 * should reurn the same version. The purpose of this macro is to
34 * let autoconf (using the AM_PATH_GCRYPT macro) check that this
35 * header matches the installed library.
36 * Note: Do not edit the next line as configure may fix the string here.
38 #define GCRYPT_VERSION "1.1.7-cvs"
41 #ifndef HAVE_BYTE_TYPEDEF
42 # undef byte /* maybe there is a macro with this name */
43 typedef unsigned char byte;
44 # define HAVE_BYTE_TYPEDEF
47 #ifdef _GCRYPT_IN_LIBGCRYPT
48 # ifndef GCRYPT_NO_MPI_MACROS
49 # define GCRYPT_NO_MPI_MACROS 1
54 typedef struct gcry_mpi *GCRY_MPI;
56 /*******************************************
58 * error handling etc. *
60 *******************************************/
62 /* FIXME: We should use the same values as they were used in GnuPG 1.0.
63 * gpg --status-fd may print some of these values */
65 GCRYERR_SUCCESS = 0, /* "no error" */
66 GCRYERR_GENERAL = 1, /* catch all the other errors code */
68 GCRYERR_INV_PK_ALGO = 4, /* invalid public key algorithm */
69 GCRYERR_INV_MD_ALGO = 5, /* invalid message digest algorithm */
70 GCRYERR_BAD_PUBLIC_KEY = 6, /* Bad public key */
71 GCRYERR_BAD_SECRET_KEY = 7, /* Bad secret key */
72 GCRYERR_BAD_SIGNATURE = 8, /* Bad signature */
74 GCRYERR_INV_CIPHER_ALGO = 12, /* invalid cipher algorithm */
76 GCRYERR_WRONG_PK_ALGO = 41, /* wrong public key algorithm */
77 GCRYERR_WEAK_KEY = 43, /* weak encryption key */
78 GCRYERR_INV_KEYLEN = 44, /* invalid length of a key*/
79 GCRYERR_INV_ARG = 45, /* invalid argument */
80 GCRYERR_SELFTEST = 50, /* selftest failed */
82 /* error codes not used in GnuPG 1.0 */
83 GCRYERR_INV_OP = 61, /* invalid operation code or ctl command */
84 GCRYERR_NO_MEM = 62, /* out of core */
85 GCRYERR_INTERNAL = 63, /* internal error */
86 GCRYERR_EOF = 64, /* (-1) is remapped to this value */
87 GCRYERR_INV_OBJ = 65, /* an object is not valid */
88 GCRYERR_TOO_SHORT = 66, /* provided buffer too short */
89 GCRYERR_TOO_LARGE = 67, /* object is too large */
90 GCRYERR_NO_OBJ = 68, /* Missing item in an object */
91 GCRYERR_NOT_IMPL = 69, /* Not implemented */
92 GCRYERR_CONFLICT = 70,
93 GCRYERR_INV_CIPHER_MODE = 71
96 const char *gcry_check_version( const char *req_version );
99 const char *gcry_strerror( int ec );
104 GCRYCTL_CFB_SYNC = 3,
105 GCRYCTL_RESET = 4, /* e.g. for MDs */
106 GCRYCTL_FINALIZE = 5,
107 GCRYCTL_GET_KEYLEN = 6,
108 GCRYCTL_GET_BLKLEN = 7,
109 GCRYCTL_TEST_ALGO = 8,
110 GCRYCTL_IS_SECURE = 9,
111 GCRYCTL_GET_ASNOID = 10,
112 GCRYCTL_ENABLE_ALGO = 11,
113 GCRYCTL_DISABLE_ALGO = 12,
114 GCRYCTL_DUMP_RANDOM_STATS = 13,
115 GCRYCTL_DUMP_SECMEM_STATS = 14,
116 GCRYCTL_GET_ALGO_NPKEY = 15,
117 GCRYCTL_GET_ALGO_NSKEY = 16,
118 GCRYCTL_GET_ALGO_NSIGN = 17,
119 GCRYCTL_GET_ALGO_NENCR = 18,
120 GCRYCTL_SET_VERBOSITY = 19,
121 GCRYCTL_SET_DEBUG_FLAGS = 20,
122 GCRYCTL_CLEAR_DEBUG_FLAGS = 21,
123 GCRYCTL_USE_SECURE_RNDPOOL= 22,
124 GCRYCTL_DUMP_MEMORY_STATS = 23,
125 GCRYCTL_INIT_SECMEM = 24,
126 GCRYCTL_TERM_SECMEM = 25,
127 GCRYCTL_DISABLE_SECMEM_WARN = 27,
128 GCRYCTL_SUSPEND_SECMEM_WARN = 28,
129 GCRYCTL_RESUME_SECMEM_WARN = 29,
130 GCRYCTL_DROP_PRIVS = 30,
131 GCRYCTL_ENABLE_M_GUARD = 31,
132 GCRYCTL_START_DUMP = 32,
133 GCRYCTL_STOP_DUMP = 33,
134 GCRYCTL_GET_ALGO_USAGE = 34,
135 GCRYCTL_IS_ALGO_ENABLED = 35,
136 GCRYCTL_DISABLE_INTERNAL_LOCKING = 36,
137 GCRYCTL_DISABLE_SECMEM = 37,
138 GCRYCTL_INITIALIZATION_FINISHED = 38,
139 GCRYCTL_INITIALIZATION_FINISHED_P = 39,
140 GCRYCTL_ANY_INITIALIZATION_P = 40
143 int gcry_control( enum gcry_ctl_cmds, ... );
145 enum gcry_random_level {
146 GCRY_WEAK_RANDOM = 0,
147 GCRY_STRONG_RANDOM = 1,
148 GCRY_VERY_STRONG_RANDOM = 2
153 typedef struct gcry_sexp *GCRY_SEXP;
155 enum gcry_sexp_format {
156 GCRYSEXP_FMT_DEFAULT = 0,
157 GCRYSEXP_FMT_CANON = 1,
158 GCRYSEXP_FMT_BASE64 = 2,
159 GCRYSEXP_FMT_ADVANCED = 3
162 void gcry_sexp_release( GCRY_SEXP sexp );
163 void gcry_sexp_dump( const GCRY_SEXP a );
164 GCRY_SEXP gcry_sexp_cons( const GCRY_SEXP a, const GCRY_SEXP b );
165 GCRY_SEXP gcry_sexp_alist( const GCRY_SEXP *array );
166 GCRY_SEXP gcry_sexp_vlist( const GCRY_SEXP a, ... );
167 GCRY_SEXP gcry_sexp_append( const GCRY_SEXP a, const GCRY_SEXP n );
168 GCRY_SEXP gcry_sexp_prepend( const GCRY_SEXP a, const GCRY_SEXP n );
169 int gcry_sexp_sscan( GCRY_SEXP *retsexp, size_t *erroff,
170 const char *buffer, size_t length );
171 int gcry_sexp_build( GCRY_SEXP *retsexp, size_t *erroff,
172 const char *format, ... );
173 size_t gcry_sexp_sprint( GCRY_SEXP sexp, int mode, char *buffer,
175 GCRY_SEXP gcry_sexp_find_token( GCRY_SEXP list,
176 const char *tok, size_t toklen );
177 int gcry_sexp_length( const GCRY_SEXP list );
178 GCRY_SEXP gcry_sexp_nth( const GCRY_SEXP list, int number );
179 GCRY_SEXP gcry_sexp_car( const GCRY_SEXP list );
180 GCRY_SEXP gcry_sexp_cdr( const GCRY_SEXP list );
181 GCRY_SEXP gcry_sexp_cadr( const GCRY_SEXP list );
182 const char *gcry_sexp_nth_data( const GCRY_SEXP list, int number,
184 GCRY_MPI gcry_sexp_nth_mpi( GCRY_SEXP list, int number, int mpifmt );
186 size_t gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
187 size_t *erroff, int *errcode);
190 /*******************************************
192 * multi precision integer functions *
194 *******************************************/
196 enum gcry_mpi_format {
198 GCRYMPI_FMT_STD = 1, /* twos complement stored without length */
199 GCRYMPI_FMT_PGP = 2, /* As used by OpenPGP (only defined as unsigned)*/
200 GCRYMPI_FMT_SSH = 3, /* As used by SSH (same as 1 but with length)*/
201 GCRYMPI_FMT_HEX = 4, /* hex format */
202 GCRYMPI_FMT_USG = 5 /* like STD but this is an unsigned one */
207 GCRYMPI_FLAG_SECURE = 1,
208 GCRYMPI_FLAG_OPAQUE = 2
213 GCRY_MPI gcry_mpi_new( unsigned int nbits );
214 GCRY_MPI gcry_mpi_snew( unsigned int nbits );
215 void gcry_mpi_release( GCRY_MPI a );
216 GCRY_MPI gcry_mpi_copy( const GCRY_MPI a );
217 GCRY_MPI gcry_mpi_set( GCRY_MPI w, const GCRY_MPI u );
218 GCRY_MPI gcry_mpi_set_ui( GCRY_MPI w, unsigned long u );
219 int gcry_mpi_cmp( const GCRY_MPI u, const GCRY_MPI v );
220 int gcry_mpi_cmp_ui( const GCRY_MPI u, unsigned long v );
221 void gcry_mpi_randomize( GCRY_MPI w,
222 unsigned int nbits, enum gcry_random_level level);
223 int gcry_mpi_scan( GCRY_MPI *ret_mpi, enum gcry_mpi_format format,
224 const char *buffer, size_t *nbytes );
225 int gcry_mpi_print( enum gcry_mpi_format format,
226 char *buffer, size_t *nbytes, const GCRY_MPI a );
227 int gcry_mpi_aprint( enum gcry_mpi_format format,
228 void **buffer, size_t *nbytes, const GCRY_MPI a );
231 void gcry_mpi_add(GCRY_MPI w, GCRY_MPI u, GCRY_MPI v);
232 void gcry_mpi_add_ui(GCRY_MPI w, GCRY_MPI u, unsigned long v );
233 void gcry_mpi_addm(GCRY_MPI w, GCRY_MPI u, GCRY_MPI v, GCRY_MPI m);
234 void gcry_mpi_sub( GCRY_MPI w, GCRY_MPI u, GCRY_MPI v);
235 void gcry_mpi_sub_ui(GCRY_MPI w, GCRY_MPI u, unsigned long v );
236 void gcry_mpi_subm( GCRY_MPI w, GCRY_MPI u, GCRY_MPI v, GCRY_MPI m);
237 void gcry_mpi_mul_ui(GCRY_MPI w, GCRY_MPI u, unsigned long v );
238 void gcry_mpi_mul_2exp( GCRY_MPI w, GCRY_MPI u, unsigned long cnt);
239 void gcry_mpi_mul( GCRY_MPI w, GCRY_MPI u, GCRY_MPI v);
240 void gcry_mpi_mulm( GCRY_MPI w, GCRY_MPI u, GCRY_MPI v, GCRY_MPI m);
242 void gcry_mpi_powm( GCRY_MPI w,
243 const GCRY_MPI b, const GCRY_MPI e, const GCRY_MPI m );
244 int gcry_mpi_gcd( GCRY_MPI g, GCRY_MPI a, GCRY_MPI b );
246 unsigned int gcry_mpi_get_nbits( GCRY_MPI a );
248 /* Please note that keygrip is still experimental and should not be
249 used without contacting the author */
250 unsigned char *gcry_pk_get_keygrip (GCRY_SEXP key, unsigned char *array);
252 int gcry_mpi_test_bit( GCRY_MPI a, unsigned int n );
253 void gcry_mpi_set_bit( GCRY_MPI a, unsigned int n );
254 void gcry_mpi_clear_bit( GCRY_MPI a, unsigned int n );
255 void gcry_mpi_set_highbit( GCRY_MPI a, unsigned int n );
256 void gcry_mpi_clear_highbit( GCRY_MPI a, unsigned int n );
257 void gcry_mpi_rshift( GCRY_MPI x, GCRY_MPI a, unsigned int n );
259 GCRY_MPI gcry_mpi_set_opaque( GCRY_MPI a, void *p, unsigned int nbits );
260 void * gcry_mpi_get_opaque( GCRY_MPI a, unsigned int *nbits );
261 void gcry_mpi_set_flag( GCRY_MPI a, enum gcry_mpi_flag flag );
262 void gcry_mpi_clear_flag( GCRY_MPI a, enum gcry_mpi_flag flag );
263 int gcry_mpi_get_flag( GCRY_MPI a, enum gcry_mpi_flag flag );
266 #ifndef GCRYPT_NO_MPI_MACROS
267 #define mpi_new(n) gcry_mpi_new( (n) )
268 #define mpi_secure_new( n ) gcry_mpi_snew( (n) )
269 #define mpi_release( a ) do { gcry_mpi_release( (a) ); \
270 (a) = NULL; } while(0)
271 #define mpi_copy( a ) gcry_mpi_copy( (a) )
272 #define mpi_set( w, u) gcry_mpi_set( (w), (u) )
273 #define mpi_set_ui( w, u) gcry_mpi_set_ui( (w), (u) )
274 #define mpi_cmp( u, v ) gcry_mpi_cmp( (u), (v) )
275 #define mpi_cmp_ui( u, v ) gcry_mpi_cmp_ui( (u), (v) )
277 #define mpi_add_ui(w,u,v) gcry_mpi_add_ui((w),(u),(v))
278 #define mpi_add(w,u,v) gcry_mpi_add ((w),(u),(v))
279 #define mpi_addm(w,u,v,m) gcry_mpi_addm ((w),(u),(v),(m))
280 #define mpi_sub_ui(w,u,v) gcry_mpi_sub_ui ((w),(u),(v))
281 #define mpi_sub(w,u,v) gcry_mpi_sub ((w),(u),(v))
282 #define mpi_subm(w,u,v,m) gcry_mpi_subm ((w),(u),(v),(m))
283 #define mpi_mul_ui(w,u,v) gcry_mpi_mul_ui ((w),(u),(v))
284 #define mpi_mul_2exp(w,u,v) gcry_mpi_mul_2exp ((w),(u),(v))
285 #define mpi_mul(w,u,v) gcry_mpi_mul ((w),(u),(v))
286 #define mpi_mulm(w,u,v,m) gcry_mpi_mulm ((w),(u),(v),(m))
287 #define mpi_powm(w,b,e,m) gcry_mpi_powm( (w), (b), (e), (m) )
288 #define mpi_gcd(g,a,b) gcry_mpi_gcd( (g), (a), (b) )
290 #define mpi_get_nbits(a) gcry_mpi_get_nbits ((a))
291 #define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b))
292 #define mpi_set_bit(a,b) gcry_mpi_set_bit ((a),(b))
293 #define mpi_set_highbit(a,b) gcry_mpi_set_highbit ((a),(b))
294 #define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b))
295 #define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b))
296 #define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c))
298 #define mpi_set_opaque(a,b,c) gcry_mpi_set_opaque( (a), (b), (c) )
299 #define mpi_get_opaque(a,b) gcry_mpi_get_opaque( (a), (b) )
300 #endif /* GCRYPT_NO_MPI_MACROS */
302 /********************************************
303 ******* symmetric cipher functions *******
304 ********************************************/
306 struct gcry_cipher_handle;
307 typedef struct gcry_cipher_handle *GCRY_CIPHER_HD;
309 enum gcry_cipher_algos {
310 GCRY_CIPHER_NONE = 0,
311 GCRY_CIPHER_IDEA = 1,
312 GCRY_CIPHER_3DES = 2,
313 GCRY_CIPHER_CAST5 = 3,
314 GCRY_CIPHER_BLOWFISH = 4,
315 GCRY_CIPHER_SAFER_SK128 = 5,
316 GCRY_CIPHER_DES_SK = 6,
318 GCRY_CIPHER_AES192 = 8,
319 GCRY_CIPHER_AES256 = 9,
320 GCRY_CIPHER_TWOFISH = 10,
321 /* other cipher numbers are above 300 for OpenPGP reasons. */
322 GCRY_CIPHER_ARCFOUR = 301
325 #define GCRY_CIPHER_AES128 GCRY_CIPHER_AES
326 #define GCRY_CIPHER_RIJNDAEL GCRY_CIPHER_AES
327 #define GCRY_CIPHER_RIJNDAEL128 GCRY_CIPHER_AES128
328 #define GCRY_CIPHER_RIJNDAEL192 GCRY_CIPHER_AES192
329 #define GCRY_CIPHER_RIJNDAEL256 GCRY_CIPHER_AES256
331 enum gcry_cipher_modes {
332 GCRY_CIPHER_MODE_NONE = 0,
333 GCRY_CIPHER_MODE_ECB = 1,
334 GCRY_CIPHER_MODE_CFB = 2,
335 GCRY_CIPHER_MODE_CBC = 3,
336 GCRY_CIPHER_MODE_STREAM = 4, /* native stream mode of some the algorithms */
337 GCRY_CIPHER_MODE_OFB = 5
340 enum gcry_cipher_flags {
341 GCRY_CIPHER_SECURE = 1, /* allocate in secure memory */
342 GCRY_CIPHER_ENABLE_SYNC = 2 /* enable CFB sync mode */
346 GCRY_CIPHER_HD gcry_cipher_open( int algo, int mode, unsigned int flags);
347 void gcry_cipher_close( GCRY_CIPHER_HD h );
348 int gcry_cipher_ctl( GCRY_CIPHER_HD h, int cmd, void *buffer, size_t buflen);
349 int gcry_cipher_info( GCRY_CIPHER_HD h, int what, void *buffer, size_t *nbytes);
350 int gcry_cipher_algo_info( int algo, int what, void *buffer, size_t *nbytes);
351 const char *gcry_cipher_algo_name( int algo );
352 int gcry_cipher_map_name( const char* name );
353 int gcry_cipher_mode_from_oid (const char *string);
355 int gcry_cipher_encrypt( GCRY_CIPHER_HD h, byte *out, size_t outsize,
356 const byte *in, size_t inlen );
357 int gcry_cipher_decrypt( GCRY_CIPHER_HD h, byte *out, size_t outsize,
358 const byte *in, size_t inlen );
361 /* some handy macros */
362 /* We have to cast a way a const char* here - this catch-all ctl function
363 * was probably not the best choice */
364 #define gcry_cipher_setkey(h,k,l) gcry_cipher_ctl( (h), GCRYCTL_SET_KEY, \
366 #define gcry_cipher_setiv(h,k,l) gcry_cipher_ctl( (h), GCRYCTL_SET_IV, \
368 #define gcry_cipher_sync(h) gcry_cipher_ctl( (h), GCRYCTL_CFB_SYNC, \
371 #define gcry_cipher_get_algo_keylen(a) \
372 gcry_cipher_algo_info( (a), GCRYCTL_GET_KEYLEN, NULL, NULL )
373 #define gcry_cipher_get_algo_blklen(a) \
374 gcry_cipher_algo_info( (a), GCRYCTL_GET_BLKLEN, NULL, NULL )
375 #define gcry_cipher_test_algo(a) \
376 gcry_cipher_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
379 /*********************************************
380 ******* asymmetric cipher functions *******
381 *********************************************/
385 GCRY_PK_RSA_E = 2, /* use only for OpenPGP */
386 GCRY_PK_RSA_S = 3, /* use only for OpenPGP */
387 GCRY_PK_ELG_E = 16, /* use only for OpenPGP */
392 /* Flags describing usage capabilites/request of a PK algorithm */
393 #define GCRY_PK_USAGE_SIGN 1
394 #define GCRY_PK_USAGE_ENCR 2
396 int gcry_pk_encrypt( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP pkey );
397 int gcry_pk_decrypt( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP skey );
398 int gcry_pk_sign( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP skey );
399 int gcry_pk_verify( GCRY_SEXP sigval, GCRY_SEXP data, GCRY_SEXP pkey );
400 int gcry_pk_testkey( GCRY_SEXP key );
401 int gcry_pk_genkey( GCRY_SEXP *r_key, GCRY_SEXP s_parms );
403 int gcry_pk_ctl( int cmd, void *buffer, size_t buflen);
404 int gcry_pk_algo_info( int algo, int what, void *buffer, size_t *nbytes);
405 const char *gcry_pk_algo_name( int algo );
406 int gcry_pk_map_name( const char* name );
407 unsigned int gcry_pk_get_nbits( GCRY_SEXP key );
410 #define gcry_pk_test_algo(a) \
411 gcry_pk_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
413 /*********************************************
414 ******* cryptograhic hash functions *******
415 *********************************************/
426 GCRY_MD_FLAG_SECURE = 1,
427 GCRY_MD_FLAG_HMAC = 2
431 struct gcry_md_context;
432 struct gcry_md_handle {
433 struct gcry_md_context *ctx;
438 typedef struct gcry_md_handle *GCRY_MD_HD;
441 GCRY_MD_HD gcry_md_open( int algo, unsigned flags );
442 void gcry_md_close( GCRY_MD_HD hd );
443 int gcry_md_enable( GCRY_MD_HD hd, int algo );
444 GCRY_MD_HD gcry_md_copy( GCRY_MD_HD hd );
445 void gcry_md_reset( GCRY_MD_HD hd );
446 int gcry_md_ctl( GCRY_MD_HD hd, int cmd, byte *buffer, size_t buflen);
447 void gcry_md_write( GCRY_MD_HD hd, const byte *buffer, size_t length);
448 byte *gcry_md_read( GCRY_MD_HD hd, int algo );
449 void gcry_md_hash_buffer( int algo, char *digest,
450 const char *buffer, size_t length);
451 int gcry_md_get_algo( GCRY_MD_HD hd );
452 unsigned int gcry_md_get_algo_dlen( int algo );
453 /*??int gcry_md_get( GCRY_MD_HD hd, int algo, byte *buffer, int buflen );*/
454 int gcry_md_info( GCRY_MD_HD h, int what, void *buffer, size_t *nbytes);
455 int gcry_md_algo_info( int algo, int what, void *buffer, size_t *nbytes);
456 const char *gcry_md_algo_name( int algo );
457 int gcry_md_map_name( const char* name );
458 int gcry_md_setkey( GCRY_MD_HD hd, const char *key, size_t keylen );
460 #define gcry_md_putc(h,c) \
462 if( (h)->bufpos == (h)->bufsize ) \
463 gcry_md_write( (h), NULL, 0 ); \
464 (h)->buf[(h)->bufpos++] = (c) & 0xff; \
467 #define gcry_md_final(a) \
468 gcry_md_ctl( (a), GCRYCTL_FINALIZE, NULL, 0 )
470 #define gcry_md_is_secure(a) \
471 gcry_md_info( (a), GCRYCTL_IS_SECURE, NULL, NULL )
473 #define gcry_md_test_algo(a) \
474 gcry_md_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
476 #define gcry_md_start_debug(a,b) \
477 gcry_md_ctl( (a), GCRYCTL_START_DUMP, (b), 0 )
478 #define gcry_md_stop_debug(a,b) \
479 gcry_md_ctl( (a), GCRYCTL_STOP_DUMP, (b), 0 )
482 /*********************************************
483 ******* random generating functions *******
484 *********************************************/
485 void gcry_randomize( byte *buffer, size_t length,
486 enum gcry_random_level level );
487 void *gcry_random_bytes( size_t nbytes, enum gcry_random_level level );
488 void *gcry_random_bytes_secure( size_t nbytes, enum gcry_random_level level );
490 /*****************************************
491 ******* miscellaneous stuff **********
492 *****************************************/
494 enum gcry_log_levels {
495 GCRY_LOG_CONT = 0, /* continue the last log line */
505 /* Provide custom functions for special tasks of libgcrypt.
507 void gcry_set_allocation_handler( void *(*new_alloc_func)(size_t n),
508 void *(*new_alloc_secure_func)(size_t n),
509 int (*new_is_secure_func)(const void*),
510 void *(*new_realloc_func)(void *p, size_t n),
511 void (*new_free_func)(void*) );
512 void gcry_set_outofcore_handler( int (*h)( void*, size_t, unsigned int ),
514 void gcry_set_fatalerror_handler( void (*fnc)(void*,int, const char*),
516 void gcry_set_gettext_handler( const char *(*f)(const char*) );
517 void gcry_set_log_handler( void (*f)(void*,int, const char*, va_list ),
521 /* Access to the memory function of libgcrypt.
522 * Especially the gcry_free() should be used for memory
523 * allocated by gcry_ functions.
525 void *gcry_malloc( size_t n );
526 void *gcry_calloc( size_t n, size_t m );
527 void *gcry_malloc_secure( size_t n );
528 void *gcry_calloc_secure( size_t n, size_t m );
529 void *gcry_realloc( void *a, size_t n );
530 char *gcry_strdup( const char *string );
531 void *gcry_xmalloc( size_t n );
532 void *gcry_xcalloc( size_t n, size_t m );
533 void *gcry_xmalloc_secure( size_t n );
534 void *gcry_xcalloc_secure( size_t n, size_t m );
535 void *gcry_xrealloc( void *a, size_t n );
536 char *gcry_xstrdup( const char * a);
537 void gcry_free( void *a );
538 int gcry_is_secure( const void *a );
541 #ifndef GCRYPT_NO_MPI_MACROS
542 # ifndef DID_MPI_TYPEDEF
543 typedef struct gcry_mpi *MPI;
544 # define DID_MPI_TYPEDEF
546 #endif /* GCRYPT_NO_MPI_MACROS */
551 #endif /* _GCRYPT_H */