some updates
[iv.d.git] / gcrypt.d
blob5efb337e2d703d2a808ff9a8486c5fd88a2c8eab
1 /* gcrypt.h - GNU Cryptographic Library Interface -*- c -*-
2 * Copyright (C) 1998-2015 Free Software Foundation, Inc.
3 * Copyright (C) 2012-2015 g10 Code GmbH
5 * This file is part of Libgcrypt.
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
20 module iv.gcrypt /*is aliced*/;
21 pragma(lib, "gcrypt");
23 import iv.alice;
24 import iv.gpgerror;
26 import core.stdc.stdarg : va_list;
27 import core.sys.posix.sys.socket : socklen_t;
30 extern(C) nothrow @nogc:
32 alias gcry_socklen_t = socklen_t;
34 /* This is required for error code compatibility. */
35 enum _GCRY_ERR_SOURCE_DEFAULT = GPG_ERR_SOURCE_GCRYPT;
38 /* The version of this header should match the one of the library. It
39 should not be used by a program because gcry_check_version() should
40 return the same version. The purpose of this macro is to let
41 autoconf (using the AM_PATH_GCRYPT macro) check that this header
42 matches the installed library. */
43 enum GCRYPT_VERSION = "1.6.3";
45 /* The version number of this header. It may be used to handle minor
46 API incompatibilities. */
47 enum GCRYPT_VERSION_NUMBER = 0x010603;
50 /* Wrappers for the libgpg-error library. */
52 alias gcry_error_t = gpg_error_t;
53 alias gcry_err_code_t = gpg_err_code_t;
54 alias gcry_err_source_t = gpg_err_source_t;
56 /*GPG_ERR_INLINE*/ gcry_error_t
57 gcry_err_make (gcry_err_source_t source, gcry_err_code_t code)
59 return gpg_err_make (source, code);
62 /* The user can define GPG_ERR_SOURCE_DEFAULT before including this
63 file to specify a default source for gpg_error. */
64 enum GCRY_ERR_SOURCE_DEFAULT = GPG_ERR_SOURCE_USER_1;
66 /*GPG_ERR_INLINE*/ gcry_error_t
67 gcry_error (gcry_err_code_t code)
69 return gcry_err_make (GCRY_ERR_SOURCE_DEFAULT, code);
72 /*GPG_ERR_INLINE*/ gcry_err_code_t
73 gcry_err_code (gcry_error_t err)
75 return gpg_err_code (err);
79 /*GPG_ERR_INLINE*/ gcry_err_source_t
80 gcry_err_source (gcry_error_t err)
82 return gpg_err_source (err);
85 /* Return a pointer to a string containing a description of the error
86 code in the error value ERR. */
87 const(char)* gcry_strerror (gcry_error_t err);
89 /* Return a pointer to a string containing a description of the error
90 source in the error value ERR. */
91 const(char)* gcry_strsource (gcry_error_t err);
93 /* Retrieve the error code for the system error ERR. This returns
94 GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
95 this). */
96 gcry_err_code_t gcry_err_code_from_errno (int err);
98 /* Retrieve the system error for the error code CODE. This returns 0
99 if CODE is not a system error code. */
100 int gcry_err_code_to_errno (gcry_err_code_t code);
102 /* Return an error value with the error source SOURCE and the system
103 error ERR. */
104 gcry_error_t gcry_err_make_from_errno (gcry_err_source_t source, int err);
106 /* Return an error value with the system error ERR. */
107 gcry_err_code_t gcry_error_from_errno (int err);
110 /* NOTE: Since Libgcrypt 1.6 the thread callbacks are not anymore
111 used. However we keep it to allow for some source code
112 compatibility if used in the standard way. */
114 /* Constants defining the thread model to use. Used with the OPTION
115 field of the struct gcry_thread_cbs. */
116 enum {
117 GCRY_THREAD_OPTION_DEFAULT = 0,
118 GCRY_THREAD_OPTION_USER = 1,
119 GCRY_THREAD_OPTION_PTH = 2,
120 GCRY_THREAD_OPTION_PTHREAD = 3,
123 /* The version number encoded in the OPTION field of the struct
124 gcry_thread_cbs. */
125 enum GCRY_THREAD_OPTION_VERSION = 1;
127 /* Wrapper for struct ath_ops. */
128 struct gcry_thread_cbs {
129 /* The OPTION field encodes the thread model and the version number
130 of this structure.
131 Bits 7 - 0 are used for the thread model
132 Bits 15 - 8 are used for the version number. */
133 uint option;
135 alias _GCRY_ATTR_INTERNAL = gcry_thread_cbs;
137 /+TODO
138 #define GCRY_THREAD_OPTION_PTH_IMPL \
139 static struct gcry_thread_cbs gcry_threads_pth = { \
140 (GCRY_THREAD_OPTION_PTH | (GCRY_THREAD_OPTION_VERSION << 8))}
142 #define GCRY_THREAD_OPTION_PTHREAD_IMPL \
143 static struct gcry_thread_cbs gcry_threads_pthread = { \
144 (GCRY_THREAD_OPTION_PTHREAD | (GCRY_THREAD_OPTION_VERSION << 8))}
148 /* A generic context object as used by some functions. */
149 struct gcry_context {}
150 alias gcry_ctx_t = gcry_context*;
152 /* The data objects used to hold multi precision integers. */
153 struct gcry_mpi {}
154 alias gcry_mpi_t = gcry_mpi*;
155 struct gcry_mpi_point {}
156 alias gcry_mpi_point_t = gcry_mpi_point*;
159 #ifndef GCRYPT_NO_DEPRECATED
160 typedef struct gcry_mpi *GCRY_MPI _GCRY_GCC_ATTR_DEPRECATED;
161 typedef struct gcry_mpi *GcryMPI _GCRY_GCC_ATTR_DEPRECATED;
162 #endif
165 /* A structure used for scatter gather hashing. */
166 struct gcry_buffer_t {
167 usize size; /* The allocated size of the buffer or 0. */
168 usize off; /* Offset into the buffer. */
169 usize len; /* The used length of the buffer. */
170 void *data; /* The buffer. */
174 /* Check that the library fulfills the version requirement. */
175 const(char)* gcry_check_version (const(char)* req_version);
177 /* Codes for function dispatchers. */
179 /* Codes used with the gcry_control function. */
180 alias gcry_ctl_cmds = int;
181 enum {
182 /* Note: 1 .. 2 are not anymore used. */
183 GCRYCTL_CFB_SYNC = 3,
184 GCRYCTL_RESET = 4, /* e.g. for MDs */
185 GCRYCTL_FINALIZE = 5,
186 GCRYCTL_GET_KEYLEN = 6,
187 GCRYCTL_GET_BLKLEN = 7,
188 GCRYCTL_TEST_ALGO = 8,
189 GCRYCTL_IS_SECURE = 9,
190 GCRYCTL_GET_ASNOID = 10,
191 GCRYCTL_ENABLE_ALGO = 11,
192 GCRYCTL_DISABLE_ALGO = 12,
193 GCRYCTL_DUMP_RANDOM_STATS = 13,
194 GCRYCTL_DUMP_SECMEM_STATS = 14,
195 GCRYCTL_GET_ALGO_NPKEY = 15,
196 GCRYCTL_GET_ALGO_NSKEY = 16,
197 GCRYCTL_GET_ALGO_NSIGN = 17,
198 GCRYCTL_GET_ALGO_NENCR = 18,
199 GCRYCTL_SET_VERBOSITY = 19,
200 GCRYCTL_SET_DEBUG_FLAGS = 20,
201 GCRYCTL_CLEAR_DEBUG_FLAGS = 21,
202 GCRYCTL_USE_SECURE_RNDPOOL= 22,
203 GCRYCTL_DUMP_MEMORY_STATS = 23,
204 GCRYCTL_INIT_SECMEM = 24,
205 GCRYCTL_TERM_SECMEM = 25,
206 GCRYCTL_DISABLE_SECMEM_WARN = 27,
207 GCRYCTL_SUSPEND_SECMEM_WARN = 28,
208 GCRYCTL_RESUME_SECMEM_WARN = 29,
209 GCRYCTL_DROP_PRIVS = 30,
210 GCRYCTL_ENABLE_M_GUARD = 31,
211 GCRYCTL_START_DUMP = 32,
212 GCRYCTL_STOP_DUMP = 33,
213 GCRYCTL_GET_ALGO_USAGE = 34,
214 GCRYCTL_IS_ALGO_ENABLED = 35,
215 GCRYCTL_DISABLE_INTERNAL_LOCKING = 36,
216 GCRYCTL_DISABLE_SECMEM = 37,
217 GCRYCTL_INITIALIZATION_FINISHED = 38,
218 GCRYCTL_INITIALIZATION_FINISHED_P = 39,
219 GCRYCTL_ANY_INITIALIZATION_P = 40,
220 GCRYCTL_SET_CBC_CTS = 41,
221 GCRYCTL_SET_CBC_MAC = 42,
222 /* Note: 43 is not anymore used. */
223 GCRYCTL_ENABLE_QUICK_RANDOM = 44,
224 GCRYCTL_SET_RANDOM_SEED_FILE = 45,
225 GCRYCTL_UPDATE_RANDOM_SEED_FILE = 46,
226 GCRYCTL_SET_THREAD_CBS = 47,
227 GCRYCTL_FAST_POLL = 48,
228 GCRYCTL_SET_RANDOM_DAEMON_SOCKET = 49,
229 GCRYCTL_USE_RANDOM_DAEMON = 50,
230 GCRYCTL_FAKED_RANDOM_P = 51,
231 GCRYCTL_SET_RNDEGD_SOCKET = 52,
232 GCRYCTL_PRINT_CONFIG = 53,
233 GCRYCTL_OPERATIONAL_P = 54,
234 GCRYCTL_FIPS_MODE_P = 55,
235 GCRYCTL_FORCE_FIPS_MODE = 56,
236 GCRYCTL_SELFTEST = 57,
237 /* Note: 58 .. 62 are used internally. */
238 GCRYCTL_DISABLE_HWF = 63,
239 GCRYCTL_SET_ENFORCED_FIPS_FLAG = 64,
240 GCRYCTL_SET_PREFERRED_RNG_TYPE = 65,
241 GCRYCTL_GET_CURRENT_RNG_TYPE = 66,
242 GCRYCTL_DISABLE_LOCKED_SECMEM = 67,
243 GCRYCTL_DISABLE_PRIV_DROP = 68,
244 GCRYCTL_SET_CCM_LENGTHS = 69,
245 GCRYCTL_CLOSE_RANDOM_DEVICE = 70,
246 GCRYCTL_INACTIVATE_FIPS_FLAG = 71,
247 GCRYCTL_REACTIVATE_FIPS_FLAG = 72
250 /* Perform various operations defined by CMD. */
251 gcry_error_t gcry_control (gcry_ctl_cmds CMD, ...);
254 /* S-expression management. */
256 /* The object to represent an S-expression as used with the public key
257 functions. */
258 struct gcry_sexp {}
259 alias gcry_sexp_t = gcry_sexp*;
262 #ifndef GCRYPT_NO_DEPRECATED
263 typedef struct gcry_sexp *GCRY_SEXP _GCRY_GCC_ATTR_DEPRECATED;
264 typedef struct gcry_sexp *GcrySexp _GCRY_GCC_ATTR_DEPRECATED;
265 #endif
268 /* The possible values for the S-expression format. */
269 alias gcry_sexp_format = int;
270 enum {
271 GCRYSEXP_FMT_DEFAULT = 0,
272 GCRYSEXP_FMT_CANON = 1,
273 GCRYSEXP_FMT_BASE64 = 2,
274 GCRYSEXP_FMT_ADVANCED = 3
277 /* Create an new S-expression object from BUFFER of size LENGTH and
278 return it in RETSEXP. With AUTODETECT set to 0 the data in BUFFER
279 is expected to be in canonized format. */
280 gcry_error_t gcry_sexp_new (gcry_sexp_t *retsexp,
281 const(void)* buffer, usize length,
282 int autodetect);
284 /* Same as gcry_sexp_new but allows to pass a FREEFNC which has the
285 effect to transfer ownership of BUFFER to the created object. */
286 gcry_error_t gcry_sexp_create (gcry_sexp_t *retsexp,
287 void *buffer, usize length,
288 int autodetect, void function (void *) freefnc);
290 /* Scan BUFFER and return a new S-expression object in RETSEXP. This
291 function expects a printf like string in BUFFER. */
292 gcry_error_t gcry_sexp_sscan (gcry_sexp_t *retsexp, usize *erroff,
293 const(char)* buffer, usize length);
295 /* Same as gcry_sexp_sscan but expects a string in FORMAT and can thus
296 only be used for certain encodings. */
297 gcry_error_t gcry_sexp_build (gcry_sexp_t *retsexp, usize *erroff,
298 const(char)* format, ...);
300 /* Like gcry_sexp_build, but uses an array instead of variable
301 function arguments. */
302 gcry_error_t gcry_sexp_build_array (gcry_sexp_t *retsexp, usize *erroff,
303 const(char)* format, void **arg_list);
305 /* Release the S-expression object SEXP */
306 void gcry_sexp_release (gcry_sexp_t sexp);
308 /* Calculate the length of an canonized S-expresion in BUFFER and
309 check for a valid encoding. */
310 usize gcry_sexp_canon_len (const(ubyte)* buffer, usize length,
311 usize *erroff, gcry_error_t *errcode);
313 /* Copies the S-expression object SEXP into BUFFER using the format
314 specified in MODE. */
315 usize gcry_sexp_sprint (gcry_sexp_t sexp, int mode, void *buffer,
316 usize maxlength);
318 /* Dumps the S-expression object A in a format suitable for debugging
319 to Libgcrypt's logging stream. */
320 void gcry_sexp_dump (const gcry_sexp_t a);
322 gcry_sexp_t gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b);
323 gcry_sexp_t gcry_sexp_alist (const gcry_sexp_t *array);
324 gcry_sexp_t gcry_sexp_vlist (const gcry_sexp_t a, ...);
325 gcry_sexp_t gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n);
326 gcry_sexp_t gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n);
328 /* Scan the S-expression for a sublist with a type (the car of the
329 list) matching the string TOKEN. If TOKLEN is not 0, the token is
330 assumed to be raw memory of this length. The function returns a
331 newly allocated S-expression consisting of the found sublist or
332 `null' when not found. */
333 gcry_sexp_t gcry_sexp_find_token (gcry_sexp_t list,
334 const(char)* tok, usize toklen);
335 /* Return the length of the LIST. For a valid S-expression this
336 should be at least 1. */
337 int gcry_sexp_length (const gcry_sexp_t list);
339 /* Create and return a new S-expression from the element with index
340 NUMBER in LIST. Note that the first element has the index 0. If
341 there is no such element, `null' is returned. */
342 gcry_sexp_t gcry_sexp_nth (const gcry_sexp_t list, int number);
344 /* Create and return a new S-expression from the first element in
345 LIST; this called the "type" and should always exist and be a
346 string. `null' is returned in case of a problem. */
347 gcry_sexp_t gcry_sexp_car (const gcry_sexp_t list);
349 /* Create and return a new list form all elements except for the first
350 one. Note, that this function may return an invalid S-expression
351 because it is not guaranteed, that the type exists and is a string.
352 However, for parsing a complex S-expression it might be useful for
353 intermediate lists. Returns `null' on error. */
354 gcry_sexp_t gcry_sexp_cdr (const gcry_sexp_t list);
356 gcry_sexp_t gcry_sexp_cadr (const gcry_sexp_t list);
359 /* This function is used to get data from a LIST. A pointer to the
360 actual data with index NUMBER is returned and the length of this
361 data will be stored to DATALEN. If there is no data at the given
362 index or the index represents another list, `null' is returned.
363 *Note:* The returned pointer is valid as long as LIST is not
364 modified or released. */
365 const(char)* gcry_sexp_nth_data (const gcry_sexp_t list, int number,
366 usize *datalen);
368 /* This function is used to get data from a LIST. A malloced buffer to the
369 data with index NUMBER is returned and the length of this
370 data will be stored to RLENGTH. If there is no data at the given
371 index or the index represents another list, `null' is returned. */
372 void *gcry_sexp_nth_buffer (const gcry_sexp_t list, int number,
373 usize *rlength);
375 /* This function is used to get and convert data from a LIST. The
376 data is assumed to be a Nul terminated string. The caller must
377 release the returned value using `gcry_free'. If there is no data
378 at the given index, the index represents a list or the value can't
379 be converted to a string, `null' is returned. */
380 char *gcry_sexp_nth_string (gcry_sexp_t list, int number);
382 /* This function is used to get and convert data from a LIST. This
383 data is assumed to be an MPI stored in the format described by
384 MPIFMT and returned as a standard Libgcrypt MPI. The caller must
385 release this returned value using `gcry_mpi_release'. If there is
386 no data at the given index, the index represents a list or the
387 value can't be converted to an MPI, `null' is returned. */
388 gcry_mpi_t gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt);
390 /* Convenience fucntion to extract parameters from an S-expression
391 * using a list of single letter parameters. */
392 gpg_error_t gcry_sexp_extract_param (gcry_sexp_t sexp,
393 const(char)* path,
394 const(char)* list,
395 ...) /*_GCRY_GCC_ATTR_SENTINEL(0)*/;
398 /*******************************************
400 * Multi Precision Integer Functions *
402 *******************************************/
404 /* Different formats of external big integer representation. */
405 alias gcry_mpi_format = int;
406 enum {
407 GCRYMPI_FMT_NONE= 0,
408 GCRYMPI_FMT_STD = 1, /* Twos complement stored without length. */
409 GCRYMPI_FMT_PGP = 2, /* As used by OpenPGP (unsigned only). */
410 GCRYMPI_FMT_SSH = 3, /* As used by SSH (like STD but with length). */
411 GCRYMPI_FMT_HEX = 4, /* Hex format. */
412 GCRYMPI_FMT_USG = 5, /* Like STD but unsigned. */
413 GCRYMPI_FMT_OPAQUE = 8 /* Opaque format (some functions only). */
416 /* Flags used for creating big integers. */
417 alias gcry_mpi_flag = int;
418 enum {
419 GCRYMPI_FLAG_SECURE = 1, /* Allocate the number in "secure" memory. */
420 GCRYMPI_FLAG_OPAQUE = 2, /* The number is not a real one but just
421 a way to store some bytes. This is
422 useful for encrypted big integers. */
423 GCRYMPI_FLAG_IMMUTABLE = 4, /* Mark the MPI as immutable. */
424 GCRYMPI_FLAG_CONST = 8, /* Mark the MPI as a constant. */
425 GCRYMPI_FLAG_USER1 = 0x0100,/* User flag 1. */
426 GCRYMPI_FLAG_USER2 = 0x0200,/* User flag 2. */
427 GCRYMPI_FLAG_USER3 = 0x0400,/* User flag 3. */
428 GCRYMPI_FLAG_USER4 = 0x0800,/* User flag 4. */
432 /* Macros to return pre-defined MPI constants. */
434 #define GCRYMPI_CONST_ONE (_gcry_mpi_get_const (1))
435 #define GCRYMPI_CONST_TWO (_gcry_mpi_get_const (2))
436 #define GCRYMPI_CONST_THREE (_gcry_mpi_get_const (3))
437 #define GCRYMPI_CONST_FOUR (_gcry_mpi_get_const (4))
438 #define GCRYMPI_CONST_EIGHT (_gcry_mpi_get_const (8))
440 gcry_mpi_t GCRYMPI_CONST_ONE () { return _gcry_mpi_get_const(1); }
441 gcry_mpi_t GCRYMPI_CONST_TWO () { return _gcry_mpi_get_const(2); }
442 gcry_mpi_t GCRYMPI_CONST_THREE () { return _gcry_mpi_get_const(3); }
443 gcry_mpi_t GCRYMPI_CONST_FOUR () { return _gcry_mpi_get_const(4); }
444 gcry_mpi_t GCRYMPI_CONST_EIGHT () { return _gcry_mpi_get_const(8); }
447 /* Allocate a new big integer object, initialize it with 0 and
448 initially allocate memory for a number of at least NBITS. */
449 gcry_mpi_t gcry_mpi_new (uint nbits);
451 /* Same as gcry_mpi_new() but allocate in "secure" memory. */
452 gcry_mpi_t gcry_mpi_snew (uint nbits);
454 /* Release the number A and free all associated resources. */
455 void gcry_mpi_release (gcry_mpi_t a);
457 /* Create a new number with the same value as A. */
458 gcry_mpi_t gcry_mpi_copy (const gcry_mpi_t a);
460 /* Store the big integer value U in W and release U. */
461 void gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u);
463 /* Store the big integer value U in W. */
464 gcry_mpi_t gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u);
466 /* Store the unsigned integer value U in W. */
467 gcry_mpi_t gcry_mpi_set_ui (gcry_mpi_t w, /*unsigned long*/uint u);
469 /* Swap the values of A and B. */
470 void gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b);
472 /* Return 1 if A is negative; 0 if zero or positive. */
473 int gcry_mpi_is_neg (gcry_mpi_t a);
475 /* W = - U */
476 void gcry_mpi_neg (gcry_mpi_t w, gcry_mpi_t u);
478 /* W = [W] */
479 void gcry_mpi_abs (gcry_mpi_t w);
481 /* Compare the big integer number U and V returning 0 for equality, a
482 positive value for U > V and a negative for U < V. */
483 int gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v);
485 /* Compare the big integer number U with the unsigned integer V
486 returning 0 for equality, a positive value for U > V and a negative
487 for U < V. */
488 int gcry_mpi_cmp_ui (const gcry_mpi_t u, /*unsigned long*/uint v);
490 /* Convert the external representation of an integer stored in BUFFER
491 with a length of BUFLEN into a newly create MPI returned in
492 RET_MPI. If NSCANNED is not null, it will receive the number of
493 bytes actually scanned after a successful operation. */
494 gcry_error_t gcry_mpi_scan (gcry_mpi_t *ret_mpi, gcry_mpi_format format,
495 const(void)* buffer, usize buflen,
496 usize *nscanned);
498 /* Convert the big integer A into the external representation
499 described by FORMAT and store it in the provided BUFFER which has
500 been allocated by the user with a size of BUFLEN bytes. NWRITTEN
501 receives the actual length of the external representation unless it
502 has been passed as null. */
503 gcry_error_t gcry_mpi_print (gcry_mpi_format format,
504 ubyte *buffer, usize buflen,
505 usize *nwritten,
506 const gcry_mpi_t a);
508 /* Convert the big integer A int the external representation described
509 by FORMAT and store it in a newly allocated buffer which address
510 will be put into BUFFER. NWRITTEN receives the actual lengths of the
511 external representation. */
512 gcry_error_t gcry_mpi_aprint (gcry_mpi_format format,
513 ubyte **buffer, usize *nwritten,
514 const gcry_mpi_t a);
516 /* Dump the value of A in a format suitable for debugging to
517 Libgcrypt's logging stream. Note that one leading space but no
518 trailing space or linefeed will be printed. It is okay to pass
519 null for A. */
520 void gcry_mpi_dump (const gcry_mpi_t a);
523 /* W = U + V. */
524 void gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
526 /* W = U + V. V is an unsigned integer. */
527 void gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, /*unsigned long*/uint v);
529 /* W = U + V mod M. */
530 void gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
532 /* W = U - V. */
533 void gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
535 /* W = U - V. V is an unsigned integer. */
536 void gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, /*unsigned long*/uint v );
538 /* W = U - V mod M */
539 void gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
541 /* W = U * V. */
542 void gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
544 /* W = U * V. V is an unsigned integer. */
545 void gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, /*unsigned long*/uint v );
547 /* W = U * V mod M. */
548 void gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
550 /* W = U * (2 ^ CNT). */
551 void gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, /*unsigned long*/uint cnt);
553 /* Q = DIVIDEND / DIVISOR, R = DIVIDEND % DIVISOR,
554 Q or R may be passed as null. ROUND should be negative or 0. */
555 void gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r,
556 gcry_mpi_t dividend, gcry_mpi_t divisor, int round);
558 /* R = DIVIDEND % DIVISOR */
559 void gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor);
561 /* W = B ^ E mod M. */
562 void gcry_mpi_powm (gcry_mpi_t w,
563 const gcry_mpi_t b, const gcry_mpi_t e,
564 const gcry_mpi_t m);
566 /* Set G to the greatest common divisor of A and B.
567 Return true if the G is 1. */
568 int gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b);
570 /* Set X to the multiplicative inverse of A mod M.
571 Return true if the value exists. */
572 int gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m);
574 /* Create a new point object. NBITS is usually 0. */
575 gcry_mpi_point_t gcry_mpi_point_new (uint nbits);
577 /* Release the object POINT. POINT may be null. */
578 void gcry_mpi_point_release (gcry_mpi_point_t point);
580 /* Store the projective coordinates from POINT into X, Y, and Z. */
581 void gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
582 gcry_mpi_point_t point);
584 /* Store the projective coordinates from POINT into X, Y, and Z and
585 release POINT. */
586 void gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
587 gcry_mpi_point_t point);
589 /* Store the projective coordinates X, Y, and Z into POINT. */
590 gcry_mpi_point_t gcry_mpi_point_set (gcry_mpi_point_t point,
591 gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z);
593 /* Store the projective coordinates X, Y, and Z into POINT and release
594 X, Y, and Z. */
595 gcry_mpi_point_t gcry_mpi_point_snatch_set (gcry_mpi_point_t point,
596 gcry_mpi_t x, gcry_mpi_t y,
597 gcry_mpi_t z);
599 /* Allocate a new context for elliptic curve operations based on the
600 parameters given by KEYPARAM or using CURVENAME. */
601 gpg_error_t gcry_mpi_ec_new (gcry_ctx_t *r_ctx,
602 gcry_sexp_t keyparam, const(char)* curvename);
604 /* Get a named MPI from an elliptic curve context. */
605 gcry_mpi_t gcry_mpi_ec_get_mpi (const(char)* name, gcry_ctx_t ctx, int copy);
607 /* Get a named point from an elliptic curve context. */
608 gcry_mpi_point_t gcry_mpi_ec_get_point (const(char)* name,
609 gcry_ctx_t ctx, int copy);
611 /* Store a named MPI into an elliptic curve context. */
612 gpg_error_t gcry_mpi_ec_set_mpi (const(char)* name, gcry_mpi_t newvalue,
613 gcry_ctx_t ctx);
615 /* Store a named point into an elliptic curve context. */
616 gpg_error_t gcry_mpi_ec_set_point (const(char)* name, gcry_mpi_point_t newvalue,
617 gcry_ctx_t ctx);
619 /* Store the affine coordinates of POINT into X and Y. */
620 int gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point,
621 gcry_ctx_t ctx);
623 /* W = 2 * U. */
624 void gcry_mpi_ec_dup (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_ctx_t ctx);
626 /* W = U + V. */
627 void gcry_mpi_ec_add (gcry_mpi_point_t w,
628 gcry_mpi_point_t u, gcry_mpi_point_t v, gcry_ctx_t ctx);
630 /* W = N * U. */
631 void gcry_mpi_ec_mul (gcry_mpi_point_t w, gcry_mpi_t n, gcry_mpi_point_t u,
632 gcry_ctx_t ctx);
634 /* Return true if POINT is on the curve described by CTX. */
635 int gcry_mpi_ec_curve_point (gcry_mpi_point_t w, gcry_ctx_t ctx);
637 /* Return the number of bits required to represent A. */
638 uint gcry_mpi_get_nbits (gcry_mpi_t a);
640 /* Return true when bit number N (counting from 0) is set in A. */
641 int gcry_mpi_test_bit (gcry_mpi_t a, uint n);
643 /* Set bit number N in A. */
644 void gcry_mpi_set_bit (gcry_mpi_t a, uint n);
646 /* Clear bit number N in A. */
647 void gcry_mpi_clear_bit (gcry_mpi_t a, uint n);
649 /* Set bit number N in A and clear all bits greater than N. */
650 void gcry_mpi_set_highbit (gcry_mpi_t a, uint n);
652 /* Clear bit number N in A and all bits greater than N. */
653 void gcry_mpi_clear_highbit (gcry_mpi_t a, uint n);
655 /* Shift the value of A by N bits to the right and store the result in X. */
656 void gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, uint n);
658 /* Shift the value of A by N bits to the left and store the result in X. */
659 void gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, uint n);
661 /* Store NBITS of the value P points to in A and mark A as an opaque
662 value. On success A received the the ownership of the value P.
663 WARNING: Never use an opaque MPI for anything thing else than
664 gcry_mpi_release, gcry_mpi_get_opaque. */
665 gcry_mpi_t gcry_mpi_set_opaque (gcry_mpi_t a, void *p, uint nbits);
667 /* Store NBITS of the value P points to in A and mark A as an opaque
668 value. The function takes a copy of the provided value P.
669 WARNING: Never use an opaque MPI for anything thing else than
670 gcry_mpi_release, gcry_mpi_get_opaque. */
671 gcry_mpi_t gcry_mpi_set_opaque_copy (gcry_mpi_t a,
672 const(void)* p, uint nbits);
674 /* Return a pointer to an opaque value stored in A and return its size
675 in NBITS. Note that the returned pointer is still owned by A and
676 that the function should never be used for an non-opaque MPI. */
677 void *gcry_mpi_get_opaque (gcry_mpi_t a, uint *nbits);
679 /* Set the FLAG for the big integer A. Currently only the flag
680 GCRYMPI_FLAG_SECURE is allowed to convert A into an big intger
681 stored in "secure" memory. */
682 void gcry_mpi_set_flag (gcry_mpi_t a, gcry_mpi_flag flag);
684 /* Clear FLAG for the big integer A. Note that this function is
685 currently useless as no flags are allowed. */
686 void gcry_mpi_clear_flag (gcry_mpi_t a, gcry_mpi_flag flag);
688 /* Return true if the FLAG is set for A. */
689 int gcry_mpi_get_flag (gcry_mpi_t a, gcry_mpi_flag flag);
691 /* Private function - do not use. */
692 gcry_mpi_t _gcry_mpi_get_const (int no);
694 /* Unless the GCRYPT_NO_MPI_MACROS is used, provide a couple of
695 convenience macros for the big integer functions. */
697 #ifndef GCRYPT_NO_MPI_MACROS
698 #define mpi_new(n) gcry_mpi_new( (n) )
699 #define mpi_secure_new( n ) gcry_mpi_snew( (n) )
700 #define mpi_release(a) \
701 do \
703 gcry_mpi_release ((a)); \
704 (a) = null; \
706 while (0)
708 #define mpi_copy( a ) gcry_mpi_copy( (a) )
709 #define mpi_snatch( w, u) gcry_mpi_snatch( (w), (u) )
710 #define mpi_set( w, u) gcry_mpi_set( (w), (u) )
711 #define mpi_set_ui( w, u) gcry_mpi_set_ui( (w), (u) )
712 #define mpi_abs( w ) gcry_mpi_abs( (w) )
713 #define mpi_neg( w, u) gcry_mpi_neg( (w), (u) )
714 #define mpi_cmp( u, v ) gcry_mpi_cmp( (u), (v) )
715 #define mpi_cmp_ui( u, v ) gcry_mpi_cmp_ui( (u), (v) )
716 #define mpi_is_neg( a ) gcry_mpi_is_neg ((a))
718 #define mpi_add_ui(w,u,v) gcry_mpi_add_ui((w),(u),(v))
719 #define mpi_add(w,u,v) gcry_mpi_add ((w),(u),(v))
720 #define mpi_addm(w,u,v,m) gcry_mpi_addm ((w),(u),(v),(m))
721 #define mpi_sub_ui(w,u,v) gcry_mpi_sub_ui ((w),(u),(v))
722 #define mpi_sub(w,u,v) gcry_mpi_sub ((w),(u),(v))
723 #define mpi_subm(w,u,v,m) gcry_mpi_subm ((w),(u),(v),(m))
724 #define mpi_mul_ui(w,u,v) gcry_mpi_mul_ui ((w),(u),(v))
725 #define mpi_mul_2exp(w,u,v) gcry_mpi_mul_2exp ((w),(u),(v))
726 #define mpi_mul(w,u,v) gcry_mpi_mul ((w),(u),(v))
727 #define mpi_mulm(w,u,v,m) gcry_mpi_mulm ((w),(u),(v),(m))
728 #define mpi_powm(w,b,e,m) gcry_mpi_powm ( (w), (b), (e), (m) )
729 #define mpi_tdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), 0)
730 #define mpi_fdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), -1)
731 #define mpi_mod(r,a,m) gcry_mpi_mod ((r), (a), (m))
732 #define mpi_gcd(g,a,b) gcry_mpi_gcd ( (g), (a), (b) )
733 #define mpi_invm(g,a,b) gcry_mpi_invm ( (g), (a), (b) )
735 #define mpi_point_new(n) gcry_mpi_point_new((n))
736 #define mpi_point_release(p) \
737 do \
739 gcry_mpi_point_release ((p)); \
740 (p) = null; \
742 while (0)
743 #define mpi_point_get(x,y,z,p) gcry_mpi_point_get((x),(y),(z),(p))
744 #define mpi_point_snatch_get(x,y,z,p) gcry_mpi_point_snatch_get((x),(y),(z),(p))
745 #define mpi_point_set(p,x,y,z) gcry_mpi_point_set((p),(x),(y),(z))
746 #define mpi_point_snatch_set(p,x,y,z) gcry_mpi_point_snatch_set((p),(x),(y),(z))
748 #define mpi_get_nbits(a) gcry_mpi_get_nbits ((a))
749 #define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b))
750 #define mpi_set_bit(a,b) gcry_mpi_set_bit ((a),(b))
751 #define mpi_set_highbit(a,b) gcry_mpi_set_highbit ((a),(b))
752 #define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b))
753 #define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b))
754 #define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c))
755 #define mpi_lshift(a,b,c) gcry_mpi_lshift ((a),(b),(c))
757 #define mpi_set_opaque(a,b,c) gcry_mpi_set_opaque( (a), (b), (c) )
758 #define mpi_get_opaque(a,b) gcry_mpi_get_opaque( (a), (b) )
759 #endif /* GCRYPT_NO_MPI_MACROS */
763 /************************************
765 * Symmetric Cipher Functions *
767 ************************************/
769 /* The data object used to hold a handle to an encryption object. */
770 struct gcry_cipher_handle {}
771 alias gcry_cipher_hd_t = gcry_cipher_handle*;
774 #ifndef GCRYPT_NO_DEPRECATED
775 typedef struct gcry_cipher_handle *GCRY_CIPHER_HD _GCRY_GCC_ATTR_DEPRECATED;
776 typedef struct gcry_cipher_handle *GcryCipherHd _GCRY_GCC_ATTR_DEPRECATED;
777 #endif
780 /* All symmetric encryption algorithms are identified by their IDs.
781 More IDs may be registered at runtime. */
782 alias gcry_cipher_algos = int;
783 enum {
784 GCRY_CIPHER_NONE = 0,
785 GCRY_CIPHER_IDEA = 1,
786 GCRY_CIPHER_3DES = 2,
787 GCRY_CIPHER_CAST5 = 3,
788 GCRY_CIPHER_BLOWFISH = 4,
789 GCRY_CIPHER_SAFER_SK128 = 5,
790 GCRY_CIPHER_DES_SK = 6,
791 GCRY_CIPHER_AES = 7,
792 GCRY_CIPHER_AES192 = 8,
793 GCRY_CIPHER_AES256 = 9,
794 GCRY_CIPHER_TWOFISH = 10,
796 /* Other cipher numbers are above 300 for OpenPGP reasons. */
797 GCRY_CIPHER_ARCFOUR = 301, /* Fully compatible with RSA's RC4 (tm). */
798 GCRY_CIPHER_DES = 302, /* Yes, this is single key 56 bit DES. */
799 GCRY_CIPHER_TWOFISH128 = 303,
800 GCRY_CIPHER_SERPENT128 = 304,
801 GCRY_CIPHER_SERPENT192 = 305,
802 GCRY_CIPHER_SERPENT256 = 306,
803 GCRY_CIPHER_RFC2268_40 = 307, /* Ron's Cipher 2 (40 bit). */
804 GCRY_CIPHER_RFC2268_128 = 308, /* Ron's Cipher 2 (128 bit). */
805 GCRY_CIPHER_SEED = 309, /* 128 bit cipher described in RFC4269. */
806 GCRY_CIPHER_CAMELLIA128 = 310,
807 GCRY_CIPHER_CAMELLIA192 = 311,
808 GCRY_CIPHER_CAMELLIA256 = 312,
809 GCRY_CIPHER_SALSA20 = 313,
810 GCRY_CIPHER_SALSA20R12 = 314,
811 GCRY_CIPHER_GOST28147 = 315
814 /* The Rijndael algorithm is basically AES, so provide some macros. */
815 enum GCRY_CIPHER_AES128 = GCRY_CIPHER_AES;
816 enum GCRY_CIPHER_RIJNDAEL = GCRY_CIPHER_AES;
817 enum GCRY_CIPHER_RIJNDAEL128 = GCRY_CIPHER_AES128;
818 enum GCRY_CIPHER_RIJNDAEL192 = GCRY_CIPHER_AES192;
819 enum GCRY_CIPHER_RIJNDAEL256 = GCRY_CIPHER_AES256;
821 /* The supported encryption modes. Note that not all of them are
822 supported for each algorithm. */
823 alias gcry_cipher_modes = int;
824 enum {
825 GCRY_CIPHER_MODE_NONE = 0, /* Not yet specified. */
826 GCRY_CIPHER_MODE_ECB = 1, /* Electronic codebook. */
827 GCRY_CIPHER_MODE_CFB = 2, /* Cipher feedback. */
828 GCRY_CIPHER_MODE_CBC = 3, /* Cipher block chaining. */
829 GCRY_CIPHER_MODE_STREAM = 4, /* Used with stream ciphers. */
830 GCRY_CIPHER_MODE_OFB = 5, /* Outer feedback. */
831 GCRY_CIPHER_MODE_CTR = 6, /* Counter. */
832 GCRY_CIPHER_MODE_AESWRAP= 7, /* AES-WRAP algorithm. */
833 GCRY_CIPHER_MODE_CCM = 8, /* Counter with CBC-MAC. */
834 GCRY_CIPHER_MODE_GCM = 9 /* Galois Counter Mode. */
837 /* Flags used with the open function. */
838 alias gcry_cipher_flags = int;
839 enum {
840 GCRY_CIPHER_SECURE = 1, /* Allocate in secure memory. */
841 GCRY_CIPHER_ENABLE_SYNC = 2, /* Enable CFB sync mode. */
842 GCRY_CIPHER_CBC_CTS = 4, /* Enable CBC cipher text stealing (CTS). */
843 GCRY_CIPHER_CBC_MAC = 8 /* Enable CBC message auth. code (MAC). */
846 /* GCM works only with blocks of 128 bits */
847 enum GCRY_GCM_BLOCK_LEN = (128 / 8);
849 /* CCM works only with blocks of 128 bits. */
850 enum GCRY_CCM_BLOCK_LEN = (128 / 8);
852 /* Create a handle for algorithm ALGO to be used in MODE. FLAGS may
853 be given as an bitwise OR of the gcry_cipher_flags values. */
854 gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *handle,
855 int algo, int mode, uint flags);
857 /* Close the cioher handle H and release all resource. */
858 void gcry_cipher_close (gcry_cipher_hd_t h);
860 /* Perform various operations on the cipher object H. */
861 gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer,
862 usize buflen);
864 /* Retrieve various information about the cipher object H. */
865 gcry_error_t gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer,
866 usize *nbytes);
868 /* Retrieve various information about the cipher algorithm ALGO. */
869 gcry_error_t gcry_cipher_algo_info (int algo, int what, void *buffer,
870 usize *nbytes);
872 /* Map the cipher algorithm whose ID is contained in ALGORITHM to a
873 string representation of the algorithm name. For unknown algorithm
874 IDs this function returns "?". */
875 const(char)* gcry_cipher_algo_name (int algorithm) /*_GCRY_GCC_ATTR_PURE*/;
877 /* Map the algorithm name NAME to an cipher algorithm ID. Return 0 if
878 the algorithm name is not known. */
879 int gcry_cipher_map_name (const(char)* name) /*_GCRY_GCC_ATTR_PURE*/;
881 /* Given an ASN.1 object identifier in standard IETF dotted decimal
882 format in STRING, return the encryption mode associated with that
883 OID or 0 if not known or applicable. */
884 int gcry_cipher_mode_from_oid (const(char)* string) /*_GCRY_GCC_ATTR_PURE*/;
886 /* Encrypt the plaintext of size INLEN in IN using the cipher handle H
887 into the buffer OUT which has an allocated length of OUTSIZE. For
888 most algorithms it is possible to pass null for in and 0 for INLEN
889 and do a in-place decryption of the data provided in OUT. */
890 gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t h,
891 void *out_, usize outsize,
892 const(void)* in_, usize inlen);
894 /* The counterpart to gcry_cipher_encrypt. */
895 gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t h,
896 void *out_, usize outsize,
897 const(void)* in_, usize inlen);
899 /* Set KEY of length KEYLEN bytes for the cipher handle HD. */
900 gcry_error_t gcry_cipher_setkey (gcry_cipher_hd_t hd,
901 const(void)* key, usize keylen);
904 /* Set initialization vector IV of length IVLEN for the cipher handle HD. */
905 gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t hd,
906 const(void)* iv, usize ivlen);
908 /* Provide additional authentication data for AEAD modes/ciphers. */
909 gcry_error_t gcry_cipher_authenticate (gcry_cipher_hd_t hd, const(void)* abuf,
910 usize abuflen);
912 /* Get authentication tag for AEAD modes/ciphers. */
913 gcry_error_t gcry_cipher_gettag (gcry_cipher_hd_t hd, void *outtag,
914 usize taglen);
916 /* Check authentication tag for AEAD modes/ciphers. */
917 gcry_error_t gcry_cipher_checktag (gcry_cipher_hd_t hd, const(void)* intag,
918 usize taglen);
920 /* Reset the handle to the state after open. */
921 auto gcry_cipher_reset (gcry_cipher_hd_t h) { return gcry_cipher_ctl(h, GCRYCTL_RESET, null, 0); }
923 /* Perform the OpenPGP sync operation if this is enabled for the
924 cipher handle H. */
925 auto gcry_cipher_sync (gcry_cipher_hd_t h) { return gcry_cipher_ctl(h, GCRYCTL_CFB_SYNC, null, 0); }
927 /* Enable or disable CTS in future calls to gcry_encrypt(). CBC mode only. */
928 auto gcry_cipher_cts (gcry_cipher_hd_t h, int on) { return gcry_cipher_ctl(h, GCRYCTL_SET_CBC_CTS, null, on); }
930 /* Set counter for CTR mode. (CTR,CTRLEN) must denote a buffer of
931 block size length, or (null,0) to set the CTR to the all-zero block. */
932 gpg_error_t gcry_cipher_setctr (gcry_cipher_hd_t hd,
933 const(void)* ctr, usize ctrlen);
935 /* Retrieve the key length in bytes used with algorithm A. */
936 usize gcry_cipher_get_algo_keylen (int algo);
938 /* Retrieve the block length in bytes used with algorithm A. */
939 usize gcry_cipher_get_algo_blklen (int algo);
941 /* Return 0 if the algorithm A is available for use. */
942 auto gcry_cipher_test_algo (int a) { return gcry_cipher_algo_info(a, GCRYCTL_TEST_ALGO, null, null); }
945 /************************************
947 * Asymmetric Cipher Functions *
949 ************************************/
951 /* The algorithms and their IDs we support. */
952 alias gcry_pk_algos = int;
953 enum {
954 GCRY_PK_RSA = 1, /* RSA */
955 GCRY_PK_RSA_E = 2, /* (deprecated: use 1). */
956 GCRY_PK_RSA_S = 3, /* (deprecated: use 1). */
957 GCRY_PK_ELG_E = 16, /* (deprecated: use 20). */
958 GCRY_PK_DSA = 17, /* Digital Signature Algorithm. */
959 GCRY_PK_ECC = 18, /* Generic ECC. */
960 GCRY_PK_ELG = 20, /* Elgamal */
961 GCRY_PK_ECDSA = 301, /* (deprecated: use 18). */
962 GCRY_PK_ECDH = 302 /* (deprecated: use 18). */
965 /* Flags describing usage capabilities of a PK algorithm. */
966 enum {
967 GCRY_PK_USAGE_SIGN = 1, /* Good for signatures. */
968 GCRY_PK_USAGE_ENCR = 2, /* Good for encryption. */
969 GCRY_PK_USAGE_CERT = 4, /* Good to certify other keys. */
970 GCRY_PK_USAGE_AUTH = 8, /* Good for authentication. */
971 GCRY_PK_USAGE_UNKN = 128, /* Unknown usage flag. */
974 /* Modes used with gcry_pubkey_get_sexp. */
975 enum {
976 GCRY_PK_GET_PUBKEY = 1,
977 GCRY_PK_GET_SECKEY = 2,
980 /* Encrypt the DATA using the public key PKEY and store the result as
981 a newly created S-expression at RESULT. */
982 gcry_error_t gcry_pk_encrypt (gcry_sexp_t *result,
983 gcry_sexp_t data, gcry_sexp_t pkey);
985 /* Decrypt the DATA using the private key SKEY and store the result as
986 a newly created S-expression at RESULT. */
987 gcry_error_t gcry_pk_decrypt (gcry_sexp_t *result,
988 gcry_sexp_t data, gcry_sexp_t skey);
990 /* Sign the DATA using the private key SKEY and store the result as
991 a newly created S-expression at RESULT. */
992 gcry_error_t gcry_pk_sign (gcry_sexp_t *result,
993 gcry_sexp_t data, gcry_sexp_t skey);
995 /* Check the signature SIGVAL on DATA using the public key PKEY. */
996 gcry_error_t gcry_pk_verify (gcry_sexp_t sigval,
997 gcry_sexp_t data, gcry_sexp_t pkey);
999 /* Check that private KEY is sane. */
1000 gcry_error_t gcry_pk_testkey (gcry_sexp_t key);
1002 /* Generate a new key pair according to the parameters given in
1003 S_PARMS. The new key pair is returned in as an S-expression in
1004 R_KEY. */
1005 gcry_error_t gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms);
1007 /* Catch all function for miscellaneous operations. */
1008 gcry_error_t gcry_pk_ctl (int cmd, void *buffer, usize buflen);
1010 /* Retrieve information about the public key algorithm ALGO. */
1011 gcry_error_t gcry_pk_algo_info (int algo, int what,
1012 void *buffer, usize *nbytes);
1014 /* Map the public key algorithm whose ID is contained in ALGORITHM to
1015 a string representation of the algorithm name. For unknown
1016 algorithm IDs this functions returns "?". */
1017 const(char)* gcry_pk_algo_name (int algorithm) /*_GCRY_GCC_ATTR_PURE*/;
1019 /* Map the algorithm NAME to a public key algorithm Id. Return 0 if
1020 the algorithm name is not known. */
1021 int gcry_pk_map_name (const(char)* name) /*_GCRY_GCC_ATTR_PURE*/;
1023 /* Return what is commonly referred as the key length for the given
1024 public or private KEY. */
1025 uint gcry_pk_get_nbits (gcry_sexp_t key) /*_GCRY_GCC_ATTR_PURE*/;
1027 /* Return the so called KEYGRIP which is the SHA-1 hash of the public
1028 key parameters expressed in a way depending on the algorithm. */
1029 ubyte *gcry_pk_get_keygrip (gcry_sexp_t key, ubyte *array);
1031 /* Return the name of the curve matching KEY. */
1032 const(char)* gcry_pk_get_curve (gcry_sexp_t key, int iterator,
1033 uint *r_nbits);
1035 /* Return an S-expression with the parameters of the named ECC curve
1036 NAME. ALGO must be set to an ECC algorithm. */
1037 gcry_sexp_t gcry_pk_get_param (int algo, const(char)* name);
1039 /* Return 0 if the public key algorithm A is available for use. */
1040 auto gcry_pk_test_algo (int a) { return gcry_pk_algo_info(a, GCRYCTL_TEST_ALGO, null, null); }
1042 /* Return an S-expression representing the context CTX. */
1043 gcry_error_t gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp,
1044 int mode, gcry_ctx_t ctx);
1048 /************************************
1050 * Cryptograhic Hash Functions *
1052 ************************************/
1054 /* Algorithm IDs for the hash functions we know about. Not all of them
1055 are implemnted. */
1056 alias gcry_md_algos = int;
1057 enum {
1058 GCRY_MD_NONE = 0,
1059 GCRY_MD_MD5 = 1,
1060 GCRY_MD_SHA1 = 2,
1061 GCRY_MD_RMD160 = 3,
1062 GCRY_MD_MD2 = 5,
1063 GCRY_MD_TIGER = 6, /* TIGER/192 as used by gpg <= 1.3.2. */
1064 GCRY_MD_HAVAL = 7, /* HAVAL, 5 pass, 160 bit. */
1065 GCRY_MD_SHA256 = 8,
1066 GCRY_MD_SHA384 = 9,
1067 GCRY_MD_SHA512 = 10,
1068 GCRY_MD_SHA224 = 11,
1069 GCRY_MD_MD4 = 301,
1070 GCRY_MD_CRC32 = 302,
1071 GCRY_MD_CRC32_RFC1510 = 303,
1072 GCRY_MD_CRC24_RFC2440 = 304,
1073 GCRY_MD_WHIRLPOOL = 305,
1074 GCRY_MD_TIGER1 = 306, /* TIGER fixed. */
1075 GCRY_MD_TIGER2 = 307, /* TIGER2 variant. */
1076 GCRY_MD_GOSTR3411_94 = 308, /* GOST R 34.11-94. */
1077 GCRY_MD_STRIBOG256 = 309, /* GOST R 34.11-2012, 256 bit. */
1078 GCRY_MD_STRIBOG512 = 310 /* GOST R 34.11-2012, 512 bit. */
1081 /* Flags used with the open function. */
1082 alias gcry_md_flags = int;
1083 enum {
1084 GCRY_MD_FLAG_SECURE = 1, /* Allocate all buffers in "secure" memory. */
1085 GCRY_MD_FLAG_HMAC = 2, /* Make an HMAC out of this algorithm. */
1086 GCRY_MD_FLAG_BUGEMU1 = 0x0100
1089 /* (Forward declaration.) */
1090 struct gcry_md_context;
1092 /* This object is used to hold a handle to a message digest object.
1093 This structure is private - only to be used by the public gcry_md_*
1094 macros. */
1095 struct gcry_md_handle {
1096 /* Actual context. */
1097 gcry_md_context* ctx;
1099 /* Buffer management. */
1100 int bufpos;
1101 int bufsize;
1102 ubyte[1] buf;
1104 alias gcry_md_hd_t = gcry_md_handle*;
1106 /* Compatibility types, do not use them. */
1108 #ifndef GCRYPT_NO_DEPRECATED
1109 typedef struct gcry_md_handle *GCRY_MD_HD _GCRY_GCC_ATTR_DEPRECATED;
1110 typedef struct gcry_md_handle *GcryMDHd _GCRY_GCC_ATTR_DEPRECATED;
1111 #endif
1114 /* Create a message digest object for algorithm ALGO. FLAGS may be
1115 given as an bitwise OR of the gcry_md_flags values. ALGO may be
1116 given as 0 if the algorithms to be used are later set using
1117 gcry_md_enable. */
1118 gcry_error_t gcry_md_open (gcry_md_hd_t *h, int algo, uint flags);
1120 /* Release the message digest object HD. */
1121 void gcry_md_close (gcry_md_hd_t hd);
1123 /* Add the message digest algorithm ALGO to the digest object HD. */
1124 gcry_error_t gcry_md_enable (gcry_md_hd_t hd, int algo);
1126 /* Create a new digest object as an exact copy of the object HD. */
1127 gcry_error_t gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd);
1129 /* Reset the digest object HD to its initial state. */
1130 void gcry_md_reset (gcry_md_hd_t hd);
1132 /* Perform various operations on the digest object HD. */
1133 gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd,
1134 void *buffer, usize buflen);
1136 /* Pass LENGTH bytes of data in BUFFER to the digest object HD so that
1137 it can update the digest values. This is the actual hash
1138 function. */
1139 void gcry_md_write (gcry_md_hd_t hd, const(void)* buffer, usize length);
1141 /* Read out the final digest from HD return the digest value for
1142 algorithm ALGO. */
1143 ubyte *gcry_md_read (gcry_md_hd_t hd, int algo);
1145 /* Convenience function to calculate the hash from the data in BUFFER
1146 of size LENGTH using the algorithm ALGO avoiding the creating of a
1147 hash object. The hash is returned in the caller provided buffer
1148 DIGEST which must be large enough to hold the digest of the given
1149 algorithm. */
1150 void gcry_md_hash_buffer (int algo, void *digest,
1151 const(void)* buffer, usize length);
1153 /* Convenience function to hash multiple buffers. */
1154 gpg_error_t gcry_md_hash_buffers (int algo, uint flags, void *digest,
1155 const gcry_buffer_t *iov, int iovcnt);
1157 /* Retrieve the algorithm used with HD. This does not work reliable
1158 if more than one algorithm is enabled in HD. */
1159 int gcry_md_get_algo (gcry_md_hd_t hd);
1161 /* Retrieve the length in bytes of the digest yielded by algorithm
1162 ALGO. */
1163 uint gcry_md_get_algo_dlen (int algo);
1165 /* Return true if the the algorithm ALGO is enabled in the digest
1166 object A. */
1167 int gcry_md_is_enabled (gcry_md_hd_t a, int algo);
1169 /* Return true if the digest object A is allocated in "secure" memory. */
1170 int gcry_md_is_secure (gcry_md_hd_t a);
1172 /* Retrieve various information about the object H. */
1173 gcry_error_t gcry_md_info (gcry_md_hd_t h, int what, void *buffer,
1174 usize *nbytes);
1176 /* Retrieve various information about the algorithm ALGO. */
1177 gcry_error_t gcry_md_algo_info (int algo, int what, void *buffer,
1178 usize *nbytes);
1180 /* Map the digest algorithm id ALGO to a string representation of the
1181 algorithm name. For unknown algorithms this function returns
1182 "?". */
1183 const(char)* gcry_md_algo_name (int algo) /*_GCRY_GCC_ATTR_PURE*/;
1185 /* Map the algorithm NAME to a digest algorithm Id. Return 0 if
1186 the algorithm name is not known. */
1187 int gcry_md_map_name (const(char)* name) /*_GCRY_GCC_ATTR_PURE*/;
1189 /* For use with the HMAC feature, the set MAC key to the KEY of
1190 KEYLEN bytes. */
1191 gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, const(void)* key, usize keylen);
1193 /* Start or stop debugging for digest handle HD; i.e. create a file
1194 named dbgmd-<n>.<suffix> while hashing. If SUFFIX is null,
1195 debugging stops and the file will be closed. */
1196 void gcry_md_debug (gcry_md_hd_t hd, const(char)* suffix);
1199 /* Update the hash(s) of H with the character C. This is a buffered
1200 version of the gcry_md_write function. */
1202 #define gcry_md_putc(h,c) \
1203 do { \
1204 gcry_md_hd_t h__ = (h); \
1205 if( (h__)->bufpos == (h__)->bufsize ) \
1206 gcry_md_write( (h__), null, 0 ); \
1207 (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \
1208 } while(0)
1210 /* Finalize the digest calculation. This is not really needed because
1211 gcry_md_read() does this implicitly. */
1212 #define gcry_md_final(a) \
1213 gcry_md_ctl ((a), GCRYCTL_FINALIZE, null, 0)
1215 /* Return 0 if the algorithm A is available for use. */
1216 #define gcry_md_test_algo(a) \
1217 gcry_md_algo_info( (a), GCRYCTL_TEST_ALGO, null, null )
1219 /* Return an DER encoded ASN.1 OID for the algorithm A in buffer B. N
1220 must point to usize variable with the available size of buffer B.
1221 After return it will receive the actual size of the returned
1222 OID. */
1223 #define gcry_md_get_asnoid(a,b,n) \
1224 gcry_md_algo_info((a), GCRYCTL_GET_ASNOID, (b), (n))
1228 /**********************************************
1230 * Message Authentication Code Functions *
1232 **********************************************/
1234 /* The data object used to hold a handle to an encryption object. */
1235 struct gcry_mac_handle {}
1236 alias gcry_mac_hd_t = gcry_mac_handle*;
1238 /* Algorithm IDs for the hash functions we know about. Not all of them
1239 are implemented. */
1240 alias gcry_mac_algos = int;
1241 enum {
1242 GCRY_MAC_NONE = 0,
1244 GCRY_MAC_HMAC_SHA256 = 101,
1245 GCRY_MAC_HMAC_SHA224 = 102,
1246 GCRY_MAC_HMAC_SHA512 = 103,
1247 GCRY_MAC_HMAC_SHA384 = 104,
1248 GCRY_MAC_HMAC_SHA1 = 105,
1249 GCRY_MAC_HMAC_MD5 = 106,
1250 GCRY_MAC_HMAC_MD4 = 107,
1251 GCRY_MAC_HMAC_RMD160 = 108,
1252 GCRY_MAC_HMAC_TIGER1 = 109, /* The fixed TIGER variant */
1253 GCRY_MAC_HMAC_WHIRLPOOL = 110,
1254 GCRY_MAC_HMAC_GOSTR3411_94 = 111,
1255 GCRY_MAC_HMAC_STRIBOG256 = 112,
1256 GCRY_MAC_HMAC_STRIBOG512 = 113,
1258 GCRY_MAC_CMAC_AES = 201,
1259 GCRY_MAC_CMAC_3DES = 202,
1260 GCRY_MAC_CMAC_CAMELLIA = 203,
1261 GCRY_MAC_CMAC_CAST5 = 204,
1262 GCRY_MAC_CMAC_BLOWFISH = 205,
1263 GCRY_MAC_CMAC_TWOFISH = 206,
1264 GCRY_MAC_CMAC_SERPENT = 207,
1265 GCRY_MAC_CMAC_SEED = 208,
1266 GCRY_MAC_CMAC_RFC2268 = 209,
1267 GCRY_MAC_CMAC_IDEA = 210,
1268 GCRY_MAC_CMAC_GOST28147 = 211,
1270 GCRY_MAC_GMAC_AES = 401,
1271 GCRY_MAC_GMAC_CAMELLIA = 402,
1272 GCRY_MAC_GMAC_TWOFISH = 403,
1273 GCRY_MAC_GMAC_SERPENT = 404,
1274 GCRY_MAC_GMAC_SEED = 405
1277 /* Flags used with the open function. */
1278 alias gcry_mac_flags = int;
1279 enum {
1280 GCRY_MAC_FLAG_SECURE = 1, /* Allocate all buffers in "secure" memory. */
1283 /* Create a MAC handle for algorithm ALGO. FLAGS may be given as an bitwise OR
1284 of the gcry_mac_flags values. CTX maybe null or gcry_ctx_t object to be
1285 associated with HANDLE. */
1286 gcry_error_t gcry_mac_open (gcry_mac_hd_t *handle, int algo,
1287 uint flags, gcry_ctx_t ctx);
1289 /* Close the MAC handle H and release all resource. */
1290 void gcry_mac_close (gcry_mac_hd_t h);
1292 /* Perform various operations on the MAC object H. */
1293 gcry_error_t gcry_mac_ctl (gcry_mac_hd_t h, int cmd, void *buffer,
1294 usize buflen);
1296 /* Retrieve various information about the MAC algorithm ALGO. */
1297 gcry_error_t gcry_mac_algo_info (int algo, int what, void *buffer,
1298 usize *nbytes);
1300 /* Set KEY of length KEYLEN bytes for the MAC handle HD. */
1301 gcry_error_t gcry_mac_setkey (gcry_mac_hd_t hd, const(void)* key,
1302 usize keylen);
1304 /* Set initialization vector IV of length IVLEN for the MAC handle HD. */
1305 gcry_error_t gcry_mac_setiv (gcry_mac_hd_t hd, const(void)* iv,
1306 usize ivlen);
1308 /* Pass LENGTH bytes of data in BUFFER to the MAC object HD so that
1309 it can update the MAC values. */
1310 gcry_error_t gcry_mac_write (gcry_mac_hd_t hd, const(void)* buffer,
1311 usize length);
1313 /* Read out the final authentication code from the MAC object HD to BUFFER. */
1314 gcry_error_t gcry_mac_read (gcry_mac_hd_t hd, void *buffer, usize *buflen);
1316 /* Verify the final authentication code from the MAC object HD with BUFFER. */
1317 gcry_error_t gcry_mac_verify (gcry_mac_hd_t hd, const(void)* buffer,
1318 usize buflen);
1320 /* Retrieve the length in bytes of the MAC yielded by algorithm ALGO. */
1321 uint gcry_mac_get_algo_maclen (int algo);
1323 /* Retrieve the default key length in bytes used with algorithm A. */
1324 uint gcry_mac_get_algo_keylen (int algo);
1326 /* Map the MAC algorithm whose ID is contained in ALGORITHM to a
1327 string representation of the algorithm name. For unknown algorithm
1328 IDs this function returns "?". */
1329 const(char)* gcry_mac_algo_name (int algorithm) /*_GCRY_GCC_ATTR_PURE*/;
1331 /* Map the algorithm name NAME to an MAC algorithm ID. Return 0 if
1332 the algorithm name is not known. */
1333 int gcry_mac_map_name (const(char)* name) /*_GCRY_GCC_ATTR_PURE*/;
1335 /* Reset the handle to the state after open/setkey. */
1336 auto gcry_mac_reset(gcry_mac_hd_t h) { return gcry_mac_ctl(h, GCRYCTL_RESET, null, 0); }
1338 /* Return 0 if the algorithm A is available for use. */
1339 auto gcry_mac_test_algo (int a) { return gcry_mac_algo_info(a, GCRYCTL_TEST_ALGO, null, null); }
1342 /******************************
1344 * Key Derivation Functions *
1346 ******************************/
1348 /* Algorithm IDs for the KDFs. */
1349 alias gcry_kdf_algos = int;
1350 enum {
1351 GCRY_KDF_NONE = 0,
1352 GCRY_KDF_SIMPLE_S2K = 16,
1353 GCRY_KDF_SALTED_S2K = 17,
1354 GCRY_KDF_ITERSALTED_S2K = 19,
1355 GCRY_KDF_PBKDF1 = 33,
1356 GCRY_KDF_PBKDF2 = 34,
1357 GCRY_KDF_SCRYPT = 48
1360 /* Derive a key from a passphrase. */
1361 gpg_error_t gcry_kdf_derive (const(void)* passphrase, usize passphraselen,
1362 int algo, int subalgo,
1363 const(void)* salt, usize saltlen,
1364 /*unsigned long*/uint iterations,
1365 usize keysize, void *keybuffer);
1370 /************************************
1372 * Random Generating Functions *
1374 ************************************/
1376 /* The type of the random number generator. */
1377 alias gcry_rng_types = int;
1378 enum {
1379 GCRY_RNG_TYPE_STANDARD = 1, /* The default CSPRNG generator. */
1380 GCRY_RNG_TYPE_FIPS = 2, /* The FIPS X9.31 AES generator. */
1381 GCRY_RNG_TYPE_SYSTEM = 3 /* The system's native generator. */
1384 /* The possible values for the random quality. The rule of thumb is
1385 to use STRONG for session keys and VERY_STRONG for key material.
1386 WEAK is usually an alias for STRONG and should not be used anymore
1387 (except with gcry_mpi_randomize); use gcry_create_nonce instead. */
1388 alias gcry_random_level = int;
1389 alias gcry_random_level_t = gcry_random_level;
1390 enum {
1391 GCRY_WEAK_RANDOM = 0,
1392 GCRY_STRONG_RANDOM = 1,
1393 GCRY_VERY_STRONG_RANDOM = 2
1396 /* Fill BUFFER with LENGTH bytes of random, using random numbers of
1397 quality LEVEL. */
1398 void gcry_randomize (void *buffer, usize length,
1399 gcry_random_level level);
1401 /* Add the external random from BUFFER with LENGTH bytes into the
1402 pool. QUALITY should either be -1 for unknown or in the range of 0
1403 to 100 */
1404 gcry_error_t gcry_random_add_bytes (const(void)* buffer, usize length,
1405 int quality);
1407 /* If random numbers are used in an application, this macro should be
1408 called from time to time so that new stuff gets added to the
1409 internal pool of the RNG. */
1410 auto gcry_fast_random_poll () { return gcry_control(GCRYCTL_FAST_POLL, null); }
1413 /* Return NBYTES of allocated random using a random numbers of quality
1414 LEVEL. */
1415 void *gcry_random_bytes (usize nbytes, gcry_random_level level)
1416 /*_GCRY_GCC_ATTR_MALLOC*/;
1418 /* Return NBYTES of allocated random using a random numbers of quality
1419 LEVEL. The random numbers are created returned in "secure"
1420 memory. */
1421 void *gcry_random_bytes_secure (usize nbytes, gcry_random_level level)
1422 /*_GCRY_GCC_ATTR_MALLOC*/;
1425 /* Set the big integer W to a random value of NBITS using a random
1426 generator with quality LEVEL. Note that by using a level of
1427 GCRY_WEAK_RANDOM gcry_create_nonce is used internally. */
1428 void gcry_mpi_randomize (gcry_mpi_t w,
1429 uint nbits, gcry_random_level level);
1432 /* Create an unpredicable nonce of LENGTH bytes in BUFFER. */
1433 void gcry_create_nonce (void *buffer, usize length);
1439 /*******************************/
1440 /* */
1441 /* Prime Number Functions */
1442 /* */
1443 /*******************************/
1445 /* Mode values passed to a gcry_prime_check_func_t. */
1446 enum {
1447 GCRY_PRIME_CHECK_AT_FINISH = 0,
1448 GCRY_PRIME_CHECK_AT_GOT_PRIME = 1,
1449 GCRY_PRIME_CHECK_AT_MAYBE_PRIME = 2,
1452 /* The function should return 1 if the operation shall continue, 0 to
1453 reject the prime candidate. */
1454 alias gcry_prime_check_func_t = int function (void *arg, int mode, gcry_mpi_t candidate);
1456 /* Flags for gcry_prime_generate(): */
1458 /* Allocate prime numbers and factors in secure memory. */
1459 enum GCRY_PRIME_FLAG_SECRET = (1 << 0);
1461 /* Make sure that at least one prime factor is of size
1462 `FACTOR_BITS'. */
1463 enum GCRY_PRIME_FLAG_SPECIAL_FACTOR = (1 << 1);
1465 /* Generate a new prime number of PRIME_BITS bits and store it in
1466 PRIME. If FACTOR_BITS is non-zero, one of the prime factors of
1467 (prime - 1) / 2 must be FACTOR_BITS bits long. If FACTORS is
1468 non-zero, allocate a new, null-terminated array holding the prime
1469 factors and store it in FACTORS. FLAGS might be used to influence
1470 the prime number generation process. */
1471 gcry_error_t gcry_prime_generate (gcry_mpi_t *prime,
1472 uint prime_bits,
1473 uint factor_bits,
1474 gcry_mpi_t **factors,
1475 gcry_prime_check_func_t cb_func,
1476 void *cb_arg,
1477 gcry_random_level_t random_level,
1478 uint flags);
1480 /* Find a generator for PRIME where the factorization of (prime-1) is
1481 in the null terminated array FACTORS. Return the generator as a
1482 newly allocated MPI in R_G. If START_G is not null, use this as
1483 teh start for the search. */
1484 gcry_error_t gcry_prime_group_generator (gcry_mpi_t *r_g,
1485 gcry_mpi_t prime,
1486 gcry_mpi_t *factors,
1487 gcry_mpi_t start_g);
1490 /* Convenience function to release the FACTORS array. */
1491 void gcry_prime_release_factors (gcry_mpi_t *factors);
1494 /* Check wether the number X is prime. */
1495 gcry_error_t gcry_prime_check (gcry_mpi_t x, uint flags);
1499 /************************************
1501 * Miscellaneous Stuff *
1503 ************************************/
1505 /* Release the context object CTX. */
1506 void gcry_ctx_release (gcry_ctx_t ctx);
1508 /* Log data using Libgcrypt's own log interface. */
1509 void gcry_log_debug (const(char)* fmt, ...) /*_GCRY_GCC_ATTR_PRINTF(1,2)*/;
1510 void gcry_log_debughex (const(char)* text, const(void)* buffer, usize length);
1511 void gcry_log_debugmpi (const(char)* text, gcry_mpi_t mpi);
1512 void gcry_log_debugpnt (const(char)* text,
1513 gcry_mpi_point_t point, gcry_ctx_t ctx);
1514 void gcry_log_debugsxp (const(char)* text, gcry_sexp_t sexp);
1517 /* Log levels used by the internal logging facility. */
1518 alias gcry_log_levels = int;
1519 enum {
1520 GCRY_LOG_CONT = 0, /* (Continue the last log line.) */
1521 GCRY_LOG_INFO = 10,
1522 GCRY_LOG_WARN = 20,
1523 GCRY_LOG_ERROR = 30,
1524 GCRY_LOG_FATAL = 40,
1525 GCRY_LOG_BUG = 50,
1526 GCRY_LOG_DEBUG = 100
1529 /* Type for progress handlers. */
1530 alias gcry_handler_progress_t= void function (void *, const(char)* , int, int, int);
1532 /* Type for memory allocation handlers. */
1533 alias gcry_handler_alloc_t = void* function (usize n);
1535 /* Type for secure memory check handlers. */
1536 alias gcry_handler_secure_check_t = int function (const(void)* );
1538 /* Type for memory reallocation handlers. */
1539 alias gcry_handler_realloc_t = void* function (void *p, usize n);
1541 /* Type for memory free handlers. */
1542 alias gcry_handler_free_t = void function (void *);
1544 /* Type for out-of-memory handlers. */
1545 alias gcry_handler_no_mem_t = int function (void *, usize, uint);
1547 /* Type for fatal error handlers. */
1548 alias gcry_handler_error_t = void function (void *, int, const(char)* );
1550 /* Type for logging handlers. */
1551 alias gcry_handler_log_t = void function (void *, int, const(char)*, va_list);
1553 /* Certain operations can provide progress information. This function
1554 is used to register a handler for retrieving these information. */
1555 void gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data);
1558 /* Register a custom memory allocation functions. */
1559 void gcry_set_allocation_handler (
1560 gcry_handler_alloc_t func_alloc,
1561 gcry_handler_alloc_t func_alloc_secure,
1562 gcry_handler_secure_check_t func_secure_check,
1563 gcry_handler_realloc_t func_realloc,
1564 gcry_handler_free_t func_free);
1566 /* Register a function used instead of the internal out of memory
1567 handler. */
1568 void gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque);
1570 /* Register a function used instead of the internal fatal error
1571 handler. */
1572 void gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque);
1574 /* Register a function used instead of the internal logging
1575 facility. */
1576 void gcry_set_log_handler (gcry_handler_log_t f, void *opaque);
1578 /* Reserved for future use. */
1579 void gcry_set_gettext_handler (const(char)* function (const(char)*) f);
1581 /* Libgcrypt uses its own memory allocation. It is important to use
1582 gcry_free () to release memory allocated by libgcrypt. */
1583 void *gcry_malloc (usize n) /*_GCRY_GCC_ATTR_MALLOC*/;
1584 void *gcry_calloc (usize n, usize m) /*_GCRY_GCC_ATTR_MALLOC*/;
1585 void *gcry_malloc_secure (usize n) /*_GCRY_GCC_ATTR_MALLOC*/;
1586 void *gcry_calloc_secure (usize n, usize m) /*_GCRY_GCC_ATTR_MALLOC*/;
1587 void *gcry_realloc (void *a, usize n);
1588 char *gcry_strdup (const(char)* string) /*_GCRY_GCC_ATTR_MALLOC*/;
1589 void *gcry_xmalloc (usize n) /*_GCRY_GCC_ATTR_MALLOC*/;
1590 void *gcry_xcalloc (usize n, usize m) /*_GCRY_GCC_ATTR_MALLOC*/;
1591 void *gcry_xmalloc_secure (usize n) /*_GCRY_GCC_ATTR_MALLOC*/;
1592 void *gcry_xcalloc_secure (usize n, usize m) /*_GCRY_GCC_ATTR_MALLOC*/;
1593 void *gcry_xrealloc (void *a, usize n);
1594 char *gcry_xstrdup (const(char)* a) /*_GCRY_GCC_ATTR_MALLOC*/;
1595 void gcry_free (void *a);
1597 /* Return true if A is allocated in "secure" memory. */
1598 int gcry_is_secure (const(void)* a) /*_GCRY_GCC_ATTR_PURE*/;
1600 /* Return true if Libgcrypt is in FIPS mode. */
1601 auto gcry_fips_mode_active () { return !!gcry_control(GCRYCTL_FIPS_MODE_P, 0); }