PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/libgcrypt/libgcrypt-1.2.2/doc/gcrypt.texi

https://bitbucket.org/lkalif/emerald-snowglobe
Unknown | 3756 lines | 2904 code | 852 blank | 0 comment | 0 complexity | 24b2b163fa8a26f44910b45e9aff279d MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, BSD-3-Clause, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. \input texinfo @c -*- Texinfo -*-
  2. @c %**start of header
  3. @setfilename gcrypt.info
  4. @include version.texi
  5. @settitle The Libgcrypt Reference Manual
  6. @c Unify some of the indices.
  7. @syncodeindex tp fn
  8. @syncodeindex pg fn
  9. @c %**end of header
  10. @copying
  11. This manual is for Libgcrypt
  12. (version @value{VERSION}, @value{UPDATED}),
  13. which is GNU's library of cryptographic building blocks.
  14. Copyright @copyright{} 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
  15. @quotation
  16. Permission is granted to copy, distribute and/or modify this document
  17. under the terms of the GNU General Public License as published by the
  18. Free Software Foundation; either version 2 of the License, or (at your
  19. option) any later version. The text of the license can be found in the
  20. section entitled ``Copying''.
  21. @end quotation
  22. @end copying
  23. @dircategory GNU Libraries
  24. @direntry
  25. * libgcrypt: (gcrypt). Cryptographic function library.
  26. @end direntry
  27. @c
  28. @c Titlepage
  29. @c
  30. @setchapternewpage odd
  31. @titlepage
  32. @title The Libgcrypt Reference Manual
  33. @subtitle Version @value{VERSION}
  34. @subtitle @value{UPDATED}
  35. @author Werner Koch (@email{wk@@gnupg.org})
  36. @author Moritz Schulte (@email{mo@@g10code.com})
  37. @page
  38. @vskip 0pt plus 1filll
  39. @insertcopying
  40. @end titlepage
  41. @summarycontents
  42. @contents
  43. @page
  44. @ifnottex
  45. @node Top
  46. @top The Libgcrypt Library
  47. @insertcopying
  48. @end ifnottex
  49. @menu
  50. * Introduction:: What is @acronym{Libgcrypt}.
  51. * Preparation:: What you should do before using the library.
  52. * Generalities:: General library functions and data types.
  53. * Handler Functions:: Working with handler functions.
  54. * Symmetric cryptography:: How to use symmetric cryptography.
  55. * Hashing:: How to use hashing.
  56. * Public Key cryptography (I):: How to use public key cryptography.
  57. * Public Key cryptography (II):: How to use public key cryptography, alternatively.
  58. * Random Numbers:: How to work with random numbers.
  59. * S-expressions:: How to manage S-expressions.
  60. * MPI library:: How to work with multi-precision-integers.
  61. * Utilities:: Utility functions.
  62. Appendices
  63. * Library Copying:: The GNU Lesser General Public License
  64. says how you can copy and share `Libgcrypt'.
  65. * Copying:: The GNU General Public License says how you
  66. can copy and share some parts of `Libgcrypt'.
  67. Indices
  68. * Concept Index:: Index of concepts and programs.
  69. * Function and Data Index:: Index of functions, variables and data types.
  70. @detailmenu
  71. --- The Detailed Node Listing ---
  72. Introduction
  73. * Getting Started:: How to use this manual.
  74. * Features:: A glance at @acronym{Libgcrypt}'s features.
  75. * Overview:: Overview about the library.
  76. Preparation
  77. * Header:: What header file you need to include.
  78. * Building sources:: How to build sources using the library.
  79. * Building sources using Automake:: How to build sources with the help of Automake.
  80. * Initializing the library:: How to initialize the library.
  81. * Multi Threading:: How @acronym{Libgcrypt} can be used in a MT environment.
  82. Generalities
  83. * Controlling the library:: Controlling @acronym{Libgcrypt}'s behavior.
  84. * Modules:: Description of extension modules.
  85. * Error Handling:: Error codes and such.
  86. Handler Functions
  87. * Progress handler:: Using a progress handler function.
  88. * Allocation handler:: Using special memory allocation functions.
  89. * Error handler:: Using error handler functions.
  90. * Logging handler:: Using a special logging function.
  91. Symmetric cryptography
  92. * Available ciphers:: List of ciphers supported by the library.
  93. * Cipher modules:: How to work with cipher modules.
  94. * Available cipher modes:: List of cipher modes supported by the library.
  95. * Working with cipher handles:: How to perform operations related to cipher handles.
  96. * General cipher functions:: General cipher functions independent of cipher handles.
  97. Hashing
  98. * Available hash algorithms:: List of hash algorithms supported by the library.
  99. * Hash algorithm modules:: How to work with hash algorithm modules.
  100. * Working with hash algorithms:: List of functions related to hashing.
  101. Public Key cryptography (I)
  102. * Used S-expressions:: Introduction into the used S-expression.
  103. * Available algorithms:: Algorithms supported by the library.
  104. * Public key modules:: How to work with public key modules.
  105. * Cryptographic Functions:: Functions for performing the cryptographic actions.
  106. * General public-key related Functions:: General functions, not implementing any cryptography.
  107. Public Key cryptography (II)
  108. * Available asymmetric algorithms:: List of algorithms supported by the library.
  109. * Working with sets of data:: How to work with sets of data.
  110. * Working with handles:: How to use handles.
  111. * Working with keys:: How to work with keys.
  112. * Using cryptographic functions:: How to perform cryptographic operations.
  113. * Handle-independent functions:: General functions independent of handles.
  114. Random Numbers
  115. * Quality of random numbers:: @acronym{Libgcrypt} uses different quality levels.
  116. * Retrieving random numbers:: How to retrieve random numbers.
  117. S-expressions
  118. * Data types for S-expressions:: Data types related with S-expressions.
  119. * Working with S-expressions:: How to work with S-expressions.
  120. MPI library
  121. * Data types:: MPI related data types.
  122. * Basic functions:: First steps with MPI numbers.
  123. * MPI formats:: External representation of MPIs.
  124. * Calculations:: Performing MPI calculations.
  125. * Comparisons:: How to compare MPI values.
  126. * Bit manipulations:: How to access single bits of MPI values.
  127. * Miscellaneous:: Miscellaneous MPI functions.
  128. Utilities
  129. * Memory allocation:: Functions related with memory allocation.
  130. @end detailmenu
  131. @end menu
  132. @c **********************************************************
  133. @c ******************* Introduction ***********************
  134. @c **********************************************************
  135. @node Introduction
  136. @chapter Introduction
  137. `@acronym{Libgcrypt}' is a library providing cryptographic building blocks.
  138. @menu
  139. * Getting Started:: How to use this manual.
  140. * Features:: A glance at @acronym{Libgcrypt}'s features.
  141. * Overview:: Overview about the library.
  142. @end menu
  143. @node Getting Started
  144. @section Getting Started
  145. This manual documents the `@acronym{Libgcrypt}' library application programming
  146. interface (API). All functions and data types provided by the library
  147. are explained.
  148. @noindent
  149. The reader is assumed to possess basic knowledge about applied
  150. cryptography.
  151. This manual can be used in several ways. If read from the beginning
  152. to the end, it gives a good introduction into the library and how it
  153. can be used in an application. Forward references are included where
  154. necessary. Later on, the manual can be used as a reference manual to
  155. get just the information needed about any particular interface of the
  156. library. Experienced programmers might want to start looking at the
  157. examples at the end of the manual, and then only read up those parts
  158. of the interface which are unclear.
  159. @node Features
  160. @section Features
  161. `Libgcrypt' might have a couple of advantages over other libraries doing
  162. a similar job.
  163. @table @asis
  164. @item It's Free Software
  165. Anybody can use, modify, and redistribute it under the terms of the GNU
  166. Lesser General Public License (@pxref{Library Copying}). Note, that
  167. some parts (which are not needed on a GNU or GNU/Linux system) are
  168. subject to the terms of the GNU General Public License
  169. (@pxref{Copying}); please see the README file of the distribution for of
  170. list of these parts.
  171. @item It encapsulates the low level cryptography
  172. `@acronym{Libgcrypt}' provides a high level interface to cryptographic building
  173. blocks using an extendable and flexible API.
  174. @end table
  175. @node Overview
  176. @section Overview
  177. @noindent
  178. The `@acronym{Libgcrypt}' library is fully thread-safe, where it makes
  179. sense to be thread-safe. An exception for thread-safety are some
  180. cryptographic functions that modify a certain context stored in
  181. handles. If the user really intents to use such functions from
  182. different threads on the same handle, he has to take care of the
  183. serialization of such functions himself. If not described otherwise,
  184. every function is thread-safe.
  185. @acronym{Libgcrypt} depends on the library `libgpg-error', which
  186. contains common error handling related code for GnuPG components.
  187. @c **********************************************************
  188. @c ******************* Preparation ************************
  189. @c **********************************************************
  190. @node Preparation
  191. @chapter Preparation
  192. To use `@acronym{Libgcrypt}', you have to perform some changes to your
  193. sources and the build system. The necessary changes are small and
  194. explained in the following sections. At the end of this chapter, it
  195. is described how the library is initialized, and how the requirements
  196. of the library are verified.
  197. @menu
  198. * Header:: What header file you need to include.
  199. * Building sources:: How to build sources using the library.
  200. * Building sources using Automake:: How to build sources with the help of Automake.
  201. * Initializing the library:: How to initialize the library.
  202. * Multi Threading:: How @acronym{Libgcrypt} can be used in a MT environment.
  203. @end menu
  204. @node Header
  205. @section Header
  206. All interfaces (data types and functions) of the library are defined
  207. in the header file `gcrypt.h'. You must include this in all source
  208. files using the library, either directly or through some other header
  209. file, like this:
  210. @example
  211. #include <gcrypt.h>
  212. @end example
  213. The name space of `@acronym{Libgcrypt}' is @code{gcry_*} for function
  214. and type names and @code{GCRY*} for other symbols. In addition the
  215. same name prefixes with one prepended underscore are reserved for
  216. internal use and should never be used by an application. Furthermore
  217. `libgpg-error' defines functions prefixed with `gpg_' and preprocessor
  218. symbols prefixed with `GPG_'. Note that @acronym{Libgcrypt} uses
  219. libgpg-error, which uses @code{gpg_err_*} as name space for function
  220. and type names and @code{GPG_ERR_*} for other symbols, including all
  221. the error codes.
  222. @node Building sources
  223. @section Building sources
  224. If you want to compile a source file including the `gcrypt.h' header
  225. file, you must make sure that the compiler can find it in the
  226. directory hierarchy. This is accomplished by adding the path to the
  227. directory in which the header file is located to the compilers include
  228. file search path (via the @option{-I} option).
  229. However, the path to the include file is determined at the time the
  230. source is configured. To solve this problem, `@acronym{Libgcrypt}' ships with a small
  231. helper program @command{libgcrypt-config} that knows the path to the
  232. include file and other configuration options. The options that need
  233. to be added to the compiler invocation at compile time are output by
  234. the @option{--cflags} option to @command{libgcrypt-config}. The following
  235. example shows how it can be used at the command line:
  236. @example
  237. gcc -c foo.c `libgcrypt-config --cflags`
  238. @end example
  239. Adding the output of @samp{libgcrypt-config --cflags} to the compilers
  240. command line will ensure that the compiler can find the `@acronym{Libgcrypt}' header
  241. file.
  242. A similar problem occurs when linking the program with the library.
  243. Again, the compiler has to find the library files. For this to work,
  244. the path to the library files has to be added to the library search path
  245. (via the @option{-L} option). For this, the option @option{--libs} to
  246. @command{libgcrypt-config} can be used. For convenience, this option
  247. also outputs all other options that are required to link the program
  248. with the `@acronym{Libgcrypt}' libraries (in particular, the @samp{-lgcrypt}
  249. option). The example shows how to link @file{foo.o} with the `@acronym{Libgcrypt}'
  250. library to a program @command{foo}.
  251. @example
  252. gcc -o foo foo.o `libgcrypt-config --libs`
  253. @end example
  254. Of course you can also combine both examples to a single command by
  255. specifying both options to @command{libgcrypt-config}:
  256. @example
  257. gcc -o foo foo.c `libgcrypt-config --cflags --libs`
  258. @end example
  259. @node Building sources using Automake
  260. @section Building sources using Automake
  261. It is much easier if you use GNU Automake instead of writing your own
  262. Makefiles. If you do that you do not have to worry about finding and
  263. invoking the @command{libgcrypt-config} script at all.
  264. @acronym{Libgcrypt} provides an extension to Automake that does all
  265. the work for you.
  266. @c A simple macro for optional variables.
  267. @macro ovar{varname}
  268. @r{[}@var{\varname\}@r{]}
  269. @end macro
  270. @defmac AM_PATH_LIBGCRYPT (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
  271. Check whether @acronym{Libgcrypt} (at least version
  272. @var{minimum-version}, if given) exists on the host system. If it is
  273. found, execute @var{action-if-found}, otherwise do
  274. @var{action-if-not-found}, if given.
  275. Additionally, the function defines @code{LIBGCRYPT_CFLAGS} to the
  276. flags needed for compilation of the program to find the
  277. @file{gcrypt.h} header file, and @code{LIBGCRYPT_LIBS} to the linker
  278. flags needed to link the program to the @acronym{Libgcrypt} library.
  279. @end defmac
  280. You can use the defined Autoconf variables like this in your
  281. @file{Makefile.am}:
  282. @example
  283. AM_CPPFLAGS = $(LIBGCRYPT_CFLAGS)
  284. LDADD = $(LIBGCRYPT_LIBS)
  285. @end example
  286. @node Initializing the library
  287. @section Initializing the library
  288. It is often desirable to check that the version of `@acronym{Libgcrypt}' used is
  289. indeed one which fits all requirements. Even with binary compatibility
  290. new features may have been introduced but due to problem with the
  291. dynamic linker an old version is actually used. So you may want to
  292. check that the version is okay right after program startup.
  293. @deftypefun const char *gcry_check_version (const char *@var{req_version})
  294. The function @code{gcry_check_version} has three purposes. It can be
  295. used to retrieve the version number of the library. In addition it
  296. can verify that the version number is higher than a certain required
  297. version number.
  298. In either case, the function initializes some sub-systems, and for
  299. this reason alone it must be invoked early in your program, before you
  300. make use of the other functions of @acronym{Libgcrypt}.
  301. @end deftypefun
  302. @node Multi Threading
  303. @section Multi Threading
  304. As mentioned earlier, the `@acronym{Libgcrypt}' library is
  305. thread-safe if you adhere to the following requirements:
  306. @itemize @bullet
  307. @item
  308. If your application is multi-threaded, you must set the thread support
  309. callbacks with the @code{GCRYCTL_SET_THREAD_CBS} command
  310. @strong{before} any other function in the library.
  311. This is easy enough if you are indeed writing an application using
  312. Libgcrypt. It is rather problematic if you are writing a library
  313. instead. Here are some tips what to do if you are writing a library:
  314. If your library requires a certain thread package, just initialize
  315. Libgcrypt to use this thread package. If your library supports multiple
  316. thread packages, but needs to be configured, you will have to
  317. implement a way to determine which thread package the application
  318. wants to use with your library anyway. Then configure Libgcrypt to use
  319. this thread package.
  320. If your library is fully reentrant without any special support by a
  321. thread package, then you are lucky indeed. Unfortunately, this does
  322. not relieve you from doing either of the two above, or use a third
  323. option. The third option is to let the application initialize Libgcrypt
  324. for you. Then you are not using Libgcrypt transparently, though.
  325. As if this was not difficult enough, a conflict may arise if two
  326. libraries try to initialize Libgcrypt independently of each others, and
  327. both such libraries are then linked into the same application. To
  328. make it a bit simpler for you, this will probably work, but only if
  329. both libraries have the same requirement for the thread package. This
  330. is currently only supported for the non-threaded case, GNU Pth and
  331. pthread. Support for more thread packages is easy to add, so contact
  332. us if you require it.
  333. @item
  334. The function @code{gcry_check_version} must be called before any other
  335. function in the library, except the @code{GCRYCTL_SET_THREAD_CBS}
  336. command (called via the @code{gcry_control} function), because it
  337. initializes the thread support subsystem in @acronym{Libgcrypt}. To
  338. achieve this in multi-threaded programs, you must synchronize the
  339. memory with respect to other threads that also want to use
  340. @acronym{Libgcrypt}. For this, it is sufficient to call
  341. @code{gcry_check_version} before creating the other threads using
  342. @acronym{Libgcrypt}@footnote{At least this is true for POSIX threads,
  343. as @code{pthread_create} is a function that synchronizes memory with
  344. respects to other threads. There are many functions which have this
  345. property, a complete list can be found in POSIX, IEEE Std 1003.1-2003,
  346. Base Definitions, Issue 6, in the definition of the term ``Memory
  347. Synchronization''. For other thread packages, more relaxed or more
  348. strict rules may apply.}.
  349. @item
  350. As with the function @code{gpg_strerror}, @code{gcry_strerror} is not
  351. thread safe. You have to use @code{gpg_strerror_r} instead.
  352. @end itemize
  353. @acronym{Libgcrypt} contains convenient macros, which define the
  354. necessary thread callbacks for PThread and for GNU Pth:
  355. @table @code
  356. @item GCRY_THREAD_OPTION_PTH_IMPL
  357. This macro defines the following (static) symbols: gcry_pth_init,
  358. gcry_pth_mutex_init, gcry_pth_mutex_destroy, gcry_pth_mutex_lock,
  359. gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write, gcry_pth_select,
  360. gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect, gcry_threads_pth.
  361. After including this macro, gcry_control() shall be used with a
  362. command of GCRYCTL_SET_THREAD_CBS in order to register the thread
  363. callback structure named ``gcry_threads_pth''.
  364. @item GCRY_THREAD_OPTION_PTHREAD_IMPL
  365. This macro defines the following (static) symbols:
  366. gcry_pthread_mutex_init, gcry_pthread_mutex_destroy, gcry_mutex_lock,
  367. gcry_mutex_unlock, gcry_threads_pthread.
  368. After including this macro, gcry_control() shall be used with a
  369. command of GCRYCTL_SET_THREAD_CBS in order to register the thread
  370. callback structure named ``gcry_threads_pthread''.
  371. @end table
  372. Note that these macros need to be terminated with a semicolon. Keep
  373. in mind that these are convenient macros for C programmers; C++
  374. programmers might have to wrap these macros in an ``extern C'' body.
  375. @c **********************************************************
  376. @c ******************* General ****************************
  377. @c **********************************************************
  378. @node Generalities
  379. @chapter Generalities
  380. @menu
  381. * Controlling the library:: Controlling @acronym{Libgcrypt}'s behavior.
  382. * Modules:: Description of extension modules.
  383. * Error Handling:: Error codes and such.
  384. @end menu
  385. @node Controlling the library
  386. @section Controlling the library
  387. @deftypefun gcry_error_t gcry_control (enum gcry_ctl_cmds @var{cmd}, ...)
  388. This function can be used to influence the general behavior of
  389. @acronym{Libgcrypt} in several ways. Depending on @var{cmd}, more
  390. arguments can or have to be provided.
  391. @end deftypefun
  392. @node Modules
  393. @section Modules
  394. @acronym{Libgcrypt} supports the use of `extension modules', which
  395. implement algorithms in addition to those already built into the
  396. library directly.
  397. @deftp {Data type} gcry_module_t
  398. This data type represents a `module'.
  399. @end deftp
  400. Functions registering modules provided by the user take a `module
  401. specification structure' as input and return a value of
  402. @code{gcry_module_t} and an ID that is unique in the modules'
  403. category. This ID can be used to reference the newly registered
  404. module. After registering a module successfully, the new functionality
  405. should be able to be used through the normal functions provided by
  406. @acronym{Libgcrypt} until it is unregistered again.
  407. @c **********************************************************
  408. @c ******************* Errors ****************************
  409. @c **********************************************************
  410. @node Error Handling
  411. @section Error Handling
  412. Many functions in @acronym{Libgcrypt} can return an error if they
  413. fail. For this reason, the application should always catch the error
  414. condition and take appropriate measures, for example by releasing the
  415. resources and passing the error up to the caller, or by displaying a
  416. descriptive message to the user and cancelling the operation.
  417. Some error values do not indicate a system error or an error in the
  418. operation, but the result of an operation that failed properly. For
  419. example, if you try to decrypt a tempered message, the decryption will
  420. fail. Another error value actually means that the end of a data
  421. buffer or list has been reached. The following descriptions explain
  422. for many error codes what they mean usually. Some error values have
  423. specific meanings if returned by a certain functions. Such cases are
  424. described in the documentation of those functions.
  425. @acronym{Libgcrypt} uses the @code{libgpg-error} library. This allows
  426. to share the error codes with other components of the GnuPG system,
  427. and thus pass error values transparently from the crypto engine, or
  428. some helper application of the crypto engine, to the user. This way
  429. no information is lost. As a consequence, @acronym{Libgcrypt} does
  430. not use its own identifiers for error codes, but uses those provided
  431. by @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
  432. However, @acronym{Libgcrypt} does provide aliases for the functions
  433. defined in libgpg-error, which might be preferred for name space
  434. consistency.
  435. Most functions in @acronym{Libgcrypt} return an error code in the case
  436. of failure. For this reason, the application should always catch the
  437. error condition and take appropriate measures, for example by
  438. releasing the resources and passing the error up to the caller, or by
  439. displaying a descriptive message to the user and canceling the
  440. operation.
  441. Some error values do not indicate a system error or an error in the
  442. operation, but the result of an operation that failed properly.
  443. GnuPG components, including Libgcrypt, use an extra library named
  444. libgpg-error to provide a common error handling scheme. For more
  445. information on libgpg-error, see the according manual.
  446. @menu
  447. * Error Values:: The error value and what it means.
  448. * Error Sources:: A list of important error sources.
  449. * Error Codes:: A list of important error codes.
  450. * Error Strings:: How to get a descriptive string from a value.
  451. @end menu
  452. @node Error Values
  453. @subsection Error Values
  454. @cindex error values
  455. @cindex error codes
  456. @cindex error sources
  457. @deftp {Data type} {gcry_err_code_t}
  458. The @code{gcry_err_code_t} type is an alias for the
  459. @code{libgpg-error} type @code{gpg_err_code_t}. The error code
  460. indicates the type of an error, or the reason why an operation failed.
  461. A list of important error codes can be found in the next section.
  462. @end deftp
  463. @deftp {Data type} {gcry_err_source_t}
  464. The @code{gcry_err_source_t} type is an alias for the
  465. @code{libgpg-error} type @code{gpg_err_source_t}. The error source
  466. has not a precisely defined meaning. Sometimes it is the place where
  467. the error happened, sometimes it is the place where an error was
  468. encoded into an error value. Usually the error source will give an
  469. indication to where to look for the problem. This is not always true,
  470. but it is attempted to achieve this goal.
  471. A list of important error sources can be found in the next section.
  472. @end deftp
  473. @deftp {Data type} {gcry_error_t}
  474. The @code{gcry_error_t} type is an alias for the @code{libgpg-error}
  475. type @code{gpg_error_t}. An error value like this has always two
  476. components, an error code and an error source. Both together form the
  477. error value.
  478. Thus, the error value can not be directly compared against an error
  479. code, but the accessor functions described below must be used.
  480. However, it is guaranteed that only 0 is used to indicate success
  481. (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
  482. the error value are set to 0, too.
  483. Note that in @acronym{Libgcrypt}, the error source is used purely for
  484. diagnostic purposes. Only the error code should be checked to test
  485. for a certain outcome of a function. The manual only documents the
  486. error code part of an error value. The error source is left
  487. unspecified and might be anything.
  488. @end deftp
  489. @deftypefun {gcry_err_code_t} gcry_err_code (@w{gcry_error_t @var{err}})
  490. The static inline function @code{gcry_err_code} returns the
  491. @code{gcry_err_code_t} component of the error value @var{err}. This
  492. function must be used to extract the error code from an error value in
  493. order to compare it with the @code{GPG_ERR_*} error code macros.
  494. @end deftypefun
  495. @deftypefun {gcry_err_source_t} gcry_err_source (@w{gcry_error_t @var{err}})
  496. The static inline function @code{gcry_err_source} returns the
  497. @code{gcry_err_source_t} component of the error value @var{err}. This
  498. function must be used to extract the error source from an error value in
  499. order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
  500. @end deftypefun
  501. @deftypefun {gcry_error_t} gcry_err_make (@w{gcry_err_source_t @var{source}}, @w{gcry_err_code_t @var{code}})
  502. The static inline function @code{gcry_err_make} returns the error
  503. value consisting of the error source @var{source} and the error code
  504. @var{code}.
  505. This function can be used in callback functions to construct an error
  506. value to return it to the library.
  507. @end deftypefun
  508. @deftypefun {gcry_error_t} gcry_error (@w{gcry_err_code_t @var{code}})
  509. The static inline function @code{gcry_error} returns the error value
  510. consisting of the default error source and the error code @var{code}.
  511. For @acronym{GCRY} applications, the default error source is
  512. @code{GPG_ERR_SOURCE_USER_1}. You can define
  513. @code{GCRY_ERR_SOURCE_DEFAULT} before including @file{gcrypt.h} to
  514. change this default.
  515. This function can be used in callback functions to construct an error
  516. value to return it to the library.
  517. @end deftypefun
  518. The @code{libgpg-error} library provides error codes for all system
  519. error numbers it knows about. If @var{err} is an unknown error
  520. number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
  521. following functions can be used to construct error values from system
  522. errno numbers.
  523. @deftypefun {gcry_error_t} gcry_err_make_from_errno (@w{gcry_err_source_t @var{source}}, @w{int @var{err}})
  524. The function @code{gcry_err_make_from_errno} is like
  525. @code{gcry_err_make}, but it takes a system error like @code{errno}
  526. instead of a @code{gcry_err_code_t} error code.
  527. @end deftypefun
  528. @deftypefun {gcry_error_t} gcry_error_from_errno (@w{int @var{err}})
  529. The function @code{gcry_error_from_errno} is like @code{gcry_error},
  530. but it takes a system error like @code{errno} instead of a
  531. @code{gcry_err_code_t} error code.
  532. @end deftypefun
  533. Sometimes you might want to map system error numbers to error codes
  534. directly, or map an error code representing a system error back to the
  535. system error number. The following functions can be used to do that.
  536. @deftypefun {gcry_err_code_t} gcry_err_code_from_errno (@w{int @var{err}})
  537. The function @code{gcry_err_code_from_errno} returns the error code
  538. for the system error @var{err}. If @var{err} is not a known system
  539. error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
  540. @end deftypefun
  541. @deftypefun {int} gcry_err_code_to_errno (@w{gcry_err_code_t @var{err}})
  542. The function @code{gcry_err_code_to_errno} returns the system error
  543. for the error code @var{err}. If @var{err} is not an error code
  544. representing a system error, or if this system error is not defined on
  545. this system, the function returns @code{0}.
  546. @end deftypefun
  547. @node Error Sources
  548. @subsection Error Sources
  549. @cindex error codes, list of
  550. The library @code{libgpg-error} defines an error source for every
  551. component of the GnuPG system. The error source part of an error
  552. value is not well defined. As such it is mainly useful to improve the
  553. diagnostic error message for the user.
  554. If the error code part of an error value is @code{0}, the whole error
  555. value will be @code{0}. In this case the error source part is of
  556. course @code{GPG_ERR_SOURCE_UNKNOWN}.
  557. The list of error sources that might occur in applications using
  558. @acronym{Libgctypt} is:
  559. @table @code
  560. @item GPG_ERR_SOURCE_UNKNOWN
  561. The error source is not known. The value of this error source is
  562. @code{0}.
  563. @item GPG_ERR_SOURCE_GPGME
  564. The error source is @acronym{GPGME} itself.
  565. @item GPG_ERR_SOURCE_GPG
  566. The error source is GnuPG, which is the crypto engine used for the
  567. OpenPGP protocol.
  568. @item GPG_ERR_SOURCE_GPGSM
  569. The error source is GPGSM, which is the crypto engine used for the
  570. OpenPGP protocol.
  571. @item GPG_ERR_SOURCE_GCRYPT
  572. The error source is @code{libgcrypt}, which is used by crypto engines
  573. to perform cryptographic operations.
  574. @item GPG_ERR_SOURCE_GPGAGENT
  575. The error source is @command{gpg-agent}, which is used by crypto
  576. engines to perform operations with the secret key.
  577. @item GPG_ERR_SOURCE_PINENTRY
  578. The error source is @command{pinentry}, which is used by
  579. @command{gpg-agent} to query the passphrase to unlock a secret key.
  580. @item GPG_ERR_SOURCE_SCD
  581. The error source is the SmartCard Daemon, which is used by
  582. @command{gpg-agent} to delegate operations with the secret key to a
  583. SmartCard.
  584. @item GPG_ERR_SOURCE_KEYBOX
  585. The error source is @code{libkbx}, a library used by the crypto
  586. engines to manage local keyrings.
  587. @item GPG_ERR_SOURCE_USER_1
  588. @item GPG_ERR_SOURCE_USER_2
  589. @item GPG_ERR_SOURCE_USER_3
  590. @item GPG_ERR_SOURCE_USER_4
  591. These error sources are not used by any GnuPG component and can be
  592. used by other software. For example, applications using
  593. @acronym{Libgcrypt} can use them to mark error values coming from callback
  594. handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
  595. created with @code{gcry_error} and @code{gcry_error_from_errno},
  596. unless you define @code{GCRY_ERR_SOURCE_DEFAULT} before including
  597. @file{gcrypt.h}.
  598. @end table
  599. @node Error Codes
  600. @subsection Error Codes
  601. @cindex error codes, list of
  602. The library @code{libgpg-error} defines many error values. The
  603. following list includes the most important error codes.
  604. @table @code
  605. @item GPG_ERR_EOF
  606. This value indicates the end of a list, buffer or file.
  607. @item GPG_ERR_NO_ERROR
  608. This value indicates success. The value of this error code is
  609. @code{0}. Also, it is guaranteed that an error value made from the
  610. error code @code{0} will be @code{0} itself (as a whole). This means
  611. that the error source information is lost for this error code,
  612. however, as this error code indicates that no error occured, this is
  613. generally not a problem.
  614. @item GPG_ERR_GENERAL
  615. This value means that something went wrong, but either there is not
  616. enough information about the problem to return a more useful error
  617. value, or there is no separate error value for this type of problem.
  618. @item GPG_ERR_ENOMEM
  619. This value means that an out-of-memory condition occurred.
  620. @item GPG_ERR_E...
  621. System errors are mapped to GPG_ERR_EFOO where FOO is the symbol for
  622. the system error.
  623. @item GPG_ERR_INV_VALUE
  624. This value means that some user provided data was out of range.
  625. @item GPG_ERR_UNUSABLE_PUBKEY
  626. This value means that some recipients for a message were invalid.
  627. @item GPG_ERR_UNUSABLE_SECKEY
  628. This value means that some signers were invalid.
  629. @item GPG_ERR_NO_DATA
  630. This value means that data was expected where no data was found.
  631. @item GPG_ERR_CONFLICT
  632. This value means that a conflict of some sort occurred.
  633. @item GPG_ERR_NOT_IMPLEMENTED
  634. This value indicates that the specific function (or operation) is not
  635. implemented. This error should never happen. It can only occur if
  636. you use certain values or configuration options which do not work,
  637. but for which we think that they should work at some later time.
  638. @item GPG_ERR_DECRYPT_FAILED
  639. This value indicates that a decryption operation was unsuccessful.
  640. @item GPG_ERR_WRONG_KEY_USAGE
  641. This value indicates that a key is not used appropriately.
  642. @item GPG_ERR_NO_SECKEY
  643. This value indicates that no secret key for the user ID is available.
  644. @item GPG_ERR_UNSUPPORTED_ALGORITHM
  645. This value means a verification failed because the cryptographic
  646. algorithm is not supported by the crypto backend.
  647. @item GPG_ERR_BAD_SIGNATURE
  648. This value means a verification failed because the signature is bad.
  649. @item GPG_ERR_NO_PUBKEY
  650. This value means a verification failed because the public key is not
  651. available.
  652. @item GPG_ERR_USER_1
  653. @item GPG_ERR_USER_2
  654. @item ...
  655. @item GPG_ERR_USER_16
  656. These error codes are not used by any GnuPG component and can be
  657. freely used by other software. Applications using @acronym{Libgcrypt}
  658. might use them to mark specific errors returned by callback handlers
  659. if no suitable error codes (including the system errors) for these
  660. errors exist already.
  661. @end table
  662. @node Error Strings
  663. @subsection Error Strings
  664. @cindex error values, printing of
  665. @cindex error codes, printing of
  666. @cindex error sources, printing of
  667. @cindex error strings
  668. @deftypefun {const char *} gcry_strerror (@w{gcry_error_t @var{err}})
  669. The function @code{gcry_strerror} returns a pointer to a statically
  670. allocated string containing a description of the error code contained
  671. in the error value @var{err}. This string can be used to output a
  672. diagnostic message to the user.
  673. @end deftypefun
  674. @deftypefun {const char *} gcry_strsource (@w{gcry_error_t @var{err}})
  675. The function @code{gcry_strerror} returns a pointer to a statically
  676. allocated string containing a description of the error source
  677. contained in the error value @var{err}. This string can be used to
  678. output a diagnostic message to the user.
  679. @end deftypefun
  680. The following example illustrates the use of the functions described
  681. above:
  682. @example
  683. @{
  684. gcry_cipher_hd_t handle;
  685. gcry_error_t err = 0;
  686. err = gcry_cipher_open (&handle, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0);
  687. if (err)
  688. @{
  689. fprintf (stderr, "Failure: %s/%s\n",
  690. gcry_strsource (err),
  691. gcry_strerror (err));
  692. @}
  693. @}
  694. @end example
  695. @c **********************************************************
  696. @c ******************* General ****************************
  697. @c **********************************************************
  698. @node Handler Functions
  699. @chapter Handler Functions
  700. @acronym{Libgcrypt} makes it possible to install so called `handler functions',
  701. which get called by @acronym{Libgcrypt} in case of certain events.
  702. @menu
  703. * Progress handler:: Using a progress handler function.
  704. * Allocation handler:: Using special memory allocation functions.
  705. * Error handler:: Using error handler functions.
  706. * Logging handler:: Using a special logging function.
  707. @end menu
  708. @node Progress handler
  709. @section Progress handler
  710. It is often useful to retrieve some feedback while long running
  711. operations are performed.
  712. @deftp {Data type} gcry_handler_progress_t
  713. Progress handler functions have to be of the type
  714. @code{gcry_handler_progress_t}, which is defined as:
  715. @code{void (*gcry_handler_progress_t) (void *, const char *, int, int, int)}
  716. @end deftp
  717. The following function may be used to register a handler function for
  718. this purpose.
  719. @deftypefun void gcry_set_progress_handler (gcry_handler_progress_t @var{cb}, void *@var{cb_data})
  720. This function installs @var{cb} as the `Progress handler' function.
  721. @var{cb} must be defined as follows:
  722. @example
  723. void
  724. my_progress_handler (void *@var{cb_data}, const char *@var{what},
  725. int @var{printchar}, int @var{current}, int @var{total})
  726. @{
  727. /* Do something. */
  728. @}
  729. @end example
  730. A description of the arguments of the progress handler function follows.
  731. @table @var
  732. @item cb_data
  733. The argument provided in the call to @code{gcry_set_progress_handler}.
  734. @item what
  735. A string identifying the type of the progress output. The following
  736. values for @var{what} are defined:
  737. @table @code
  738. @item need_entropy
  739. Not enough entropy is available. @var{total} holds the number of
  740. required bytes.
  741. @item primegen
  742. Values for @var{printchar}:
  743. @table @code
  744. @item \n
  745. Prime generated.
  746. @item !
  747. Need to refresh the pool of prime numbers.
  748. @item <, >
  749. Number of bits adjusted.
  750. @item ^
  751. Searching for a generator.
  752. @item .
  753. Fermat test on 10 candidates failed.
  754. @item :
  755. Restart with a new random value.
  756. @item +
  757. Rabin Miller test passed.
  758. @end table
  759. @end table
  760. @end table
  761. @end deftypefun
  762. @node Allocation handler
  763. @section Allocation handler
  764. It is possible to make @acronym{Libgcrypt} use special memory
  765. allocation functions instead of the built-in ones.
  766. Memory allocation functions are of the following types:
  767. @deftp {Data type} gcry_handler_alloc_t
  768. This type is defined as: @code{void *(*gcry_handler_alloc_t) (size_t n)}.
  769. @end deftp
  770. @deftp {Data type} gcry_handler_secure_check_t
  771. This type is defined as: @code{int *(*gcry_handler_secure_check_t) (const void *)}.
  772. @end deftp
  773. @deftp {Data type} gcry_handler_realloc_t
  774. This type is defined as: @code{void *(*gcry_handler_realloc_t) (void *p, size_t n)}.
  775. @end deftp
  776. @deftp {Data type} gcry_handler_free_t
  777. This type is defined as: @code{void *(*gcry_handler_free_t) (void *)}.
  778. @end deftp
  779. Special memory allocation functions can be installed with the
  780. following function:
  781. @deftypefun void gcry_set_allocation_handler (gcry_handler_alloc_t @var{func_alloc}, gcry_handler_alloc_t @var{func_alloc_secure}, gcry_handler_secure_check_t @var{func_secure_check}, gcry_handler_realloc_t @var{func_realloc}, gcry_handler_free_t @var{func_free})
  782. Install the provided functions and use them instead of the built-in
  783. functions for doing memory allocation.
  784. @end deftypefun
  785. @node Error handler
  786. @section Error handler
  787. The following functions may be used to register handler functions that
  788. are called by @acronym{Libgcrypt} in case certain error conditions
  789. occur.
  790. @deftp {Data type} gcry_handler_no_mem_t
  791. This type is defined as: @code{void (*gcry_handler_no_mem_t) (void *, size_t, unsigned int)}
  792. @end deftp
  793. @deftypefun void gcry_set_outofcore_handler (gcry_handler_no_mem_t @var{func_no_mem}, void *@var{cb_data})
  794. This function registers @var{func_no_mem} as `out-of-core handler',
  795. which means that it will be called in the case of not having enough
  796. memory available.
  797. @end deftypefun
  798. @deftp {Data type} gcry_handler_error_t
  799. This type is defined as: @code{void (*gcry_handler_error_t) (void *, int, const char *)}
  800. @end deftp
  801. @deftypefun void gcry_set_fatalerror_handler (gcry_handler_error_t @var{func_error}, void *@var{cb_data})
  802. This function registers @var{func_error} as `error handler',
  803. which means that it will be called in error conditions.
  804. @end deftypefun
  805. @node Logging handler
  806. @section Logging handler
  807. @deftp {Data type} gcry_handler_log_t
  808. This type is defined as: @code{void (*gcry_handler_log_t) (void *, int, const char *, va_list)}
  809. @end deftp
  810. @deftypefun void gcry_set_log_handler (gcry_handler_log_t @var{func_log}, void *@var{cb_data})
  811. This function registers @var{func_log} as `logging handler', which
  812. means that it will be called in case @acronym{Libgcrypt} wants to log
  813. a message.
  814. @end deftypefun
  815. @c **********************************************************
  816. @c ******************* Ciphers ****************************
  817. @c **********************************************************
  818. @c @include cipher-ref.texi
  819. @node Symmetric cryptography
  820. @chapter Symmetric cryptography
  821. The cipher functions are used for symmetrical cryptography,
  822. i.e. cryptography using a shared key. The programming model follows
  823. an open/process/close paradigm and is in that similar to other
  824. building blocks provided by @acronym{Libgcrypt}.
  825. @menu
  826. * Available ciphers:: List of ciphers supported by the library.
  827. * Cipher modules:: How to work with cipher modules.
  828. * Available cipher modes:: List of cipher modes supported by the library.
  829. * Working with cipher handles:: How to perform operations related to cipher handles.
  830. * General cipher functions:: General cipher functions independent of cipher handles.
  831. @end menu
  832. @node Available ciphers
  833. @section Available ciphers
  834. @table @code
  835. @item GCRY_CIPHER_NONE
  836. This is not a real algorithm but used by some functions as error return.
  837. The value always evaluates to false.
  838. @item GCRY_CIPHER_IDEA
  839. This is the IDEA algorithm. The constant is provided but there is
  840. currently no implementation for it because the algorithm is patented.
  841. @item GCRY_CIPHER_3DES
  842. Triple-DES with 3 Keys as EDE. The key size of this algorithm is 168 but
  843. you have to pass 192 bits because the most significant bits of each byte
  844. are ignored.
  845. @item GCRY_CIPHER_CAST5
  846. CAST128-5 block cipher algorithm. The key size is 128 bits.
  847. @item GCRY_CIPHER_BLOWFISH
  848. The blowfish algorithm. The current implementation allows only for a key
  849. size of 128 bits.
  850. @item GCRY_CIPHER_SAFER_SK128
  851. Reserved and not currently implemented.
  852. @item GCRY_CIPHER_DES_SK
  853. Reserved and not currently implemented.
  854. @item GCRY_CIPHER_AES
  855. @itemx GCRY_CIPHER_AES128
  856. @itemx GCRY_CIPHER_RIJNDAEL
  857. @itemx GCRY_CIPHER_RIJNDAEL128
  858. AES (Rijndael) with a 128 bit key.
  859. @item GCRY_CIPHER_AES192
  860. @itemx GCRY_CIPHER_RIJNDAEL128
  861. AES (Rijndael) with a 192 bit key.
  862. @item GCRY_CIPHER_AES256
  863. @itemx GCRY_CIPHER_RIJNDAEL256
  864. AES (Rijndael) with a 256 bit key.
  865. @item GCRY_CIPHER_TWOFISH
  866. The Twofish algorithm with a 256 bit key.
  867. @item GCRY_CIPHER_TWOFISH128
  868. The Twofish algorithm with a 128 bit key.
  869. @item GCRY_CIPHER_ARCFOUR
  870. An algorithm which is 100% compatible with RSA Inc.'s RC4 algorithm.
  871. Note that this is a stream cipher and must be used very carefully to
  872. avoid a couple of weaknesses.
  873. @item GCRY_CIPHER_DES
  874. Standard DES with a 56 bit key. You need to pass 64 bit but the high
  875. bits of each byte are ignored. Note, that this is a weak algorithm
  876. which can be broken in reasonable time using a brute force approach.
  877. @end table
  878. @node Cipher modules
  879. @section Cipher modules
  880. @acronym{Libgcrypt} makes it possible to load additional `cipher
  881. modules'; these cipher can be used just like the cipher algorithms
  882. that are built into the library directly. For an introduction into
  883. extension modules, see @xref{Modules}.
  884. @deftp {Data type} gcry_cipher_spec_t
  885. This is the `module specification structure' needed for registering
  886. cipher modules, which has to be filled in by the user before it can be
  887. used to register a module. It contains the following members:
  888. @table @code
  889. @item const char *name
  890. The primary name of the algorithm.
  891. @item const char **aliases
  892. A list of strings that are `aliases' for the algorithm. The list must
  893. be terminated with a NULL element.
  894. @item gcry_cipher_oid_spec_t *oids
  895. A list of OIDs that are to be associated with the algorithm. The
  896. list's last element must have it's `oid' member set to NULL. See
  897. below for an explanation of this type.
  898. @item size_t blocksize
  899. The block size of the algorithm, in bytes.
  900. @item size_t keylen
  901. The length of the key, in bits.
  902. @item size_t contextsize
  903. The size of the algorithm-specific `context', that should be allocated
  904. for each handle.
  905. @item gcry_cipher_setkey_t setkey
  906. The function responsible for initializing a handle with a provided
  907. key. See below for a description of this type.
  908. @item gcry_cipher_encrypt_t encrypt
  909. The function responsible for encrypting a single block. See below for
  910. a description of this type.
  911. @item gcry_cipher_decrypt_t decrypt
  912. The function responsible for decrypting a single block. See below for
  913. a description of this type.
  914. @item gcry_cipher_stencrypt_t stencrypt
  915. Like `encrypt', for stream ciphers. See below for a description of
  916. this type.
  917. @item gcry_cipher_stdecrypt_t stdecrypt
  918. Like `decrypt', for stream ciphers. See below for a description of
  919. this type.
  920. @end table
  921. @end deftp
  922. @deftp {Data type} gcry_cipher_oid_spec_t
  923. This type is used for associating a user-provided algorithm
  924. implementation with certain OIDs. It contains the following members:
  925. @table @code
  926. @item const char *oid
  927. Textual representation of the OID.
  928. @item int mode
  929. Cipher mode for which this OID is valid.
  930. @end table
  931. @end deftp
  932. @deftp {Data type} gcry_cipher_setkey_t
  933. Type for the `setkey' function, defined as: gcry_err_code_t
  934. (*gcry_cipher_setkey_t) (void *c, const unsigned char *key, unsigned
  935. keylen)
  936. @end deftp
  937. @deftp {Data type} gcry_cipher_encrypt_t
  938. Type for the `encrypt' function, defined as: gcry_err_code_t
  939. (*gcry_cipher_encrypt_t) (void *c, const unsigned char *outbuf, const
  940. unsigned char *inbuf)
  941. @end deftp
  942. @deftp {Data type} gcry_cipher_decrypt_t
  943. Type for the `decrypt' function, defined as: gcry_err_code_t
  944. (*gcry_cipher_decrypt_t) (void *c, const unsigned char *outbuf, const
  945. unsigned char *inbuf)
  946. @end deftp
  947. @deftp {Data type} gcry_cipher_stencrypt_t
  948. Type for the `stencrypt' function, defined as: gcry_err_code_t
  949. (*gcry_cipher_stencrypt_t) (void *c, const unsigned char *outbuf, const
  950. unsigned char *, unsigned int n)
  951. @end deftp
  952. @deftp {Data type} gcry_cipher_stdecrypt_t
  953. Type for the `stdecrypt' function, defined as: gcry_err_code_t
  954. (*gcry_cipher_stdecrypt_t) (void *c, const unsigned char *outbuf, const
  955. unsigned char *, unsigned int n)
  956. @end deftp
  957. @deftypefun gcry_error_t gcry_cipher_register (gcry_cipher_spec_t *@var{cipher}, unsigned int *algorithm_id, gcry_module_t *@var{module})
  958. Register a new cipher module whose specification can be found in
  959. @var{cipher}. On success, a new algorithm ID is stored in
  960. @var{algorithm_id} and a pointer representing this module is stored
  961. in @var{module}.
  962. @end deftypefun
  963. @deftypefun void gcry_cipher_unregister (gcry_module_t @var{module})
  964. Unregister the cipher identified by @var{module}, which must have been
  965. registered with gcry_cipher_register.
  966. @end deftypefun
  967. @deftypefun gcry_error_t gcry_cipher_list (int *@var{list}, int *@var{list_length})
  968. Get a list consisting of the IDs of the loaded cipher modules. If
  969. @var{list} is zero, write the number of loaded cipher modules to
  970. @var{list_length} and return. If @var{list} is non-zero, the first
  971. *@var{list_length} algorithm IDs are stored in @var{list}, which must
  972. be of according size. In case there are less cipher modules than
  973. *@var{list_length}, *@var{list_length} is updated to the correct
  974. number.
  975. @end deftypefun
  976. @node Available cipher modes
  977. @section Available cipher modes
  978. @table @code
  979. @item GCRY_CIPHER_MODE_NONE
  980. No mode specified, may be set later using other functions. The value
  981. of this constant is always 0.
  982. @item GCRY_CIPHER_MODE_ECB
  983. Electronic Codebook mode.
  984. @item GCRY_CIPHER_MODE_CFB
  985. Cipher Feedback mode.
  986. @item GCRY_CIPHER_MODE_CBC
  987. Cipher Block Chaining mode.
  988. @item GCRY_CIPHER_MODE_STREAM
  989. Stream mode, only to be used with stream cipher algorithms.
  990. @item GCRY_CIPHER_MODE_OFB
  991. Outer Feedback mode.
  992. @item GCRY_CIPHER_MODE_CTR
  993. Counter mode.
  994. @end table
  995. @node Working with cipher handles
  996. @section Working with cipher handles
  997. To use a cipher algorithm, you must first allocate an according
  998. handle. This is to be done using the open function:
  999. @deftypefun gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *@var{hd}, int @var{algo}, int @var{mode}, unsigned int @var{flags})
  1000. This function creates the context handle required for most of the
  1001. other cipher functions and returns a handle to it in `hd'. In case of
  1002. an error, an according error code is returned.
  1003. The ID of algorithm to use must be specified via @var{algo}. See
  1004. @xref{Available ciphers}, for a list of supported ciphers and the
  1005. according constants.
  1006. Besides using the constants directly, the function
  1007. @code{gcry_cipher_map_name} may be used to convert the textual name of
  1008. an algorithm into the according numeric ID.
  1009. The cipher mode to use must be specified via @var{mode}. See
  1010. @xref{Available cipher modes}, for a list of supported cipher modes
  1011. and the according constants. Note, that some modes do not work
  1012. together with all algorithms.
  1013. The third argument @var{flags} can either be passed as @code{0} or as
  1014. the bit-wise OR of the following constants.
  1015. @table @code
  1016. @item GCRY_CIPHER_SECURE
  1017. Make sure that all operations are allocated in secure memory. This is
  1018. useful, when the key material is highly confidential.
  1019. @item GCRY_CIPHER_ENABLE_SYNC
  1020. This flag enables the CFB sync mode, which is a special feature of
  1021. @acronym{Libgcrypt}'s CFB mode implementation to allow for OpenPGP's CFB variant.
  1022. See @code{gcry_cipher_sync}.
  1023. @i…

Large files files are truncated, but you can click here to view the full file