PageRenderTime 23ms CodeModel.GetById 6ms app.highlight 200ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://bitbucket.org/lkalif/emerald-snowglobe
Unknown | 4698 lines | 3737 code | 961 blank | 0 comment | 0 complexity | 20c855858e53f0cbed0617a6e61e1af9 MD5 | raw file
   1This is gcrypt.info, produced by makeinfo version 4.7 from gcrypt.texi.
   2
   3   This manual is for Libgcrypt (version 1.2.2, 29 July 2005), which is
   4GNU's library of cryptographic building blocks.
   5
   6   Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
   7
   8     Permission is granted to copy, distribute and/or modify this
   9     document under the terms of the GNU General Public License as
  10     published by the Free Software Foundation; either version 2 of the
  11     License, or (at your option) any later version. The text of the
  12     license can be found in the section entitled "Copying".
  13
  14INFO-DIR-SECTION GNU Libraries
  15START-INFO-DIR-ENTRY
  16* libgcrypt: (gcrypt).  Cryptographic function library.
  17END-INFO-DIR-ENTRY
  18
  19
  20File: gcrypt.info,  Node: Top,  Next: Introduction,  Up: (dir)
  21
  22The Libgcrypt Library
  23*********************
  24
  25This manual is for Libgcrypt (version 1.2.2, 29 July 2005), which is
  26GNU's library of cryptographic building blocks.
  27
  28   Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
  29
  30     Permission is granted to copy, distribute and/or modify this
  31     document under the terms of the GNU General Public License as
  32     published by the Free Software Foundation; either version 2 of the
  33     License, or (at your option) any later version. The text of the
  34     license can be found in the section entitled "Copying".
  35
  36* Menu:
  37
  38* Introduction::                 What is Libgcrypt.
  39* Preparation::                  What you should do before using the library.
  40* Generalities::                 General library functions and data types.
  41* Handler Functions::            Working with handler functions.
  42* Symmetric cryptography::       How to use symmetric cryptography.
  43* Hashing::                      How to use hashing.
  44* Public Key cryptography (I)::  How to use public key cryptography.
  45* Public Key cryptography (II):: How to use public key cryptography, alternatively.
  46* Random Numbers::               How to work with random numbers.
  47* S-expressions::                How to manage S-expressions.
  48* MPI library::                  How to work with multi-precision-integers.
  49* Utilities::                    Utility functions.
  50
  51Appendices
  52
  53* Library Copying::             The GNU Lesser General Public License
  54                                says how you can copy and share `Libgcrypt'.
  55* Copying::                     The GNU General Public License says how you
  56                                can copy and share some parts of `Libgcrypt'.
  57
  58Indices
  59
  60* Concept Index::               Index of concepts and programs.
  61* Function and Data Index::     Index of functions, variables and data types.
  62
  63 --- The Detailed Node Listing ---
  64
  65Introduction
  66* Getting Started::             How to use this manual.
  67* Features::                    A glance at Libgcrypt's features.
  68* Overview::                    Overview about the library.
  69
  70Preparation
  71* Header::                              What header file you need to include.
  72* Building sources::                    How to build sources using the library.
  73* Building sources using Automake::     How to build sources with the help of Automake.
  74* Initializing the library::            How to initialize the library.
  75* Multi Threading::                     How Libgcrypt can be used in a MT environment.
  76
  77Generalities
  78* Controlling the library::     Controlling Libgcrypt's behavior.
  79* Modules::                     Description of extension modules.
  80* Error Handling::              Error codes and such.
  81
  82Handler Functions
  83* Progress handler::            Using a progress handler function.
  84* Allocation handler::          Using special memory allocation functions.
  85* Error handler::               Using error handler functions.
  86* Logging handler::             Using a special logging function.
  87
  88Symmetric cryptography
  89* Available ciphers::           List of ciphers supported by the library.
  90* Cipher modules::              How to work with cipher modules.
  91* Available cipher modes::      List of cipher modes supported by the library.
  92* Working with cipher handles:: How to perform operations related to cipher handles.
  93* General cipher functions::    General cipher functions independent of cipher handles.
  94
  95Hashing
  96* Available hash algorithms::           List of hash algorithms supported by the library.
  97* Hash algorithm modules::              How to work with hash algorithm modules.
  98* Working with hash algorithms::        List of functions related to hashing.
  99
 100Public Key cryptography (I)
 101* Used S-expressions::                    Introduction into the used S-expression.
 102* Available algorithms::                  Algorithms supported by the library.
 103* Public key modules::                    How to work with public key modules.
 104* Cryptographic Functions::               Functions for performing the cryptographic actions.
 105* General public-key related Functions::  General functions, not implementing any cryptography.
 106
 107Public 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
 115Random Numbers
 116* Quality of random numbers::   Libgcrypt uses different quality levels.
 117* Retrieving random numbers::   How to retrieve random numbers.
 118
 119S-expressions
 120* Data types for S-expressions::   Data types related with S-expressions.
 121* Working with S-expressions::     How to work with S-expressions.
 122
 123MPI library
 124* Data types::                  MPI related data types.
 125* Basic functions::             First steps with MPI numbers.
 126* MPI formats::                 External representation of MPIs.
 127* Calculations::                Performing MPI calculations.
 128* Comparisons::                 How to compare MPI values.
 129* Bit manipulations::           How to access single bits of MPI values.
 130* Miscellaneous::               Miscellaneous MPI functions.
 131
 132Utilities
 133* Memory allocation::           Functions related with memory allocation.
 134
 135
 136File: gcrypt.info,  Node: Introduction,  Next: Preparation,  Prev: Top,  Up: Top
 137
 1381 Introduction
 139**************
 140
 141`Libgcrypt' is a library providing cryptographic building blocks.
 142
 143* Menu:
 144
 145* Getting Started::             How to use this manual.
 146* Features::                    A glance at Libgcrypt's features.
 147* Overview::                    Overview about the library.
 148
 149
 150File: gcrypt.info,  Node: Getting Started,  Next: Features,  Up: Introduction
 151
 1521.1 Getting Started
 153===================
 154
 155This manual documents the `Libgcrypt' library application programming
 156interface (API).  All functions and data types provided by the library
 157are explained.
 158
 159The reader is assumed to possess basic knowledge about applied
 160cryptography.
 161
 162   This manual can be used in several ways.  If read from the beginning
 163to the end, it gives a good introduction into the library and how it
 164can be used in an application.  Forward references are included where
 165necessary.  Later on, the manual can be used as a reference manual to
 166get just the information needed about any particular interface of the
 167library.  Experienced programmers might want to start looking at the
 168examples at the end of the manual, and then only read up those parts of
 169the interface which are unclear.
 170
 171
 172File: gcrypt.info,  Node: Features,  Next: Overview,  Prev: Getting Started,  Up: Introduction
 173
 1741.2 Features
 175============
 176
 177`Libgcrypt' might have a couple of advantages over other libraries doing
 178a similar job.
 179
 180It's Free Software
 181     Anybody can use, modify, and redistribute it under the terms of
 182     the GNU Lesser General Public License (*note Library Copying::).
 183     Note, that some parts (which are not needed on a GNU or GNU/Linux
 184     system) are subject to the terms of the GNU General Public License
 185     (*note Copying::); please see the README file of the distribution
 186     for of list of these parts.
 187
 188It encapsulates the low level cryptography
 189     `Libgcrypt' provides a high level interface to cryptographic
 190     building blocks using an extendable and flexible API.
 191
 192
 193
 194File: gcrypt.info,  Node: Overview,  Prev: Features,  Up: Introduction
 195
 1961.3 Overview
 197============
 198
 199The `Libgcrypt' library is fully thread-safe, where it makes sense to
 200be thread-safe.  An exception for thread-safety are some cryptographic
 201functions that modify a certain context stored in handles.  If the user
 202really intents to use such functions from different threads on the same
 203handle, he has to take care of the serialization of such functions
 204himself.  If not described otherwise, every function is thread-safe.
 205
 206   Libgcrypt depends on the library `libgpg-error', which contains
 207common error handling related code for GnuPG components.
 208
 209
 210File: gcrypt.info,  Node: Preparation,  Next: Generalities,  Prev: Introduction,  Up: Top
 211
 2122 Preparation
 213*************
 214
 215To use `Libgcrypt', you have to perform some changes to your sources
 216and the build system.  The necessary changes are small and explained in
 217the following sections.  At the end of this chapter, it is described
 218how the library is initialized, and how the requirements of the library
 219are verified.
 220
 221* Menu:
 222
 223* Header::                      What header file you need to include.
 224* Building sources::            How to build sources using the library.
 225* Building sources using Automake::  How to build sources with the help of Automake.
 226* Initializing the library::    How to initialize the library.
 227* Multi Threading::             How Libgcrypt can be used in a MT environment.
 228
 229
 230File: gcrypt.info,  Node: Header,  Next: Building sources,  Up: Preparation
 231
 2322.1 Header
 233==========
 234
 235All interfaces (data types and functions) of the library are defined in
 236the header file `gcrypt.h'.  You must include this in all source files
 237using the library, either directly or through some other header file,
 238like this:
 239
 240     #include <gcrypt.h>
 241
 242   The name space of `Libgcrypt' is `gcry_*' for function and type
 243names and `GCRY*' for other symbols.  In addition the same name
 244prefixes with one prepended underscore are reserved for internal use
 245and should never be used by an application.  Furthermore `libgpg-error'
 246defines functions prefixed with `gpg_' and preprocessor symbols
 247prefixed with `GPG_'.  Note that Libgcrypt uses libgpg-error, which
 248uses `gpg_err_*' as name space for function and type names and
 249`GPG_ERR_*' for other symbols, including all the error codes.
 250
 251
 252File: gcrypt.info,  Node: Building sources,  Next: Building sources using Automake,  Prev: Header,  Up: Preparation
 253
 2542.2 Building sources
 255====================
 256
 257If you want to compile a source file including the `gcrypt.h' header
 258file, you must make sure that the compiler can find it in the directory
 259hierarchy.  This is accomplished by adding the path to the directory in
 260which the header file is located to the compilers include file search
 261path (via the `-I' option).
 262
 263   However, the path to the include file is determined at the time the
 264source is configured.  To solve this problem, `Libgcrypt' ships with a
 265small helper program `libgcrypt-config' that knows the path to the
 266include file and other configuration options.  The options that need to
 267be added to the compiler invocation at compile time are output by the
 268`--cflags' option to `libgcrypt-config'.  The following example shows
 269how it can be used at the command line:
 270
 271     gcc -c foo.c `libgcrypt-config --cflags`
 272
 273   Adding the output of `libgcrypt-config --cflags' to the compilers
 274command line will ensure that the compiler can find the `Libgcrypt'
 275header file.
 276
 277   A similar problem occurs when linking the program with the library.
 278Again, the compiler has to find the library files.  For this to work,
 279the path to the library files has to be added to the library search path
 280(via the `-L' option).  For this, the option `--libs' to
 281`libgcrypt-config' can be used.  For convenience, this option also
 282outputs all other options that are required to link the program with
 283the `Libgcrypt' libraries (in particular, the `-lgcrypt' option).  The
 284example shows how to link `foo.o' with the `Libgcrypt' library to a
 285program `foo'.
 286
 287     gcc -o foo foo.o `libgcrypt-config --libs`
 288
 289   Of course you can also combine both examples to a single command by
 290specifying both options to `libgcrypt-config':
 291
 292     gcc -o foo foo.c `libgcrypt-config --cflags --libs`
 293
 294
 295File: gcrypt.info,  Node: Building sources using Automake,  Next: Initializing the library,  Prev: Building sources,  Up: Preparation
 296
 2972.3 Building sources using Automake
 298===================================
 299
 300It is much easier if you use GNU Automake instead of writing your own
 301Makefiles.  If you do that you do not have to worry about finding and
 302invoking the `libgcrypt-config' script at all.  Libgcrypt provides an
 303extension to Automake that does all the work for you.
 304
 305 -- Macro: AM_PATH_LIBGCRYPT ([MINIMUM-VERSION], [ACTION-IF-FOUND],
 306          [ACTION-IF-NOT-FOUND])
 307     Check whether Libgcrypt (at least version MINIMUM-VERSION, if
 308     given) exists on the host system.  If it is found, execute
 309     ACTION-IF-FOUND, otherwise do ACTION-IF-NOT-FOUND, if given.
 310
 311     Additionally, the function defines `LIBGCRYPT_CFLAGS' to the flags
 312     needed for compilation of the program to find the `gcrypt.h'
 313     header file, and `LIBGCRYPT_LIBS' to the linker flags needed to
 314     link the program to the Libgcrypt library.
 315
 316   You can use the defined Autoconf variables like this in your
 317`Makefile.am':
 318
 319     AM_CPPFLAGS = $(LIBGCRYPT_CFLAGS)
 320     LDADD = $(LIBGCRYPT_LIBS)
 321
 322
 323File: gcrypt.info,  Node: Initializing the library,  Next: Multi Threading,  Prev: Building sources using Automake,  Up: Preparation
 324
 3252.4 Initializing the library
 326============================
 327
 328It is often desirable to check that the version of `Libgcrypt' used is
 329indeed one which fits all requirements.  Even with binary compatibility
 330new features may have been introduced but due to problem with the
 331dynamic linker an old version is actually used.  So you may want to
 332check that the version is okay right after program startup.
 333
 334 -- Function: const char *gcry_check_version (const char *REQ_VERSION)
 335     The function `gcry_check_version' has three purposes.  It can be
 336     used to retrieve the version number of the library.  In addition it
 337     can verify that the version number is higher than a certain
 338     required version number.
 339
 340     In either case, the function initializes some sub-systems, and for
 341     this reason alone it must be invoked early in your program, before
 342     you make use of the other functions of Libgcrypt.
 343
 344
 345File: gcrypt.info,  Node: Multi Threading,  Prev: Initializing the library,  Up: Preparation
 346
 3472.5 Multi Threading
 348===================
 349
 350As mentioned earlier, the `Libgcrypt' library is thread-safe if you
 351adhere to the following requirements:
 352
 353   * If your application is multi-threaded, you must set the thread
 354     support callbacks with the `GCRYCTL_SET_THREAD_CBS' command
 355     *before* any other function in the library.
 356
 357     This is easy enough if you are indeed writing an application using
 358     Libgcrypt.  It is rather problematic if you are writing a library
 359     instead.  Here are some tips what to do if you are writing a
 360     library:
 361
 362     If your library requires a certain thread package, just initialize
 363     Libgcrypt to use this thread package.  If your library supports
 364     multiple thread packages, but needs to be configured, you will
 365     have to implement a way to determine which thread package the
 366     application wants to use with your library anyway.  Then configure
 367     Libgcrypt to use this thread package.
 368
 369     If your library is fully reentrant without any special support by a
 370     thread package, then you are lucky indeed.  Unfortunately, this
 371     does not relieve you from doing either of the two above, or use a
 372     third option.  The third option is to let the application
 373     initialize Libgcrypt for you.  Then you are not using Libgcrypt
 374     transparently, though.
 375
 376     As if this was not difficult enough, a conflict may arise if two
 377     libraries try to initialize Libgcrypt independently of each
 378     others, and both such libraries are then linked into the same
 379     application.  To make it a bit simpler for you, this will probably
 380     work, but only if both libraries have the same requirement for the
 381     thread package.  This is currently only supported for the
 382     non-threaded case, GNU Pth and pthread.  Support for more thread
 383     packages is easy to add, so contact us if you require it.
 384
 385   * The function `gcry_check_version' must be called before any other
 386     function in the library, except the `GCRYCTL_SET_THREAD_CBS'
 387     command (called via the `gcry_control' function), because it
 388     initializes the thread support subsystem in Libgcrypt.  To achieve
 389     this in multi-threaded programs, you must synchronize the memory
 390     with respect to other threads that also want to use Libgcrypt.
 391     For this, it is sufficient to call `gcry_check_version' before
 392     creating the other threads using Libgcrypt(1).
 393
 394   *  As with the function `gpg_strerror', `gcry_strerror' is not
 395     thread safe.  You have to use `gpg_strerror_r' instead.
 396
 397   Libgcrypt contains convenient macros, which define the necessary
 398thread callbacks for PThread and for GNU Pth:
 399
 400`GCRY_THREAD_OPTION_PTH_IMPL'
 401     This macro defines the following (static) symbols: gcry_pth_init,
 402     gcry_pth_mutex_init, gcry_pth_mutex_destroy, gcry_pth_mutex_lock,
 403     gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write,
 404     gcry_pth_select, gcry_pth_waitpid, gcry_pth_accept,
 405     gcry_pth_connect, gcry_threads_pth.
 406
 407     After including this macro, gcry_control() shall be used with a
 408     command of GCRYCTL_SET_THREAD_CBS in order to register the thread
 409     callback structure named "gcry_threads_pth".
 410
 411`GCRY_THREAD_OPTION_PTHREAD_IMPL'
 412     This macro defines the following (static) symbols:
 413     gcry_pthread_mutex_init, gcry_pthread_mutex_destroy,
 414     gcry_mutex_lock, gcry_mutex_unlock, gcry_threads_pthread.
 415
 416     After including this macro, gcry_control() shall be used with a
 417     command of GCRYCTL_SET_THREAD_CBS in order to register the thread
 418     callback structure named "gcry_threads_pthread".
 419
 420   Note that these macros need to be terminated with a semicolon.  Keep
 421in mind that these are convenient macros for C programmers; C++
 422programmers might have to wrap these macros in an "extern C" body.
 423
 424   ---------- Footnotes ----------
 425
 426   (1) At least this is true for POSIX threads, as `pthread_create' is
 427a function that synchronizes memory with respects to other threads.
 428There are many functions which have this property, a complete list can
 429be found in POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in
 430the definition of the term "Memory Synchronization".  For other thread
 431packages, more relaxed or more strict rules may apply.
 432
 433
 434File: gcrypt.info,  Node: Generalities,  Next: Handler Functions,  Prev: Preparation,  Up: Top
 435
 4363 Generalities
 437**************
 438
 439* Menu:
 440
 441* Controlling the library::     Controlling Libgcrypt's behavior.
 442* Modules::                     Description of extension modules.
 443* Error Handling::              Error codes and such.
 444
 445
 446File: gcrypt.info,  Node: Controlling the library,  Next: Modules,  Up: Generalities
 447
 4483.1 Controlling the library
 449===========================
 450
 451 -- Function: gcry_error_t gcry_control (enum gcry_ctl_cmds CMD, ...)
 452     This function can be used to influence the general behavior of
 453     Libgcrypt in several ways.  Depending on CMD, more arguments can
 454     or have to be provided.
 455
 456
 457
 458File: gcrypt.info,  Node: Modules,  Next: Error Handling,  Prev: Controlling the library,  Up: Generalities
 459
 4603.2 Modules
 461===========
 462
 463Libgcrypt supports the use of `extension modules', which implement
 464algorithms in addition to those already built into the library directly.
 465
 466 -- Data type: gcry_module_t
 467     This data type represents a `module'.
 468
 469   Functions registering modules provided by the user take a `module
 470specification structure' as input and return a value of `gcry_module_t'
 471and an ID that is unique in the modules' category.  This ID can be used
 472to reference the newly registered module.  After registering a module
 473successfully, the new functionality should be able to be used through
 474the normal functions provided by Libgcrypt until it is unregistered
 475again.
 476
 477
 478File: gcrypt.info,  Node: Error Handling,  Prev: Modules,  Up: Generalities
 479
 4803.3 Error Handling
 481==================
 482
 483Many functions in Libgcrypt can return an error if they fail.  For this
 484reason, the application should always catch the error condition and
 485take appropriate measures, for example by releasing the resources and
 486passing the error up to the caller, or by displaying a descriptive
 487message to the user and cancelling the operation.
 488
 489   Some error values do not indicate a system error or an error in the
 490operation, but the result of an operation that failed properly.  For
 491example, if you try to decrypt a tempered message, the decryption will
 492fail.  Another error value actually means that the end of a data buffer
 493or list has been reached.  The following descriptions explain for many
 494error codes what they mean usually.  Some error values have specific
 495meanings if returned by a certain functions.  Such cases are described
 496in the documentation of those functions.
 497
 498   Libgcrypt uses the `libgpg-error' library.  This allows to share the
 499error codes with other components of the GnuPG system, and thus pass
 500error values transparently from the crypto engine, or some helper
 501application of the crypto engine, to the user.  This way no information
 502is lost.  As a consequence, Libgcrypt does not use its own identifiers
 503for error codes, but uses those provided by `libgpg-error'.  They
 504usually start with `GPG_ERR_'.
 505
 506   However, Libgcrypt does provide aliases for the functions defined in
 507libgpg-error, which might be preferred for name space consistency.
 508
 509   Most functions in Libgcrypt return an error code in the case of
 510failure.  For this reason, the application should always catch the
 511error condition and take appropriate measures, for example by releasing
 512the resources and passing the error up to the caller, or by displaying
 513a descriptive message to the user and canceling the operation.
 514
 515   Some error values do not indicate a system error or an error in the
 516operation, but the result of an operation that failed properly.
 517
 518   GnuPG components, including Libgcrypt, use an extra library named
 519libgpg-error to provide a common error handling scheme.  For more
 520information on libgpg-error, see the according manual.
 521
 522* Menu:
 523
 524* Error Values::                The error value and what it means.
 525* Error Sources::               A list of important error sources.
 526* Error Codes::                 A list of important error codes.
 527* Error Strings::               How to get a descriptive string from a value.
 528
 529
 530File: gcrypt.info,  Node: Error Values,  Next: Error Sources,  Up: Error Handling
 531
 5323.3.1 Error Values
 533------------------
 534
 535 -- Data type: gcry_err_code_t
 536     The `gcry_err_code_t' type is an alias for the `libgpg-error' type
 537     `gpg_err_code_t'.  The error code indicates the type of an error,
 538     or the reason why an operation failed.
 539
 540     A list of important error codes can be found in the next section.
 541
 542 -- Data type: gcry_err_source_t
 543     The `gcry_err_source_t' type is an alias for the `libgpg-error'
 544     type `gpg_err_source_t'.  The error source has not a precisely
 545     defined meaning.  Sometimes it is the place where the error
 546     happened, sometimes it is the place where an error was encoded
 547     into an error value.  Usually the error source will give an
 548     indication to where to look for the problem.  This is not always
 549     true, but it is attempted to achieve this goal.
 550
 551     A list of important error sources can be found in the next section.
 552
 553 -- Data type: gcry_error_t
 554     The `gcry_error_t' type is an alias for the `libgpg-error' type
 555     `gpg_error_t'.  An error value like this has always two
 556     components, an error code and an error source.  Both together form
 557     the error value.
 558
 559     Thus, the error value can not be directly compared against an error
 560     code, but the accessor functions described below must be used.
 561     However, it is guaranteed that only 0 is used to indicate success
 562     (`GPG_ERR_NO_ERROR'), and that in this case all other parts of the
 563     error value are set to 0, too.
 564
 565     Note that in Libgcrypt, the error source is used purely for
 566     diagnostic purposes.  Only the error code should be checked to test
 567     for a certain outcome of a function.  The manual only documents the
 568     error code part of an error value.  The error source is left
 569     unspecified and might be anything.
 570
 571 -- Function: gcry_err_code_t gcry_err_code (gcry_error_t ERR)
 572     The static inline function `gcry_err_code' returns the
 573     `gcry_err_code_t' component of the error value ERR.  This function
 574     must be used to extract the error code from an error value in
 575     order to compare it with the `GPG_ERR_*' error code macros.
 576
 577 -- Function: gcry_err_source_t gcry_err_source (gcry_error_t ERR)
 578     The static inline function `gcry_err_source' returns the
 579     `gcry_err_source_t' component of the error value ERR.  This
 580     function must be used to extract the error source from an error
 581     value in order to compare it with the `GPG_ERR_SOURCE_*' error
 582     source macros.
 583
 584 -- Function: gcry_error_t gcry_err_make (gcry_err_source_t SOURCE,
 585          gcry_err_code_t CODE)
 586     The static inline function `gcry_err_make' returns the error value
 587     consisting of the error source SOURCE and the error code CODE.
 588
 589     This function can be used in callback functions to construct an
 590     error value to return it to the library.
 591
 592 -- Function: gcry_error_t gcry_error (gcry_err_code_t CODE)
 593     The static inline function `gcry_error' returns the error value
 594     consisting of the default error source and the error code CODE.
 595
 596     For GCRY applications, the default error source is
 597     `GPG_ERR_SOURCE_USER_1'.  You can define `GCRY_ERR_SOURCE_DEFAULT'
 598     before including `gcrypt.h' to change this default.
 599
 600     This function can be used in callback functions to construct an
 601     error value to return it to the library.
 602
 603   The `libgpg-error' library provides error codes for all system error
 604numbers it knows about.  If ERR is an unknown error number, the error
 605code `GPG_ERR_UNKNOWN_ERRNO' is used.  The following functions can be
 606used to construct error values from system errno numbers.
 607
 608 -- Function: gcry_error_t gcry_err_make_from_errno
 609          (gcry_err_source_t SOURCE, int ERR)
 610     The function `gcry_err_make_from_errno' is like `gcry_err_make',
 611     but it takes a system error like `errno' instead of a
 612     `gcry_err_code_t' error code.
 613
 614 -- Function: gcry_error_t gcry_error_from_errno (int ERR)
 615     The function `gcry_error_from_errno' is like `gcry_error', but it
 616     takes a system error like `errno' instead of a `gcry_err_code_t'
 617     error code.
 618
 619   Sometimes you might want to map system error numbers to error codes
 620directly, or map an error code representing a system error back to the
 621system error number.  The following functions can be used to do that.
 622
 623 -- Function: gcry_err_code_t gcry_err_code_from_errno (int ERR)
 624     The function `gcry_err_code_from_errno' returns the error code for
 625     the system error ERR.  If ERR is not a known system error, the
 626     function returns `GPG_ERR_UNKNOWN_ERRNO'.
 627
 628 -- Function: int gcry_err_code_to_errno (gcry_err_code_t ERR)
 629     The function `gcry_err_code_to_errno' returns the system error for
 630     the error code ERR.  If ERR is not an error code representing a
 631     system error, or if this system error is not defined on this
 632     system, the function returns `0'.
 633
 634
 635File: gcrypt.info,  Node: Error Sources,  Next: Error Codes,  Prev: Error Values,  Up: Error Handling
 636
 6373.3.2 Error Sources
 638-------------------
 639
 640The library `libgpg-error' defines an error source for every component
 641of the GnuPG system.  The error source part of an error value is not
 642well defined.  As such it is mainly useful to improve the diagnostic
 643error message for the user.
 644
 645   If the error code part of an error value is `0', the whole error
 646value will be `0'.  In this case the error source part is of course
 647`GPG_ERR_SOURCE_UNKNOWN'.
 648
 649   The list of error sources that might occur in applications using
 650Libgctypt is:
 651
 652`GPG_ERR_SOURCE_UNKNOWN'
 653     The error source is not known.  The value of this error source is
 654     `0'.
 655
 656`GPG_ERR_SOURCE_GPGME'
 657     The error source is GPGME itself.
 658
 659`GPG_ERR_SOURCE_GPG'
 660     The error source is GnuPG, which is the crypto engine used for the
 661     OpenPGP protocol.
 662
 663`GPG_ERR_SOURCE_GPGSM'
 664     The error source is GPGSM, which is the crypto engine used for the
 665     OpenPGP protocol.
 666
 667`GPG_ERR_SOURCE_GCRYPT'
 668     The error source is `libgcrypt', which is used by crypto engines
 669     to perform cryptographic operations.
 670
 671`GPG_ERR_SOURCE_GPGAGENT'
 672     The error source is `gpg-agent', which is used by crypto engines
 673     to perform operations with the secret key.
 674
 675`GPG_ERR_SOURCE_PINENTRY'
 676     The error source is `pinentry', which is used by `gpg-agent' to
 677     query the passphrase to unlock a secret key.
 678
 679`GPG_ERR_SOURCE_SCD'
 680     The error source is the SmartCard Daemon, which is used by
 681     `gpg-agent' to delegate operations with the secret key to a
 682     SmartCard.
 683
 684`GPG_ERR_SOURCE_KEYBOX'
 685     The error source is `libkbx', a library used by the crypto engines
 686     to manage local keyrings.
 687
 688`GPG_ERR_SOURCE_USER_1'
 689
 690`GPG_ERR_SOURCE_USER_2'
 691
 692`GPG_ERR_SOURCE_USER_3'
 693
 694`GPG_ERR_SOURCE_USER_4'
 695     These error sources are not used by any GnuPG component and can be
 696     used by other software.  For example, applications using Libgcrypt
 697     can use them to mark error values coming from callback handlers.
 698     Thus `GPG_ERR_SOURCE_USER_1' is the default for errors created
 699     with `gcry_error' and `gcry_error_from_errno', unless you define
 700     `GCRY_ERR_SOURCE_DEFAULT' before including `gcrypt.h'.
 701
 702
 703File: gcrypt.info,  Node: Error Codes,  Next: Error Strings,  Prev: Error Sources,  Up: Error Handling
 704
 7053.3.3 Error Codes
 706-----------------
 707
 708The library `libgpg-error' defines many error values.  The following
 709list includes the most important error codes.
 710
 711`GPG_ERR_EOF'
 712     This value indicates the end of a list, buffer or file.
 713
 714`GPG_ERR_NO_ERROR'
 715     This value indicates success.  The value of this error code is
 716     `0'.  Also, it is guaranteed that an error value made from the
 717     error code `0' will be `0' itself (as a whole).  This means that
 718     the error source information is lost for this error code, however,
 719     as this error code indicates that no error occured, this is
 720     generally not a problem.
 721
 722`GPG_ERR_GENERAL'
 723     This value means that something went wrong, but either there is not
 724     enough information about the problem to return a more useful error
 725     value, or there is no separate error value for this type of
 726     problem.
 727
 728`GPG_ERR_ENOMEM'
 729     This value means that an out-of-memory condition occurred.
 730
 731`GPG_ERR_E...'
 732     System errors are mapped to GPG_ERR_EFOO where FOO is the symbol
 733     for the system error.
 734
 735`GPG_ERR_INV_VALUE'
 736     This value means that some user provided data was out of range.
 737
 738`GPG_ERR_UNUSABLE_PUBKEY'
 739     This value means that some recipients for a message were invalid.
 740
 741`GPG_ERR_UNUSABLE_SECKEY'
 742     This value means that some signers were invalid.
 743
 744`GPG_ERR_NO_DATA'
 745     This value means that data was expected where no data was found.
 746
 747`GPG_ERR_CONFLICT'
 748     This value means that a conflict of some sort occurred.
 749
 750`GPG_ERR_NOT_IMPLEMENTED'
 751     This value indicates that the specific function (or operation) is
 752     not implemented.  This error should never happen.  It can only
 753     occur if you use certain values or configuration options which do
 754     not work, but for which we think that they should work at some
 755     later time.
 756
 757`GPG_ERR_DECRYPT_FAILED'
 758     This value indicates that a decryption operation was unsuccessful.
 759
 760`GPG_ERR_WRONG_KEY_USAGE'
 761     This value indicates that a key is not used appropriately.
 762
 763`GPG_ERR_NO_SECKEY'
 764     This value indicates that no secret key for the user ID is
 765     available.
 766
 767`GPG_ERR_UNSUPPORTED_ALGORITHM'
 768     This value means a verification failed because the cryptographic
 769     algorithm is not supported by the crypto backend.
 770
 771`GPG_ERR_BAD_SIGNATURE'
 772     This value means a verification failed because the signature is
 773     bad.
 774
 775`GPG_ERR_NO_PUBKEY'
 776     This value means a verification failed because the public key is
 777     not available.
 778
 779`GPG_ERR_USER_1'
 780
 781`GPG_ERR_USER_2'
 782
 783`...'
 784
 785`GPG_ERR_USER_16'
 786     These error codes are not used by any GnuPG component and can be
 787     freely used by other software.  Applications using Libgcrypt might
 788     use them to mark specific errors returned by callback handlers if
 789     no suitable error codes (including the system errors) for these
 790     errors exist already.
 791
 792
 793File: gcrypt.info,  Node: Error Strings,  Prev: Error Codes,  Up: Error Handling
 794
 7953.3.4 Error Strings
 796-------------------
 797
 798 -- Function: const char * gcry_strerror (gcry_error_t ERR)
 799     The function `gcry_strerror' returns a pointer to a statically
 800     allocated string containing a description of the error code
 801     contained in the error value ERR.  This string can be used to
 802     output a diagnostic message to the user.
 803
 804 -- Function: const char * gcry_strsource (gcry_error_t ERR)
 805     The function `gcry_strerror' returns a pointer to a statically
 806     allocated string containing a description of the error source
 807     contained in the error value ERR.  This string can be used to
 808     output a diagnostic message to the user.
 809
 810   The following example illustrates the use of the functions described
 811above:
 812
 813     {
 814       gcry_cipher_hd_t handle;
 815       gcry_error_t err = 0;
 816
 817       err = gcry_cipher_open (&handle, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0);
 818       if (err)
 819         {
 820           fprintf (stderr, "Failure: %s/%s\n",
 821                    gcry_strsource (err),
 822                    gcry_strerror (err));
 823         }
 824     }
 825
 826
 827File: gcrypt.info,  Node: Handler Functions,  Next: Symmetric cryptography,  Prev: Generalities,  Up: Top
 828
 8294 Handler Functions
 830*******************
 831
 832Libgcrypt makes it possible to install so called `handler functions',
 833which get called by Libgcrypt in case of certain events.
 834
 835* Menu:
 836
 837* Progress handler::            Using a progress handler function.
 838* Allocation handler::          Using special memory allocation functions.
 839* Error handler::               Using error handler functions.
 840* Logging handler::             Using a special logging function.
 841
 842
 843File: gcrypt.info,  Node: Progress handler,  Next: Allocation handler,  Up: Handler Functions
 844
 8454.1 Progress handler
 846====================
 847
 848It is often useful to retrieve some feedback while long running
 849operations are performed.
 850
 851 -- Data type: gcry_handler_progress_t
 852     Progress handler functions have to be of the type
 853     `gcry_handler_progress_t', which is defined as:
 854
 855     `void (*gcry_handler_progress_t) (void *, const char *, int, int,
 856     int)'
 857
 858   The following function may be used to register a handler function for
 859this purpose.
 860
 861 -- Function: void gcry_set_progress_handler (gcry_handler_progress_t
 862          CB, void *CB_DATA)
 863     This function installs CB as the `Progress handler' function.  CB
 864     must be defined as follows:
 865
 866          void
 867          my_progress_handler (void *CB_DATA, const char *WHAT,
 868                               int PRINTCHAR, int CURRENT, int TOTAL)
 869          {
 870            /* Do something.  */
 871          }
 872
 873     A description of the arguments of the progress handler function
 874     follows.
 875
 876    CB_DATA
 877          The argument provided in the call to
 878          `gcry_set_progress_handler'.
 879
 880    WHAT
 881          A string identifying the type of the progress output.  The
 882          following values for WHAT are defined:
 883
 884         `need_entropy'
 885               Not enough entropy is available.  TOTAL holds the number
 886               of required bytes.
 887
 888         `primegen'
 889               Values for PRINTCHAR:
 890              `\n'
 891                    Prime generated.
 892
 893              `!'
 894                    Need to refresh the pool of prime numbers.
 895
 896              `<, >'
 897                    Number of bits adjusted.
 898
 899              `^'
 900                    Searching for a generator.
 901
 902              `.'
 903                    Fermat test on 10 candidates failed.
 904
 905              `:'
 906                    Restart with a new random value.
 907
 908              `+'
 909                    Rabin Miller test passed.
 910
 911
 912
 913
 914File: gcrypt.info,  Node: Allocation handler,  Next: Error handler,  Prev: Progress handler,  Up: Handler Functions
 915
 9164.2 Allocation handler
 917======================
 918
 919It is possible to make Libgcrypt use special memory allocation
 920functions instead of the built-in ones.
 921
 922   Memory allocation functions are of the following types:
 923
 924 -- Data type: gcry_handler_alloc_t
 925     This type is defined as: `void *(*gcry_handler_alloc_t) (size_t
 926     n)'.
 927
 928 -- Data type: gcry_handler_secure_check_t
 929     This type is defined as: `int *(*gcry_handler_secure_check_t)
 930     (const void *)'.
 931
 932 -- Data type: gcry_handler_realloc_t
 933     This type is defined as: `void *(*gcry_handler_realloc_t) (void
 934     *p, size_t n)'.
 935
 936 -- Data type: gcry_handler_free_t
 937     This type is defined as: `void *(*gcry_handler_free_t) (void *)'.
 938
 939   Special memory allocation functions can be installed with the
 940following function:
 941
 942 -- Function: void gcry_set_allocation_handler (gcry_handler_alloc_t
 943          FUNC_ALLOC, gcry_handler_alloc_t FUNC_ALLOC_SECURE,
 944          gcry_handler_secure_check_t FUNC_SECURE_CHECK,
 945          gcry_handler_realloc_t FUNC_REALLOC, gcry_handler_free_t
 946          FUNC_FREE)
 947     Install the provided functions and use them instead of the built-in
 948     functions for doing memory allocation.
 949
 950
 951File: gcrypt.info,  Node: Error handler,  Next: Logging handler,  Prev: Allocation handler,  Up: Handler Functions
 952
 9534.3 Error handler
 954=================
 955
 956The following functions may be used to register handler functions that
 957are called by Libgcrypt in case certain error conditions occur.
 958
 959 -- Data type: gcry_handler_no_mem_t
 960     This type is defined as: `void (*gcry_handler_no_mem_t) (void *,
 961     size_t, unsigned int)'
 962
 963 -- Function: void gcry_set_outofcore_handler (gcry_handler_no_mem_t
 964          FUNC_NO_MEM, void *CB_DATA)
 965     This function registers FUNC_NO_MEM as `out-of-core handler',
 966     which means that it will be called in the case of not having enough
 967     memory available.
 968
 969 -- Data type: gcry_handler_error_t
 970     This type is defined as: `void (*gcry_handler_error_t) (void *,
 971     int, const char *)'
 972
 973 -- Function: void gcry_set_fatalerror_handler (gcry_handler_error_t
 974          FUNC_ERROR, void *CB_DATA)
 975     This function registers FUNC_ERROR as `error handler', which means
 976     that it will be called in error conditions.
 977
 978
 979File: gcrypt.info,  Node: Logging handler,  Prev: Error handler,  Up: Handler Functions
 980
 9814.4 Logging handler
 982===================
 983
 984 -- Data type: gcry_handler_log_t
 985     This type is defined as: `void (*gcry_handler_log_t) (void *, int,
 986     const char *, va_list)'
 987
 988 -- Function: void gcry_set_log_handler (gcry_handler_log_t FUNC_LOG,
 989          void *CB_DATA)
 990     This function registers FUNC_LOG as `logging handler', which means
 991     that it will be called in case Libgcrypt wants to log a message.
 992
 993
 994File: gcrypt.info,  Node: Symmetric cryptography,  Next: Hashing,  Prev: Handler Functions,  Up: Top
 995
 9965 Symmetric cryptography
 997************************
 998
 999The cipher functions are used for symmetrical cryptography, i.e.
1000cryptography using a shared key.  The programming model follows an
1001open/process/close paradigm and is in that similar to other building
1002blocks provided by Libgcrypt.
1003
1004* Menu:
1005
1006* Available ciphers::           List of ciphers supported by the library.
1007* Cipher modules::              How to work with cipher modules.
1008* Available cipher modes::      List of cipher modes supported by the library.
1009* Working with cipher handles::  How to perform operations related to cipher handles.
1010* General cipher functions::    General cipher functions independent of cipher handles.
1011
1012
1013File: gcrypt.info,  Node: Available ciphers,  Next: Cipher modules,  Up: Symmetric cryptography
1014
10155.1 Available ciphers
1016=====================
1017
1018`GCRY_CIPHER_NONE'
1019     This is not a real algorithm but used by some functions as error
1020     return.  The value always evaluates to false.
1021
1022`GCRY_CIPHER_IDEA'
1023     This is the IDEA algorithm.  The constant is provided but there is
1024     currently no implementation for it because the algorithm is
1025     patented.
1026
1027`GCRY_CIPHER_3DES'
1028     Triple-DES with 3 Keys as EDE.  The key size of this algorithm is
1029     168 but you have to pass 192 bits because the most significant
1030     bits of each byte are ignored.
1031
1032`GCRY_CIPHER_CAST5'
1033     CAST128-5 block cipher algorithm.  The key size is 128 bits.
1034
1035`GCRY_CIPHER_BLOWFISH'
1036     The blowfish algorithm. The current implementation allows only for
1037     a key size of 128 bits.
1038
1039`GCRY_CIPHER_SAFER_SK128'
1040     Reserved and not currently implemented.
1041
1042`GCRY_CIPHER_DES_SK'
1043     Reserved and not currently implemented.
1044
1045`GCRY_CIPHER_AES'
1046`GCRY_CIPHER_AES128'
1047`GCRY_CIPHER_RIJNDAEL'
1048`GCRY_CIPHER_RIJNDAEL128'
1049     AES (Rijndael) with a 128 bit key.
1050
1051`GCRY_CIPHER_AES192'
1052`GCRY_CIPHER_RIJNDAEL128'
1053     AES (Rijndael) with a 192 bit key.
1054
1055`GCRY_CIPHER_AES256'
1056`GCRY_CIPHER_RIJNDAEL256'
1057     AES (Rijndael) with a 256 bit key.
1058
1059`GCRY_CIPHER_TWOFISH'
1060     The Twofish algorithm with a 256 bit key.
1061
1062`GCRY_CIPHER_TWOFISH128'
1063     The Twofish algorithm with a 128 bit key.
1064
1065`GCRY_CIPHER_ARCFOUR'
1066     An algorithm which is 100% compatible with RSA Inc.'s RC4
1067     algorithm.  Note that this is a stream cipher and must be used
1068     very carefully to avoid a couple of weaknesses.
1069
1070`GCRY_CIPHER_DES'
1071     Standard DES with a 56 bit key. You need to pass 64 bit but the
1072     high bits of each byte are ignored.  Note, that this is a weak
1073     algorithm which can be broken in reasonable time using a brute
1074     force approach.
1075
1076
1077
1078File: gcrypt.info,  Node: Cipher modules,  Next: Available cipher modes,  Prev: Available ciphers,  Up: Symmetric cryptography
1079
10805.2 Cipher modules
1081==================
1082
1083Libgcrypt makes it possible to load additional `cipher modules'; these
1084cipher can be used just like the cipher algorithms that are built into
1085the library directly.  For an introduction into extension modules, see
1086*Note Modules::.
1087
1088 -- Data type: gcry_cipher_spec_t
1089     This is the `module specification structure' needed for registering
1090     cipher modules, which has to be filled in by the user before it
1091     can be used to register a module.  It contains the following
1092     members:
1093
1094    `const char *name'
1095          The primary name of the algorithm.
1096
1097    `const char **aliases'
1098          A list of strings that are `aliases' for the algorithm.  The
1099          list must be terminated with a NULL element.
1100
1101    `gcry_cipher_oid_spec_t *oids'
1102          A list of OIDs that are to be associated with the algorithm.
1103          The list's last element must have it's `oid' member set to
1104          NULL.  See below for an explanation of this type.
1105
1106    `size_t blocksize'
1107          The block size of the algorithm, in bytes.
1108
1109    `size_t keylen'
1110          The length of the key, in bits.
1111
1112    `size_t contextsize'
1113          The size of the algorithm-specific `context', that should be
1114          allocated for each handle.
1115
1116    `gcry_cipher_setkey_t setkey'
1117          The function responsible for initializing a handle with a
1118          provided key.  See below for a description of this type.
1119
1120    `gcry_cipher_encrypt_t encrypt'
1121          The function responsible for encrypting a single block.  See
1122          below for a description of this type.
1123
1124    `gcry_cipher_decrypt_t decrypt'
1125          The function responsible for decrypting a single block.  See
1126          below for a description of this type.
1127
1128    `gcry_cipher_stencrypt_t stencrypt'
1129          Like `encrypt', for stream ciphers.  See below for a
1130          description of this type.
1131
1132    `gcry_cipher_stdecrypt_t stdecrypt'
1133          Like `decrypt', for stream ciphers.  See below for a
1134          description of this type.
1135
1136 -- Data type: gcry_cipher_oid_spec_t
1137     This type is used for associating a user-provided algorithm
1138     implementation with certain OIDs.  It contains the following
1139     members:
1140    `const char *oid'
1141          Textual representation of the OID.
1142
1143    `int mode'
1144          Cipher mode for which this OID is valid.
1145
1146 -- Data type: gcry_cipher_setkey_t
1147     Type for the `setkey' function, defined as: gcry_err_code_t
1148     (*gcry_cipher_setkey_t) (void *c, const unsigned char *key,
1149     unsigned keylen)
1150
1151 -- Data type: gcry_cipher_encrypt_t
1152     Type for the `encrypt' function, defined as: gcry_err_code_t
1153     (*gcry_cipher_encrypt_t) (void *c, const unsigned char *outbuf,
1154     const unsigned char *inbuf)
1155
1156 -- Data type: gcry_cipher_decrypt_t
1157     Type for the `decrypt' function, defined as: gcry_err_code_t
1158     (*gcry_cipher_decrypt_t) (void *c, const unsigned char *outbuf,
1159     const unsigned char *inbuf)
1160
1161 -- Data type: gcry_cipher_stencrypt_t
1162     Type for the `stencrypt' function, defined as: gcry_err_code_t
1163     (*gcry_cipher_stencrypt_t) (void *c, const unsigned char *outbuf,
1164     const unsigned char *, unsigned int n)
1165
1166 -- Data type: gcry_cipher_stdecrypt_t
1167     Type for the `stdecrypt' function, defined as: gcry_err_code_t
1168     (*gcry_cipher_stdecrypt_t) (void *c, const unsigned char *outbuf,
1169     const unsigned char *, unsigned int n)
1170
1171 -- Function: gcry_error_t gcry_cipher_register (gcry_cipher_spec_t
1172          *CIPHER, unsigned int *algorithm_id, gcry_module_t *MODULE)
1173     Register a new cipher module whose specification can be found in
1174     CIPHER.  On success, a new algorithm ID is stored in ALGORITHM_ID
1175     and a pointer representing this module is stored in MODULE.
1176
1177 -- Function: void gcry_cipher_unregister (gcry_module_t MODULE)
1178     Unregister the cipher identified by MODULE, which must have been
1179     registered with gcry_cipher_register.
1180
1181 -- Function: gcry_error_t gcry_cipher_list (int *LIST, int
1182          *LIST_LENGTH)
1183     Get a list consisting of the IDs of the loaded cipher modules.  If
1184     LIST is zero, write the number of loaded cipher modules to
1185     LIST_LENGTH and return.  If LIST is non-zero, the first
1186     *LIST_LENGTH algorithm IDs are stored in LIST, which must be of
1187     according size.  In case there are less cipher modules than
1188     *LIST_LENGTH, *LIST_LENGTH is updated to the correct number.
1189
1190
1191File: gcrypt.info,  Node: Available cipher modes,  Next: Working with cipher handles,  Prev: Cipher modules,  Up: Symmetric cryptography
1192
11935.3 Available cipher modes
1194==========================
1195
1196`GCRY_CIPHER_MODE_NONE'
1197     No mode specified, may be set later using other functions.  The
1198     value of this constant is always 0.
1199
1200`GCRY_CIPHER_MODE_ECB'
1201     Electronic Codebook mode.
1202
1203`GCRY_CIPHER_MODE_CFB'
1204     Cipher Feedback mode.
1205
1206`GCRY_CIPHER_MODE_CBC'
1207     Cipher Block Chaining mode.
1208
1209`GCRY_CIPHER_MODE_STREAM'
1210     Stream mode, only to be used with stream cipher algorithms.
1211
1212`GCRY_CIPHER_MODE_OFB'
1213     Outer Feedback mode.
1214
1215`GCRY_CIPHER_MODE_CTR'
1216     Counter mode.
1217
1218
1219
1220File: gcrypt.info,  Node: Working with cipher handles,  Next: General cipher functions,  Prev: Available cipher modes,  Up: Symmetric cryptography
1221
12225.4 Working with cipher handles
1223===============================
1224
1225To use a cipher algorithm, you must first allocate an according handle.
1226This is to be done using the open function:
1227
1228 -- Function: gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *HD, int
1229          ALGO, int MODE, unsigned int FLAGS)
1230     This function creates the context handle required for most of the
1231     other cipher functions and returns a handle to it in `hd'.  In
1232     case of an error, an according error code is returned.
1233
1234     The ID of algorithm to use must be specified via ALGO.  See *Note
1235     Available ciphers::, for a list of supported ciphers and the
1236     according constants.
1237
1238     Besides using the constants directly, the function
1239     `gcry_cipher_map_name' may be used to convert the textual name of
1240     an algorithm into the according numeric ID.
1241
1242     The cipher mode to use must be specified via MODE.  See *Note
1243     Available cipher modes::, for a list of supported cipher modes and
1244     the according constants.  Note, that some modes do not work
1245     together with all algorithms.
1246
1247     The third argument FLAGS can either be passed as `0' or as the
1248     bit-wise OR of the following constants.
1249
1250    `GCRY_CIPHER_SECURE'
1251          Make sure that all operations are allocated in secure memory.
1252          This is useful, when the key material is highly confidential.
1253
1254    `GCRY_CIPHER_ENABLE_SYNC'
1255          This flag enables the CFB sync mode, which is a special
1256          feature of Libgcrypt's CFB mode implementation to allow for
1257          OpenPGP's CFB variant.  See `gcry_cipher_sync'.
1258
1259    `GCRY_CIPHER_CBC_CTS'
1260          Enable cipher text stealing (CTS) for the CBC mode.  Cannot
1261          be used simultaneous as GCRY_CIPHER_CBC_MAC
1262
1263    `GCRY_CIPHER_CBC_MAC'
1264          Compute CBC-MAC keyed checksums.  This is the same as CBC
1265          mode, but only output the last block.  Cannot be used
1266          simultaneous as GCRY_CIPHER_CBC_CTS.
1267
1268   Use the following function to release an existing handle:
1269
1270 -- Function: void gcry_cipher_close (gcry_cipher_hd_t H)
1271     This function releases the context created by `gcry_cipher_open'.
1272
1273   In order to use a handle for performing cryptographic operations, a
1274`key' has to be set first:
1275
1276 -- Function: gcry_error_t gcry_cipher_setkey (gcry_cipher_hd_t H, void
1277          *K, size_t L)
1278     Set the key K used for encryption or decryption in the context
1279     denoted by the handle H.  The length L of the key K must match the
1280     required length of the algorithm set for this context or be in the
1281     allowed range for algorithms with variable key size.  The function
1282     checks this and returns an error if there is a problem.  A caller
1283     should always check for an error.
1284
1285     Note, this is currently implemented as a macro but may be changed
1286     to a function in the future.
1287
1288   Most crypto modes requires an initialization vector (IV), which
1289usually is a non-secret random string acting as a kind of salt value.
1290The CTR mode requires a counter, which is also similar to a salt value.
1291To set the IV or CTR, use these functions:
1292
1293 -- Function: gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t H, void
1294          *K, size_t L)
1295     Set the initialization vector used for encryption or decryption.
1296     The vector is passed as the buffer K of length L and copied to
1297     internal data structures.  The function checks that the IV matches
1298     the requirement of the selected algorithm and mode.  Note, that
1299     this is implemented as a macro.
1300
1301 -- Function: gcry_error_t gcry_cipher_setctr (gcry_cipher_hd_t H, void
1302          *C, size_t L)
1303     Set the counter vector used for encryption or decryption. The
1304     counter is passed as the buffer C of length L and copied to
1305     internal data structures.  The function checks that the counter
1306     matches the requirement of the selected algorithm (i.e., it must be
1307     the same size as the block size).  Note, that this is implemented
1308     as a macro.
1309
1310 -- Function: gcry_error_t gcry_cipher_reset (gcry_cipher_hd_t H)
1311     Set the given handle's context back to the state it had after the
1312     last call to gcry_cipher_setkey and clear the initialization
1313     vector.
1314
1315     Note, that gcry_cipher_reset is implemented as a macro.
1316
1317   The actual encryption and decryption is done by using one of the
1318following functions.  They may be used as often as required to process
1319all the data.
1320
1321 -- Function: gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t H,
1322          void *out, size_t OUTSIZE, const void *IN, size_t INLEN)
1323     `gcry_cipher_encrypt' is used to encrypt the data.  This function
1324     can either work in place or with two buffers.  It uses the cipher
1325     context already setup and described by the handle H.  There are 2
1326     ways to use the function: If IN is passed as `NULL' and INLEN is
1327     `0', in-place encryption of the data in OUT or length OUTSIZE
1328     takes place.  With IN being not `NULL', INLEN bytes are encrypted
1329     to the buffer OUT which must have at least a size of INLEN.
1330     OUTLEN must be set to the allocated size of OUT, so that the
1331     function can check that there is sufficient space. Note, that
1332     overlapping buffers are not allowed.
1333
1334     Depending on the selected algorithms and encryption mode, the
1335     length of the buffers must be a multiple of the block size.
1336
1337     The function returns `0' on success or an error code.
1338
1339 -- Function: gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t H,
1340          void *out, size_t OUTSIZE, const void *IN, size_t INLEN)
1341     `gcry_cipher_decrypt' is used to decrypt the data.  This function
1342     can either work in place or with two buffers.  It uses the cipher
1343     context already setup and described by the handle H.  There are 2
1344     ways to use the function: If IN is passed as `NULL' and INLEN is
1345     `0', in-place decryption of the data in OUT or length OUTSIZE
1346     takes place.  With IN being not `NULL', INLEN bytes are decrypted
1347     to the buffer OUT which must have at least a size of INLEN.
1348     OUTLEN must be set to the allocated size of OUT, so that the
1349     function can check that there is sufficient space. Note, that
1350     overlapping buffers are not allowed.
1351
1352     Depending on the selected algorithms and encryption mode, the
1353     length of the buffers must be a multiple of the block size.
1354
1355     The function returns `0' on success or an error code.
1356
1357   OpenPGP (as defined in RFC-2440) requires a special sync operation in
1358some places, the following function is used for this:
1359
1360 -- Function: gcry_error_t gcry_cipher_sync (gcry_cipher_hd_t H)
1361     Perform the OpenPGP sync operation on context H. Note, that this
1362     is a no-op unless the context was created with the flag
1363     `GCRY_CIPHER_ENABLE_SYNC'
1364
1365   Some of the described functions are implemented as macros utilizing a
1366catch-all control function.  This control function is rarely used
1367directly but there is nothing which would inhibit it:
1368
1369 -- Function: gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t H, int
1370          CMD, void *BUFFER, size_t BUFLEN)
1371     `gcry_cipher_ctl' controls various aspects of the cipher module and
1372     specific cipher contexts.  Usually some more specialized functions
1373     or macros are used for this purpose.  The semantics of the
1374     function and its parameters depends on the the command CMD and the
1375     passed context handle H.  Please see the comments in the source
1376     code (`src/global.c') for details.
1377
1378 -- Function: gcry_error_t gcry_cipher_info (gcry_cipher_hd_t H, int
1379          WHAT, void *BUFFER, size_t *NBYTES)
1380     `gcry_cipher_info' is used to retrieve various information about a
1381     cipher context or the cipher module in general.
1382
1383     Currently no information is available.
1384
1385
1386File: gcrypt.info,  Node: General cipher functions,  Prev: Working with cipher handles,  Up: Symmetric cryptography
1387
13885.5 General cipher functions
1389============================
1390
1391To work with the algorithms, several functions are available to map
1392algorithm names to the internal identifiers, as well as ways to
1393retrieve information about an algorithm or the current cipher context.
1394
1395 -- Function: gcry_error_t gcry_cipher_algo_info (int ALGO, int WHAT,
1396          void *BUFFER, size_t *NBYTES)
1397     This function is used to retrieve information on a specific
1398     algorithm.  You pass the cipher algorithm ID as ALGO and the type
1399     of information requested as WHAT. The result is either returned as
1400     the return code of the function or copied to the provided BUFFER
1401     whose allocated length must be available in an integer variable
1402     with the address passed in NBYTES.  This variable will also
1403     receive the actual used length of the buffer.
1404
1405     Here is a list of supported codes for WHAT:
1406
1407    `GCRYCTL_GET_KEYLEN:'
1408          Return the length of the key. If the algorithm supports
1409          multiple key lengths, the maximum supported value is
1410          returned.  The length is returned as number of octets (bytes)
1411          and not as number of bits in NBYTES; BUFFER must be zero.
1412
1413    `GCRYCTL_GET_BLKLEN:'
1414          Return the block length of the algorithm.  The length is
1415          returned as a number of octets in NBYTES; BUFFER must be zero.
1416
1417    `GCRYCTL_TEST_ALGO:'
1418          Returns `0' when the specified algorithm is available for use.
1419          BUFFER and NBYTES must be zero.
1420
1421
1422
1423 -- Function: const char *gcry_cipher_algo_name (int ALGO)
1424     `gcry_cipher_algo_name' returns a string with the name of the
1425     cipher algorithm ALGO.  If the algorithm is not known or another
1426     error occurred, an empty string is returned.  This function will
1427     never return `NULL'.
1428
1429 -- Function: int gcry_cipher_map_name (const char *NAME)
1430     `gcry_cipher_map_name' returns the algorithm identifier for the
1431     cipher algorithm described by the string NAME.  If this algorithm
1432     is not available `0' is returned.
1433
1434 -- Function: int gcry_cipher_mode_from_oid (const char *STRING)
1435     Return the cipher mode associated with an ASN.1 object identifier.
1436     The object identifier is expected to be in the IETF-style dotted
1437     decimal notation.  The function returns `0' for an unknown object
1438     identifier or when no mode is associated with it.
1439
1440
1441File: gcrypt.info,  Node: Hashing,  Next: Public Key cryptography (I),  Prev: Symmetric cryptography,  Up: Top
1442
14436 Hashing
1444*********
1445
1446Libgcrypt provides an easy and consistent to use interface for hashing.
1447Hashing is buffered and several hash algorithms can be updated at
1448once.  It is possible to calculate a MAC using the same routines.  The
1449programming model follows an open/process/close paradigm and is in that
1450similar to other building blocks provided by Libgcrypt.
1451
1452   For convenience reasons, a few cyclic redundancy check value
1453operations are also supported.
1454
1455* Menu:
1456
1457* Available hash algorithms::   List of hash algorithms supported by the library.
1458* Hash algorithm modules::      How to work with hash algorithm modules.
1459* Working with hash algorithms::  List of functions related to hashing.
1460
1461
1462File: gcrypt.info,  Node: Available hash algorithms,  Next: Hash algorithm modules,  Up: Hashing
1463
14646.1 Available hash algorithms
1465=============================
1466
1467`GCRY_MD_NONE'
1468     This is not a real algorithm but used by some functions as an error
1469     return value.  This constant is guaranteed to have the value `0'.
1470
1471`GCRY_MD_SHA1'
1472     This is the SHA-1 algorithm which yields a message digest of 20
1473     bytes.
1474
1475`GCRY_MD_RMD160'
1476     This is the 160 bit version of the RIPE message digest
1477     (RIPE-MD-160).  Like SHA-1 it also yields a digest of 20 bytes.
1478
1479`GCRY_MD_MD5'
1480     This is the well known MD5 algorithm, which yields a message
1481     digest of 16 bytes.
1482
1483`GCRY_MD_MD4'
1484     This is the MD4 algorithm, which yields a message digest of 16
1485     bytes.
1486
1487`GCRY_MD_MD2'
1488     This is an reserved identifier for MD-2; there is no
1489     implementation yet.
1490
1491`GCRY_MD_TIGER'
1492     This is the TIGER/192 algorithm which yields a message digest of
1493     24 bytes.
1494
1495`GCRY_MD_HAVAL'
1496     This is an reserved for the HAVAL algorithm with 5 passes and 160
1497     bit. It yields a message digest of 20 bytes.  Note that there is no
1498     implementation yet available.
1499
1500`GCRY_MD_SHA256'
1501     This is the SHA-256 algorithm which yields a message digest of 32
1502     bytes.  See FIPS 180-2 for the specification.
1503
1504`GCRY_MD_SHA384'
1505     This is reserved for SHA-2 with 384 bits. It yields a message
1506     digest of 48 bytes.  Note that there is no implementation yet
1507     available.
1508
1509`GCRY_MD_SHA512'
1510     This is reserved for SHA-2 with 512 bits. It yields a message
1511     digest of 64 bytes.  Note that there is no implementation yet
1512     available.
1513
1514`GCRY_MD_CRC32'
1515     This is the ISO 3309 and ITU-T V.42 cyclic redundancy check.  It
1516     yields an output of 4 bytes.
1517
1518`GCRY_MD_CRC32_RFC1510'
1519     This is the above cyclic redundancy check function, as modified by
1520     RFC 1510.  It yields an output of 4 bytes.
1521
1522`GCRY_MD_CRC24_RFC2440'
1523     This is the OpenPGP cyclic redundancy check function.  It yields an
1524     output of 3 bytes.
1525
1526
1527
1528File: gcrypt.info,  Node: Hash algorithm modules,  Next: Working with hash algorithms,  Prev: Available hash algorithms,  Up: Hashing
1529
15306.2 Hash algorithm modules
1531==========================
1532
1533Libgcrypt makes it possible to load additional `message digest
1534modules'; these cipher can be used just like the message digest
1535algorithms that are built into the library directly.  For an
1536introduction into extension modules, see *Note Modules::.
1537
1538 -- Data type: gcry_md_spec_t
1539     This is the `module specification structure' needed for registering
1540     message digest modules, which has to be filled in by the user
1541     before it can be used to register a module.  It contains the
1542     following members:
1543
1544    `const char *name'
1545          The primary name of this algorithm.
1546
1547    `unsigned char *asnoid'
1548          Array of bytes that form the ASN OID.
1549
1550    `int asnlen'
1551          Length of bytes in `asnoid'.
1552
1553    `gcry_md_oid_spec_t *oids'
1554          A list of OIDs that are to be associated with the algorithm.
1555          The list's last element must have it's `oid' member set to
1556          NULL.  See below for an explanation of this type.  See below
1557          for an explanation of this type.
1558
1559    `int mdlen'
1560          Length of the message digest algorithm.  See below for an
1561          explanation of this type.
1562
1563    `gcry_md_init_t init'
1564          The function responsible for initializing a handle.  See
1565          below for an explanation of this type.
1566
1567    `gcry_md_write_t write'
1568          The function responsible for writing data into a message
1569          digest context.  See below for an explanation of this type.
1570
1571    `gcry_md_final_t final'
1572          The function responsible for `finalizing' a message digest
1573          context.  See below for an explanation of this type.
1574
1575    `gcry_md_read_t read'
1576          The function responsible for reading out a message digest
1577          result.  See below for an explanation of this type.
1578
1579    `size_t contextsize'
1580          The size of the algorithm-specific `context', that should be
1581          allocated for each handle.
1582
1583 -- Data type: gcry_md_oid_spec_t
1584     This type is used for associating a user-provided algorithm
1585     implementation with certain OIDs.  It contains the following
1586     members:
1587
1588    `const char *oidstring'
1589          Textual representation of the OID.
1590
1591 -- Data type: gcry_md_init_t
1592     Type for the `init' function, defined as: void (*gcry_md_init_t)
1593     (void *c)
1594
1595 -- Data type: gcry_md_write_t
1596     Type for the `write' function, defined as: void (*gcry_md_write_t)
1597     (void *c, unsigned char *buf, size_t nbytes)
1598
1599 -- Data type: gcry_md_final_t
1600     Type for the `final' function, defined as: void (*gcry_md_final_t)
1601     (void *c)
1602
1603 -- Data type: gcry_md_read_t
1604     Type for the `read' function, defined as: unsigned char
1605     *(*gcry_md_read_t) (void *c)
1606
1607 -- Function: gcry_error_t gcry_md_register (gcry_md_spec_t *DIGEST,
1608          unsigned int *algorithm_id, gcry_module_t *MODULE)
1609     Register a new digest module whose specification can be found in
1610     DIGEST.  On success, a new algorithm ID is stored in ALGORITHM_ID
1611     and a pointer representing this module is stored in MODULE.
1612
1613 -- Function: void gcry_md_unregister (gcry_module_t MODULE)
1614     Unregister the digest identified by MODULE, which must have been
1615     registered with gcry_md_register.
1616
1617 -- Function: gcry_error_t gcry_md_list (int *LIST, int *LIST_LENGTH)
1618     Get a list consisting of the IDs of the loaded message digest
1619     modules.  If LIST is zero, write the number of loaded message
1620     digest modules to LIST_LENGTH and return.  If LIST is non-zero,
1621     the first *LIST_LENGTH algorithm IDs are stored in LIST, which
1622     must be of according size.  In case there are less message digests
1623     modules than *LIST_LENGTH, *LIST_LENGTH is updated to the correct
1624     number.
1625
1626
1627File: gcrypt.info,  Node: Working with hash algorithms,  Prev: Hash algorithm modules,  Up: Hashing
1628
16296.3 Working with hash algorithms
1630================================
1631
1632To use most of these function it is necessary to create a context; this
1633is done using:
1634
1635 -- Function: gcry_error_t gcry_md_open (gcry_md_hd_t *HD, int ALGO,
1636          unsigned int FLAGS)
1637     Create a message digest object for algorithm ALGO.  FLAGS may be
1638     given as an bitwise OR of constants described below.  ALGO may be
1639     given as `0' if the algorithms to use are later set using
1640     `gcry_md_enable'. HD is guaranteed to either receive a valid
1641     handle or NULL.
1642
1643     For a list of supported algorithms, see *Note Available hash
1644     algorithms::.
1645
1646     The flags allowed for MODE are:
1647
1648    `GCRY_MD_FLAG_SECURE'
1649          Allocate all buffers and the resulting digest in "secure
1650          memory".  Use this is the hashed data is highly confidential.
1651
1652    `GCRY_MD_FLAG_HMAC'
1653          Turn the algorithm into a HMAC message authentication
1654          algorithm.  This does only work if just one algorithm is
1655          enabled for the handle and SHA-384 and SHA512 is not used.
1656          Note that the function `gcry_md_setkey' must be used set the
1657          MAC key.  If you want CBC message authentication codes based
1658          on a cipher, see *Note Working with cipher handles::.
1659
1660
1661     You may use the function `gcry_md_is_enabled' to later check
1662     whether an algorithm has been enabled.
1663
1664
1665   If you want to calculate several hash algorithms at the same time,
1666you have to use the following function right after the `gcry_md_open':
1667
1668 -- Function: gcry_error_t gcry_md_enable (gcry_md_hd_t H, int ALGO)
1669     Add the message digest algorithm ALGO to the digest object
1670     described by handle H.  Duplicated enabling of algorithms is
1671     detected and ignored.
1672
1673   If the flag `GCRY_MD_FLAG_HMAC' was used, the key for the MAC must
1674be set using the function:
1675
1676 -- Function: gcry_error_t gcry_md_setkey (gcry_md_hd_t H, const void
1677          *KEY, size_t KEYLEN)
1678     For use with the HMAC feature, set the MAC key to the value of KEY
1679     of length KEYLEN.
1680
1681   After you are done with the hash calculation, you should release the
1682resources by using:
1683
1684 -- Function: void gcry_md_close (gcry_md_hd_t H)
1685     Release all resources of hash context H.  H should not be used
1686     after a call to this function.  A `NULL' passed as H is ignored.
1687
1688
1689   Often you have to do several hash operations using the same
1690algorithm.  To avoid the overhead of creating and releasing context, a
1691reset function is provided:
1692
1693 -- Function: void gcry_md_reset (gcry_md_hd_t H)
1694     Reset the current context to its initial state.  This is
1695     effectively identical to a close followed by an open and enabling
1696     all currently active algorithms.
1697
1698   Often it is necessary to start hashing some data and than continue to
1699hash different data.  To avoid hashing the same data several times
1700(which might not even be possible if the data is received from a pipe),
1701a snapshot of the current hash context can be taken and turned into a
1702new context:
1703
1704 -- Function: gcry_error_t gcry_md_copy (gcry_md_hd_t *HANDLE_DST,
1705          gcry_md_hd_t HANDLE_SRC)
1706     Create a new digest object as an exact copy of the object
1707     described by handle HANDLE_SRC and store it in HANDLE_DST.  The
1708     context is not reset and you can continue to hash data using this
1709     context and independently using the original context.
1710
1711   Now that we have prepared everything to calculate hashes, its time to
1712see how it is actually done.  There are 2  ways for this, one to update
1713the hash with a block of memory and one macro to update the hash by
1714just one character.  Both may be used intermixed.
1715
1716 -- Function: void gcry_md_write (gcry_md_hd_t H, const void *BUFFER,
1717          size_t LENGTH)
1718     Pass LENGTH bytes of the data in BUFFER to the digest object with
1719     handle H to update the digest values. This function should be used
1720     for large blocks of data.
1721
1722 -- Function: void gcry_md_putc (gcry_md_hd_t H, int C)
1723     Pass the byte in C to the digest object with handle H to update
1724     the digest value.  This is an efficient function, implemented as a
1725     macro to buffer the data before an actual update.
1726
1727   The semantics of the hash functions don't allow to read out
1728intermediate message digests because the calculation must be finalized
1729fist.  This finalization may for example include the number of bytes
1730hashed in the message digest.
1731
1732 -- Function: void gcry_md_final (gcry_md_hd_t H)
1733     Finalize the message digest calculation.  This is not really needed
1734     because `gcry_md_read' does this implicitly.  After this has been
1735     done no further updates (by means of `gcry_md_write' or
1736     `gcry_md_putc' are allowed.  Only the first call to this function
1737     has an effect. It is implemented as a macro.
1738
1739   The way to read out the calculated message digest is by using the
1740function:
1741
1742 -- Function: unsigned char *gcry_md_read (gcry_md_hd_t H, int ALGO)
1743     `gcry_md_read' returns the message digest after finalizing the
1744     calculation.  This function may be used as often as required but
1745     it will always return the same value for one handle.  The returned
1746     message digest is allocated within the message context and
1747     therefore valid until the handle is released or reseted (using
1748     `gcry_md_close' or `gcry_md_reset'.  ALGO may be given as 0 to
1749     return the only enabled message digest or it may specify one of
1750     the enabled algorithms.  The function does return `NULL' if the
1751     requested algorithm has not been enabled.
1752
1753   Because it is often necessary to get the message digest of one block
1754of memory, a fast convenience function is available for this task:
1755
1756 -- Function: void gcry_md_hash_buffer (int ALGO, void *DIGEST, const
1757          cvoid *BUFFER, size_t LENGTH);
1758     `gcry_md_hash_buffer' is a shortcut function to calculate a message
1759     digest of a buffer.  This function does not require a context and
1760     immediately returns the message digest of the LENGTH bytes at
1761     BUFFER.  DIGEST must be allocated by the caller, large enough to
1762     hold the message digest yielded by the the specified algorithm
1763     ALGO.  This required size may be obtained by using the function
1764     `gcry_md_get_algo_dlen'.
1765
1766     Note, that this function will abort the process if an unavailable
1767     algorithm is used.
1768
1769   Hash algorithms are identified by internal algorithm numbers (see
1770`gcry_md_open' for a list.  However, in most applications they are used
1771by names, so 2 functions are available to map between string
1772representations and hash algorithm identifiers.
1773
1774 -- Function: const char *gcry_md_algo_name (int ALGO)
1775     Map the digest algorithm id ALGO to a string representation of the
1776     algorithm name.  For unknown algorithms this functions returns an
1777     empty string.  This function should not be used to test for the
1778     availability of an algorithm.
1779
1780 -- Function: int gcry_md_map_name (const char *NAME)
1781     Map the algorithm with NAME to a digest algorithm identifier.
1782     Returns 0 if the algorithm name is not known.  Names representing
1783     ASN.1 object identifiers are recognized if the IETF dotted format
1784     is used and the OID is prefixed with either "`oid.'" or "`OID.'".
1785     For a list of supported OIDs, see the source code at
1786     `cipher/md.c'. This function should not be used to test for the
1787     availability of an algorithm.
1788
1789 -- Function: gcry_error_t gcry_md_get_asnoid (int ALGO, void *BUFFER,
1790          size_t *LENGTH)
1791     Return an DER encoded ASN.1 OID for the algorithm ALGO in the user
1792     allocated BUFFER. LENGTH must point to variable with the available
1793     size of BUFFER and receives after return the actual size of the
1794     returned OID.  The returned error code may be `GPG_ERR_TOO_SHORT'
1795     if the provided buffer is to short to receive the OID; it is
1796     possible to call the function with `NULL' for BUFFER to have it
1797     only return the required size.  The function returns 0 on success.
1798
1799
1800   To test whether an algorithm is actually available for use, the
1801following macro should be used:
1802
1803 -- Function: gcry_error_t gcry_md_test_algo (int ALGO)
1804     The macro returns 0 if the algorithm ALGO is available for use.
1805
1806   If the length of a message digest is not known, it can be retrieved
1807using the following function:
1808
1809 -- Function: unsigned int gcry_md_get_algo_dlen (int ALGO)
1810     Retrieve the length in bytes of the digest yielded by algorithm
1811     ALGO.  This is often used prior to `gcry_md_read' to allocate
1812     sufficient memory for the digest.
1813
1814   In some situations it might be hard to remember the algorithm used
1815for the ongoing hashing. The following function might be used to get
1816that information:
1817
1818 -- Function: int gcry_md_get_algo (gcry_md_hd_t H)
1819     Retrieve the algorithm used with the handle H. Note, that this
1820     does not work reliable if more than one algorithm is enabled in H.
1821
1822   The following macro might also be useful:
1823
1824 -- Function: int gcry_md_is_secure (gcry_md_hd_t H)
1825     This function returns true when the digest object H is allocated
1826     in "secure memory"; i.e. H was created with the
1827     `GCRY_MD_FLAG_SECURE'.
1828
1829 -- Function: int gcry_md_is_enabled (gcry_md_hd_t H, int ALGO)
1830     This function returns true when the algorithm ALGO has been
1831     enabled for the digest object H.
1832
1833   Tracking bugs related to hashing is often a cumbersome task which
1834requires to add a lot of printf statements into the code.  Libgcrypt
1835provides an easy way to avoid this.  The actual data hashed can be
1836written to files on request.  The following 2 macros should be used to
1837implement such a debugging facility:
1838
1839 -- Function: void gcry_md_start_debug (gcry_md_hd_t H, const char
1840          *SUFFIX)
1841     Enable debugging for the digest object with handle H.  This
1842     creates create files named `dbgmd-<n>.<string>' while doing the
1843     actual hashing.  SUFFIX is the string part in the filename.  The
1844     number is a counter incremented for each new hashing.  The data in
1845     the file is the raw data as passed to `gcry_md_write' or
1846     `gcry_md_putc'.
1847
1848 -- Function: void gcry_md_stop_debug (gcry_md_hd_t H, int RESERVED)
1849     Stop debugging on handle H.  RESERVED should be specified as 0.
1850     This function is usually not required because `gcry_md_close' does
1851     implicitly stop debugging.
1852
1853
1854File: gcrypt.info,  Node: Public Key cryptography (I),  Next: Public Key cryptography (II),  Prev: Hashing,  Up: Top
1855
18567 Public Key cryptography (I)
1857*****************************
1858
1859Public key cryptography, also known as asymmetric cryptography, is an
1860easy way for key management and to provide digital signatures.
1861Libgcrypt provides two completely different interfaces to public key
1862cryptography, this chapter explains the one based on S-expressions.
1863
1864* Menu:
1865
1866* Available algorithms::        Algorithms supported by the library.
1867* Used S-expressions::          Introduction into the used S-expression.
1868* Public key modules::          How to work with public key modules.
1869* Cryptographic Functions::     Functions for performing the cryptographic actions.
1870* General public-key related Functions::  General functions, not implementing any cryptography.
1871
1872
1873File: gcrypt.info,  Node: Available algorithms,  Next: Used S-expressions,  Up: Public Key cryptography (I)
1874
18757.1 Available algorithms
1876========================
1877
1878Libgcrypt supports the RSA (Rivest-Shamir-Adleman) algorithms as well
1879as DSA (Digital Signature Algorithm) and ElGamal.  The versatile
1880interface allows to add more algorithms in the future.
1881
1882
1883File: gcrypt.info,  Node: Used S-expressions,  Next: Public key modules,  Prev: Available algorithms,  Up: Public Key cryptography (I)
1884
18857.2 Used S-expressions
1886======================
1887
1888Libgcrypt's API for asymmetric cryptography is based on data structures
1889called S-expressions (see XXXX) and does not work with contexts as most
1890of the other building blocks of Libgcrypt do.
1891
1892   The following information are stored in S-expressions:
1893
1894keys
1895
1896plain text data
1897
1898encrypted data
1899
1900signatures
1901
1902To describe how Libgcrypt expect keys, we use some examples. Note that
1903words in uppercase indicate parameters whereas lowercase words are
1904literals.
1905
1906     (private-key
1907       (dsa
1908         (p P-MPI)
1909         (q Q-MPI)
1910         (g G-MPI)
1911         (y Y-MPI)
1912         (x X-MPI)))
1913
1914This specifies a DSA private key with the following parameters:
1915
1916P-MPI
1917     DSA prime p.
1918
1919Q-MPI
1920     DSA group order q (which is a prime divisor of p-1).
1921
1922G-MPI
1923     DSA group generator g.
1924
1925Y-MPI
1926     DSA public key value y = g^x \bmod p.
1927
1928X-MPI
1929     DSA secret exponent x.
1930
1931   All the MPI values are  expected to be in `GCRYMPI_FMT_USG' format.
1932The public key is similar with "private-key" replaced by "public-key"
1933and no X-MPI.
1934
1935   An easy way to create such an S-expressions is by using
1936`gcry_sexp_build' which allows to pass a string with printf-like
1937escapes to insert MPI values.
1938
1939Here is an example for an RSA key:
1940
1941     (private-key
1942       (rsa
1943         (n N-MPI)
1944         (e E-MPI)
1945         (d D-MPI)
1946         (p P-MPI)
1947         (q Q-MPI)
1948         (u U-MPI)
1949
1950with
1951
1952N-MPI
1953     RSA public modulus n.
1954
1955E-MPI
1956     RSA public exponent e.
1957
1958D-MPI
1959     RSA secret exponent d = e^-1 \bmod (p-1)(q-1).
1960
1961P-MPI
1962     RSA secret prime p.
1963
1964Q-MPI
1965     RSA secret prime q with q > p.
1966
1967U-MPI
1968     multiplicative inverse u = p^-1 \bmod q.
1969
1970
1971File: gcrypt.info,  Node: Public key modules,  Next: Cryptographic Functions,  Prev: Used S-expressions,  Up: Public Key cryptography (I)
1972
19737.3 Public key modules
1974======================
1975
1976Libgcrypt makes it possible to load additional `public key modules';
1977these public key algorithms can be used just like the algorithms that
1978are built into the library directly.  For an introduction into
1979extension modules, see *Note Modules::.
1980
1981 -- Data type: gcry_pk_spec_t
1982     This is the `module specification structure' needed for registering
1983     public key modules, which has to be filled in by the user before it
1984     can be used to register a module.  It contains the following
1985     members:
1986
1987    `const char *name'
1988          The primary name of this algorithm.
1989
1990    `char **aliases'
1991          A list of strings that are `aliases' for the algorithm.  The
1992          list must be terminated with a NULL element.
1993
1994    `const char *elements_pkey'
1995          String containing the one-letter names of the MPI values
1996          contained in a public key.
1997
1998    `const char *element_skey'
1999          String containing the one-letter names of the MPI values
2000          contained in a secret key.
2001
2002    `const char *elements_enc'
2003          String containing the one-letter names of the MPI values that
2004          are the result of an encryption operation using this
2005          algorithm.
2006
2007    `const char *elements_sig'
2008          String containing the one-letter names of the MPI values that
2009          are the result of a sign operation using this algorithm.
2010
2011    `const char *elements_grip'
2012          String containing the one-letter names of the MPI values that
2013          are to be included in the `key grip'.
2014
2015    `int use'
2016          The bitwise-OR of the following flags, depending on the
2017          abilities of the algorithm:
2018         `GCRY_PK_USAGE_SIGN'
2019               The algorithm supports signing and verifying of data.
2020
2021         `GCRY_PK_USAGE_ENCR'
2022               The algorithm supports the encryption and decryption of
2023               data.
2024
2025    `gcry_pk_generate_t generate'
2026          The function responsible for generating a new key pair.  See
2027          below for a description of this type.
2028
2029    `gcry_pk_check_secret_key_t check_secret_key'
2030          The function responsible for checking the sanity of a
2031          provided secret key.  See below for a description of this
2032          type.
2033
2034    `gcry_pk_encrypt_t encrypt'
2035          The function responsible for encrypting data.  See below for a
2036          description of this type.
2037
2038    `gcry_pk_decrypt_t decrypt'
2039          The function responsible for decrypting data.  See below for a
2040          description of this type.
2041
2042    `gcry_pk_sign_t sign'
2043          The function responsible for signing data.  See below for a
2044          description of this type.
2045
2046    `gcry_pk_verify_t verify'
2047          The function responsible for verifying that the provided
2048          signature matches the provided data.  See below for a
2049          description of this type.
2050
2051    `gcry_pk_get_nbits_t get_nbits'
2052          The function responsible for returning the number of bits of
2053          a provided key.  See below for a description of this type.
2054
2055 -- Data type: gcry_pk_generate_t
2056     Type for the `generate' function, defined as: gcry_err_code_t
2057     (*gcry_pk_generate_t) (int algo, unsigned int nbits, unsigned long
2058     use_e, gcry_mpi_t *skey, gcry_mpi_t **retfactors)
2059
2060 -- Data type: gcry_pk_check_secret_key_t
2061     Type for the `check_secret_key' function, defined as:
2062     gcry_err_code_t (*gcry_pk_check_secret_key_t) (int algo,
2063     gcry_mpi_t *skey)
2064
2065 -- Data type: gcry_pk_encrypt_t
2066     Type for the `encrypt' function, defined as: gcry_err_code_t
2067     (*gcry_pk_encrypt_t) (int algo, gcry_mpi_t *resarr, gcry_mpi_t
2068     data, gcry_mpi_t *pkey, int flags)
2069
2070 -- Data type: gcry_pk_decrypt_t
2071     Type for the `decrypt' function, defined as: gcry_err_code_t
2072     (*gcry_pk_decrypt_t) (int algo, gcry_mpi_t *result, gcry_mpi_t
2073     *data, gcry_mpi_t *skey, int flags)
2074
2075 -- Data type: gcry_pk_sign_t
2076     Type for the `sign' function, defined as: gcry_err_code_t
2077     (*gcry_pk_sign_t) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data,
2078     gcry_mpi_t *skey)
2079
2080 -- Data type: gcry_pk_verify_t
2081     Type for the `verify' function, defined as: gcry_err_code_t
2082     (*gcry_pk_verify_t) (int algo, gcry_mpi_t hash, gcry_mpi_t *data,
2083     gcry_mpi_t *pkey, int (*cmp) (void *, gcry_mpi_t), void *opaquev)
2084
2085 -- Data type: gcry_pk_get_nbits_t
2086     Type for the `get_nbits' function, defined as: unsigned
2087     (*gcry_pk_get_nbits_t) (int algo, gcry_mpi_t *pkey)
2088
2089 -- Function: gcry_error_t gcry_pk_register (gcry_pk_spec_t *PUBKEY,
2090          unsigned int *algorithm_id, gcry_module_t *MODULE)
2091     Register a new public key module whose specification can be found
2092     in PUBKEY.  On success, a new algorithm ID is stored in
2093     ALGORITHM_ID and a pointer representing this module is stored in
2094     MODULE.
2095
2096 -- Function: void gcry_pk_unregister (gcry_module_t MODULE)
2097     Unregister the public key module identified by MODULE, which must
2098     have been registered with gcry_pk_register.
2099
2100 -- Function: gcry_error_t gcry_pk_list (int *LIST, int *LIST_LENGTH)
2101     Get a list consisting of the IDs of the loaded pubkey modules.  If
2102     LIST is zero, write the number of loaded pubkey modules to
2103     LIST_LENGTH and return.  If LIST is non-zero, the first
2104     *LIST_LENGTH algorithm IDs are stored in LIST, which must be of
2105     according size.  In case there are less pubkey modules than
2106     *LIST_LENGTH, *LIST_LENGTH is updated to the correct number.
2107
2108
2109File: gcrypt.info,  Node: Cryptographic Functions,  Next: General public-key related Functions,  Prev: Public key modules,  Up: Public Key cryptography (I)
2110
21117.4 Cryptographic Functions
2112===========================
2113
2114Note, that we will in future allow to use keys without p,q and u
2115specified and may also support other parameters for performance reasons.
2116
2117Some functions operating on S-expressions support `flags', that
2118influence the operation.  These flags have to be listed in a
2119sub-S-expression named `flags'; the following flags are known:
2120
2121PKCS1
2122     Use PKCS#1 block type 2 padding.
2123
2124NO-BLINDING
2125     Do not use a technique called `blinding', which is used by default
2126     in order to prevent leaking of secret information.  Blinding is
2127     only implemented by RSA, but it might be implemented by other
2128     algorithms in the future as well, when necessary.
2129
2130Now that we know the key basics, we can carry on and explain how to
2131encrypt and decrypt data.  In almost all cases the data is a random
2132session key which is in turn used for the actual encryption of the real
2133data.  There are 2 functions to do this:
2134
2135 -- Function: gcry_error_t gcry_pk_encrypt (gcry_sexp_t *R_CIPH,
2136          gcry_sexp_t DATA, gcry_sexp_t PKEY)
2137     Obviously a public key must be provided for encryption.  It is
2138     expected as an appropriate S-expression (see above) in PKEY.  The
2139     data to be encrypted can either be in the simple old format, which
2140     is a very simple S-expression consisting only of one MPI, or it
2141     may be a more complex S-expression which also allows to specify
2142     flags for operation, like e.g. padding rules.
2143
2144     If you don't want to let Libgcrypt handle the padding, you must
2145     pass an appropriate MPI using this expression for DATA:
2146
2147          (data
2148            (flags raw)
2149            (value MPI))
2150
2151     This has the same semantics as the old style MPI only way.  MPI is
2152     the actual data, already padded appropriate for your protocol.
2153     Most systems however use PKCS#1 padding and so you can use this
2154     S-expression for DATA:
2155
2156          (data
2157            (flags pkcs1)
2158            (value BLOCK))
2159
2160     Here, the "flags" list has the "pkcs1" flag which let the function
2161     know that it should provide PKCS#1 block type 2 padding.  The
2162     actual data to be encrypted is passed as a string of octets in
2163     BLOCK.  The function checks that this data actually can be used
2164     with the given key, does the padding and encrypts it.
2165
2166     If the function could successfully perform the encryption, the
2167     return value will be 0 and a a new S-expression with the encrypted
2168     result is allocated and assign to the variable at the address of
2169     R_CIPH.  The caller is responsible to release this value using
2170     `gcry_sexp_release'.  In case of an error, an error code is
2171     returned and R_CIPH will be set to `NULL'.
2172
2173     The returned S-expression has this format when used with RSA:
2174
2175          (enc-val
2176            (rsa
2177              (a A-MPI)))
2178
2179     Where A-MPI is an MPI with the result of the RSA operation.  When
2180     using the ElGamal algorithm, the return value will have this
2181     format:
2182
2183          (enc-val
2184            (elg
2185              (a A-MPI)
2186              (b B-MPI)))
2187
2188     Where A-MPI and B-MPI are MPIs with the result of the ElGamal
2189     encryption operation.
2190
2191 -- Function: gcry_error_t gcry_pk_decrypt (gcry_sexp_t *R_PLAIN,
2192          gcry_sexp_t DATA, gcry_sexp_t SKEY)
2193     Obviously a private key must be provided for decryption.  It is
2194     expected as an appropriate S-expression (see above) in SKEY.  The
2195     data to be decrypted must match the format of the result as
2196     returned by `gcry_pk_encrypt', but should be enlarged with a
2197     `flags' element:
2198
2199          (enc-val
2200            (flags)
2201            (elg
2202              (a A-MPI)
2203              (b B-MPI)))
2204
2205     Note, that this function currently does not know of any padding
2206     methods and the caller must do any un-padding on his own.
2207
2208     The function returns 0 on success or an error code.  The variable
2209     at the address of R_PLAIN will be set to NULL on error or receive
2210     the decrypted value on success.  The format of R_PLAIN is a simple
2211     S-expression part (i.e. not a valid one) with just one MPI if
2212     there was no `flags' element in DATA; if at least an empty `flags'
2213     is passed in DATA, the format is:
2214
2215          (value PLAINTEXT)
2216
2217   Another operation commonly performed using public key cryptography is
2218signing data.  In some sense this is even more important than
2219encryption because digital signatures are an important instrument for
2220key management.  Libgcrypt supports digital signatures using 2
2221functions, similar to the encryption functions:
2222
2223 -- Function: gcry_error_t gcry_pk_sign (gcry_sexp_t *R_SIG,
2224          gcry_sexp_t DATA, gcry_sexp_t SKEY)
2225     This function creates a digital signature for DATA using the
2226     private key SKEY and place it into the variable at the address of
2227     R_SIG.  DATA may either be the simple old style S-expression with
2228     just one MPI or a modern and more versatile S-expression which
2229     allows to let Libgcrypt handle padding:
2230
2231           (data
2232            (flags pkcs1)
2233            (hash HASH-ALGO BLOCK))
2234
2235     This example requests to sign the data in BLOCK after applying
2236     PKCS#1 block type 1 style padding.  HASH-ALGO is a string with the
2237     hash algorithm to be encoded into the signature, this may be any
2238     hash algorithm name as supported by Libgcrypt.  Most likely, this
2239     will be "sha1", "rmd160" or "md5".  It is obvious that the length
2240     of BLOCK must match the size of that message digests; the function
2241     checks that this and other constraints are valid.
2242
2243     If PKCS#1 padding is not required (because the caller does already
2244     provide a padded value), either the old format or better the
2245     following format should be used:
2246
2247          (data
2248            (flags raw)
2249            (value MPI))
2250
2251     Here, the data to be signed is directly given as an MPI.
2252
2253     The signature is returned as a newly allocated S-expression in
2254     R_SIG using this format for RSA:
2255
2256          (sig-val
2257            (rsa
2258              (s S-MPI)))
2259
2260     Where S-MPI is the result of the RSA sign operation.  For DSA the
2261     S-expression returned is:
2262
2263          (sig-val
2264            (dsa
2265              (r R-MPI)
2266              (s S-MPI)))
2267
2268     Where R-MPI and S-MPI are the result of the DSA sign operation.
2269     For ElGamal signing (which is slow, yields large numbers and
2270     probably is not as secure as the other algorithms), the same
2271     format is used with "elg" replacing "dsa".
2272
2273The operation most commonly used is definitely the verification of a
2274signature.  Libgcrypt provides this function:
2275
2276 -- Function: gcry_error_t gcry_pk_verify (gcry_sexp_t SIG,
2277          gcry_sexp_t DATA, gcry_sexp_t PKEY)
2278     This is used to check whether the signature SIG matches the DATA.
2279     The public key PKEY must be provided to perform this verification.
2280     This function is similar in its parameters to `gcry_pk_sign' with
2281     the exceptions that the public key is used instead of the private
2282     key and that no signature is created but a signature, in a format
2283     as created by `gcry_pk_sign', is passed to the function in SIG.
2284
2285     The result is 0 for success (i.e. the data matches the signature),
2286     or an error code where the most relevant code is
2287     `GCRYERR_BAD_SIGNATURE' to indicate that the signature does not
2288     match the provided data.
2289
2290
2291
2292File: gcrypt.info,  Node: General public-key related Functions,  Prev: Cryptographic Functions,  Up: Public Key cryptography (I)
2293
22947.5 General public-key related Functions
2295========================================
2296
2297A couple of utility functions are available to retrieve the length of
2298the key, map algorithm identifiers and perform sanity checks:
2299
2300 -- Function: const char * gcry_pk_algo_name (int ALGO)
2301     Map the public key algorithm id ALGO to a string representation of
2302     the algorithm name.  For unknown algorithms this functions returns
2303     an empty string.
2304
2305 -- Function: int gcry_pk_map_name (const char *NAME)
2306     Map the algorithm NAME to a public key algorithm Id.  Returns 0 if
2307     the algorithm name is not known.
2308
2309 -- Function: int gcry_pk_test_algo (int ALGO)
2310     Return 0 if the public key algorithm ALGO is available for use.
2311     Note, that this is implemented as a macro.
2312
2313 -- Function: unsigned int gcry_pk_get_nbits (gcry_sexp_t KEY)
2314     Return what is commonly referred as the key length for the given
2315     public or private in KEY.
2316
2317 -- Function: unsigned char * gcry_pk_get_keygrip (gcry_sexp_t KEY,
2318          unsigned char *ARRAY)
2319     Return the so called "keygrip" which is the SHA-1 hash of the
2320     public key parameters expressed in a way depended on the
2321     algorithm.  ARRAY must either provide space for 20 bytes or
2322     `NULL;'. In the latter case a newly allocated array of that size
2323     is returned.  On success a pointer to the newly allocated space or
2324     to ARRAY is returned.  `NULL' is returned to indicate an error
2325     which is most likely an unknown algorithm or one where a "keygrip"
2326     has not yet been defined.  The function accepts public or secret
2327     keys in KEY.
2328
2329 -- Function: gcry_error_t gcry_pk_testkey (gcry_sexp_t KEY)
2330     Return zero if the private key KEY is `sane', an error code
2331     otherwise.  Note, that it is not possible to chek the `saneness'
2332     of a public key.
2333
2334
2335 -- Function: int gcry_pk_algo_info (int ALGO, int WHAT, void *BUFFER,
2336          size_t *NBYTES)
2337     Depending on the value of WHAT return various information about
2338     the public key algorithm with the id ALGO.  Note, that the
2339     function returns `-1' on error and the actual error code must be
2340     retrieved using the function `gcry_errno'.  The currently defined
2341     values for WHAT are:
2342
2343    `GCRYCTL_TEST_ALGO:'
2344          Return 0 when the specified algorithm is available for use.
2345          BUFFER must be `NULL', NBYTES may be passed as `NULL' or
2346          point to a variable with the required usage of the algorithm.
2347          This may be 0 for "don't care" or the bit-wise OR of these
2348          flags:
2349
2350         `GCRY_PK_USAGE_SIGN'
2351               Algorithm is usable for signing.
2352
2353         `GCRY_PK_USAGE_ENCR'
2354               Algorithm is usable for encryption.
2355
2356    `GCRYCTL_GET_ALGO_USAGE:'
2357          Return the usage flags for the given algorithm.  An invalid
2358          algorithm return 0.  Disabled algorithms are ignored here
2359          because we want to know whether the algorithm is at all
2360          capable of a certain usage.
2361
2362    `GCRYCTL_GET_ALGO_NPKEY'
2363          Return the number of elements the public key for algorithm
2364          ALGO consist of.  Return 0 for an unknown algorithm.
2365
2366    `GCRYCTL_GET_ALGO_NSKEY'
2367          Return the number of elements the private key for algorithm
2368          ALGO consist of.  Note that this value is always larger than
2369          that of the public key.  Return 0 for an unknown algorithm.
2370
2371    `GCRYCTL_GET_ALGO_NSIGN'
2372          Return the number of elements a signature created with the
2373          algorithm ALGO consists of.  Return 0 for an unknown
2374          algorithm or for an algorithm not capable of creating
2375          signatures.
2376
2377    `GCRYCTL_GET_ALGO_NENC'
2378          Return the number of elements a encrypted message created
2379          with the algorithm ALGO consists of.  Return 0 for an unknown
2380          algorithm or for an algorithm not capable of encryption.
2381
2382     Please note that parameters not required should be passed as
2383     `NULL'.
2384
2385 -- Function: gcry_error_t gcry_pk_ctl (int CMD, void *BUFFER,
2386          size_t BUFLEN)
2387     This is a general purpose function to perform certain control
2388     operations.  CMD controls what is to be done. The return value is
2389     0 for success or an error code.  Currently supported values for
2390     CMD are:
2391
2392    `GCRYCTL_DISABLE_ALGO'
2393          Disable the algorithm given as an algorithm id in BUFFER.
2394          BUFFER must point to an `int' variable with the algorithm id
2395          and BUFLEN must have the value `sizeof (int)'.
2396
2397
2398Libgcrypt also provides a function for generating public key pairs:
2399
2400 -- Function: gcry_error_t gcry_pk_genkey (gcry_sexp_t *R_KEY,
2401          gcry_sexp_t PARMS)
2402     This function create a new public key pair using information given
2403     in the S-expression PARMS and stores the private and the public key
2404     in one new S-expression at the address given by R_KEY.  In case of
2405     an error, R_KEY is set to `NULL'.  The return code is 0 for
2406     success or an error code otherwise.
2407
2408     Here is an example for PARMS for creating a 1024 bit RSA key:
2409
2410          (genkey
2411            (rsa
2412              (nbits 4:1024)))
2413
2414     To create an ElGamal key, substitute "elg" for "rsa" and to create
2415     a DSA key use "dsa".  Valid ranges for the key length depend on the
2416     algorithms; all commonly used key lengths are supported.  Currently
2417     supported parameters are:
2418
2419    `nbits'
2420          This is always required to specify the length of the key.
2421          The argument is a string with a number in C-notation.
2422
2423    `rsa-use-e'
2424          This is only used with RSA to give a hint for the public
2425          exponent. The value will be used as a base to test for a
2426          usable exponent. Some values are special:
2427
2428         `0'
2429               Use a secure and fast value.  This is currently the
2430               number 41.
2431
2432         `1'
2433               Use a secure value as required by some specification.
2434               This is currently the number 65537.
2435
2436         `2'
2437               Reserved
2438
2439          If this parameter is not used, Libgcrypt uses for historic
2440          reasons 65537.
2441
2442
2443     The key pair is returned in a format depending on the algorithm.
2444     Both private and public keys are returned in one container and may
2445     be accompanied by some miscellaneous information.
2446
2447     As an example, here is what the ElGamal key generation returns:
2448
2449          (key-data
2450            (public-key
2451              (elg
2452                (p P-MPI)
2453                (g G-MPI)
2454                (y Y-MPI)))
2455            (private-key
2456              (elg
2457                (p P-MPI)
2458                (g G-MPI)
2459                (y Y-MPI)
2460                (x X-MPI)))
2461            (misc-key-info
2462              (pm1-factors N1 N2 ... NN)))
2463
2464     As you can see, some of the information is duplicated, but this
2465     provides an easy way to extract either the public or the private
2466     key.  Note that the order of the elements is not defined, e.g. the
2467     private key may be stored before the public key. N1 N2 ... NN is a
2468     list of prime numbers used to composite P-MPI; this is in general
2469     not a very useful information.
2470
2471
2472File: gcrypt.info,  Node: Public Key cryptography (II),  Next: Random Numbers,  Prev: Public Key cryptography (I),  Up: Top
2473
24748 Public Key cryptography (II)
2475******************************
2476
2477This chapter documents the alternative interface to asymmetric
2478cryptography (ac) that is not based on S-expressions, but on native C
2479data structures.  As opposed to the pk interface described in the
2480former chapter, this one follows an open/use/close paradigm like other
2481building blocks of the library.
2482
2483* Menu:
2484
2485* Available asymmetric algorithms::  List of algorithms supported by the library.
2486* Working with sets of data::   How to work with sets of data.
2487* Working with handles::        How to use handles.
2488* Working with keys::           How to work with keys.
2489* Using cryptographic functions::  How to perform cryptographic operations.
2490* Handle-independent functions::  General functions independent of handles.
2491
2492
2493File: gcrypt.info,  Node: Available asymmetric algorithms,  Next: Working with sets of data,  Up: Public Key cryptography (II)
2494
24958.1 Available asymmetric algorithms
2496===================================
2497
2498Libgcrypt supports the RSA (Rivest-Shamir-Adleman) algorithms as well
2499as DSA (Digital Signature Algorithm) and ElGamal.  The versatile
2500interface allows to add more algorithms in the future.
2501
2502 -- Data type: gcry_ac_id_t
2503     The following constants are defined for this type:
2504
2505    `GCRY_AC_RSA'
2506          Riven-Shamir-Adleman
2507
2508    `GCRY_AC_DSA'
2509          Digital Signature Algorithm
2510
2511    `GCRY_AC_ELG'
2512          ElGamal
2513
2514    `GCRY_AC_ELG_E'
2515          ElGamal, encryption only.
2516
2517
2518File: gcrypt.info,  Node: Working with sets of data,  Next: Working with handles,  Prev: Available asymmetric algorithms,  Up: Public Key cryptography (II)
2519
25208.2 Working with sets of data
2521=============================
2522
2523In the context of this interface the term `data set' refers to a list
2524of `named MPI values' that is used by functions performing
2525cryptographic operations.
2526
2527   Such data sets are used for representing keys, since keys simply
2528consist of a variable amount of numbers.  Furthermore some functions
2529return data sets to the caller that are to be provided to other
2530functions.
2531
2532   This section documents the data types, symbols and functions that are
2533relevant for working with such data sets.
2534
2535 -- Data type: gcry_ac_data_t
2536     A data set, that is simply a list of named MPI values.
2537
2538   The following flags are supported:
2539
2540`GCRY_AC_FLAG_DEALLOC'
2541     Used for storing data in a data set.  If given, the data will be
2542     released by the library.
2543
2544`GCRY_AC_FLAG_COPY'
2545     Used for storing/retrieving data in/from a data set.  If given, the
2546     library will create copies of the provided/contained data, which
2547     will then be given to the user/associated with the data set.
2548
2549 -- Function: gcry_error_t gcry_ac_data_new (gcry_ac_data_t *DATA)
2550     Creates a new, empty data set and stores it in DATA.
2551
2552 -- Function: void gcry_ac_data_destroy (gcry_ac_data_t DATA)
2553     Destroys the data set DATA.
2554
2555 -- Function: gcry_error_t gcry_ac_data_set (gcry_ac_data_t DATA,
2556          unsigned int FLAGS, char *NAME, gcry_mpi_t MPI)
2557     Add the value MPI to DATA with the label NAME.  If FLAGS contains
2558     GCRY_AC_FLAG_DATA_COPY, the data set will contain copies of NAME
2559     and MPI.  If FLAGS contains GCRY_AC_FLAG_DATA_DEALLOC or
2560     GCRY_AC_FLAG_DATA_COPY, the values contained in the data set will
2561     be deallocated when they are to be removed from the data set.
2562
2563 -- Function: gcry_error_t gcry_ac_data_copy (gcry_ac_data_t *DATA_CP,
2564          gcry_ac_data_t DATA)
2565     Create a copy of the data set DATA and store it in DATA_CP.
2566
2567 -- Function: unsigned int gcry_ac_data_length (gcry_ac_data_t DATA)
2568     Returns the number of named MPI values inside of the data set DATA.
2569
2570 -- Function: gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t DATA,
2571          unsigned int FLAGS, char *NAME, gcry_mpi_t *MPI)
2572     Store the value labelled with NAME found in DATA in MPI.  If FLAGS
2573     contains GCRY_AC_FLAG_COPY, store a copy of the MPI value
2574     contained in the data set.  MPI may be NULL.
2575
2576 -- Function: gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t DATA,
2577          unsigned int flags, unsigned int INDEX, const char **NAME,
2578          gcry_mpi_t *MPI)
2579     Stores in NAME and MPI the named MPI value contained in the data
2580     set DATA with the index IDX.  If FLAGS contains GCRY_AC_FLAG_COPY,
2581     store copies of the values contained in the data set. NAME or MPI
2582     may be NULL.
2583
2584 -- Function: void gcry_ac_data_clear (gcry_ac_data_t DATA)
2585     Destroys any values contained in the data set DATA.
2586
2587
2588File: gcrypt.info,  Node: Working with handles,  Next: Working with keys,  Prev: Working with sets of data,  Up: Public Key cryptography (II)
2589
25908.3 Working with handles
2591========================
2592
2593In order to use an algorithm, an according handle must be created.
2594This is done using the following function:
2595
2596 -- Function: gcry_error_t gcry_ac_open (gcry_ac_handle_t *HANDLE, int
2597          ALGORITHM, int FLAGS)
2598     Creates a new handle for the algorithm ALGORITHM and stores it in
2599     HANDLE.  FLAGS is not used yet.
2600
2601     ALGORITHM must be a valid algorithm ID, see *Note Available
2602     algorithms::, for a list of supported algorithms and the according
2603     constants.  Besides using the listed constants directly, the
2604     functions `gcry_ac_name_to_id' may be used to convert the textual
2605     name of an algorithm into the according numeric ID.
2606
2607 -- Function: void gcry_ac_close (gcry_ac_handle_t HANDLE)
2608     Destroys the handle HANDLE.
2609
2610
2611File: gcrypt.info,  Node: Working with keys,  Next: Using cryptographic functions,  Prev: Working with handles,  Up: Public Key cryptography (II)
2612
26138.4 Working with keys
2614=====================
2615
2616 -- Data type: gcry_ac_key_type_t
2617     Defined constants:
2618
2619    `GCRY_AC_KEY_TYPE_SECRET'
2620          Specifies a secret key.
2621
2622    `GCRY_AC_KEY_TYPE_PUBLIC'
2623          Specifies a public key.
2624
2625 -- Data type: gcry_ac_key_t
2626     This type represents a single `key', either a secret one or a
2627     public one.
2628
2629 -- Data type: gcry_ac_key_pair_t
2630     This type represents a `key pair' containing a secret and a public
2631     key.
2632
2633   Key data structures can be created in two different ways; a new key
2634pair can be generated, resulting in ready-to-use key.  Alternatively a
2635key can be initialized from a given data set.
2636
2637 -- Function: gcry_error_t gcry_ac_key_init (gcry_ac_key_t *KEY,
2638          gcry_ac_handle_t HANDLE, gcry_ac_key_type_t TYPE,
2639          gcry_ac_data_t DATA)
2640     Creates a new key of type TYPE, consisting of the MPI values
2641     contained in the data set DATA and stores it in KEY.
2642
2643 -- Function: gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t
2644          HANDLE, unsigned int NBITS, void *KEY_SPEC,
2645          gcry_ac_key_pair_t *KEY_PAIR, gcry_mpi_t **MISC_DATA)
2646     Generates a new key pair via the handle HANDLE of NBITS bits and
2647     stores it in KEY_PAIR.
2648
2649     In case non-standard settings are wanted, a pointer to a structure
2650     of type `gcry_ac_key_spec_<algorithm>_t', matching the selected
2651     algorithm, can be given as KEY_SPEC.  MISC_DATA is not used yet.
2652     Such a structure does only exist for RSA.  A descriptions of the
2653     members of the supported structures follows.
2654
2655    `gcry_ac_key_spec_rsa_t'
2656
2657         `gcry_mpi_t e'
2658               Generate the key pair using a special `e'.  The value of
2659               `e' has the following meanings:
2660              `= 0'
2661                    Let Libgcrypt device what exponent should be used.
2662
2663              `= 1'
2664                    Request the use of a "secure" exponent; this is
2665                    required by some specification to be 65537.
2666
2667              `> 2'
2668                    Try starting at this value until a working exponent
2669                    is found.  Note, that the current implementation
2670                    leaks some information about the private key
2671                    because the incrementation used is not randomized.
2672                    Thus, this function will be changed in the future
2673                    to return a random exponent of the given size.
2674
2675     Example code:
2676          {
2677            gcry_ac_key_pair_t key_pair;
2678            gcry_ac_key_spec_rsa  rsa_spec;
2679
2680            rsa_spec.e = gcry_mpi_new (0);
2681            gcry_mpi_set_ui (rsa_spec.e, 1)
2682
2683            err = gcry_ac_open  (&handle, GCRY_AC_RSA, 0);
2684            assert (! err);
2685
2686            err = gcry_ac_key_pair_generate (handle, &key_pair, 1024, (void *) &rsa_spec);
2687            assert (! err);
2688          }
2689
2690 -- Function: gcry_ac_key_t gcry_ac_key_pair_extract
2691          (gcry_ac_key_pair_t KEY_PAIR, gcry_ac_key_type_t WHICH)
2692     Returns the key of type WHICH out of the key pair KEY_PAIR.
2693
2694 -- Function: void gcry_ac_key_destroy (gcry_ac_key_t KEY)
2695     Destroys the key KEY.
2696
2697 -- Function: void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t
2698          KEY_PAIR)
2699     Destroys the key pair KEY_PAIR.
2700
2701 -- Function: gcry_ac_data_t gcry_ac_key_data_get (gcry_ac_key_t KEY)
2702     Returns the data set contained in the key KEY.
2703
2704 -- Function: gcry_error_t gcry_ac_key_test (gcry_ac_handle_t HANDLE,
2705          gcry_ac_key_t KEY)
2706     Verifies that the private key KEY is sane via HANDLE.
2707
2708 -- Function: gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t
2709          HANDLE, gcry_ac_key_t KEY, unsigned int *NBITS)
2710     Stores the number of bits of the key KEY in NBITS via HANDLE.
2711
2712 -- Function: gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t
2713          HANDLE, gcry_ac_key_t KEY, unsigned char *KEY_GRIP)
2714     Writes the 20 byte long key grip of the key KEY to KEY_GRIP via
2715     HANDLE.
2716
2717
2718File: gcrypt.info,  Node: Using cryptographic functions,  Next: Handle-independent functions,  Prev: Working with keys,  Up: Public Key cryptography (II)
2719
27208.5 Using cryptographic functions
2721=================================
2722
2723The following flags might be relevant:
2724
2725`GCRY_AC_FLAG_NO_BLINDING'
2726     Disable any blinding, which might be supported by the chosen
2727     algorithm; blinding is the default.
2728
2729 -- Function: gcry_error_t gcry_ac_data_encrypt (gcry_ac_handle_t
2730          HANDLE, unsigned int FLAGS, gcry_ac_key_t KEY, gcry_mpi_t
2731          DATA_PLAIN, gcry_ac_data_t **DATA_ENCRYPTED)
2732     Encrypts the plain text MPI value DATA_PLAIN with the key public
2733     KEY under the control of the flags FLAGS and stores the resulting
2734     data set into DATA_ENCRYPTED.
2735
2736 -- Function: gcry_error_t gcry_ac_data_decrypt (gcry_ac_handle_t
2737          HANDLE, unsigned int FLAGS, gcry_ac_key_t KEY, gcry_mpi_t
2738          *DATA_PLAIN, gcry_ac_data_t DATA_ENCRYPTED)
2739     Decrypts the encrypted data contained in the data set
2740     DATA_ENCRYPTED with the secret key KEY under the control of the
2741     flags FLAGS and stores the resulting plain text MPI value in
2742     DATA_PLAIN.
2743
2744 -- Function: gcry_error_t gcry_ac_data_sign (gcry_ac_handle_t HANDLE,
2745          gcry_ac_key_t KEY, gcry_mpi_t DATA, gcry_ac_data_t
2746          *DATA_SIGNATURE)
2747     Signs the data contained in DATA with the secret key KEY and
2748     stores the resulting signature in the data set DATA_SIGNATURE.
2749
2750 -- Function: gcry_error_t gcry_ac_data_verify (gcry_ac_handle_t
2751          HANDLE, gcry_ac_key_t KEY, gcry_mpi_t DATA, gcry_ac_data_t
2752          DATA_SIGNATURE)
2753     Verifies that the signature contained in the data set
2754     DATA_SIGNATURE is indeed the result of signing the data contained
2755     in DATA with the secret key belonging to the public key KEY.
2756
2757
2758File: gcrypt.info,  Node: Handle-independent functions,  Prev: Using cryptographic functions,  Up: Public Key cryptography (II)
2759
27608.6 Handle-independent functions
2761================================
2762
2763 -- Function: gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t ALGORITHM,
2764          const char **NAME)
2765     Stores the textual representation of the algorithm whose id is
2766     given in ALGORITHM in NAME.
2767
2768 -- Function: gcry_error_t gcry_ac_name_to_id (const char *NAME,
2769          gcry_ac_id_t *ALGORITHM)
2770     Stores the numeric ID of the algorithm whose textual
2771     representation is contained in NAME in ALGORITHM.
2772
2773
2774File: gcrypt.info,  Node: Random Numbers,  Next: S-expressions,  Prev: Public Key cryptography (II),  Up: Top
2775
27769 Random Numbers
2777****************
2778
2779* Menu:
2780
2781* Quality of random numbers::   Libgcrypt uses different quality levels.
2782* Retrieving random numbers::   How to retrieve random numbers.
2783
2784
2785File: gcrypt.info,  Node: Quality of random numbers,  Next: Retrieving random numbers,  Up: Random Numbers
2786
27879.1 Quality of random numbers
2788=============================
2789
2790Libgcypt offers random numbers of different quality levels:
2791
2792 -- Data type: enum gcry_random_level
2793     The constants for the random quality levels are of this type.
2794
2795`GCRY_WEAK_RANDOM'
2796     This should not anymore be used.  It has recently been changed to
2797     an alias of GCRY_STRONG_RANDOM.  Use `gcry_create_nonce' instead.
2798
2799`GCRY_STRONG_RANDOM'
2800     Use this level for e.g. session keys and similar purposes.
2801
2802`GCRY_VERY_STRONG_RANDOM'
2803     Use this level for e.g. key material.
2804
2805
2806File: gcrypt.info,  Node: Retrieving random numbers,  Prev: Quality of random numbers,  Up: Random Numbers
2807
28089.2 Retrieving random numbers
2809=============================
2810
2811 -- Function: void gcry_randomize (unsigned char *BUFFER, size_t
2812          LENGTH, enum gcry_random_level LEVEL)
2813     Fill BUFFER with LENGTH random bytes using a random quality as
2814     defined by LEVEL.
2815
2816 -- Function: void * gcry_random_bytes (size_t NBYTES, enum
2817          gcry_random_level LEVEL)
2818     Allocate a memory block consisting of NBYTES fresh random bytes
2819     using a random quality as defined by LEVEL.
2820
2821 -- Function: void * gcry_random_bytes_secure (size_t NBYTES, enum
2822          gcry_random_level LEVEL)
2823     Allocate a memory block consisting of NBYTES fresh random bytes
2824     using a random quality as defined by LEVEL.  This function differs
2825     from `gcry_random_bytes' in that the returned buffer is allocated
2826     in a "secure" area of the memory.
2827
2828 -- Function: void gcry_create_nonce (void *BUFFER, size_t LENGTH)
2829     Fill BUFFER with LENGTH unpredictable bytes.  This is commonly
2830     called a nonce and may also be used for initialization vectors and
2831     padding.  This is an extra function nearly independent of the
2832     other random function for 3 reasons: It better protects the
2833     regular random generator's internal state, provides better
2834     performance and does not drain the precious entropy pool.
2835
2836
2837
2838File: gcrypt.info,  Node: S-expressions,  Next: MPI library,  Prev: Random Numbers,  Up: Top
2839
284010 S-expressions
2841****************
2842
2843S-expressions are used by the public key functions to pass complex data
2844structures around.  These LISP like objects are used by some
2845cryptographic protocols (cf. RFC-2692) and Libgcrypt provides functions
2846to parse and construct them.  For detailed information, see `Ron
2847Rivest, code and description of S-expressions,
2848`http://theory.lcs.mit.edu/~rivest/sexp.html''.
2849
2850* Menu:
2851
2852* Data types for S-expressions::  Data types related with S-expressions.
2853* Working with S-expressions::  How to work with S-expressions.
2854
2855
2856File: gcrypt.info,  Node: Data types for S-expressions,  Next: Working with S-expressions,  Up: S-expressions
2857
285810.1 Data types for S-expressions
2859=================================
2860
2861 -- Data type: gcry_sexp_t
2862     The `gcry_sexp_t' type describes an object with the Libgcrypt
2863     internal representation of an S-expression.
2864
2865
2866File: gcrypt.info,  Node: Working with S-expressions,  Prev: Data types for S-expressions,  Up: S-expressions
2867
286810.2 Working with S-expressions
2869===============================
2870
2871There are several functions to create an Libgcrypt S-expression object
2872from its external representation or from a string template.  There is
2873also a function to convert the internal representation back into one of
2874the external formats:
2875
2876 -- Function: gcry_error_t gcry_sexp_new (gcry_sexp_t *R_SEXP,
2877          const void *BUFFER, size_t LENGTH, int AUTODETECT)
2878     This is the generic function to create an new S-expression object
2879     from its external representation in BUFFER of LENGTH bytes.  On
2880     success the result is stored at the address given by R_SEXP.  With
2881     AUTODETECT set to 0, the data in BUFFER is expected to be in
2882     canonized format, with AUTODETECT set to 1 the parses any of the
2883     defined external formats.  If BUFFER does not hold a valid
2884     S-expression an error code is returned and R_SEXP set to `NULL'.
2885     Note, that the caller is responsible for releasing the newly
2886     allocated S-expression using `gcry_sexp_release'.
2887
2888 -- Function: gcry_error_t gcry_sexp_create (gcry_sexp_t *R_SEXP,
2889          void *BUFFER, size_t LENGTH, int AUTODETECT,
2890          void (*FREEFNC)(void*))
2891     This function is identical to `gcry_sexp_new' but has an extra
2892     argument FREEFNC, which, when not set to `NULL', is expected to be
2893     a function to release the BUFFER; most likely the standard `free'
2894     function is used for this argument.  This has the effect of
2895     transferring the ownership of BUFFER to the created object in
2896     R_SEXP.  The advantage of using this function is that Libgcrypt
2897     might decide to directly use the provided buffer and thus avoid
2898     extra copying.
2899
2900 -- Function: gcry_error_t gcry_sexp_sscan (gcry_sexp_t *R_SEXP,
2901          size_t *ERROFF, const char *BUFFER, size_t LENGTH)
2902     This is another variant of the above functions.  It behaves nearly
2903     identical but provides an ERROFF argument which will receive the
2904     offset into the buffer where the parsing stopped on error.
2905
2906 -- Function: gcry_error_t gcry_sexp_build (gcry_sexp_t *R_SEXP,
2907          size_t *ERROFF, const char *FORMAT, ...)
2908     This function creates an internal S-expression from the string
2909     template FORMAT and stores it at the address of R_SEXP. If there
2910     is a parsing error, the function returns an appropriate error code
2911     and stores the offset into FORMAT where the parsing stopped in
2912     ERROFF.  The function supports a couple of printf-like formatting
2913     characters and expects arguments for some of these escape
2914     sequences right after FORMAT.  The following format characters are
2915     defined:
2916
2917    `%m'
2918          The next argument is expected to be of type `gcry_mpi_t' and
2919          a copy of its value is inserted into the resulting
2920          S-expression.
2921
2922    `%s'
2923          The next argument is expected to be of type `char *' and that
2924          string is inserted into the resulting S-expression.
2925
2926    `%d'
2927          The next argument is expected to be of type `int' and its
2928          value ist inserted into the resulting S-expression.
2929
2930    `%b'
2931          The next argument is expected to be of type `int' directly
2932          followed by an argument of type `char *'.  This represents a
2933          buffer of given length to be inserted into the resulting
2934          regular expression.
2935
2936     No other format characters are defined and would return an error.
2937     Note, that the format character `%%' does not exists, because a
2938     percent sign is not a valid character in an S-expression.
2939
2940 -- Function: void gcry_sexp_release (gcry_sexp_t SEXP)
2941     Release the S-expression object SEXP.
2942
2943The next 2 functions are used to convert the internal representation
2944back into a regular external S-expression format and to show the
2945structure for debugging.
2946
2947 -- Function: size_t gcry_sexp_sprint (gcry_sexp_t SEXP, int MODE,
2948          void *BUFFER, size_t MAXLENGTH)
2949     Copies the S-expression object SEXP into BUFFER using the format
2950     specified in MODE.  MAXLENGTH must be set to the allocated length
2951     of BUFFER.  The function returns the actual length of valid bytes
2952     put into BUFFER or 0 if the provided buffer is too short.  Passing
2953     `NULL' for BUFFER returns the required length for BUFFER.  For
2954     convenience reasons an extra byte with value 0 is appended to the
2955     buffer.
2956
2957     The following formats are supported:
2958
2959    `GCRYSEXP_FMT_DEFAULT'
2960          Returns a convenient external S-expression representation.
2961
2962    `GCRYSEXP_FMT_CANON'
2963          Return the S-expression in canonical format.
2964
2965    `GCRYSEXP_FMT_BASE64'
2966          Not currently supported.
2967
2968    `GCRYSEXP_FMT_ADVANCED'
2969          Returns the S-expression in advanced format.
2970
2971 -- Function: void gcry_sexp_dump (gcry_sexp_t SEXP)
2972     Dumps SEXP in a format suitable for debugging to Libgcrypt's
2973     logging stream.
2974
2975Often canonical encoding is used in the external representation.  The
2976following function can be used to check for valid encoding and to learn
2977the length of the S-expression"
2978
2979 -- Function: size_t gcry_sexp_canon_len (const unsigned char *BUFFER,
2980          size_t LENGTH, size_t *ERROFF, int *ERRCODE)
2981     Scan the canonical encoded BUFFER with implicit length values and
2982     return the actual length this S-expression uses.  For a valid
2983     S-expression it should never return 0.  If LENGTH is not 0, the
2984     maximum length to scan is given; this can be used for syntax
2985     checks of data passed from outside.  ERRCODE and ERROFF may both be
2986     passed as `NULL'.
2987
2988
2989There are a couple of functions to parse S-expressions and retrieve
2990elements:
2991
2992 -- Function: gcry_sexp_t gcry_sexp_find_token (const gcry_sexp_t LIST,
2993          const char *TOKEN, size_t TOKLEN)
2994     Scan the S-expression for a sublist with a type (the car of the
2995     list) matching the string TOKEN.  If TOKLEN is not 0, the token is
2996     assumed to be raw memory of this length.  The function returns a
2997     newly allocated S-expression consisting of the found sublist or
2998     `NULL' when not found.
2999
3000 -- Function: int gcry_sexp_length (const gcry_sexp_t LIST)
3001     Return the length of the LIST.  For a valid S-expression this
3002     should be at least 1.
3003
3004 -- Function: gcry_sexp_t gcry_sexp_nth (const gcry_sexp_t LIST,
3005          int NUMBER)
3006     Create and return a new S-expression from the element with index
3007     NUMBER in LIST.  Note that the first element has the index 0.  If
3008     there is no such element, `NULL' is returned.
3009
3010 -- Function: gcry_sexp_t gcry_sexp_car (const gcry_sexp_t LIST)
3011     Create and return a new S-expression from the first element in
3012     LIST; this called the "type" and should always exist and be a
3013     string. `NULL' is returned in case of a problem.
3014
3015 -- Function: gcry_sexp_t gcry_sexp_cdr (const gcry_sexp_t LIST)
3016     Create and return a new list form all elements except for the
3017     first one.  Note, that this function may return an invalid
3018     S-expression because it is not guaranteed, that the type exists
3019     and is a string.  However, for parsing a complex S-expression it
3020     might be useful for intermediate lists.  Returns `NULL' on error.
3021
3022 -- Function: const char * gcry_sexp_nth_data (const gcry_sexp_t LIST,
3023          int NUMBER, size_t *DATALEN)
3024     This function is used to get data from a LIST.  A pointer to the
3025     actual data with index NUMBER is returned and the length of this
3026     data will be stored to DATALEN.  If there is no data at the given
3027     index or the index represents another list, `NULL' is returned.
3028     *Take care:* The returned pointer is valid as long as LIST is not
3029     modified or released.
3030
3031     Here is an example on how to extract and print the surname (Meier)
3032     from the S-expression `(Name Otto Meier (address Burgplatz 3))':
3033
3034          size_t len;
3035          const char *name;
3036
3037          name = gcry_sexp_nth_data (list, 2, &len);
3038          printf ("my name is %.*s\n", (int)len, name);
3039
3040 -- Function: gcry_mpi_t gcry_sexp_nth_mpi (gcry_sexp_t LIST,
3041          int NUMBER, int MPIFMT)
3042     This function is used to get and convert data from a LIST. This
3043     data is assumed to be an MPI stored in the format described by
3044     MPIFMT and returned as a standard Libgcrypt MPI.  The caller must
3045     release this returned value using `gcry_mpi_release'.  If there is
3046     no data at the given index, the index represents a list or the
3047     value can't be converted to an MPI, `NULL' is returned.
3048
3049
3050File: gcrypt.info,  Node: MPI library,  Next: Utilities,  Prev: S-expressions,  Up: Top
3051
305211 MPI library
3053**************
3054
3055* Menu:
3056
3057* Data types::                  MPI related data types.
3058* Basic functions::             First steps with MPI numbers.
3059* MPI formats::                 External representation of MPIs.
3060* Calculations::                Performing MPI calculations.
3061* Comparisons::                 How to compare MPI values.
3062* Bit manipulations::           How to access single bits of MPI values.
3063* Miscellaneous::               Miscellaneous MPI functions.
3064
3065   Public key cryptography is based on mathematics with large numbers.
3066To implement the public key functions, a library for handling these
3067large numbers is required.  Because of the general usefulness of such a
3068library, its interface is exposed by Libgcrypt.  The implementation is
3069based on an old release of GNU Multi-Precision Library (GMP) but in the
3070meantime heavily modified and stripped down to what is required for
3071cryptography. For a lot of CPUs, high performance assembler
3072implementations of some very low level functions are used to gain much
3073better performance than with the standard C implementation.
3074
3075In the context of Libgcrypt and in most other applications, these large
3076numbers are called MPIs (multi-precision-integers).
3077
3078
3079File: gcrypt.info,  Node: Data types,  Next: Basic functions,  Up: MPI library
3080
308111.1 Data types
3082===============
3083
3084 -- Data type: gcry_mpi_t
3085     The `gcry_mpi_t' type represents an object to hold an MPI.
3086
3087
3088File: gcrypt.info,  Node: Basic functions,  Next: MPI formats,  Prev: Data types,  Up: MPI library
3089
309011.2 Basic functions
3091====================
3092
3093To work with MPIs, storage must be allocated and released for the
3094numbers.  This can be done with one of these functions:
3095
3096 -- Function: gcry_mpi_t gcry_mpi_new (unsigned int NBITS)
3097     Allocate a new MPI object, initialize it to 0 and initially
3098     allocate enough memory for a number of at least NBITS.  This
3099     pre-allocation is only a small performance issue and not actually
3100     necessary because Libgcrypt automatically re-allocates the
3101     required memory.
3102
3103 -- Function: gcry_mpi_t gcry_mpi_snew (unsigned int NBITS)
3104     This is identical to `gcry_mpi_new' but allocates the MPI in the so
3105     called "secure memory" which in turn will take care that all
3106     derived values will also be stored in this "secure memory".  Use
3107     this for highly confidential data like private key parameters.
3108
3109 -- Function: gcry_mpi_t gcry_mpi_copy (const gcry_mpi_t A)
3110     Create a new MPI as the exact copy of A.
3111
3112 -- Function: void gcry_mpi_release (gcry_mpi_t A)
3113     Release the MPI A and free all associated resources.  Passing
3114     `NULL' is allowed and ignored.  When a MPI stored in the "secure
3115     memory" is released, that memory gets wiped out immediately.
3116
3117The simplest operations are used to assign a new value to an MPI:
3118
3119 -- Function: gcry_mpi_t gcry_mpi_set (gcry_mpi_t W, const gcry_mpi_t U)
3120     Assign the value of U to W and return W.  If `NULL' is passed for
3121     W, a new MPI is allocated, set to the value of U and returned.
3122
3123 -- Function: gcry_mpi_t gcry_mpi_set_ui (gcry_mpi_t W, unsigned long U)
3124     Assign the value of U to W and return W.  If `NULL' is passed for
3125     W, a new MPI is allocated, set to the value of U and returned.
3126     This function takes an `unsigned int' as type for U and thus it is
3127     only possible to set W to small values (usually up to the word
3128     size of the CPU).
3129
3130 -- Function: void gcry_mpi_swap (gcry_mpi_t A, gcry_mpi_t B)
3131     Swap the values of A and B.
3132
3133
3134File: gcrypt.info,  Node: MPI formats,  Next: Calculations,  Prev: Basic functions,  Up: MPI library
3135
313611.3 MPI formats
3137================
3138
3139The following functions are used to convert between an external
3140representation of an MPI and the internal one of Libgcrypt.
3141
3142 -- Function: int gcry_mpi_scan (gcry_mpi_t *R_MPI,
3143          enum gcry_mpi_format FORMAT, const void *BUFFER,
3144          size_t BUFLEN, size_t *NSCANNED)
3145     Convert the external representation of an integer stored in BUFFER
3146     with a length of BUFLEN into a newly created MPI returned which
3147     will be stored at the address of R_MPI.  For certain formats the
3148     length argument is not required and may be passed as `0'.  After a
3149     successful operation the variable NSCANNED receives the number of
3150     bytes actually scanned unless NSCANNED was given as `NULL'. FORMAT
3151     describes the format of the MPI as stored in BUFFER:
3152
3153    `GCRYMPI_FMT_STD'
3154          2-complement stored without a length header.
3155
3156    `GCRYMPI_FMT_PGP'
3157          As used by OpenPGP (only defined as unsigned). This is
3158          basically `GCRYMPI_FMT_STD' with a 2 byte big endian length
3159          header.
3160
3161    `GCRYMPI_FMT_SSH'
3162          As used in the Secure Shell protocol.  This is
3163          `GCRYMPI_FMT_STD' with a 4 byte big endian header.
3164
3165    `GCRYMPI_FMT_HEX'
3166          Stored as a C style string with each byte of the MPI encoded
3167          as 2 hex digits.
3168
3169    `GCRYMPI_FMT_USG'
3170          Simple unsigned integer.
3171
3172     Note, that all of the above formats store the integer in big-endian
3173     format (MSB first).
3174
3175 -- Function: int gcry_mpi_print (enum gcry_mpi_format FORMAT,
3176          unsigned char *BUFFER, size_t BUFLEN, size_t *NWRITTEN,
3177          const gcry_mpi_t A)
3178     Convert the MPI A into an external representation described by
3179     FORMAT (see above) and store it in the provided BUFFER which has a
3180     usable length of at least the BUFLEN bytes. If NWRITTEN is not
3181     NULL, it will receive the number of bytes actually stored in
3182     BUFFER after a successful operation.
3183
3184 -- Function: int gcry_mpi_aprint (enum gcry_mpi_format FORMAT,
3185          unsigned char **BUFFER, size_t *NBYTES, const gcry_mpi_t A)
3186     Convert the MPI A into an external representation described by
3187     FORMAT (see above) and store it in a newly allocated buffer which
3188     address will be stored in the variable BUFFER points to.  The
3189     number of bytes stored in this buffer will be stored in the
3190     variable NBYTES points to, unless NBYTES is `NULL'.
3191
3192 -- Function: void gcry_mpi_dump (const gcry_mpi_t A)
3193     Dump the value of A in a format suitable for debugging to
3194     Libgcrypt's logging stream.  Note that one leading space but no
3195     trailing space or linefeed will be printed.  It is okay to pass
3196     `NULL' for A.
3197
3198
3199File: gcrypt.info,  Node: Calculations,  Next: Comparisons,  Prev: MPI formats,  Up: MPI library
3200
320111.4 Calculations
3202=================
3203
3204Basic arithmetic operations:
3205
3206 -- Function: void gcry_mpi_add (gcry_mpi_t W, gcry_mpi_t U,
3207          gcry_mpi_t V)
3208     W = U + V.
3209
3210 -- Function: void gcry_mpi_add_ui (gcry_mpi_t W, gcry_mpi_t U,
3211          unsigned long V)
3212     W = U + V.  Note, that V is an unsigned integer.
3213
3214 -- Function: void gcry_mpi_addm (gcry_mpi_t W, gcry_mpi_t U,
3215          gcry_mpi_t V, gcry_mpi_t M)
3216     W = U + V \bmod M.
3217
3218 -- Function: void gcry_mpi_sub (gcry_mpi_t W, gcry_mpi_t U,
3219          gcry_mpi_t V)
3220     W = U - V.
3221
3222 -- Function: void gcry_mpi_sub_ui (gcry_mpi_t W, gcry_mpi_t U,
3223          unsigned long V)
3224     W = U - V.  V is an unsigned integer.
3225
3226 -- Function: void gcry_mpi_subm (gcry_mpi_t W, gcry_mpi_t U,
3227          gcry_mpi_t V, gcry_mpi_t M)
3228     W = U - V \bmod M.
3229
3230 -- Function: void gcry_mpi_mul (gcry_mpi_t W, gcry_mpi_t U,
3231          gcry_mpi_t V)
3232     W = U * V.
3233
3234 -- Function: void gcry_mpi_mul_ui (gcry_mpi_t W, gcry_mpi_t U,
3235          unsigned long V)
3236     W = U * V.  V is an unsigned integer.
3237
3238 -- Function: void gcry_mpi_mulm (gcry_mpi_t W, gcry_mpi_t U,
3239          gcry_mpi_t V, gcry_mpi_t M)
3240     W = U * V \bmod M.
3241
3242 -- Function: void gcry_mpi_mul_2exp (gcry_mpi_t W, gcry_mpi_t U,
3243          unsigned long E)
3244     W = U * 2^e.
3245
3246 -- Function: void gcry_mpi_div (gcry_mpi_t Q, gcry_mpi_t R,
3247          gcry_mpi_t DIVIDEND, gcry_mpi_t DIVISOR, int ROUND)
3248     Q = DIVIDEND / DIVISOR, R = DIVIDEND \bmod DIVISOR.  Q and R may
3249     be passed as `NULL'.  ROUND should be negative or 0.
3250
3251 -- Function: void gcry_mpi_mod (gcry_mpi_t R, gcry_mpi_t DIVIDEND,
3252          gcry_mpi_t DIVISOR)
3253     R = DIVIDEND \bmod DIVISOR.
3254
3255 -- Function: void gcry_mpi_powm (gcry_mpi_t W, const gcry_mpi_t B,
3256          const gcry_mpi_t E, const gcry_mpi_t M)
3257     W = B^e \bmod M.
3258
3259 -- Function: int gcry_mpi_gcd (gcry_mpi_t G, gcry_mpi_t A,
3260          gcry_mpi_t B)
3261     Set G to the greatest common divisor of A and B.  Return true if
3262     the G is 1.
3263
3264 -- Function: int gcry_mpi_invm (gcry_mpi_t X, gcry_mpi_t A,
3265          gcry_mpi_t M)
3266     Set X to the multiplicative inverse of A \bmod M.  Return true if
3267     the inverse exists.
3268
3269
3270File: gcrypt.info,  Node: Comparisons,  Next: Bit manipulations,  Prev: Calculations,  Up: MPI library
3271
327211.5 Comparisons
3273================
3274
3275The next 2 functions are used to compare MPIs:
3276
3277 -- Function: int gcry_mpi_cmp (const gcry_mpi_t U, const gcry_mpi_t V)
3278     Compare the big integer number U and V returning 0 for equality, a
3279     positive value for U > V and a negative for U < V.
3280
3281 -- Function: int gcry_mpi_cmp_ui (const gcry_mpi_t U, unsigned long V)
3282     Compare the big integer number U with the unsigned integer V
3283     returning 0 for equality, a positive value for U > V and a
3284     negative for U < V.
3285
3286
3287File: gcrypt.info,  Node: Bit manipulations,  Next: Miscellaneous,  Prev: Comparisons,  Up: MPI library
3288
328911.6 Bit manipulations
3290======================
3291
3292There are a couple of functions to get information on arbitrary bits in
3293an MPI and to set or clear them:
3294
3295 -- Function: unsigned int gcry_mpi_get_nbits (gcry_mpi_t A)
3296     Return the number of bits required to represent A.
3297
3298 -- Function: int gcry_mpi_test_bit (gcry_mpi_t A, unsigned int N)
3299     Return true if bit number N (counting from 0) is set in A.
3300
3301 -- Function: void gcry_mpi_set_bit (gcry_mpi_t A, unsigned int N)
3302     Set bit number N in A.
3303
3304 -- Function: void gcry_mpi_clear_bit (gcry_mpi_t A, unsigned int N)
3305     Clear bit number N in A.
3306
3307 -- Function: void gcry_mpi_set_highbit (gcry_mpi_t A, unsigned int N)
3308     Set bit number N in A and clear all bits greater than N.
3309
3310 -- Function: void gcry_mpi_clear_highbit (gcry_mpi_t A, unsigned int N)
3311     Clear bit number N in A and all bits greater than N.
3312
3313 -- Function: void gcry_mpi_rshift (gcry_mpi_t X, gcry_mpi_t A,
3314          unsigned int N)
3315     Shift the value of A by N bits to the right and store the result
3316     in X.
3317
3318
3319File: gcrypt.info,  Node: Miscellaneous,  Prev: Bit manipulations,  Up: MPI library
3320
332111.7 Miscellanous
3322=================
3323
3324 -- Function: gcry_mpi_t gcry_mpi_set_opaque (gcry_mpi_t A, void *P,
3325          unsigned int NBITS)
3326     Store NBITS of the value P points to in A and mark A as an opaque
3327     value (i.e. an value that can't be used for any math calculation
3328     and is only used to store an arbitrary bit pattern in A).
3329
3330     WARNING: Never use an opaque MPI for actual math operations.  The
3331     only valid functions are gcry_mpi_get_opaque and gcry_mpi_release.
3332     Use gcry_mpi_scan to convert a string of arbitrary bytes into an
3333     MPI.
3334
3335
3336 -- Function: void * gcry_mpi_get_opaque (gcry_mpi_t A,
3337          unsigned int *NBITS)
3338     Return a pointer to an opaque value stored in A and return its
3339     size in NBITS.  Note, that the returned pointer is still owned by
3340     A and that the function should never be used for an non-opaque MPI.
3341
3342 -- Function: void gcry_mpi_set_flag (gcry_mpi_t A,
3343          enum gcry_mpi_flag FLAG)
3344     Set the FLAG for the MPI A.  Currently only the flag
3345     `GCRYMPI_FLAG_SECURE' is allowed to convert A into an MPI stored
3346     in "secure memory".
3347
3348 -- Function: void gcry_mpi_clear_flag (gcry_mpi_t A,
3349          enum gcry_mpi_flag FLAG)
3350     Clear FLAG for the big integer A.  Note, that this function is
3351     currently useless as no flags are allowed.
3352
3353 -- Function: int gcry_mpi_get_flag (gcry_mpi_t A,
3354          enum gcry_mpi_flag FLAG)
3355     Return true when the FLAG is set for A.
3356
3357 -- Function: void gcry_mpi_randomize (gcry_mpi_t W,
3358          unsigned int NBITS, enum gcry_random_level LEVEL)
3359     Set the big integer W to a random value of NBITS, using random
3360     data quality of level LEVEL.  In case NBITS is not a multiple of a
3361     byte, NBITS is rounded up to the next byte boundary.
3362
3363
3364File: gcrypt.info,  Node: Utilities,  Next: Library Copying,  Prev: MPI library,  Up: Top
3365
336612 Utilities
3367************
3368
3369* Menu:
3370
3371* Memory allocation::           Functions related with memory allocation.
3372
3373
3374File: gcrypt.info,  Node: Memory allocation,  Up: Utilities
3375
337612.1 Memory allocation
3377======================
3378
3379 -- Function: void *gcry_malloc (size_t N)
3380     This function tries to allocate N bytes of memory.  On success it
3381     returns a pointer to the memory area, in an out-of-core condition,
3382     it returns NULL.
3383
3384 -- Function: void *gcry_malloc_secure (size_t N)
3385     Like `gcry_malloc', but uses secure memory.
3386
3387 -- Function: void *gcry_calloc (size_t N)
3388     This function tries to allocate N bytes of cleared memory (i.e.
3389     memory that is initialized with zero bytes).  On success it
3390     returns a pointer to the memory area, in an out-of-core condition,
3391     it returns NULL.
3392
3393 -- Function: void *gcry_calloc_secure (size_t N)
3394     Like `gcry_calloc', but uses secure memory.
3395
3396 -- Function: void *gcry_realloc (void *P, size_t N)
3397     This function tries to resize the memory area pointed to by P to N
3398     bytes.  On success it returns a pointer to the new memory area, in
3399     an out-of-core condition, it returns NULL.  Depending on whether
3400     the memory pointed to by P is secure memory or not, gcry_realloc
3401     tries to use secure memory as well.
3402
3403 -- Function: void gcry_free (void *P)
3404     Release the memory area pointed to by P.
3405
3406
3407File: gcrypt.info,  Node: Library Copying,  Next: Copying,  Prev: Utilities,  Up: Top
3408
3409Appendix A GNU LESSER GENERAL PUBLIC LICENSE
3410********************************************
3411
3412                      Version 2.1, February 1999
3413
3414     Copyright (C) 1991, 1999 Free Software Foundation, Inc.
3415     59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
3416
3417     Everyone is permitted to copy and distribute verbatim copies
3418     of this license document, but changing it is not allowed.
3419
3420     [This is the first released version of the Lesser GPL.  It also counts
3421     as the successor of the GNU Library Public License, version 2, hence the
3422     version number 2.1.]
3423
3424A.0.1 Preamble
3425--------------
3426
3427The licenses for most software are designed to take away your freedom
3428to share and change it.  By contrast, the GNU General Public Licenses
3429are intended to guarantee your freedom to share and change free
3430software--to make sure the software is free for all its users.
3431
3432   This license, the Lesser General Public License, applies to some
3433specially designated software--typically libraries--of the Free
3434Software Foundation and other authors who decide to use it.  You can use
3435it too, but we suggest you first think carefully about whether this
3436license or the ordinary General Public License is the better strategy to
3437use in any particular case, based on the explanations below.
3438
3439   When we speak of free software, we are referring to freedom of use,
3440not price.  Our General Public Licenses are designed to make sure that
3441you have the freedom to distribute copies of free software (and charge
3442for this service if you wish); that you receive source code or can get
3443it if you want it; that you can change the software and use pieces of it
3444in new free programs; and that you are informed that you can do these
3445things.
3446
3447   To protect your rights, we need to make restrictions that forbid
3448distributors to deny you these rights or to ask you to surrender these
3449rights.  These restrictions translate to certain responsibilities for
3450you if you distribute copies of the library or if you modify it.
3451
3452   For example, if you distribute copies of the library, whether gratis
3453or for a fee, you must give the recipients all the rights that we gave
3454you.  You must make sure that they, too, receive or can get the source
3455code.  If you link other code with the library, you must provide
3456complete object files to the recipients, so that they can relink them
3457with the library after making changes to the library and recompiling
3458it.  And you must show them these terms so they know their rights.
3459
3460   We protect your rights with a two-step method: (1) we copyright the
3461library, and (2) we offer you this license, which gives you legal
3462permission to copy, distribute and/or modify the library.
3463
3464   To protect each distributor, we want to make it very clear that
3465there is no warranty for the free library.  Also, if the library is
3466modified by someone else and passed on, the recipients should know that
3467what they have is not the original version, so that the original
3468author's reputation will not be affected by problems that might be
3469introduced by others.
3470
3471   Finally, software patents pose a constant threat to the existence of
3472any free program.  We wish to make sure that a company cannot
3473effectively restrict the users of a free program by obtaining a
3474restrictive license from a patent holder.  Therefore, we insist that
3475any patent license obtained for a version of the library must be
3476consistent with the full freedom of use specified in this license.
3477
3478   Most GNU software, including some libraries, is covered by the
3479ordinary GNU General Public License.  This license, the GNU Lesser
3480General Public License, applies to certain designated libraries, and is
3481quite different from the ordinary General Public License.  We use this
3482license for certain libraries in order to permit linking those
3483libraries into non-free programs.
3484
3485   When a program is linked with a library, whether statically or using
3486a shared library, the combination of the two is legally speaking a
3487combined work, a derivative of the original library.  The ordinary
3488General Public License therefore permits such linking only if the
3489entire combination fits its criteria of freedom.  The Lesser General
3490Public License permits more lax criteria for linking other code with
3491the library.
3492
3493   We call this license the "Lesser" General Public License because it
3494does _Less_ to protect the user's freedom than the ordinary General
3495Public License.  It also provides other free software developers Less
3496of an advantage over competing non-free programs.  These disadvantages
3497are the reason we use the ordinary General Public License for many
3498libraries.  However, the Lesser license provides advantages in certain
3499special circumstances.
3500
3501   For example, on rare occasions, there may be a special need to
3502encourage the widest possible use of a certain library, so that it
3503becomes a de-facto standard.  To achieve this, non-free programs must be
3504allowed to use the library.  A more frequent case is that a free
3505library does the same job as widely used non-free libraries.  In this
3506case, there is little to gain by limiting the free library to free
3507software only, so we use the Lesser General Public License.
3508
3509   In other cases, permission to use a particular library in non-free
3510programs enables a greater number of people to use a large body of free
3511software.  For example, permission to use the GNU C Library in non-free
3512programs enables many more people to use the whole GNU operating
3513system, as well as its variant, the GNU/Linux operating system.
3514
3515   Although the Lesser General Public License is Less protective of the
3516users' freedom, it does ensure that the user of a program that is
3517linked with the Library has the freedom and the wherewithal to run that
3518program using a modified version of the Library.
3519
3520   The precise terms and conditions for copying, distribution and
3521modification follow.  Pay close attention to the difference between a
3522"work based on the library" and a "work that uses the library".  The
3523former contains code derived from the library, whereas the latter must
3524be combined with the library in order to run.
3525
3526                   GNU LESSER GENERAL PUBLIC LICENSE
3527    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
3528  0. This License Agreement applies to any software library or other
3529     program which contains a notice placed by the copyright holder or
3530     other authorized party saying it may be distributed under the
3531     terms of this Lesser General Public License (also called "this
3532     License").  Each licensee is addressed as "you".
3533
3534     A "library" means a collection of software functions and/or data
3535     prepared so as to be conveniently linked with application programs
3536     (which use some of those functions and data) to form executables.
3537
3538     The "Library", below, refers to any such software library or work
3539     which has been distributed under these terms.  A "work based on the
3540     Library" means either the Library or any derivative work under
3541     copyright law: that is to say, a work containing the Library or a
3542     portion of it, either verbatim or with modifications and/or
3543     translated straightforwardly into another language.  (Hereinafter,
3544     translation is included without limitation in the term
3545     "modification".)
3546
3547     "Source code" for a work means the preferred form of the work for
3548     making modifications to it.  For a library, complete source code
3549     means all the source code for all modules it contains, plus any
3550     associated interface definition files, plus the scripts used to
3551     control compilation and installation of the library.
3552
3553     Activities other than copying, distribution and modification are
3554     not covered by this License; they are outside its scope.  The act
3555     of running a program using the Library is not restricted, and
3556     output from such a program is covered only if its contents
3557     constitute a work based on the Library (independent of the use of
3558     the Library in a tool for writing it).  Whether that is true
3559     depends on what the Library does and what the program that uses
3560     the Library does.
3561
3562  1. You may copy and distribute verbatim copies of the Library's
3563     complete source code as you receive it, in any medium, provided
3564     that you conspicuously and appropriately publish on each copy an
3565     appropriate copyright notice and disclaimer of warranty; keep
3566     intact all the notices that refer to this License and to the
3567     absence of any warranty; and distribute a copy of this License
3568     along with the Library.
3569
3570     You may charge a fee for the physical act of transferring a copy,
3571     and you may at your option offer warranty protection in exchange
3572     for a fee.
3573
3574  2. You may modify your copy or copies of the Library or any portion
3575     of it, thus forming a work based on the Library, and copy and
3576     distribute such modifications or work under the terms of Section 1
3577     above, provided that you also meet all of these conditions:
3578
3579       a. The modified work must itself be a software library.
3580
3581       b. You must cause the files modified to carry prominent notices
3582          stating that you changed the files and the date of any change.
3583
3584       c. You must cause the whole of the work to be licensed at no
3585          charge to all third parties under the terms of this License.
3586
3587       d. If a facility in the modified Library refers to a function or
3588          a table of data to be supplied by an application program that
3589          uses the facility, other than as an argument passed when the
3590          facility is invoked, then you must make a good faith effort
3591          to ensure that, in the event an application does not supply
3592          such function or table, the facility still operates, and
3593          performs whatever part of its purpose remains meaningful.
3594
3595          (For example, a function in a library to compute square roots
3596          has a purpose that is entirely well-defined independent of the
3597          application.  Therefore, Subsection 2d requires that any
3598          application-supplied function or table used by this function
3599          must be optional: if the application does not supply it, the
3600          square root function must still compute square roots.)
3601
3602     These requirements apply to the modified work as a whole.  If
3603     identifiable sections of that work are not derived from the
3604     Library, and can be reasonably considered independent and separate
3605     works in themselves, then this License, and its terms, do not
3606     apply to those sections when you distribute them as separate
3607     works.  But when you distribute the same sections as part of a
3608     whole which is a work based on the Library, the distribution of
3609     the whole must be on the terms of this License, whose permissions
3610     for other licensees extend to the entire whole, and thus to each
3611     and every part regardless of who wrote it.
3612
3613     Thus, it is not the intent of this section to claim rights or
3614     contest your rights to work written entirely by you; rather, the
3615     intent is to exercise the right to control the distribution of
3616     derivative or collective works based on the Library.
3617
3618     In addition, mere aggregation of another work not based on the
3619     Library with the Library (or with a work based on the Library) on
3620     a volume of a storage or distribution medium does not bring the
3621     other work under the scope of this License.
3622
3623  3. You may opt to apply the terms of the ordinary GNU General Public
3624     License instead of this License to a given copy of the Library.
3625     To do this, you must alter all the notices that refer to this
3626     License, so that they refer to the ordinary GNU General Public
3627     License, version 2, instead of to this License.  (If a newer
3628     version than version 2 of the ordinary GNU General Public License
3629     has appeared, then you can specify that version instead if you
3630     wish.)  Do not make any other change in these notices.
3631
3632     Once this change is made in a given copy, it is irreversible for
3633     that copy, so the ordinary GNU General Public License applies to
3634     all subsequent copies and derivative works made from that copy.
3635
3636     This option is useful when you wish to copy part of the code of
3637     the Library into a program that is not a library.
3638
3639  4. You may copy and distribute the Library (or a portion or
3640     derivative of it, under Section 2) in object code or executable
3641     form under the terms of Sections 1 and 2 above provided that you
3642     accompany it with the complete corresponding machine-readable
3643     source code, which must be distributed under the terms of Sections
3644     1 and 2 above on a medium customarily used for software
3645     interchange.
3646
3647     If distribution of object code is made by offering access to copy
3648     from a designated place, then offering equivalent access to copy
3649     the source code from the same place satisfies the requirement to
3650     distribute the source code, even though third parties are not
3651     compelled to copy the source along with the object code.
3652
3653  5. A program that contains no derivative of any portion of the
3654     Library, but is designed to work with the Library by being
3655     compiled or linked with it, is called a "work that uses the
3656     Library".  Such a work, in isolation, is not a derivative work of
3657     the Library, and therefore falls outside the scope of this License.
3658
3659     However, linking a "work that uses the Library" with the Library
3660     creates an executable that is a derivative of the Library (because
3661     it contains portions of the Library), rather than a "work that
3662     uses the library".  The executable is therefore covered by this
3663     License.  Section 6 states terms for distribution of such
3664     executables.
3665
3666     When a "work that uses the Library" uses material from a header
3667     file that is part of the Library, the object code for the work may
3668     be a derivative work of the Library even though the source code is
3669     not.  Whether this is true is especially significant if the work
3670     can be linked without the Library, or if the work is itself a
3671     library.  The threshold for this to be true is not precisely
3672     defined by law.
3673
3674     If such an object file uses only numerical parameters, data
3675     structure layouts and accessors, and small macros and small inline
3676     functions (ten lines or less in length), then the use of the object
3677     file is unrestricted, regardless of whether it is legally a
3678     derivative work.  (Executables containing this object code plus
3679     portions of the Library will still fall under Section 6.)
3680
3681     Otherwise, if the work is a derivative of the Library, you may
3682     distribute the object code for the work under the terms of Section
3683     6.  Any executables containing that work also fall under Section 6,
3684     whether or not they are linked directly with the Library itself.
3685
3686  6. As an exception to the Sections above, you may also combine or
3687     link a "work that uses the Library" with the Library to produce a
3688     work containing portions of the Library, and distribute that work
3689     under terms of your choice, provided that the terms permit
3690     modification of the work for the customer's own use and reverse
3691     engineering for debugging such modifications.
3692
3693     You must give prominent notice with each copy of the work that the
3694     Library is used in it and that the Library and its use are covered
3695     by this License.  You must supply a copy of this License.  If the
3696     work during execution displays copyright notices, you must include
3697     the copyright notice for the Library among them, as well as a
3698     reference directing the user to the copy of this License.  Also,
3699     you must do one of these things:
3700
3701       a. Accompany the work with the complete corresponding
3702          machine-readable source code for the Library including
3703          whatever changes were used in the work (which must be
3704          distributed under Sections 1 and 2 above); and, if the work
3705          is an executable linked with the Library, with the complete
3706          machine-readable "work that uses the Library", as object code
3707          and/or source code, so that the user can modify the Library
3708          and then relink to produce a modified executable containing
3709          the modified Library.  (It is understood that the user who
3710          changes the contents of definitions files in the Library will
3711          not necessarily be able to recompile the application to use
3712          the modified definitions.)
3713
3714       b. Use a suitable shared library mechanism for linking with the
3715          Library.  A suitable mechanism is one that (1) uses at run
3716          time a copy of the library already present on the user's
3717          computer system, rather than copying library functions into
3718          the executable, and (2) will operate properly with a modified
3719          version of the library, if the user installs one, as long as
3720          the modified version is interface-compatible with the version
3721          that the work was made with.
3722
3723       c. Accompany the work with a written offer, valid for at least
3724          three years, to give the same user the materials specified in
3725          Subsection 6a, above, for a charge no more than the cost of
3726          performing this distribution.
3727
3728       d. If distribution of the work is made by offering access to copy
3729          from a designated place, offer equivalent access to copy the
3730          above specified materials from the same place.
3731
3732       e. Verify that the user has already received a copy of these
3733          materials or that you have already sent this user a copy.
3734
3735     For an executable, the required form of the "work that uses the
3736     Library" must include any data and utility programs needed for
3737     reproducing the executable from it.  However, as a special
3738     exception, the materials to be distributed need not include
3739     anything that is normally distributed (in either source or binary
3740     form) with the major components (compiler, kernel, and so on) of
3741     the operating system on which the executable runs, unless that
3742     component itself accompanies the executable.
3743
3744     It may happen that this requirement contradicts the license
3745     restrictions of other proprietary libraries that do not normally
3746     accompany the operating system.  Such a contradiction means you
3747     cannot use both them and the Library together in an executable
3748     that you distribute.
3749
3750  7. You may place library facilities that are a work based on the
3751     Library side-by-side in a single library together with other
3752     library facilities not covered by this License, and distribute
3753     such a combined library, provided that the separate distribution
3754     of the work based on the Library and of the other library
3755     facilities is otherwise permitted, and provided that you do these
3756     two things:
3757
3758       a. Accompany the combined library with a copy of the same work
3759          based on the Library, uncombined with any other library
3760          facilities.  This must be distributed under the terms of the
3761          Sections above.
3762
3763       b. Give prominent notice with the combined library of the fact
3764          that part of it is a work based on the Library, and explaining
3765          where to find the accompanying uncombined form of the same
3766          work.
3767
3768  8. You may not copy, modify, sublicense, link with, or distribute the
3769     Library except as expressly provided under this License.  Any
3770     attempt otherwise to copy, modify, sublicense, link with, or
3771     distribute the Library is void, and will automatically terminate
3772     your rights under this License.  However, parties who have
3773     received copies, or rights, from you under this License will not
3774     have their licenses terminated so long as such parties remain in
3775     full compliance.
3776
3777  9. You are not required to accept this License, since you have not
3778     signed it.  However, nothing else grants you permission to modify
3779     or distribute the Library or its derivative works.  These actions
3780     are prohibited by law if you do not accept this License.
3781     Therefore, by modifying or distributing the Library (or any work
3782     based on the Library), you indicate your acceptance of this
3783     License to do so, and all its terms and conditions for copying,
3784     distributing or modifying the Library or works based on it.
3785
3786 10. Each time you redistribute the Library (or any work based on the
3787     Library), the recipient automatically receives a license from the
3788     original licensor to copy, distribute, link with or modify the
3789     Library subject to these terms and conditions.  You may not impose
3790     any further restrictions on the recipients' exercise of the rights
3791     granted herein.  You are not responsible for enforcing compliance
3792     by third parties with this License.
3793
3794 11. If, as a consequence of a court judgment or allegation of patent
3795     infringement or for any other reason (not limited to patent
3796     issues), conditions are imposed on you (whether by court order,
3797     agreement or otherwise) that contradict the conditions of this
3798     License, they do not excuse you from the conditions of this
3799     License.  If you cannot distribute so as to satisfy simultaneously
3800     your obligations under this License and any other pertinent
3801     obligations, then as a consequence you may not distribute the
3802     Library at all.  For example, if a patent license would not permit
3803     royalty-free redistribution of the Library by all those who
3804     receive copies directly or indirectly through you, then the only
3805     way you could satisfy both it and this License would be to refrain
3806     entirely from distribution of the Library.
3807
3808     If any portion of this section is held invalid or unenforceable
3809     under any particular circumstance, the balance of the section is
3810     intended to apply, and the section as a whole is intended to apply
3811     in other circumstances.
3812
3813     It is not the purpose of this section to induce you to infringe any
3814     patents or other property right claims or to contest validity of
3815     any such claims; this section has the sole purpose of protecting
3816     the integrity of the free software distribution system which is
3817     implemented by public license practices.  Many people have made
3818     generous contributions to the wide range of software distributed
3819     through that system in reliance on consistent application of that
3820     system; it is up to the author/donor to decide if he or she is
3821     willing to distribute software through any other system and a
3822     licensee cannot impose that choice.
3823
3824     This section is intended to make thoroughly clear what is believed
3825     to be a consequence of the rest of this License.
3826
3827 12. If the distribution and/or use of the Library is restricted in
3828     certain countries either by patents or by copyrighted interfaces,
3829     the original copyright holder who places the Library under this
3830     License may add an explicit geographical distribution limitation
3831     excluding those countries, so that distribution is permitted only
3832     in or among countries not thus excluded.  In such case, this
3833     License incorporates the limitation as if written in the body of
3834     this License.
3835
3836 13. The Free Software Foundation may publish revised and/or new
3837     versions of the Lesser General Public License from time to time.
3838     Such new versions will be similar in spirit to the present version,
3839     but may differ in detail to address new problems or concerns.
3840
3841     Each version is given a distinguishing version number.  If the
3842     Library specifies a version number of this License which applies
3843     to it and "any later version", you have the option of following
3844     the terms and conditions either of that version or of any later
3845     version published by the Free Software Foundation.  If the Library
3846     does not specify a license version number, you may choose any
3847     version ever published by the Free Software Foundation.
3848
3849 14. If you wish to incorporate parts of the Library into other free
3850     programs whose distribution conditions are incompatible with these,
3851     write to the author to ask for permission.  For software which is
3852     copyrighted by the Free Software Foundation, write to the Free
3853     Software Foundation; we sometimes make exceptions for this.  Our
3854     decision will be guided by the two goals of preserving the free
3855     status of all derivatives of our free software and of promoting
3856     the sharing and reuse of software generally.
3857
3858                                NO WARRANTY
3859 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
3860     WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE
3861     LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
3862     HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT
3863     WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
3864     NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
3865     FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
3866     QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU.  SHOULD THE
3867     LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
3868     SERVICING, REPAIR OR CORRECTION.
3869
3870 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
3871     WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
3872     MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE
3873     LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
3874     INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
3875     INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
3876     DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
3877     OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY
3878     OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
3879     ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
3880
3881                      END OF TERMS AND CONDITIONS
3882A.0.2 How to Apply These Terms to Your New Libraries
3883----------------------------------------------------
3884
3885If you develop a new library, and you want it to be of the greatest
3886possible use to the public, we recommend making it free software that
3887everyone can redistribute and change.  You can do so by permitting
3888redistribution under these terms (or, alternatively, under the terms of
3889the ordinary General Public License).
3890
3891   To apply these terms, attach the following notices to the library.
3892It is safest to attach them to the start of each source file to most
3893effectively convey the exclusion of warranty; and each file should have
3894at least the "copyright" line and a pointer to where the full notice is
3895found.
3896
3897     ONE LINE TO GIVE THE LIBRARY'S NAME AND AN IDEA OF WHAT IT DOES.
3898     Copyright (C) YEAR  NAME OF AUTHOR
3899
3900     This library is free software; you can redistribute it and/or modify it
3901     under the terms of the GNU Lesser General Public License as published by
3902     the Free Software Foundation; either version 2.1 of the License, or (at
3903     your option) any later version.
3904
3905     This library is distributed in the hope that it will be useful, but
3906     WITHOUT ANY WARRANTY; without even the implied warranty of
3907     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
3908     Lesser General Public License for more details.
3909
3910     You should have received a copy of the GNU Lesser General Public
3911     License along with this library; if not, write to the Free Software
3912     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
3913     USA.
3914
3915   Also add information on how to contact you by electronic and paper
3916mail.
3917
3918   You should also get your employer (if you work as a programmer) or
3919your school, if any, to sign a "copyright disclaimer" for the library,
3920if necessary.  Here is a sample; alter the names:
3921
3922     Yoyodyne, Inc., hereby disclaims all copyright interest in the library
3923     `Frob' (a library for tweaking knobs) written by James Random Hacker.
3924
3925     SIGNATURE OF TY COON, 1 April 1990
3926     Ty Coon, President of Vice
3927
3928   That's all there is to it!
3929
3930
3931File: gcrypt.info,  Node: Copying,  Next: Concept Index,  Prev: Library Copying,  Up: Top
3932
3933Appendix B GNU GENERAL PUBLIC LICENSE
3934*************************************
3935
3936                         Version 2, June 1991
3937
3938     Copyright (C) 1989, 1991 Free Software Foundation, Inc.
3939     59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
3940
3941     Everyone is permitted to copy and distribute verbatim copies
3942     of this license document, but changing it is not allowed.
3943
3944B.0.1 Preamble
3945--------------
3946
3947The licenses for most software are designed to take away your freedom
3948to share and change it.  By contrast, the GNU General Public License is
3949intended to guarantee your freedom to share and change free
3950software--to make sure the software is free for all its users.  This
3951General Public License applies to most of the Free Software
3952Foundation's software and to any other program whose authors commit to
3953using it.  (Some other Free Software Foundation software is covered by
3954the GNU Library General Public License instead.)  You can apply it to
3955your programs, too.
3956
3957   When we speak of free software, we are referring to freedom, not
3958price.  Our General Public Licenses are designed to make sure that you
3959have the freedom to distribute copies of free software (and charge for
3960this service if you wish), that you receive source code or can get it
3961if you want it, that you can change the software or use pieces of it in
3962new free programs; and that you know you can do these things.
3963
3964   To protect your rights, we need to make restrictions that forbid
3965anyone to deny you these rights or to ask you to surrender the rights.
3966These restrictions translate to certain responsibilities for you if you
3967distribute copies of the software, or if you modify it.
3968
3969   For example, if you distribute copies of such a program, whether
3970gratis or for a fee, you must give the recipients all the rights that
3971you have.  You must make sure that they, too, receive or can get the
3972source code.  And you must show them these terms so they know their
3973rights.
3974
3975   We protect your rights with two steps: (1) copyright the software,
3976and (2) offer you this license which gives you legal permission to copy,
3977distribute and/or modify the software.
3978
3979   Also, for each author's protection and ours, we want to make certain
3980that everyone understands that there is no warranty for this free
3981software.  If the software is modified by someone else and passed on, we
3982want its recipients to know that what they have is not the original, so
3983that any problems introduced by others will not reflect on the original
3984authors' reputations.
3985
3986   Finally, any free program is threatened constantly by software
3987patents.  We wish to avoid the danger that redistributors of a free
3988program will individually obtain patent licenses, in effect making the
3989program proprietary.  To prevent this, we have made it clear that any
3990patent must be licensed for everyone's free use or not licensed at all.
3991
3992   The precise terms and conditions for copying, distribution and
3993modification follow.
3994
3995    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
3996  1. This License applies to any program or other work which contains a
3997     notice placed by the copyright holder saying it may be distributed
3998     under the terms of this General Public License.  The "Program",
3999     below, refers to any such program or work, and a "work based on
4000     the Program" means either the Program or any derivative work under
4001     copyright law: that is to say, a work containing the Program or a
4002     portion of it, either verbatim or with modifications and/or
4003     translated into another language.  (Hereinafter, translation is
4004     included without limitation in the term "modification".)  Each
4005     licensee is addressed as "you".
4006
4007     Activities other than copying, distribution and modification are
4008     not covered by this License; they are outside its scope.  The act
4009     of running the Program is not restricted, and the output from the
4010     Program is covered only if its contents constitute a work based on
4011     the Program (independent of having been made by running the
4012     Program).  Whether that is true depends on what the Program does.
4013
4014  2. You may copy and distribute verbatim copies of the Program's
4015     source code as you receive it, in any medium, provided that you
4016     conspicuously and appropriately publish on each copy an appropriate
4017     copyright notice and disclaimer of warranty; keep intact all the
4018     notices that refer to this License and to the absence of any
4019     warranty; and give any other recipients of the Program a copy of
4020     this License along with the Program.
4021
4022     You may charge a fee for the physical act of transferring a copy,
4023     and you may at your option offer warranty protection in exchange
4024     for a fee.
4025
4026  3. You may modify your copy or copies of the Program or any portion
4027     of it, thus forming a work based on the Program, and copy and
4028     distribute such modifications or work under the terms of Section 1
4029     above, provided that you also meet all of these conditions:
4030
4031       a. You must cause the modified files to carry prominent notices
4032          stating that you changed the files and the date of any change.
4033
4034       b. You must cause any work that you distribute or publish, that
4035          in whole or in part contains or is derived from the Program
4036          or any part thereof, to be licensed as a whole at no charge
4037          to all third parties under the terms of this License.
4038
4039       c. If the modified program normally reads commands interactively
4040          when run, you must cause it, when started running for such
4041          interactive use in the most ordinary way, to print or display
4042          an announcement including an appropriate copyright notice and
4043          a notice that there is no warranty (or else, saying that you
4044          provide a warranty) and that users may redistribute the
4045          program under these conditions, and telling the user how to
4046          view a copy of this License.  (Exception: if the Program
4047          itself is interactive but does not normally print such an
4048          announcement, your work based on the Program is not required
4049          to print an announcement.)
4050
4051     These requirements apply to the modified work as a whole.  If
4052     identifiable sections of that work are not derived from the
4053     Program, and can be reasonably considered independent and separate
4054     works in themselves, then this License, and its terms, do not
4055     apply to those sections when you distribute them as separate
4056     works.  But when you distribute the same sections as part of a
4057     whole which is a work based on the Program, the distribution of
4058     the whole must be on the terms of this License, whose permissions
4059     for other licensees extend to the entire whole, and thus to each
4060     and every part regardless of who wrote it.
4061
4062     Thus, it is not the intent of this section to claim rights or
4063     contest your rights to work written entirely by you; rather, the
4064     intent is to exercise the right to control the distribution of
4065     derivative or collective works based on the Program.
4066
4067     In addition, mere aggregation of another work not based on the
4068     Program with the Program (or with a work based on the Program) on
4069     a volume of a storage or distribution medium does not bring the
4070     other work under the scope of this License.
4071
4072  4. You may copy and distribute the Program (or a work based on it,
4073     under Section 2) in object code or executable form under the terms
4074     of Sections 1 and 2 above provided that you also do one of the
4075     following:
4076
4077       a. Accompany it with the complete corresponding machine-readable
4078          source code, which must be distributed under the terms of
4079          Sections 1 and 2 above on a medium customarily used for
4080          software interchange; or,
4081
4082       b. Accompany it with a written offer, valid for at least three
4083          years, to give any third party, for a charge no more than your
4084          cost of physically performing source distribution, a complete
4085          machine-readable copy of the corresponding source code, to be
4086          distributed under the terms of Sections 1 and 2 above on a
4087          medium customarily used for software interchange; or,
4088
4089       c. Accompany it with the information you received as to the offer
4090          to distribute corresponding source code.  (This alternative is
4091          allowed only for noncommercial distribution and only if you
4092          received the program in object code or executable form with
4093          such an offer, in accord with Subsection b above.)
4094
4095     The source code for a work means the preferred form of the work for
4096     making modifications to it.  For an executable work, complete
4097     source code means all the source code for all modules it contains,
4098     plus any associated interface definition files, plus the scripts
4099     used to control compilation and installation of the executable.
4100     However, as a special exception, the source code distributed need
4101     not include anything that is normally distributed (in either
4102     source or binary form) with the major components (compiler,
4103     kernel, and so on) of the operating system on which the executable
4104     runs, unless that component itself accompanies the executable.
4105
4106     If distribution of executable or object code is made by offering
4107     access to copy from a designated place, then offering equivalent
4108     access to copy the source code from the same place counts as
4109     distribution of the source code, even though third parties are not
4110     compelled to copy the source along with the object code.
4111
4112  5. You may not copy, modify, sublicense, or distribute the Program
4113     except as expressly provided under this License.  Any attempt
4114     otherwise to copy, modify, sublicense or distribute the Program is
4115     void, and will automatically terminate your rights under this
4116     License.  However, parties who have received copies, or rights,
4117     from you under this License will not have their licenses
4118     terminated so long as such parties remain in full compliance.
4119
4120  6. You are not required to accept this License, since you have not
4121     signed it.  However, nothing else grants you permission to modify
4122     or distribute the Program or its derivative works.  These actions
4123     are prohibited by law if you do not accept this License.
4124     Therefore, by modifying or distributing the Program (or any work
4125     based on the Program), you indicate your acceptance of this
4126     License to do so, and all its terms and conditions for copying,
4127     distributing or modifying the Program or works based on it.
4128
4129  7. Each time you redistribute the Program (or any work based on the
4130     Program), the recipient automatically receives a license from the
4131     original licensor to copy, distribute or modify the Program
4132     subject to these terms and conditions.  You may not impose any
4133     further restrictions on the recipients' exercise of the rights
4134     granted herein.  You are not responsible for enforcing compliance
4135     by third parties to this License.
4136
4137  8. If, as a consequence of a court judgment or allegation of patent
4138     infringement or for any other reason (not limited to patent
4139     issues), conditions are imposed on you (whether by court order,
4140     agreement or otherwise) that contradict the conditions of this
4141     License, they do not excuse you from the conditions of this
4142     License.  If you cannot distribute so as to satisfy simultaneously
4143     your obligations under this License and any other pertinent
4144     obligations, then as a consequence you may not distribute the
4145     Program at all.  For example, if a patent license would not permit
4146     royalty-free redistribution of the Program by all those who
4147     receive copies directly or indirectly through you, then the only
4148     way you could satisfy both it and this License would be to refrain
4149     entirely from distribution of the Program.
4150
4151     If any portion of this section is held invalid or unenforceable
4152     under any particular circumstance, the balance of the section is
4153     intended to apply and the section as a whole is intended to apply
4154     in other circumstances.
4155
4156     It is not the purpose of this section to induce you to infringe any
4157     patents or other property right claims or to contest validity of
4158     any such claims; this section has the sole purpose of protecting
4159     the integrity of the free software distribution system, which is
4160     implemented by public license practices.  Many people have made
4161     generous contributions to the wide range of software distributed
4162     through that system in reliance on consistent application of that
4163     system; it is up to the author/donor to decide if he or she is
4164     willing to distribute software through any other system and a
4165     licensee cannot impose that choice.
4166
4167     This section is intended to make thoroughly clear what is believed
4168     to be a consequence of the rest of this License.
4169
4170  9. If the distribution and/or use of the Program is restricted in
4171     certain countries either by patents or by copyrighted interfaces,
4172     the original copyright holder who places the Program under this
4173     License may add an explicit geographical distribution limitation
4174     excluding those countries, so that distribution is permitted only
4175     in or among countries not thus excluded.  In such case, this
4176     License incorporates the limitation as if written in the body of
4177     this License.
4178
4179 10. The Free Software Foundation may publish revised and/or new
4180     versions of the General Public License from time to time.  Such
4181     new versions will be similar in spirit to the present version, but
4182     may differ in detail to address new problems or concerns.
4183
4184     Each version is given a distinguishing version number.  If the
4185     Program specifies a version number of this License which applies
4186     to it and "any later version", you have the option of following
4187     the terms and conditions either of that version or of any later
4188     version published by the Free Software Foundation.  If the Program
4189     does not specify a version number of this License, you may choose
4190     any version ever published by the Free Software Foundation.
4191
4192 11. If you wish to incorporate parts of the Program into other free
4193     programs whose distribution conditions are different, write to the
4194     author to ask for permission.  For software which is copyrighted
4195     by the Free Software Foundation, write to the Free Software
4196     Foundation; we sometimes make exceptions for this.  Our decision
4197     will be guided by the two goals of preserving the free status of
4198     all derivatives of our free software and of promoting the sharing
4199     and reuse of software generally.
4200
4201                                NO WARRANTY
4202 12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
4203     WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
4204     LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
4205     HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
4206     WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
4207     NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4208     FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
4209     QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
4210     PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
4211     SERVICING, REPAIR OR CORRECTION.
4212
4213 13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
4214     WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
4215     MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
4216     LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
4217     INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
4218     INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
4219     DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
4220     OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
4221     OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
4222     ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
4223
4224                      END OF TERMS AND CONDITIONS
4225How to Apply These Terms to Your New Programs
4226=============================================
4227
4228If you develop a new program, and you want it to be of the greatest
4229possible use to the public, the best way to achieve this is to make it
4230free software which everyone can redistribute and change under these
4231terms.
4232
4233   To do so, attach the following notices to the program.  It is safest
4234to attach them to the start of each source file to most effectively
4235convey the exclusion of warranty; and each file should have at least
4236the "copyright" line and a pointer to where the full notice is found.
4237
4238     ONE LINE TO GIVE THE PROGRAM'S NAME AND AN IDEA OF WHAT IT DOES.
4239     Copyright (C) 19YY  NAME OF AUTHOR
4240
4241     This program is free software; you can redistribute it and/or
4242     modify it under the terms of the GNU General Public License
4243     as published by the Free Software Foundation; either version 2
4244     of the License, or (at your option) any later version.
4245
4246     This program is distributed in the hope that it will be useful,
4247     but WITHOUT ANY WARRANTY; without even the implied warranty of
4248     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4249     GNU General Public License for more details.
4250
4251     You should have received a copy of the GNU General Public License along
4252     with this program; if not, write to the Free Software Foundation, Inc.,
4253     59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4254
4255   Also add information on how to contact you by electronic and paper
4256mail.
4257
4258   If the program is interactive, make it output a short notice like
4259this when it starts in an interactive mode:
4260
4261     Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
4262     Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
4263     type `show w'.  This is free software, and you are welcome
4264     to redistribute it under certain conditions; type `show c'
4265     for details.
4266
4267   The hypothetical commands `show w' and `show c' should show the
4268appropriate parts of the General Public License.  Of course, the
4269commands you use may be called something other than `show w' and `show
4270c'; they could even be mouse-clicks or menu items--whatever suits your
4271program.
4272
4273   You should also get your employer (if you work as a programmer) or
4274your school, if any, to sign a "copyright disclaimer" for the program,
4275if necessary.  Here is a sample; alter the names:
4276
4277     Yoyodyne, Inc., hereby disclaims all copyright
4278     interest in the program `Gnomovision'
4279     (which makes passes at compilers) written
4280     by James Hacker.
4281
4282     SIGNATURE OF TY COON, 1 April 1989
4283     Ty Coon, President of Vice
4284
4285   This General Public License does not permit incorporating your
4286program into proprietary programs.  If your program is a subroutine
4287library, you may consider it more useful to permit linking proprietary
4288applications with the library.  If this is what you want to do, use the
4289GNU Library General Public License instead of this License.
4290
4291
4292File: gcrypt.info,  Node: Concept Index,  Next: Function and Data Index,  Prev: Copying,  Up: Top
4293
4294Concept Index
4295*************
4296
4297[index]
4298* Menu:
4299
4300* error codes:                           Error Values.          (line 6)
4301* error codes, list of <1>:              Error Codes.           (line 6)
4302* error codes, list of:                  Error Sources.         (line 6)
4303* error codes, printing of:              Error Strings.         (line 6)
4304* error sources:                         Error Values.          (line 6)
4305* error sources, printing of:            Error Strings.         (line 6)
4306* error strings:                         Error Strings.         (line 6)
4307* error values:                          Error Values.          (line 6)
4308* error values, printing of:             Error Strings.         (line 6)
4309* GPL, GNU General Public License:       Copying.               (line 6)
4310* LGPL, Lesser General Public License:   Library Copying.       (line 6)
4311
4312
4313File: gcrypt.info,  Node: Function and Data Index,  Prev: Concept Index,  Up: Top
4314
4315Function and Data Index
4316***********************
4317
4318[index]
4319* Menu:
4320
4321* *:                                     Retrieving random numbers.
4322                                                              (line  13)
4323* *gcry_calloc:                          Memory allocation.   (line  15)
4324* *gcry_calloc_secure:                   Memory allocation.   (line  21)
4325* *gcry_malloc:                          Memory allocation.   (line   7)
4326* *gcry_malloc_secure:                   Memory allocation.   (line  12)
4327* *gcry_realloc:                         Memory allocation.   (line  24)
4328* AM_PATH_LIBGCRYPT:                     Building sources using Automake.
4329                                                              (line  13)
4330* char <1>:                              Working with hash algorithms.
4331                                                              (line 117)
4332* char <2>:                              General cipher functions.
4333                                                              (line  39)
4334* char:                                  Initializing the library.
4335                                                              (line  13)
4336* enum:                                  Quality of random numbers.
4337                                                              (line   9)
4338* gcry_ac_close:                         Working with handles.
4339                                                              (line  21)
4340* gcry_ac_data_clear:                    Working with sets of data.
4341                                                              (line  68)
4342* gcry_ac_data_copy:                     Working with sets of data.
4343                                                              (line  48)
4344* gcry_ac_data_decrypt:                  Using cryptographic functions.
4345                                                              (line  22)
4346* gcry_ac_data_destroy:                  Working with sets of data.
4347                                                              (line  36)
4348* gcry_ac_data_encrypt:                  Using cryptographic functions.
4349                                                              (line  15)
4350* gcry_ac_data_get_index:                Working with sets of data.
4351                                                              (line  62)
4352* gcry_ac_data_get_name:                 Working with sets of data.
4353                                                              (line  55)
4354* gcry_ac_data_new:                      Working with sets of data.
4355                                                              (line  33)
4356* gcry_ac_data_set:                      Working with sets of data.
4357                                                              (line  40)
4358* gcry_ac_data_sign:                     Using cryptographic functions.
4359                                                              (line  30)
4360* gcry_ac_data_t:                        Working with sets of data.
4361                                                              (line  19)
4362* gcry_ac_data_verify:                   Using cryptographic functions.
4363                                                              (line  36)
4364* gcry_ac_id_t:                          Available asymmetric algorithms.
4365                                                              (line  11)
4366* gcry_ac_id_to_name:                    Handle-independent functions.
4367                                                              (line   8)
4368* gcry_ac_key_data_get:                  Working with keys.   (line  92)
4369* gcry_ac_key_destroy:                   Working with keys.   (line  85)
4370* gcry_ac_key_get_grip:                  Working with keys.   (line 104)
4371* gcry_ac_key_get_nbits:                 Working with keys.   (line 100)
4372* gcry_ac_key_init:                      Working with keys.   (line  30)
4373* gcry_ac_key_pair_destroy:              Working with keys.   (line  89)
4374* gcry_ac_key_pair_extract:              Working with keys.   (line  82)
4375* gcry_ac_key_pair_generate:             Working with keys.   (line  36)
4376* gcry_ac_key_pair_t:                    Working with keys.   (line  20)
4377* gcry_ac_key_t:                         Working with keys.   (line  16)
4378* gcry_ac_key_test:                      Working with keys.   (line  96)
4379* gcry_ac_key_type_t:                    Working with keys.   (line   7)
4380* gcry_ac_name_to_id:                    Handle-independent functions.
4381                                                              (line  13)
4382* gcry_ac_open:                          Working with handles.
4383                                                              (line  11)
4384* gcry_cipher_algo_info:                 General cipher functions.
4385                                                              (line  12)
4386* gcry_cipher_close:                     Working with cipher handles.
4387                                                              (line  52)
4388* gcry_cipher_ctl:                       Working with cipher handles.
4389                                                              (line 152)
4390* gcry_cipher_decrypt:                   Working with cipher handles.
4391                                                              (line 122)
4392* gcry_cipher_decrypt_t:                 Cipher modules.      (line  80)
4393* gcry_cipher_encrypt:                   Working with cipher handles.
4394                                                              (line 104)
4395* gcry_cipher_encrypt_t:                 Cipher modules.      (line  75)
4396* gcry_cipher_info:                      Working with cipher handles.
4397                                                              (line 161)
4398* gcry_cipher_list:                      Cipher modules.      (line 106)
4399* gcry_cipher_map_name:                  General cipher functions.
4400                                                              (line  45)
4401* gcry_cipher_mode_from_oid:             General cipher functions.
4402                                                              (line  50)
4403* gcry_cipher_oid_spec_t:                Cipher modules.      (line  60)
4404* gcry_cipher_open:                      Working with cipher handles.
4405                                                              (line  11)
4406* gcry_cipher_register:                  Cipher modules.      (line  96)
4407* gcry_cipher_reset:                     Working with cipher handles.
4408                                                              (line  92)
4409* gcry_cipher_setctr:                    Working with cipher handles.
4410                                                              (line  84)
4411* gcry_cipher_setiv:                     Working with cipher handles.
4412                                                              (line  76)
4413* gcry_cipher_setkey:                    Working with cipher handles.
4414                                                              (line  59)
4415* gcry_cipher_setkey_t:                  Cipher modules.      (line  70)
4416* gcry_cipher_spec_t:                    Cipher modules.      (line  12)
4417* gcry_cipher_stdecrypt_t:               Cipher modules.      (line  90)
4418* gcry_cipher_stencrypt_t:               Cipher modules.      (line  85)
4419* gcry_cipher_sync:                      Working with cipher handles.
4420                                                              (line 142)
4421* gcry_cipher_unregister:                Cipher modules.      (line 101)
4422* gcry_control:                          Controlling the library.
4423                                                              (line   7)
4424* gcry_create_nonce:                     Retrieving random numbers.
4425                                                              (line  24)
4426* gcry_err_code:                         Error Values.        (line  43)
4427* gcry_err_code_from_errno:              Error Values.        (line  95)
4428* gcry_err_code_t:                       Error Values.        (line   7)
4429* gcry_err_code_to_errno:                Error Values.        (line 100)
4430* gcry_err_make:                         Error Values.        (line  57)
4431* gcry_err_make_from_errno:              Error Values.        (line  81)
4432* gcry_err_source:                       Error Values.        (line  49)
4433* gcry_err_source_t:                     Error Values.        (line  14)
4434* gcry_error:                            Error Values.        (line  64)
4435* gcry_error_from_errno:                 Error Values.        (line  86)
4436* gcry_error_t:                          Error Values.        (line  25)
4437* gcry_free:                             Memory allocation.   (line  31)
4438* gcry_handler_alloc_t:                  Allocation handler.  (line  12)
4439* gcry_handler_error_t:                  Error handler.       (line  20)
4440* gcry_handler_free_t:                   Allocation handler.  (line  24)
4441* gcry_handler_log_t:                    Logging handler.     (line   7)
4442* gcry_handler_no_mem_t:                 Error handler.       (line  10)
4443* gcry_handler_progress_t:               Progress handler.    (line  10)
4444* gcry_handler_realloc_t:                Allocation handler.  (line  20)
4445* gcry_handler_secure_check_t:           Allocation handler.  (line  16)
4446* gcry_md_close:                         Working with hash algorithms.
4447                                                              (line  59)
4448* gcry_md_copy:                          Working with hash algorithms.
4449                                                              (line  80)
4450* gcry_md_enable:                        Working with hash algorithms.
4451                                                              (line  43)
4452* gcry_md_final:                         Working with hash algorithms.
4453                                                              (line 107)
4454* gcry_md_final_t:                       Hash algorithm modules.
4455                                                              (line  73)
4456* gcry_md_get_algo:                      Working with hash algorithms.
4457                                                              (line 193)
4458* gcry_md_get_asnoid:                    Working with hash algorithms.
4459                                                              (line 165)
4460* gcry_md_hash_buffer:                   Working with hash algorithms.
4461                                                              (line 132)
4462* gcry_md_init_t:                        Hash algorithm modules.
4463                                                              (line  65)
4464* gcry_md_is_enabled:                    Working with hash algorithms.
4465                                                              (line 204)
4466* gcry_md_is_secure:                     Working with hash algorithms.
4467                                                              (line 199)
4468* gcry_md_list:                          Hash algorithm modules.
4469                                                              (line  91)
4470* gcry_md_map_name:                      Working with hash algorithms.
4471                                                              (line 155)
4472* gcry_md_oid_spec_t:                    Hash algorithm modules.
4473                                                              (line  57)
4474* gcry_md_open:                          Working with hash algorithms.
4475                                                              (line  11)
4476* gcry_md_putc:                          Working with hash algorithms.
4477                                                              (line  97)
4478* gcry_md_read_t:                        Hash algorithm modules.
4479                                                              (line  77)
4480* gcry_md_register:                      Hash algorithm modules.
4481                                                              (line  82)
4482* gcry_md_reset:                         Working with hash algorithms.
4483                                                              (line  68)
4484* gcry_md_setkey:                        Working with hash algorithms.
4485                                                              (line  52)
4486* gcry_md_spec_t:                        Hash algorithm modules.
4487                                                              (line  12)
4488* gcry_md_start_debug:                   Working with hash algorithms.
4489                                                              (line 215)
4490* gcry_md_stop_debug:                    Working with hash algorithms.
4491                                                              (line 223)
4492* gcry_md_test_algo:                     Working with hash algorithms.
4493                                                              (line 178)
4494* gcry_md_unregister:                    Hash algorithm modules.
4495                                                              (line  87)
4496* gcry_md_write:                         Working with hash algorithms.
4497                                                              (line  92)
4498* gcry_md_write_t:                       Hash algorithm modules.
4499                                                              (line  69)
4500* gcry_module_t:                         Modules.             (line  10)
4501* gcry_mpi_add:                          Calculations.        (line  10)
4502* gcry_mpi_add_ui:                       Calculations.        (line  14)
4503* gcry_mpi_addm:                         Calculations.        (line  18)
4504* gcry_mpi_aprint:                       MPI formats.         (line  53)
4505* gcry_mpi_clear_bit:                    Bit manipulations.   (line  19)
4506* gcry_mpi_clear_flag:                   Miscellaneous.       (line  32)
4507* gcry_mpi_clear_highbit:                Bit manipulations.   (line  25)
4508* gcry_mpi_cmp:                          Comparisons.         (line   9)
4509* gcry_mpi_cmp_ui:                       Comparisons.         (line  13)
4510* gcry_mpi_copy:                         Basic functions.     (line  23)
4511* gcry_mpi_div:                          Calculations.        (line  50)
4512* gcry_mpi_dump:                         MPI formats.         (line  60)
4513* gcry_mpi_gcd:                          Calculations.        (line  63)
4514* gcry_mpi_get_flag:                     Miscellaneous.       (line  37)
4515* gcry_mpi_get_nbits:                    Bit manipulations.   (line  10)
4516* gcry_mpi_get_opaque:                   Miscellaneous.       (line  20)
4517* gcry_mpi_invm:                         Calculations.        (line  68)
4518* gcry_mpi_mod:                          Calculations.        (line  55)
4519* gcry_mpi_mul:                          Calculations.        (line  34)
4520* gcry_mpi_mul_2exp:                     Calculations.        (line  46)
4521* gcry_mpi_mul_ui:                       Calculations.        (line  38)
4522* gcry_mpi_mulm:                         Calculations.        (line  42)
4523* gcry_mpi_new:                          Basic functions.     (line  10)
4524* gcry_mpi_powm:                         Calculations.        (line  59)
4525* gcry_mpi_print:                        MPI formats.         (line  45)
4526* gcry_mpi_randomize:                    Miscellaneous.       (line  41)
4527* gcry_mpi_release:                      Basic functions.     (line  26)
4528* gcry_mpi_rshift:                       Bit manipulations.   (line  29)
4529* gcry_mpi_scan:                         MPI formats.         (line  12)
4530* gcry_mpi_set:                          Basic functions.     (line  33)
4531* gcry_mpi_set_bit:                      Bit manipulations.   (line  16)
4532* gcry_mpi_set_flag:                     Miscellaneous.       (line  26)
4533* gcry_mpi_set_highbit:                  Bit manipulations.   (line  22)
4534* gcry_mpi_set_opaque:                   Miscellaneous.       (line   8)
4535* gcry_mpi_set_ui:                       Basic functions.     (line  37)
4536* gcry_mpi_snew:                         Basic functions.     (line  17)
4537* gcry_mpi_sub:                          Calculations.        (line  22)
4538* gcry_mpi_sub_ui:                       Calculations.        (line  26)
4539* gcry_mpi_subm:                         Calculations.        (line  30)
4540* gcry_mpi_swap:                         Basic functions.     (line  44)
4541* gcry_mpi_t:                            Data types.          (line   7)
4542* gcry_mpi_test_bit:                     Bit manipulations.   (line  13)
4543* gcry_pk_algo_info:                     General public-key related Functions.
4544                                                              (line  46)
4545* gcry_pk_algo_name:                     General public-key related Functions.
4546                                                              (line  10)
4547* gcry_pk_check_secret_key_t:            Public key modules.  (line  91)
4548* gcry_pk_ctl:                           General public-key related Functions.
4549                                                              (line  96)
4550* gcry_pk_decrypt:                       Cryptographic Functions.
4551                                                              (line  85)
4552* gcry_pk_decrypt_t:                     Public key modules.  (line 101)
4553* gcry_pk_encrypt:                       Cryptographic Functions.
4554                                                              (line  29)
4555* gcry_pk_encrypt_t:                     Public key modules.  (line  96)
4556* gcry_pk_generate_t:                    Public key modules.  (line  86)
4557* gcry_pk_genkey:                        General public-key related Functions.
4558                                                              (line 111)
4559* gcry_pk_get_keygrip:                   General public-key related Functions.
4560                                                              (line  28)
4561* gcry_pk_get_nbits:                     General public-key related Functions.
4562                                                              (line  23)
4563* gcry_pk_get_nbits_t:                   Public key modules.  (line 116)
4564* gcry_pk_list:                          Public key modules.  (line 131)
4565* gcry_pk_map_name:                      General public-key related Functions.
4566                                                              (line  15)
4567* gcry_pk_register:                      Public key modules.  (line 121)
4568* gcry_pk_sign:                          Cryptographic Functions.
4569                                                              (line 117)
4570* gcry_pk_sign_t:                        Public key modules.  (line 106)
4571* gcry_pk_spec_t:                        Public key modules.  (line  12)
4572* gcry_pk_test_algo:                     General public-key related Functions.
4573                                                              (line  19)
4574* gcry_pk_testkey:                       General public-key related Functions.
4575                                                              (line  39)
4576* gcry_pk_unregister:                    Public key modules.  (line 127)
4577* gcry_pk_verify:                        Cryptographic Functions.
4578                                                              (line 170)
4579* gcry_pk_verify_t:                      Public key modules.  (line 111)
4580* gcry_randomize:                        Retrieving random numbers.
4581                                                              (line   8)
4582* gcry_set_allocation_handler:           Allocation handler.  (line  34)
4583* gcry_set_fatalerror_handler:           Error handler.       (line  25)
4584* gcry_set_log_handler:                  Logging handler.     (line  12)
4585* gcry_set_outofcore_handler:            Error handler.       (line  15)
4586* gcry_set_progress_handler:             Progress handler.    (line  21)
4587* gcry_sexp_build:                       Working with S-expressions.
4588                                                              (line  43)
4589* gcry_sexp_canon_len:                   Working with S-expressions.
4590                                                              (line 116)
4591* gcry_sexp_car:                         Working with S-expressions.
4592                                                              (line 146)
4593* gcry_sexp_cdr:                         Working with S-expressions.
4594                                                              (line 151)
4595* gcry_sexp_create:                      Working with S-expressions.
4596                                                              (line  26)
4597* gcry_sexp_dump:                        Working with S-expressions.
4598                                                              (line 107)
4599* gcry_sexp_find_token:                  Working with S-expressions.
4600                                                              (line 129)
4601* gcry_sexp_length:                      Working with S-expressions.
4602                                                              (line 136)
4603* gcry_sexp_new:                         Working with S-expressions.
4604                                                              (line  13)
4605* gcry_sexp_nth:                         Working with S-expressions.
4606                                                              (line 141)
4607* gcry_sexp_nth_data:                    Working with S-expressions.
4608                                                              (line 159)
4609* gcry_sexp_nth_mpi:                     Working with S-expressions.
4610                                                              (line 177)
4611* gcry_sexp_release:                     Working with S-expressions.
4612                                                              (line  76)
4613* gcry_sexp_sprint:                      Working with S-expressions.
4614                                                              (line  84)
4615* gcry_sexp_sscan:                       Working with S-expressions.
4616                                                              (line  37)
4617* gcry_sexp_t:                           Data types for S-expressions.
4618                                                              (line   7)
4619* gcry_strerror:                         Error Strings.       (line   7)
4620* gcry_strsource:                        Error Strings.       (line  13)
4621* int <1>:                               Working with sets of data.
4622                                                              (line  51)
4623* int:                                   Working with hash algorithms.
4624                                                              (line 184)
4625
4626
4627
4628Tag Table:
4629Node: Top730
4630Node: Introduction6207
4631Node: Getting Started6581
4632Node: Features7464
4633Node: Overview8254
4634Node: Preparation8902
4635Node: Header9700
4636Node: Building sources10583
4637Node: Building sources using Automake12505
4638Node: Initializing the library13686
4639Node: Multi Threading14729
4640Ref: Multi Threading-Footnote-118634
4641Node: Generalities19042
4642Node: Controlling the library19367
4643Node: Modules19751
4644Node: Error Handling20530
4645Node: Error Values23055
4646Node: Error Sources27995
4647Node: Error Codes30266
4648Node: Error Strings33227
4649Node: Handler Functions34379
4650Node: Progress handler34938
4651Node: Allocation handler36885
4652Node: Error handler38180
4653Node: Logging handler39237
4654Node: Symmetric cryptography39743
4655Node: Available ciphers40532
4656Node: Cipher modules42436
4657Node: Available cipher modes46959
4658Node: Working with cipher handles47638
4659Node: General cipher functions55498
4660Node: Hashing57975
4661Node: Available hash algorithms58781
4662Node: Hash algorithm modules60808
4663Node: Working with hash algorithms64655
4664Node: Public Key cryptography (I)75048
4665Node: Available algorithms75901
4666Node: Used S-expressions76254
4667Node: Public key modules78046
4668Node: Cryptographic Functions83634
4669Node: General public-key related Functions91123
4670Node: Public Key cryptography (II)98345
4671Node: Available asymmetric algorithms99252
4672Node: Working with sets of data99932
4673Node: Working with handles102954
4674Node: Working with keys103898
4675Node: Using cryptographic functions107960
4676Node: Handle-independent functions109778
4677Node: Random Numbers110392
4678Node: Quality of random numbers110687
4679Node: Retrieving random numbers111343
4680Node: S-expressions112755
4681Node: Data types for S-expressions113399
4682Node: Working with S-expressions113725
4683Node: MPI library122259
4684Node: Data types123567
4685Node: Basic functions123773
4686Node: MPI formats125841
4687Node: Calculations128631
4688Node: Comparisons130886
4689Node: Bit manipulations131504
4690Node: Miscellaneous132648
4691Node: Utilities134492
4692Node: Memory allocation134696
4693Node: Library Copying135952
4694Node: Copying164116
4695Node: Concept Index183319
4696Node: Function and Data Index184274
4697
4698End Tag Table