1 /* gcrypt.h - GNU Cryptographic Library Interface -*- c -*-
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
3 2007, 2008, 2009, 2010, 2011,
4 2012 Free Software Foundation, Inc.
5 Copyright (C) 2012, 2013 g10 Code GmbH
7 This file is part of Libgcrypt.
9 Libgcrypt is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of
12 the License, or (at your option) any later version.
14 Libgcrypt is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this program; if not, see <http://www.gnu.org/licenses/>.
22 File: @configure_input@ */
29 #include <grub/gcrypt/gpg-error.h>
31 #include <sys/types.h>
33 #if defined _WIN32 || defined __WIN32__
40 /* This is required for error code compatibility. */
41 #define _GCRY_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_GCRYPT
45 #if 0 /* (Keep Emacsens' auto-indent happy.) */
50 /* The version of this header should match the one of the library. It
51 should not be used by a program because gcry_check_version() should
52 return the same version. The purpose of this macro is to let
53 autoconf (using the AM_PATH_GCRYPT macro) check that this header
54 matches the installed library. */
55 #define GCRYPT_VERSION "@VERSION@"
57 /* The version number of this header. It may be used to handle minor
58 API incompatibilities. */
59 #define GCRYPT_VERSION_NUMBER @VERSION_NUMBER@
62 /* Internal: We can't use the convenience macros for the multi
63 precision integer functions when building this library. */
64 #ifdef _GCRYPT_IN_LIBGCRYPT
65 #ifndef GCRYPT_NO_MPI_MACROS
66 #define GCRYPT_NO_MPI_MACROS 1
70 /* We want to use gcc attributes when possible. Warning: Don't use
71 these macros in your programs: As indicated by the leading
72 underscore they are subject to change without notice. */
75 #define _GCRY_GCC_VERSION (__GNUC__ * 10000 \
76 + __GNUC_MINOR__ * 100 \
77 + __GNUC_PATCHLEVEL__)
79 #if _GCRY_GCC_VERSION >= 30100
80 #define _GCRY_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__))
83 #if _GCRY_GCC_VERSION >= 29600
84 #define _GCRY_GCC_ATTR_PURE __attribute__ ((__pure__))
87 #if _GCRY_GCC_VERSION >= 30200
88 #define _GCRY_GCC_ATTR_MALLOC __attribute__ ((__malloc__))
93 #ifndef _GCRY_GCC_ATTR_DEPRECATED
94 #define _GCRY_GCC_ATTR_DEPRECATED
96 #ifndef _GCRY_GCC_ATTR_PURE
97 #define _GCRY_GCC_ATTR_PURE
99 #ifndef _GCRY_GCC_ATTR_MALLOC
100 #define _GCRY_GCC_ATTR_MALLOC
103 /* Make up an attribute to mark functions and types as deprecated but
104 allow internal use by Libgcrypt. */
105 #ifdef _GCRYPT_IN_LIBGCRYPT
106 #define _GCRY_ATTR_INTERNAL
108 #define _GCRY_ATTR_INTERNAL _GCRY_GCC_ATTR_DEPRECATED
111 /* Wrappers for the libgpg-error library. */
113 typedef gpg_err_source_t gcry_err_source_t
;
115 static GPG_ERR_INLINE gcry_error_t
116 gcry_err_make (gcry_err_source_t source
, gcry_err_code_t code
)
118 return gpg_err_make (source
, code
);
121 /* The user can define GPG_ERR_SOURCE_DEFAULT before including this
122 file to specify a default source for gpg_error. */
123 #ifndef GCRY_ERR_SOURCE_DEFAULT
124 #define GCRY_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1
127 static GPG_ERR_INLINE gcry_error_t
128 gcry_error (gcry_err_code_t code
)
130 return gcry_err_make (GCRY_ERR_SOURCE_DEFAULT
, code
);
133 static GPG_ERR_INLINE gcry_err_code_t
134 gcry_err_code (gcry_error_t err
)
136 return gpg_err_code (err
);
140 static GPG_ERR_INLINE gcry_err_source_t
141 gcry_err_source (gcry_error_t err
)
143 return gpg_err_source (err
);
146 /* Return a pointer to a string containing a description of the error
147 code in the error value ERR. */
148 const char *gcry_strerror (gcry_error_t err
);
150 /* Return a pointer to a string containing a description of the error
151 source in the error value ERR. */
152 const char *gcry_strsource (gcry_error_t err
);
154 /* Retrieve the error code for the system error ERR. This returns
155 GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
157 gcry_err_code_t
gcry_err_code_from_errno (int err
);
159 /* Retrieve the system error for the error code CODE. This returns 0
160 if CODE is not a system error code. */
161 int gcry_err_code_to_errno (gcry_err_code_t code
);
163 /* Return an error value with the error source SOURCE and the system
165 gcry_error_t
gcry_err_make_from_errno (gcry_err_source_t source
, int err
);
167 /* Return an error value with the system error ERR. */
168 gcry_err_code_t
gcry_error_from_errno (int err
);
171 /* The data object used to hold a multi precision integer. */
174 #ifndef GCRYPT_NO_DEPRECATED
175 typedef struct gcry_mpi
*GCRY_MPI _GCRY_GCC_ATTR_DEPRECATED
;
176 typedef struct gcry_mpi
*GcryMPI _GCRY_GCC_ATTR_DEPRECATED
;
181 /* Check that the library fulfills the version requirement. */
182 const char *gcry_check_version (const char *req_version
);
184 /* Codes for function dispatchers. */
186 /* Codes used with the gcry_control function. */
191 GCRYCTL_CFB_SYNC
= 3,
192 GCRYCTL_RESET
= 4, /* e.g. for MDs */
193 GCRYCTL_FINALIZE
= 5,
194 GCRYCTL_GET_KEYLEN
= 6,
195 GCRYCTL_GET_BLKLEN
= 7,
196 GCRYCTL_TEST_ALGO
= 8,
197 GCRYCTL_IS_SECURE
= 9,
198 GCRYCTL_GET_ASNOID
= 10,
199 GCRYCTL_ENABLE_ALGO
= 11,
200 GCRYCTL_DISABLE_ALGO
= 12,
201 GCRYCTL_DUMP_RANDOM_STATS
= 13,
202 GCRYCTL_DUMP_SECMEM_STATS
= 14,
203 GCRYCTL_GET_ALGO_NPKEY
= 15,
204 GCRYCTL_GET_ALGO_NSKEY
= 16,
205 GCRYCTL_GET_ALGO_NSIGN
= 17,
206 GCRYCTL_GET_ALGO_NENCR
= 18,
207 GCRYCTL_SET_VERBOSITY
= 19,
208 GCRYCTL_SET_DEBUG_FLAGS
= 20,
209 GCRYCTL_CLEAR_DEBUG_FLAGS
= 21,
210 GCRYCTL_USE_SECURE_RNDPOOL
= 22,
211 GCRYCTL_DUMP_MEMORY_STATS
= 23,
212 GCRYCTL_INIT_SECMEM
= 24,
213 GCRYCTL_TERM_SECMEM
= 25,
214 GCRYCTL_DISABLE_SECMEM_WARN
= 27,
215 GCRYCTL_SUSPEND_SECMEM_WARN
= 28,
216 GCRYCTL_RESUME_SECMEM_WARN
= 29,
217 GCRYCTL_DROP_PRIVS
= 30,
218 GCRYCTL_ENABLE_M_GUARD
= 31,
219 GCRYCTL_START_DUMP
= 32,
220 GCRYCTL_STOP_DUMP
= 33,
221 GCRYCTL_GET_ALGO_USAGE
= 34,
222 GCRYCTL_IS_ALGO_ENABLED
= 35,
223 GCRYCTL_DISABLE_INTERNAL_LOCKING
= 36,
224 GCRYCTL_DISABLE_SECMEM
= 37,
225 GCRYCTL_INITIALIZATION_FINISHED
= 38,
226 GCRYCTL_INITIALIZATION_FINISHED_P
= 39,
227 GCRYCTL_ANY_INITIALIZATION_P
= 40,
228 GCRYCTL_SET_CBC_CTS
= 41,
229 GCRYCTL_SET_CBC_MAC
= 42,
230 GCRYCTL_SET_CTR
= 43,
231 GCRYCTL_ENABLE_QUICK_RANDOM
= 44,
232 GCRYCTL_SET_RANDOM_SEED_FILE
= 45,
233 GCRYCTL_UPDATE_RANDOM_SEED_FILE
= 46,
234 GCRYCTL_SET_THREAD_CBS
= 47,
235 GCRYCTL_FAST_POLL
= 48,
236 GCRYCTL_SET_RANDOM_DAEMON_SOCKET
= 49,
237 GCRYCTL_USE_RANDOM_DAEMON
= 50,
238 GCRYCTL_FAKED_RANDOM_P
= 51,
239 GCRYCTL_SET_RNDEGD_SOCKET
= 52,
240 GCRYCTL_PRINT_CONFIG
= 53,
241 GCRYCTL_OPERATIONAL_P
= 54,
242 GCRYCTL_FIPS_MODE_P
= 55,
243 GCRYCTL_FORCE_FIPS_MODE
= 56,
244 GCRYCTL_SELFTEST
= 57,
245 /* Note: 58 .. 62 are used internally. */
246 GCRYCTL_DISABLE_HWF
= 63,
247 GCRYCTL_SET_ENFORCED_FIPS_FLAG
= 64
250 /* Perform various operations defined by CMD. */
251 gcry_error_t
gcry_control (enum gcry_ctl_cmds CMD
, ...);
254 /* S-expression management. */
256 /* The object to represent an S-expression as used with the public key
259 typedef struct gcry_sexp
*gcry_sexp_t
;
261 #ifndef GCRYPT_NO_DEPRECATED
262 typedef struct gcry_sexp
*GCRY_SEXP _GCRY_GCC_ATTR_DEPRECATED
;
263 typedef struct gcry_sexp
*GcrySexp _GCRY_GCC_ATTR_DEPRECATED
;
266 /* The possible values for the S-expression format. */
267 enum gcry_sexp_format
269 GCRYSEXP_FMT_DEFAULT
= 0,
270 GCRYSEXP_FMT_CANON
= 1,
271 GCRYSEXP_FMT_BASE64
= 2,
272 GCRYSEXP_FMT_ADVANCED
= 3
275 /* Create an new S-expression object from BUFFER of size LENGTH and
276 return it in RETSEXP. With AUTODETECT set to 0 the data in BUFFER
277 is expected to be in canonized format. */
278 gcry_error_t
gcry_sexp_new (gcry_sexp_t
*retsexp
,
279 const void *buffer
, size_t length
,
282 /* Same as gcry_sexp_new but allows to pass a FREEFNC which has the
283 effect to transfer ownership of BUFFER to the created object. */
284 gcry_error_t
gcry_sexp_create (gcry_sexp_t
*retsexp
,
285 void *buffer
, size_t length
,
286 int autodetect
, void (*freefnc
) (void *));
288 /* Scan BUFFER and return a new S-expression object in RETSEXP. This
289 function expects a printf like string in BUFFER. */
290 gcry_error_t
gcry_sexp_sscan (gcry_sexp_t
*retsexp
, size_t *erroff
,
291 const char *buffer
, size_t length
);
293 /* Same as gcry_sexp_sscan but expects a string in FORMAT and can thus
294 only be used for certain encodings. */
295 gcry_error_t
gcry_sexp_build (gcry_sexp_t
*retsexp
, size_t *erroff
,
296 const char *format
, ...);
298 /* Like gcry_sexp_build, but uses an array instead of variable
299 function arguments. */
300 gcry_error_t
gcry_sexp_build_array (gcry_sexp_t
*retsexp
, size_t *erroff
,
301 const char *format
, void **arg_list
);
303 /* Release the S-expression object SEXP */
304 void gcry_sexp_release (gcry_sexp_t sexp
);
306 /* Calculate the length of an canonized S-expresion in BUFFER and
307 check for a valid encoding. */
308 size_t gcry_sexp_canon_len (const unsigned char *buffer
, size_t length
,
309 size_t *erroff
, gcry_error_t
*errcode
);
311 /* Copies the S-expression object SEXP into BUFFER using the format
312 specified in MODE. */
313 size_t gcry_sexp_sprint (gcry_sexp_t sexp
, int mode
, void *buffer
,
316 /* Dumps the S-expression object A in a format suitable for debugging
317 to Libgcrypt's logging stream. */
318 void gcry_sexp_dump (const gcry_sexp_t a
);
320 gcry_sexp_t
gcry_sexp_cons (const gcry_sexp_t a
, const gcry_sexp_t b
);
321 gcry_sexp_t
gcry_sexp_alist (const gcry_sexp_t
*array
);
322 gcry_sexp_t
gcry_sexp_vlist (const gcry_sexp_t a
, ...);
323 gcry_sexp_t
gcry_sexp_append (const gcry_sexp_t a
, const gcry_sexp_t n
);
324 gcry_sexp_t
gcry_sexp_prepend (const gcry_sexp_t a
, const gcry_sexp_t n
);
326 /* Scan the S-expression for a sublist with a type (the car of the
327 list) matching the string TOKEN. If TOKLEN is not 0, the token is
328 assumed to be raw memory of this length. The function returns a
329 newly allocated S-expression consisting of the found sublist or
330 `NULL' when not found. */
331 gcry_sexp_t
gcry_sexp_find_token (gcry_sexp_t list
,
332 const char *tok
, size_t toklen
);
333 /* Return the length of the LIST. For a valid S-expression this
334 should be at least 1. */
335 int gcry_sexp_length (const gcry_sexp_t list
);
337 /* Create and return a new S-expression from the element with index
338 NUMBER in LIST. Note that the first element has the index 0. If
339 there is no such element, `NULL' is returned. */
340 gcry_sexp_t
gcry_sexp_nth (const gcry_sexp_t list
, int number
);
342 /* Create and return a new S-expression from the first element in
343 LIST; this called the "type" and should always exist and be a
344 string. `NULL' is returned in case of a problem. */
345 gcry_sexp_t
gcry_sexp_car (const gcry_sexp_t list
);
347 /* Create and return a new list form all elements except for the first
348 one. Note, that this function may return an invalid S-expression
349 because it is not guaranteed, that the type exists and is a string.
350 However, for parsing a complex S-expression it might be useful for
351 intermediate lists. Returns `NULL' on error. */
352 gcry_sexp_t
gcry_sexp_cdr (const gcry_sexp_t list
);
354 gcry_sexp_t
gcry_sexp_cadr (const gcry_sexp_t list
);
357 /* This function is used to get data from a LIST. A pointer to the
358 actual data with index NUMBER is returned and the length of this
359 data will be stored to DATALEN. If there is no data at the given
360 index or the index represents another list, `NULL' is returned.
361 *Note:* The returned pointer is valid as long as LIST is not
362 modified or released. */
363 const char *gcry_sexp_nth_data (const gcry_sexp_t list
, int number
,
366 /* This function is used to get and convert data from a LIST. The
367 data is assumed to be a Nul terminated string. The caller must
368 release the returned value using `gcry_free'. If there is no data
369 at the given index, the index represents a list or the value can't
370 be converted to a string, `NULL' is returned. */
371 char *gcry_sexp_nth_string (gcry_sexp_t list
, int number
);
373 /* This function is used to get and convert data from a LIST. This
374 data is assumed to be an MPI stored in the format described by
375 MPIFMT and returned as a standard Libgcrypt MPI. The caller must
376 release this returned value using `gcry_mpi_release'. If there is
377 no data at the given index, the index represents a list or the
378 value can't be converted to an MPI, `NULL' is returned. */
379 gcry_mpi_t
gcry_sexp_nth_mpi (gcry_sexp_t list
, int number
, int mpifmt
);
383 /*******************************************
385 * Multi Precision Integer Functions *
387 *******************************************/
389 /* Different formats of external big integer representation. */
393 GCRYMPI_FMT_STD
= 1, /* Twos complement stored without length. */
394 GCRYMPI_FMT_PGP
= 2, /* As used by OpenPGP (unsigned only). */
395 GCRYMPI_FMT_SSH
= 3, /* As used by SSH (like STD but with length). */
396 GCRYMPI_FMT_HEX
= 4, /* Hex format. */
397 GCRYMPI_FMT_USG
= 5 /* Like STD but unsigned. */
400 /* Flags used for creating big integers. */
403 GCRYMPI_FLAG_SECURE
= 1, /* Allocate the number in "secure" memory. */
404 GCRYMPI_FLAG_OPAQUE
= 2 /* The number is not a real one but just
405 a way to store some bytes. This is
406 useful for encrypted big integers. */
410 /* Allocate a new big integer object, initialize it with 0 and
411 initially allocate memory for a number of at least NBITS. */
412 gcry_mpi_t
gcry_mpi_new (unsigned int nbits
);
414 /* Same as gcry_mpi_new() but allocate in "secure" memory. */
415 gcry_mpi_t
gcry_mpi_snew (unsigned int nbits
);
417 /* Release the number A and free all associated resources. */
418 void gcry_mpi_release (gcry_mpi_t a
);
420 /* Create a new number with the same value as A. */
421 gcry_mpi_t
gcry_mpi_copy (const gcry_mpi_t a
);
423 /* Store the big integer value U in W. */
424 gcry_mpi_t
gcry_mpi_set (gcry_mpi_t w
, const gcry_mpi_t u
);
426 /* Store the unsigned integer value U in W. */
427 gcry_mpi_t
gcry_mpi_set_ui (gcry_mpi_t w
, unsigned long u
);
429 /* Swap the values of A and B. */
430 void gcry_mpi_swap (gcry_mpi_t a
, gcry_mpi_t b
);
432 /* Compare the big integer number U and V returning 0 for equality, a
433 positive value for U > V and a negative for U < V. */
434 int gcry_mpi_cmp (const gcry_mpi_t u
, const gcry_mpi_t v
);
436 /* Compare the big integer number U with the unsigned integer V
437 returning 0 for equality, a positive value for U > V and a negative
439 int gcry_mpi_cmp_ui (const gcry_mpi_t u
, unsigned long v
);
441 /* Convert the external representation of an integer stored in BUFFER
442 with a length of BUFLEN into a newly create MPI returned in
443 RET_MPI. If NSCANNED is not NULL, it will receive the number of
444 bytes actually scanned after a successful operation. */
445 gcry_error_t
gcry_mpi_scan (gcry_mpi_t
*ret_mpi
, enum gcry_mpi_format format
,
446 const void *buffer
, size_t buflen
,
449 /* Convert the big integer A into the external representation
450 described by FORMAT and store it in the provided BUFFER which has
451 been allocated by the user with a size of BUFLEN bytes. NWRITTEN
452 receives the actual length of the external representation unless it
453 has been passed as NULL. */
454 gcry_error_t
gcry_mpi_print (enum gcry_mpi_format format
,
455 unsigned char *buffer
, size_t buflen
,
459 /* Convert the big integer A int the external representation described
460 by FORMAT and store it in a newly allocated buffer which address
461 will be put into BUFFER. NWRITTEN receives the actual lengths of the
462 external representation. */
463 gcry_error_t
gcry_mpi_aprint (enum gcry_mpi_format format
,
464 unsigned char **buffer
, size_t *nwritten
,
467 /* Dump the value of A in a format suitable for debugging to
468 Libgcrypt's logging stream. Note that one leading space but no
469 trailing space or linefeed will be printed. It is okay to pass
471 void gcry_mpi_dump (const gcry_mpi_t a
);
475 void gcry_mpi_add (gcry_mpi_t w
, gcry_mpi_t u
, gcry_mpi_t v
);
477 /* W = U + V. V is an unsigned integer. */
478 void gcry_mpi_add_ui (gcry_mpi_t w
, gcry_mpi_t u
, unsigned long v
);
480 /* W = U + V mod M. */
481 void gcry_mpi_addm (gcry_mpi_t w
, gcry_mpi_t u
, gcry_mpi_t v
, gcry_mpi_t m
);
484 void gcry_mpi_sub (gcry_mpi_t w
, gcry_mpi_t u
, gcry_mpi_t v
);
486 /* W = U - V. V is an unsigned integer. */
487 void gcry_mpi_sub_ui (gcry_mpi_t w
, gcry_mpi_t u
, unsigned long v
);
489 /* W = U - V mod M */
490 void gcry_mpi_subm (gcry_mpi_t w
, gcry_mpi_t u
, gcry_mpi_t v
, gcry_mpi_t m
);
493 void gcry_mpi_mul (gcry_mpi_t w
, gcry_mpi_t u
, gcry_mpi_t v
);
495 /* W = U * V. V is an unsigned integer. */
496 void gcry_mpi_mul_ui (gcry_mpi_t w
, gcry_mpi_t u
, unsigned long v
);
498 /* W = U * V mod M. */
499 void gcry_mpi_mulm (gcry_mpi_t w
, gcry_mpi_t u
, gcry_mpi_t v
, gcry_mpi_t m
);
501 /* W = U * (2 ^ CNT). */
502 void gcry_mpi_mul_2exp (gcry_mpi_t w
, gcry_mpi_t u
, unsigned long cnt
);
504 /* Q = DIVIDEND / DIVISOR, R = DIVIDEND % DIVISOR,
505 Q or R may be passed as NULL. ROUND should be negative or 0. */
506 void gcry_mpi_div (gcry_mpi_t q
, gcry_mpi_t r
,
507 gcry_mpi_t dividend
, gcry_mpi_t divisor
, int round
);
509 /* R = DIVIDEND % DIVISOR */
510 void gcry_mpi_mod (gcry_mpi_t r
, gcry_mpi_t dividend
, gcry_mpi_t divisor
);
512 /* W = B ^ E mod M. */
513 void gcry_mpi_powm (gcry_mpi_t w
,
514 const gcry_mpi_t b
, const gcry_mpi_t e
,
517 /* Set G to the greatest common divisor of A and B.
518 Return true if the G is 1. */
519 int gcry_mpi_gcd (gcry_mpi_t g
, gcry_mpi_t a
, gcry_mpi_t b
);
521 /* Set X to the multiplicative inverse of A mod M.
522 Return true if the value exists. */
523 int gcry_mpi_invm (gcry_mpi_t x
, gcry_mpi_t a
, gcry_mpi_t m
);
526 /* Return the number of bits required to represent A. */
527 unsigned int gcry_mpi_get_nbits (gcry_mpi_t a
);
529 /* Return true when bit number N (counting from 0) is set in A. */
530 int gcry_mpi_test_bit (gcry_mpi_t a
, unsigned int n
);
532 /* Set bit number N in A. */
533 void gcry_mpi_set_bit (gcry_mpi_t a
, unsigned int n
);
535 /* Clear bit number N in A. */
536 void gcry_mpi_clear_bit (gcry_mpi_t a
, unsigned int n
);
538 /* Set bit number N in A and clear all bits greater than N. */
539 void gcry_mpi_set_highbit (gcry_mpi_t a
, unsigned int n
);
541 /* Clear bit number N in A and all bits greater than N. */
542 void gcry_mpi_clear_highbit (gcry_mpi_t a
, unsigned int n
);
544 /* Shift the value of A by N bits to the right and store the result in X. */
545 void gcry_mpi_rshift (gcry_mpi_t x
, gcry_mpi_t a
, unsigned int n
);
547 /* Shift the value of A by N bits to the left and store the result in X. */
548 void gcry_mpi_lshift (gcry_mpi_t x
, gcry_mpi_t a
, unsigned int n
);
550 /* Store NBITS of the value P points to in A and mark A as an opaque
551 value. WARNING: Never use an opaque MPI for anything thing else then
552 gcry_mpi_release, gcry_mpi_get_opaque. */
553 gcry_mpi_t
gcry_mpi_set_opaque (gcry_mpi_t a
, void *p
, unsigned int nbits
);
555 /* Return a pointer to an opaque value stored in A and return its size
556 in NBITS. Note that the returned pointer is still owned by A and
557 that the function should never be used for an non-opaque MPI. */
558 void *gcry_mpi_get_opaque (gcry_mpi_t a
, unsigned int *nbits
);
560 /* Set the FLAG for the big integer A. Currently only the flag
561 GCRYMPI_FLAG_SECURE is allowed to convert A into an big intger
562 stored in "secure" memory. */
563 void gcry_mpi_set_flag (gcry_mpi_t a
, enum gcry_mpi_flag flag
);
565 /* Clear FLAG for the big integer A. Note that this function is
566 currently useless as no flags are allowed. */
567 void gcry_mpi_clear_flag (gcry_mpi_t a
, enum gcry_mpi_flag flag
);
569 /* Return true when the FLAG is set for A. */
570 int gcry_mpi_get_flag (gcry_mpi_t a
, enum gcry_mpi_flag flag
);
572 /* Unless the GCRYPT_NO_MPI_MACROS is used, provide a couple of
573 convenience macros for the big integer functions. */
574 #ifndef GCRYPT_NO_MPI_MACROS
575 #define mpi_new(n) gcry_mpi_new( (n) )
576 #define mpi_secure_new( n ) gcry_mpi_snew( (n) )
577 #define mpi_release(a) \
580 gcry_mpi_release ((a)); \
585 #define mpi_copy( a ) gcry_mpi_copy( (a) )
586 #define mpi_set( w, u) gcry_mpi_set( (w), (u) )
587 #define mpi_set_ui( w, u) gcry_mpi_set_ui( (w), (u) )
588 #define mpi_cmp( u, v ) gcry_mpi_cmp( (u), (v) )
589 #define mpi_cmp_ui( u, v ) gcry_mpi_cmp_ui( (u), (v) )
591 #define mpi_add_ui(w,u,v) gcry_mpi_add_ui((w),(u),(v))
592 #define mpi_add(w,u,v) gcry_mpi_add ((w),(u),(v))
593 #define mpi_addm(w,u,v,m) gcry_mpi_addm ((w),(u),(v),(m))
594 #define mpi_sub_ui(w,u,v) gcry_mpi_sub_ui ((w),(u),(v))
595 #define mpi_sub(w,u,v) gcry_mpi_sub ((w),(u),(v))
596 #define mpi_subm(w,u,v,m) gcry_mpi_subm ((w),(u),(v),(m))
597 #define mpi_mul_ui(w,u,v) gcry_mpi_mul_ui ((w),(u),(v))
598 #define mpi_mul_2exp(w,u,v) gcry_mpi_mul_2exp ((w),(u),(v))
599 #define mpi_mul(w,u,v) gcry_mpi_mul ((w),(u),(v))
600 #define mpi_mulm(w,u,v,m) gcry_mpi_mulm ((w),(u),(v),(m))
601 #define mpi_powm(w,b,e,m) gcry_mpi_powm ( (w), (b), (e), (m) )
602 #define mpi_tdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), 0)
603 #define mpi_fdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), -1)
604 #define mpi_mod(r,a,m) gcry_mpi_mod ((r), (a), (m))
605 #define mpi_gcd(g,a,b) gcry_mpi_gcd ( (g), (a), (b) )
606 #define mpi_invm(g,a,b) gcry_mpi_invm ( (g), (a), (b) )
608 #define mpi_get_nbits(a) gcry_mpi_get_nbits ((a))
609 #define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b))
610 #define mpi_set_bit(a,b) gcry_mpi_set_bit ((a),(b))
611 #define mpi_set_highbit(a,b) gcry_mpi_set_highbit ((a),(b))
612 #define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b))
613 #define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b))
614 #define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c))
615 #define mpi_lshift(a,b,c) gcry_mpi_lshift ((a),(b),(c))
617 #define mpi_set_opaque(a,b,c) gcry_mpi_set_opaque( (a), (b), (c) )
618 #define mpi_get_opaque(a,b) gcry_mpi_get_opaque( (a), (b) )
619 #endif /* GCRYPT_NO_MPI_MACROS */
623 /************************************
625 * Symmetric Cipher Functions *
627 ************************************/
629 /* The data object used to hold a handle to an encryption object. */
630 struct gcry_cipher_handle
;
631 typedef struct gcry_cipher_handle
*gcry_cipher_hd_t
;
633 #ifndef GCRYPT_NO_DEPRECATED
634 typedef struct gcry_cipher_handle
*GCRY_CIPHER_HD _GCRY_GCC_ATTR_DEPRECATED
;
635 typedef struct gcry_cipher_handle
*GcryCipherHd _GCRY_GCC_ATTR_DEPRECATED
;
638 /* All symmetric encryption algorithms are identified by their IDs.
639 More IDs may be registered at runtime. */
640 enum gcry_cipher_algos
642 GCRY_CIPHER_NONE
= 0,
643 GCRY_CIPHER_IDEA
= 1,
644 GCRY_CIPHER_3DES
= 2,
645 GCRY_CIPHER_CAST5
= 3,
646 GCRY_CIPHER_BLOWFISH
= 4,
647 GCRY_CIPHER_SAFER_SK128
= 5,
648 GCRY_CIPHER_DES_SK
= 6,
650 GCRY_CIPHER_AES192
= 8,
651 GCRY_CIPHER_AES256
= 9,
652 GCRY_CIPHER_TWOFISH
= 10,
654 /* Other cipher numbers are above 300 for OpenPGP reasons. */
655 GCRY_CIPHER_ARCFOUR
= 301, /* Fully compatible with RSA's RC4 (tm). */
656 GCRY_CIPHER_DES
= 302, /* Yes, this is single key 56 bit DES. */
657 GCRY_CIPHER_TWOFISH128
= 303,
658 GCRY_CIPHER_SERPENT128
= 304,
659 GCRY_CIPHER_SERPENT192
= 305,
660 GCRY_CIPHER_SERPENT256
= 306,
661 GCRY_CIPHER_RFC2268_40
= 307, /* Ron's Cipher 2 (40 bit). */
662 GCRY_CIPHER_RFC2268_128
= 308, /* Ron's Cipher 2 (128 bit). */
663 GCRY_CIPHER_SEED
= 309, /* 128 bit cipher described in RFC4269. */
664 GCRY_CIPHER_CAMELLIA128
= 310,
665 GCRY_CIPHER_CAMELLIA192
= 311,
666 GCRY_CIPHER_CAMELLIA256
= 312
669 /* The Rijndael algorithm is basically AES, so provide some macros. */
670 #define GCRY_CIPHER_AES128 GCRY_CIPHER_AES
671 #define GCRY_CIPHER_RIJNDAEL GCRY_CIPHER_AES
672 #define GCRY_CIPHER_RIJNDAEL128 GCRY_CIPHER_AES128
673 #define GCRY_CIPHER_RIJNDAEL192 GCRY_CIPHER_AES192
674 #define GCRY_CIPHER_RIJNDAEL256 GCRY_CIPHER_AES256
676 /* The supported encryption modes. Note that not all of them are
677 supported for each algorithm. */
678 enum gcry_cipher_modes
680 GCRY_CIPHER_MODE_NONE
= 0, /* Not yet specified. */
681 GCRY_CIPHER_MODE_ECB
= 1, /* Electronic codebook. */
682 GCRY_CIPHER_MODE_CFB
= 2, /* Cipher feedback. */
683 GCRY_CIPHER_MODE_CBC
= 3, /* Cipher block chaining. */
684 GCRY_CIPHER_MODE_STREAM
= 4, /* Used with stream ciphers. */
685 GCRY_CIPHER_MODE_OFB
= 5, /* Outer feedback. */
686 GCRY_CIPHER_MODE_CTR
= 6, /* Counter. */
687 GCRY_CIPHER_MODE_AESWRAP
= 7 /* AES-WRAP algorithm. */
690 /* Flags used with the open function. */
691 enum gcry_cipher_flags
693 GCRY_CIPHER_SECURE
= 1, /* Allocate in secure memory. */
694 GCRY_CIPHER_ENABLE_SYNC
= 2, /* Enable CFB sync mode. */
695 GCRY_CIPHER_CBC_CTS
= 4, /* Enable CBC cipher text stealing (CTS). */
696 GCRY_CIPHER_CBC_MAC
= 8 /* Enable CBC message auth. code (MAC). */
700 /* Create a handle for algorithm ALGO to be used in MODE. FLAGS may
701 be given as an bitwise OR of the gcry_cipher_flags values. */
702 gcry_error_t
gcry_cipher_open (gcry_cipher_hd_t
*handle
,
703 int algo
, int mode
, unsigned int flags
);
705 /* Close the cioher handle H and release all resource. */
706 void gcry_cipher_close (gcry_cipher_hd_t h
);
708 /* Perform various operations on the cipher object H. */
709 gcry_error_t
gcry_cipher_ctl (gcry_cipher_hd_t h
, int cmd
, void *buffer
,
712 /* Retrieve various information about the cipher object H. */
713 gcry_error_t
gcry_cipher_info (gcry_cipher_hd_t h
, int what
, void *buffer
,
716 /* Retrieve various information about the cipher algorithm ALGO. */
717 gcry_error_t
gcry_cipher_algo_info (int algo
, int what
, void *buffer
,
720 /* Map the cipher algorithm whose ID is contained in ALGORITHM to a
721 string representation of the algorithm name. For unknown algorithm
722 IDs this function returns "?". */
723 const char *gcry_cipher_algo_name (int algorithm
) _GCRY_GCC_ATTR_PURE
;
725 /* Map the algorithm name NAME to an cipher algorithm ID. Return 0 if
726 the algorithm name is not known. */
727 int gcry_cipher_map_name (const char *name
) _GCRY_GCC_ATTR_PURE
;
729 /* Given an ASN.1 object identifier in standard IETF dotted decimal
730 format in STRING, return the encryption mode associated with that
731 OID or 0 if not known or applicable. */
732 int gcry_cipher_mode_from_oid (const char *string
) _GCRY_GCC_ATTR_PURE
;
734 /* Encrypt the plaintext of size INLEN in IN using the cipher handle H
735 into the buffer OUT which has an allocated length of OUTSIZE. For
736 most algorithms it is possible to pass NULL for in and 0 for INLEN
737 and do a in-place decryption of the data provided in OUT. */
738 gcry_error_t
gcry_cipher_encrypt (gcry_cipher_hd_t h
,
739 void *out
, size_t outsize
,
740 const void *in
, size_t inlen
);
742 /* The counterpart to gcry_cipher_encrypt. */
743 gcry_error_t
gcry_cipher_decrypt (gcry_cipher_hd_t h
,
744 void *out
, size_t outsize
,
745 const void *in
, size_t inlen
);
747 /* Set KEY of length KEYLEN bytes for the cipher handle HD. */
748 gcry_error_t
gcry_cipher_setkey (gcry_cipher_hd_t hd
,
749 const void *key
, size_t keylen
);
752 /* Set initialization vector IV of length IVLEN for the cipher handle HD. */
753 gcry_error_t
gcry_cipher_setiv (gcry_cipher_hd_t hd
,
754 const void *iv
, size_t ivlen
);
757 /* Reset the handle to the state after open. */
758 #define gcry_cipher_reset(h) gcry_cipher_ctl ((h), GCRYCTL_RESET, NULL, 0)
760 /* Perform the OpenPGP sync operation if this is enabled for the
762 #define gcry_cipher_sync(h) gcry_cipher_ctl( (h), GCRYCTL_CFB_SYNC, NULL, 0)
764 /* Enable or disable CTS in future calls to gcry_encrypt(). CBC mode only. */
765 #define gcry_cipher_cts(h,on) gcry_cipher_ctl( (h), GCRYCTL_SET_CBC_CTS, \
768 /* Set counter for CTR mode. (CTR,CTRLEN) must denote a buffer of
769 block size length, or (NULL,0) to set the CTR to the all-zero block. */
770 gpg_error_t
gcry_cipher_setctr (gcry_cipher_hd_t hd
,
771 const void *ctr
, size_t ctrlen
);
773 /* Retrieve the key length in bytes used with algorithm A. */
774 size_t gcry_cipher_get_algo_keylen (int algo
);
776 /* Retrieve the block length in bytes used with algorithm A. */
777 size_t gcry_cipher_get_algo_blklen (int algo
);
779 /* Return 0 if the algorithm A is available for use. */
780 #define gcry_cipher_test_algo(a) \
781 gcry_cipher_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
783 /* Get a list consisting of the IDs of the loaded cipher modules. If
784 LIST is zero, write the number of loaded cipher modules to
785 LIST_LENGTH and return. If LIST is non-zero, the first
786 *LIST_LENGTH algorithm IDs are stored in LIST, which must be of
787 according size. In case there are less cipher modules than
788 *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */
789 gcry_error_t
gcry_cipher_list (int *list
, int *list_length
);
792 /************************************
794 * Asymmetric Cipher Functions *
796 ************************************/
798 /* The algorithms and their IDs we support. */
802 GCRY_PK_RSA_E
= 2, /* (deprecated) */
803 GCRY_PK_RSA_S
= 3, /* (deprecated) */
811 /* Flags describing usage capabilities of a PK algorithm. */
812 #define GCRY_PK_USAGE_SIGN 1 /* Good for signatures. */
813 #define GCRY_PK_USAGE_ENCR 2 /* Good for encryption. */
814 #define GCRY_PK_USAGE_CERT 4 /* Good to certify other keys. */
815 #define GCRY_PK_USAGE_AUTH 8 /* Good for authentication. */
816 #define GCRY_PK_USAGE_UNKN 128 /* Unknown usage flag. */
818 /* Encrypt the DATA using the public key PKEY and store the result as
819 a newly created S-expression at RESULT. */
820 gcry_error_t
gcry_pk_encrypt (gcry_sexp_t
*result
,
821 gcry_sexp_t data
, gcry_sexp_t pkey
);
823 /* Decrypt the DATA using the private key SKEY and store the result as
824 a newly created S-expression at RESULT. */
825 gcry_error_t
gcry_pk_decrypt (gcry_sexp_t
*result
,
826 gcry_sexp_t data
, gcry_sexp_t skey
);
828 /* Sign the DATA using the private key SKEY and store the result as
829 a newly created S-expression at RESULT. */
830 gcry_error_t
gcry_pk_sign (gcry_sexp_t
*result
,
831 gcry_sexp_t data
, gcry_sexp_t skey
);
833 /* Check the signature SIGVAL on DATA using the public key PKEY. */
834 gcry_error_t
gcry_pk_verify (gcry_sexp_t sigval
,
835 gcry_sexp_t data
, gcry_sexp_t pkey
);
837 /* Check that private KEY is sane. */
838 gcry_error_t
gcry_pk_testkey (gcry_sexp_t key
);
840 /* Generate a new key pair according to the parameters given in
841 S_PARMS. The new key pair is returned in as an S-expression in
843 gcry_error_t
gcry_pk_genkey (gcry_sexp_t
*r_key
, gcry_sexp_t s_parms
);
845 /* Catch all function for miscellaneous operations. */
846 gcry_error_t
gcry_pk_ctl (int cmd
, void *buffer
, size_t buflen
);
848 /* Retrieve information about the public key algorithm ALGO. */
849 gcry_error_t
gcry_pk_algo_info (int algo
, int what
,
850 void *buffer
, size_t *nbytes
);
852 /* Map the public key algorithm whose ID is contained in ALGORITHM to
853 a string representation of the algorithm name. For unknown
854 algorithm IDs this functions returns "?". */
855 const char *gcry_pk_algo_name (int algorithm
) _GCRY_GCC_ATTR_PURE
;
857 /* Map the algorithm NAME to a public key algorithm Id. Return 0 if
858 the algorithm name is not known. */
859 int gcry_pk_map_name (const char* name
) _GCRY_GCC_ATTR_PURE
;
861 /* Return what is commonly referred as the key length for the given
862 public or private KEY. */
863 unsigned int gcry_pk_get_nbits (gcry_sexp_t key
) _GCRY_GCC_ATTR_PURE
;
865 /* Please note that keygrip is still experimental and should not be
866 used without contacting the author. */
867 unsigned char *gcry_pk_get_keygrip (gcry_sexp_t key
, unsigned char *array
);
869 /* Return the name of the curve matching KEY. */
870 const char *gcry_pk_get_curve (gcry_sexp_t key
, int iterator
,
871 unsigned int *r_nbits
);
873 /* Return an S-expression with the parameters of the named ECC curve
874 NAME. ALGO must be set to an ECC algorithm. */
875 gcry_sexp_t
gcry_pk_get_param (int algo
, const char *name
);
877 /* Return 0 if the public key algorithm A is available for use. */
878 #define gcry_pk_test_algo(a) \
879 gcry_pk_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
881 /* Get a list consisting of the IDs of the loaded pubkey modules. If
882 LIST is zero, write the number of loaded pubkey modules to
883 LIST_LENGTH and return. If LIST is non-zero, the first
884 *LIST_LENGTH algorithm IDs are stored in LIST, which must be of
885 according size. In case there are less pubkey modules than
886 *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */
887 gcry_error_t
gcry_pk_list (int *list
, int *list_length
);
891 /************************************
893 * Cryptograhic Hash Functions *
895 ************************************/
897 /* Algorithm IDs for the hash functions we know about. Not all of them
906 GCRY_MD_TIGER
= 6, /* TIGER/192 as used by gpg <= 1.3.2. */
907 GCRY_MD_HAVAL
= 7, /* HAVAL, 5 pass, 160 bit. */
914 GCRY_MD_CRC32_RFC1510
= 303,
915 GCRY_MD_CRC24_RFC2440
= 304,
916 GCRY_MD_WHIRLPOOL
= 305,
917 GCRY_MD_TIGER1
= 306, /* TIGER fixed. */
918 GCRY_MD_TIGER2
= 307 /* TIGER2 variant. */
921 /* Flags used with the open function. */
924 GCRY_MD_FLAG_SECURE
= 1, /* Allocate all buffers in "secure" memory. */
925 GCRY_MD_FLAG_HMAC
= 2 /* Make an HMAC out of this algorithm. */
928 /* (Forward declaration.) */
929 struct gcry_md_context
;
931 /* This object is used to hold a handle to a message digest object.
932 This structure is private - only to be used by the public gcry_md_*
934 typedef struct gcry_md_handle
936 /* Actual context. */
937 struct gcry_md_context
*ctx
;
939 /* Buffer management. */
942 unsigned char buf
[1];
945 /* Compatibility types, do not use them. */
946 #ifndef GCRYPT_NO_DEPRECATED
947 typedef struct gcry_md_handle
*GCRY_MD_HD _GCRY_GCC_ATTR_DEPRECATED
;
948 typedef struct gcry_md_handle
*GcryMDHd _GCRY_GCC_ATTR_DEPRECATED
;
951 /* Create a message digest object for algorithm ALGO. FLAGS may be
952 given as an bitwise OR of the gcry_md_flags values. ALGO may be
953 given as 0 if the algorithms to be used are later set using
955 gcry_error_t
gcry_md_open (gcry_md_hd_t
*h
, int algo
, unsigned int flags
);
957 /* Release the message digest object HD. */
958 void gcry_md_close (gcry_md_hd_t hd
);
960 /* Add the message digest algorithm ALGO to the digest object HD. */
961 gcry_error_t
gcry_md_enable (gcry_md_hd_t hd
, int algo
);
963 /* Create a new digest object as an exact copy of the object HD. */
964 gcry_error_t
gcry_md_copy (gcry_md_hd_t
*bhd
, gcry_md_hd_t ahd
);
966 /* Reset the digest object HD to its initial state. */
967 void gcry_md_reset (gcry_md_hd_t hd
);
969 /* Perform various operations on the digest object HD. */
970 gcry_error_t
gcry_md_ctl (gcry_md_hd_t hd
, int cmd
,
971 void *buffer
, size_t buflen
);
973 /* Pass LENGTH bytes of data in BUFFER to the digest object HD so that
974 it can update the digest values. This is the actual hash
976 void gcry_md_write (gcry_md_hd_t hd
, const void *buffer
, size_t length
);
978 /* Read out the final digest from HD return the digest value for
980 unsigned char *gcry_md_read (gcry_md_hd_t hd
, int algo
);
982 /* Convenience function to calculate the hash from the data in BUFFER
983 of size LENGTH using the algorithm ALGO avoiding the creating of a
984 hash object. The hash is returned in the caller provided buffer
985 DIGEST which must be large enough to hold the digest of the given
987 void gcry_md_hash_buffer (int algo
, void *digest
,
988 const void *buffer
, size_t length
);
990 /* Retrieve the algorithm used with HD. This does not work reliable
991 if more than one algorithm is enabled in HD. */
992 int gcry_md_get_algo (gcry_md_hd_t hd
);
994 /* Retrieve the length in bytes of the digest yielded by algorithm
996 unsigned int gcry_md_get_algo_dlen (int algo
);
998 /* Return true if the the algorithm ALGO is enabled in the digest
1000 int gcry_md_is_enabled (gcry_md_hd_t a
, int algo
);
1002 /* Return true if the digest object A is allocated in "secure" memory. */
1003 int gcry_md_is_secure (gcry_md_hd_t a
);
1005 /* Retrieve various information about the object H. */
1006 gcry_error_t
gcry_md_info (gcry_md_hd_t h
, int what
, void *buffer
,
1009 /* Retrieve various information about the algorithm ALGO. */
1010 gcry_error_t
gcry_md_algo_info (int algo
, int what
, void *buffer
,
1013 /* Map the digest algorithm id ALGO to a string representation of the
1014 algorithm name. For unknown algorithms this function returns
1016 const char *gcry_md_algo_name (int algo
) _GCRY_GCC_ATTR_PURE
;
1018 /* Map the algorithm NAME to a digest algorithm Id. Return 0 if
1019 the algorithm name is not known. */
1020 int gcry_md_map_name (const char* name
) _GCRY_GCC_ATTR_PURE
;
1022 /* For use with the HMAC feature, the set MAC key to the KEY of
1024 gcry_error_t
gcry_md_setkey (gcry_md_hd_t hd
, const void *key
, size_t keylen
);
1026 /* Start or stop debugging for digest handle HD; i.e. create a file
1027 named dbgmd-<n>.<suffix> while hashing. If SUFFIX is NULL,
1028 debugging stops and the file will be closed. */
1029 void gcry_md_debug (gcry_md_hd_t hd
, const char *suffix
);
1032 /* Update the hash(s) of H with the character C. This is a buffered
1033 version of the gcry_md_write function. */
1034 #define gcry_md_putc(h,c) \
1036 gcry_md_hd_t h__ = (h); \
1037 if( (h__)->bufpos == (h__)->bufsize ) \
1038 gcry_md_write( (h__), NULL, 0 ); \
1039 (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \
1042 /* Finalize the digest calculation. This is not really needed because
1043 gcry_md_read() does this implicitly. */
1044 #define gcry_md_final(a) \
1045 gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0)
1047 /* Return 0 if the algorithm A is available for use. */
1048 #define gcry_md_test_algo(a) \
1049 gcry_md_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
1051 /* Return an DER encoded ASN.1 OID for the algorithm A in buffer B. N
1052 must point to size_t variable with the available size of buffer B.
1053 After return it will receive the actual size of the returned
1055 #define gcry_md_get_asnoid(a,b,n) \
1056 gcry_md_algo_info((a), GCRYCTL_GET_ASNOID, (b), (n))
1058 /* Enable debugging for digest object A; i.e. create files named
1059 dbgmd-<n>.<string> while hashing. B is a string used as the suffix
1060 for the filename. This macro is deprecated, use gcry_md_debug. */
1061 #ifndef GCRYPT_NO_DEPRECATED
1062 #define gcry_md_start_debug(a,b) \
1063 gcry_md_ctl( (a), GCRYCTL_START_DUMP, (b), 0 )
1065 /* Disable the debugging of A. This macro is deprecated, use
1067 #define gcry_md_stop_debug(a,b) \
1068 gcry_md_ctl( (a), GCRYCTL_STOP_DUMP, (b), 0 )
1071 /* Get a list consisting of the IDs of the loaded message digest
1072 modules. If LIST is zero, write the number of loaded message
1073 digest modules to LIST_LENGTH and return. If LIST is non-zero, the
1074 first *LIST_LENGTH algorithm IDs are stored in LIST, which must be
1075 of according size. In case there are less message digest modules
1076 than *LIST_LENGTH, *LIST_LENGTH is updated to the correct
1078 gcry_error_t
gcry_md_list (int *list
, int *list_length
);
1081 #if !defined(GCRYPT_NO_DEPRECATED) || defined(_GCRYPT_IN_LIBGCRYPT)
1082 /* Alternative interface for asymmetric cryptography. This interface
1085 /* The algorithm IDs. */
1086 typedef enum gcry_ac_id
1093 gcry_ac_id_t _GCRY_ATTR_INTERNAL
;
1096 typedef enum gcry_ac_key_type
1101 gcry_ac_key_type_t _GCRY_ATTR_INTERNAL
;
1103 /* Encoding methods. */
1104 typedef enum gcry_ac_em
1106 GCRY_AC_EME_PKCS_V1_5
,
1107 GCRY_AC_EMSA_PKCS_V1_5
1109 gcry_ac_em_t _GCRY_ATTR_INTERNAL
;
1111 /* Encryption and Signature schemes. */
1112 typedef enum gcry_ac_scheme
1114 GCRY_AC_ES_PKCS_V1_5
,
1115 GCRY_AC_SSA_PKCS_V1_5
1117 gcry_ac_scheme_t _GCRY_ATTR_INTERNAL
;
1120 #define GCRY_AC_FLAG_DEALLOC (1 << 0)
1121 #define GCRY_AC_FLAG_COPY (1 << 1)
1122 #define GCRY_AC_FLAG_NO_BLINDING (1 << 2)
1124 /* This type represents a `data set'. */
1125 typedef struct gcry_ac_data
*gcry_ac_data_t _GCRY_ATTR_INTERNAL
;
1127 /* This type represents a single `key', either a secret one or a
1129 typedef struct gcry_ac_key
*gcry_ac_key_t _GCRY_ATTR_INTERNAL
;
1131 /* This type represents a `key pair' containing a secret and a public
1133 typedef struct gcry_ac_key_pair
*gcry_ac_key_pair_t _GCRY_ATTR_INTERNAL
;
1135 /* This type represents a `handle' that is needed by functions
1136 performing cryptographic operations. */
1137 typedef struct gcry_ac_handle
*gcry_ac_handle_t _GCRY_ATTR_INTERNAL
;
1139 typedef gpg_error_t (*gcry_ac_data_read_cb_t
) (void *opaque
,
1140 unsigned char *buffer
,
1142 /* */ _GCRY_ATTR_INTERNAL
;
1144 typedef gpg_error_t (*gcry_ac_data_write_cb_t
) (void *opaque
,
1145 unsigned char *buffer
,
1147 /* */ _GCRY_ATTR_INTERNAL
;
1151 GCRY_AC_IO_READABLE
,
1154 gcry_ac_io_mode_t _GCRY_ATTR_INTERNAL
;
1161 gcry_ac_io_type_t _GCRY_ATTR_INTERNAL
;
1163 typedef struct gcry_ac_io
1165 /* This is an INTERNAL structure, do NOT use manually. */
1166 gcry_ac_io_mode_t mode _GCRY_ATTR_INTERNAL
;
1167 gcry_ac_io_type_t type _GCRY_ATTR_INTERNAL
;
1174 gcry_ac_data_read_cb_t cb
;
1179 unsigned char *data
;
1188 gcry_ac_data_write_cb_t cb
;
1193 unsigned char **data
;
1198 } io _GCRY_ATTR_INTERNAL
;
1200 gcry_ac_io_t _GCRY_ATTR_INTERNAL
;
1202 /* The caller of gcry_ac_key_pair_generate can provide one of these
1203 structures in order to influence the key generation process in an
1204 algorithm-specific way. */
1205 typedef struct gcry_ac_key_spec_rsa
1207 gcry_mpi_t e
; /* E to use. */
1208 } gcry_ac_key_spec_rsa_t _GCRY_ATTR_INTERNAL
;
1210 /* Structure used for passing data to the implementation of the
1211 `EME-PKCS-V1_5' encoding method. */
1212 typedef struct gcry_ac_eme_pkcs_v1_5
1215 } gcry_ac_eme_pkcs_v1_5_t _GCRY_ATTR_INTERNAL
;
1217 typedef enum gcry_md_algos gcry_md_algo_t _GCRY_ATTR_INTERNAL
;
1219 /* Structure used for passing data to the implementation of the
1220 `EMSA-PKCS-V1_5' encoding method. */
1221 typedef struct gcry_ac_emsa_pkcs_v1_5
1225 } gcry_ac_emsa_pkcs_v1_5_t _GCRY_ATTR_INTERNAL
;
1227 /* Structure used for passing data to the implementation of the
1228 `SSA-PKCS-V1_5' signature scheme. */
1229 typedef struct gcry_ac_ssa_pkcs_v1_5
1232 } gcry_ac_ssa_pkcs_v1_5_t _GCRY_ATTR_INTERNAL
;
1233 #endif /* !GCRYPT_NO_DEPRECATED || !_GCRYPT_IN_LIBGCRYPT */
1236 #ifndef GCRYPT_NO_DEPRECATED
1237 /* Returns a new, empty data set in DATA. */
1238 gcry_error_t
gcry_ac_data_new (gcry_ac_data_t
*data
)
1239 /* */ _GCRY_ATTR_INTERNAL
;
1241 /* Destroy the data set DATA. */
1242 void gcry_ac_data_destroy (gcry_ac_data_t data
)
1243 /* */ _GCRY_ATTR_INTERNAL
;
1245 /* Create a copy of the data set DATA and store it in DATA_CP. */
1246 gcry_error_t
gcry_ac_data_copy (gcry_ac_data_t
*data_cp
,
1247 gcry_ac_data_t data
)
1248 /* */ _GCRY_ATTR_INTERNAL
;
1250 /* Return the number of named MPI values inside of the data set
1252 unsigned int gcry_ac_data_length (gcry_ac_data_t data
)
1253 /* */ _GCRY_ATTR_INTERNAL
;
1255 /* Destroy any values contained in the data set DATA. */
1256 void gcry_ac_data_clear (gcry_ac_data_t data
)
1257 /* */ _GCRY_ATTR_INTERNAL
;
1259 /* Add the value MPI to DATA with the label NAME. If FLAGS contains
1260 GCRY_AC_FLAG_DATA_COPY, the data set will contain copies of NAME
1261 and MPI. If FLAGS contains GCRY_AC_FLAG_DATA_DEALLOC or
1262 GCRY_AC_FLAG_DATA_COPY, the values contained in the data set will
1263 be deallocated when they are to be removed from the data set. */
1264 gcry_error_t
gcry_ac_data_set (gcry_ac_data_t data
, unsigned int flags
,
1265 const char *name
, gcry_mpi_t mpi
)
1266 /* */ _GCRY_ATTR_INTERNAL
;
1268 /* Store the value labelled with NAME found in DATA in MPI. If FLAGS
1269 contains GCRY_AC_FLAG_COPY, store a copy of the MPI value contained
1270 in the data set. MPI may be NULL. */
1271 gcry_error_t
gcry_ac_data_get_name (gcry_ac_data_t data
, unsigned int flags
,
1272 const char *name
, gcry_mpi_t
*mpi
)
1273 /* */ _GCRY_ATTR_INTERNAL
;
1275 /* Stores in NAME and MPI the named MPI value contained in the data
1276 set DATA with the index IDX. If FLAGS contains GCRY_AC_FLAG_COPY,
1277 store copies of the values contained in the data set. NAME or MPI
1279 gcry_error_t
gcry_ac_data_get_index (gcry_ac_data_t data
, unsigned int flags
,
1281 const char **name
, gcry_mpi_t
*mpi
)
1282 /* */ _GCRY_ATTR_INTERNAL
;
1284 /* Convert the data set DATA into a new S-Expression, which is to be
1285 stored in SEXP, according to the identifiers contained in
1287 gcry_error_t
gcry_ac_data_to_sexp (gcry_ac_data_t data
, gcry_sexp_t
*sexp
,
1288 const char **identifiers
)
1289 /* */ _GCRY_ATTR_INTERNAL
;
1291 /* Create a new data set, which is to be stored in DATA_SET, from the
1292 S-Expression SEXP, according to the identifiers contained in
1294 gcry_error_t
gcry_ac_data_from_sexp (gcry_ac_data_t
*data
, gcry_sexp_t sexp
,
1295 const char **identifiers
)
1296 /* */ _GCRY_ATTR_INTERNAL
;
1298 /* Initialize AC_IO according to MODE, TYPE and the variable list of
1299 arguments. The list of variable arguments to specify depends on
1301 void gcry_ac_io_init (gcry_ac_io_t
*ac_io
, gcry_ac_io_mode_t mode
,
1302 gcry_ac_io_type_t type
, ...)
1303 /* */ _GCRY_ATTR_INTERNAL
;
1305 /* Initialize AC_IO according to MODE, TYPE and the variable list of
1306 arguments AP. The list of variable arguments to specify depends on
1308 void gcry_ac_io_init_va (gcry_ac_io_t
*ac_io
, gcry_ac_io_mode_t mode
,
1309 gcry_ac_io_type_t type
, va_list ap
)
1310 /* */ _GCRY_ATTR_INTERNAL
;
1312 /* Create a new ac handle. */
1313 gcry_error_t
gcry_ac_open (gcry_ac_handle_t
*handle
,
1314 gcry_ac_id_t algorithm
, unsigned int flags
)
1315 /* */ _GCRY_ATTR_INTERNAL
;
1317 /* Destroy an ac handle. */
1318 void gcry_ac_close (gcry_ac_handle_t handle
)
1319 /* */ _GCRY_ATTR_INTERNAL
;
1321 /* Initialize a key from a given data set. */
1322 gcry_error_t
gcry_ac_key_init (gcry_ac_key_t
*key
, gcry_ac_handle_t handle
,
1323 gcry_ac_key_type_t type
, gcry_ac_data_t data
)
1324 /* */ _GCRY_ATTR_INTERNAL
;
1326 /* Generates a new key pair via the handle HANDLE of NBITS bits and
1327 stores it in KEY_PAIR. In case non-standard settings are wanted, a
1328 pointer to a structure of type gcry_ac_key_spec_<algorithm>_t,
1329 matching the selected algorithm, can be given as KEY_SPEC.
1330 MISC_DATA is not used yet. */
1331 gcry_error_t
gcry_ac_key_pair_generate (gcry_ac_handle_t handle
,
1332 unsigned int nbits
, void *spec
,
1333 gcry_ac_key_pair_t
*key_pair
,
1334 gcry_mpi_t
**misc_data
)
1335 /* */ _GCRY_ATTR_INTERNAL
;
1337 /* Returns the key of type WHICH out of the key pair KEY_PAIR. */
1338 gcry_ac_key_t
gcry_ac_key_pair_extract (gcry_ac_key_pair_t key_pair
,
1339 gcry_ac_key_type_t which
)
1340 /* */ _GCRY_ATTR_INTERNAL
;
1342 /* Returns the data set contained in the key KEY. */
1343 gcry_ac_data_t
gcry_ac_key_data_get (gcry_ac_key_t key
)
1344 /* */ _GCRY_ATTR_INTERNAL
;
1346 /* Verifies that the key KEY is sane via HANDLE. */
1347 gcry_error_t
gcry_ac_key_test (gcry_ac_handle_t handle
, gcry_ac_key_t key
)
1348 /* */ _GCRY_ATTR_INTERNAL
;
1350 /* Stores the number of bits of the key KEY in NBITS via HANDLE. */
1351 gcry_error_t
gcry_ac_key_get_nbits (gcry_ac_handle_t handle
,
1352 gcry_ac_key_t key
, unsigned int *nbits
)
1353 /* */ _GCRY_ATTR_INTERNAL
;
1355 /* Writes the 20 byte long key grip of the key KEY to KEY_GRIP via
1357 gcry_error_t
gcry_ac_key_get_grip (gcry_ac_handle_t handle
, gcry_ac_key_t key
,
1358 unsigned char *key_grip
)
1359 /* */ _GCRY_ATTR_INTERNAL
;
1361 /* Destroy a key. */
1362 void gcry_ac_key_destroy (gcry_ac_key_t key
)
1363 /* */ _GCRY_ATTR_INTERNAL
;
1365 /* Destroy a key pair. */
1366 void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t key_pair
)
1367 /* */ _GCRY_ATTR_INTERNAL
;
1369 /* Encodes a message according to the encoding method METHOD. OPTIONS
1370 must be a pointer to a method-specific structure
1372 gcry_error_t
gcry_ac_data_encode (gcry_ac_em_t method
,
1373 unsigned int flags
, void *options
,
1374 gcry_ac_io_t
*io_read
,
1375 gcry_ac_io_t
*io_write
)
1376 /* */ _GCRY_ATTR_INTERNAL
;
1378 /* Decodes a message according to the encoding method METHOD. OPTIONS
1379 must be a pointer to a method-specific structure
1381 gcry_error_t
gcry_ac_data_decode (gcry_ac_em_t method
,
1382 unsigned int flags
, void *options
,
1383 gcry_ac_io_t
*io_read
,
1384 gcry_ac_io_t
*io_write
)
1385 /* */ _GCRY_ATTR_INTERNAL
;
1387 /* Encrypt the plain text MPI value DATA_PLAIN with the key KEY under
1388 the control of the flags FLAGS and store the resulting data set
1389 into DATA_ENCRYPTED. */
1390 gcry_error_t
gcry_ac_data_encrypt (gcry_ac_handle_t handle
,
1393 gcry_mpi_t data_plain
,
1394 gcry_ac_data_t
*data_encrypted
)
1395 /* */ _GCRY_ATTR_INTERNAL
;
1397 /* Decrypt the decrypted data contained in the data set DATA_ENCRYPTED
1398 with the key KEY under the control of the flags FLAGS and store the
1399 resulting plain text MPI value in DATA_PLAIN. */
1400 gcry_error_t
gcry_ac_data_decrypt (gcry_ac_handle_t handle
,
1403 gcry_mpi_t
*data_plain
,
1404 gcry_ac_data_t data_encrypted
)
1405 /* */ _GCRY_ATTR_INTERNAL
;
1407 /* Sign the data contained in DATA with the key KEY and store the
1408 resulting signature in the data set DATA_SIGNATURE. */
1409 gcry_error_t
gcry_ac_data_sign (gcry_ac_handle_t handle
,
1412 gcry_ac_data_t
*data_signature
)
1413 /* */ _GCRY_ATTR_INTERNAL
;
1415 /* Verify that the signature contained in the data set DATA_SIGNATURE
1416 is indeed the result of signing the data contained in DATA with the
1417 secret key belonging to the public key KEY. */
1418 gcry_error_t
gcry_ac_data_verify (gcry_ac_handle_t handle
,
1421 gcry_ac_data_t data_signature
)
1422 /* */ _GCRY_ATTR_INTERNAL
;
1424 /* Encrypts the plain text readable from IO_MESSAGE through HANDLE
1425 with the public key KEY according to SCHEME, FLAGS and OPTS. If
1426 OPTS is not NULL, it has to be a pointer to a structure specific to
1427 the chosen scheme (gcry_ac_es_*_t). The encrypted message is
1428 written to IO_CIPHER. */
1429 gcry_error_t
gcry_ac_data_encrypt_scheme (gcry_ac_handle_t handle
,
1430 gcry_ac_scheme_t scheme
,
1431 unsigned int flags
, void *opts
,
1433 gcry_ac_io_t
*io_message
,
1434 gcry_ac_io_t
*io_cipher
)
1435 /* */ _GCRY_ATTR_INTERNAL
;
1437 /* Decrypts the cipher text readable from IO_CIPHER through HANDLE
1438 with the secret key KEY according to SCHEME, @var{flags} and OPTS.
1439 If OPTS is not NULL, it has to be a pointer to a structure specific
1440 to the chosen scheme (gcry_ac_es_*_t). The decrypted message is
1441 written to IO_MESSAGE. */
1442 gcry_error_t
gcry_ac_data_decrypt_scheme (gcry_ac_handle_t handle
,
1443 gcry_ac_scheme_t scheme
,
1444 unsigned int flags
, void *opts
,
1446 gcry_ac_io_t
*io_cipher
,
1447 gcry_ac_io_t
*io_message
)
1448 /* */ _GCRY_ATTR_INTERNAL
;
1450 /* Signs the message readable from IO_MESSAGE through HANDLE with the
1451 secret key KEY according to SCHEME, FLAGS and OPTS. If OPTS is not
1452 NULL, it has to be a pointer to a structure specific to the chosen
1453 scheme (gcry_ac_ssa_*_t). The signature is written to
1455 gcry_error_t
gcry_ac_data_sign_scheme (gcry_ac_handle_t handle
,
1456 gcry_ac_scheme_t scheme
,
1457 unsigned int flags
, void *opts
,
1459 gcry_ac_io_t
*io_message
,
1460 gcry_ac_io_t
*io_signature
)
1461 /* */ _GCRY_ATTR_INTERNAL
;
1463 /* Verifies through HANDLE that the signature readable from
1464 IO_SIGNATURE is indeed the result of signing the message readable
1465 from IO_MESSAGE with the secret key belonging to the public key KEY
1466 according to SCHEME and OPTS. If OPTS is not NULL, it has to be an
1467 anonymous structure (gcry_ac_ssa_*_t) specific to the chosen
1469 gcry_error_t
gcry_ac_data_verify_scheme (gcry_ac_handle_t handle
,
1470 gcry_ac_scheme_t scheme
,
1471 unsigned int flags
, void *opts
,
1473 gcry_ac_io_t
*io_message
,
1474 gcry_ac_io_t
*io_signature
)
1475 /* */ _GCRY_ATTR_INTERNAL
;
1477 /* Store the textual representation of the algorithm whose id is given
1478 in ALGORITHM in NAME. This function is deprecated; use
1479 gcry_pk_algo_name. */
1480 gcry_error_t
gcry_ac_id_to_name (gcry_ac_id_t algorithm
,
1482 /* */ _GCRY_GCC_ATTR_DEPRECATED
;
1483 /* Store the numeric ID of the algorithm whose textual representation
1484 is contained in NAME in ALGORITHM. This function is deprecated;
1485 use gcry_pk_map_name. */
1486 gcry_error_t
gcry_ac_name_to_id (const char *name
,
1487 gcry_ac_id_t
*algorithm
)
1488 /* */ _GCRY_GCC_ATTR_DEPRECATED
;
1489 #endif /*GCRYPT_NO_DEPRECATED*/
1492 /******************************
1494 * Key Derivation Functions *
1496 ******************************/
1498 /* Algorithm IDs for the KDFs. */
1502 GCRY_KDF_SIMPLE_S2K
= 16,
1503 GCRY_KDF_SALTED_S2K
= 17,
1504 GCRY_KDF_ITERSALTED_S2K
= 19,
1505 GCRY_KDF_PBKDF1
= 33,
1506 GCRY_KDF_PBKDF2
= 34
1509 /* Derive a key from a passphrase. */
1510 gpg_error_t
gcry_kdf_derive (const void *passphrase
, size_t passphraselen
,
1511 int algo
, int subalgo
,
1512 const void *salt
, size_t saltlen
,
1513 unsigned long iterations
,
1514 size_t keysize
, void *keybuffer
);
1519 /************************************
1521 * Random Generating Functions *
1523 ************************************/
1525 /* The possible values for the random quality. The rule of thumb is
1526 to use STRONG for session keys and VERY_STRONG for key material.
1527 WEAK is usually an alias for STRONG and should not be used anymore
1528 (except with gcry_mpi_randomize); use gcry_create_nonce instead. */
1529 typedef enum gcry_random_level
1531 GCRY_WEAK_RANDOM
= 0,
1532 GCRY_STRONG_RANDOM
= 1,
1533 GCRY_VERY_STRONG_RANDOM
= 2
1535 gcry_random_level_t
;
1537 /* Fill BUFFER with LENGTH bytes of random, using random numbers of
1539 void gcry_randomize (void *buffer
, size_t length
,
1540 enum gcry_random_level level
);
1542 /* Add the external random from BUFFER with LENGTH bytes into the
1543 pool. QUALITY should either be -1 for unknown or in the range of 0
1545 gcry_error_t
gcry_random_add_bytes (const void *buffer
, size_t length
,
1548 /* If random numbers are used in an application, this macro should be
1549 called from time to time so that new stuff gets added to the
1550 internal pool of the RNG. */
1551 #define gcry_fast_random_poll() gcry_control (GCRYCTL_FAST_POLL, NULL)
1554 /* Return NBYTES of allocated random using a random numbers of quality
1556 void *gcry_random_bytes (size_t nbytes
, enum gcry_random_level level
)
1557 _GCRY_GCC_ATTR_MALLOC
;
1559 /* Return NBYTES of allocated random using a random numbers of quality
1560 LEVEL. The random numbers are created returned in "secure"
1562 void *gcry_random_bytes_secure (size_t nbytes
, enum gcry_random_level level
)
1563 _GCRY_GCC_ATTR_MALLOC
;
1566 /* Set the big integer W to a random value of NBITS using a random
1567 generator with quality LEVEL. Note that by using a level of
1568 GCRY_WEAK_RANDOM gcry_create_nonce is used internally. */
1569 void gcry_mpi_randomize (gcry_mpi_t w
,
1570 unsigned int nbits
, enum gcry_random_level level
);
1573 /* Create an unpredicable nonce of LENGTH bytes in BUFFER. */
1574 void gcry_create_nonce (void *buffer
, size_t length
);
1580 /*******************************/
1582 /* Prime Number Functions */
1584 /*******************************/
1586 /* Mode values passed to a gcry_prime_check_func_t. */
1587 #define GCRY_PRIME_CHECK_AT_FINISH 0
1588 #define GCRY_PRIME_CHECK_AT_GOT_PRIME 1
1589 #define GCRY_PRIME_CHECK_AT_MAYBE_PRIME 2
1591 /* The function should return 1 if the operation shall continue, 0 to
1592 reject the prime candidate. */
1593 typedef int (*gcry_prime_check_func_t
) (void *arg
, int mode
,
1594 gcry_mpi_t candidate
);
1596 /* Flags for gcry_prime_generate(): */
1598 /* Allocate prime numbers and factors in secure memory. */
1599 #define GCRY_PRIME_FLAG_SECRET (1 << 0)
1601 /* Make sure that at least one prime factor is of size
1603 #define GCRY_PRIME_FLAG_SPECIAL_FACTOR (1 << 1)
1605 /* Generate a new prime number of PRIME_BITS bits and store it in
1606 PRIME. If FACTOR_BITS is non-zero, one of the prime factors of
1607 (prime - 1) / 2 must be FACTOR_BITS bits long. If FACTORS is
1608 non-zero, allocate a new, NULL-terminated array holding the prime
1609 factors and store it in FACTORS. FLAGS might be used to influence
1610 the prime number generation process. */
1611 gcry_error_t
gcry_prime_generate (gcry_mpi_t
*prime
,
1612 unsigned int prime_bits
,
1613 unsigned int factor_bits
,
1614 gcry_mpi_t
**factors
,
1615 gcry_prime_check_func_t cb_func
,
1617 gcry_random_level_t random_level
,
1618 unsigned int flags
);
1620 /* Find a generator for PRIME where the factorization of (prime-1) is
1621 in the NULL terminated array FACTORS. Return the generator as a
1622 newly allocated MPI in R_G. If START_G is not NULL, use this as
1623 teh start for the search. */
1624 gcry_error_t
gcry_prime_group_generator (gcry_mpi_t
*r_g
,
1626 gcry_mpi_t
*factors
,
1627 gcry_mpi_t start_g
);
1630 /* Convenience function to release the FACTORS array. */
1631 void gcry_prime_release_factors (gcry_mpi_t
*factors
);
1634 /* Check wether the number X is prime. */
1635 gcry_error_t
gcry_prime_check (gcry_mpi_t x
, unsigned int flags
);
1639 /************************************
1641 * Miscellaneous Stuff *
1643 ************************************/
1645 /* Log levels used by the internal logging facility. */
1646 enum gcry_log_levels
1648 GCRY_LOG_CONT
= 0, /* (Continue the last log line.) */
1651 GCRY_LOG_ERROR
= 30,
1652 GCRY_LOG_FATAL
= 40,
1654 GCRY_LOG_DEBUG
= 100
1657 /* Type for progress handlers. */
1658 typedef void (*gcry_handler_progress_t
) (void *, const char *, int, int, int);
1660 /* Type for memory allocation handlers. */
1661 typedef void *(*gcry_handler_alloc_t
) (size_t n
);
1663 /* Type for secure memory check handlers. */
1664 typedef int (*gcry_handler_secure_check_t
) (const void *);
1666 /* Type for memory reallocation handlers. */
1667 typedef void *(*gcry_handler_realloc_t
) (void *p
, size_t n
);
1669 /* Type for memory free handlers. */
1670 typedef void (*gcry_handler_free_t
) (void *);
1672 /* Type for out-of-memory handlers. */
1673 typedef int (*gcry_handler_no_mem_t
) (void *, size_t, unsigned int);
1675 /* Type for fatal error handlers. */
1676 typedef void (*gcry_handler_error_t
) (void *, int, const char *);
1678 /* Type for logging handlers. */
1679 typedef void (*gcry_handler_log_t
) (void *, int, const char *, va_list);
1681 /* Certain operations can provide progress information. This function
1682 is used to register a handler for retrieving these information. */
1683 void gcry_set_progress_handler (gcry_handler_progress_t cb
, void *cb_data
);
1686 /* Register a custom memory allocation functions. */
1687 void gcry_set_allocation_handler (
1688 gcry_handler_alloc_t func_alloc
,
1689 gcry_handler_alloc_t func_alloc_secure
,
1690 gcry_handler_secure_check_t func_secure_check
,
1691 gcry_handler_realloc_t func_realloc
,
1692 gcry_handler_free_t func_free
);
1694 /* Register a function used instead of the internal out of memory
1696 void gcry_set_outofcore_handler (gcry_handler_no_mem_t h
, void *opaque
);
1698 /* Register a function used instead of the internal fatal error
1700 void gcry_set_fatalerror_handler (gcry_handler_error_t fnc
, void *opaque
);
1702 /* Register a function used instead of the internal logging
1704 void gcry_set_log_handler (gcry_handler_log_t f
, void *opaque
);
1706 /* Reserved for future use. */
1707 void gcry_set_gettext_handler (const char *(*f
)(const char*));
1709 /* Libgcrypt uses its own memory allocation. It is important to use
1710 gcry_free () to release memory allocated by libgcrypt. */
1711 void *gcry_malloc (size_t n
) _GCRY_GCC_ATTR_MALLOC
;
1712 void *gcry_calloc (size_t n
, size_t m
) _GCRY_GCC_ATTR_MALLOC
;
1713 void *gcry_malloc_secure (size_t n
) _GCRY_GCC_ATTR_MALLOC
;
1714 void *gcry_calloc_secure (size_t n
, size_t m
) _GCRY_GCC_ATTR_MALLOC
;
1715 void *gcry_realloc (void *a
, size_t n
);
1716 char *gcry_strdup (const char *string
) _GCRY_GCC_ATTR_MALLOC
;
1717 void *gcry_xmalloc (size_t n
) _GCRY_GCC_ATTR_MALLOC
;
1718 void *gcry_xcalloc (size_t n
, size_t m
) _GCRY_GCC_ATTR_MALLOC
;
1719 void *gcry_xmalloc_secure (size_t n
) _GCRY_GCC_ATTR_MALLOC
;
1720 void *gcry_xcalloc_secure (size_t n
, size_t m
) _GCRY_GCC_ATTR_MALLOC
;
1721 void *gcry_xrealloc (void *a
, size_t n
);
1722 char *gcry_xstrdup (const char * a
) _GCRY_GCC_ATTR_MALLOC
;
1723 void gcry_free (void *a
);
1725 /* Return true if A is allocated in "secure" memory. */
1726 int gcry_is_secure (const void *a
) _GCRY_GCC_ATTR_PURE
;
1728 /* Return true if Libgcrypt is in FIPS mode. */
1729 #define gcry_fips_mode_active() !!gcry_control (GCRYCTL_FIPS_MODE_P, 0)
1732 /* Include support for Libgcrypt modules. */
1733 #include <gcrypt-module.h>
1735 #if 0 /* (Keep Emacsens' auto-indent happy.) */
1741 #endif /* _GCRYPT_H */
1743 @emacs_local_vars_begin@
1744 @emacs_local_vars_read_only@
1745 @emacs_local_vars_end@