diff --git a/ChangeLog b/ChangeLog index 3ffab3eb..442618dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,1121 +1,1130 @@ +2007-02-22 Werner Koch + + * configure.ac: New option --enable-random-daemon. + Create versioninfo.rc and provide the build information. + +2007-02-21 Werner Koch + + * Makefile.am, configure.ac: Ignore w32-dll/ + 2007-02-20 Werner Koch * configure.ac: Bump LT version to C14/A3/R0 in preparation for a release. * autogen.sh: Add option --force. * configure.ac: New option --disable-endian-check. Use a real noexecstack test instead of requiring an option. Add SVN version magic. 2007-02-02 Werner Koch * configure.ac (FALLBACK_SOCKLEN_T): Special case for mingw32. 2006-11-15 Werner Koch * autogen.sh: Add convenience option --build-amd64. 2006-10-20 Werner Koch * Makefile.am (stowinstall): New convenience target. 2006-10-12 Marcus Brinkmann * configure.ac (FALLBACK_SOCKLEN_T): Third time is a charm. Define gcry_socklen_t, to avoid conflicts with socklen_t definitions by autoconf. 2006-10-11 Marcus Brinkmann * configure.ac (FALLBACK_SOCKLEN_T): Rewrite in terms of socklen.m4. 2006-10-11 Marcus Brinkmann * acinclude.m4 (GNUPG_FIX_HDR_VERSION): Removed. * configure.ac: Do not call GNUPG_FIX_HDR_VERSION. 2006-10-10 Marcus Brinkmann * configure.ac: Invoke AC_CHECK_SOCKLEN_TYPE. (AC_CONFIG_FILES): Add src/gcrypt.h. (AC_CONFIG_SRCDIR): Change to src/libgcrypt.vers. 2006-10-02 Werner Koch * acinclude.m4 (GNUPG_SYS_SYMBOL_UNDERSCORE): Test on HOST and not TARGET. Hardwire for mingw32. Allow setting via command line when cross compiling. 2006-08-29 Werner Koch * configure.ac (USE_SEED): New. 2006-07-26 Werner Koch * configure.ac: New options --enable-noexecstack and --disable-optimization. 2006-07-04 Marcus Brinkmann * configure.ac: Call AC_LIBTOO_WIN32_DLL and AC_LIBTOOL_RC. * configure.ac: Call gl_TYPE_SOCKLEN_T instead of the other socklen_t checks. 2006-06-08 Marcus Brinkmann * configure.ac (PTH_LIBS): Add --all to pth-config invocation. 2006-03-14 Werner Koch * configure.ac: Check for fctnl and ftruncate. (HAVE_PTH): Check for GNU Pth. (HAVE_W32_SYSTEM): Define it. * acinclude.m4 (GNUPG_PTH_VERSION_CHECK): New. Taken from GnuPG 1.4. 2005-12-08 Werner Koch * configure.ac: Changed the random device names for netbsd. From Christian Biere. 2005-11-02 Moritz Schulte * NEWS: Documented minor API changes. 2005-09-15 Moritz Schulte * Makefile.am (EXTRA_DIST): Depend on README.SVN, not on README.CVS. 2005-06-25 Moritz Schulte * configure.ac: Removed src/libgcrypt.pc from AC_CONFIG_FILES. 2005-06-10 Werner Koch * configure.ac: Move detection of basic stuff to the top. For example we need to know whether gcc is used before testing for it. Reported by Ralf Fassel. 2005-04-23 Moritz Schulte * acinclude.m4 (TYPE_SOCKLEN_T): New type definition test; provided by Albert Chin. * configure.ac: Don't use $(CMD) as it's not portable; use CMD in backticks instead. Simpler -lnsl/-lsocket test. Use TYPE_SOCKLEN_T test. Don't forget to set `random_modules' correctly. 2005-04-22 Moritz Schulte * configure.ac: Added support for pkgconfig; provided by Albert Chin. 2005-04-11 Moritz Schulte * configure.ac: Integrate Whirlpool. 2005-01-04 Werner Koch Updated to automake 1.9. * acinclude.m4: Updated for use with automake 1.9. * configure.ac: Require libgpg-error 1.0; not really needed but that is the first stable version. * Makefile.am (ACLOCAL_AMFLAGS): New for -I m4. (AUTOMAKE_OPTIONS): New to create a bzip archive. 2005-02-03 Moritz Schulte * THANKS: Updated. 2004-08-09 Moritz Schulte * THANKS: Updated. 2004-07-04 Moritz Schulte * THANKS: Updated. 2004-04-21 Werner Koch * configure.ac: Don't print a warning if GNU make was not found. 2004-05-07 Moritz Schulte * THANKS: Updated. 2004-04-02 Thomas Schwinge * autogen.sh: Added ACLOCAL_FLAGS. 2004-04-15 Werner Koch Released 1.2.0. * configure.ac: Set LT to C12/A1/R1. 2004-04-06 Werner Koch * config.guess, config.sub, ltmain.sh: Updated to those from libtools 1.5.4. 2004-03-29 Werner Koch Released 1.1.94. * configure.ac: Set LT to C12/A1/R0. 2004-03-10 Marcus Brinkmann * configure.ac (LIBGCRYPT_CONFIG_LIBS_PTHREAD, LIBGCRYPT_CONFIG_CFLAGS_PTHREAD, LIBGCRYPT_CONFIG_LIBS_PTH, LIBGCRYPT_CONFIG_CFLAGS_PTH, have_pth, have_pthread, AC_CHECK_PTH, AC_CHECK_LIB(pthread), HAVE_PTH, HAVE_PTHREAD): Removed. 2004-03-06 Werner Koch Released 1.1.93. * configure.ac (LIBGCRYPT_CONFIG_SONAME_NUMBER): Replaced by LIBGCRYPT_CONPIG_API_VERSION. Set it to 1. Set LT to C11/A0/R1. 2004-03-05 Werner Koch * configure.ac (LIBGCRYPT_CONFIG_SONAME_NUMBER): New. 2004-02-20 Werner Koch Released 1.1.92. * configure.ac: Set LT to C11/A0/R0. 2004-02-11 Werner Koch * autogen.sh (check_version): Removed bashism and simplified. 2004-02-06 Werner Koch * configure.ac: Add rfc2268 cipher algorithm. 2004-01-25 Moritz Schulte * THANKS: Updated. 2003-12-19 Werner Koch Released 1.1.91. * configure.ac: Bumbed LT version to C10/A3/R1. 2003-12-08 Werner Koch * Makefile.am (dist-hook): Don't distribute stuff from the now obsolete scripts dir. (EXTRA_DIST): Remove README_alpha * README-alpha: Removed. * configure.ac (AM_CONFIG_AUX_DIR): Removed. * COPYING.DOC: Removed. * Makefile.am (EXTRA_DIST): Added README.CVS and autogen.sh. Removed COPYING.DOC. 2003-11-14 Werner Koch Released 1.1.90. * configure.ac: Bumbed LT version to C10/A3/R0. * configure.ac (have_ld_version_script): Set the default in a separate test. (PRINTABLE_OS_NAME): Don't handle the Hurd extra, this leads to conflicts with BSD based GNU systems. The Hurd has now a working uname. 2003-11-04 Werner Koch * configure.ac (USE_SHA1): Make sure it is always included. (USE_RMD160): Removed this AM conditional. 2003-10-31 Werner Koch * configure.ac: Bumbed version number to 1.1.90-cvs for futher development Released 1.1.44. * acinclude.m4 (AC_CHECK_PTH): Added. * configure.ac: Use it here instead of the generic lib test. Bumbed LT vesion to C9/A2/R0. 2003-10-27 Werner Koch * configure.ac: Give a hint on where libgpg-error is available. Reformatted long lines. Don't include gcrypt-defs.h. (--enable-gcc-warnings): New option. 2003-10-24 Moritz Schulte * configure.ac: Check for socklen_t. 2003-10-11 Moritz Schulte * acinclude.m4: Update AM_PATH_GPG_ERROR macro. 2003-09-04 Werner Koch Released 1.1.43. * configure.ac: Require libgpg-error 0.4 due to the prime interface. 2003-08-29 Werner Koch * acinclude.m4 (GNUPG_SYS_SYMBOL_UNDERSCORE): Re-implemented. * configure.ac: Use it here. 2003-08-27 Moritz Schulte * configure.ac: Substitute: LIBGCRYPT_CONFIG_LIBS_PTHREAD, LIBGCRYPT_CONFIG_CFLAGS_PTHREAD, LIBGCRYPT_CONFIG_LIBS_PTH, LIBGCRYPT_CONFIG_CFLAGS_PTH, LIBGCRYPT_THREAD_MODULES. 2003-08-07 Moritz Schulte * configure.ac: Fail, if libgpg-error could not be found. 2003-07-31 Werner Koch Released 1.1.42. * configure.ac: Set LT version to 7/0/0. 2003-07-30 Werner Koch * AUTHORS (Maintainer): Assigned Moritz as Maintainer. 2003-07-30 Moritz Schulte * NEWS: Include much more complete list of `Interface changes relative to the 1.1.12 release'. 2003-07-14 Moritz Schulte * configure.ac: Bumbed version number up to 1.1.42-cvs. 2003-07-09 Moritz Schulte * configure.ac: Reintroduce --disable-asm, since it is needed by mpi/config.links. 2003-07-05 Moritz Schulte * README: Few changes, mention libgpg-error. 2003-06-18 Moritz Schulte * configure.ac (available_ciphers): Removed Serpent, hrrm. 2003-06-17 Moritz Schulte * acinclude.m4: Removed macro definitions: GNUPG_CHECK_FAQPROG, GNUPG_CHECK_ENDIAN, GNUPG_CHECK_CACHE, GNUPG_CHECK_PIC, GNUPG_CHECK_EXPORTDYNAMIC, GNUPG_CHECK_IPC, GNUPG_PROG_NM, GNUPG_SYS_SYMBOL_UNDERSCORE, GNUPG_FUNC_MKDIR_TAKES_ONE_ARG, GPH_PROG_DB2ANY. Added macro definitions: AM_PATH_GPG_ERROR. * configure.ac: Use alternative approach for building based on conditional sources, which does not make automake eat all your memory, etc. Removed unused tests. Renamed --enable-static-rnd to --enable-random. Use Autoconf's AC_C_BIGENDIAN macro instead of our own. Re-organized the whole file. 2003-06-16 Moritz Schulte * configure.ac (AC_CONFIG_FILES): Removed doc/version.sgml. 2003-06-11 Moritz Schulte * configure.ac: Remove --enable-libgpg-error flag. Ue AC_PATH_GPG_ERROR. 2003-06-09 Moritz Schulte * NEWS: Mention API changes and libgpg-error. 2003-05-25 Moritz Schulte * configure.ac (USE_LIBGPG_ERROR): Implementation of the --enable-libgpg-error switch. Define USE_LIBGPG_ERROR in LIBGCRYPT_CONFIG_FLAGS, in case libgpg-error is used. 2003-05-22 Moritz Schulte * configure.ac (AC_CHECK_HEADERS): Removed unused headers: termio.h, langinfo.h. (AC_CHECK_FUNCS): Removed unused functions: strsep, strlwr, tcgetattr, setrlimit, strftime, nl_langinfo, sigaction, sigprocmask, fopen64, fstat64. 2003-04-27 Moritz Schulte * README: Documented new configure switches. Mention the --enable-maintainer-switch. * configure.ac: Merged some code from GnuPG's configure.ac for disabling sha512/tiger in case no 64 data types are available. 2003-04-17 Moritz Schulte * configure.ac: Include support for sha512. 2003-04-17 Moritz Schulte * AUTHORS: Updated. 2003-04-16 Moritz Schulte * configure.ac: Implement command line switches: --enable-ciphers, --enable-pubkey-ciphers and --enable-digests. Set Automake conditionals and config.h symbols depending on the selected ciphers, pubkey-ciphers, digests and random-modules. * acinclude.m4 (LIST_MEMBER): New macro. * configure.ac: Simplified, removed code for parsing EXTRA_PROGRAMS from Makefile.am. 2003-04-08 Moritz Schulte * configure.ac: Merged random-module selection code from GnuPG's configure.ac. 2003-04-07 Moritz Schulte * configure.ac: Removed code for generating contruct.c. Remove digest modules from the static_modules list, only handle random module selection. 2003-03-24 Moritz Schulte * NEWS: Mention new CBC_MAC flag. * AUTHORS (Maintainer): Update entry for Simon Josefsson. 2003-03-04 Moritz Schulte * TODO: Remove item about resetting handles, since gcry_cipher_reset is implemented by now. * NEWS: Mentioned gcry_cipher_reset. 2003-01-21 Werner Koch * README (Configure options): New. * configure.ac (have_ld_version_script): New option --enable-ld-version-script. 2003-01-20 Simon Josefsson * configure.ac (MODULES_IN_CIPHER): Add crc. 2003-01-20 Werner Koch Released 1.1.12. * configure.ac (LIBGCRYPT_LT_REVISION): Bumbed up. 2002-12-21 Werner Koch Released 1.1.11. * configure.ac (LIBGCRYPT_LT_CURRENT: Bumbed to 6/5/0 due to a new interface 2002-12-19 Werner Koch * configure.ac (have_pthread): Check for pthreads in libc. (have_ld_version_script): New. 2002-11-10 Werner Koch * configure.ac (MODULES_IN_CIPHER): Add md4.c. By Simon Josefsson. 2002-09-20 Werner Koch Released 1.1.10. * configure.ac (HAVE_DEV_RANDOM_IOCTL): Don't check for it; it is not used. (AS_CHECK_HEADERS): Check for sys/select.h. * Makefile.am (DIST_SUBDIRS): New to include the w32-dll directory 2002-09-18 Timo Schulz * configure.ac: Added makefile for the W32 DLL. 2002-09-17 Werner Koch * configure.ac: Check for Pth and Pthreads. 2002-08-23 Werner Koch Released 1.1.9. * configure.ac (LIBGCRYPT_CONFIG_CFLAGS): Renamed from LIBGCRYPT_CFLAGS and removed the libpath because it is set by the config script. (LIBGCRYPT_LT_REVISION): Set LT version to 5/4/1. 2002-06-25 Werner Koch Released 1.1.8. * configure.ac: Set LT version to 5/4/0. 2002-05-21 Werner Koch Released 1.1.7. * configure.ac: Set LT version to 4/3/0. 2002-05-17 Werner Koch * configure.ac: Removed all the dynamic loading stuff. 2002-05-16 Werner Koch * configure.ac: Reordered the C_CHECK_FUNCS. 2002-05-15 Werner Koch * configure.ac: Adjusted for new MPI module stuff. 2002-05-14 Werner Koch Changed license to the LGPL. 2002-05-02 Werner Koch * jnlib/: Removed. * Makefile.am (SUBDIRS): Removed jnlib. * configure.ac (jnlib/Makefile): Removed. * configure.ac: Define _REENTRANT. 2002-02-18 Werner Koch * configure.ac (MPI_EXTRA_ASM_OBJS): Use .lo suffix. (AC_CANONICAL_TARGET): Added. 2002-02-07 Werner Koch Released 1.1.6. 2002-01-24 Werner Koch * jnlib/: Replaced by a fresh copy from GnuPG (actually the NewPG development branch). Adjusted Makefile.am and jnlib-config.h accordingly. 2001-12-18 Werner Koch Released 1.1.5. * Makefile.am (dist-hook): Only look in mpi and scripts for distfiles; this way we don't include those of a stale "make dist" directory. * acinclude.m4 (GNUPG_FIX_HDR_VERSION): Make it work with the new automake. * configure.ac: Don't chmod db2any. 2001-08-06 Werner Koch * configure.ac: Removed cross compiling hacks. 2001-08-03 Werner Koch Released 1.1.4. * acinclude.m4 (GNUPG_CHECK_TYPEDEF): Define GNU Source. Migrated to autoconf 2.52. * acinclude.m4: Removed GNUPG_LINK_FILES and converted. * acconfig.h: Removed * configure.in: Replaced by... * configure.ac: and modified for use with autoconf 2.52. Replaced GNUPG_LINK_FILES with AC_CONFIG_LINKS and moved some informational messages to the end. Removed --enable-m-debug * tests/: New. * Makefile.am: Included tests directory * configure.in (DYNLINK_MOD_CFLAGS): Use -shared with dec-osf. Reported by Chris Adams. Merged some cases. 2001-05-31 Werner Koch Released 1.1.3. * configure.in: Use _gcry_ prefix when creating the cipher constructor. * acconfig.h (_GCRYPT_IN_LIBGCRYPT): Define it here. 2001-05-28 Werner Koch * acinclude.m4 (GPH_PROG_DOCBOOK): Removed. (GPH_PROG_DB2ANY): New. Taken from GPH. * configure.in: Use it here. 2000-12-19 Werner Koch Major change: Removed all GnuPG stuff and renamed this piece of software to gcrypt. The directory gcrypt has been renamed to src. 2000-11-14 Werner Koch Version 1.1.2 released. 2000-11-13 Werner Koch * acinclude.m4 (GNUPG_FIX_HDR_VERSION): VPATH build fix. 2000-10-10 Werner Koch * Makefile.am (dist-hook): Create the version file. * configure.in: Set the libtool version here, removed the need for the version file. Mon Sep 18 16:35:45 CEST 2000 Werner Koch * acinclude.m4 (GNUPG_CHECK_MLOCK): Removed that silly mkdir(). * configure.in: Changes to allow for Solaris random device. By Nils Ellmenreich. (--with-egd-socket): New. * configure.in (GNUPG_HOMEDIR): New. * configure.in: Check for fstat64 and fopen64 * acinclude.m4 (GNUPG_CHECK_FAQPROG): New. * configure.in: Test for this. * configure.in (DYNLINK_MOD_CFLAGS): Fix by David Champion. Tue Aug 22 14:31:15 CEST 2000 Werner Koch Version 1.1.1 Fri Aug 18 14:27:14 CEST 2000 Werner Koch * agent/: New. * Makefile.am, configure.in: Support for the new directory. Mon Jul 17 16:35:47 CEST 2000 Werner Koch * configure.in (mingw32): Changes to allow for mingw32msvc Fri Jul 14 19:38:23 CEST 2000 Werner Koch The big merge between this one and the stable branch 1.0. Still need to merge TNANKS, AUTHORS and such. It probaly does not compile yet. * acinclude.m4 (GNUPG_CHECK_MLOCK): Fixed syntax error in C code. * configure.in: Add check for termio.h, wait unctiosn and sigaction. * acinclude.m4, configure.in (GNUPG_CHECK_GNUMAKE): New. * acinclude.m4 (MKDIR_TAKES_ONE_ARG): Check some headers. By Gaël Quéri. * configure.in (AM_INIT_AUTOMAKE): Use this now. By Gaël. * acinclude.m4 (GNUPG_CHECK_EXPORTDYNAMIC): Replacement for GNUPG_CHECK_RDYNAMIC which should handle gcc with non GNU ld nicer. Contributed by Dave Dykstra. * configure.in (GNYPG_CHECK_RDYNAMIC): Replaced by the new check. * configure.in: Add a test for unisgned long long. * configure.in (DYNLINK_MOD_CFLAGS): Set different for NetBSD. * configure.in: Add check for clock_gettime * configure.in (ALL_LINGUAS): Add nl. * configure.in (ALL_LINGUAS): Add Esperanto. * configure.in (ALL_LINGUAS): Add sv and ja. * configure.in: Use /usr/local for CFLAGS and LDFLAGS when target is freebsd. By Rémi. * configure.in: Do not set development version when the version has a dash in it. Suggested by Dave Dykstra. * configure.in: Removed substitution for doc/gph/Makefile. Do all the gcc warning only in maintainer mode. * configure.in (dlopen): Use CHECK_FUNC for a test of dlopen in libc. Suggested by Alexandre Oliva. (-Wall): Moved the settting of gcc warning options near to the end so that tests don't get confused. Suggested by Paul D. Smith. * acinclude.m4 (GNUPG_SYS_NM_PARSE): Added BSDI support. (GNUPG_CHECK_RDYNAMIC): Ditto. * acinclude.m4 (GNUPG_CHECK_MLOCK): Changed the way to test for librt. Test suggested by Jeff Long. * acinclude.m4 (GNUPG_CHECK_MLOCK): Do librt check only when we can't link a test program. This way GNU systems don't need to link against linrt. (GNUPG_CHECK_IPC): Fixed use of TRY_COMPILE macro. From Tim Mooney. * acinclude.m4 (GNUPG_SYS_SYMBOL_UNDERSCORE): Add support for DJGPP. (GNUPG_CHECK_MLOCK): Check whether mlock sits in librt. * acinclude.m4 (GNUPG_CHECK_RDYNAMIC): Add NetBSD. By Thomas Klausner. * acconfig.h (HAVE_MLOCK): Added Mon Mar 13 19:22:46 CET 2000 Werner Koch * configure.in: Now uses the Docbook M4s from GPH. Mon Jan 31 17:46:35 CET 2000 Werner Koch * Makefile.am: Re-added tools. By Rémi. Mon Jan 31 16:37:34 CET 2000 Werner Koch * configure.in: Create a symlink for types.h in gcrypt/. Thu Jan 27 18:00:44 CET 2000 Werner Koch * configure.in (g10defs.h): Replaced by gnupg-defs.h Mon Jan 24 13:04:28 CET 2000 Werner Koch * jnlib/ : New. * configure.in: Do set development version when the version has a dash in it. Suggested by Dave Dykstra. Thu Dec 9 17:22:27 CET 1999 Werner Koch * acinclude.m4 (GNUPG_FIX_HDR_VERSION): New. * configure.in: Check and fix the version number of gcrypt/gcrypt.h so that it is always the save as VERSION. Thu Oct 28 16:17:46 CEST 1999 Werner Koch * Started with development series 1.1 on 1999-10-26 Tue Oct 26 14:10:21 CEST 1999 Werner Koch * README-alpha: New * configure.in: Fixed quoting in test for development version. * THANKS: Add entries for Michael, Brenno and J Horacio who did very nice Howto documents - I apoligize for forgetting to mention them earlier. Fri Sep 17 12:56:42 CEST 1999 Werner Koch * configure.in: Add "-lcap" when capabilities are requested. Add the conditional CROSS_COMPILING. * Makefile.am: Don't use checks when CROSS_COMPILING. Wed Sep 15 16:22:17 CEST 1999 Werner Koch * configure.in (ALL_LINGUAS): Add pt_PT. * configure.in: Some tweaks for cross compiling under MingW32 * acconfig.h (USE_STATIC_RNDW32): New. Tue Sep 7 17:08:10 CEST 1999 Werner Koch * VERSION: Set to 1.0.0. Mon Sep 6 19:59:08 CEST 1999 Werner Koch * configure.in: Create makefile in doc/gph * acinclude.m4 (GNUPG_FUNC_MKDIR_TAKES_ONE_ARG): New * configure.in: use the above. Thu Sep 2 16:40:55 CEST 1999 Werner Koch * VERSION: Set to 0.9.11. Tue Aug 31 17:20:44 CEST 1999 Werner Koch * configure.in: Minor changes to the OS/2 and Mingw32 system labels. Add a printable name for Hurd. Mon Aug 30 20:38:33 CEST 1999 Werner Koch * configure.in: Some support for DJGPP (Mark Elbrecht) Wed Aug 4 10:34:46 CEST 1999 Werner Koch * VERSION: Set to 0.9.10. Mon Jul 26 09:34:46 CEST 1999 Werner Koch * acinclude.m4 (GNUPG_SYS_SYMBOL_UNDERSCORE): remove init of ac_cv_... * Makefile.am (DISCLEANFILES): New Fri Jul 23 13:53:03 CEST 1999 Werner Koch * VERSION: Set to 0.9.9. * configure.in: Print a notice when rndunix is used. Thu Jul 15 10:15:35 CEST 1999 Werner Koch * acinclude.m4 (GNUPG_SYS_SYMBOL_UNDERSCORE): Fixed last modification. Wed Jul 7 13:08:40 CEST 1999 Werner Koch * Makefile.am: Support for libtool. * configure.in: Ditto. Tue Jun 29 21:44:25 CEST 1999 Werner Koch * configure.in (use_local_zlib): The lost dollar is back. * acinclude.m4 (GNUPG_SYS_SYMBOL_UNDERSCORE): Add EMX case. * configure.in: Another variant of the MX vendor string * configure.in (--with-capabilities): Some test code (Remi). Sat Jun 26 12:15:59 CEST 1999 Werner Koch * acinclude.m4 (GNUPG_CHECK_RDYNAMIC): Support for HPUX and IRIX. * configure.in (HAVE_DL_SHL_LOAD): New for HPUX (Dave Dykstra). * VERSION: Now 0.9.8 Wed Jun 16 20:16:21 CEST 1999 Werner Koch * configure.in: Add test for docbook-to-man Tue Jun 15 12:21:08 CEST 1999 Werner Koch * acinclude.m4 (GNUPG_SYS_NM_PARSE): Support for {net,free}bsd, Thu Jun 10 14:18:23 CEST 1999 Werner Koch * configure.in (ZLIB,GDBM): Check both, header and lib. Sat Jun 5 15:30:33 CEST 1999 Werner Koch * pkclist.c (key_present_in_pk_list): New (Michael). Tue May 25 19:50:32 CEST 1999 Werner Koch * configure.in (IS_DEVELOPMENT_VERSION): Fixed detection. Sun May 23 14:20:22 CEST 1999 Werner Koch * acinclude.m4 (GNUPG_SYS_SYMBOL_UNDERSCORE): assume yes when cross-compiling. Mon May 17 21:54:43 CEST 1999 Werner Koch * configure.in (socket): Fix for Unisys by Katsuhiro Kondou. Sat May 8 19:28:08 CEST 1999 Werner Koch * NEWS: Add a marker line which I forgot to do for 0.9.6. Thu May 6 14:18:17 CEST 1999 Werner Koch * README: Minor updates * VERSION: Now 0.9.6 Thu Apr 8 09:35:53 CEST 1999 Werner Koch * acinclude.m4 (GNUPG_CHECK_RDYNAMIC): Fix for amiga-openbsd (Peter Reich) (GNUPG_PROG_NM): Ditto Wed Apr 7 20:51:39 CEST 1999 Werner Koch * Makefile.am (g10defs.h): Removed. * configure.in (AC_OUTPUT_COMMANDS): Create g10defs.h Sat Mar 20 12:55:33 CET 1999 Werner Koch * VERSION: Now 0.9.5 Sun Mar 14 19:34:36 CET 1999 Werner Koch * acinclude.m4 (AM_SYS_SYMBOL_UNDERSCORE): Removed because it is now in the latest libtool. Thu Mar 11 16:39:46 CET 1999 Werner Koch * configure.in: Removed the need for libtool Mon Mar 8 20:47:17 CET 1999 Werner Koch * configure.in (DLSYM_NEEDS_UNDERSCORE): Replaced. * acinclude.in (AM_SYS_SYMBOL_UNDERSCORE): New. * VERSION: Now 0.9.4 Sun Feb 28 19:11:00 CET 1999 Werner Koch * configure.in (dld): Test disabled. Fri Feb 26 17:55:41 CET 1999 Werner Koch * encode.c (encode_simple): temporary fix. Wed Feb 24 11:07:27 CET 1999 Werner Koch * configure.in: New option --enable-static-rnd. Mon Feb 22 20:04:00 CET 1999 Werner Koch * BUGS: Now we assign bug numbers. * OBUGS: New to keep rack o fixed bugs (CVS only) Fri Feb 19 18:01:54 CET 1999 Werner Koch * VERSION: Released 0.9.3 Fri Feb 19 15:49:15 CET 1999 Werner Koch * acinclude.m4: Removed gettext macros. Tue Feb 16 14:10:02 CET 1999 Werner Koch * configure.in (socket): Check for -lsocket and -lnsl. (osf4): Disable all warnings for DEC's cc. (-Wall): Add more warning options for gcc Sat Feb 13 12:04:43 CET 1999 Werner Koch * configure.in: Changed detection of compiler flags. * intl/ : Removed directory Wed Feb 10 17:15:39 CET 1999 Werner Koch * acinclude.m4 (GNUPG_CHECK_RDYNAMIC): Fix for freebsd 2.2 * configure.in: a lot of changes to allow selection of modules. Add support for OS/2. * acinclude.m4: add some more caching * README: Spelling and grammar corrections (John A. Martin) * INSTALL: Ditto. Wed Jan 20 21:40:21 CET 1999 Werner Koch * configure.in: --enable-m-guard is now default Wed Jan 13 12:49:36 CET 1999 Werner Koch * INSTALL: Applied new information how to build rpms by Fabio Coatti * Makefile.in (gnupg.spec): Changed the names. Tue Jan 12 11:17:18 CET 1999 Werner Koch * config.links (m68k-atari-mint): New Tue Jan 12 09:17:19 CET 1999 Gaël Quéri * all: Fixed typos all over the place Sat Jan 9 16:02:23 CET 1999 Werner Koch * configure.in: Add a way to statically link rndunix Sun Jan 3 15:28:44 CET 1999 Werner Koch * acinclude.m4 (GNUPG_CHECK_RDYNAMIC): New. * configure.in (DYNLOAD_CFLAGS): Use result from CHECK_RDYNAMIC Wed Dec 23 13:18:14 CET 1998 Werner Koch * README: Replaced the command overview with a short intro. Sat Dec 12 18:40:32 CET 1998 Werner Koch * configure.in: Add check for dlopen in libc (Greg Troxel) and a new define * acconfig.h (DLSYM_NEEDS_UNDERSCORE): New. Thu Dec 10 20:15:36 CET 1998 Werner Koch * acinclude.m (GNUPG_CHECK_PIC): New * configure.in, acinclude.m4: Renamed all WK_ to GNUPG_ Tue Dec 8 15:09:29 CET 1998 Werner Koch * VERSION: Set to 0.4.5 Wed Nov 25 12:38:29 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (USE_RNDLINUX): New. Fri Nov 20 19:34:57 1998 Werner Koch (wk@isil.d.shuttle.de) * VERSION: Released 0.4.4 * configure.in (try_asm_modules): For option --disable-asm Tue Nov 10 19:32:40 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (MPI_SFLAGS): New. Tue Nov 10 13:44:53 1998 Werner Koch (wk@isil.d.shuttle.de) * ABOUT-NLS: New * configure.in (AC_REVISION): New. Sun Nov 8 18:20:35 1998 Werner Koch (wk@isil.d.shuttle.de) * VERSION: Set to 0.4.3 Sun Oct 25 19:49:37 1998 Werner Koch (wk@isil.d.shuttle.de) * Makefile.am (g10defs.h): New macro GNUPG_DATADIR. Wed Oct 21 17:24:24 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in: Removed gettext kludge * acinclude.m4: Add patched AM_WITH_NKS macro Tue Oct 20 19:03:36 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in: Kludge to make AM_GNU_GETTEXT work, changed some macors to more modern versions. Also changeg the all makefiles to remove duplicate ../intl. * acinclude.m4: Removed the gettext stuff, as this already comes with automake now. Wed Oct 14 12:11:34 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (NAME_OF_DEV_RANDOM): New. (DYNLINK_MOD_CFLAGS): New. Thu Oct 8 10:55:15 1998 Werner Koch (wk@isil.d.shuttle.de) * Makefile.am (g10defs.h): creates include file * acconfig.h: now includes g10defs.h * configure.in: Removed G10_LOCALEDIR and GNUPG_LIB Thu Sep 17 18:49:40 1998 Werner Koch (wk@(none)) * Makefile.am (dist-hook): Now creates RPM file. * scripts/gnupg.spec: New template file for RPMs Thu Jul 30 19:17:07 1998 Werner Koch (wk@(none)) * acinclude.h (WK_CHECK_IPC): New * configure.in : Add checks for SysV IPC Thu Jun 25 11:18:49 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (--disable-dynload): New. Wed Jun 10 07:48:59 1998 Werner Koch,mobil,,, (wk@tobold) * configure.in (GNUPG_LIBDIR): New. Mon May 25 19:10:59 1998 Werner Koch (wk@isil.d.shuttle.de) * rand-unix.c (fast_random_poll): fixed syntax bug. Mon May 11 10:21:31 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (PRINTABLE_OS_NAME): Linux is now GNU/Linux Tue Apr 14 19:08:05 1998 Werner Koch (wk@isil.d.shuttle.de) * [all files]: Applied Matthew Skala's typo and grammar fixes. Wed Mar 4 10:32:40 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (getrusage,gettimeofday): New tests. Fri Feb 27 13:14:17 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (--disable-m-guard): New. Thu Feb 26 17:09:27 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in, acinclude.m4, intl/, po/: New macros taken from GNOME, switched to automake 1.2f Thu Feb 26 09:05:46 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (doc/Makefile): New Thu Feb 26 07:40:47 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in: Changed gettext stuff Wed Feb 25 11:44:10 1998 Werner Koch (wk@isil.d.shuttle.de) * checks/*test : restructured the directory. Tue Feb 24 15:59:12 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in: Changed the name of the package to GNUPG and chnaged several other names too. Wed Feb 18 17:36:45 1998 Werner Koch (wk@isil.d.shuttle.de) * Makefile.am (checks): New. Sat Feb 14 15:37:55 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (mpi_config_done): Removed asm links caching. Sat Feb 14 14:02:20 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in (PRINTABLE_OS_NAME): New. * acconfig.h: Likewise. Fri Feb 13 19:43:41 1998 Werner Koch (wk@isil.d.shuttle.de) * configure.in : Fixed zlib stuff * Makefile.am: Likewise Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without modifications, as long as this notice is preserved. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/Makefile.am b/Makefile.am index c0e0042a..f706593c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,51 +1,51 @@ ## Process this file with automake to produce Makefile.in # Copyright (C) 1992, 1999, 2000, 2002 Free Software Foundation, Inc. # # This file is part of Libgcrypt. # # Libgcrypt is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # # Libgcrypt is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA ACLOCAL_AMFLAGS = -I m4 AUTOMAKE_OPTIONS = dist-bzip2 -DIST_SUBDIRS = m4 mpi cipher src doc tests w32-dll +DIST_SUBDIRS = m4 mpi cipher src doc tests SUBDIRS = mpi cipher src doc tests EXTRA_DIST = BUGS autogen.sh README.apichanges README.SVN DISTCLEANFILES = # Add all the files listed in "distfiles" files to the distribution, # apply version number s to some files and create a VERSION file which # we need for the Prereq: patch file trick. dist-hook: @set -e; \ for file in `cd $(top_srcdir); \ find mpi -type f -name distfiles`; do \ dir=`dirname $$file` ; $(mkinstalldirs) $(distdir)/$$dir ; \ for i in distfiles `cat $(top_srcdir)/$$file` ; do \ ln $(top_srcdir)/$$dir/$$i $(distdir)/$$dir/$$i 2> /dev/null \ || cp -p $(top_srcdir)/$$dir/$$i $(distdir)/$$dir/$$i; \ done ; \ done @set -e; \ echo "$(VERSION)" > $(distdir)/VERSION stowinstall: $(MAKE) $(AM_MAKEFLAGS) install prefix=/usr/local/stow/libgcrypt diff --git a/NEWS b/NEWS index 5bf4aa5e..4e4a6418 100644 --- a/NEWS +++ b/NEWS @@ -1,445 +1,460 @@ Noteworthy changes in version 1.3.0 (unreleased) ------------------------------------------------ * Changed the way the RNG gets initialized. This allows to keep it uninitialized as long as no random numbers are used. To override this, the new macro gcry_fast_random_poll may be used. It is in general a good idea to spread this macro into the application code to make sure that these polls happen often enough. + * Made the RNG immune against fork without exec. + * Reading and writing the random seed file is now protected by a fcntl style file lock on systems that provide this function. * Support for SHA-224 and HMAC using SHA-384 and SHA-512. * Support for the SEED cipher. * Support for OFB encryption mode. * gcry_mpi_rshift does not anymore truncate the shift count. * Reserved algorithm ranges for use by applications. * Support for DSA2. * The new function gcry_md_debug should be used instead of the gcry_md_start_debug and gcry_md_stop_debug macros. + * New configure option --enable-random-daemon to support a system + wide random daemon. The daemon code is experimental and not yet + very well working. It will eventually allow to keep a global + random pool for the sake of short living processes. + + * Non executable stack support is now used by default on systems + supporting it. + + * Support for Microsoft Windows OSes. + + * Minor changes to some function declarations. Buffer arguments are + now typed as void pointer. This should not affect any compilation. + Fixed two bugs in return values and clarified documentation. + * Interface changes relative to the 1.2.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcry_fast_random_poll NEW + gcry_md_debug NEW GCRYCTL_FAKED_RANDOM_P NEW - gcry_pk_algo_name CHANGED (minor change in respect to return value) - gcry_cipher_algo_name CHANGED (minor change in respect to return value) GCRY_MD_SHA224 NEW GCRY_PK_USAGE_CERT NEW GCRY_PK_USAGE_AUTH NEW GCRY_PK_USAGE_UNKN NEW - gcry_mpi_scan CHANGED: Argument BUFFER is now void*. GCR_CIPHER_SEED NEW - gcry_pk_spec_t CHANGED (minor change, bug fix) - gcry_md_write_t CHANGED (minor change, bug fix) - gcry_md_debug NEW - gcry_cipher_encrypt CHANGED (minor change) - gcry_cipher_decrypt CHANGED (minor change) - gcry_randomize CHANGED (minor change) - gcry_cipher_register CHANGED (minor change) - - FIXME: Please add API changes immediatley so that we don't - forget about them. - + gcry_mpi_scan CHANGED: Argument BUFFER is now void*. + gcry_pk_algo_name CHANGED: Returns "?" instead of NULL. + gcry_cipher_algo_name CHANGED: Returns "?" instead of "". + gcry_pk_spec_t CHANGED: Element ALIASES is now const ptr. + gcry_md_write_t CHANGED: Argument BUF is now a const void*. + gcry_md_ctl CHANGED: Argument BUFFER is now void*. + gcry_cipher_encrypt CHANGED: Arguments IN and OUT are now void*. + gcry_cipher_decrypt CHANGED: Arguments IN and OUT are now void*. + gcry_sexp_sprint CHANGED: Argument BUFFER is now void*. + gcry_create_nonce CHANGED: Argument BUFFER is now void*. + gcry_randomize CHANGED: Argument BUFFER is now void*. + gcry_cipher_register CHANGED: Argument ALGORITHM_ID is now int*. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 1.2.0 (2004-04-15) ------------------------------------------------ * First stable release. Noteworthy changes in version 1.1.94 (2004-03-29) ------------------------------------------------- * The support for multi-threaded users goes into its third incarnation. We removed compile time support for thread libraries. To support the thread library of your choice, you have to set up callback handlers at initialization time. New data structures, a new control command, and default initializers are provided for this purpose. * Interface changes relative to the 1.1.93 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libgcrypt-config --thread OBSOLETE libgcrypt-pth.la REMOVED libgcrypt-pthread.la REMOVED GCRYCTL_SET_THREAD_CBS NEW struct gcrypt_thread_cbs NEW enum gcry_thread_option NEW GCRY_THREAD_OPTION_PTH_IMPL NEW GCRY_THREAD_OPTION_PTHREAD_IMPL NEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 1.1.93 (2004-03-06) ------------------------------------------------- * The automatic thread library detection has finally been removed. From now on, only linking explicitely to libgcrypt, libgcrypt-pth or libgcrypt-pthread is supported. Noteworthy changes in version 1.1.92 (2004-02-20) ------------------------------------------------- * Minor bug fixes. * Included a limited implementation of RFC2268. * Changed API of the gcry_ac_ functions. Only a very few programs should be affected by this. * Interface changes relative to the 1.1.91 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCRY_CIPHER_RFC2268_40 NEW. gcry_ac_data_set CHANGED: New argument FLAGS. gcry_ac_data_get_name CHANGED: New argument FLAGS. gcry_ac_data_get_index CHANGED: New argument FLAGS. gcry_ac_key_pair_generate CHANGED: New and reordered arguments. gcry_ac_key_test CHANGED: New argument HANDLE. gcry_ac_key_get_nbits CHANGED: New argument HANDLE. gcry_ac_key_get_grip CHANGED: New argument HANDLE. gcry_ac_data_search REMOVED. gcry_ac_data_add REMOVED. GCRY_AC_DATA_FLAG_NO_BLINDING REMOVED. GCRY_AC_FLAG_NO_BLINDING NEW: Replaces above. Noteworthy changes in version 1.1.91 (2003-12-19) ------------------------------------------------- * Code cleanups and minor bug fixes. Noteworthy changes in version 1.1.90 (2003-11-14) ------------------------------------------------- * The use of the GCRY_WEAK_RANDOM level is now deprecated in favor of the new gcry_create_nonce function. * gcry_sexp_build now supports a "%b" format to include a memory buffer. * Minor configuration fixes. * Interface changes relative to the 1.1.44 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcry_create_nonce NEW gcry_sexp_build ENHANCED Noteworthy changes in version 1.1.44 (2003-10-31) ------------------------------------------------- * Bug fixes and more code cleanups. * Enhanced the prime API. * Interface changes relative to the 1.1.43 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcry_prime_group_generator NEW gcry_prime_release_factors NEW Noteworthy changes in version 1.1.43 (2003-09-04) ------------------------------------------------- * Bug fixes and internal code cleanups. * Support for the Serpent cipher algorithm. * Interface changes relative to the 1.1.42 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcry_prime_generate NEW gcry_prime_check NEW Noteworthy changes in version 1.1.42 (2003-07-31) ------------------------------------------------- * Major API cleanup. Applications need to be converted to the new API. See README.apichanges for hints on how to do that. Backward compatibility is provided where it was possible without too much effort and did not collide with the overall sanitization effort. However, this is only for ease of transition. NO DEPRECATED FUNCTION OR DATA TYPE IS CONSIDERED A PART OF THE API OR ABI AND WILL BE DROPPED IN THE FUTURE WITHOUT CHANGING THE SONAME OF THE LIBRARY. * If gcrypt.h is included in sources compiled by GCC 3.1 or later, deprecated attributes will warn about use of obsolete functions and type definitions. You can suppress these warnings by passing -Wno-deprecated-declarations to the gcc command. * gcry_check_version must be called from now on to initialize the library, it is not longer optional. * Removed `libgcrypt errno' concept. * Libgcrypt depends on libgpg-error, a library that provides error codes and according functions for all GnuPG components. Functions that used to return error codes asa `int' have been changed to return a code of type `gcry_error_t'. All GCRYERR_* error symbols have been removed, since they are now contained in libgpg-error (GPG_ERR_*). All functions and types in libgpg-error have also been wrapped in Libgcrypt. The new types are gcry_err_code_t and gcry_err_source_t. The new functions are gcry_err_code, gcry_err_source, gcry_error, gcry_err_make, gcry_error_from_errno, gcry_err_make_from_errno, gcry_err_code_from_errno, gcry_err_code_to_errno, gcry_strsource. * New function gcry_mpi_dump to help in debugging. * Added alternative interface for asymmetric cryptography. * CRC-32, CRC-32 a'la RFC 1510, CRC-24 a'la RFC 2440 are now supported. * SHA-256, SHA-384 and SHA-512 are now supported. * 128 bit Twofish is now supported. * The random module won't print the "not enough random bytes available" anymore. A new progress status is issued instead. * CBC-MAC for block ciphers is now supported, by using a GCRY_CIPHER_CBC_MAC cipher flag. * CTR mode for block ciphers is now supported. * The public RSA exponent can now be specified in key generation. * RSA blinding is now supported and is used automatically for RSA decryption. It can be explicitely disabled by using the `no-blinding' symbol in the `flags' S-Expression or by using the GCRY_AC_FLAG_DATA_NO_BLINDING flag when using the ac interface. * gcry_sexp_canon_len does not use a `historically encoded' error code anymore. * Interface changes relative to the 1.1.12 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCRY_MPI DEPRECATED; Use: gcry_mpi_t GcryMPI DEPRECATED; Use: gcry_mpi_t GCRY_SEXP DEPRECATED; Use: gcry_sexp_t GcrySexp DEPRECATED; Use: gcry_sexp_t GCRY_CIPHER_HD DEPRECATED; Use: gcry_cipher_hd_t GcryCipherHd DEPRECATED; Use: gcry_cipher_hd_t GCRY_MD_HD DEPRECATED; Use: gcry_md_hd_t GcryMDHd DEPRECATED; Use: gcry_md_hd_t gcry_error_t NEW gcry_err_code_t NEW gcry_err_source_t NEW gcry_err_make NEW gcry_error NEW gcry_err_code NEW gcry_err_source NEW gcry_err_code_from_errno NEW gcry_err_code_to_errno NEW gcry_err_make_from_errno NEW gcry_error_from_errno NEW gcry_strsource NEW GCRYERR_{some error code} REMOVED; Use GPG_ERR_* from libgpg-error instead. gcry_errno REMOVED gcry_sexp_canon_len CHANGED gcry_sexp_build_array NEW gcry_mpi_scan CHANGED: New argument to separate in/out args. gcry_mpi_print CHANGED: Ditto. gcry_mpi_dump NEW gcry_cipher_open CHANGED gcry_cipher_reset NEW gcry_cipher_register NEW gcry_cipher_unregister NEW gcry_cipher_list NEW gcry_cipher_algo_keylen REPLACED macro with function. gcry_cipher_algo_blklen REPLACED macro with function. gcry_pk_register NEW gcry_pk_unregister NEW gcry_pk_list NEW gcry_pk_decrypt ENHANCED: Allows flag to return complete S-expression. gcry_md_open CHANGED gcry_md_copy CHANGED gcry_md_is_enabled NEW gcry_md_is_secure NEW gcry_md_register NEW gcry_md_unregister NEW gcry_md_list NEW gcry_ac_data_t NEW gcry_ac_key_t NEW gcry_ac_key_pair_t NEW gcry_ac_handle_t NEW gcry_ac_key_spec_rsa_t NEW gcry_ac_data_new NEW gcry_ac_data_destroy NEW gcry_ac_data_set NEW gcry_ac_data_copy NEW gcry_ac_data_length NEW gcry_ac_data_get_name NEW gcry_ac_data_get_index NEW gcry_ac_data_clear NEW gcry_ac_open NEW gcry_ac_close NEW gcry_ac_key_init NEW gcry_ac_key_pair_generate NEW gcry_ac_key_pair_extract NEW gcry_ac_key_data_get NEW gcry_ac_key_test NEW gcry_ac_key_get_nbits NEW gcry_ac_key_get_grip NEW gcry_ac_key_destroy NEW gcry_ac_key_pair_destroy NEW gcry_ac_data_encrypt NEW gcry_ac_data_decrypt NEW gcry_ac_data_sign NEW gcry_ac_data_verify NEW gcry_ac_id_to_name NEW gcry_ac_name_to_id NEW gcry_handler_progress_t NEW gcry_handler_alloc_t NEW gcry_handler_secure_check_t NEW gcry_handle_realloc_t NEW gcry_handler_free_t NEW gcry_handler_no_mem_t NEW gcry_handler_error_t NEW gcry_handler_log_t NEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 1.1.12 (2003-01-20) ------------------------------------------------- * gcry_pk_sign, gcry_pk_verify and gcry_pk_encrypt can now handle an optional pkcs1 flags parameter in the S-expression. A similar flag may be passed to gcry_pk_decrypt but it is only syntactically implemented. * New convenience macro gcry_md_get_asnoid. * There is now some real stuff in the manual. Noteworthy changes in version 1.1.11 (2002-12-21) ------------------------------------------------- * Don't export internal symbols anymore (currently only for GNU systems) * New algorithm: MD4 * Implemented ciphertext stealing. * Smaller bugs fixes and a few new OIDs. * Interface changes relative to the 1.1.8 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcry_cipher_cts NEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 1.1.10 (2002-09-20) ------------------------------------------------- * Fixed shared library builds for i386, PPC and Sparc. * Added simple benchmark tool. * Replaced the internal mutexes by code which automatically adapts to the used threading library. Currently Pth and Pthread are supported. For non-ELF systems the GNU toolchain is now required.. * Added untested support to build Windows DLLs. Noteworthy changes in version 1.1.9 (2002-08-23) ------------------------------------------------ * Support for plain old DES. Noteworthy changes in version 1.1.8 (2002-06-25) ------------------------------------------------ * Minor cleanups and exported a few new functions. * Interface changes relative to the 1.1.7 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcry_mpi_div NEW gcry_mpi_mod NEW gcry_mpi_invm NEW gcry_mpi_swap NEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 1.1.7 (2002-05-21) ------------------------------------------------ * Libgcrypt is now distributed under the terms of the GNU Lesser General Public License; see the README file for details. * It is possible to use libgcrypt w/o intialized secure memory. * Libgcrypt should now be thread safe after the initialization. gcry_control (GCRYCRL_INITIALIZATION_FINISHED,NULL,0) should have been called before creating additional threads. * Interface changes relative to the 1.1.6 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCRYCTL_DISABLE_INTERNAL_LOCKING NEW GCRYCTL_DISABLE_SECMEM NEW GCRYCTL_INITIALIZATION_FINISHED NEW GCRYCTL_INITIALIZATION_FINISHED_P NEW GCRYCTL_ANY_INITIALIZATION_P NEW gcry_strdup NEW gcry_sexp_create NEW gcry_sexp_new NEW gcry_set_progress_handler NEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 1.1.6 (2002-02-07) ------------------------------------------------ * Enhanced the S-expression conversion functions. Noteworthy changes in version 1.1.5 (2001-12-18) ------------------------------------------------ * gcry_{cipher,md}_map_name are now able to map stringified object IDs. * New functions gcry_sexp_canon_len and gcry_cipher_mode_from_oid. * Closed some memory leaks. Noteworthy changes in version 1.1.4 (2001-08-03) ------------------------------------------------ * Arcfour does now work. * Some minor fixes. * Added a first test program * Migrated to autoconf 2.52. Noteworthy changes in version 1.1.3 (2001-05-31) ------------------------------------------------ * First release of Libgcrypt which is a result of splitting GnuPG into into libgcrypt and GnuPG. Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without modifications, as long as this notice is preserved. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/README b/README index ff03f8d1..a3973fd1 100644 --- a/README +++ b/README @@ -1,127 +1,132 @@ libgcrypt - The GNU crypto library ------------------------------------ Version 1.3.x WARNING: This is the development branch of Libgcrypt. The stable version is 1.2.x. Copyright 2000, 2002, 2003, 2004, 2007 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without modifications, as long as this notice is preserved. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Overview -------- Libgcrypt is a general purpose crypto library based on the code used in GnuPG. We can't start with a new version number because libgcrypt was part of gnupg 1.1 and some applications already used it and tested for the version number. We believe that the API can stay as it is, except that new functions may be added in the future. Libgcrypt depends on the library `libgpg-error', which must be installed correctly before Libgcrypt is to be built. Mailing List ------------ You may want to join the developer's mailing list gcrypt-devel@gnupg.org by sending mail with a subject of "subscribe" to gcrypt-devel-request@gnupg.org. An archive of this list is available at http://lists.gnupg.org . License ------- Most of this library is distributed under the terms of the GNU Lesser General Public License (LGPL); see the file COPYING.LIB for the actual terms. However some parts are distributed under the GNU General Public License (GPL) so if you configure Libgcrypt to include these modules, you have to comply with the conditions of the GPL as found in the file COPYING. The modules under the GPL are: rndunix - Entropy gatherer for Unices without a /dev/random rndw32 - Entropy gatherer for MS Windows gcryptrnd - The random number daemon. getrandom - A client for that daemon. The documentation is available under the terms of the GPL. This library used to be available under the GPL - this was changed with version 1.1.7 with the rationale that there are now many free crypto libraries available and many of them come with capabilities similar to Libcrypt. We decided that to foster the use of cryptography in Free Software an LGPLed library would make more sense because it avoids problems due to license incompatibilities between some Free Software licenses and the GPL. Please note that in many cases it is better for a library to be licensed under the GPL, so that it provides an advantage for free software projects. The Lesser GPL is so named because it does less to protect the freedom of the users of the code that it covers. See http://www.gnu.org/philosophy/why-not-lgpl.html for more explanation. Configure options ----------------- Here is a list of configure options which are sometimes useful for installation. --enable-m-guard Enable the integrated malloc checking code. Please note that this feature does not work on all CPUs (e.g. SunOS 5.7 on UltraSparc-2) and might give you a bus error. --disable-asm Do not use assembler modules. It is not possible to use this on some CPU types. --enable-ld-version-script Libgcrypt tries to build a library where internal symbols are not exported. This requires support from ld and is currently enabled for a few OSes. If you know that your ld supports the so called ELF version scripts, you can use this option to force its use. OTOH, if you get error message from the linker, you probably want to use this option to disable the use of version scripts. Note, that you should never ever use an undocumented symbol or one which is prefixed with an underscore. --enable-ciphers=list --enable-pubkey-ciphers=list --enable-digests=list If not otherwise specified, all algorithms included in the libgcrypt source tree are built. An exception are algorithms, which depend on features not provided by the system, like 64bit data types. With these switches it is possible to select exactly those algorithm modules, which should be built. --disable-endian-check Don't let configure test for the endianness but try to use the OS provided macros at compile time. This is helpful to create OS X fat binaries. + --enable-random-daemon + Include support for a global random damon and + build the daemon. The daemon itself is in an + experimental state. + Contact ------- See the file AUTHORS. diff --git a/autogen.sh b/autogen.sh index 5c5f72c5..395c9bd9 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,201 +1,200 @@ #! /bin/sh # Run this to generate all the initial makefiles, etc. # # Copyright (C) 2003 g10 Code GmbH # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. configure_ac="configure.ac" cvtver () { awk 'NR==1 {split($NF,A,".");X=1000000*A[1]+1000*A[2]+A[3];print X;exit 0}' } check_version () { if [ `("$1" --version || echo "0") | cvtver` -ge "$2" ]; then return 0 fi echo "**Error**: "\`$1\'" not installed or too old." >&2 echo ' Version '$3' or newer is required.' >&2 [ -n "$4" ] && echo ' Note that this is part of '\`$4\''.' >&2 DIE="yes" return 1 } DIE=no FORCE= if test "$1" == "--force"; then FORCE=" --force" shift fi # ***** W32 build script ******* # Used to cross-compile for Windows. if test "$1" = "--build-w32"; then tmp=`dirname $0` tsdir=`cd "$tmp"; pwd` shift if [ ! -f $tsdir/config.guess ]; then echo "$tsdir/config.guess not found" >&2 exit 1 fi build=`$tsdir/config.guess` [ -z "$w32root" ] && w32root="$HOME/w32root" echo "Using $w32root as standard install directory" >&2 # Locate the cross compiler crossbindir= for host in i586-mingw32msvc i386-mingw32msvc; do if ${host}-gcc --version >/dev/null 2>&1 ; then crossbindir=/usr/${host}/bin conf_CC="CC=${host}-gcc" break; fi done if [ -z "$crossbindir" ]; then echo "Cross compiler kit not installed" >&2 echo "Under Debian GNU/Linux, you may install it using" >&2 echo " apt-get install mingw32 mingw32-runtime mingw32-binutils" >&2 echo "Stop." >&2 exit 1 fi if [ -f "$tsdir/config.log" ]; then if ! head $tsdir/config.log | grep "$host" >/dev/null; then echo "Pease run a 'make distclean' first" >&2 exit 1 fi fi ./configure --enable-maintainer-mode --prefix=${w32root} \ --host=${host} --build=${build} \ - --with-gpg-error-prefix=${w32root} \ - --disable-shared + --with-gpg-error-prefix=${w32root} exit $? fi # ***** end W32 build script ******* # ***** AMD64 cross build script ******* # Used to cross-compile for AMD64 (for testing) if test "$1" = "--build-amd64"; then tmp=`dirname $0` tsdir=`cd "$tmp"; pwd` shift if [ ! -f $tsdir/config.guess ]; then echo "$tsdir/config.guess not found" >&2 exit 1 fi build=`$tsdir/config.guess` [ -z "$amd64root" ] && amd64root="$HOME/amd64root" echo "Using $amd64root as standard install directory" >&2 # Locate the cross compiler crossbindir= for host in x86_64-linux-gnu amd64-linux-gnu; do if ${host}-gcc --version >/dev/null 2>&1 ; then crossbindir=/usr/${host}/bin conf_CC="CC=${host}-gcc" break; fi done if [ -z "$crossbindir" ]; then echo "Cross compiler kit not installed" >&2 echo "Stop." >&2 exit 1 fi if [ -f "$tsdir/config.log" ]; then if ! head $tsdir/config.log | grep "$host" >/dev/null; then echo "Please run a 'make distclean' first" >&2 exit 1 fi fi $tsdir/configure --enable-maintainer-mode --prefix=${amd64root} \ --host=${host} --build=${build} \ --with-gpg-error-prefix=${amd64root} rc=$? exit $rc fi # ***** end AMD64 cross build script ******* # Grep the required versions from configure.ac autoconf_vers=`sed -n '/^AC_PREREQ(/ { s/^.*(\(.*\))/\1/p q }' ${configure_ac}` autoconf_vers_num=`echo "$autoconf_vers" | cvtver` automake_vers=`sed -n '/^min_automake_version=/ { s/^.*="\(.*\)"/\1/p q }' ${configure_ac}` automake_vers_num=`echo "$automake_vers" | cvtver` #gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ { #s/^.*(\(.*\))/\1/p #q #}' ${configure_ac}` #gettext_vers_num=`echo "$gettext_vers" | cvtver` if [ -z "$autoconf_vers" -o -z "$automake_vers" ] then echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2 exit 1 fi # Allow to override the default tool names AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX} AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX} AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX} ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX} #GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX} #MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX} if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf fi if check_version $AUTOMAKE $automake_vers_num $automake_vers; then check_version $ACLOCAL $automake_vers_num $autoconf_vers automake fi #if check_version $GETTEXT $gettext_vers_num $gettext_vers; then # check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext #fi if test "$DIE" = "yes"; then cat < + + * rndw32.c (_gcry_rndw32_gather_random_fast): Make it return void. + + * cipher.c (gcry_cipher_algo_name): Simplified. + + * random.c: Use the daemon only if compiled with USE_RANDOM_DAEMON. + + * Makefile.am (libcipher_la_SOURCES): Build random-daemon support + only if requested. + 2007-02-21 Werner Koch * random.c (rndpool, keypool): Make unsigned. (mix_pool): Change char* variables to unsigned char*. (gcry_randomize): Make arg BUFFER a void*. (gcry_create_nonce): Ditto. * rmd160.c (gcry_rmd160_mixblock): Make BUFFER a void*. (_gcry_rmd160_hash_buffer): Make OUTBUF and BUFFER void*. * sha1.c (_gcry_sha1_hash_buffer): Ditto. * cipher.c (gcry_cipher_encrypt, cry_cipher_decrypt): Change buffer args to void*. (gcry_cipher_register): Make ALGORITHM_ID a int *. * md.c (md_start_debug): Make SUFFIX a const char*. Use snprintf. (gcry_md_debug): New. (gcry_md_ctl): Changed arg BUFFER from unsigned char*. * md.c (md_write): Make INBUF a const void*. (gcry_md_write): Remove needless cast. * crc.c (crc32_write): Make INBUF a const void* (update_crc32, crc24rfc2440_write): Ditto. * sha512.c (sha512_write, transform): Ditto. * sha256.c (sha256_write, transform): Ditto. * rmd160.c (rmd160_write, transform): Ditto. * md5.c (md5_write, transform): Ditto. * md4.c (md4_write, transform): Ditto. * sha1.c (sha1_write, transform): Ditto. * tiger.c (tiger_write, transform): Ditto. * whirlpool.c (whirlpool_write, whirlpool_add, transform): Ditto. * elgamal.c (elg_names): Change to a const*. * dsa.c (dsa_names): Ditto. * rsa.c (rsa_names): Ditto. * pubkey.c (gcry_pk_lookup_func_name): Make ALIASES a const. 2007-02-20 Werner Koch * rndlinux.c (open_device): Remove unsused arg MINOR. 2007-01-30 Werner Koch * sha256.c (oid_spec_sha256): Add alias from pkcs#1. * sha512.c (oid_spec_sha512): Ditto. (oid_spec_sha384): Ditto. 2006-12-18 Werner Koch * rndlinux.c (set_cloexec_flag): New. (open_device): Set close-on-exit flags. Suggested by Max Kellermann. Fixes Debian#403613. * Makefile.am (AM_CPPFLAGS, AM_CFLAGS): Splitted and merged Moritz' changes. (INCLUDES): Removed. 2006-11-30 Werner Koch * serpent.c (byte_swap_32): Remove trailing semicolon. 2006-11-15 Werner Koch * Makefile.am (INCLUDES): Include ../src/ 2006-11-03 Werner Koch * random.c [HAVE_GETTIMEOFDAY]: Included sys/time.h and not sys/times.h. Reported by Rafaël Carré. 2006-11-05 Moritz Schulte * Makefile.am (AM_CFLAGS): Added -I$(top_builddir)/src so that the new gcrypt.h is used, not the one installed in the system. 2006-10-25 Werner Koch * primegen.c (prime_generate_internal): Tweaked use of secure memory and entropy use. Safe unused primes from the pool. Allocate at least a pool of 30. (save_pool_prime, get_pool_prime): New. 2006-10-23 Werner Koch * ac.c (_gcry_ac_data_from_sexp): Reset sexp_tmp for failsafe means. Release sexp_cur if needed. Reported by Dirk Stoecker. * pubkey.c (pubkeys_registered_lock): Intialized it. It is not realy needed because this is a mere initialization to 0 anyway. Noted by Victor Stinner. 2006-10-17 Werner Koch * dsa.c (_gcry_dsa_generate2): New. (generate): New arg QBITS. Add sanity checks for reasonable qbits and nbits. * pubkey.c (gcry_pk_genkey): Parse an qbits element. (pubkey_generate): New arg QBITS. Pass it to the DSA generation. 2006-10-05 Werner Koch * md.c (gcry_md_algo_info) : Check that the algo is available. 2006-10-04 David Shaw (wk) * tiger.c (round): Rename to tiger_round as gcc 4 has a built-in round function that this conflicts with. 2006-09-11 Werner Koch * rndw32.c (slow_gatherer_windowsNT): While adding data use the size of the diskPerformance and not its address. Has been fixed in GnuPG more than a year ago. Noted by Lee Fisher. 2006-08-30 Werner Koch * pubkey.c (sexp_data_to_mpi): Need to allow "ripemd160" here as this is the canonical name. 2006-08-29 Hye-Shik Chang (wk) * seed.c: New. 2006-08-03 Werner Koch * random-daemon.c (_gcry_daemon_initialize_basics): Don't initialize the socket. Remove arg SOCKETNAME. (connect_to_socket): Make sure that daemon is set to -1 on error. (call_daemon): Initialize the socket on the first call. (_gcry_daemon_randomize, _gcry_daemon_get_random_bytes) (_gcry_daemon_create_nonce): New arg SOCKETNAME. * random.c (initialize): Call new daemon initializator. (get_random_bytes, gcry_randomize, gcry_create_nonce): Pass socket name to daemon call and reset allow_daemon on failure. 2006-07-26 Werner Koch * rmd160.c (_gcry_rmd160_mixblock): Add cast to transform call. * blowfish.c (selftest): Cast string to usnigned char*. * primegen.c (prime_generate_internal): Cast unsigned/char* mismatch in calling m_out_of_n. (is_prime): Changed COUNT to unsigned int *. * ac.c (_gcry_ac_data_copy): Initialize DATA_MPIS. * random.c (gcry_create_nonce): Update the pid after a fork. Reported by Uoti Urpala. 2006-07-04 Marcus Brinkmann * sha512.c: Fix typo in copyright notice. 2006-06-21 Werner Koch * rsa.c (_gcry_rsa_generate): Replace xcalloc by calloc. * pubkey.c (gcry_pk_encrypt, gcry_pk_sign): Ditto. (sexp_to_key, sexp_to_sig, sexp_to_enc, gcry_pk_encrypt) (gcry_pk_sign, gcry_pk_genkey, gcry_pk_get_keygrip): Ditto. * md.c (md_copy): Ditto. 2006-04-22 Moritz Schulte * random-daemon.c (_gcry_daemon_initialize_basics): New argument: SOCKETNAME. Passing on to connect_to_socket() if non-NULL. (connect_to_socket, writen, readn, call_daemon): New functions. (_gcry_daemon_randomize, _gcry_daemon_get_random_bytes) (_gcry_daemon_create_nonce): Call call_daemon(). (RANDOM_DAEMON_SOCKET): New symbol. (daemon_socket): New static variable. * random.h (_gcry_daemon_initialize_basics): New parameter: SOCKETNAME. (_gcry_set_random_daemon_socket): New declaration. * random.c (initialize_basics): Pass DAEMON_SOCKET_NAME to _gcry_daemon_initialize_basics. (_gcry_set_random_daemon_socket): New function, setting DAEMON_SOCKET_NAME. 2006-04-01 Moritz Schulte * ac.c (eme_pkcs_v1_5_encode): Use KEY_SIZE directly, no need to call gcry_ac_key_get_nbits. (eme_pkcs_v1_5_decode): Likewise. (ac_es_dencode_prepare_pkcs_v1_5): Fill options_em structure with key_size. (_gcry_ac_data_dump, gcry_ac_data_dump): New functions. (_gcry_ac_data_to_sexp, _gcry_ac_data_from_sexp): More or less rewritten; changed S-Expression format so that it matches the one used in pubkey.c. 2006-03-15 Werner Koch * random-daemon.c: New. * random.c (_gcry_use_random_daemon): New. (get_random_bytes, gcry_randomize, gcry_create_nonce): Try diverting to the daemon functions. 2006-03-14 Werner Koch * random.c (lock_seed_file): New. (read_seed_file, _gcry_update_random_seed_file): Use it. * random.c (gcry_create_nonce): Detect a fork and re-seed. (read_pool): Fixed the fork detection; it used to work only for multi-threaded processes. 2006-03-12 Brad Hards (wk) * md.c (md_open): Use new variable macpads_Bsize instead of hardwiring the block size. Changed at all places. 2006-03-10 Brad Hards (wk, patch 2005-04-22) * md.c, sha256.c: Add support for SHA-224. (sha224_init): New. 2006-01-18 Brad Hards (wk 2006-03-07) * cipher.c (cipher_encrypt, cipher_decrypt, do_ofb_encrypt) (do_ofb_decrypt, gcry_cipher_open): Implement Output Feedback Mode. 2005-11-02 Moritz Schulte * pubkey.c (gcry_pk_algo_name): Return "?" instead of NULL for unknown algorithm IDs. * cipher.c (cipher_algo_to_string): Likewise. 2005-11-01 Moritz Schulte * pubkey.c (gcry_pk_algo_info): Don't forget to break after switch case. 2005-09-19 Werner Koch * dsa.c (generate): Add preliminary support for 2 and 4 keys. Return an error code if the key size is not supported. (_gcry_dsa_generate): Return an error. 2005-08-22 Werner Koch * primegen.c (check_prime): New arg RM_ROUNDS. (prime_generate_internal): Call it here with 5 rounds as used before. (gcry_prime_check): But here with 64 rounds. (is_prime): Make sure never to use less than 5 rounds. 2005-04-16 Moritz Schulte * ac.c (_gcry_ac_init): New function. 2005-04-12 Moritz Schulte * ac.c (_gcry_ac_io_write, _gcry_ac_io_read): Initialize err to make the compiler happy. Always use errno, now that gcry_malloc() is guaranteed to set errno on failure. (_gcry_ac_data_to_sexp): Don't forget to goto out after error in loop. (_gcry_ac_data_to_sexp): Remove unused variable: mpi_list; (_gcry_ac_data_to_sexp): Always deallocate sexp_buffer. (_gcry_ac_data_from_sexp): Don't forget to initialize data_set_new. (_gcry_ac_data_from_sexp): Handle special case, which is necessary, since gcry_sexp_nth() does not distinguish between "element does not exist" and "element is the empty list". (_gcry_ac_io_init_va): Use assert to make sure that mode and type are correct. Use gcry_error_t types where gcry_err_code_t types have been used before. 2005-04-11 Moritz Schulte * ac.c (_gcry_ac_data_sign_scheme): Don't forget to initialize buffer. * whirlpool.c: New file. * md.c (digest_table): Add whirlpool. * Makefile.am (EXTRA_libcipher_la_SOURCES): Added: whirlpool.c. 2005-03-30 Moritz Schulte * ac.c (_gcry_ac_data_from_sexp): Use length of SEXP_CUR, not length of SEXP; do not forget to set SEXP_TMP to NULL after it has been released. (struct gcry_ac_mpi): New member: name_provided. (_gcry_ac_data_set): Rename variable `name_final' to `name_cp'; remove const qualifier; change code to not cast away const qualifiers; use name_provided member as well. (_gcry_ac_data_set, _gcry_ac_data_get_name): Use name_provided member of named mpi structure. (gcry_ac_name_to_id): Do not forget to initialize err. (_gcry_ac_data_get_index): Do not forget to initialize mpi_return; use gcry_free() instead of free(); remove unnecessary cast; rename mpi_return and name_return to mpi_cp and name_cp; adjust code. (ac_data_mpi_copy): Do not cast away const qualifier. (ac_data_values_destroy): Likewise. (ac_data_construct): Likewise. (ac_data_mpi_copy): Initialize flags to GCRY_AC_FLAG_DEALLOC. (ac_data_extract): Use GCRY_AC_FLAG_DEALLOC instead of GCRY_AC_FLAG_COPY. (_gcry_ac_io_init_va, _gcry_ac_io_init, gcry_ac_io_init) (gcry_ac_io_init_va, _gcry_ac_io_write, _gcry_ac_io_read) (_gcry_ac_io_read_all, _gcry_ac_io_process): New functions. (gry_ac_em_dencode_t): Use gcry_ac_io_t in prototype instead of memroy strings directly; adjust encode/decode functions to use io objects. (emsa_pkcs_v1_5_encode_data_cb): New function ... (emsa_pkcs_v1_5_encode): ... use it here. (ac_data_dencode): Use io objects. (_gcry_ac_data_encode, _gcry_ac_data_decode, gcry_ac_data_encode) (gcry_ac_data_decode): Likewise. (_gcry_ac_data_encrypt_scheme, gcry_ac_data_encrypt_scheme) (_gcry_ac_data_decrypt_scheme, gcry_ac_data_decrypt_scheme) (_gcry_ac_data_sign_scheme, gcry_ac_data_sign_scheme) (_gcry_ac_data_verify_scheme, gcry_ac_data_verify_scheme): Likewise. 2005-03-23 Werner Koch * rndw32.c (_gcry_rndw32_gather_random_fast): While adding data use the size of the object and not the one of its address. Bug reported by Sascha Kiefer. 2005-03-19 Moritz Schulte * cipher.c (do_cbc_encrypt): Be careful to not overwrite data, which is to be used later on. This happend, in case CTS is enabled and OUTBUF is equal to INBUF. 2005-02-25 Werner Koch * pubkey.c (gcry_pk_get_keygrip): Allow for shadowed-private-key. 2005-02-13 Moritz Schulte * serpent.c: Updated from 1.2 branch: s/u32_t/u32/ and s/byte_t/byte/. Too match what we have always used and are using in all other files too (serpent_test): Moved prototype out of a fucntion. 2005-02-07 Moritz Schulte * ac.c: Major parts rewritten. * pubkey.c (_gcry_pk_get_elements): New function. 2004-12-09 Werner Koch * serpent.c (serpent_setkey): Moved prototype of serpent_test to outer scope. 2004-09-11 Moritz Schulte * pubkey.c (pubkey_table): Added an alias entry for GCRY_PK_ELG_E. 2004-08-23 Moritz Schulte * ac.c: Do not include . * rndegd.c: Likewise. * sha1.c: Likewise. * rndunix.c: Likewise. * rndlinux.c: Likewise. * rmd160.c: Likewise. * md5.c: Likewise. * md4.c: Likewise. * cipher.c: Likewise. * crc.c: Likewise. * blowfish.c: Likewise. * pubkey.c (dummy_generate, dummy_check_secret_key) (dummy_encrypt, dummy_decrypt, dummy_sign, dummy_verify): Return err code GPG_ERR_NOT_IMPLEMENTED instead of aborting through log_bug(). (dummy_get_nbits): Return 0 instead of aborting though log_bug(). 2004-08-19 Werner Koch * pubkey.c (sexp_data_to_mpi): Changed the zero random byte substituting code to actually do clever things. Thanks to Matthias Urlichs for noting the implementation problem. 2004-08-09 Moritz Schulte * pubkey.c (gcry_pk_sign): Fixed memory leak; fix provided by Modestas Vainius. 2004-07-16 Werner Koch * rijndael.c (do_encrypt): Fix alignment problem. Bugs found by Matthias Urlichs. (do_decrypt): Ditto. (keySched, keySched2): Use 2 macros along with unions in the key schedule context. 2004-07-14 Moritz Schulte * rsa.c (_gcry_rsa_decrypt): Don't forget to free "a". Thanks to Nikos Mavroyanopoulos. 2004-05-09 Werner Koch * random.c (read_pool): Mix the PID in to better protect after a fork. 2004-07-04 Moritz Schulte * serpent.c: Use "u32_t" instead of "unsigned long", do not declare S-Box variables as "register". Fixes failure on OpenBSD/sparc64, reported by Nikolay Sturm. 2004-05-07 Werner Koch * random.c (initialize): Factored out some code to .. (initialize_basics): .. new function. (_gcry_random_initialize): Just call initialize_basics unless the new arg FULL is set to TRUE. (_gcry_fast_random_poll): Don't do anything unless the random system has been really initialized. 2004-05-07 Moritz Schulte * ac.c (gcry_ac_open): Do not dereference NULL pointer. Reported by Umberto Salsi. 2004-02-20 Werner Koch * primegen.c (check_prime): New args CB_FUNC and CB_ARG; call them at different stages. Pass these arguments through all callers. 2004-02-06 Werner Koch * des.c: Add a new OID as used by pkcs#12. * rfc2268.c: New. Taken from libgcrypt. * cipher.c: Setup the rfc2268 algorithm. 2004-01-25 Moritz Schulte * primegen.c (prime_generate_internal): Do not forget to free `q_factor'; fixed by Brieuc Jeunhomme. (prime_generate_internal): Do not forget to free `prime'. 2004-01-14 Moritz Schulte * ac.c (gcry_ac_data_set): New argument: flags; slightly rewritten. (gcry_ac_data_get_name, gcry_ac_data_get_index): Likewise. (gcry_ac_key_pair_generate): New argument: misc_data; modified order of arguments. (gcry_ac_key_test): New argument: handle. (gcry_ac_key_get_nbits, gcry_ac_key_get_grip): Likewise. Use GCRY_AC_FLAG_NO_BLINDING instead of GCRY_AC_DATA_FLAG_NO_BLINDING. (gcry_ac_mpi): New member: flags. (gcry_ac_data_search, gcry_ac_data_add): Removed functions. 2003-12-22 Werner Koch * primegen.c (is_prime): Release A2. 2003-12-19 Werner Koch * md.c: Moved a couple of functions down below the data structure definitions. (struct gcry_md_context): New field ACTUAL_HANDLE_SIZE. (md_open): Set it here. (strcut gcry_md_list): New field ACTUAL_STRUCT_SIZE. (md_enable): Set it here. (md_close): Wipe the context memory. secure memory. * cipher.c (struct gcry_cipher_handle): New field ACTUAL_HANDLE_SIZE. (gcry_cipher_open): Set it here. (gcry_cipher_close): Use it to always wipe out the handle data. * ac.c (gcry_ac_open): Make sure HANDLE gets initialized even when the function is not successful. (gcry_ac_close): Allow a NULL handle. (gcry_ac_key_destroy, gcry_ac_key_pair_destroy): Ditto. (gcry_ac_key_get_grip): Return INV_OBJ on error. * primegen.c (prime_generate_internal): Fixed error code for failed malloc. Replaced the !err if chain by gotos. (gcry_prime_group_generator): Remove the extra sanity check. * md.c: Minor code and comment cleanups. 2003-12-16 Werner Koch * primegen.c (gen_prime): Doc fix. Thanks to Newton Hammet. 2003-12-11 Werner Koch * rndunix.c (slow_poll): Don't use #warning but #error. * rndegd.c: Changed indentation. (my_make_filename): Removd the var_arg cruft becuase we don't need it here. Changed caller. * rndlinux.c: Changed indentation. (open_device): Remove the superfluous stat call and clarify comment. * rsa.c: Changed indentation. (secret): Use the standard algorithm if p, q and u are not available. (rsa_blind, rsa_unblind): Renamed from _gcry_rsa_blind, _gcry_rsa_unblind and moved more to the top. * md4.c: Changed indentation. Removed unnecessary casts. * md5.c, rmd160.c, sha1.c, tiger.c: Ditto. * rijndael.c, twofish.c: Ditto. * serpent.c: Removed unnecessary casts. * sha256.c, sha512.c: Ditto. 2003-12-09 Werner Koch * dsa.c: Unified indentation style. * elgamal.c: Ditto. * des.c (des_key_schedule): Code beautifications. * blowfish.c: Changed indentation style. * cast5.c (do_cast_setkey): Ditto. * pubkey.c (gcry_pk_encrypt): Replaced the chain of if(!err) tests by straightforward gotos. Other cleanups. (gcry_pk_decrypt): Ditto. (gcry_pk_sign): Ditto. (gcry_pk_verify): Ditto. (gcry_pk_genkey): Ditto. Use strtoul instead of strtol. (gcry_pk_ctl): Use GPG_ERR_INV_ARG to indicate bad arguments. 2003-12-07 Werner Koch * pubkey.c (gcry_pk_register_default): Undef the helper macro. (gcry_pk_map_name): Allow NULL for string. (sexp_to_key): Use memcpy and not strncpy. Use gcry_free and not free. (sexp_to_sig): Ditto. (sexp_to_enc): Ditto. Replaced the chain of if(!err) tests by straightforward gotos. 2003-12-05 Werner Koch * cipher.c: Documentation cleanups. (gcry_cipher_mode_from_oid): Allow NULL for STRING. 2003-12-03 Werner Koch * elgamal.c (sign, do_encrypt, gen_k): Make sure that a small K is only used for encryption. 2003-11-18 Werner Koch * random.h (rndw32_set_dll_name): Removed unused prototype. * Makefile.am (EXTRA_DIST): Added Manifest. 2003-11-11 Werner Koch * Manifest: New. 2003-11-04 Werner Koch * md.c (gcry_md_hash_buffer): Use shortcut for SHA1 * sha1.c (_gcry_sha1_hash_buffer): New. * random.c: Reformatted most functions. (mix_pool): Moved the failsafe_digest from global scope to here. (do_fast_random_poll): Use the generic fucntions even if a fast gathering function has been used. (read_pool): Detect a fork and retry. (gcry_randomize, get_random_bytes): Don't distinguish anymore between weak and strong random. (gcry_create_nonce): New. 2003-10-31 Werner Koch * rndw32.c (slow_gatherer_windowsNT): Use a plain buffer for the disk performance values and not the W32 API structure. * dsa.c (verify): s/exp/ex/ due to shadowing of a builtin. * elgamal.c (verify): Ditto. * ac.c (gcry_ac_data_get_index): s/index/idx/ (gcry_ac_data_copy_internal): Remove the cast in _gcry_malloc. (gcry_ac_data_add): Must use gcry_realloc instead of realloc. * pubkey.c (sexp_elements_extract): s/index/idx/ as tribute to the forehackers. (gcry_pk_encrypt): Removed shadowed definition of I. Reordered arguments to malloc for clarity. (gcry_pk_sign, gcry_pk_genkey): Ditto. * primegen.c (prime_generate_internal): s/random/randomlevel/. 2003-10-27 Moritz Schulte * pubkey.c (gcry_pk_encrypt): Don't forget to deallocate pkey. 2003-10-27 Werner Koch * random.c (gcry_random_add_bytes): Return if buflen is zero to avoid gcc warning about unsed parameter. (MASK_LEVEL): Simplified; does now work for signed and unsigned w/o warnings. * md.c (md_start_debug): Removed the const from SUFFIX, because this function is called from the control fucntion which does not require const. Prefixed all (pubkey,digest,cipher}_spec_* globale variables with _gcry_. * ac.c (ac_key_identifiers): Made static. * random.c (getfnc_gather_random,getfnc_fast_random_poll): Move prototypes to .. * rand-internal.h: .. here * random.c (getfnc_gather_random): Include rndw32 gatherer. * rndunix.c, rndw32.c, rndegd.c: Include them here. * rndlinux.c (_gcry_rndlinux_gather_random): Prepend the _gcry_ prefix. Changed all callers. * rndegd.c (_gcry_rndegd_gather_random): Likewise. (_gcry_rndegd_connect_socket): Likewise. * rndunix.c (_gcry_rndunix_gather_random): Likewise. (waitpid): Made static. * rndw32.c: Removed the old and unused winseed.dll cruft. (_gcry_rndw32_gather_random_fast): Renamed from gather_random_fast. (_gcry_rndw32_gather_random): Renamed from gather_random. Note, that the changes 2003-04-08 somehow got lost. * sha512.c (sha512_init, sha384_init): Made static. * cipher.c (do_ctr_decrypt): Removed "return" from this void function. 2003-10-24 Moritz Schulte * serpent.c: Fix an issue on big-endian systems. * rndw32.c: Removed IS_MODULE -cruft. * rndlinux.c (rndlinux_gather_random): Likewise. 2003-10-10 Werner Koch * primegen.c (gen_prime): Bail out if NBITS is less than 16. (prime_generate_internal): Initialize prime variable to suppress compiler warning. Check pbits, initialize qbits when passed as zero. * primegen.c (prime_generate_internal): New arg ALL_FACTORS. Changed all callers. (gcry_prime_generate): Make the factors arg optional. Request all_factors. Make sure PRIME is set to NULL even on error. (gcry_prime_group_generator): New. (gcry_prime_release_factors): New. 2003-10-06 Werner Koch * primegen.c (gen_prime): Assert that NBITS is never zero, it would cause a segv. 2003-09-28 Moritz Schulte * ac.c: Include "cipher.h". 2003-09-27 Moritz Schulte * rndegd.c (do_read): Return nread instead of nbytes; thanks to Michael Caerwyn. 2003-09-04 Werner Koch * pubkey.c (_gcry_pk_aliased_algo_name): New. * ac.c (gcry_ac_open): Use it here. * Makefile.am (EXTRA_libcipher_la_SOURCES): Add serpent.c 2003-09-02 Moritz Schulte * primegen.c (gcry_prime_check, gcry_prime_generate): New functions. (prime_generate_internal): New function, based on _gcry_generate_elg_prime. (_gcry_generate_elg_prime): Rewritten as a wrapper for prime_generate_internal. 2003-08-28 Werner Koch * pubkey.c (gcry_pk_encrypt): Don't include the flags list in the return value. This does not make sense and breaks any programs parsing the output strictly (e.g. current gpgsm). (gcry_pk_encrypt): If aliases for the algorithm name exists, take the first one instead of the regular name to adhere to SPKI conventions. (gcry_pk_genkey): Ditto. (gcry_pk_sign): Ditto. Removed unused KEY_ALGO_NAME. 2003-08-19 Moritz Schulte * cipher.c: Add support for Serpent * serpent.c: New file. 2003-08-10 Moritz Schulte * rsa.c (_gcry_rsa_blind, _gcry_rsa_unblind): Declare static. 2003-08-09 Timo Schulz * random.c (getfnc_gather_random): Don't check NAME_OF_DEV_RANDOM two times, but also the NAME_OF_DEV_URANDOM device. 2003-08-08 Moritz Schulte * pubkey.c (sexp_to_enc): Fixed extraction of S-Expression: do not fail if no `flags' sub S-Expression is found. 2003-07-27 Werner Koch * md.c (gcry_md_lookup_func_oid): Allow for empty OID lists. 2003-07-23 Moritz Schulte * ac.c (gcry_ac_data_construct): New argument: include_flags, only include `flags' S-expression, if include_flags is true. Adjust callers. Thanks for triggering a bug caused by `flags' sub-S-expression where they are not expected to Ralf Schneider. 2003-07-21 Moritz Schulte * pubkey.c (gcry_pk_lookup_func_name): Use new member name `aliases' instead of `sexp_names'. * ac.c (gcry_ac_key_data_get): New function. * cipher.c (gcry_cipher_lookup_func_name): Fix return value. 2003-07-20 Moritz Schulte * blowfish.c: Adjusted for new gcry_cipher_spec_t structure. * cast5.c: Likewise. * twofish.c: Likewise. * arcfour.c: Likewise. * rijndael.c (rijndael_oids, rijndael192_oids, rijndael256_oids): New variables, adjust for new gcry_cipher_spec_t structure. * des.c (oids_tripledes): New variable, adjust for new gcry_cipher_spec_t structure. * md.c (oid_table): Removed. * tiger.c (oid_spec_tiger): New variable. (digest_spec_tiger): Adjusted for new gry_md_spec_t structure. * sha512.c (oid_spec_sha512): New variable. (digest_spec_sha512): Adjusted for new gry_md_spec_t structure. * sha512.c (oid_spec_sha384): New variable. (digest_spec_sha384): Adjusted for new gry_md_spec_t structure. * sha256.c (oid_spec_sha256): New variable. (digest_spec_sha256): Adjusted for new gry_md_spec_t structure. * sha1.c (oid_spec_sha1): New variable. (digest_spec_sha1): Adjusted for new gry_md_spec_t structure. * rmd160.c (oid_spec_rmd160): New variable. (digest_spec_rnd160): Adjusted for new gry_md_spec_t structure. * md5.c (oid_spec_md5): New variable. (digest_spec_md5): Adjusted for new gry_md_spec_t structure. * md4.c (oid_spec_md4): New variable. (digest_spec_md4): Adjusted for new gry_md_spec_t structure. * crc.c (digest_spec_crc32, digest_spec_crc32_rfc1510, digest_spec_crc32_rfc2440): Adjusted for new gry_md_spec_t structure. 2003-07-19 Moritz Schulte * md.c (gcry_md_lookup_func_oid): New function. (search_oid): New function, copied from cipher.c. (gcry_md_map_name): Adjust for new search_oid_interface. * cipher.c (oid_table): Removed table. (gcry_cipher_lookup_func_oid): New function. (search_oid): Rewritten to use the module functions. (gcry_cipher_map_name): Adjust for new search_oid interface. (gcry_cipher_mode_from_oid): Likewise. 2003-07-18 Werner Koch * md.c (gcry_md_hash_buffer): Convert ERR to gpg_error_t in gpg_strerror. 2003-07-14 Moritz Schulte * cipher.c (gcry_cipher_lookup_func_name): Also check the cipher name aliases, not just the primary name. (gcry_cipher_map_name): Remove kludge for aliasing Rijndael to AES. * arcfour.c, blowfish.c, cast5.c, des.c, twofish.c: Adjust cipher specification structures. * rijndael.c (rijndael_names, rijndael192_names, rijndael256_names): New variables, use them in the cipher specifications. * rmd160test.c: Removed file. * ac.c, arcfour.c, blowfish.c, cast5.c, cipher.c, des.c, dsa.c, elgamal.c, md.c, pubkey.c, random.c, rijndael.c, rsa.c, twofish.c: Used gcry_err* wrappers for libgpg symbols. * primegen.c (gen_prime): Correct the order arguments to extra_check. 2003-07-12 Moritz Schulte * ac.c: Replaced all public occurences of gpg_error_t with gcry_error_t. * cipher.c: Likewise. * md.c: Likewise. * pubkey.c: Likewise. * random.c: Likewise. * cipher.c: Added support for TWOFISH128. 2003-07-08 Moritz Schulte * ac.c (gcry_ac_data_copy_internal): New function, based on gcry_ac_data_copy. (gcry_ac_data_copy): Made public, use gcry_ac_data_copy_internal. (gcry_ac_key_init): Use gcry_ac_data_copy_internal. 2003-07-07 Moritz Schulte * ac.c (gcry_ac_data_set): Only release old MPI value if it is different from the new value. Bug reported by Simon Josefsson . * pubkey.c (gcry_pk_list): New function. * md.c (gcry_md_list): New function. * ac.c (gcry_ac_key_pair_generate): Fix calculation of format string size. 2003-07-05 Moritz Schulte * md.c: Named struct of digest_table `digest_table_entry'. (digest_table_entry): New member: algorithm; filled in. (digest_table_entry): Removed unused member: flags. (gcry_md_register): New argument: algorithm_id, filled in. (gcry_md_register_default): Used algorithm ID from module structure. (gcry_md_map_name): Likewise. (md_enable): Likewise. (md_read): Likewise. (gcry_md_info): Likewise. * pubkey.c: Named truct for pubkey_table `pubkey_table_entry'. (pubkey_table_entry): New member: algorithm; filled in. (gcry_pk_register_default): Used algorithm ID from pubkey_table. (gcry_pk_register): New argument: algorithm_id, filled in. (gcry_pk_map_name): Used algorithm ID from module structure. (gcry_pk_decrypt): Likewise. (gcry_pk_encrypt): Likewise. (gcry_pk_verify): Likewise. (gcry_pk_sign): Likewise. (gcry_pk_testkey): Likewise. (gcry_pk_genkey): Likewise. (gcry_pk_get_nbits): Likewise. (sexp_to_key): Removed unused variable: algo. (sexp_to_sig): Likewise. * cipher.c: Named struct for cipher_table `cipher_table_entry'. (cipher_table_entry): New member: algorithm; filled in. (gcry_cipher_register_default): Used algorithm ID from cipher_table. (gcry_cipher_register): New argument: algorithm_id, filled in. (gcry_cipher_map_name): Used algorithm ID from module structure. * arcfour.c (cipher_spec_arcfour): Removed algorithm ID. * blowfish.c (cipher_spec_blowfish): Likewise. * cast5.c (cipher_spec_cast5): Likewise. * crc.c (digest_spec_crc32): Likewise. * crc.c (digest_spec_crc32_rfc1510): Likewise. * crc.c (digest_spec_crc32_rfc2440): Likewise. * des.c (cipher_spec_des): Likewise. * des.c (cipher_spec_tripledes): Likewise. * dsa.c (pubkey_spec_dsa): Likewise. * elgamal.c (pubkey_spec_elg): Likewise. * md4.c (digest_spec_md4): Likewise. * md5.c (digest_spec_md5): Likewise. * aes.c (cipher_spec_aes): Likewise. * aes.c (cipher_spec_aes192): Likewise. * aes.c (cipher_spec_aes256): Likewise. * rsa.c (pubkey_spec_rsa): Likewise. * sha1.c (digest_spec_sha1): Likewise. * sha256.c (digest_spec_sha256): Likewise. * sha512.c (digest_spec_sha512): Likewise. * tiger.c (digest_spec_tiger): Likewise. * twofish.c (cipher_spec_twofish): Likewise. * twofish.c (cipher_spec_twofish128): Likewise. * Makefile.am (EXTRA_libcipher_la_SOURCES): Fix list of source files; reported by Simon Josefsson . * pubkey.c: Replaced all occurences of `id' with `algorithm', since `id' is a keyword in obj-c. * md.c: Likewise. * cipher.c: Likewise. * crc.c, md4.c, md5.c, rmd160.c, sha1.c, sha256.c, tiger.c: Replaced all occurences of gcry_digest_spec_t with gcry_md_spec_t. * dsa.c, rsa.c, elgamal.c: Replaced all occurencens of gcry_pubkey_spec_t with gcry_pk_spec_t. * md.c: Replaced all occurences of gcry_digest_spec_t with gcry_md_spec_t. (gcry_digest_register_default): Renamed to ... (gcry_md_register_default): ... this; adjusted callers. (gcry_digest_lookup_func_name): Renamed to ... (gcry_md_lookup_func_name): ... this; adjusted callers. (gcry_digest_lookup_name): Renamed to ... (gcry_md_lookup_name): ... this; adjusted callers. (gcry_digest_register): Renamed to ... (gcry_md_register): ... this. (gcry_digest_unregister): Renamed to ... (gcry_md_unregister): ... this. * pubkey.c (gcry_pubkey_register): Renamed to ... (gcry_pk_register): ... this. (gcry_pubkey_unregister): Renamed to ... (gcry_pk_unregister): ... this. Replaced all occurences of gcry_pubkey_spec_t with gcry_pk_spec_t. (gcry_pubkey_register_default): Renamed to ... (gcry_pk_register_default): ... this; adjusted callers. (gcry_pubkey_lookup_func_name): Renamed to ... (gcry_pk_lookup_func_name): ... this; adjusted callers. (gcry_pubkey_lookup_name): Renamed to ... (gcry_pk_lookup_name): ... this; adjusted callers. * md.c (gcry_md_hash_buffer): Fix error checking. Thanks to Simon Josefsson . 2003-07-04 Moritz Schulte * cipher.c (gcry_cipher_list): New function. 2003-07-01 Moritz Schulte * pubkey.c (sexp_to_sig): Accept a `flags' S-expression to be more consistent with sexp_to_enc. 2003-06-30 Moritz Schulte * Makefile.am (libcipher_la_SOURCES): Added: ac.c. * pubkey.c (_gcry_pk_module_lookup): New function. (_gcry_pk_module_release): New function. 2003-06-29 Moritz Schulte * ac.c: New file. 2003-06-26 Werner Koch * md.c (gcry_md_hash_buffer): Trigger BUG correcly with new API. 2003-06-19 Werner Koch * md.c (gcry_md_is_enabled): Fixed. 2003-06-18 Werner Koch * cipher.c (gcry_cipher_get_algo_keylen): New. (gcry_cipher_get_algo_blklen): New. 2003-06-18 Moritz Schulte * arcfour.c, cipher.c, blowfish.c, md.c, cast5.c, pubkey.c, crc.c, des.c, dsa.c, elgamal.c, md4.c, md5.c, random.c, rijndael.c, rmd160.c, rsa.c, sha1.c, sha256.c, sha512.c, tiger.c, twofish.c: Replaced older types GcryDigestSpec, GcryCipherSpec and GcryPubkeySpec with newer types: gcry_digest_spec_t, gcry_cipher_spec_t and gcry_pubkey_spec_t. * md.c (gcry_digest_id_new): Removed function. (gcry_digest_register): Removed code for generating a new module ID. * pubkey.c (gcry_pubkey_id_new): Removed function. (gcry_pubkey_register): Removed code for generating a new module ID. * cipher.c, md.c, pubkey.c: Replace old type GcryModule with newer one: gcry_module_t. (gcry_cipher_id_new): Removed function. (gcry_cipher_register): Removed code for generating a new module ID. * cipher.c (gcry_cipher_register): Adjust call to _gcry_module_add. (gcry_cipher_register_default): Likewise. * pubkey.c (gcry_pubkey_register_default): Likewise. (gcry_pubkey_register): Likewise. * md.c (gcry_digest_register_default): Likewise. (gcry_digest_register): Likewise. * md.c (gcry_digest_lookup_func_id): Removed function. (gcry_digest_lookup_id): Likewise. (gcry_digest_id_new): Use _gcry_module_lookup_id instead of gcry_digest_lookup_id. (digest_algo_to_string): Likewise. (check_digest_algo): Likewise. (md_enable): Likewise. (md_digest_length): Likewise. (md_asn_oid): Likewise. * pubkey.c (gcry_pubkey_lookup_id): Removed function. (gcry_pubkey_lookup_func_id): Likewise. (gcry_pubkey_id_new): Use _gcry_module_lookup_id instead of gcry_pubkey_id_new. (gcry_pk_algo_name): Likewise. (disable_pubkey_algo): Likewise. (check_pubkey_algo): Likewise. (pubkey_get_npkey): Likewise. (pubkey_get_nskey): Likewise. (pubkey_get_nsig): Likewise. (pubkey_get_nenc): Likewise. (pubkey_generate): Likewise. (pubkey_check_secret_key): Likewise. (pubkey_encrypt): Likewise. (pubkey_decrypt): Likewise. (pubkey_sign): Likewise. (pubkey_verify): Likewise. (gcry_pk_algo_info): Likewise. * cipher.c (gcry_cipher_lookup_func_id): Removed function. (gcry_cipher_lookup_id): Likewise. (cipher_algo_to_string): use _gcry_module_lookup_id instead of gcry_cipher_lookup_id. (disable_cipher_algo): Likewise. (check_cipher_algo): Likewise. (cipher_get_blocksize): Likewise. (gcry_cipher_open): Likewise. (gcry_cipher_id_new): Likewise. 2003-06-17 Moritz Schulte * Makefile.am (GCRYPT_MODULES): Set to @GCRYPT_CIPHERS@, @GCRYPT_PUBKEY_CIPHERS@, @GCRYPT_DIGESTS@ and @GCRYPT_RANDOM@. (libcipher_la_DEPENDENCIES): Set to $(GCRYPT_MODULES). (libcipher_la_LIBADD): Likewise. (AM_CFLAGS): Added: @GPG_ERROR_CFLAGS@. (EXTRA_libcipher_la_SOURCES): Added all conditional sources. * md.c (md_open): Use _gcry_fast_random_poll instead of fast_random_poll. * cipher.c (gcry_cipher_open): Likewise. * random.h (fast_random_poll): Removed macro. * blowfish.c, md4.c, md5.c, rmd160.c, sha1.c, sha256.c, sha512.c, tiger.c: Use Autoconf's WORDS_BIGENDIAN instead of our own BIG_ENDIAN_HOST. 2003-06-16 Moritz Schulte * random.c (getfnc_gather_random): Do not special-case USE_ALL_RANDOM_MODULES, make it the default. * dsa.c: Replace last occurences of old type names with newer names (i.e. replace MPI with gcry_mpi_t). * elgamal.c: Likewise. * primegen.c: Likewise. * pubkey.c: Likewise. * rsa.c: Likewise. 2003-06-14 Moritz Schulte * des.c (des_setkey): Add selftest check. (tripledes_set3keys): Likewise. (do_tripledes_setkey): Remove selftest check. (do_des_setkey): Likewise. 2003-06-11 Moritz Schulte * md.c (_gcry_md_init): New function. * cipher.c (_gcry_cipher_init): New function. * pubkey.c (_gcry_pk_init): New function. 2003-06-13 Werner Koch * md.c (gcry_md_get_algo): Reverted to old API. This is a convenience function anyway and error checking is not approriate. (gcry_md_is_secure): New. (gcry_md_is_enabled): New. 2003-06-12 Werner Koch * cipher.c (gcry_cipher_open): Make sure HANDLE is set to NULL on error. 2003-06-11 Werner Koch * md.c (gcry_md_open): Make sure H receives either NULL or an valid handle. (gcry_md_copy): Swapped arguments so that it is more in lione with md_open and most other API fucntions like memcpy (destination comes first). Make sure HANDLE is set to NULL on error. * rijndael.c (do_encrypt): Hack to force correct alignment. It seems not to be not sufficient, though. We should rework this fucntions and remove all these ugly casts. Let the compiler optimize or have an assembler implementation. 2003-06-09 Moritz Schulte * Makefile.am: Removed rules serpent, since that is not commited yet. 2003-06-08 Moritz Schulte * pubkey.c (gcry_pk_encrypt): Improve calculation for size of the format string. 2003-06-07 Moritz Schulte * arcfour.c, bithelp.h, blowfish.c, cast5.c, cipher.c, crc.c, des.c, dsa.c, elgamal.c, md4.c, md5.c, md.c, primegen.c, pubkey.c, rand-internal.h, random.c, random.h, rijndael.c, rmd160.c, rmd160test.c, rmd.h, rndeged.c, rndlinux.c, rndunix.c, rndw32.c, rsa.c, sha1.c, sha256.c, sha512.c, tiger.c, twofish.c: Edited all preprocessor instructions to remove whitespace before the '#'. This is not required by C89, but there are some compilers out there that don't like it. Replaced any occurence of the now deprecated type names with the new ones. 2003-06-04 Moritz Schulte * pubkey.c (gcry_pk_encrypt): Construct an arg_list and use gcry_sexp_build_array instead of gcry_sexp_build. (gcry_pk_sign): Likewise. (gcry_pk_genkey): Likewise. 2003-06-01 Moritz Schulte * dsa.c (_gcry_dsa_generate): Do not check wether the algorithm ID does indeed belong to DSA. (_gcry_dsa_sign): Likewise. (_gcry_dsa_verify): Likewise. (_gcry_dsa_get_nbits): Likewise. * elgamal.c (_gcry_elg_check_secret_key): Do not check wether the algorithm ID does indeed belong to ElGamal. (_gcry_elg_encrypt): Likewise. (_gcry_elg_decrypt): Likewise. (_gcry_elg_sign): Likewise. (_gcry_elg_verify): Likewise. (_gcry_elg_get_nbits): Likewise. (_gcry_elg_generate): Likewise. * rsa.c (_gcry_rsa_generate): Do not check wether the algorithm ID does indeed belong to RSA. (_gcry_rsa_encrypt): Likewise. (_gcry_rsa_decrypt): Likewise. (_gcry_rsa_sign): Likewise. (_gcry_rsa_verify): Likewise. (_gcry_rsa_get_nbits): Likewise. 2003-05-30 Moritz Schulte * md.c (md_get_algo): Return zero in case to algorithm is enabled. * md.c (gcry_md_info): Adjusted for new no-errno-API. (md_final): Likewise. (gcry_md_get_algo): Likewise. * pubkey.c (gcry_pk_get_keygrip): Likewise. (gcry_pk_ctl): Likewise. (gcry_pk_algo_info): Likewise. * des.c (selftest): Likewise. 2003-05-29 Moritz Schulte * md.c (md_enable): Do not forget to release module on error. (gcry_md_open): Adjusted for new no-errno-API. (md_open): Likewise. (md_copy): Likewise. (gcry_md_copy): Likewise. (gcry_md_setkey): Likewise. (gcry_md_algo_info): Likewise. * cipher.c (gcry_cipher_open): Adjusted for new no-errno-API and also fixed a locking bug. (gcry_cipher_encrypt): Adjusted for new no-errno-API. (gcry_cipher_decrypt): Likewise. (gcry_cipher_ctl): Likewise. (gcry_cipher_info): Likewise. (gcry_cipher_algo_info): Likewise. 2003-05-28 Moritz Schulte * md.c (md_enable): Adjusted for libgpg-error. (gcry_md_enable): Likewise. (gcry_digest_register_default): Likewise. (gcry_digest_register): Likewise. (check_digest_algo): Likewise. (prepare_macpads): Likewise. (gcry_md_setkey): Likewise. (gcry_md_ctl): Likewise. (gcry_md_get): Likewise. (gcry_md_algo_info): Likewise. (gcry_md_info): Likewise. * dsa.c (_gcry_dsa_generate): Likewise. (_gcry_dsa_check_secret_key): Likewise. (_gcry_dsa_sign): Likewie. (_gcry_dsa_verify): Likewise. * twofish.c (do_twofish_setkey): Likewise. (twofish_setkey): Likewise. * cipher.c (gcry_cipher_register): Likewise. 2003-05-25 Moritz Schulte * rijndael.c (do_setkey): Adjusted for libgpg-error. (rijndael_setkey): Likewise. * random.c (gcry_random_add_bytes): Likewise. * elgamal.c (_gcry_elg_generate): Likewise. (_gcry_elg_check_secret_key): Likewise. (_gcry_elg_encrypt): Likewise. (_gcry_elg_decrypt): Likewise. (_gcry_elg_sign): Likewise. (_gcry_elg_verify): Likewise. * rsa.c (_gcry_rsa_generate): Likewise. (_gcry_rsa_check_secret_key): Likewise. (_gcry_rsa_encrypt): Likewise. (_gcry_rsa_decrypt): Likewise. (_gcry_rsa_sign): Likewise. (_gcry_rsa_verify): Likewise. * pubkey.c (dummy_generate, dummy_check_secret_key, dummy_encrypt, dummy_decrypt, dummy_sign, dummy_verify): Likewise. (gcry_pubkey_register): Likewise. (check_pubkey_algo): Likewise. (pubkey_generate): Likewise. (pubkey_check_secret_key): Likewise. (pubkey_encrypt): Likewise. (pubkey_decrypt): Likewise. (pubkey_sign): Likewise. (pubkey_verify): Likewise. (sexp_elements_extract): Likewise. (sexp_to_key): Likewise. (sexp_to_sig): Likewise. (sexp_to_enc): Likewise. (sexp_data_to_mpi): Likewise. (gcry_pk_encrypt): Likewise. (gcry_pk_decrypt): Likewise. (gcry_pk_sign): Likewise. (gcry_pk_verify): Likewise. (gcry_pk_testkey): Likewise. (gcry_pk_genkey): Likewise. (gcry_pk_ctl): Likewise. * cipher.c (dummy_setkey): Likewise. (check_cipher_algo): Likewise. (gcry_cipher_open): Likewise. (cipher_setkey): Likewise. (gcry_cipher_ctl): Likewise. (cipher_encrypt): Likewise. (gcry_cipher_encrypt): Likewise. (cipher_decrypt): Likewise. (gcry_cipher_decrypt): Likewise. (gcry_cipher_info): Likewise. (gcry_cipher_algo_info): Likewise. * cast5.c (cast_setkey): Likewise. (do_cast_setkey): Likewise. * arcfour.c (arcfour_setkey): Likewise. (do_arcfour_setkey): Likewise. * blowfish.c (do_bf_setkey): Likewise. (bf_setkey): Likewise. * des.c (do_des_setkey): Likewise. (do_tripledes_setkey): Likewise. 2003-05-22 Moritz Schulte * tiger.c: Merged code ussing the U64_C macro from GnuPG. * sha512.c: Likewise. 2003-05-17 Moritz Schulte * pubkey.c (gcry_pk_genkey): Fix type: acquire a lock, instead of releasing it. 2003-05-11 Moritz Schulte * pubkey.c (gcry_pk_testkey): Call REGISTER_DEFAULT_CIPHERS. (gcry_pk_ctl): Likewise. 2003-04-27 Moritz Schulte * pubkey.c (gcry_pk_genkey): Release sexp after extracted data has been used. * md.c (gcry_md_get_algo_dlen): Simplified, simply call md_digest_length to do the job. * des.c (do_des_setkey): Check for selftest failure not only during initialization. (do_tripledes_setkey): Include check for selftest failure. * pubkey.c (gcry_pubkey_register_default): New macro `pubkey_use_dummy', use it. * elgamal.c (elg_names): New variable. (pubkey_spec_elg): Include elg_names. * dsa.c (dsa_names): New variable. (pubkey_spec_dsa): Include dsa_names. * rsa.c (rsa_names): New variable. (pubkey_spec_rsa): Include rsa_names. * pubkey.c (gcry_pubkey_lookup_func_name): Compare name also with the names listed in `sexp_names'. 2003-04-24 Moritz Schulte * pubkey.c (sexp_to_key): New variables: module, pubkey. Adjusted to new module interface. (sexp_to_key): Changend type of argument `retalgo' from `int *' to `GcryModule **'. Adjusted all callers. Removed argument: r_algotblidx. (sexp_to_sig): Changend type of argument `retalgo' from `int *' to `GcryModule **'. Adjusted all callers. (sexp_to_enc): Likewise. (pubkey_get_npkey, pubkey_get_nskey, pubkey_get_nsig, pubkey_get_nenc): Use strlen to find out the number. * rsa.c: Adjust pubkey_spec_rsa to new internal interface. * dsa.c: Likewise. * elgamal.c: Likewise. 2003-04-17 Moritz Schulte * pubkey.c (sexp_elements_extract): New function. * pubkey.c (sexp_to_key): Removed variable `idx', added `err', use sexp_elements_extract. (sexp_to_sig): Likewise. (sexp_to_enc): Likewise. * pubkey.c: Terminate list correctly. * md.c: Include sha512/sha384 in digest_table. 2003-04-16 Moritz Schulte * Makefile.am: Include support for sha512.c. * sha512.c: New file, merged from GnuPG, with few modifications for libgcrypt. * rand-internal.h: Removed declarations for constructor functions. * md.c (md_copy): Call _gcry_module_use for incrementing the usage counter of the digest modules. * rsa.c: Do not include "rsa.h". * dsa.c: Do not include "dsa.h". * elgamal.c: Do not include "elgamal.h". * des.c: Do not include "des.h". * cast5.c: Do not include "cast5.h". * blowfish.c: Do not include "blowfish.h". * arcfour.c: Do not include "arcfour.h". * Makefile.am (libcipher_la_DEPENDENCIES): Removed. (libcipher_la_LIBADD): Removed. Use Automake conditionals for conditional compilation. 2003-04-13 Moritz Schulte * cipher.c (gcry_cipher_open): Call REGISTER_DEFAULT_CIPHERS. * md.c (gcry_md_list): New member: module. (md_enable): New variable: module, changed use of module and digest. (md_enable): Initialize member: module. (md_close): Call _gcry_module_release. * cipher.c (gcry_cipher_open): New variable: module, changed use of module and cipher. (struct gcry_cipher_handle): New member: module. (gcry_cipher_open): Initialize member: module. (gcry_cipher_close): Call _gcry_module_release. 2003-04-09 Moritz Schulte * cipher.c: Include "ath.h". * md.c: Likewise. * pubkey.c: Likewise. * cipher.c (ciphers_registered_lock): New variable. * md.c (digests_registered_lock): New variable. * pubkey.c (pubkeys_registered_lock): New variable. * rndlinux.c (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_rndlinux_constructor): Removed function. * rndegd.c (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_rndegd_constructor): Removed function. * rndunix.c (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_rndunix_constructor): Removed function. * rndw32.c (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_rndw32_constructor): Removed function. * rndegd.c (rndegd_connect_socket): Simplify code for creating the egd socket address. (rndegd_connect_socket): Call log_fatal use instead of g10_log_fatal. (egd_gather_random): Renamed to ... (rndegd_gather_random): ... here. 2003-04-08 Moritz Schulte * rndlinux.c: Do not include "dynload.h". * rndunix.c: Likewise. * rndw32.c: Likewise. * rndegd.c (rndegd_connect_socket): Factored out from ... (egd_gather_random): here; call it. (egd_socket): New variable. (egd_gather_random): Initialize fd with egd_socket, do not declare fd static. (do_read): Merged few changes from GnuPG. FIXME - not finished? Do not include "dynload.h". * rndw32.c (gather_random): Renamed to rndw32_gather_random, do not declare static. (gather_random_fast): Renamed to rndw32_gather_random_fast, do not declare static. * rndunix.c (gather_random): Renamed to rndunix_gather_random, do not declare static. * rndegd.c (gather_random): Renamed to rndegd_gather_random, do not declare static. * rndlinux.c (gather_random): Renamed to rndlinux_gather_random, do not declare static. 2003-04-07 Moritz Schulte * Makefile.am (libcipher_la_SOURCES): Removed construct.c. (libcipher_la_SOURCES): Added sha1.c, sha256.c, rmd160.c, md4.c, md5.c, tiger.c and crc.c (EXTRA_PROGRAMS): Removed sha1, sha256, rmd160, md4, md5, tiger and crc. Removed definitions: EXTRA_md4_SOURCES, EXTRA_md5_SOURCES, EXTRA_rmd160_SOURCES, EXTRA_sha1_SOURCES, EXTRA_sha256_SOURCES, EXTRA_tiger_SOURCES and EXTRA_crc_SOURCES, BUILT_SOURCES, DISTCLEANFILES. * pubkey.c: Do not include "elgamal.h", "dsa.h" and "rsa.h". * Makefile.am (libcipher_la_SOURCES): Removed rsa.h, elgamal.h, dsa.h, des.h, cast5.h, arcfour.h and blowfish.h. * rsa.h: Removed file. * elgamal.h: Removed file. * dsa.h: Removed file. * des.h: Removed file. * cast5.h: Removed file. * arcfour.h: Removed file. * blowfish.h: Removed file. * Makefile.am (libcipher_la_SOURCES): Removed dynload.c and dynload.h. * rsa.c (pubkey_spec_rsa): New variable. * dsa.c (pubkey_spec_rsa): New variable. * elgamal.c (pubkey_spec_elg): New variable. * rsa.c (_gcry_rsa_get_info): Removed function. * elgamal.c (_gcry_elg_get_info): Removed function. * dsa.c (_gcry_dsa_get_info): Removed function. * tiger.c (tiger_get_info): Removed function. (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_tiger_constructor): Removed function. * sha1.c (sha1_get_info): Removed function. (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_sha1_constructor): Removed function. * sha256.c (sha256_get_info): Removed function. (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_sha256_constructor): Removed function. * rmd160.c (rmd160_get_info): Removed function. (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_rmd160_constructor): Removed function. * md5.c (md5_get_info): Removed function. (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_md5_constructor): Removed function. * md4.c (md4_get_info): Removed function. (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func): Removed function. (_gcry_md4_constructor): Removed function. * crc.c (crc_get_info): Removed function. * arcfour.c (do_arcfour_setkey): Changed type of context argument to `void *', added local variable for cast, adjusted callers. (arcfour_setkey): Likewise. (encrypt_stream): Likewise. * cast5.c (cast_setkey): Likewise. (encrypt_block): Likewise. * rijndael.c (rijndael_setkey): Likewise. (rijndael_encrypt): Likewise. (rijndael_decrypt): Likewise. * twofish.c (twofish_setkey): Likewise. (twofish_encrypt): Likewise. (twofish_decrypt): Likewise. * des.c (do_des_setkey): Likewise. (do_des_encrypt): Likewise. (do_des_encrypt): Likewise. (do_tripledes_encrypt): Likewise. (do_tripledes_encrypt): Likewise. * blowfish.c (bf_setkey: Likewise. (encrypt_block): Likewise. (decrypt_block): Likewise. * arcfour.c (encrypt_stream): Likewise. * rijndael.c (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func) Removed function. * twofish.c (gnupgext_version, func_table): Removed definitions. (gnupgext_enum_func) Removed function. * cast5.c (CIPHER_ALGO_CAST5): Removed. * blowfish.c (FNCCAST_SETKEY, FNCCAST_CRYPT): Removed macros. (CIPHER_ALGO_BLOWFISH): Removed symbol. * cast5.c (FNCCAST_SETKEY, FNCCAST_CRYPT): Likewise. * des.c (selftest_failed): Removed. (initialized): New variable. (do_des_setkey): Run selftest, if not yet done. (FNCCAST_SETKEY, FNCCAST_CRYPT): Removed macros. * arcfour.c (_gcry_arcfour_get_info): Removed function. * blowfish.c (_gcry_blowfish_get_info): Removed function. * cast5.c (_gcry_cast5_get_info): Removed function. * des.c (_gcry_des_get_info): Removed function. * rijndael.c (_gcry_rijndael_get_info): Removed function. * twofish.c (_gcry_twofish_get_info): Removed function. * arcfour.c (cipher_spec_arcfour): New variable. * twofish.c (cipher_spec_twofish, cipher_spec_twofish128): New variables. * rijndael.c (cipher_spec_aes, cipher_spec_aes192, cipher_spec256): New variables. * des.c (cipher_spec_des, cipher_spec_tripledes): New variables. * cast5.c (cipher_spec_cast5): New variable. * blowfish.c (cipher_spec_blowfish): Likewise. * twofish.c: Do not include "dynload.h". * rijndael.c: Likewise. * des.c: Likewise. * cast5.c: Likewise. * blowfish.c: Likewise. * cipher.c: Likewise. * crc.c: Likewise. * md4.c: Likewise. * md5.c: Likewise. * md.c: Likewise. * pubkey.c: Likewise. * rijndael.c: Likewise. * sha1.c: Likewise. * sha256.c: Likewise. * arcfour.c: Include "cipher.h". * twofish.c: Likewise. * rijndael.c: Likewise. * des.c: Likewise. * cast5.c: Likewise. * blowfish.c: Likewise. * twofish.c (twofish_setkey): Declared argument `key' const. (twofish_encrypt): Declared argument `inbuf' const. (twofish_decrypt): Likewise. * rijndael.c (rijndael_setkey): Declared argument `key' const. (rijndael_encrypt): Declared argument `inbuf' const. (rijndael_decrypt): Likewise. * des.c (do_des_setkey): Declared argument `key' const. (do_tripledes_setkey): Likewise. (do_des_encrypt): Declared argument `inbuf' const. (do_des_decrypt): Likewise. (do_tripledes_encrypt): Likewise. (do_tripledes_decrypt): Likewise. * cast5.c (encrypt_block): Declared argument `inbuf' const. (decrypt_block): Likewise. (cast_setkey): Declared argument `key' const. * blowfish.c (do_bf_setkey): Declared argument `key' const. (encrypt_block): Declared argument `inbuf' const. (encrypt_block): Likewise. * cipher.c: Remove CIPHER_ALGO_DUMMY related code. Removed struct cipher_table_s. Changed definition of cipher_table. Removed definition of disabled_algos. (ciphers_registered, default_ciphers_registered): New variables. (REGISTER_DEFAULT_CIPHERS): New macro. (dummy_setkey): Declared argument `key' const. (dummy_encrypt_block): Declared argument `inbuf' const. (dummy_encrypt_block): Likewise. (dummy_encrypt_stream): Likewise. (dummy_encrypt_stream): Likewise. (dummy_setkey): Use `unsigned char' instead of `byte'. (dummy_encrypt_block): Likewise. (dummy_decrypt_block): Likewise. (dummy_encrypt_stream): Likewise. (dummy_decrypt_stream): Likewise. (gcry_cipher_register_default): New function. (gcry_cipher_lookup_func_id): New function. (gcry_cipher_lookup_func_name): New function. (gcry_cipher_lookup_id): New function. (gcry_cipher_lookup_name): New function. (gcry_cipher_id_new): New function. (gcry_cipher_register): New function. (gcry_cipher_unregister): New function. (setup_cipher_table): Removed function. (load_cipher_modules): Removed function. (gcry_cipher_map_name): Adjusted to use new module management. (cipher_algo_to_string): Likewise. (disable_cipher_algo): Likewise. (check_cipher_algo): Likewise. (cipher_get_keylen): Likewise. (cipher_get_blocksize): Likewise. (gcry_cipher_open): Likewise. (struct gcry_cipher_handle): Replaced members algo, algo_index, blocksize, setkey, encrypt, decrypt, stencrypt, stdecrypt with one member: cipher. (gcry_cipher_open): Adjusted code for new handle structure. (cipher_setkey): Likewise. (cipher_setiv): Likewise. (cipher_reset): Likewise. (do_ecb_encrypt): Likewise. (do_ecb_decrypt): Likewise. (do_cbc_encrypt): Likewise. (do_cbc_decrypt): Likewise. (do_cfb_encrypt): Likewise. (do_cfb_decrypt): Likewise. (do_ctr_encrypt): Likewise. (cipher_encrypt): Likewise. (gcry_cipher_encrypt): Likewise. (cipher_decrypt): Likewise. (gcry_cipher_decrypt): Likewise. (cipher_sync): Likewise. (gcry_cipher_ctl): Likewise. * pubkey.c: Removed struct pubkey_table_s. Changed definition of pubkey_table. Removed definition of disabled_algos. (pubkeys_registered, default_pubkeys_registered): New variables. (REGISTER_DEFAULT_PUBKEYS): New macro. (setup_pubkey_table): Removed function. (load_pubkey_modules): Removed function. (gcry_pubkey_register_default): New function. (gcry_pubkey_lookup_func_id): New function. (gcry_pubkey_lookup_func_name): New function. (gcry_pubkey_lookup_id): New function. (gcry_pubkey_lookup_name): New function. (gcry_pubkey_id_new): New function. (gcry_pubkey_register): New function. (gcry_pubkey_unregister): New function. (gcry_pk_map_name): Adjusted to use new module management. (gcry_pk_algo_name): Likewise. (disable_pubkey_algo): Likewise. (check_pubkey_algo): Likewise. (pubkey_get_npkey): Likewise. (pubkey_get_nskey): Likewise. (pubkey_get_nsig): Likewise. (pubkey_get_nenc): Likewise. (pubkey_generate): Likewise. (pubkey_check_secret_key): Likewise. (pubkey_encrypt): Likewise. (pubkey_decrypt): Likewise. (pubkey_sign): Likewise. (pubkey_verify): Likewise. (gcry_pk_get_nbits): Likewise. (gcry_pk_algo_info): Likewise. * md.c: Removed struct md_digest_list_s. (digest_list): Changed definition. (digests_registered, default_digests_registered): New variables. (REGISTER_DEFAULT_DIGESTS): New macro. (new_list_item): Removed function. (setup_md_table): Removed function. (load_digest_module): Removed function. (gcry_digest_register_default): New function. (gcry_digest_lookup_func_id): New function. (gcry_digest_lookup_func_name): New function. (gcry_digest_lookup_id): New function. (gcry_digest_lookup_name): New function. (gcry_digest_id_new): New function. (gcry_digest_register): New function. (gcry_digest_unregister): New function. (GcryDigestEntry): New type. (struct gcry_md_context): Adjusted type of `list'. (gcry_md_map_name): Adjusted to use new module management. (digest_algo_to_string): Likewise. (check_digest_algo): Likewise. (md_enable): Likewise. (md_digest_length): Likewise. (md_asn_oid): Likewise. 2003-04-07 Moritz Schulte * pubkey.c: Replaced PUBKEY_ALGO_DSA with GCRY_PK_DSA, PUBKEY_ALGO_RSA with GCRY_PK_RSA and PUBKEY_ALGO_ELGAMAL with GCRY_PK_ELG. * dsa.c: Replaced PUBKEY_ALGO_DSA with GCRY_PK_DSA. 2003-04-01 Moritz Schulte * des.c: Removed checks for GCRY_CIPHER_3DES and GCRY_CIPHER_DES. 2003-03-31 Moritz Schulte * tiger.c (tiger_get_info): Do not declare static. * sha256.c (sha256_get_info): Likewise. * sha1.c (sha1_get_info): Likewise. * rmd160.c (rmd160_get_info): Likewise. * md5.c (md5_get_info): Likewise. * md4.c (md4_get_info): Likewise. * crc.c (crc_get_info): Likewise. * md.c (load_digest_module): Call setup_md_table during initialization. (new_list_item): Link new element into digest_list. * cipher.c (do_ctr_decrypt): Made do_ctr_encrypt act as a wrapper for do_ctr_encrypt, since these functions are identical. 2003-03-30 Simon Josefsson * cipher.c (struct gcry_cipher_handle): Add counter field. (gcry_cipher_open): Add CTR. (cipher_reset): Clear counter field. (do_ctr_encrypt, do_ctr_decrypt): New functions. (cipher_encrypt, cipher_decrypt): Call CTR functions. (gcry_cipher_ctl): Add SET_CTR to set counter. 2003-03-30 Moritz Schulte * rsa.c (_gcry_rsa_blind): New function. (_gcry_rsa_unblind): New function. (_gcry_rsa_decrypt): Use _gcry_rsa_blind and _gcry_rsa_decrypt. 2003-03-26 Moritz Schulte * dynload.c (_gcry_enum_gnupgext_pubkeys): Adjust `encrypt' and `decrypt' function arguments. (_gcry_enum_gnupgext_pubkeys): Likewise. * dynload.h: Likewise. * pubkey.c (dummy_decrypt): Add argument: int flags. (dummy_encrypt): Likewise. * elgamal.c (_gcry_elg_encrypt): Add argument: int flags. (_gcry_elg_decrypt): Likewise. * rsa.c (_gcry_rsa_encrypt): Add argument: int flags. (_gcry_rsa_decrypt): Likewise. * pubkey.c: Add `flags' argument to members `encrypt' and `decrypt' of struct `pubkey_table_s'. * rsa.h: Add `flags' argument to function declarations. * elgamal.h: Likewise. * pubkey.c (sexp_data_to_mpi): New variable: int parsed_flags. (sexp_data_to_mpi): Set `parsed_flags'. (sexp_data_to_mpi): New argument: int *flags. (gcry_pk_encrypt): New variable: int flags. (gcry_pk_encrypt): Pass `flags' to pubkey_encrypt. (pubkey_encrypt): New variable: int flags. (pubkey_encrypt): Pass `flags' to pubkey encrypt function. (pubkey_decrypt): Likewise. (pubkey_decrypt): Pass `flags' to pubkey encrypt function. (gcry_pk_encrypt): Include `flags' s-exp in return list. (sexp_to_enc): New argument: int *flags. (gcry_pk_decrypt): New variable: int flags. (gcry_pk_decrypt): Pass `flags' to pubkey_decrypt. (sexp_to_enc): New variable: int parsed_flags. (sexp_to_enc): Set `parsed_flags'. 2003-03-22 Simon Josefsson * cipher.c (gcry_cipher_open, do_cbc_encrypt) (gcry_cipher_encrypt): Support GCRY_CIPHER_CBC_MAC. (gcry_cipher_ctl): Support GCRYCTL_SET_CBC_MAC. 2003-03-19 Werner Koch * primegen.c (gen_prime): New args EXTRA_CHECK and EXTRA_CHECK_ARG to allow for a user callback. Changed all callers. (_gcry_generate_secret_prime) (_gcry_generate_public_prime): Ditto, pass them to gen_prime. * rsa.c (check_exponent): New. (generate): Use a callback to ensure that a given exponent is actually generated. 2003-03-12 Moritz Schulte * primegen.c: Initialize `no_of_small_prime_numbers' statically. (gen_prime): Remove calculation of `no_of_small_prime_numbers'. 2003-03-03 Moritz Schulte * md.c (gcry_md_ctl): Rewritten to use same style like the other functions dispatchers. 2003-03-02 Moritz Schulte * cipher.c (struct gcry_cipher_handle): New member: algo_index. (gcry_cipher_open): Allocate memory for two cipher contexts. Initialize algo_index. (cipher_setkey): Duplicate context into reserved memory. (cipher_reset): New function, which resets the context and clear the IV. (gcry_cipher_ctl): Call cipher_reset. 2003-02-23 Moritz Schulte * cipher.c: Remove (bogus) `digitp' macro definition. * md.c: Likewise. * blowfish.c (burn_stack): Removed. * arcfour.c (burn_stack): Likewise. * cast5.c (burn_stack): Likewise. * des.c (burn_stack): Likewise. * md4.c (burn_stack): Likewise. * md5.c (burn_stack): Likewise. * random.c (burn_stack): Likewise. * rijndael.c (burn_stack): Likewise. * rmd160.c (burn_stack): Likewise. * sha1.c (burn_stack): Likewise. * sha256.c (burn_stack): Likewise. * tiger.c (burn_stack): Likewise. * twofish.c (burn_stack): Likewise. * blowfish.c: Changed all occurences of burn_stack to _gcry_burn_stack. * arcfour.c: Likewise. * cast5.c: Likewise. * des.c: Likewise. * md4.c: Likewise. * md5.c: Likewise. * random.c: Likewise. * rijndael.c: Likewise. * rmd160.c: Likewise. * sha1.c: Likewise. * sha256.c: Likewise. * tiger.c: Likewise. * twofish.c: Likewise. * arcfour.c (_gcry_arcfour_get_info): Use GCRY_CIPHER_ARCFOUR instead of hard-coded value `301'. 2003-01-24 Werner Koch * random.c (_gcry_register_random_progress): New. (_gcry_random_progress): New. * rndlinux.c (gather_random): Call the random progress function. 2003-01-23 Werner Koch * rsa.c (generate): New arg USE_E to request a specific public exponent. (_gcry_rsa_generate): Ditto. * elgamal.c (_gcry_elg_generate): Must add an dummy argument instead of USE_E. * dsa.c (_gcry_dsa_generate): Ditto. * pubkey.c (dummy_generate): Ditto. (pubkey_generate): Add USE_E arg and pass it down. (gcry_pk_genkey): Detect "rsa-use-e" parameter and pass it to generate. * pubkey.c (sexp_to_enc): New arg RET_MODERN. (gcry_pk_decrypt): Make use of it to return a real S-expression. Return better error codes. (gcry_pk_verify): Return better error codes. 2003-01-21 Werner Koch * random.c (gcry_random_add_bytes): Add QUALITY argument, let function return an error code and disable its core for now. 2003-01-21 Timo Schulz * random.c (gcry_random_add_bytes): New. Function to add external random to the pool. 2003-01-20 Simon Josefsson * crc.c: New. * Makefile.am (EXTRA_PROGRAMS, EXTRA_crc_SOURCES): Add crc.c. * md.c (gcry_md_get_algo_dlen): Add values for CRC. 2003-01-20 Werner Koch * sha256.c: New. * bithelp.h (ror): New. * Makfile.am: Add sha256.c. * md.c (oid_table): Add values for SHA256 et al. (gcry_md_get_algo_dlen): Likewise 2003-01-20 Werner Koch * pubkey.c (gcry_pk_get_keygrip): Implemented keygrips for DSA and ElGamal. 2003-01-17 Werner Koch * cipher.c (gcry_cipher_encrypt): Reworked so that the output will never contain the plaintext even if the caller did not checked the return value. * md.c (gcry_md_get_algo): Changed error code to GCRYERR_GENERAL because we don't have an invalid md algo but no algorithm enabled. * pubkey.c (gcry_pk_genkey): Changed error code for bounds check of table parameters to GCRYERR_INTERNAL. * md.c (gcry_md_open): Partly reverted Timo's change from 2002-10-10 by removing the check for the algorithm. An algorithm of 0 is allowed and anyway we should not double check it or check it using a different function. Also fixed the flags check. * pubkey.c (gcry_pk_encrypt): Make sure that R_CIPH points to NULL on error. (gcry_pk_decrypt): Ditto for R_PLAIN. (gcry_pk_sign): Ditto for R_SIG. (gcry_pk_genkey): Ditto for R_KEY. 2003-01-16 Werner Koch * md.c (gcry_md_write): Changed 2nd argument type to void*. (gcry_md_hash_buffer): Changed type of boths buffers to void*. (gcry_md_setkey): Changed 2nd argument type to void*. 2003-01-15 Werner Koch * pubkey.c (sexp_data_to_mpi): New. This handles pkcs1 padding. (gcry_pk_sign, gcry_pk_verify): Use it here. (gcry_pk_encrypt): And here. (pubkey_verify): Add debug code. (sexp_to_enc): Handle flags in the input and return the pkcs1 flag in a new parameter. (gcry_pk_decrypt): Prepare for future pkcs1 handling. 2002-12-19 Werner Koch * random.c (_gcry_random_initialize): New. 2002-12-16 Werner Koch * cipher.c: Added a Teletrust specific OID for 3DES. 2002-12-12 Werner Koch * md.c: Added another oddball OIW OID (sha-1WithRSAEncryption). 2002-11-23 Werner Koch * md.c (load_digest_module): Enlarged checked_algos bitmap. * md4.c (func_table): Fixed entry for md4. Both by Simon Josephson. (transform): Copy data to get the alignment straight. Tested only on i386. 2002-11-10 Simon Josefsson * cipher.c (gcry_cipher_open): Don't reject CTS flag. (do_cbc_encrypt, do_cbc_decrypt, cipher_encrypt) (gcry_cipher_encrypt, cipher_decrypt) (gcry_cipher_decrypt): Support CTS flag. (gcry_cipher_ctl): Toggle CTS flag. 2002-11-10 Werner Koch * md4.c: New. By Simon Josefsson. * Makefile.am (EXTRA_PROGRAMS): Add md4.c. * md.c (oid_table,gcry_md_get_algo_dlen): MD4 support. 2002-10-14 Werner Koch * arcfour.c (do_encrypt_stream): Don't use increment op when assigning to the same variable. 2002-10-10 Timo Schulz * pubkey.c (gcry_pk_genkey): Check boundaries. * md.c (gcry_md_open): Check that algo is available and only valid flag values are used. (gcry_md_get_algo): Add error handling. 2002-09-26 Werner Koch * md.c: Include an OID for TIGER. * tiger.c (tiger_get_info): Use a regular OID. 2002-09-17 Werner Koch * random.c: Replaced mutex.h by the new ath.h. Changed all calls. 2002-09-16 Werner Koch * arcfour.c (do_encrypt_stream): Use register modifier and modulo. According to Nikos Mavroyanopoulos this increases perfromace on i386 system noticable. And I always tought gcc is clever enough. * md5.c (transform): Use register modifier. * rmd160.c (transform): Ditto. * sha1.c (transform): Ditto. We hope that there are 6 free registers. * random.c (gcry_randomize): Rewrote to avoid malloc calls. * rndlinux.c (gather_random): Replaced remaining fprintfs by log_*. * arcfour.c (do_arcfour_setkey): Ditto. * twofish.c (do_twofish_setkey): Ditto. * rndegd.c (gather_random): Ditto. * rijndael.c (do_setkey): Ditto. * random.c (_gcry_random_dump_stats): Ditto. * primegen.c (_gcry_generate_elg_prime): Ditto. * des.c (_gcry_des_get_info): Ditto. * cast5.c (do_cast_setkey): Ditto. * blowfish.c (do_bf_setkey): Ditto. 2002-08-26 Werner Koch * des.c (weak_keys): Fixed one entry in the table and compared all entries against the literature. (selftest): Checksum the weak key table. 2002-08-21 Werner Koch * pubkey.c: Enable keygrip calculation for "openpgp-rsa". 2002-08-17 Werner Koch * cipher.c (setup_cipher_table): Don't overwrite the DES entry with the entry for DUMMY. 2002-08-14 Werner Koch * des.c (do_des_setkey,do_des_encrypt, do_des_decrypt): New. (_gcry_des_get_info): Support plain old DES. * cipher.c (setup_cipher_table): Put DES into the table. 2002-07-25 Werner Koch * rndunix.c (_gcry_rndunix_constructor): Prefixed with _gcry_. Noted by Stephan Austermuehle. 2002-07-08 Timo Schulz * rndw32.c: Replaced the m_ memory functions with the real gcry_ functions. Renamed all g10_ prefixed functions to log_. 2002-06-12 Werner Koch * rsa.c (generate): Use e = 65537 for now. 2002-06-11 Werner Koch * pubkey.c (gcry_pk_get_keygrip): Allow a "protected-private-key". 2002-06-05 Timo Schulz * cipher.c (gcry_cipher_encrypt, gcry_cipher_decrypt): Check that the input size is a multiple of the blocksize. 2002-05-23 Werner Koch * md.c (oid_table): Add an rsadsi OID for MD5. 2002-05-21 Werner Koch * primegen.c, elgamal.c, dsa.c (progress): Do not print anything by default. Pass an extra identifying string to the callback and reserved 2 argumenst for current and total counters. Changed the register function prototype. 2002-05-17 Werner Koch * rndegd.c (rndegd_constructor): Fixed name of register function and prefixed the function name with _gcry_. * rndw32.c (rndw32_constructor): Ditto. * tiger.c (tiger_constructor): Ditto. * Makefile.am: Removed all dynamic loading stuff. * dynload.c: Ditto. Now only used for the constructor system. 2002-05-15 Werner Koch * random.c (gcry_random_bytes,gcry_random_bytes_secure) (gcry_randomize): Make sure we are initialized. 2002-05-14 Werner Koch Changed license of most files to the LGPL. 2002-05-02 Werner Koch * random.c (_gcry_fast_random_poll): Initialize the module so the mutex can be used. * primegen.c (small_prime_numbers): Moved table from smallprime.c * smallprime.c: File removed. * des.c (leftkey_swap, rightkey_swap, working_memcmp): Made static. * cipher.c (gcry_cipher_map_name): Map "RIJNDAEL" to "AES". * rijndael.c (rijndael_get_info): We do only support a 128 bit blocksize so it makes sense to change the algorithm strings to AES. * tiger.c (tiger_final): Removed superfluous token pasting operators. * md5.c (md5_final): Ditto. 2002-04-30 Werner Koch * cipher.c: Fixed list of copyright years. 2002-03-18 Werner Koch * random.c (initialize): Initialize the new pool lock mutex. (_gcry_fast_random_poll): Add locking and moved main code out to... (do_fast_random_poll): new function. (read_pool): Use the new function here. (get_random_bytes): Add locking. (_gcry_update_random_seed_file): Ditto. 2002-03-11 Werner Koch * md.c: Add rsaSignatureWithripemd160 to OID table. 2002-02-20 Werner Koch * sha1.c: Removed a left over comment note. The code has been rewritten from scratch in 1998. Thanks to Niels Möller for reporting this misleading comment. 2002-02-18 Werner Koch * rndunix.c (rndunix_constructor): Use the the new prefixed function name. Reported by Jordi Mallach. 2002-02-10 Werner Koch * random.c (mix_pool): Carry an extra failsafe_digest buffer around to make the function more robust. 2002-02-08 Werner Koch * random.c (add_randomness): Xor new data into the pool and not just copy it. This avoids any choosen input attacks which are not serious in our setting because an outsider won't be able to mix data in and even then we keep going with a PRNG. Thanks to Stefan Keller for pointing this out. 2002-01-04 Werner Koch * pubkey.c (gcry_pk_genkey): Do not release skey - it is static. * primegen.c (gen_prime): Of course we should use set_bit and not set_highbit to set the second high bit. 2001-12-18 Werner Koch * rsa.c (generate): Loop until we find the exact modulus size. Changed the exponent to 41. (rsa_get_info): s/usage/r_usage/ to avoid shadow warnings. * primegen.c (gen_prime): Set 2 high order bits for secret primes. * Makefile.am (DISTCLEANFILES): Include construct.c. 2001-12-17 Werner Koch * pubkey.c (gcry_pk_get_keygrip): New - experimental. 2001-12-11 Werner Koch * cipher.c: Added OIDs for AES. (gcry_cipher_mode_from_oid): New. (gcry_cipher_map_name): Moved OID search code to .. (search_oid): .. new function. 2001-12-10 Werner Koch * pubkey.c (gcry_pk_encrypt): Find the signature algorithm by name and not by number. * pubkey.c (gcry_pk_encrypt,gcry_pk_decrypt,gcry_pk_sign) (gcry_pk_verify,gcry_pk_testkey, gcry_pk_genkey) (gcry_pk_get_nbits): Release the arrays. Noted by Nikos Mavroyanopoulos. 2001-12-06 Werner Koch * cipher.c (gcry_cipher_map_name): Look also for OIDs prefixed with "oid." or "OID.". 2001-12-05 Werner Koch * pubkey.c (algo_info_table): Fixed entry for openpgp-rsa. 2001-11-24 Werner Koch * pubkey.c: Added the rsaEncryption OID to the tables. (sexp_to_key): Add an arg to return the index of the algorithm, changed all callers. (gcry_pk_sign): Find the signature algorithm by name and not by number. (gcry_pk_get_nbits): Fixed so that we can now really pass a secret key to get the result. * md.c (gcry_md_map_name): Look also for OIDs prefixed with "oid." or "OID." so that an OID string can be used as an S-Exp token. 2001-11-20 Werner Koch * md.c (gcry_md_map_name): Lookup by OID if the the name begins with a digit. (oid_table): New. 2001-11-16 Werner Koch * md.c (gcry_md_info): New operator GCRYCTL_IS_ALGO_ENABLED. 2001-11-07 Werner Koch * md.c (gcry_md_hash_buffer): Close the handle which was left open for algorithms other than rmd160. 2001-08-08 Werner Koch * rndw32.c (gather_random): Use toolhelp in addition to the NT gatherer for Windows2000. Suggested by Sami Tolvanen. * random.c (read_pool): Fixed length check, this used to be one byte to strict. Made an assert out of it because the caller has already made sure that only poolsize bytes are requested. Reported by Marcus Brinkmann. 2001-08-03 Werner Koch * cipher.c (cipher_encrypt, cipher_decrypt): Prepare to return errors. We have to change the interface to all ciphers to make this really work but we should do so to prepare for hardware encryption modules. (gcry_cipher_encrypt, gcry_cipher_decrypt): Return the error and set lasterr. (gcry_cipher_ctl): Make sure that errors from setkey are returned. 2001-08-02 Werner Koch * rndlinux.c (gather_random): casted a size_t arg to int so that the format string is correct. Casting is okay here and avoids translation changes. * random.c (fast_random_poll): Do not check the return code of getrusage. * rndunix.c: Add a signal.h header to avoid warnings on Solaris 7 and 8. * tiger.c (print_abc,print_data): Removed. * rijndael.c, des.c, blowfish.c, twofish.c, cast5.c, arcfour.c (burn_stack): New. Add wrappers for most functions to be able to call burn_stack after the function invocation. This methods seems to be the most portable way to zeroise the stack used. It does only work on stack frame based machines but it is highly portable and has no side effects. Just setting the automatic variables at the end of a function to zero does not work well because the compiler will optimize them away - marking them as volatile would be bad for performance. * md5.c, sha1.c, rmd160.c, tiger.c (burn_stack): Likewise. * random.c (burn_stack): New. (mix_pool): Use it here to burn the stack of the mixblock function. * primegen.c (_gcry_generate_elg_prime): Freed q at 3 places. Thanks to Tommi Komulainen. * arcfour.c (arcfour_setkey): Check the minimim keylength against bytes and not bits. (selftest): Must reset the key before decryption. 2001-05-31 Werner Koch * sha1.c (sha1_init): Made static. Changed all g10_ prefixed function names as well as some mpi_ function names to cope with the introduced naming changes. * md.c (prepare_macpads): Made key const. 2001-05-28 Werner Koch * rndegd.c (gather_random): Removed the use of tty_printf. 2001-03-29 Werner Koch * md5.c (md5_final): Fixed calculation of hashed length. Thanks to disastry@saiknes.lv for pointing out that it was horrible wrong for more than 512MB of input. * sha1.c (sha1_final): Ditto. * rmd160.c (rmd160_final): Ditto. * tiger.c (tiger_final): Ditto. * blowfish.c (encrypt,do_encrypt): Changed name to do_encrypt to avoid name clashes with an encrypt function in stdlib.h of Dynix/PIX. Thanks to Gene Carter. * elgamal.c (encrypt,do_encrypt): Ditto. * twofish.c (gnupgext_enum_func): Use only when when compiled as a module. * rijndael.c (gnupgext_enum_func): Ditto. * tiger.c (tiger_get_info): Return "TIGER192" and not just "TIGER". By Edwin Woudt. * random.c: Always include time.h - standard requirement. Thanks to James Troup. * rndw32.c: Fixes to the macros. 2001-01-11 Werner Koch * cipher.c (cipher_encrypt,gcry_cipher_encrypt): Use blocksize and not 8. 2000-12-19 Werner Koch Major change: Removed all GnuPG stuff and renamed this piece of software to gcrypt. 2000-11-14 Werner Koch * dsa.c (test_keys): Replaced mpi_alloc by gcry_mpi_new and mpi_free by gcry_mpi_release. * elgamal.c (test_keys,generate): Ditto, also for mpi_alloc_secure. * rsa.c (test_keys,generate,rsa_verify): Ditto. * primegen.c (generate_elg_prime): Ditto. (gen_prime): Ditto and removed nlimbs. * rsa.c (generate): Allocate 2 more vars in secure memory. * Makefile.am (OMIT_DEPENDENCIES): Hack to work around dependency problems. 2000-10-09 Werner Koch * arcfour.c, arcfour.h: New. * cipher.c (cipher_encrypt, cipher_decrypt): Add stream mode. (setup_cipher_table): Add Arcfour. (gcry_cipher_open): Kludge to allow stream mode. Wed Oct 4 13:16:18 CEST 2000 Werner Koch * sha1.c (transform): Use rol() macro. Actually this is not needed for a newer gcc but there are still aoter compilers. * rsa.c (test_keys): Use new random function. * md.c (gcry_md_setkey): New function to overcome problems with const conflics. (gcry_md_ctl): Pass set key to the new functions. * rijndael.c: New. * cipher.c: Add Rijndael support. Mon Sep 18 16:35:45 CEST 2000 Werner Koch * rndlinux.c (open_device): Loose random device checking. By Nils Ellmenreich. * random.c (fast_random_poll): Check ENOSYS for getrusage. * rndunix.c: Add 2 sources for QNX. By Sam Roberts. * pubkey.c (gcry_pk_algo_info): Add GCRYCTL_GET_ALGO_USAGE. * rsa.c: Changed the comment about the patent. (secret): Speed up by using the CRT. For a 2k keys this is about 3 times faster. (stronger_key_check): New but unused code to check the secret key. * Makefile.am: Included rsa.[ch]. * pubkey.c: Enabled RSA support. (pubkey_get_npkey): Removed RSA workaround. Mon Jul 31 10:04:47 CEST 2000 Werner Koch * pubkey.c: Replaced all gcry_sexp_{car,cdr}_{data,mpi} by the new gcry_sexp_nth_{data,mpi} functions. Tue Jul 25 17:44:15 CEST 2000 Werner Koch * pubkey.c (exp_to_key,sexp_to_sig,sexp_to_enc,gcry_pk_encrypt, gcry_pk_decrypt,gcry_pk_sign,gcry_pk_genkey): Changed to work with the new S-Exp interface. Mon Jul 17 16:35:47 CEST 2000 Werner Koch * random.c (gather_faked): Replaced make_timestamp by time(2) again. Fri Jul 14 19:38:23 CEST 2000 Werner Koch * md.c (gcry_md_ctl): Support GCRYCTL_{START,STOP}_DUMP. * Makefile.am: Never compile mingw32 as module. * Makefile.am: Tweaked module build and removed libtool * Makefile.am: Replaced -O1 by -O. Suggested by Alec Habig. * elgamal.c (sign): Removed inactive code. * rsa.c, rsa.h: New based on the old module version (only in CVS for now). * pubkey.c (setup_pubkey_table): Added commented support for RSA. * rndunix.c (waitpid): New. For UTS 2.1. All by Dave Dykstra. (my_popen): Do the FD_CLOEXEC only if it is available (start_gatherer): Cope with missing _SC_OPEN_MAX * rndunix.c: Add some more headers for QNX. By Sam Roberts. * rndegd.c (gather_random): Shortcut level 0. * rndunix.c (gather_random): Ditto. * rndw32.c (gather_random): Ditto. * rndw32.c: Replaced with code from Cryptlib and commented the old stuff. * rndw32.c: Add some debuging code enabled by an environment variable. * random.c (read_seed_file): Binary open for DOSish system (update_random_seed_file): Ditto. * random.c [MINGW32]: Include process.h for getpid. * random.c (fast_random_poll): Add clock_gettime() as fallback for system which support this POSIX.4 fucntion. By Sam Roberts. * random.c (read_seed_file): Removed the S_ISLNK test becuase it is already covered by !S_ISREG and is not defined in Unixware. Reported by Dave Dykstra. (update_random_seed_file): Silently ignore update request when pool is not filled. * random.c (read_seed_file): New. (set_random_seed_file): New. (read_pool): Try to read the seeding file. (update_random_seed_file): New. (read_pool): Do an initial extra seeding when level 2 quality random is requested the first time. This requestes at least POOLSIZE/2 bytes of entropy. Compined with the seeding file this should make normal random bytes cheaper and increase the quality of the random bytes used for key generation. * random.c (read_pool): Print a more friendly error message in cases when too much random is requested in one call. * random.c (fast_random_poll): Check whether RUSAGE_SELF is defined; this is not the case for some ESIX and Unixware, although they have getrusage(). * primegen.c (generate_elg_prime): All primes are now generated with the lowest random quality level. Because they are public anyway we don't need stronger random and by this we do not drain the systems entropy so much. * primegen.c (register_primegen_progress): New. * dsa.c (register_pk_dsa_progress): New. * elgamal.c (register_pk_elg_progress): New. * elgamal.c (wiener_map): New. (gen_k): Use a much smaller k. (generate): Calculate the qbits using the wiener map and choose an x at a size comparable to the one choosen in gen_k * rmd160.c (rmd160_get_info): Moved casting to the left side due to a problem with UTS4.3. Suggested by Dave Dykstra. * sha1.c (sha1_get_info): Ditto. * tiger.c (tiger_get_info): Ditto. * md5.c (md5_get_info): Ditto * des.c (des_get_info): Ditto. * blowfish.c (blowfish_get_info): Ditto. * cast5.c (cast5_get_info): Ditto. * twofish.c (twofish_get_info): Ditto. Fri Mar 24 11:25:45 CET 2000 Werner Koch * md.c (md_open): Add hmac arg and allocate space for the pads. (md_finalize): Add HMAC support. (md_copy): Ditto. (md_close): Ditto. (gcry_md_reset): Ditto. (gcry_md_ctl): Ditto. (prepare_macpdas): New. Mon Mar 13 19:22:46 CET 2000 Werner Koch * md.c (gcry_md_hash_buffer): Add support for the other algorithms. Mon Jan 31 16:37:34 CET 2000 Werner Koch * genprime.c (generate_elg_prime): Fixed returned factors which never worked for non-DSA keys. Thu Jan 27 18:00:44 CET 2000 Werner Koch * pubkey.c (sexp_to_key): Fixed mem leaks in case of errors. Mon Jan 24 22:24:38 CET 2000 Werner Koch * pubkey.c (gcry_pk_decrypt): Implemented. (gcry_pk_encrypt): Implemented. (gcry_pk_testkey): New. (gcry_pk_genkey): New. (pubkey_decrypt): Made static. (pubkey_encrypt): Ditto. (pubkey_check_secret_key): Ditto. (pubkey_generate): Ditto. Mon Jan 24 13:04:28 CET 2000 Werner Koch * pubkey.c (pubkey_nbits): Removed and replaced by ... (gcry_pk_get_nbits): this new one. Wed Dec 8 21:58:32 CET 1999 Werner Koch * dsa.c: s/mpi_powm/gcry_mpi_powm/g * elgamal.c: Ditto. * primegen.c: Ditto. * : Replaced g10_opt_verbose by g10_log_verbosity(). * Makefile.am (INCLUDES): removed intl, add ../gcrypt Fri Nov 19 17:15:20 CET 1999 Werner Koch * dynload.c (cmp_filenames): New to replaced compare_filename() in module. (register_cipher_extension): Removed the tilde expansion stuff. * rndeg.c (my_make_filename): New. * : Replaced header util.h by g10lib.h * random.c (gather_faked): Replaced make_timestamp by time(2). Disabled wrning printed with tty_printf. * rndlinux.c (gather_random): Always use fprintf instead of tty_xxx; this should be replaced by a callback function. * primegen.c (gen_prime): Use gcry_mpi_randomize. (is_prime): Ditto. * elgamal.c (test_keys): Ditto. * dsa.c (test_keys): Ditto. * cipher.c (gcry_cipher_close): Die on invalid handle. Mon Nov 15 21:36:02 CET 1999 Werner Koch * elgamal.c (gen_k): Use the new random API. (generate): Ditto. * dsa.c (gen_k): Ditto. (generate): Ditto. Sat Nov 13 17:44:23 CET 1999 Werner Koch * pubkey.c (disable_pubkey_algo): Made static. (gcry_pk_ctl): New. * random.c (get_random_bits): Renamed to ... (get_random_bytes): ... this and made static. (gcry_random_bytes): New. (gcry_random_bytes_secure): New. (randomize_buffer): Renamed to ... (gcry_randomize): ...this. * md.c (gcry_md_hash_buffer): New. * pubkey.c (gcry_pk_algo_info): 4 new commands. (pubkey_get_npkey): Made static. (pubkey_get_nskey): Made static. (pubkey_get_nsig): Made static. (pubkey_get_nenc): Made static. * pubkey.c: Removed all G10ERR_xxx. * cipher.c: Changed all GCRYERR_INV_ALGO to GCRYERR_INV_CIPHER_ALGO. * md.c: Changed all GCRYERR_INV_ALGO to GCRYERR_INV_MD_ALGO. * cast5.c (cast_setkey): Changed errocodes to GCRYERR_xxx. * blowfish.c: Ditto. * des.c: Ditto. * twofish.c: Ditto. * dsa.c: Ditto. * elgamal.c: Ditto. * g10c.c: Removed * cipher.c (gcry_cipher_open): Replaced alloc functions and return NULL if we are out of core. * dynload.c: Replaced all memory allocation functions. * md.c: Ditto. * primegen.c: Ditto. * pubkey.c: Ditto. * random.c: Ditto. * rndw32.c: Ditto. * elgamal.c: Ditto. * dsa.c: Ditto. Tue Oct 26 14:10:21 CEST 1999 Werner Koch * elgamal.c (sign): Hugh found strange code here. Replaced by BUG(). * cipher.c: Merged with gcrypt/symapi.c. * pubkey.c (string_to_pubkey_algo): Renamed function to ... (gcry_pk_map_name): ... this. (pubkey_algo_to_string): Renamed function to ... (gcry_pk_algo_name): ... this. (gcry_pk_algo_info): New. * pubkey.c: Merged with gcrypt/pkapi.c. * md.c (md_reset): Clear finalized; thanks to Ulf Moeller for fixing this bug. * md.c: Merged with gcrypt/mdapi.c Wed Sep 15 14:39:59 CEST 1999 Michael Roth * des.c: Various speed improvements: One bit pre rotation trick after initial permutation (Richard Outerbridge). Finished test of SSLeay Tripple-DES patterns. Wed Sep 15 16:22:17 CEST 1999 Werner Koch * rndw32.c: New. Mon Sep 13 10:51:29 CEST 1999 Werner Koch * bithelp.h: New. * rmd160.h, sha1.h, md5.h: Use the rol macro from bithelp.h Tue Sep 7 16:23:36 CEST 1999 Werner Koch * Makefile.am: Fixed seds for latest egcc. By Ollivier Robert. Mon Sep 6 19:59:08 CEST 1999 Werner Koch * des.c (selftest): Add some testpattern Mon Aug 30 20:38:33 CEST 1999 Werner Koch * cipher.c (do_cbc_encrypt): Fixed serious bug occuring when not using in place encryption. Pointed out by Frank Stajano. Mon Jul 26 09:34:46 CEST 1999 Werner Koch * md5.c (md5_final): Fix for a SCO cpp bug. Thu Jul 15 10:15:35 CEST 1999 Werner Koch * elgamal.c (elg_check_secret_key,elg_encrypt elg_decrypt,elg_sign,elg_verify): Sanity check on the args. * dsa.c (dsa_check_secret_key,dsa_sign,dsa_verify): Ditto. * pubkey.c (disable_pubkey_algo): New. (check_pubkey_algo2): Look at disabled algo table. * cipher.c (disable_cipher_algo): New. (check_cipher_algo): Look at disabled algo table. Wed Jul 7 13:08:40 CEST 1999 Werner Koch * Makefile.am: Support for libtool. Fri Jul 2 11:45:54 CEST 1999 Werner Koch * dsa.c (gen_k): Changed algorithm to consume less random bytes * elgamal.c (gen_k): Ditto. * random.c (random_dump_stats): New. Thu Jul 1 12:47:31 CEST 1999 Werner Koch * primegen.c, elgamal.c, dsa.c (progess): New and replaced all fputc with a call to this function. Sat Jun 26 12:15:59 CEST 1999 Werner Koch * rndegd.c (do_write): s/ssize_t/int/ due to SunOS 4.1 probs. * cipher.c (do_cbc_encrypt, do_cbc_decrypt): New. * dynload.c (HAVE_DL_SHL_LOAD): Map hpux API to dlopen (Dave Dykstra). * Makefile.am (install-exec-hook): Removed. Sun May 23 14:20:22 CEST 1999 Werner Koch * cipher.c (setup_cipher_table): Enable Twofish * random.c (fast_random_poll): Disable use of times() for mingw32. Mon May 17 21:54:43 CEST 1999 Werner Koch * dynload.c (register_internal_cipher_extension): Minor init fix. Tue May 4 15:47:53 CEST 1999 Werner Koch * primegen.c (gen_prime): Readded the Fermat test. Fixed the bug that we didn't correct for step when passing the prime to the Rabin-Miller test which led to bad performance (Stefan Keller). (check_prime): Add a first Fermat test. Sun Apr 18 10:11:28 CEST 1999 Werner Koch * cipher.c (cipher_setiv): Add ivlen arg, changed all callers. * random.c (randomize_buffer): alway use secure memory because we can't use m_is_secure() on a statically allocated buffer. * twofish.c: Replaced some macros by a loop to reduce text size. * Makefile.am (twofish): No more need for sed editing. Fri Apr 9 12:26:25 CEST 1999 Werner Koch * cipher.c (cipher_open): Reversed the changes for AUTO_CFB. * blowfish.c: Dropped the Blowfish 160 mode. * cipher.c (cipher_open): Ditto. (setup_cipher_table): Ditto. And removed support of twofish128 Wed Apr 7 20:51:39 CEST 1999 Werner Koch * random.c (get_random_bits): Can now handle requests > POOLSIZE * cipher.c (cipher_open): Now uses standard CFB for automode if the blocksize is gt 8 (according to rfc2440). * twofish.c: Applied Matthew Skala's patches for 256 bit key. Tue Apr 6 19:58:12 CEST 1999 Werner Koch * random.c (get_random_bits): Can now handle requests > POOLSIZE * cipher.c (cipher_open): Now uses standard CFB for automode if the blocksize is gt 8 (according to rfc2440). Sat Mar 20 11:44:21 CET 1999 Werner Koch * rndlinux.c (tty_printf) [IS_MODULE]: Removed. * rndegd.c (gather_random): Some fixes. Wed Mar 17 13:09:03 CET 1999 Werner Koch * rndegd.c (do_read): New. (gather_random): Changed the implementation. Mon Mar 8 20:47:17 CET 1999 Werner Koch * dynload.c (DLSYM_NEEDS_UNDERSCORE): Renamed. Fri Feb 26 17:55:41 CET 1999 Werner Koch * md.c: Nearly a total rewrote. Wed Feb 24 11:07:27 CET 1999 Werner Koch * cipher.c (context): Fixed alignment * md.c: Ditto. * rndegd.c: New Mon Feb 22 20:04:00 CET 1999 Werner Koch * rndegd.c: New. Wed Feb 10 17:15:39 CET 1999 Werner Koch * Makefile.am: Modules are now figured out by configure * construct.c: New. Generated by configure. Changed all modules to work with that. * sha1.h: Removed. * md5.h: Removed. * twofish.c: Changed interface to allow Twofish/256 * rndunix.c (start_gatherer): Die on SIGPIPE. Wed Jan 20 18:59:49 CET 1999 Werner Koch * rndunix.c (gather_random): Fix to avoid infinite loop. Sun Jan 17 11:04:33 CET 1999 Werner Koch * des.c (is_weak_key): Replace system memcmp due to bugs in SunOS's memcmp. (des_get_info): Return error on failed selftest. * twofish.c (twofish_setkey): Return error on failed selftest or invalid keylength. * cast5.c (cast_setkey): Ditto. * blowfish.c (bf_setkey): Return error on failed selftest. Tue Jan 12 11:17:18 CET 1999 Werner Koch * random.c (random_is_faked): New. * tiger.c: Only compile if we have the u64 type Sat Jan 9 16:02:23 CET 1999 Werner Koch * rndunix.c (gather_random): check for setuid. * Makefile.am: Add a way to staically link random modules Thu Jan 7 18:00:58 CET 1999 Werner Koch * md.c (md_stop_debug): Do a flush first. (md_open): size of buffer now depends on the secure parameter Sun Jan 3 15:28:44 CET 1999 Werner Koch * rndunix.c (start_gatherer): Fixed stupid ==/= bug 1998-12-31 Geoff Keating * des.c (is_weak_key): Rewrite loop end condition. Tue Dec 29 14:41:47 CET 1998 Werner Koch * random.c: add unistd.h for getpid(). (RAND_MAX): Fallback value for Sun. Wed Dec 23 17:12:24 CET 1998 Werner Koch * md.c (md_copy): Reset debug. Mon Dec 14 21:18:49 CET 1998 Werner Koch * random.c (read_random_source): Changed the interface to the random gathering function. (gather_faked): Use new interface. * dynload.c (dynload_getfnc_fast_random_poll): Ditto. (dynload_getfnc_gather_random): Ditto. * rndlinux.c (gather_random): Ditto. * rndunix.c (gather_random): Ditto. Sat Dec 12 18:40:32 CET 1998 Werner Koch * dynload.c (SYMBOL_VERSION): New to cope with system which needs underscores. * rndunix.c: Rewrote large parts Thu Dec 10 20:15:36 CET 1998 Werner Koch * dynload.c (load_extension): increased needed verbosity level. * random.c (fast_random_poll): Fallback to a default fast random poll function. (read_random_source): Always use the faked entroy gatherer if no gather module is available. * rndlinux.c (fast_poll): Removed. * rndunix.c (fast_poll): Removed. Wed Nov 25 12:33:41 1998 Werner Koch (wk@isil.d.shuttle.de) * rand-*.c: Removed. * rndlinux.c : New. * rndunix.c : New. * random.c : Restructured the interface to the gather modules. (intialize): Call constructor functions (read_radnom_source): Moved to here. * dynload.c (dynload_getfnc_gather_random): New. (dynload_getfnc_fast_random_poll): New. (register_internal_cipher_extension): New. (register_cipher_extension): Support of internal modules. Sun Nov 8 17:44:36 1998 Werner Koch (wk@isil.d.shuttle.de) * rand-unix.c (read_random_source): Removed the assert. Mon Oct 19 18:34:30 1998 me,,, (wk@tobold) * pubkey.c: Hack to allow us to give some info about RSA keys back. Thu Oct 15 11:47:57 1998 Werner Koch (wk@isil.d.shuttle.de) * dynload.c: Support for DLD Wed Oct 14 12:13:07 1998 Werner Koch (wk@isil.d.shuttle.de) * rand-unix.c: Now uses names from configure for /dev/random. 1998-10-10 SL Baur * Makefile.am: fix sed -O substitutions to catch -O6, etc. Tue Oct 6 10:06:32 1998 Werner Koch (wk@isil.d.shuttle.de) * rand-unix.c (HAVE_GETTIMEOFDAY): Fixed (was ..GETTIMEOFTIME :-) * rand-dummy.c (HAVE_GETTIMEOFDAY): Ditto. Mon Sep 28 13:23:09 1998 Werner Koch (wk@isil.d.shuttle.de) * md.c (md_digest): New. (md_reset): New. Wed Sep 23 12:27:02 1998 Werner Koch (wk@isil.d.shuttle.de) * tiger.c (TIGER_CONTEXT): moved "buf", so that it is 64 bit aligned. Mon Sep 21 06:22:53 1998 Werner Koch (wk@(none)) * des.c: Some patches from Michael. Thu Sep 17 19:00:06 1998 Werner Koch (wk@(none)) * des.c : New file from Michael Roth Mon Sep 14 11:10:55 1998 Werner Koch (wk@(none)) * blowfish.c (bf_setkey): Niklas Hernaeus patch to detect weak keys. Mon Sep 14 09:19:25 1998 Werner Koch (wk@(none)) * dynload.c (RTLD_NOW): Now defined to 1 if it is undefined. Mon Sep 7 17:04:33 1998 Werner Koch (wk@(none)) * Makefile.am: Fixes to allow a different build directory Thu Aug 6 17:25:38 1998 Werner Koch,mobil,,, (wk@tobold) * random.c (get_random_byte): Removed and changed all callers to use get_random_bits() Mon Jul 27 10:30:22 1998 Werner Koch (wk@(none)) * cipher.c : Support for other blocksizes (cipher_get_blocksize): New. * twofish.c: New. * Makefile.am: Add twofish module. Mon Jul 13 21:30:52 1998 Werner Koch (wk@isil.d.shuttle.de) * random.c (read_pool): Simple alloc if secure_alloc is not set. (get_random_bits): Ditto. Thu Jul 9 13:01:14 1998 Werner Koch (wk@isil.d.shuttle.de) * dynload.c (load_extension): Function now nbails out if the program is run setuid. Wed Jul 8 18:58:23 1998 Werner Koch (wk@isil.d.shuttle.de) * rmd160.c (rmd160_hash_buffer): New. Thu Jul 2 10:50:30 1998 Werner Koch (wk@isil.d.shuttle.de) * cipher.c (cipher_open): algos >=100 use standard CFB Thu Jun 25 11:18:25 1998 Werner Koch (wk@isil.d.shuttle.de) * Makefile.am: Support for extensions Thu Jun 18 12:09:38 1998 Werner Koch (wk@isil.d.shuttle.de) * random.c (mix_pool): simpler handling for level 0 Mon Jun 15 14:40:48 1998 Werner Koch (wk@isil.d.shuttle.de) * tiger.c: Removed from dist, will reappear as dynload module Sat Jun 13 14:16:57 1998 Werner Koch (wk@isil.d.shuttle.de) * pubkey.c: Major changes to allow extensions. Changed the inteface of all public key ciphers and added the ability to load extensions on demand. * misc.c: Removed. Wed Jun 10 07:52:08 1998 Werner Koch,mobil,,, (wk@tobold) * dynload.c: New. * cipher.c: Major changes to allow extensions. Mon Jun 8 22:43:00 1998 Werner Koch (wk@isil.d.shuttle.de) * cipher.c: Major internal chnages to support extensions. * blowfish.c (blowfish_get_info): New and made all internal functions static, changed heder. * cast5.c (cast5_get_info): Likewise. Mon Jun 8 12:27:52 1998 Werner Koch (wk@isil.d.shuttle.de) * tiger.c (transform): Fix for big endian * cipher.c (do_cfb_decrypt): Big endian fix. Fri May 22 07:30:39 1998 Werner Koch (wk@isil.d.shuttle.de) * md.c (md_get_oid): Add a new one for TIGER. Thu May 21 13:24:52 1998 Werner Koch (wk@isil.d.shuttle.de) * cipher.c: Add support for a dummy cipher Thu May 14 15:40:36 1998 Werner Koch (wk@isil.d.shuttle.de) * rmd160.c (transform): fixed sigbus - I should better add Christian von Roques's new implemenation of rmd160_write. Fri May 8 18:07:44 1998 Werner Koch (wk@isil.d.shuttle.de) * rand-internal.h, rand-unix.c, rand-w32.c, rand_dummy.c: New * random.c: Moved system specific functions to rand-****.c Fri May 8 14:01:17 1998 Werner Koch (wk@isil.d.shuttle.de) * random.c (fast_random_poll): add call to gethrtime. Tue May 5 21:28:55 1998 Werner Koch (wk@isil.d.shuttle.de) * elgamal.c (elg_generate): choosing x was not correct, could yield 6 bytes which are not from the random pool, tsss, tsss.. Tue May 5 14:09:06 1998 Werner Koch (wk@isil.d.shuttle.de) * primegen.c (generate_elg_prime): Add arg mode, changed all callers and implemented mode 1. Mon Apr 27 14:41:58 1998 Werner Koch (wk@isil.d.shuttle.de) * cipher.c (cipher_get_keylen): New. Sun Apr 26 14:44:52 1998 Werner Koch (wk@isil.d.shuttle.de) * tiger.c, tiger.h: New. Wed Apr 8 14:57:11 1998 Werner Koch (wk@isil.d.shuttle.de) * misc.c (check_pubkey_algo2): New. Tue Apr 7 18:46:49 1998 Werner Koch (wk@isil.d.shuttle.de) * cipher.c: New * misc.c (check_cipher_algo): Moved to cipher.c * cast5.c: Moved many functions to cipher.c * blowfish.c: Likewise. Sat Apr 4 19:52:08 1998 Werner Koch (wk@isil.d.shuttle.de) * cast5.c: Implemented and tested. Wed Apr 1 16:38:27 1998 Werner Koch (wk@isil.d.shuttle.de) * elgamal.c (elg_generate): Faster generation of x in some cases. Thu Mar 19 13:54:48 1998 Werner Koch (wk@isil.d.shuttle.de) * blowfish.c (blowfish_decode_cfb): changed XOR operation (blowfish_encode_cfb): Ditto. Thu Mar 12 14:04:05 1998 Werner Koch (wk@isil.d.shuttle.de) * sha1.c (transform): Rewrote * blowfish.c (encrypt): Unrolled for rounds == 16 (decrypt): Ditto. Tue Mar 10 16:32:08 1998 Werner Koch (wk@isil.d.shuttle.de) * rmd160.c (transform): Unrolled the loop. Tue Mar 10 13:05:14 1998 Werner Koch (wk@isil.d.shuttle.de) * random.c (read_pool): Add pool_balance stuff. (get_random_bits): New. * elgamal.c (elg_generate): Now uses get_random_bits to generate x. Tue Mar 10 11:33:51 1998 Werner Koch (wk@isil.d.shuttle.de) * md.c (md_digest_length): New. Tue Mar 10 11:27:41 1998 Werner Koch (wk@isil.d.shuttle.de) * dsa.c (dsa_verify): Works. Mon Mar 9 12:59:08 1998 Werner Koch (wk@isil.d.shuttle.de) * dsa.c, dsa.h: Removed some unused code. Wed Mar 4 10:39:22 1998 Werner Koch (wk@isil.d.shuttle.de) * md.c (md_open): Add call to fast_random_poll. blowfish.c (blowfish_setkey): Ditto. Tue Mar 3 13:32:54 1998 Werner Koch (wk@isil.d.shuttle.de) * rmd160.c (rmd160_mixblock): New. * random.c: Restructured to start with a new RNG implementation. * random.h: New. Mon Mar 2 19:21:46 1998 Werner Koch (wk@isil.d.shuttle.de) * gost.c, gost.h: Removed because they did only contain trash. Sun Mar 1 16:42:29 1998 Werner Koch (wk@isil.d.shuttle.de) * random.c (fill_buffer): removed error message if n == -1. Fri Feb 27 16:39:34 1998 Werner Koch (wk@isil.d.shuttle.de) * md.c (md_enable): No init if called twice. Thu Feb 26 07:57:02 1998 Werner Koch (wk@isil.d.shuttle.de) * primegen.c (generate_elg_prime): Changed the progress printing. (gen_prime): Ditto. Tue Feb 24 12:28:42 1998 Werner Koch (wk@isil.d.shuttle.de) * md5.c, md.5 : Replaced by a modified version of md5.c from GNU textutils 1.22. Wed Feb 18 14:08:30 1998 Werner Koch (wk@isil.d.shuttle.de) * md.c, md.h : New debugging support Mon Feb 16 10:08:47 1998 Werner Koch (wk@isil.d.shuttle.de) * misc.c (cipher_algo_to_string): New (pubkey_algo_to_string): New. (digest_algo_to_string): New. Copyright 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without modifications, as long as this notice is preserved. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/cipher/Makefile.am b/cipher/Makefile.am index 49fcf3d2..a992de0f 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -1,79 +1,84 @@ # Makefile for cipher modules # Copyright (C) 1998, 1999, 2000, 2001, 2002, # 2003 Free Software Foundation, Inc. # # This file is part of Libgcrypt. # # Libgcrypt is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # # Libgcrypt is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA # Process this file with automake to produce Makefile.in EXTRA_DIST = Manifest # Need to include ../src in addition to top_srcdir because gcrypt.h is # a built header. AM_CPPFLAGS = -I../src -I$(top_srcdir)/src AM_CFLAGS = $(GPG_ERROR_CFLAGS) noinst_LTLIBRARIES = libcipher.la GCRYPT_MODULES = @GCRYPT_CIPHERS@ @GCRYPT_PUBKEY_CIPHERS@ @GCRYPT_DIGESTS@ \ @GCRYPT_RANDOM@ libcipher_la_DEPENDENCIES = $(GCRYPT_MODULES) libcipher_la_LIBADD = $(GCRYPT_MODULES) libcipher_la_SOURCES = \ cipher.c pubkey.c ac.c md.c \ bithelp.h \ primegen.c \ -random.c random-daemon.c random.h \ +random.c random.h \ rand-internal.h \ rmd.h +if USE_RANDOM_DAEMON +libcipher_la_SOURCES += random-daemon.c +endif USE_RANDOM_DAEMON + + EXTRA_libcipher_la_SOURCES = \ arcfour.c \ blowfish.c \ cast5.c \ crc.c \ des.c \ dsa.c \ elgamal.c \ md4.c \ md5.c \ rijndael.c \ rmd160.c \ rndlinux.c \ rndegd.c \ rndunix.c \ rndw32.c \ rsa.c \ seed.c \ serpent.c \ sha1.c \ sha256.c \ sha512.c \ tiger.c \ whirlpool.c \ twofish.c \ rfc2268.c # We need to lower the optimization for this module. tiger.o: $(srcdir)/tiger.c `echo $(COMPILE) -c $(srcdir)/tiger.c | sed -e 's/-O[2-9s]*/-O1/g' ` tiger.lo: $(srcdir)/tiger.c `echo $(LTCOMPILE) -c $(srcdir)/tiger.c | sed -e 's/-O[2-9s]*/-O1/g' ` diff --git a/cipher/cipher.c b/cipher/cipher.c index 9b17592c..43576fa7 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -1,1524 +1,1523 @@ /* cipher.c - cipher dispatcher * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 * 2005, Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser general Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include #include #include #include #include #include "g10lib.h" #include "cipher.h" #include "ath.h" #define MAX_BLOCKSIZE 16 #define TABLE_SIZE 14 #define CTX_MAGIC_NORMAL 0x24091964 #define CTX_MAGIC_SECURE 0x46919042 /* This is the list of the default ciphers, which are included in libgcrypt. */ static struct cipher_table_entry { gcry_cipher_spec_t *cipher; unsigned int algorithm; } cipher_table[] = { #if USE_BLOWFISH { &_gcry_cipher_spec_blowfish, GCRY_CIPHER_BLOWFISH }, #endif #if USE_DES { &_gcry_cipher_spec_des, GCRY_CIPHER_DES }, { &_gcry_cipher_spec_tripledes, GCRY_CIPHER_3DES }, #endif #if USE_ARCFOUR { &_gcry_cipher_spec_arcfour, GCRY_CIPHER_ARCFOUR }, #endif #if USE_CAST5 { &_gcry_cipher_spec_cast5, GCRY_CIPHER_CAST5 }, #endif #if USE_AES { &_gcry_cipher_spec_aes, GCRY_CIPHER_AES }, { &_gcry_cipher_spec_aes192, GCRY_CIPHER_AES192 }, { &_gcry_cipher_spec_aes256, GCRY_CIPHER_AES256 }, #endif #if USE_TWOFISH { &_gcry_cipher_spec_twofish, GCRY_CIPHER_TWOFISH }, { &_gcry_cipher_spec_twofish128, GCRY_CIPHER_TWOFISH128 }, #endif #if USE_SERPENT { &_gcry_cipher_spec_serpent128, GCRY_CIPHER_SERPENT128 }, { &_gcry_cipher_spec_serpent192, GCRY_CIPHER_SERPENT192 }, { &_gcry_cipher_spec_serpent256, GCRY_CIPHER_SERPENT256 }, #endif #ifdef USE_RFC2268 { &_gcry_cipher_spec_rfc2268_40, GCRY_CIPHER_RFC2268_40 }, #endif #ifdef USE_SEED { &_gcry_cipher_spec_seed, GCRY_CIPHER_SEED }, #endif { NULL } }; /* List of registered ciphers. */ static gcry_module_t ciphers_registered; /* This is the lock protecting CIPHERS_REGISTERED. */ static ath_mutex_t ciphers_registered_lock = ATH_MUTEX_INITIALIZER; /* Flag to check wether the default ciphers have already been registered. */ static int default_ciphers_registered; /* Convenient macro for registering the default ciphers. */ #define REGISTER_DEFAULT_CIPHERS \ do \ { \ ath_mutex_lock (&ciphers_registered_lock); \ if (! default_ciphers_registered) \ { \ gcry_cipher_register_default (); \ default_ciphers_registered = 1; \ } \ ath_mutex_unlock (&ciphers_registered_lock); \ } \ while (0) /* The handle structure. */ struct gcry_cipher_handle { int magic; size_t actual_handle_size; /* Allocated size of this handle. */ gcry_cipher_spec_t *cipher; gcry_module_t module; int mode; unsigned int flags; unsigned char iv[MAX_BLOCKSIZE]; /* (this should be ulong aligned) */ unsigned char lastiv[MAX_BLOCKSIZE]; int unused; /* in IV */ unsigned char ctr[MAX_BLOCKSIZE]; /* For Counter (CTR) mode. */ PROPERLY_ALIGNED_TYPE context; }; /* These dummy functions are used in case a cipher implementation refuses to provide it's own functions. */ static gcry_err_code_t dummy_setkey (void *c, const unsigned char *key, unsigned int keylen) { (void)c; (void)key; (void)keylen; return GPG_ERR_NO_ERROR; } static void dummy_encrypt_block (void *c, unsigned char *outbuf, const unsigned char *inbuf) { (void)c; (void)outbuf; (void)inbuf; BUG(); } static void dummy_decrypt_block (void *c, unsigned char *outbuf, const unsigned char *inbuf) { (void)c; (void)outbuf; (void)inbuf; BUG(); } static void dummy_encrypt_stream (void *c, unsigned char *outbuf, const unsigned char *inbuf, unsigned int n) { (void)c; (void)outbuf; (void)inbuf; (void)n; BUG(); } static void dummy_decrypt_stream (void *c, unsigned char *outbuf, const unsigned char *inbuf, unsigned int n) { (void)c; (void)outbuf; (void)inbuf; (void)n; BUG(); } /* Internal function. Register all the ciphers included in CIPHER_TABLE. Note, that this function gets only used by the macro REGISTER_DEFAULT_CIPHERS which protects it using a mutex. */ static void gcry_cipher_register_default (void) { gcry_err_code_t err = GPG_ERR_NO_ERROR; int i; for (i = 0; !err && cipher_table[i].cipher; i++) { if (! cipher_table[i].cipher->setkey) cipher_table[i].cipher->setkey = dummy_setkey; if (! cipher_table[i].cipher->encrypt) cipher_table[i].cipher->encrypt = dummy_encrypt_block; if (! cipher_table[i].cipher->decrypt) cipher_table[i].cipher->decrypt = dummy_decrypt_block; if (! cipher_table[i].cipher->stencrypt) cipher_table[i].cipher->stencrypt = dummy_encrypt_stream; if (! cipher_table[i].cipher->stdecrypt) cipher_table[i].cipher->stdecrypt = dummy_decrypt_stream; err = _gcry_module_add (&ciphers_registered, cipher_table[i].algorithm, (void *) cipher_table[i].cipher, NULL); } if (err) BUG (); } /* Internal callback function. Used via _gcry_module_lookup. */ static int gcry_cipher_lookup_func_name (void *spec, void *data) { gcry_cipher_spec_t *cipher = (gcry_cipher_spec_t *) spec; char *name = (char *) data; const char **aliases = cipher->aliases; int i, ret = ! stricmp (name, cipher->name); if (aliases) for (i = 0; aliases[i] && (! ret); i++) ret = ! stricmp (name, aliases[i]); return ret; } /* Internal callback function. Used via _gcry_module_lookup. */ static int gcry_cipher_lookup_func_oid (void *spec, void *data) { gcry_cipher_spec_t *cipher = (gcry_cipher_spec_t *) spec; char *oid = (char *) data; gcry_cipher_oid_spec_t *oid_specs = cipher->oids; int ret = 0, i; if (oid_specs) for (i = 0; oid_specs[i].oid && (! ret); i++) if (! stricmp (oid, oid_specs[i].oid)) ret = 1; return ret; } /* Internal function. Lookup a cipher entry by it's name. */ static gcry_module_t gcry_cipher_lookup_name (const char *name) { gcry_module_t cipher; cipher = _gcry_module_lookup (ciphers_registered, (void *) name, gcry_cipher_lookup_func_name); return cipher; } /* Internal function. Lookup a cipher entry by it's oid. */ static gcry_module_t gcry_cipher_lookup_oid (const char *oid) { gcry_module_t cipher; cipher = _gcry_module_lookup (ciphers_registered, (void *) oid, gcry_cipher_lookup_func_oid); return cipher; } /* Register a new cipher module whose specification can be found in CIPHER. On success, a new algorithm ID is stored in ALGORITHM_ID and a pointer representhing this module is stored in MODULE. */ gcry_error_t gcry_cipher_register (gcry_cipher_spec_t *cipher, int *algorithm_id, gcry_module_t *module) { gcry_err_code_t err = 0; gcry_module_t mod; ath_mutex_lock (&ciphers_registered_lock); err = _gcry_module_add (&ciphers_registered, 0, (void *) cipher, &mod); ath_mutex_unlock (&ciphers_registered_lock); if (! err) { *module = mod; *algorithm_id = mod->mod_id; } return gcry_error (err); } /* Unregister the cipher identified by MODULE, which must have been registered with gcry_cipher_register. */ void gcry_cipher_unregister (gcry_module_t module) { ath_mutex_lock (&ciphers_registered_lock); _gcry_module_release (module); ath_mutex_unlock (&ciphers_registered_lock); } /* Locate the OID in the oid table and return the index or -1 when not found. An opitonal "oid." or "OID." prefix in OID is ignored, the OID is expected to be in standard IETF dotted notation. The internal algorithm number is returned in ALGORITHM unless it ispassed as NULL. A pointer to the specification of the module implementing this algorithm is return in OID_SPEC unless passed as NULL.*/ static int search_oid (const char *oid, int *algorithm, gcry_cipher_oid_spec_t *oid_spec) { gcry_module_t module; int ret = 0; if (oid && ((! strncmp (oid, "oid.", 4)) || (! strncmp (oid, "OID.", 4)))) oid += 4; module = gcry_cipher_lookup_oid (oid); if (module) { gcry_cipher_spec_t *cipher = module->spec; int i; for (i = 0; cipher->oids[i].oid && !ret; i++) if (! stricmp (oid, cipher->oids[i].oid)) { if (algorithm) *algorithm = module->mod_id; if (oid_spec) *oid_spec = cipher->oids[i]; ret = 1; } _gcry_module_release (module); } return ret; } /* Map STRING to the cipher algorithm identifier. Returns the algorithm ID of the cipher for the given name or 0 if the name is not known. It is valid to pass NULL for STRING which results in a return value of 0. */ int gcry_cipher_map_name (const char *string) { gcry_module_t cipher; int ret, algorithm = 0; if (! string) return 0; REGISTER_DEFAULT_CIPHERS; /* If the string starts with a digit (optionally prefixed with either "OID." or "oid."), we first look into our table of ASN.1 object identifiers to figure out the algorithm */ ath_mutex_lock (&ciphers_registered_lock); ret = search_oid (string, &algorithm, NULL); if (! ret) { cipher = gcry_cipher_lookup_name (string); if (cipher) { algorithm = cipher->mod_id; _gcry_module_release (cipher); } } ath_mutex_unlock (&ciphers_registered_lock); return algorithm; } /* Given a STRING with an OID in dotted decimal notation, this function returns the cipher mode (GCRY_CIPHER_MODE_*) associated with that OID or 0 if no mode is known. Passing NULL for string yields a return value of 0. */ int gcry_cipher_mode_from_oid (const char *string) { gcry_cipher_oid_spec_t oid_spec; int ret = 0, mode = 0; if (!string) return 0; ath_mutex_lock (&ciphers_registered_lock); ret = search_oid (string, NULL, &oid_spec); if (ret) mode = oid_spec.mode; ath_mutex_unlock (&ciphers_registered_lock); return mode; } /* Map the cipher algorithm whose ID is contained in ALGORITHM to a string representation of the algorithm name. For unknown algorithm IDs this function returns "?". */ static const char * cipher_algo_to_string (int algorithm) { gcry_module_t cipher; const char *name; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); cipher = _gcry_module_lookup_id (ciphers_registered, algorithm); if (cipher) { name = ((gcry_cipher_spec_t *) cipher->spec)->name; _gcry_module_release (cipher); } else name = "?"; ath_mutex_unlock (&ciphers_registered_lock); return name; } /* Map the cipher algorithm identifier ALGORITHM to a string representing this algorithm. This string is the default name as used by Libgcrypt. An pointer to an empty string is returned for an unknown algorithm. NULL is never returned. */ const char * gcry_cipher_algo_name (int algorithm) { - const char *s = cipher_algo_to_string (algorithm); - return s ? s : ""; + return cipher_algo_to_string (algorithm); } /* Flag the cipher algorithm with the identifier ALGORITHM as disabled. There is no error return, the function does nothing for unknown algorithms. Disabled algorithms are vitually not available in Libgcrypt. */ static void disable_cipher_algo (int algorithm) { gcry_module_t cipher; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); cipher = _gcry_module_lookup_id (ciphers_registered, algorithm); if (cipher) { if (! (cipher->flags & FLAG_MODULE_DISABLED)) cipher->flags |= FLAG_MODULE_DISABLED; _gcry_module_release (cipher); } ath_mutex_unlock (&ciphers_registered_lock); } /* Return 0 if the cipher algorithm with indentifier ALGORITHM is available. Returns a basic error code value if it is not available. */ static gcry_err_code_t check_cipher_algo (int algorithm) { gcry_err_code_t err = GPG_ERR_NO_ERROR; gcry_module_t cipher; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); cipher = _gcry_module_lookup_id (ciphers_registered, algorithm); if (cipher) { if (cipher->flags & FLAG_MODULE_DISABLED) err = GPG_ERR_CIPHER_ALGO; _gcry_module_release (cipher); } else err = GPG_ERR_CIPHER_ALGO; ath_mutex_unlock (&ciphers_registered_lock); return err; } /* Return the standard length of the key for the cipher algorithm with the identifier ALGORITHM. This function expects a valid algorithm and will abort if the algorithm is not available or the length of the key is not known. */ static unsigned int cipher_get_keylen (int algorithm) { gcry_module_t cipher; unsigned len = 0; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); cipher = _gcry_module_lookup_id (ciphers_registered, algorithm); if (cipher) { len = ((gcry_cipher_spec_t *) cipher->spec)->keylen; if (! len) log_bug ("cipher %d w/o key length\n", algorithm); _gcry_module_release (cipher); } else log_bug ("cipher %d not found\n", algorithm); ath_mutex_unlock (&ciphers_registered_lock); return len; } /* Return the block length of the cipher algorithm with the identifier ALGORITHM. This function expects a valid algorithm and will abort if the algorithm is not available or the length of the key is not known. */ static unsigned int cipher_get_blocksize (int algorithm) { gcry_module_t cipher; unsigned len = 0; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); cipher = _gcry_module_lookup_id (ciphers_registered, algorithm); if (cipher) { len = ((gcry_cipher_spec_t *) cipher->spec)->blocksize; if (! len) log_bug ("cipher %d w/o blocksize\n", algorithm); _gcry_module_release (cipher); } else log_bug ("cipher %d not found\n", algorithm); ath_mutex_unlock (&ciphers_registered_lock); return len; } /* Open a cipher handle for use with cipher algorithm ALGORITHM, using the cipher mode MODE (one of the GCRY_CIPHER_MODE_*) and return a handle in HANDLE. Put NULL into HANDLE and return an error code if something goes wrong. FLAGS may be used to modify the operation. The defined flags are: GCRY_CIPHER_SECURE: allocate all internal buffers in secure memory. GCRY_CIPHER_ENABLE_SYNC: Enable the sync operation as used in OpenPGP. GCRY_CIPHER_CBC_CTS: Enable CTS mode. GCRY_CIPHER_CBC_MAC: Enable MAC mode. Values for these flags may be combined using OR. */ gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *handle, int algo, int mode, unsigned int flags) { int secure = (flags & GCRY_CIPHER_SECURE); gcry_cipher_spec_t *cipher = NULL; gcry_module_t module = NULL; gcry_cipher_hd_t h = NULL; gcry_err_code_t err = 0; /* If the application missed to call the random poll function, we do it here to ensure that it is used once in a while. */ _gcry_fast_random_poll (); REGISTER_DEFAULT_CIPHERS; /* Fetch the according module and check wether the cipher is marked available for use. */ ath_mutex_lock (&ciphers_registered_lock); module = _gcry_module_lookup_id (ciphers_registered, algo); if (module) { /* Found module. */ if (module->flags & FLAG_MODULE_DISABLED) { /* Not available for use. */ err = GPG_ERR_CIPHER_ALGO; _gcry_module_release (module); } else cipher = (gcry_cipher_spec_t *) module->spec; } else err = GPG_ERR_CIPHER_ALGO; ath_mutex_unlock (&ciphers_registered_lock); /* check flags */ if ((! err) && ((flags & ~(0 | GCRY_CIPHER_SECURE | GCRY_CIPHER_ENABLE_SYNC | GCRY_CIPHER_CBC_CTS | GCRY_CIPHER_CBC_MAC)) || (flags & GCRY_CIPHER_CBC_CTS & GCRY_CIPHER_CBC_MAC))) err = GPG_ERR_CIPHER_ALGO; /* check that a valid mode has been requested */ if (! err) switch (mode) { case GCRY_CIPHER_MODE_ECB: case GCRY_CIPHER_MODE_CBC: case GCRY_CIPHER_MODE_CFB: case GCRY_CIPHER_MODE_OFB: case GCRY_CIPHER_MODE_CTR: if ((cipher->encrypt == dummy_encrypt_block) || (cipher->decrypt == dummy_decrypt_block)) err = GPG_ERR_INV_CIPHER_MODE; break; case GCRY_CIPHER_MODE_STREAM: if ((cipher->stencrypt == dummy_encrypt_stream) || (cipher->stdecrypt == dummy_decrypt_stream)) err = GPG_ERR_INV_CIPHER_MODE; break; case GCRY_CIPHER_MODE_NONE: /* FIXME: issue a warning when this mode is used */ break; default: err = GPG_ERR_INV_CIPHER_MODE; } /* ? FIXME: perform selftest here and mark this with a flag in cipher_table ? */ if (! err) { size_t size = (sizeof (*h) + 2 * cipher->contextsize - sizeof (PROPERLY_ALIGNED_TYPE)); if (secure) h = gcry_calloc_secure (1, size); else h = gcry_calloc (1, size); if (! h) err = gpg_err_code_from_errno (errno); else { h->magic = secure ? CTX_MAGIC_SECURE : CTX_MAGIC_NORMAL; h->actual_handle_size = size; h->cipher = cipher; h->module = module; h->mode = mode; h->flags = flags; } } /* Done. */ if (err) { if (module) { /* Release module. */ ath_mutex_lock (&ciphers_registered_lock); _gcry_module_release (module); ath_mutex_unlock (&ciphers_registered_lock); } } *handle = err ? NULL : h; return gcry_error (err); } /* Release all resources associated with the cipher handle H. H may be NULL in which case this is a no-operation. */ void gcry_cipher_close (gcry_cipher_hd_t h) { if (! h) return; if ((h->magic != CTX_MAGIC_SECURE) && (h->magic != CTX_MAGIC_NORMAL)) _gcry_fatal_error(GPG_ERR_INTERNAL, "gcry_cipher_close: already closed/invalid handle"); else h->magic = 0; /* Release module. */ ath_mutex_lock (&ciphers_registered_lock); _gcry_module_release (h->module); ath_mutex_unlock (&ciphers_registered_lock); /* We always want to wipe out the memory even when the context has been allocated in secure memory. The user might have disabled secure memory or is using his own implementation which does not do the wiping. To accomplish this we need to keep track of the actual size of this structure because we have no way to known how large the allocated area was when using a standard malloc. */ wipememory (h, h->actual_handle_size); gcry_free (h); } /* Set the key to be used for the encryption context C to KEY with length KEYLEN. The length should match the required length. */ static gcry_error_t cipher_setkey (gcry_cipher_hd_t c, byte *key, unsigned keylen) { gcry_err_code_t ret; ret = (*c->cipher->setkey) (&c->context.c, key, keylen); if (! ret) /* Duplicate initial context. */ memcpy ((void *) ((char *) &c->context.c + c->cipher->contextsize), (void *) &c->context.c, c->cipher->contextsize); return gcry_error (ret); } /* Set the IV to be used for the encryption context C to IV with length IVLEN. The length should match the required length. */ static void cipher_setiv( gcry_cipher_hd_t c, const byte *iv, unsigned ivlen ) { memset( c->iv, 0, c->cipher->blocksize ); if( iv ) { if( ivlen != c->cipher->blocksize ) log_info("WARNING: cipher_setiv: ivlen=%u blklen=%u\n", ivlen, (unsigned) c->cipher->blocksize ); if (ivlen > c->cipher->blocksize) ivlen = c->cipher->blocksize; memcpy( c->iv, iv, ivlen ); } c->unused = 0; } /* Reset the cipher context to the initial contex. This is basically the same as an release followed by a new. */ static void cipher_reset (gcry_cipher_hd_t c) { memcpy (&c->context.c, (char *) &c->context.c + c->cipher->contextsize, c->cipher->contextsize); memset (c->iv, 0, c->cipher->blocksize); memset (c->lastiv, 0, c->cipher->blocksize); memset (c->ctr, 0, c->cipher->blocksize); } static void do_ecb_encrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nblocks ) { unsigned int n; for(n=0; n < nblocks; n++ ) { c->cipher->encrypt ( &c->context.c, outbuf, (byte*)/*arggg*/inbuf ); inbuf += c->cipher->blocksize; outbuf += c->cipher->blocksize; } } static void do_ecb_decrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nblocks ) { unsigned n; for(n=0; n < nblocks; n++ ) { c->cipher->decrypt ( &c->context.c, outbuf, (byte*)/*arggg*/inbuf ); inbuf += c->cipher->blocksize; outbuf += c->cipher->blocksize; } } static void do_cbc_encrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nbytes ) { unsigned int n; byte *ivp; int i; size_t blocksize = c->cipher->blocksize; unsigned nblocks = nbytes / blocksize; if ((c->flags & GCRY_CIPHER_CBC_CTS) && nbytes > blocksize) { if ((nbytes % blocksize) == 0) nblocks--; } for(n=0; n < nblocks; n++ ) { /* fixme: the xor should work on words and not on * bytes. Maybe it is a good idea to enhance the cipher backend * API to allow for CBC handling direct in the backend */ for(ivp=c->iv,i=0; i < blocksize; i++ ) outbuf[i] = inbuf[i] ^ *ivp++; c->cipher->encrypt ( &c->context.c, outbuf, outbuf ); memcpy(c->iv, outbuf, blocksize ); inbuf += blocksize; if (!(c->flags & GCRY_CIPHER_CBC_MAC)) outbuf += blocksize; } if ((c->flags & GCRY_CIPHER_CBC_CTS) && nbytes > blocksize) { /* We have to be careful here, since outbuf might be equal to inbuf. */ int restbytes; byte b; if ((nbytes % blocksize) == 0) restbytes = blocksize; else restbytes = nbytes % blocksize; outbuf -= blocksize; for (ivp = c->iv, i = 0; i < restbytes; i++) { b = inbuf[i]; outbuf[blocksize + i] = outbuf[i]; outbuf[i] = b ^ *ivp++; } for (; i < blocksize; i++) outbuf[i] = 0 ^ *ivp++; c->cipher->encrypt (&c->context.c, outbuf, outbuf); memcpy (c->iv, outbuf, blocksize); } } static void do_cbc_decrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nbytes ) { unsigned int n; byte *ivp; int i; size_t blocksize = c->cipher->blocksize; unsigned int nblocks = nbytes / blocksize; if ((c->flags & GCRY_CIPHER_CBC_CTS) && nbytes > blocksize) { nblocks--; if ((nbytes % blocksize) == 0) nblocks--; memcpy(c->lastiv, c->iv, blocksize ); } for(n=0; n < nblocks; n++ ) { /* Because outbuf and inbuf might be the same, we have * to save the original ciphertext block. We use lastiv * for this here because it is not used otherwise. */ memcpy(c->lastiv, inbuf, blocksize ); c->cipher->decrypt ( &c->context.c, outbuf, inbuf ); for(ivp=c->iv,i=0; i < blocksize; i++ ) outbuf[i] ^= *ivp++; memcpy(c->iv, c->lastiv, blocksize ); inbuf += c->cipher->blocksize; outbuf += c->cipher->blocksize; } if ((c->flags & GCRY_CIPHER_CBC_CTS) && nbytes > blocksize) { int restbytes; if ((nbytes % blocksize) == 0) restbytes = blocksize; else restbytes = nbytes % blocksize; memcpy(c->lastiv, c->iv, blocksize ); /* save Cn-2 */ memcpy(c->iv, inbuf + blocksize, restbytes ); /* save Cn */ c->cipher->decrypt ( &c->context.c, outbuf, inbuf ); for(ivp=c->iv,i=0; i < restbytes; i++ ) outbuf[i] ^= *ivp++; memcpy(outbuf + blocksize, outbuf, restbytes); for(i=restbytes; i < blocksize; i++) c->iv[i] = outbuf[i]; c->cipher->decrypt ( &c->context.c, outbuf, c->iv ); for(ivp=c->lastiv,i=0; i < blocksize; i++ ) outbuf[i] ^= *ivp++; /* c->lastiv is now really lastlastiv, does this matter? */ } } static void do_cfb_encrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned nbytes ) { byte *ivp; size_t blocksize = c->cipher->blocksize; if( nbytes <= c->unused ) { /* Short enough to be encoded by the remaining XOR mask. */ /* XOR the input with the IV and store input into IV. */ for (ivp=c->iv+c->cipher->blocksize - c->unused; nbytes; nbytes--, c->unused-- ) *outbuf++ = (*ivp++ ^= *inbuf++); return; } if( c->unused ) { /* XOR the input with the IV and store input into IV */ nbytes -= c->unused; for(ivp=c->iv+blocksize - c->unused; c->unused; c->unused-- ) *outbuf++ = (*ivp++ ^= *inbuf++); } /* Now we can process complete blocks. */ while( nbytes >= blocksize ) { int i; /* Encrypt the IV (and save the current one). */ memcpy( c->lastiv, c->iv, blocksize ); c->cipher->encrypt ( &c->context.c, c->iv, c->iv ); /* XOR the input with the IV and store input into IV */ for(ivp=c->iv,i=0; i < blocksize; i++ ) *outbuf++ = (*ivp++ ^= *inbuf++); nbytes -= blocksize; } if( nbytes ) { /* process the remaining bytes */ /* encrypt the IV (and save the current one) */ memcpy( c->lastiv, c->iv, blocksize ); c->cipher->encrypt ( &c->context.c, c->iv, c->iv ); c->unused = blocksize; /* and apply the xor */ c->unused -= nbytes; for(ivp=c->iv; nbytes; nbytes-- ) *outbuf++ = (*ivp++ ^= *inbuf++); } } static void do_cfb_decrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nbytes ) { byte *ivp; ulong temp; size_t blocksize = c->cipher->blocksize; if( nbytes <= c->unused ) { /* Short enough to be encoded by the remaining XOR mask. */ /* XOR the input with the IV and store input into IV. */ for(ivp=c->iv+blocksize - c->unused; nbytes; nbytes--,c->unused--) { temp = *inbuf++; *outbuf++ = *ivp ^ temp; *ivp++ = temp; } return; } if( c->unused ) { /* XOR the input with the IV and store input into IV. */ nbytes -= c->unused; for(ivp=c->iv+blocksize - c->unused; c->unused; c->unused-- ) { temp = *inbuf++; *outbuf++ = *ivp ^ temp; *ivp++ = temp; } } /* now we can process complete blocks */ while( nbytes >= blocksize ) { int i; /* encrypt the IV (and save the current one) */ memcpy( c->lastiv, c->iv, blocksize ); c->cipher->encrypt ( &c->context.c, c->iv, c->iv ); /* XOR the input with the IV and store input into IV */ for(ivp=c->iv,i=0; i < blocksize; i++ ) { temp = *inbuf++; *outbuf++ = *ivp ^ temp; *ivp++ = temp; } nbytes -= blocksize; } if( nbytes ) { /* process the remaining bytes */ /* encrypt the IV (and save the current one) */ memcpy( c->lastiv, c->iv, blocksize ); c->cipher->encrypt ( &c->context.c, c->iv, c->iv ); c->unused = blocksize; /* and apply the xor */ c->unused -= nbytes; for(ivp=c->iv; nbytes; nbytes-- ) { temp = *inbuf++; *outbuf++ = *ivp ^ temp; *ivp++ = temp; } } } static void do_ofb_encrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned nbytes ) { byte *ivp; size_t blocksize = c->cipher->blocksize; if ( nbytes <= c->unused ) { /* Short enough to be encoded by the remaining XOR mask. */ /* XOR the input with the IV */ for (ivp=c->iv+c->cipher->blocksize - c->unused; nbytes; nbytes--, c->unused-- ) *outbuf++ = (*ivp++ ^ *inbuf++); return; } if( c->unused ) { nbytes -= c->unused; for(ivp=c->iv+blocksize - c->unused; c->unused; c->unused-- ) *outbuf++ = (*ivp++ ^ *inbuf++); } /* Now we can process complete blocks. */ while ( nbytes >= blocksize ) { int i; /* Encrypt the IV (and save the current one). */ memcpy( c->lastiv, c->iv, blocksize ); c->cipher->encrypt ( &c->context.c, c->iv, c->iv ); for (ivp=c->iv,i=0; i < blocksize; i++ ) *outbuf++ = (*ivp++ ^ *inbuf++); nbytes -= blocksize; } if ( nbytes ) { /* process the remaining bytes */ memcpy( c->lastiv, c->iv, blocksize ); c->cipher->encrypt ( &c->context.c, c->iv, c->iv ); c->unused = blocksize; c->unused -= nbytes; for(ivp=c->iv; nbytes; nbytes-- ) *outbuf++ = (*ivp++ ^ *inbuf++); } } static void do_ofb_decrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nbytes ) { byte *ivp; size_t blocksize = c->cipher->blocksize; if( nbytes <= c->unused ) { /* Short enough to be encoded by the remaining XOR mask. */ for (ivp=c->iv+blocksize - c->unused; nbytes; nbytes--,c->unused--) *outbuf++ = *ivp++ ^ *inbuf++; return; } if ( c->unused ) { nbytes -= c->unused; for (ivp=c->iv+blocksize - c->unused; c->unused; c->unused-- ) *outbuf++ = *ivp++ ^ *inbuf++; } /* Now we can process complete blocks. */ while ( nbytes >= blocksize ) { int i; /* Encrypt the IV (and save the current one). */ memcpy( c->lastiv, c->iv, blocksize ); c->cipher->encrypt ( &c->context.c, c->iv, c->iv ); for (ivp=c->iv,i=0; i < blocksize; i++ ) *outbuf++ = *ivp++ ^ *inbuf++; nbytes -= blocksize; } if ( nbytes ) { /* Process the remaining bytes. */ /* Encrypt the IV (and save the current one). */ memcpy( c->lastiv, c->iv, blocksize ); c->cipher->encrypt ( &c->context.c, c->iv, c->iv ); c->unused = blocksize; c->unused -= nbytes; for (ivp=c->iv; nbytes; nbytes-- ) *outbuf++ = *ivp++ ^ *inbuf++; } } static void do_ctr_encrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nbytes ) { unsigned int n; byte tmp[MAX_BLOCKSIZE]; int i; for(n=0; n < nbytes; n++) { if ((n % c->cipher->blocksize) == 0) { c->cipher->encrypt (&c->context.c, tmp, c->ctr); for (i = c->cipher->blocksize; i > 0; i--) { c->ctr[i-1]++; if (c->ctr[i-1] != 0) break; } } /* XOR input with encrypted counter and store in output. */ outbuf[n] = inbuf[n] ^ tmp[n % c->cipher->blocksize]; } } static void do_ctr_decrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nbytes ) { do_ctr_encrypt (c, outbuf, inbuf, nbytes); } /**************** * Encrypt INBUF to OUTBUF with the mode selected at open. * inbuf and outbuf may overlap or be the same. * Depending on the mode some contraints apply to NBYTES. */ static gcry_err_code_t cipher_encrypt (gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nbytes) { gcry_err_code_t rc = GPG_ERR_NO_ERROR; switch( c->mode ) { case GCRY_CIPHER_MODE_ECB: if (!(nbytes%c->cipher->blocksize)) do_ecb_encrypt(c, outbuf, inbuf, nbytes/c->cipher->blocksize ); else rc = GPG_ERR_INV_ARG; break; case GCRY_CIPHER_MODE_CBC: if (!(nbytes%c->cipher->blocksize) || (nbytes > c->cipher->blocksize && (c->flags & GCRY_CIPHER_CBC_CTS))) do_cbc_encrypt(c, outbuf, inbuf, nbytes ); else rc = GPG_ERR_INV_ARG; break; case GCRY_CIPHER_MODE_CFB: do_cfb_encrypt(c, outbuf, inbuf, nbytes ); break; case GCRY_CIPHER_MODE_OFB: do_ofb_encrypt(c, outbuf, inbuf, nbytes ); break; case GCRY_CIPHER_MODE_CTR: do_ctr_encrypt(c, outbuf, inbuf, nbytes ); break; case GCRY_CIPHER_MODE_STREAM: c->cipher->stencrypt ( &c->context.c, outbuf, (byte*)/*arggg*/inbuf, nbytes ); break; case GCRY_CIPHER_MODE_NONE: if( inbuf != outbuf ) memmove( outbuf, inbuf, nbytes ); break; default: log_fatal("cipher_encrypt: invalid mode %d\n", c->mode ); rc = GPG_ERR_INV_CIPHER_MODE; break; } return rc; } /**************** * Encrypt IN and write it to OUT. If IN is NULL, in-place encryption has * been requested. */ gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t h, void *out, size_t outsize, const void *in, size_t inlen) { gcry_err_code_t err; if (!in) /* Caller requested in-place encryption. */ /* Actually cipher_encrypt() does not need to know about it, but * we may change it in the future to get better performance. */ err = cipher_encrypt (h, out, out, outsize); else if (outsize < ((h->flags & GCRY_CIPHER_CBC_MAC) ? h->cipher->blocksize : inlen)) err = GPG_ERR_TOO_SHORT; else if ((h->mode == GCRY_CIPHER_MODE_ECB || (h->mode == GCRY_CIPHER_MODE_CBC && (! ((h->flags & GCRY_CIPHER_CBC_CTS) && (inlen > h->cipher->blocksize))))) && (inlen % h->cipher->blocksize)) err = GPG_ERR_INV_ARG; else err = cipher_encrypt (h, out, in, inlen); if (err && out) memset (out, 0x42, outsize); /* Failsafe: Make sure that the plaintext will never make it into OUT. */ return gcry_error (err); } /**************** * Decrypt INBUF to OUTBUF with the mode selected at open. * inbuf and outbuf may overlap or be the same. * Depending on the mode some some contraints apply to NBYTES. */ static gcry_err_code_t cipher_decrypt (gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned int nbytes) { gcry_err_code_t rc = GPG_ERR_NO_ERROR; switch( c->mode ) { case GCRY_CIPHER_MODE_ECB: if (!(nbytes%c->cipher->blocksize)) do_ecb_decrypt(c, outbuf, inbuf, nbytes/c->cipher->blocksize ); else rc = GPG_ERR_INV_ARG; break; case GCRY_CIPHER_MODE_CBC: if (!(nbytes%c->cipher->blocksize) || (nbytes > c->cipher->blocksize && (c->flags & GCRY_CIPHER_CBC_CTS))) do_cbc_decrypt(c, outbuf, inbuf, nbytes ); else rc = GPG_ERR_INV_ARG; break; case GCRY_CIPHER_MODE_CFB: do_cfb_decrypt(c, outbuf, inbuf, nbytes ); break; case GCRY_CIPHER_MODE_OFB: do_ofb_decrypt(c, outbuf, inbuf, nbytes ); break; case GCRY_CIPHER_MODE_CTR: do_ctr_decrypt(c, outbuf, inbuf, nbytes ); break; case GCRY_CIPHER_MODE_STREAM: c->cipher->stdecrypt ( &c->context.c, outbuf, (byte*)/*arggg*/inbuf, nbytes ); break; case GCRY_CIPHER_MODE_NONE: if( inbuf != outbuf ) memmove( outbuf, inbuf, nbytes ); break; default: log_fatal ("cipher_decrypt: invalid mode %d\n", c->mode ); rc = GPG_ERR_INV_CIPHER_MODE; break; } return rc; } gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t h, void *out, size_t outsize, const void *in, size_t inlen) { gcry_err_code_t err = 0; if (!in) /* Caller requested in-place encryption. */ /* Actually cipher_encrypt() does not need to know about it, but * we may change it in the future to get better performance. */ err = cipher_decrypt (h, out, out, outsize); else if (outsize < inlen) err = GPG_ERR_TOO_SHORT; else if (((h->mode == GCRY_CIPHER_MODE_ECB) || ((h->mode == GCRY_CIPHER_MODE_CBC) && (! ((h->flags & GCRY_CIPHER_CBC_CTS) && (inlen > h->cipher->blocksize))))) && (inlen % h->cipher->blocksize) != 0) err = GPG_ERR_INV_ARG; else err = cipher_decrypt (h, out, in, inlen); return gcry_error (err); } /**************** * Used for PGP's somewhat strange CFB mode. Only works if * the corresponding flag is set. */ static void cipher_sync( gcry_cipher_hd_t c ) { if( (c->flags & GCRY_CIPHER_ENABLE_SYNC) && c->unused ) { memmove(c->iv + c->unused, c->iv, c->cipher->blocksize - c->unused ); memcpy(c->iv, c->lastiv + c->cipher->blocksize - c->unused, c->unused); c->unused = 0; } } gcry_error_t gcry_cipher_ctl( gcry_cipher_hd_t h, int cmd, void *buffer, size_t buflen) { gcry_err_code_t rc = GPG_ERR_NO_ERROR; switch (cmd) { case GCRYCTL_SET_KEY: rc = cipher_setkey( h, buffer, buflen ); break; case GCRYCTL_SET_IV: cipher_setiv( h, buffer, buflen ); break; case GCRYCTL_RESET: cipher_reset (h); break; case GCRYCTL_CFB_SYNC: cipher_sync( h ); break; case GCRYCTL_SET_CBC_CTS: if (buflen) if (h->flags & GCRY_CIPHER_CBC_MAC) rc = GPG_ERR_INV_FLAG; else h->flags |= GCRY_CIPHER_CBC_CTS; else h->flags &= ~GCRY_CIPHER_CBC_CTS; break; case GCRYCTL_SET_CBC_MAC: if (buflen) if (h->flags & GCRY_CIPHER_CBC_CTS) rc = GPG_ERR_INV_FLAG; else h->flags |= GCRY_CIPHER_CBC_MAC; else h->flags &= ~GCRY_CIPHER_CBC_MAC; break; case GCRYCTL_DISABLE_ALGO: /* this one expects a NULL handle and buffer pointing to an * integer with the algo number. */ if( h || !buffer || buflen != sizeof(int) ) return gcry_error (GPG_ERR_CIPHER_ALGO); disable_cipher_algo( *(int*)buffer ); break; case GCRYCTL_SET_CTR: if (buffer && buflen == h->cipher->blocksize) memcpy (h->ctr, buffer, h->cipher->blocksize); else if (buffer == NULL || buflen == 0) memset (h->ctr, 0, h->cipher->blocksize); else rc = GPG_ERR_INV_ARG; break; default: rc = GPG_ERR_INV_OP; } return gcry_error (rc); } /**************** * Return information about the cipher handle. */ gcry_error_t gcry_cipher_info( gcry_cipher_hd_t h, int cmd, void *buffer, size_t *nbytes) { gcry_err_code_t err = GPG_ERR_NO_ERROR; (void)h; (void)buffer; (void)nbytes; switch (cmd) { default: err = GPG_ERR_INV_OP; } return gcry_error (err); } /**************** * Return information about the given cipher algorithm * WHAT select the kind of information returned: * GCRYCTL_GET_KEYLEN: * Return the length of the key, if the algorithm * supports multiple key length, the maximum supported value * is returnd. The length is return as number of octets. * buffer and nbytes must be zero. * The keylength is returned in _bytes_. * GCRYCTL_GET_BLKLEN: * Return the blocklength of the algorithm counted in octets. * buffer and nbytes must be zero. * GCRYCTL_TEST_ALGO: * Returns 0 when the specified algorithm is available for use. * buffer and nbytes must be zero. * * Note: Because this function is in most cases used to return an * integer value, we can make it easier for the caller to just look at * the return value. The caller will in all cases consult the value * and thereby detecting whether a error occured or not (i.e. while checking * the block size) */ gcry_error_t gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes) { gcry_err_code_t err = GPG_ERR_NO_ERROR; unsigned int ui; switch (what) { case GCRYCTL_GET_KEYLEN: if (buffer || (! nbytes)) err = GPG_ERR_CIPHER_ALGO; else { ui = cipher_get_keylen (algo); if ((ui > 0) && (ui <= 512)) *nbytes = (size_t) ui / 8; else /* The only reason is an invalid algo or a strange blocksize. */ err = GPG_ERR_CIPHER_ALGO; } break; case GCRYCTL_GET_BLKLEN: if (buffer || (! nbytes)) err = GPG_ERR_CIPHER_ALGO; else { ui = cipher_get_blocksize (algo); if ((ui > 0) && (ui < 10000)) *nbytes = ui; else /* The only reason is an invalid algo or a strange blocksize. */ err = GPG_ERR_CIPHER_ALGO; } break; case GCRYCTL_TEST_ALGO: if (buffer || nbytes) err = GPG_ERR_INV_ARG; else err = check_cipher_algo (algo); break; default: err = GPG_ERR_INV_OP; } return gcry_error (err); } size_t gcry_cipher_get_algo_keylen (int algo) { size_t n; if (gcry_cipher_algo_info( algo, GCRYCTL_GET_KEYLEN, NULL, &n)) n = 0; return n; } size_t gcry_cipher_get_algo_blklen (int algo) { size_t n; if (gcry_cipher_algo_info( algo, GCRYCTL_GET_BLKLEN, NULL, &n)) n = 0; return n; } gcry_err_code_t _gcry_cipher_init (void) { gcry_err_code_t err = GPG_ERR_NO_ERROR; REGISTER_DEFAULT_CIPHERS; return err; } /* Get a list consisting of the IDs of the loaded cipher modules. If LIST is zero, write the number of loaded cipher modules to LIST_LENGTH and return. If LIST is non-zero, the first *LIST_LENGTH algorithm IDs are stored in LIST, which must be of according size. In case there are less cipher modules than *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */ gcry_error_t gcry_cipher_list (int *list, int *list_length) { gcry_err_code_t err = GPG_ERR_NO_ERROR; ath_mutex_lock (&ciphers_registered_lock); err = _gcry_module_list (ciphers_registered, list, list_length); ath_mutex_unlock (&ciphers_registered_lock); return err; } diff --git a/cipher/rand-internal.h b/cipher/rand-internal.h index bf1b2af0..6c548acb 100644 --- a/cipher/rand-internal.h +++ b/cipher/rand-internal.h @@ -1,41 +1,41 @@ /* rand-internal.h - header to glue the random functions * Copyright (C) 1998, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser general Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifndef G10_RAND_INTERNAL_H #define G10_RAND_INTERNAL_H void _gcry_random_progress (const char *what, int printchar, int current, int total); int _gcry_rndlinux_gather_random (void (*add) (const void *, size_t, int), int requester, size_t length, int level); int _gcry_rndunix_gather_random (void (*add) (const void *, size_t, int), int requester, size_t length, int level); int _gcry_rndegd_gather_random (void (*add) (const void *, size_t, int), int requester, size_t length, int level); int _gcry_rndegd_connect_socket (int nofail); int _gcry_rndw32_gather_random (void (*add) (const void *, size_t, int), int requester, size_t length, int level); -int _gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t, int), - int requester ); +void _gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t, int), + int requester ); #endif /*G10_RAND_INTERNAL_H*/ diff --git a/cipher/random.c b/cipher/random.c index c9c95cc0..5453124c 100644 --- a/cipher/random.c +++ b/cipher/random.c @@ -1,1307 +1,1328 @@ /* random.c - random number generator * Copyright (C) 1998, 2000, 2001, 2002, 2003, * 2004, 2005, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /**************** * This random number generator is modelled after the one described in * Peter Gutmann's paper: "Software Generation of Practically Strong * Random Numbers". See also chapter 6 in his book "Cryptographic * Security Architecture", New York, 2004, ISBN 0-387-95387-6. */ #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_GETHRTIME #include #endif #ifdef HAVE_GETTIMEOFDAY #include #endif #ifdef HAVE_GETRUSAGE #include #endif #ifdef __MINGW32__ #include #endif #include "g10lib.h" #include "rmd.h" #include "random.h" #include "rand-internal.h" #include "cipher.h" /* only used for the rmd160_hash_buffer() prototype */ #include "ath.h" #ifndef RAND_MAX /* for SunOS */ #define RAND_MAX 32767 #endif /* Check whether we can lock the seed file read write. */ #if defined(HAVE_FCNTL) && defined(HAVE_FTRUNCATE) && !defined(HAVE_W32_SYSTEM) #define LOCK_SEED_FILE 1 #else #define LOCK_SEED_FILE 0 #endif #if SIZEOF_UNSIGNED_LONG == 8 #define ADD_VALUE 0xa5a5a5a5a5a5a5a5 #elif SIZEOF_UNSIGNED_LONG == 4 #define ADD_VALUE 0xa5a5a5a5 #else #error weird size for an unsigned long #endif #define BLOCKLEN 64 /* hash this amount of bytes */ #define DIGESTLEN 20 /* into a digest of this length (rmd160) */ /* poolblocks is the number of digests which make up the pool * and poolsize must be a multiple of the digest length * to make the AND operations faster, the size should also be * a multiple of ulong */ #define POOLBLOCKS 30 #define POOLSIZE (POOLBLOCKS*DIGESTLEN) #if (POOLSIZE % SIZEOF_UNSIGNED_LONG) #error Please make sure that poolsize is a multiple of ulong #endif #define POOLWORDS (POOLSIZE / SIZEOF_UNSIGNED_LONG) static int is_initialized; -static int allow_daemon; /* If true, try to use the daemon first. */ + #define MASK_LEVEL(a) do { (a) &= 3; } while(0) static unsigned char *rndpool; /* Allocated size is POOLSIZE+BLOCKLEN. */ static unsigned char *keypool; /* Allocated size is POOLSIZE+BLOCKLEN. */ static size_t pool_readpos; static size_t pool_writepos; static int pool_filled; static int pool_balance; static int just_mixed; static int did_initial_extra_seeding; static char *seed_file_name; -static char *daemon_socket_name; static int allow_seed_file_update; +#ifdef USE_RANDOM_DAEMON +static int allow_daemon; /* If true, try to use the daemon first. */ +static char *daemon_socket_name; /* User supplied name of the socket. */ +#endif /*USE_RANDOM_DAEMON*/ + static int secure_alloc; static int quick_test; static int faked_rng; static ath_mutex_t pool_lock = ATH_MUTEX_INITIALIZER; static int pool_is_locked; /* only used for assertion */ static ath_mutex_t nonce_buffer_lock = ATH_MUTEX_INITIALIZER; static byte *get_random_bytes( size_t nbytes, int level, int secure ); static void read_pool( byte *buffer, size_t length, int level ); static void add_randomness( const void *buffer, size_t length, int source ); static void random_poll(void); static void do_fast_random_poll (void); static void read_random_source( int requester, size_t length, int level); static int gather_faked( void (*add)(const void*, size_t, int), int requester, size_t length, int level ); static struct { ulong mixrnd; ulong mixkey; ulong slowpolls; ulong fastpolls; ulong getbytes1; ulong ngetbytes1; ulong getbytes2; ulong ngetbytes2; ulong addbytes; ulong naddbytes; } rndstats; static void (*progress_cb) (void *,const char*,int,int, int ); static void *progress_cb_data; /* Note, we assume that this function is used before any concurrent access happens. */ static void initialize_basics(void) { static int initialized; int err; if (!initialized) { initialized = 1; err = ath_mutex_init (&pool_lock); if (err) log_fatal ("failed to create the pool lock: %s\n", strerror (err) ); err = ath_mutex_init (&nonce_buffer_lock); if (err) log_fatal ("failed to create the nonce buffer lock: %s\n", strerror (err) ); +#ifdef USE_RANDOM_DAEMON _gcry_daemon_initialize_basics (); +#endif /*USE_RANDOM_DAEMON*/ } } static void initialize(void) { initialize_basics (); /* The data buffer is allocated somewhat larger, so that we can use this extra space (which is allocated in secure memory) as a temporary hash buffer */ rndpool = secure_alloc ? gcry_xcalloc_secure(1,POOLSIZE+BLOCKLEN) : gcry_xcalloc(1,POOLSIZE+BLOCKLEN); keypool = secure_alloc ? gcry_xcalloc_secure(1,POOLSIZE+BLOCKLEN) : gcry_xcalloc(1,POOLSIZE+BLOCKLEN); is_initialized = 1; } /* Used to register a progress callback. */ void _gcry_register_random_progress (void (*cb)(void *,const char*,int,int,int), void *cb_data ) { progress_cb = cb; progress_cb_data = cb_data; } /* This progress function is currently used by the random modules to give hint on how much more entropy is required. */ void _gcry_random_progress (const char *what, int printchar, int current, int total) { if (progress_cb) progress_cb (progress_cb_data, what, printchar, current, total); } /* Initialize this random subsystem. If FULL is false, this function merely calls the initialize and does not do anything more. Doing this is not really required but when running in a threaded environment we might get a race condition otherwise. */ void _gcry_random_initialize (int full) { if (!full) initialize_basics (); else if (!is_initialized) initialize (); } void _gcry_random_dump_stats() { /* FIXME: don't we need proper locking here? -mo */ log_info ( "random usage: poolsize=%d mixed=%lu polls=%lu/%lu added=%lu/%lu\n" " outmix=%lu getlvl1=%lu/%lu getlvl2=%lu/%lu\n", POOLSIZE, rndstats.mixrnd, rndstats.slowpolls, rndstats.fastpolls, rndstats.naddbytes, rndstats.addbytes, rndstats.mixkey, rndstats.ngetbytes1, rndstats.getbytes1, rndstats.ngetbytes2, rndstats.getbytes2 ); } void _gcry_secure_random_alloc() { secure_alloc = 1; } int _gcry_quick_random_gen( int onoff ) { int last; /* No need to lock it here because we are only initializing. A prerequisite of the entire code is that it has already been initialized before any possible concurrent access */ read_random_source(0,0,0); /* init */ last = quick_test; if( onoff != -1 ) quick_test = onoff; return faked_rng? 1 : last; } void _gcry_set_random_daemon_socket (const char *socketname) { +#ifdef USE_RANDOM_DAEMON if (daemon_socket_name) BUG (); daemon_socket_name = gcry_xstrdup (socketname); +#else /*!USE_RANDOM_DAEMON*/ + (void)socketname; +#endif /*!USE_RANDOM_DAEMON*/ } /* With ONOFF set to 1, enable the use of the daemon. With ONOFF set to 0, disable the use of the daemon. With ONOF set to -1, return whether the daemon has been enabled. */ int _gcry_use_random_daemon (int onoff) { +#ifdef USE_RANDOM_DAEMON int last; /* FIXME: This is not really thread safe. */ last = allow_daemon; if (onoff != -1) allow_daemon = onoff; return last; +#else /*!USE_RANDOM_DAEMON*/ + (void)onoff; + return 0; +#endif /*!USE_RANDOM_DAEMON*/ } int _gcry_random_is_faked() { if( !is_initialized ) initialize(); return (faked_rng || quick_test); } /* * Return a pointer to a randomized buffer of LEVEL and NBYTES length. * Caller must free the buffer. */ static byte * get_random_bytes ( size_t nbytes, int level, int secure) { byte *buf, *p; int err; /* First a hack to avoid the strong random using our regression test suite. */ if (quick_test && level > 1) level = 1; /* Make sure the requested level is in range. */ MASK_LEVEL(level); +#ifdef USE_RANDOM_DAEMON if (allow_daemon && (p=_gcry_daemon_get_random_bytes (daemon_socket_name, nbytes, level,secure))) return p; /* The daemon succeeded. */ allow_daemon = 0; /* Daemon failed - switch off. */ +#endif /*USE_RANDOM_DAEMON*/ /* Lock the pool. */ err = ath_mutex_lock (&pool_lock); if (err) log_fatal ("failed to acquire the pool lock: %s\n", strerror (err)); pool_is_locked = 1; /* Keep some statistics. */ if (level >= 2) { rndstats.getbytes2 += nbytes; rndstats.ngetbytes2++; } else { rndstats.getbytes1 += nbytes; rndstats.ngetbytes1++; } /* Allocate the return buffer. */ buf = secure && secure_alloc ? gcry_xmalloc_secure( nbytes ) : gcry_xmalloc( nbytes ); /* Fill that buffer with random. */ for (p = buf; nbytes > 0; ) { size_t n; n = nbytes > POOLSIZE? POOLSIZE : nbytes; read_pool( p, n, level ); nbytes -= n; p += n; } /* Release the pool lock. */ pool_is_locked = 0; err = ath_mutex_unlock (&pool_lock); if (err) log_fatal ("failed to release the pool lock: %s\n", strerror (err)); /* Return the buffer. */ return buf; } /* Add BUFLEN bytes from BUF to the internal random pool. QUALITY should be in the range of 0..100 to indicate the goodness of the entropy added, or -1 for goodness not known. Note, that this function currently does nothing. */ gcry_error_t gcry_random_add_bytes (const void * buf, size_t buflen, int quality) { gcry_err_code_t err = GPG_ERR_NO_ERROR; if (!buf || quality < -1 || quality > 100) err = GPG_ERR_INV_ARG; if (!buflen) return 0; /* Shortcut this dummy case. */ #if 0 /* Before we actuall enable this code, we need to lock the pool, have a look at the quality and find a way to add them without disturbing the real entropy (we have estimated). */ /*add_randomness( buf, buflen, 1 );*/ #endif return err; } /* The public function to return random data of the quality LEVEL. */ void * gcry_random_bytes( size_t nbytes, enum gcry_random_level level ) { if (!is_initialized) initialize(); return get_random_bytes( nbytes, level, 0 ); } /* The public function to return random data of the quality LEVEL; this version of the function return the random a buffer allocated in secure memory. */ void * gcry_random_bytes_secure( size_t nbytes, enum gcry_random_level level ) { if (!is_initialized) initialize(); return get_random_bytes( nbytes, level, 1 ); } /* Public function to fill the buffer with LENGTH bytes of cryptographically strong random bytes. level 0 is not very strong, 1 is strong enough for most usage, 2 is good for key generation stuff but may be very slow. */ void gcry_randomize (void *buffer, size_t length, enum gcry_random_level level) { unsigned char *p; int err; /* Make sure we are initialized. */ if (!is_initialized) initialize (); /* Handle our hack used for regression tests of Libgcrypt. */ if( quick_test && level > 1 ) level = 1; /* Make sure the level is okay. */ MASK_LEVEL(level); +#ifdef USE_RANDOM_DAEMON if (allow_daemon && !_gcry_daemon_randomize (daemon_socket_name, buffer, length, level)) return; /* The daemon succeeded. */ allow_daemon = 0; /* Daemon failed - switch off. */ +#endif /*USE_RANDOM_DAEMON*/ /* Acquire the pool lock. */ err = ath_mutex_lock (&pool_lock); if (err) log_fatal ("failed to acquire the pool lock: %s\n", strerror (err)); pool_is_locked = 1; /* Update the statistics. */ if (level >= 2) { rndstats.getbytes2 += length; rndstats.ngetbytes2++; } else { rndstats.getbytes1 += length; rndstats.ngetbytes1++; } /* Read the random into the provided buffer. */ for (p = buffer; length > 0;) { size_t n; n = length > POOLSIZE? POOLSIZE : length; read_pool (p, n, level); length -= n; p += n; } /* Release the pool lock. */ pool_is_locked = 0; err = ath_mutex_unlock (&pool_lock); if (err) log_fatal ("failed to release the pool lock: %s\n", strerror (err)); } /* Mix the pool: |........blocks*20byte........|20byte|..44byte..| <..44byte..> <20byte> | | | +------+ +---------------------------|----------+ v v |........blocks*20byte........|20byte|..44byte..| <.....64bytes.....> | +----------------------------------+ Hash v |.............................|20byte|..44byte..| <20byte><20byte><..44byte..> | | | +---------------------+ +-----------------------------+ | v v |.............................|20byte|..44byte..| <.....64byte......> | +-------------------------+ Hash v |.............................|20byte|..44byte..| <20byte><20byte><..44byte..> and so on until we did this for all blocks. To better protect against implementation errors in this code, we xor a digest of the entire pool into the pool before mixing. Note: this function must only be called with a locked pool. */ static void mix_pool(unsigned char *pool) { static unsigned char failsafe_digest[DIGESTLEN]; static int failsafe_digest_valid; unsigned char *hashbuf = pool + POOLSIZE; unsigned char *p, *pend; int i, n; RMD160_CONTEXT md; #if DIGESTLEN != 20 #error must have a digest length of 20 for ripe-md-160 #endif assert (pool_is_locked); _gcry_rmd160_init( &md ); /* Loop over the pool. */ pend = pool + POOLSIZE; memcpy(hashbuf, pend - DIGESTLEN, DIGESTLEN ); memcpy(hashbuf+DIGESTLEN, pool, BLOCKLEN-DIGESTLEN); _gcry_rmd160_mixblock( &md, hashbuf); memcpy(pool, hashbuf, 20 ); if (failsafe_digest_valid && pool == rndpool) { for (i=0; i < 20; i++) pool[i] ^= failsafe_digest[i]; } p = pool; for (n=1; n < POOLBLOCKS; n++) { memcpy (hashbuf, p, DIGESTLEN); p += DIGESTLEN; if (p+DIGESTLEN+BLOCKLEN < pend) memcpy (hashbuf+DIGESTLEN, p+DIGESTLEN, BLOCKLEN-DIGESTLEN); else { unsigned char *pp = p + DIGESTLEN; for (i=DIGESTLEN; i < BLOCKLEN; i++ ) { if ( pp >= pend ) pp = pool; hashbuf[i] = *pp++; } } _gcry_rmd160_mixblock ( &md, hashbuf); memcpy(p, hashbuf, 20 ); } /* Our hash implementation does only leave small parts (64 bytes) of the pool on the stack, so it is okay not to require secure memory here. Before we use this pool, it will be copied to the help buffer anyway. */ if ( pool == rndpool) { _gcry_rmd160_hash_buffer (failsafe_digest, pool, POOLSIZE); failsafe_digest_valid = 1; } _gcry_burn_stack (384); /* for the rmd160_mixblock(), rmd160_hash_buffer */ } void _gcry_set_random_seed_file( const char *name ) { if (seed_file_name) BUG (); seed_file_name = gcry_xstrdup (name); } /* Lock an open file identified by file descriptor FD and wait a reasonable time to succeed. With FOR_WRITE set to true a write lock will be taken. FNAME is used only for diagnostics. Returns 0 on success or -1 on error. */ static int lock_seed_file (int fd, const char *fname, int for_write) { #if LOCK_SEED_FILE struct flock lck; struct timeval tv; int backoff=0; /* We take a lock on the entire file. */ memset (&lck, 0, sizeof lck); lck.l_type = for_write? F_WRLCK : F_RDLCK; lck.l_whence = SEEK_SET; while (fcntl (fd, F_SETLK, &lck) == -1) { if (errno != EAGAIN && errno != EACCES) { log_info (_("can't lock `%s': %s\n"), fname, strerror (errno)); return -1; } if (backoff > 2) /* Show the first message after ~2.25 seconds. */ log_info( _("waiting for lock on `%s'...\n"), fname); tv.tv_sec = backoff; tv.tv_usec = 250000; select (0, NULL, NULL, NULL, &tv); if (backoff < 10) backoff++ ; } #endif /*LOCK_SEED_FILE*/ return 0; } /* Read in a seed form the random_seed file and return true if this was successful. */ static int read_seed_file (void) { int fd; struct stat sb; unsigned char buffer[POOLSIZE]; int n; assert (pool_is_locked); if (!seed_file_name) return 0; #ifdef HAVE_DOSISH_SYSTEM fd = open( seed_file_name, O_RDONLY | O_BINARY ); #else fd = open( seed_file_name, O_RDONLY ); #endif if( fd == -1 && errno == ENOENT) { allow_seed_file_update = 1; return 0; } if (fd == -1 ) { log_info(_("can't open `%s': %s\n"), seed_file_name, strerror(errno) ); return 0; } if (lock_seed_file (fd, seed_file_name, 0)) { close (fd); return 0; } if (fstat( fd, &sb ) ) { log_info(_("can't stat `%s': %s\n"), seed_file_name, strerror(errno) ); close(fd); return 0; } if (!S_ISREG(sb.st_mode) ) { log_info(_("`%s' is not a regular file - ignored\n"), seed_file_name ); close(fd); return 0; } if (!sb.st_size ) { log_info(_("note: random_seed file is empty\n") ); close(fd); allow_seed_file_update = 1; return 0; } if (sb.st_size != POOLSIZE ) { log_info(_("warning: invalid size of random_seed file - not used\n") ); close(fd); return 0; } do { n = read( fd, buffer, POOLSIZE ); } while (n == -1 && errno == EINTR ); if (n != POOLSIZE) { log_fatal(_("can't read `%s': %s\n"), seed_file_name,strerror(errno) ); close(fd);/*NOTREACHED*/ return 0; } close(fd); add_randomness( buffer, POOLSIZE, 0 ); /* add some minor entropy to the pool now (this will also force a mixing) */ { pid_t x = getpid(); add_randomness( &x, sizeof(x), 0 ); } { time_t x = time(NULL); add_randomness( &x, sizeof(x), 0 ); } { clock_t x = clock(); add_randomness( &x, sizeof(x), 0 ); } /* And read a few bytes from our entropy source. By using a level * of 0 this will not block and might not return anything with some * entropy drivers, however the rndlinux driver will use * /dev/urandom and return some stuff - Do not read to much as we * want to be friendly to the scare system entropy resource. */ read_random_source( 0, 16, 0 ); allow_seed_file_update = 1; return 1; } void _gcry_update_random_seed_file() { ulong *sp, *dp; int fd, i; int err; if ( !seed_file_name || !is_initialized || !pool_filled ) return; if ( !allow_seed_file_update ) { log_info(_("note: random_seed file not updated\n")); return; } err = ath_mutex_lock (&pool_lock); if (err) log_fatal ("failed to acquire the pool lock: %s\n", strerror (err)); pool_is_locked = 1; /* Copy the entropy pool to a scratch pool and mix both of them. */ for (i=0,dp=(ulong*)keypool, sp=(ulong*)rndpool; i < POOLWORDS; i++, dp++, sp++ ) { *dp = *sp + ADD_VALUE; } mix_pool(rndpool); rndstats.mixrnd++; mix_pool(keypool); rndstats.mixkey++; #if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__) fd = open (seed_file_name, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IRUSR|S_IWUSR ); #else # if LOCK_SEED_FILE fd = open (seed_file_name, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR ); # else fd = open (seed_file_name, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR ); # endif #endif if (fd == -1 ) log_info (_("can't create `%s': %s\n"), seed_file_name, strerror(errno) ); else if (lock_seed_file (fd, seed_file_name, 1)) { close (fd); } #if LOCK_SEED_FILE else if (ftruncate (fd, 0)) { log_info(_("can't write `%s': %s\n"), seed_file_name, strerror(errno)); close (fd); } #endif /*LOCK_SEED_FILE*/ else { do { i = write (fd, keypool, POOLSIZE ); } while (i == -1 && errno == EINTR); if (i != POOLSIZE) log_info (_("can't write `%s': %s\n"),seed_file_name, strerror(errno)); if (close(fd)) log_info (_("can't close `%s': %s\n"),seed_file_name, strerror(errno)); } pool_is_locked = 0; err = ath_mutex_unlock (&pool_lock); if (err) log_fatal ("failed to release the pool lock: %s\n", strerror (err)); } /* Read random out of the pool. This function is the core of the public random functions. Note that Level 0 is not anymore handeld special and in fact an alias for level 1. Must be called with the pool already locked. */ static void read_pool (byte *buffer, size_t length, int level) { int i; unsigned long *sp, *dp; /* The volatile is there to make sure the compiler does not optimize the code away in case the getpid function is badly attributed. Note that we keep a pid in a static variable as well as in a stack based one; the latter is to detect ill behaving thread libraries, ignoring the pool mutexes. */ static volatile pid_t my_pid = (pid_t)(-1); volatile pid_t my_pid2; retry: /* Get our own pid, so that we can detect a fork. */ my_pid2 = getpid (); if (my_pid == (pid_t)(-1)) my_pid = my_pid2; if ( my_pid != my_pid2 ) { /* We detected a plain fork; i.e. we are now the child. Update the static pid and add some randomness. */ pid_t x; my_pid = my_pid2; x = my_pid; add_randomness (&x, sizeof(x), 0); just_mixed = 0; /* Make sure it will get mixed. */ } assert (pool_is_locked); /* Our code does not allow to extract more than POOLSIZE. Better check it here. */ if (length > POOLSIZE) { log_bug("too many random bits requested\n"); } if (!pool_filled) { if (read_seed_file() ) pool_filled = 1; } /* For level 2 quality (key generation) we always make sure that the pool has been seeded enough initially. */ if (level == 2 && !did_initial_extra_seeding) { size_t needed; pool_balance = 0; needed = length - pool_balance; if (needed < POOLSIZE/2) needed = POOLSIZE/2; else if( needed > POOLSIZE ) BUG (); read_random_source (3, needed, 2); pool_balance += needed; did_initial_extra_seeding = 1; } /* For level 2 make sure that there is enough random in the pool. */ if (level == 2 && pool_balance < length) { size_t needed; if (pool_balance < 0) pool_balance = 0; needed = length - pool_balance; if (needed > POOLSIZE) BUG (); read_random_source( 3, needed, 2 ); pool_balance += needed; } /* Make sure the pool is filled. */ while (!pool_filled) random_poll(); /* Always do a fast random poll (we have to use the unlocked version). */ do_fast_random_poll(); /* Mix the pid in so that we for sure won't deliver the same random after a fork. */ { pid_t apid = my_pid; add_randomness (&apid, sizeof (apid), 0); } /* Mix the pool (if add_randomness() didn't it). */ if (!just_mixed) { mix_pool(rndpool); rndstats.mixrnd++; } /* Create a new pool. */ for(i=0,dp=(ulong*)keypool, sp=(ulong*)rndpool; i < POOLWORDS; i++, dp++, sp++ ) *dp = *sp + ADD_VALUE; /* Mix both pools. */ mix_pool(rndpool); rndstats.mixrnd++; mix_pool(keypool); rndstats.mixkey++; /* Read the requested data. We use a read pointer to read from a different position each time. */ while (length--) { *buffer++ = keypool[pool_readpos++]; if (pool_readpos >= POOLSIZE) pool_readpos = 0; pool_balance--; } if (pool_balance < 0) pool_balance = 0; /* Clear the keypool. */ memset (keypool, 0, POOLSIZE); /* We need to detect whether a fork has happened. A fork might have an identical pool and thus the child and the parent could emit the very same random number. This test here is to detect forks in a multi-threaded process. */ if ( getpid () != my_pid2 ) { pid_t x = getpid(); add_randomness (&x, sizeof(x), 0); just_mixed = 0; /* Make sure it will get mixed. */ my_pid = x; /* Also update the static pid. */ goto retry; } } /* * Add LENGTH bytes of randomness from buffer to the pool. * source may be used to specify the randomness source. * Source is: * 0 - used ony for initialization * 1 - fast random poll function * 2 - normal poll function * 3 - used when level 2 random quality has been requested * to do an extra pool seed. */ static void add_randomness( const void *buffer, size_t length, int source ) { const byte *p = buffer; assert (pool_is_locked); if (!is_initialized) initialize (); rndstats.addbytes += length; rndstats.naddbytes++; while (length-- ) { rndpool[pool_writepos++] ^= *p++; if (pool_writepos >= POOLSIZE ) { if (source > 1) pool_filled = 1; pool_writepos = 0; mix_pool(rndpool); rndstats.mixrnd++; just_mixed = !length; } } } static void random_poll() { rndstats.slowpolls++; read_random_source (2, POOLSIZE/5, 1); } static int (* getfnc_gather_random (void))(void (*)(const void*, size_t, int), int, size_t, int) { static int (*fnc)(void (*)(const void*, size_t, int), int, size_t, int); if (fnc) return fnc; #if USE_RNDLINUX if ( !access (NAME_OF_DEV_RANDOM, R_OK) && !access (NAME_OF_DEV_URANDOM, R_OK)) { fnc = _gcry_rndlinux_gather_random; return fnc; } #endif #if USE_RNDEGD if ( _gcry_rndegd_connect_socket (1) != -1 ) { fnc = _gcry_rndegd_gather_random; return fnc; } #endif #if USE_RNDUNIX fnc = _gcry_rndunix_gather_random; return fnc; #endif #if USE_RNDW32 fnc = _gcry_rndw32_gather_random; return fnc; #endif log_fatal (_("no entropy gathering module detected\n")); return NULL; /*NOTREACHED*/ } static void (* getfnc_fast_random_poll (void))( void (*)(const void*, size_t, int), int) { #if USE_RNDW32 return _gcry_rndw32_gather_random_fast; #endif return NULL; } static void do_fast_random_poll (void) { static void (*fnc)( void (*)(const void*, size_t, int), int) = NULL; static int initialized = 0; assert (pool_is_locked); rndstats.fastpolls++; if (!initialized ) { if (!is_initialized ) initialize(); initialized = 1; fnc = getfnc_fast_random_poll (); } if (fnc) (*fnc)( add_randomness, 1 ); /* Continue with the generic functions. */ #if HAVE_GETHRTIME { hrtime_t tv; tv = gethrtime(); add_randomness( &tv, sizeof(tv), 1 ); } #elif HAVE_GETTIMEOFDAY { struct timeval tv; if( gettimeofday( &tv, NULL ) ) BUG(); add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 ); add_randomness( &tv.tv_usec, sizeof(tv.tv_usec), 1 ); } #elif HAVE_CLOCK_GETTIME { struct timespec tv; if( clock_gettime( CLOCK_REALTIME, &tv ) == -1 ) BUG(); add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 ); add_randomness( &tv.tv_nsec, sizeof(tv.tv_nsec), 1 ); } #else /* use times */ # ifndef HAVE_DOSISH_SYSTEM { struct tms buf; times( &buf ); add_randomness( &buf, sizeof buf, 1 ); } # endif #endif #ifdef HAVE_GETRUSAGE # ifdef RUSAGE_SELF { struct rusage buf; /* QNX/Neutrino does return ENOSYS - so we just ignore it and * add whatever is in buf. In a chroot environment it might not * work at all (i.e. because /proc/ is not accessible), so we better * ugnore all error codes and hope for the best */ getrusage (RUSAGE_SELF, &buf ); add_randomness( &buf, sizeof buf, 1 ); memset( &buf, 0, sizeof buf ); } # else /*!RUSAGE_SELF*/ # ifdef __GCC__ # warning There is no RUSAGE_SELF on this system # endif # endif /*!RUSAGE_SELF*/ #endif /*HAVE_GETRUSAGE*/ /* time and clock are availabe on all systems - so we better do it just in case one of the above functions didn't work */ { time_t x = time(NULL); add_randomness( &x, sizeof(x), 1 ); } { clock_t x = clock(); add_randomness( &x, sizeof(x), 1 ); } } /* The fast random pool function as called at some places in libgcrypt. This is merely a wrapper to make sure that this module is initalized and to look the pool. Note, that this function is a NOP unless a random function has been used or _gcry_initialize (1) has been used. We use this hack so that the internal use of this function in cipher_open and md_open won't start filling up the radnom pool, even if no random will be required by the process. */ void _gcry_fast_random_poll (void) { int err; if (!is_initialized) return; err = ath_mutex_lock (&pool_lock); if (err) log_fatal ("failed to acquire the pool lock: %s\n", strerror (err)); pool_is_locked = 1; do_fast_random_poll (); pool_is_locked = 0; err = ath_mutex_unlock (&pool_lock); if (err) log_fatal ("failed to acquire the pool lock: %s\n", strerror (err)); } static void read_random_source( int requester, size_t length, int level ) { static int (*fnc)(void (*)(const void*, size_t, int), int, size_t, int) = NULL; if (!fnc ) { if (!is_initialized ) initialize(); fnc = getfnc_gather_random (); if (!fnc) { faked_rng = 1; fnc = gather_faked; } if (!requester && !length && !level) return; /* Just the init was requested. */ } if ((*fnc)( add_randomness, requester, length, level ) < 0) log_fatal ("No way to gather entropy for the RNG\n"); } static int gather_faked( void (*add)(const void*, size_t, int), int requester, size_t length, int level ) { static int initialized=0; size_t n; char *buffer, *p; (void)add; (void)level; if( !initialized ) { log_info(_("WARNING: using insecure random number generator!!\n")); /* we can't use tty_printf here - do we need this function at all - does it really make sense or canit be viewed as a potential security problem ? wk 17.11.99 */ #if 0 tty_printf(_("The random number generator is only a kludge to let\n" "it run - it is in no way a strong RNG!\n\n" "DON'T USE ANY DATA GENERATED BY THIS PROGRAM!!\n\n")); #endif initialized=1; #ifdef HAVE_RAND srand( time(NULL)*getpid()); #else srandom( time(NULL)*getpid()); #endif } p = buffer = gcry_xmalloc( length ); n = length; #ifdef HAVE_RAND while( n-- ) *p++ = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1); #else while( n-- ) *p++ = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1); #endif add_randomness( buffer, length, requester ); gcry_free(buffer); return 0; /* okay */ } /* Create an unpredicable nonce of LENGTH bytes in BUFFER. */ void gcry_create_nonce (void *buffer, size_t length) { static unsigned char nonce_buffer[20+8]; static int nonce_buffer_initialized = 0; static volatile pid_t my_pid; /* The volatile is there to make sure the compiler does not optimize the code away in case the getpid function is badly attributed. */ volatile pid_t apid; unsigned char *p; size_t n; int err; /* Make sure we are initialized. */ if (!is_initialized) initialize (); +#ifdef USE_RANDOM_DAEMON if (allow_daemon && !_gcry_daemon_create_nonce (daemon_socket_name, buffer, length)) return; /* The daemon succeeded. */ allow_daemon = 0; /* Daemon failed - switch off. */ +#endif /*USE_RANDOM_DAEMON*/ /* Acquire the nonce buffer lock. */ err = ath_mutex_lock (&nonce_buffer_lock); if (err) log_fatal ("failed to acquire the nonce buffer lock: %s\n", strerror (err)); apid = getpid (); /* The first time intialize our buffer. */ if (!nonce_buffer_initialized) { time_t atime = time (NULL); pid_t xpid = apid; my_pid = apid; if ((sizeof apid + sizeof atime) > sizeof nonce_buffer) BUG (); /* Initialize the first 20 bytes with a reasonable value so that a failure of gcry_randomize won't affect us too much. Don't care about the uninitialized remaining bytes. */ p = nonce_buffer; memcpy (p, &xpid, sizeof xpid); p += sizeof xpid; memcpy (p, &atime, sizeof atime); /* Initialize the never changing private part of 64 bits. */ gcry_randomize (nonce_buffer+20, 8, GCRY_WEAK_RANDOM); nonce_buffer_initialized = 1; } else if ( my_pid != apid ) { /* We forked. Need to reseed the buffer - doing this for the private part should be sufficient. */ gcry_randomize (nonce_buffer+20, 8, GCRY_WEAK_RANDOM); /* Update the pid so that we won't run into here again and again. */ my_pid = apid; } /* Create the nonce by hashing the entire buffer, returning the hash and updating the first 20 bytes of the buffer with this hash. */ for (p = buffer; length > 0; length -= n, p += n) { _gcry_sha1_hash_buffer (nonce_buffer, nonce_buffer, sizeof nonce_buffer); n = length > 20? 20 : length; memcpy (p, nonce_buffer, n); } /* Release the nonce buffer lock. */ err = ath_mutex_unlock (&nonce_buffer_lock); if (err) log_fatal ("failed to release the nonce buffer lock: %s\n", strerror (err)); } diff --git a/cipher/random.h b/cipher/random.h index 25f96254..ed330b62 100644 --- a/cipher/random.h +++ b/cipher/random.h @@ -1,55 +1,56 @@ /* random.h - random functions * Copyright (C) 1998, 2002, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifndef G10_RANDOM_H #define G10_RANDOM_H #include "types.h" void _gcry_random_initialize (int full); void _gcry_register_random_progress (void (*cb)(void *,const char*,int,int,int), void *cb_data ); void _gcry_random_dump_stats(void); void _gcry_secure_random_alloc(void); int _gcry_quick_random_gen( int onoff ); int _gcry_random_is_faked(void); void _gcry_set_random_daemon_socket (const char *socketname); int _gcry_use_random_daemon (int onoff); void _gcry_set_random_seed_file (const char *name); void _gcry_update_random_seed_file (void); byte *_gcry_get_random_bits( size_t nbits, int level, int secure ); void _gcry_fast_random_poll( void ); /*-- random-daemon.c (only used from random.c) --*/ +#ifdef USE_RANDOM_DAEMON void _gcry_daemon_initialize_basics (void); int _gcry_daemon_randomize (const char *socketname, void *buffer, size_t length, enum gcry_random_level level); void *_gcry_daemon_get_random_bytes (const char *socketname, size_t nbytes, int level, int secure); int _gcry_daemon_create_nonce (const char *socketname, void *buffer, size_t length); - +#endif /*USE_RANDOM_DAEMON*/ #endif /*G10_RANDOM_H*/ diff --git a/cipher/rndw32.c b/cipher/rndw32.c index 994fdb15..1c2ff208 100644 --- a/cipher/rndw32.c +++ b/cipher/rndw32.c @@ -1,683 +1,681 @@ /* rndw32.c - W32 entropy gatherer * Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc. * Copyright Peter Gutmann, Matt Thomlinson and Blake Coverett 1996-1999 * * This file is part of Libgcrypt. * ************************************************************************* * The code here is based on code from Cryptlib 3.0 beta by Peter Gutmann. * Source file misc/rndwin32.c "Win32 Randomness-Gathering Code" with this * copyright notice: * * This module is part of the cryptlib continuously seeded pseudorandom * number generator. For usage conditions, see lib_rand.c * * [Here is the notice from lib_rand.c, which is now called dev_sys.c] * * This module and the misc/rnd*.c modules represent the cryptlib * continuously seeded pseudorandom number generator (CSPRNG) as described in * my 1998 Usenix Security Symposium paper "The generation of random numbers * for cryptographic purposes". * * The CSPRNG code is copyright Peter Gutmann (and various others) 1996, * 1997, 1998, 1999, all rights reserved. Redistribution of the CSPRNG * modules and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice * and this permission notice in its entirety. * * 2. Redistributions in binary form must reproduce the copyright notice in * the documentation and/or other materials provided with the distribution. * * 3. A copy of any bugfixes or enhancements made must be provided to the * author, to allow them to be added to the * baseline version of the code. * * ALTERNATIVELY, the code may be distributed under the terms of the GNU * General Public License, version 2 or any later version published by the * Free Software Foundation, in which case the provisions of the GNU GPL are * required INSTEAD OF the above restrictions. * * Although not required under the terms of the GPL, it would still be nice if * you could make any changes available to the author to allow a consistent * code base to be maintained ************************************************************************* */ #include #include #include #include #include #include #include #include "types.h" #include "g10lib.h" #include "rand-internal.h" static int debug_me; /* * Definitions which are missing from the current GNU Windows32Api */ #ifndef TH32CS_SNAPHEAPLIST #define TH32CS_SNAPHEAPLIST 1 #define TH32CS_SNAPPROCESS 2 #define TH32CS_SNAPTHREAD 4 #define TH32CS_SNAPMODULE 8 #define TH32CS_SNAPALL (1|2|4|8) #define TH32CS_INHERIT 0x80000000 #endif /*TH32CS_SNAPHEAPLIST*/ #ifndef IOCTL_DISK_PERFORMANCE #define IOCTL_DISK_PERFORMANCE 0x00070020 #endif #ifndef VER_PLATFORM_WIN32_WINDOWS #define VER_PLATFORM_WIN32_WINDOWS 1 #endif /* This used to be (6*8+5*4+8*2), but Peter Gutmann figured a larger value in a newer release. So we use a far larger value. */ #define SIZEOF_DISK_PERFORMANCE_STRUCT 256 typedef struct { DWORD dwSize; DWORD th32ProcessID; DWORD th32HeapID; DWORD dwFlags; } HEAPLIST32; typedef struct { DWORD dwSize; HANDLE hHandle; DWORD dwAddress; DWORD dwBlockSize; DWORD dwFlags; DWORD dwLockCount; DWORD dwResvd; DWORD th32ProcessID; DWORD th32HeapID; } HEAPENTRY32; typedef struct { DWORD dwSize; DWORD cntUsage; DWORD th32ProcessID; DWORD th32DefaultHeapID; DWORD th32ModuleID; DWORD cntThreads; DWORD th32ParentProcessID; LONG pcPriClassBase; DWORD dwFlags; char szExeFile[260]; } PROCESSENTRY32; typedef struct { DWORD dwSize; DWORD cntUsage; DWORD th32ThreadID; DWORD th32OwnerProcessID; LONG tpBasePri; LONG tpDeltaPri; DWORD dwFlags; } THREADENTRY32; typedef struct { DWORD dwSize; DWORD th32ModuleID; DWORD th32ProcessID; DWORD GlblcntUsage; DWORD ProccntUsage; BYTE *modBaseAddr; DWORD modBaseSize; HMODULE hModule; char szModule[256]; char szExePath[260]; } MODULEENTRY32; /* Type definitions for function pointers to call Toolhelp32 functions * used with the windows95 gatherer */ typedef BOOL (WINAPI * MODULEWALK) (HANDLE hSnapshot, MODULEENTRY32 *lpme); typedef BOOL (WINAPI * THREADWALK) (HANDLE hSnapshot, THREADENTRY32 *lpte); typedef BOOL (WINAPI * PROCESSWALK) (HANDLE hSnapshot, PROCESSENTRY32 *lppe); typedef BOOL (WINAPI * HEAPLISTWALK) (HANDLE hSnapshot, HEAPLIST32 *lphl); typedef BOOL (WINAPI * HEAPFIRST) (HEAPENTRY32 *lphe, DWORD th32ProcessID, DWORD th32HeapID); typedef BOOL (WINAPI * HEAPNEXT) (HEAPENTRY32 *lphe); typedef HANDLE (WINAPI * CREATESNAPSHOT) (DWORD dwFlags, DWORD th32ProcessID); /* Type definitions for function pointers to call NetAPI32 functions */ typedef DWORD (WINAPI * NETSTATISTICSGET) (LPWSTR szServer, LPWSTR szService, DWORD dwLevel, DWORD dwOptions, LPBYTE * lpBuffer); typedef DWORD (WINAPI * NETAPIBUFFERSIZE) (LPVOID lpBuffer, LPDWORD cbBuffer); typedef DWORD (WINAPI * NETAPIBUFFERFREE) (LPVOID lpBuffer); /* When we query the performance counters, we allocate an initial buffer and * then reallocate it as required until RegQueryValueEx() stops returning * ERROR_MORE_DATA. The following values define the initial buffer size and * step size by which the buffer is increased */ #define PERFORMANCE_BUFFER_SIZE 65536 /* Start at 64K */ #define PERFORMANCE_BUFFER_STEP 16384 /* Step by 16K */ static void slow_gatherer_windows95( void (*add)(const void*, size_t, int), int requester ) { static CREATESNAPSHOT pCreateToolhelp32Snapshot = NULL; static MODULEWALK pModule32First = NULL; static MODULEWALK pModule32Next = NULL; static PROCESSWALK pProcess32First = NULL; static PROCESSWALK pProcess32Next = NULL; static THREADWALK pThread32First = NULL; static THREADWALK pThread32Next = NULL; static HEAPLISTWALK pHeap32ListFirst = NULL; static HEAPLISTWALK pHeap32ListNext = NULL; static HEAPFIRST pHeap32First = NULL; static HEAPNEXT pHeap32Next = NULL; HANDLE hSnapshot; /* initialize the Toolhelp32 function pointers */ if ( !pCreateToolhelp32Snapshot ) { HANDLE hKernel; if ( debug_me ) log_debug ("rndw32#slow_gatherer_95: init toolkit\n" ); /* Obtain the module handle of the kernel to retrieve the addresses * of the Toolhelp32 functions */ if ( ( !(hKernel = GetModuleHandle ("KERNEL32.DLL"))) ) { log_fatal ( "rndw32: can't get module handle\n" ); } /* Now get pointers to the functions */ pCreateToolhelp32Snapshot = (CREATESNAPSHOT) GetProcAddress (hKernel, "CreateToolhelp32Snapshot"); pModule32First = (MODULEWALK) GetProcAddress (hKernel, "Module32First"); pModule32Next = (MODULEWALK) GetProcAddress (hKernel, "Module32Next"); pProcess32First = (PROCESSWALK) GetProcAddress (hKernel, "Process32First"); pProcess32Next = (PROCESSWALK) GetProcAddress (hKernel, "Process32Next"); pThread32First = (THREADWALK) GetProcAddress (hKernel, "Thread32First"); pThread32Next = (THREADWALK) GetProcAddress (hKernel, "Thread32Next"); pHeap32ListFirst = (HEAPLISTWALK) GetProcAddress (hKernel, "Heap32ListFirst"); pHeap32ListNext = (HEAPLISTWALK) GetProcAddress (hKernel, "Heap32ListNext"); pHeap32First = (HEAPFIRST) GetProcAddress (hKernel, "Heap32First"); pHeap32Next = (HEAPNEXT) GetProcAddress (hKernel, "Heap32Next"); if ( !pCreateToolhelp32Snapshot || !pModule32First || !pModule32Next || !pProcess32First || !pProcess32Next || !pThread32First || !pThread32Next || !pHeap32ListFirst || !pHeap32ListNext || !pHeap32First || !pHeap32Next ) { log_fatal ( "rndw32: failed to get a toolhelp function\n" ); } } /* Take a snapshot of everything we can get to which is currently * in the system */ if ( !(hSnapshot = pCreateToolhelp32Snapshot (TH32CS_SNAPALL, 0)) ) { log_fatal ( "rndw32: failed to take a toolhelp snapshot\n" ); } /* Walk through the local heap */ { HEAPLIST32 hl32; hl32.dwSize = sizeof (HEAPLIST32); if (pHeap32ListFirst (hSnapshot, &hl32)) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_95: walk heap\n" ); do { HEAPENTRY32 he32; /* First add the information from the basic Heaplist32 struct */ (*add) ( &hl32, sizeof (hl32), requester ); /* Now walk through the heap blocks getting information * on each of them */ he32.dwSize = sizeof (HEAPENTRY32); if (pHeap32First (&he32, hl32.th32ProcessID, hl32.th32HeapID)){ do { (*add) ( &he32, sizeof (he32), requester ); } while (pHeap32Next (&he32)); } } while (pHeap32ListNext (hSnapshot, &hl32)); } } /* Walk through all processes */ { PROCESSENTRY32 pe32; pe32.dwSize = sizeof (PROCESSENTRY32); if (pProcess32First (hSnapshot, &pe32)) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_95: walk processes\n" ); do { (*add) ( &pe32, sizeof (pe32), requester ); } while (pProcess32Next (hSnapshot, &pe32)); } } /* Walk through all threads */ { THREADENTRY32 te32; te32.dwSize = sizeof (THREADENTRY32); if (pThread32First (hSnapshot, &te32)) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_95: walk threads\n" ); do { (*add) ( &te32, sizeof (te32), requester ); } while (pThread32Next (hSnapshot, &te32)); } } /* Walk through all modules associated with the process */ { MODULEENTRY32 me32; me32.dwSize = sizeof (MODULEENTRY32); if (pModule32First (hSnapshot, &me32)) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_95: walk modules\n" ); do { (*add) ( &me32, sizeof (me32), requester ); } while (pModule32Next (hSnapshot, &me32)); } } CloseHandle (hSnapshot); } static void slow_gatherer_windowsNT( void (*add)(const void*, size_t, int), int requester ) { static int is_initialized = 0; static NETSTATISTICSGET pNetStatisticsGet = NULL; static NETAPIBUFFERSIZE pNetApiBufferSize = NULL; static NETAPIBUFFERFREE pNetApiBufferFree = NULL; static int is_workstation = 1; static int cbPerfData = PERFORMANCE_BUFFER_SIZE; PERF_DATA_BLOCK *pPerfData; HANDLE hDevice, hNetAPI32 = NULL; DWORD dwSize, status; int nDrive; if ( !is_initialized ) { HKEY hKey; if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: init toolkit\n" ); /* Find out whether this is an NT server or workstation if necessary */ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_READ, &hKey) == ERROR_SUCCESS) { BYTE szValue[32]; dwSize = sizeof (szValue); if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: check product options\n" ); status = RegQueryValueEx (hKey, "ProductType", 0, NULL, szValue, &dwSize); if (status == ERROR_SUCCESS && stricmp (szValue, "WinNT")) { /* Note: There are (at least) three cases for ProductType: * WinNT = NT Workstation, ServerNT = NT Server, LanmanNT = * NT Server acting as a Domain Controller */ is_workstation = 0; if ( debug_me ) log_debug ("rndw32: this is a NT server\n"); } RegCloseKey (hKey); } /* Initialize the NetAPI32 function pointers if necessary */ if ( (hNetAPI32 = LoadLibrary ("NETAPI32.DLL")) ) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: netapi32 loaded\n" ); pNetStatisticsGet = (NETSTATISTICSGET) GetProcAddress (hNetAPI32, "NetStatisticsGet"); pNetApiBufferSize = (NETAPIBUFFERSIZE) GetProcAddress (hNetAPI32, "NetApiBufferSize"); pNetApiBufferFree = (NETAPIBUFFERFREE) GetProcAddress (hNetAPI32, "NetApiBufferFree"); if ( !pNetStatisticsGet || !pNetApiBufferSize || !pNetApiBufferFree ) { FreeLibrary (hNetAPI32); hNetAPI32 = NULL; log_debug ("rndw32: No NETAPI found\n" ); } } is_initialized = 1; } /* Get network statistics. Note: Both NT Workstation and NT Server by * default will be running both the workstation and server services. The * heuristic below is probably useful though on the assumption that the * majority of the network traffic will be via the appropriate service. * In any case the network statistics return almost no randomness */ { LPBYTE lpBuffer; if (hNetAPI32 && !pNetStatisticsGet (NULL, is_workstation ? L"LanmanWorkstation" : L"LanmanServer", 0, 0, &lpBuffer) ) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: get netstats\n" ); pNetApiBufferSize (lpBuffer, &dwSize); (*add) ( lpBuffer, dwSize,requester ); pNetApiBufferFree (lpBuffer); } } /* Get disk I/O statistics for all the hard drives */ for (nDrive = 0;; nDrive++) { char diskPerformance[SIZEOF_DISK_PERFORMANCE_STRUCT]; char szDevice[50]; /* Check whether we can access this device */ sprintf (szDevice, "\\\\.\\PhysicalDrive%d", nDrive); hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) break; /* Note: This only works if you have turned on the disk performance * counters with 'diskperf -y'. These counters are off by default */ if (DeviceIoControl (hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0, diskPerformance, SIZEOF_DISK_PERFORMANCE_STRUCT, &dwSize, NULL)) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: iostats drive %d\n", nDrive ); (*add) (diskPerformance, dwSize, requester ); } else { log_info ("NOTE: you should run 'diskperf -y' " "to enable the disk statistics\n"); } CloseHandle (hDevice); } #if 0 /* we don't need this in GnuPG */ /* Wait for any async keyset driver binding to complete. You may be * wondering what this call is doing here... the reason it's necessary is * because RegQueryValueEx() will hang indefinitely if the async driver * bind is in progress. The problem occurs in the dynamic loading and * linking of driver DLL's, which work as follows: * * hDriver = LoadLibrary( DRIVERNAME ); * pFunction1 = ( TYPE_FUNC1 ) GetProcAddress( hDriver, NAME_FUNC1 ); * pFunction2 = ( TYPE_FUNC1 ) GetProcAddress( hDriver, NAME_FUNC2 ); * * If RegQueryValueEx() is called while the GetProcAddress()'s are in * progress, it will hang indefinitely. This is probably due to some * synchronisation problem in the NT kernel where the GetProcAddress() * calls affect something like a module reference count or function * reference count while RegQueryValueEx() is trying to take a snapshot * of the statistics, which include the reference counts. Because of * this, we have to wait until any async driver bind has completed * before we can call RegQueryValueEx() */ waitSemaphore (SEMAPHORE_DRIVERBIND); #endif /* Get information from the system performance counters. This can take * a few seconds to do. In some environments the call to * RegQueryValueEx() can produce an access violation at some random time * in the future, adding a short delay after the following code block * makes the problem go away. This problem is extremely difficult to * reproduce, I haven't been able to get it to occur despite running it * on a number of machines. The best explanation for the problem is that * on the machine where it did occur, it was caused by an external driver * or other program which adds its own values under the * HKEY_PERFORMANCE_DATA key. The NT kernel calls the required external * modules to map in the data, if there's a synchronisation problem the * external module would write its data at an inappropriate moment, * causing the access violation. A low-level memory checker indicated * that ExpandEnvironmentStrings() in KERNEL32.DLL, called an * interminable number of calls down inside RegQueryValueEx(), was * overwriting memory (it wrote twice the allocated size of a buffer to a * buffer allocated by the NT kernel). This may be what's causing the * problem, but since it's in the kernel there isn't much which can be * done. * * In addition to these problems the code in RegQueryValueEx() which * estimates the amount of memory required to return the performance * counter information isn't very accurate, since it always returns a * worst-case estimate which is usually nowhere near the actual amount * required. For example it may report that 128K of memory is required, * but only return 64K of data */ { pPerfData = gcry_xmalloc (cbPerfData); for (;;) { dwSize = cbPerfData; if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: get perf data\n" ); status = RegQueryValueEx (HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, (LPBYTE) pPerfData, &dwSize); if (status == ERROR_SUCCESS) { if (!memcmp (pPerfData->Signature, L"PERF", 8)) { (*add) ( pPerfData, dwSize, requester ); } else log_debug ( "rndw32: no PERF signature\n"); break; } else if (status == ERROR_MORE_DATA) { cbPerfData += PERFORMANCE_BUFFER_STEP; pPerfData = gcry_realloc (pPerfData, cbPerfData); } else { log_debug ( "rndw32: get performance data problem\n"); break; } } gcry_free (pPerfData); } /* Although this isn't documented in the Win32 API docs, it's necessary to explicitly close the HKEY_PERFORMANCE_DATA key after use (it's implicitly opened on the first call to RegQueryValueEx()). If this isn't done then any system components which provide performance data can't be removed or changed while the handle remains active */ RegCloseKey (HKEY_PERFORMANCE_DATA); } int _gcry_rndw32_gather_random( void (*add)(const void*, size_t, int), int requester, size_t length, int level ) { static int is_initialized; static int is_windowsNT, has_toolhelp; if( !level ) return 0; /* We don't differentiate between level 1 and 2 here because * there is no internal entropy pool as a scary resource. It may * all work slower, but because our entropy source will never * block but deliver some not easy to measure entropy, we assume level 2 */ if ( !is_initialized ) { OSVERSIONINFO osvi = { sizeof( osvi ) }; DWORD platform; GetVersionEx( &osvi ); platform = osvi.dwPlatformId; is_windowsNT = platform == VER_PLATFORM_WIN32_NT; has_toolhelp = (platform == VER_PLATFORM_WIN32_WINDOWS || (is_windowsNT && osvi.dwMajorVersion >= 5)); if ( platform == VER_PLATFORM_WIN32s ) { log_fatal("can't run on a W32s platform\n" ); } is_initialized = 1; if ( debug_me ) log_debug ("rndw32#gather_random: platform=%d\n", (int)platform ); } if ( debug_me ) log_debug ("rndw32#gather_random: req=%d len=%u lvl=%d\n", requester, (unsigned int)length, level ); if ( has_toolhelp ) { slow_gatherer_windows95 ( add, requester ); } if ( is_windowsNT ) { slow_gatherer_windowsNT ( add, requester ); } return 0; } -int +void _gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t, int), int requester ) { static int addedFixedItems = 0; if ( debug_me ) log_debug ("rndw32#gather_random_fast: req=%d\n", requester ); /* Get various basic pieces of system information: Handle of active * window, handle of window with mouse capture, handle of clipboard owner * handle of start of clpboard viewer list, pseudohandle of current * process, current process ID, pseudohandle of current thread, current * thread ID, handle of desktop window, handle of window with keyboard * focus, whether system queue has any events, cursor position for last * message, 1 ms time for last message, handle of window with clipboard * open, handle of process heap, handle of procs window station, types of * events in input queue, and milliseconds since Windows was started */ { byte buffer[20*sizeof(ulong)], *bufptr; bufptr = buffer; #define ADD(f) do { ulong along = (ulong)(f); \ memcpy (bufptr, &along, sizeof (along) ); \ bufptr += sizeof (along); } while (0) ADD ( GetActiveWindow ()); ADD ( GetCapture ()); ADD ( GetClipboardOwner ()); ADD ( GetClipboardViewer ()); ADD ( GetCurrentProcess ()); ADD ( GetCurrentProcessId ()); ADD ( GetCurrentThread ()); ADD ( GetCurrentThreadId ()); ADD ( GetDesktopWindow ()); ADD ( GetFocus ()); ADD ( GetInputState ()); ADD ( GetMessagePos ()); ADD ( GetMessageTime ()); ADD ( GetOpenClipboardWindow ()); ADD ( GetProcessHeap ()); ADD ( GetProcessWindowStation ()); ADD ( GetQueueStatus (QS_ALLEVENTS)); ADD ( GetTickCount ()); assert ( bufptr-buffer < sizeof (buffer) ); (*add) ( buffer, bufptr-buffer, requester ); #undef ADD } /* Get multiword system information: Current caret position, current * mouse cursor position */ { POINT point; GetCaretPos (&point); (*add) ( &point, sizeof (point), requester ); GetCursorPos (&point); (*add) ( &point, sizeof (point), requester ); } /* Get percent of memory in use, bytes of physical memory, bytes of free * physical memory, bytes in paging file, free bytes in paging file, user * bytes of address space, and free user bytes */ { MEMORYSTATUS memoryStatus; memoryStatus.dwLength = sizeof (MEMORYSTATUS); GlobalMemoryStatus (&memoryStatus); (*add) ( &memoryStatus, sizeof (memoryStatus), requester ); } /* Get thread and process creation time, exit time, time in kernel mode, and time in user mode in 100ns intervals */ { HANDLE handle; FILETIME creationTime, exitTime, kernelTime, userTime; DWORD minimumWorkingSetSize, maximumWorkingSetSize; handle = GetCurrentThread (); GetThreadTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime); (*add) ( &creationTime, sizeof (creationTime), requester ); (*add) ( &exitTime, sizeof (exitTime), requester ); (*add) ( &kernelTime, sizeof (kernelTime), requester ); (*add) ( &userTime, sizeof (userTime), requester ); handle = GetCurrentProcess (); GetProcessTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime); (*add) ( &creationTime, sizeof (creationTime), requester ); (*add) ( &exitTime, sizeof (exitTime), requester ); (*add) ( &kernelTime, sizeof (kernelTime), requester ); (*add) ( &userTime, sizeof (userTime), requester ); /* Get the minimum and maximum working set size for the current process */ GetProcessWorkingSetSize (handle, &minimumWorkingSetSize, &maximumWorkingSetSize); (*add) ( &minimumWorkingSetSize, sizeof (minimumWorkingSetSize), requester ); (*add) ( &maximumWorkingSetSize, sizeof (maximumWorkingSetSize), requester ); } /* The following are fixed for the lifetime of the process so we only * add them once */ if (!addedFixedItems) { STARTUPINFO startupInfo; /* Get name of desktop, console window title, new window position and * size, window flags, and handles for stdin, stdout, and stderr */ startupInfo.cb = sizeof (STARTUPINFO); GetStartupInfo (&startupInfo); (*add) ( &startupInfo, sizeof (STARTUPINFO), requester ); addedFixedItems = 1; } /* The performance of QPC varies depending on the architecture it's * running on and on the OS. Under NT it reads the CPU's 64-bit timestamp * counter (at least on a Pentium and newer '486's, it hasn't been tested * on anything without a TSC), under Win95 it reads the 1.193180 MHz PIC * timer. There are vague mumblings in the docs that it may fail if the * appropriate hardware isn't available (possibly '386's or MIPS machines * running NT), but who's going to run NT on a '386? */ { LARGE_INTEGER performanceCount; if (QueryPerformanceCounter (&performanceCount)) { if ( debug_me ) log_debug ("rndw32#gather_random_fast: perf data\n"); (*add) (&performanceCount, sizeof (performanceCount), requester); } else { /* Millisecond accuracy at best... */ DWORD aword = GetTickCount (); (*add) (&aword, sizeof (aword), requester ); } } - - return 0; } diff --git a/configure.ac b/configure.ac index c33437e4..58a50845 100644 --- a/configure.ac +++ b/configure.ac @@ -1,935 +1,969 @@ # Configure.ac script for Libgcrypt # Copyright (C) 1998, 1999, 2000, 2001, 2002 # 2003, 2004, 2006 Free Software Foundation, Inc. # # This file is part of Libgcrypt. # # Libgcrypt is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser general Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # # Libgcrypt is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA # # (Process this file with autoconf to produce a configure script.) AC_REVISION($Revision$) AC_PREREQ(2.59) min_automake_version="1.9.3" # Remember to change the version number immediately *after* a release. # Set my_issvn to "yes" for non-released code. Remember to run an # "svn up" and "autogen.sh" right before creating a distribution. m4_define([my_version], [1.3.0]) m4_define([my_issvn], [yes]) m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \ || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) AC_INIT([libgcrypt], my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision]), [bug-libgcrypt@gnupg.org]) # LT Version numbers, remember to change them just *before* a release. # (Interfaces removed: CURRENT++, AGE=0, REVISION=0) # (Interfaces added: CURRENT++, AGE++, REVISION=0) # (No interfaces changed: REVISION++) LIBGCRYPT_LT_CURRENT=14 LIBGCRYPT_LT_AGE=3 LIBGCRYPT_LT_REVISION=0 # If the API is changed in an incompatible way: increment the next counter. LIBGCRYPT_CONFIG_API_VERSION=1 NEED_GPG_ERROR_VERSION=1.0 - +BUILD_REVISION=svn_revision PACKAGE=$PACKAGE_NAME VERSION=$PACKAGE_VERSION AC_CONFIG_SRCDIR([src/libgcrypt.vers]) AC_CANONICAL_TARGET() AM_INIT_AUTOMAKE($PACKAGE, $VERSION) AM_CONFIG_HEADER(config.h) AM_MAINTAINER_MODE AH_TOP([ /* need this, because some autoconf tests rely on this (e.g. stpcpy) * and it should be used for new programs */ #define _GNU_SOURCE 1 ]) AH_BOTTOM([ #define _GCRYPT_IN_LIBGCRYPT 1 /* If the configure check for endianness has been disabled, get it from OS macros. This is intended for making fat binary builds on OS X. */ #ifdef DISABLED_ENDIAN_CHECK # if defined(__BIG_ENDIAN__) # define WORDS_BIGENDIAN 1 # elif defined(__LITTLE_ENDIAN__) # undef WORDS_BIGENDIAN # else # error "No endianness found" # endif #endif /*DISABLED_ENDIAN_CHECK*/ ]) AH_VERBATIM([_REENTRANT], [/* To allow the use of Libgcrypt in multithreaded programs we have to use special features from the library. */ #ifndef _REENTRANT # define _REENTRANT 1 #endif ]) AC_SUBST(LIBGCRYPT_LT_CURRENT) AC_SUBST(LIBGCRYPT_LT_AGE) AC_SUBST(LIBGCRYPT_LT_REVISION) AC_SUBST(PACKAGE) AC_SUBST(VERSION) AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package]) AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package]) ###################### ## Basic checks. ### (we need some results later on (e.g. $GCC) ###################### AC_PROG_MAKE_SET missing_dir=`cd $ac_aux_dir && pwd` AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) # AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) AC_PROG_CC AC_PROG_CPP AM_PROG_AS AC_ISC_POSIX AC_PROG_INSTALL AC_PROG_AWK AC_LIBTOOL_WIN32_DLL AC_LIBTOOL_RC AM_PROG_LIBTOOL ########################## ## General definitions. ## ########################## # Used by libgcrypt-config LIBGCRYPT_CONFIG_LIBS="-lgcrypt" LIBGCRYPT_CONFIG_CFLAGS="" # Definitions for symmetric ciphers. available_ciphers="arcfour blowfish cast5 des aes twofish serpent rfc2268 seed" enabled_ciphers="" # Definitions for public-key ciphers. available_pubkey_ciphers="dsa elgamal rsa" enabled_pubkey_ciphers="" # Definitions for message digests. available_digests="crc md4 md5 rmd160 sha1 sha256" available_digests_64="sha512 tiger whirlpool" enabled_digests="" # Definitions for random modules. available_random_modules="linux egd unix" auto_random_modules="$available_random_modules" # Supported thread backends. LIBGCRYPT_THREAD_MODULES="" # Other definitions. print_egd_notice=no have_w32_system=no # Setup some stuff depending on host/target. case "${target}" in *-*-mingw32*) available_random_modules="w32" ac_cv_have_dev_random=no have_w32_system=yes AC_DEFINE(USE_ONLY_8DOT3,1, [set this to limit filenames to the 8.3 format]) AC_DEFINE(HAVE_DRIVE_LETTERS,1, [defined if we must run on a stupid file system]) AC_DEFINE(HAVE_DOSISH_SYSTEM,1, [defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2) with special properties like no file modes]) ;; i?86-emx-os2 | i?86-*-os2*emx) # OS/2 with the EMX environment ac_cv_have_dev_random=no AC_DEFINE(HAVE_DRIVE_LETTERS) AC_DEFINE(HAVE_DOSISH_SYSTEM) ;; i?86-*-msdosdjgpp*) # DOS with the DJGPP environment ac_cv_have_dev_random=no AC_DEFINE(HAVE_DRIVE_LETTERS) AC_DEFINE(HAVE_DOSISH_SYSTEM) ;; *-*-freebsd*) # FreeBSD CPPFLAGS="$CPPFLAGS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" ;; *-*-hpux*) if test -z "$GCC" ; then CFLAGS="$CFLAGS -Ae -D_HPUX_SOURCE" fi ;; *-dec-osf4*) if test -z "$GCC" ; then # Suppress all warnings # to get rid of the unsigned/signed char mismatch warnings. CFLAGS="$CFLAGS -w" fi ;; m68k-atari-mint) ;; *) ;; esac if test "$have_w32_system" = yes; then AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system]) fi AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes) -# A printable OS Name is sometime useful. +# A printable OS Name is sometimes useful. case "${target}" in *-*-mingw32*) PRINTABLE_OS_NAME="MingW32" ;; i?86-emx-os2 | i?86-*-os2*emx ) PRINTABLE_OS_NAME="OS/2" ;; i?86-*-msdosdjgpp*) PRINTABLE_OS_NAME="MSDOS/DJGPP" ;; *-linux*) PRINTABLE_OS_NAME="GNU/Linux" ;; *) PRINTABLE_OS_NAME=`uname -s || echo "Unknown"` ;; esac - +# Figure out the name of the random device case "${target}" in *-openbsd*) # FIXME: Are these the best flags for OpenBSD? NAME_OF_DEV_RANDOM="/dev/srandom" NAME_OF_DEV_URANDOM="/dev/urandom" # DYNLINK_MOD_CFLAGS="-shared -rdynamic $CFLAGS_PIC -Wl,-Bshareable -Wl,-x" ;; *-solaris* | *-irix* | *-dec-osf* | *-netbsd* ) NAME_OF_DEV_RANDOM="/dev/random" NAME_OF_DEV_URANDOM="/dev/random" # DYNLINK_MOD_CFLAGS="-shared $CFLAGS_PIC" ;; *) NAME_OF_DEV_RANDOM="/dev/random" NAME_OF_DEV_URANDOM="/dev/urandom" # -shared is a gcc-ism. Find pic flags from GNUPG_CHECK_PIC. # if test -n "$GCC" ; then # DYNLINK_MOD_CFLAGS="-shared $CFLAGS_PIC" # else # DYNLINK_MOD_CFLAGS="$CFLAGS_PIC" # fi ;; esac AC_ARG_ENABLE(endian-check, AC_HELP_STRING([--disable-endian-check], [disable the endian check and trust the OS provided macros]), endiancheck=$enableval,endiancheck=yes) if test x"$endiancheck" = xyes ; then AC_C_BIGENDIAN else AC_DEFINE(DISABLED_ENDIAN_CHECK,1,[configure did not test for endianess]) fi AC_CHECK_SIZEOF(unsigned short, 2) AC_CHECK_SIZEOF(unsigned int, 4) AC_CHECK_SIZEOF(unsigned long, 4) AC_CHECK_SIZEOF(unsigned long long, 0) if test "$ac_cv_sizeof_unsigned_short" = "0" \ || test "$ac_cv_sizeof_unsigned_int" = "0" \ || test "$ac_cv_sizeof_unsigned_long" = "0"; then AC_MSG_WARN([Hmmm, something is wrong with the sizes - using defaults]); fi # Do we have any 64-bit data types? if test "$ac_cv_sizeof_unsigned_int" != "8" \ && test "$ac_cv_sizeof_unsigned_long" != "8" \ && test "$ac_cv_sizeof_unsigned_long_long" != "8" \ && test "$ac_cv_sizeof_uint64_t" != "8"; then AC_MSG_WARN([No 64-bit types. Disabling TIGER/192, SHA-384, and SHA-512]) else available_digests="$available_digests $available_digests_64" fi # If not specified otherwise, all available algorithms will be # included. default_ciphers="$available_ciphers" default_pubkey_ciphers="$available_pubkey_ciphers" default_digests="$available_digests" ############################ ## Command line switches. ## ############################ # Implementation of the --enable-ciphers switch. AC_ARG_ENABLE(ciphers, AC_HELP_STRING([--enable-ciphers=ciphers], [select the symmetric ciphers to include]), [enabled_ciphers=`echo $enableval | tr , ' ' | tr '[A-Z]' '[a-z]'`], [enabled_ciphers=""]) if test "x$enabled_ciphers" = "x" \ -o "$enabled_ciphers" = "yes" \ -o "$enabled_ciphers" = "no"; then enabled_ciphers=$default_ciphers fi AC_MSG_CHECKING([which symmetric ciphers to include]) for cipher in $enabled_ciphers; do LIST_MEMBER($cipher, $available_ciphers) if test "$found" = "0"; then AC_MSG_ERROR([unsupported cipher specified]) fi done AC_MSG_RESULT([$enabled_ciphers]) # Implementation of the --enable-pubkey-ciphers switch. AC_ARG_ENABLE(pubkey-ciphers, AC_HELP_STRING([--enable-pubkey-ciphers=ciphers], [select the public-key ciphers to include]), [enabled_pubkey_ciphers=`echo $enableval | tr , ' ' | tr '[A-Z]' '[a-z]'`], [enabled_pubkey_ciphers=""]) if test "x$enabled_pubkey_ciphers" = "x" \ -o "$enabled_pubkey_ciphers" = "yes" \ -o "$enabled_pubkey_ciphers" = "no"; then enabled_pubkey_ciphers=$default_pubkey_ciphers fi AC_MSG_CHECKING([which public-key ciphers to include]) for cipher in $enabled_pubkey_ciphers; do LIST_MEMBER($cipher, $available_pubkey_ciphers) if test "$found" = "0"; then AC_MSG_ERROR([unsupported public-key cipher specified]) fi done AC_MSG_RESULT([$enabled_pubkey_ciphers]) # Implementation of the --enable-digests switch. AC_ARG_ENABLE(digests, AC_HELP_STRING([--enable-digests=digests], [select the message digests to include]), [enabled_digests=`echo $enableval | tr , ' ' | tr '[A-Z]' '[a-z]'`], [enabled_digests=""]) if test "x$enabled_digests" = "x" \ -o "$enabled_digests" = "yes" \ -o "$enabled_digests" = "no"; then enabled_digests=$default_digests fi AC_MSG_CHECKING([which message digests to include]) for digest in $enabled_digests; do LIST_MEMBER($digest, $available_digests) if test "$found" = "0"; then AC_MSG_ERROR([unsupported message digest specified]) fi done AC_MSG_RESULT([$enabled_digests]) # Implementation of the --enable-random switch. AC_ARG_ENABLE(random, AC_HELP_STRING([--enable-random=name], [select which random number generator to use]), [random=`echo $enableval | tr '[A-Z]' '[a-z]'`], []) if test "x$random" = "x" -o "$random" = "yes" -o "$random" = "no"; then random=default fi AC_MSG_CHECKING([which random module to use]) if test "$random" != "default" -a "$random" != "auto"; then LIST_MEMBER($random, $available_random_modules) if test "$found" = "0"; then AC_MSG_ERROR([unsupported random module specified]) fi fi AC_MSG_RESULT($random) # Implementation of the --disable-dev-random switch. AC_MSG_CHECKING([whether use of /dev/random is requested]) AC_ARG_ENABLE(dev-random, [ --disable-dev-random disable the use of dev random], try_dev_random=$enableval, try_dev_random=yes) AC_MSG_RESULT($try_dev_random) # Implementation of the --with-egd-socket switch. AC_ARG_WITH(egd-socket, [ --with-egd-socket=NAME Use NAME for the EGD socket)], egd_socket_name="$withval", egd_socket_name="" ) AC_DEFINE_UNQUOTED(EGD_SOCKET_NAME, "$egd_socket_name", [Define if you don't want the default EGD socket name. For details see cipher/rndegd.c]) +# Implementation of the --enable-random-daemon +AC_MSG_CHECKING([whether the experimental random daemon is requested]) +AC_ARG_ENABLE([random-daemon], + AC_HELP_STRING([--enable-random-daemon], + [Build and support the experimental gcryptrnd]), + [use_random_daemon=$enableval], + [use_random_daemon=no]) +AC_MSG_RESULT($use_random_daemon) +if test x$use_random_daemon = xyes ; then + AC_DEFINE(USE_RANDOM_DAEMON,1, + [Define to support the experimental random daemon]) +fi +AM_CONDITIONAL(USE_RANDOM_DAEMON, test x$use_random_daemon = xyes) + + # Implementation of --disable-asm. AC_MSG_CHECKING([whether assembler modules are requested]) AC_ARG_ENABLE([asm], AC_HELP_STRING([--disable-asm], [Disable assembler modules]), [try_asm_modules=$enableval], [try_asm_modules=yes]) AC_MSG_RESULT($try_asm_modules) # Implementation of the --enable-m-guard switch. AC_MSG_CHECKING([whether memory guard is requested]) AC_ARG_ENABLE(m-guard, [ --enable-m-guard enable memory guard facility], use_m_guard=$enableval, use_m_guard=no) AC_MSG_RESULT($use_m_guard) if test "$use_m_guard" = yes ; then AC_DEFINE(M_GUARD,1,[Define to use the (obsolete) malloc guarding feature]) fi # Implementation of the --with-capabilities switch. # Check whether we want to use Linux capabilities AC_MSG_CHECKING([whether use of capabilities is requested]) AC_ARG_WITH(capabilities, [ --with-capabilities use linux capabilities [default=no]], [use_capabilities="$withval"],[use_capabilities=no]) AC_MSG_RESULT($use_capabilities) AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME", [A human readable text with the name of the OS]) # For some systems we know that we have ld_version scripts. # Use it then as default. have_ld_version_script=no case "${host}" in *-*-linux*) have_ld_version_script=yes ;; *-*-gnu*) have_ld_version_script=yes ;; esac AC_ARG_ENABLE([ld-version-script], AC_HELP_STRING([--enable-ld-version-script], [enable/disable use of linker version script. (default is system dependent)]), [have_ld_version_script=$enableval], [ : ] ) AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes") AC_DEFINE_UNQUOTED(NAME_OF_DEV_RANDOM, "$NAME_OF_DEV_RANDOM", [defined to the name of the strong random device]) AC_DEFINE_UNQUOTED(NAME_OF_DEV_URANDOM, "$NAME_OF_DEV_URANDOM", [defined to the name of the weaker random device]) ############################### #### Checks for libraries. #### ############################### # # gpg-error is required. # AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION") if test "x$GPG_ERROR_LIBS" = "x"; then AC_MSG_ERROR([libgpg-error is needed. See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .]) fi AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GCRYPT, [The default error source for libgcrypt.]) # # Check whether the GNU Pth library is available. We require this # to build the optional gcryptrnd program. # AC_ARG_WITH(pth-prefix, AC_HELP_STRING([--with-pth-prefix=PFX], [prefix where GNU Pth is installed (optional)]), pth_config_prefix="$withval", pth_config_prefix="") if test x$pth_config_prefix != x ; then PTH_CONFIG="$pth_config_prefix/bin/pth-config" fi -AC_PATH_PROG(PTH_CONFIG, pth-config, no) -if test "$PTH_CONFIG" = "no"; then +if test "$use_random_daemon" = "yes"; then + AC_PATH_PROG(PTH_CONFIG, pth-config, no) + if test "$PTH_CONFIG" = "no"; then AC_MSG_WARN([[ *** *** To build the Libgcrypt's random humber daemon *** we need the support of the GNU Portable Threads Library. *** Download it from ftp://ftp.gnu.org/gnu/pth/ *** On a Debian GNU/Linux system you might want to try *** apt-get install libpth-dev ***]]) - else - GNUPG_PTH_VERSION_CHECK([1.3.7]) - if test $have_pth = yes; then - PTH_CFLAGS=`$PTH_CONFIG --cflags` - PTH_LIBS=`$PTH_CONFIG --ldflags` - PTH_LIBS="$PTH_LIBS `$PTH_CONFIG --libs --all`" - AC_DEFINE(USE_GNU_PTH, 1, - [Defined if the GNU Portable Thread Library should be used]) - AC_DEFINE(HAVE_PTH, 1, - [Defined if the GNU Pth is available]) + else + GNUPG_PTH_VERSION_CHECK([1.3.7]) + if test $have_pth = yes; then + PTH_CFLAGS=`$PTH_CONFIG --cflags` + PTH_LIBS=`$PTH_CONFIG --ldflags` + PTH_LIBS="$PTH_LIBS `$PTH_CONFIG --libs --all`" + AC_DEFINE(USE_GNU_PTH, 1, + [Defined if the GNU Portable Thread Library should be used]) + AC_DEFINE(HAVE_PTH, 1, + [Defined if the GNU Pth is available]) + fi fi fi AC_SUBST(PTH_CFLAGS) AC_SUBST(PTH_LIBS) # Solaris needs -lsocket and -lnsl. Unisys system includes # gethostbyname in libsocket but needs libnsl for socket. AC_SEARCH_LIBS(setsockopt, [socket], , [AC_SEARCH_LIBS(setsockopt, [socket], , , [-lnsl])]) AC_SEARCH_LIBS(setsockopt, [nsl]) ################################## #### Checks for header files. #### ################################## AC_HEADER_STDC AC_CHECK_HEADERS(unistd.h sys/select.h) ########################################## #### Checks for typedefs, structures, #### #### and compiler characteristics. #### ########################################## AC_C_CONST AC_C_INLINE AC_TYPE_SIZE_T AC_TYPE_SIGNAL AC_DECL_SYS_SIGLIST GNUPG_CHECK_TYPEDEF(byte, HAVE_BYTE_TYPEDEF) GNUPG_CHECK_TYPEDEF(ushort, HAVE_USHORT_TYPEDEF) GNUPG_CHECK_TYPEDEF(ulong, HAVE_ULONG_TYPEDEF) GNUPG_CHECK_TYPEDEF(u16, HAVE_U16_TYPEDEF) GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF) gl_TYPE_SOCKLEN_T case "${host}" in *-*-mingw32*) # socklen_t may or may not be defined depending on what headers # are included. To be safe we use int as this is the actual type. FALLBACK_SOCKLEN_T="typedef int gcry_socklen_t;" ;; *) if test ".$gl_cv_socklen_t_equiv" = "."; then FALLBACK_SOCKLEN_T="typedef socklen_t gcry_socklen_t;" else FALLBACK_SOCKLEN_T="typedef ${gl_cv_socklen_t_equiv} gcry_socklen_t;" fi esac AC_SUBST(FALLBACK_SOCKLEN_T) ####################################### #### Checks for library functions. #### ####################################### AC_FUNC_VPRINTF # We have replacements for these in src/missing-string.c AC_CHECK_FUNCS(stpcpy strcasecmp) # We have replacements for these in src/g10lib.h AC_CHECK_FUNCS(strtoul memmove stricmp atexit raise) # Other checks AC_CHECK_FUNCS(strerror rand mmap getpagesize waitpid wait4) AC_CHECK_FUNCS(gettimeofday getrusage gethrtime clock_gettime) AC_CHECK_FUNCS(fcntl ftruncate) GNUPG_CHECK_MLOCK # Check whether we can use Linux capabilities as requested. if test "$use_capabilities" = "yes" ; then use_capabilities=no AC_CHECK_HEADERS(sys/capability.h) if test "$ac_cv_header_sys_capability_h" = "yes" ; then AC_CHECK_LIB(cap, cap_init, ac_need_libcap=1) if test "$ac_cv_lib_cap_cap_init" = "yes"; then AC_DEFINE(USE_CAPABILITIES,1, [define if capabilities should be used]) LIBS="$LIBS -lcap" use_capabilities=yes fi fi if test "$use_capabilities" = "no" ; then AC_MSG_WARN([[ *** *** The use of capabilities on this system is not possible. *** You need a recent Linux kernel and some patches: *** fcaps-2.2.9-990610.patch (kernel patch for 2.2.9) *** fcap-module-990613.tar.gz (kernel module) *** libcap-1.92.tar.gz (user mode library and utilities) *** And you have to configure the kernel with CONFIG_VFS_CAP_PLUGIN *** set (filesystems menu). Be warned: This code is *really* ALPHA. ***]]) fi fi # Check whether a random device is available. if test "$try_dev_random" = yes ; then AC_CACHE_CHECK(for random device, ac_cv_have_dev_random, [if test -r "$NAME_OF_DEV_RANDOM" && test -r "$NAME_OF_DEV_URANDOM" ; then ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi]) if test "$ac_cv_have_dev_random" = yes; then AC_DEFINE(HAVE_DEV_RANDOM,1, [defined if the system supports a random device] ) fi else AC_MSG_CHECKING(for random device) ac_cv_have_dev_random=no AC_MSG_RESULT(has been disabled) fi # Figure out the random modules for this configuration. if test "$random" = "default"; then # Select default value. if test "$ac_cv_have_dev_random" = yes; then # Try Linuxish random device. random_modules="linux" else case "${target}" in *-*-mingw32*|*-*-cygwin*) # Windows random device. random_modules="w32" ;; *) # Build everything, allow to select at runtime. random_modules="$auto_random_modules" ;; esac fi else if test "$random" = "auto"; then # Build everything, allow to select at runtime. random_modules="$auto_random_modules" else random_modules="$random" fi fi # # Setup assembler stuff. # GNUPG_SYS_SYMBOL_UNDERSCORE() AC_MSG_CHECKING(for mpi assembler functions) if test -f $srcdir/mpi/config.links ; then . $srcdir/mpi/config.links AC_CONFIG_LINKS("$mpi_ln_list") ac_cv_mpi_mod_list="$mpi_mod_list" ac_cv_mpi_sflags="$mpi_sflags" ac_cv_mpi_config_done="yes" AC_MSG_RESULT(done) else AC_MSG_RESULT(failed) AC_MSG_ERROR([mpi/config.links missing!]) fi MPI_MOD_LIST_LO="" MPI_MOD_LIST_O="" if test "$ac_cv_mpi_mod_list" != ""; then for i in $ac_cv_mpi_mod_list; do MPI_MOD_LIST_LO="$MPI_MOD_LIST_LO $i.lo" MPI_MOD_LIST_O="$MPI_MOD_LIST_O $i.o" done fi AC_SUBST(MPI_MOD_LIST_LO) AC_SUBST(MPI_MOD_LIST_O) MPI_SFLAGS="$ac_cv_mpi_sflags" AC_SUBST(MPI_SFLAGS) # Allow users to append something to the version string without # flagging it as development version. The user version part is # considered everything after a dash. changequote(,)# tmp_pat='[a-zA-Z]' changequote([,])# if echo "$VERSION" | sed 's/-.*//' | grep "$tmp_pat" >/dev/null ; then AC_DEFINE(IS_DEVELOPMENT_VERSION,1, [Defined if this is not a regular release]) fi AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes) # This is handy for debugging so the compiler doesn't rearrange # things and eliminate variables. AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization], [disable compiler optimization]), [if test $enableval = no ; then CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'` fi]) AC_ARG_ENABLE(gcc-warnings, AC_HELP_STRING([--enable-gcc-warnings], [enable more verbose gcc warnings]), [more_gcc_warnings="$enableval"], [more_gcc_warnings="no"]) if test "$GCC" = yes; then if test "$USE_MAINTAINER_MODE" = "yes" || test "$more_gcc_warnings" = "yes"; then CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes" if test "$more_gcc_warnings" = "yes"; then CFLAGS="$CFLAGS -W -Wextra -Wpointer-arith -Wbad-function-cast" CFLAGS="$CFLAGS -Wwrite-strings" CFLAGS="$CFLAGS -Wdeclaration-after-statement" CFLAGS="$CFLAGS -Wno-missing-field-initializers" CFLAGS="$CFLAGS -Wno-sign-compare" # Note: We don't use -Wunreachable-code because this gives # warnings for all asserts and many inline functions like # gpg_error (gcc 4.1.2 20060928). fi else CFLAGS="$CFLAGS -Wall" fi fi # Check whether as(1) supports a noeexecstack feature. This test # includes an override option. CL_AS_NOEXECSTACK AC_SUBST(LIBGCRYPT_CONFIG_API_VERSION) AC_SUBST(LIBGCRYPT_CONFIG_LIBS) AC_SUBST(LIBGCRYPT_CONFIG_CFLAGS) AC_SUBST(LIBGCRYPT_THREAD_MODULES) AC_CONFIG_COMMANDS([gcrypt-conf],[[ chmod +x src/libgcrypt-config ]],[[ prefix=$prefix exec_prefix=$exec_prefix libdir=$libdir datadir=$datadir DATADIRNAME=$DATADIRNAME ]]) ##################### #### Conclusion. #### ##################### # Define conditional sources and config.h symbols depending on the # selected ciphers, pubkey-ciphers, digests and random modules. LIST_MEMBER(arcfour, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS arcfour.lo" AC_DEFINE_UNQUOTED(USE_ARCFOUR, $found, [Defined if this module should be included]) LIST_MEMBER(blowfish, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish.lo" AC_DEFINE_UNQUOTED(USE_BLOWFISH, $found, [Defined if this module should be included]) LIST_MEMBER(cast5, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5.lo" AC_DEFINE_UNQUOTED(USE_CAST5, $found, [Defined if this module should be included]) LIST_MEMBER(des, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS des.lo" AC_DEFINE_UNQUOTED(USE_DES, $found, [Defined if this module should be included]) LIST_MEMBER(aes, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael.lo" AC_DEFINE_UNQUOTED(USE_AES, $found, [Defined if this module should be included]) LIST_MEMBER(twofish, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish.lo" AC_DEFINE_UNQUOTED(USE_TWOFISH, $found, [Defined if this module should be included]) LIST_MEMBER(serpent, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent.lo" AC_DEFINE_UNQUOTED(USE_SERPENT, $found, [Defined if this module should be included]) LIST_MEMBER(rfc2268, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS rfc2268.lo" AC_DEFINE_UNQUOTED(USE_RFC2268, $found, [Defined if this module should be included]) LIST_MEMBER(seed, $enabled_ciphers) test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS seed.lo" AC_DEFINE_UNQUOTED(USE_SEED, $found, [Defined if this module should be included]) LIST_MEMBER(dsa, $enabled_pubkey_ciphers) test "$found" = "1" && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dsa.lo" AC_DEFINE_UNQUOTED(USE_DSA, $found, [Defined if this module should be included]) LIST_MEMBER(rsa, $enabled_pubkey_ciphers) test "$found" = "1" && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS rsa.lo" AC_DEFINE_UNQUOTED(USE_RSA, $found, [Defined if this module should be included]) LIST_MEMBER(elgamal, $enabled_pubkey_ciphers) test "$found" = "1" \ && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS elgamal.lo" AC_DEFINE_UNQUOTED(USE_ELGAMAL, $found, [Defined if this module should be included]) LIST_MEMBER(crc, $enabled_digests) test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS crc.lo" AC_DEFINE_UNQUOTED(USE_CRC, $found, [Defined if this module should be included]) LIST_MEMBER(md4, $enabled_digests) test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS md4.lo" AC_DEFINE_UNQUOTED(USE_MD4, $found, [Defined if this module should be included]) LIST_MEMBER(md5, $enabled_digests) test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS md5.lo" AC_DEFINE_UNQUOTED(USE_MD5, $found, [Defined if this module should be included]) LIST_MEMBER(sha256, $enabled_digests) test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256.lo" AC_DEFINE_UNQUOTED(USE_SHA256, $found, [Defined if this module should be included]) LIST_MEMBER(sha512, $enabled_digests) test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512.lo" AC_DEFINE_UNQUOTED(USE_SHA512, $found, [Defined if this module should be included]) LIST_MEMBER(tiger, $enabled_digests) test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS tiger.lo" AC_DEFINE_UNQUOTED(USE_TIGER, $found, [Defined if this module should be included]) LIST_MEMBER(whirlpool, $enabled_digests) test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS whirlpool.lo" AC_DEFINE_UNQUOTED(USE_WHIRLPOOL, $found, [Defined if this module should be included]) # rmd160 and sha1 should be included always. GCRYPT_DIGESTS="$GCRYPT_DIGESTS rmd160.lo sha1.lo" AC_DEFINE_UNQUOTED(USE_RMD160, 1, [Defined if this module should be included]) AC_DEFINE_UNQUOTED(USE_SHA1, 1, [Defined if this module should be included]) LIST_MEMBER(linux, $random_modules) test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndlinux.lo" AC_DEFINE_UNQUOTED(USE_RNDLINUX, $found, [Defined if the /dev/random based RNG should be used.]) LIST_MEMBER(unix, $random_modules) test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndunix.lo" AC_DEFINE_UNQUOTED(USE_RNDUNIX, $found, [Defined if the default Unix RNG should be used.]) if test "$found" = "1"; then print_egd_notice=yes fi LIST_MEMBER(egd, $random_modules) test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndegd.lo" AC_DEFINE_UNQUOTED(USE_RNDEGD, $found, [Defined if the EGD based RNG should be used.]) LIST_MEMBER(w32, $random_modules) test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32.lo" AC_DEFINE_UNQUOTED(USE_RNDW32, $found, [Defined if the Windows specific RNG should be used.]) AC_SUBST([GCRYPT_CIPHERS]) AC_SUBST([GCRYPT_PUBKEY_CIPHERS]) AC_SUBST([GCRYPT_DIGESTS]) AC_SUBST([GCRYPT_RANDOM]) AC_SUBST(LIBGCRYPT_CIPHERS, $enabled_ciphers) AC_SUBST(LIBGCRYPT_PUBKEY_CIPHERS, $enabled_pubkey_ciphers) AC_SUBST(LIBGCRYPT_DIGESTS, $enabled_digests) +# Generate extended version information for W32. +if test "$have_w32_system" = yes; then + BUILD_TIMESTAMP=`date --iso-8601=minutes` + changequote(,)dnl + BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'` + changequote([,])dnl + BUILD_FILEVERSION="${BUILD_FILEVERSION}${BUILD_REVISION}" +fi +AC_SUBST(BUILD_REVISION) +AC_SUBST(BUILD_TIMESTAMP) +AC_SUBST(BUILD_FILEVERSION) +AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION", + [Subversion revision used to build this package]) + + + +# And create the files. AC_CONFIG_FILES([ Makefile m4/Makefile mpi/Makefile cipher/Makefile doc/Makefile src/Makefile src/gcrypt.h src/libgcrypt-config +src/versioninfo.rc tests/Makefile -w32-dll/Makefile ]) AC_OUTPUT # Give some feedback echo if test "$print_egd_notice" = "yes"; then cat < @end example The name space of `@acronym{Libgcrypt}' is @code{gcry_*} for function and type names and @code{GCRY*} for other symbols. In addition the same name prefixes with one prepended underscore are reserved for internal use and should never be used by an application. Furthermore `libgpg-error' defines functions prefixed with `gpg_' and preprocessor symbols prefixed with `GPG_'. Note that @acronym{Libgcrypt} uses libgpg-error, which uses @code{gpg_err_*} as name space for function and type names and @code{GPG_ERR_*} for other symbols, including all the error codes. @node Building sources @section Building sources If you want to compile a source file including the `gcrypt.h' header file, you must make sure that the compiler can find it in the directory hierarchy. This is accomplished by adding the path to the directory in which the header file is located to the compilers include file search path (via the @option{-I} option). However, the path to the include file is determined at the time the source is configured. To solve this problem, `@acronym{Libgcrypt}' ships with a small helper program @command{libgcrypt-config} that knows the path to the include file and other configuration options. The options that need to be added to the compiler invocation at compile time are output by the @option{--cflags} option to @command{libgcrypt-config}. The following example shows how it can be used at the command line: @example gcc -c foo.c `libgcrypt-config --cflags` @end example Adding the output of @samp{libgcrypt-config --cflags} to the compilers command line will ensure that the compiler can find the `@acronym{Libgcrypt}' header file. A similar problem occurs when linking the program with the library. Again, the compiler has to find the library files. For this to work, the path to the library files has to be added to the library search path (via the @option{-L} option). For this, the option @option{--libs} to @command{libgcrypt-config} can be used. For convenience, this option also outputs all other options that are required to link the program with the `@acronym{Libgcrypt}' libraries (in particular, the @samp{-lgcrypt} option). The example shows how to link @file{foo.o} with the `@acronym{Libgcrypt}' library to a program @command{foo}. @example gcc -o foo foo.o `libgcrypt-config --libs` @end example Of course you can also combine both examples to a single command by specifying both options to @command{libgcrypt-config}: @example gcc -o foo foo.c `libgcrypt-config --cflags --libs` @end example @node Building sources using Automake @section Building sources using Automake It is much easier if you use GNU Automake instead of writing your own Makefiles. If you do that you do not have to worry about finding and invoking the @command{libgcrypt-config} script at all. @acronym{Libgcrypt} provides an extension to Automake that does all the work for you. @c A simple macro for optional variables. @macro ovar{varname} @r{[}@var{\varname\}@r{]} @end macro @defmac AM_PATH_LIBGCRYPT (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found}) Check whether @acronym{Libgcrypt} (at least version @var{minimum-version}, if given) exists on the host system. If it is found, execute @var{action-if-found}, otherwise do @var{action-if-not-found}, if given. Additionally, the function defines @code{LIBGCRYPT_CFLAGS} to the flags needed for compilation of the program to find the @file{gcrypt.h} header file, and @code{LIBGCRYPT_LIBS} to the linker flags needed to link the program to the @acronym{Libgcrypt} library. @end defmac You can use the defined Autoconf variables like this in your @file{Makefile.am}: @example AM_CPPFLAGS = $(LIBGCRYPT_CFLAGS) LDADD = $(LIBGCRYPT_LIBS) @end example @node Initializing the library @section Initializing the library It is often desirable to check that the version of `@acronym{Libgcrypt}' used is indeed one which fits all requirements. Even with binary compatibility new features may have been introduced but due to problem with the dynamic linker an old version is actually used. So you may want to check that the version is okay right after program startup. @deftypefun const char *gcry_check_version (const char *@var{req_version}) The function @code{gcry_check_version} has three purposes. It can be used to retrieve the version number of the library. In addition it can verify that the version number is higher than a certain required version number. In either case, the function initializes some sub-systems, and for this reason alone it must be invoked early in your program, before you make use of the other functions of @acronym{Libgcrypt}. @end deftypefun @node Multi Threading @section Multi Threading As mentioned earlier, the `@acronym{Libgcrypt}' library is thread-safe if you adhere to the following requirements: @itemize @bullet @item If your application is multi-threaded, you must set the thread support callbacks with the @code{GCRYCTL_SET_THREAD_CBS} command @strong{before} any other function in the library. This is easy enough if you are indeed writing an application using Libgcrypt. It is rather problematic if you are writing a library instead. Here are some tips what to do if you are writing a library: If your library requires a certain thread package, just initialize Libgcrypt to use this thread package. If your library supports multiple thread packages, but needs to be configured, you will have to implement a way to determine which thread package the application wants to use with your library anyway. Then configure Libgcrypt to use this thread package. If your library is fully reentrant without any special support by a thread package, then you are lucky indeed. Unfortunately, this does not relieve you from doing either of the two above, or use a third option. The third option is to let the application initialize Libgcrypt for you. Then you are not using Libgcrypt transparently, though. As if this was not difficult enough, a conflict may arise if two libraries try to initialize Libgcrypt independently of each others, and both such libraries are then linked into the same application. To make it a bit simpler for you, this will probably work, but only if both libraries have the same requirement for the thread package. This is currently only supported for the non-threaded case, GNU Pth and pthread. Support for more thread packages is easy to add, so contact us if you require it. @item The function @code{gcry_check_version} must be called before any other function in the library, except the @code{GCRYCTL_SET_THREAD_CBS} command (called via the @code{gcry_control} function), because it initializes the thread support subsystem in @acronym{Libgcrypt}. To achieve this in multi-threaded programs, you must synchronize the memory with respect to other threads that also want to use @acronym{Libgcrypt}. For this, it is sufficient to call @code{gcry_check_version} before creating the other threads using @acronym{Libgcrypt}@footnote{At least this is true for POSIX threads, as @code{pthread_create} is a function that synchronizes memory with respects to other threads. There are many functions which have this property, a complete list can be found in POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the definition of the term ``Memory Synchronization''. For other thread packages, more relaxed or more strict rules may apply.}. @item As with the function @code{gpg_strerror}, @code{gcry_strerror} is not thread safe. You have to use @code{gpg_strerror_r} instead. @end itemize @acronym{Libgcrypt} contains convenient macros, which define the necessary thread callbacks for PThread and for GNU Pth: @table @code @item GCRY_THREAD_OPTION_PTH_IMPL This macro defines the following (static) symbols: gcry_pth_init, gcry_pth_mutex_init, gcry_pth_mutex_destroy, gcry_pth_mutex_lock, gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write, gcry_pth_select, gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect, gcry_threads_pth. After including this macro, gcry_control() shall be used with a command of GCRYCTL_SET_THREAD_CBS in order to register the thread callback structure named ``gcry_threads_pth''. @item GCRY_THREAD_OPTION_PTHREAD_IMPL This macro defines the following (static) symbols: gcry_pthread_mutex_init, gcry_pthread_mutex_destroy, gcry_mutex_lock, gcry_mutex_unlock, gcry_threads_pthread. After including this macro, gcry_control() shall be used with a command of GCRYCTL_SET_THREAD_CBS in order to register the thread callback structure named ``gcry_threads_pthread''. @end table Note that these macros need to be terminated with a semicolon. Keep in mind that these are convenient macros for C programmers; C++ programmers might have to wrap these macros in an ``extern C'' body. @c ********************************************************** @c ******************* General **************************** @c ********************************************************** @node Generalities @chapter Generalities @menu * Controlling the library:: Controlling @acronym{Libgcrypt}'s behavior. * Modules:: Description of extension modules. * Error Handling:: Error codes and such. @end menu @node Controlling the library @section Controlling the library @deftypefun gcry_error_t gcry_control (enum gcry_ctl_cmds @var{cmd}, ...) This function can be used to influence the general behavior of @acronym{Libgcrypt} in several ways. Depending on @var{cmd}, more arguments can or have to be provided. @table @code @item GCRYCTL_ENABLE_M_GUARD; Arguments: none This command enables the built-in memory guard. It must not be used to activate the memory guard after the memory management has already been used; therefore it can ONLY be used at initialization time. Note that the memory guard is NOT used when the user of the library has set his own memory management callbacks. @item GCRYCTL_ENABLE_QUICK_RANDOM; Arguments: none This command activates the use of a highly-insecure, but fast PRNG. It can only be used at initialization time - FIXME: is this correct? @item GCRYCTL_DUMP_RANDOM_STATS This command dumps PRNG related statistics to the librarys logging stream. @item GCRYCTL_DUMP_MEMORY_STATS This command dumps memory manamgent related statistics to the librarys logging stream. @item GCRYCTL_DUMP_SECMEM_STATS This command dumps secure memory manamgent related statistics to the librarys logging stream. @item GCRYCTL_DROP_PRIVS This command disables the use of secure memory and drops the priviliges of the current process. FIXME. @item GCRYCTL_DISABLE_SECMEM This command disables the use of secure memory. FIXME. @item GCRYCTL_INIT_SECMEM @item GCRYCTL_TERM_SECMEM @item GCRYCTL_DISABLE_SECMEM_WARN @item GCRYCTL_SUSPEND_SECMEM_WARN @item GCRYCTL_RESUME_SECMEM_WARN @item GCRYCTL_USE_SECURE_RNDPOOL; Arguments: none This command tells the PRNG to store random numbers in secure memory. FIXME: what about initialization time? @item GCRYCTL_SET_RANDOM_SEED_FILE; Arguments: const char *filename This command specifies the file, which is to be used as seed file for the PRNG. If the seed file is registered prior to initialization of the PRNG, the seed file's content (if it exists and seems to be valid) is feed into the PRNG pool. After the seed file has been registered, the PRNG can be signalled to write out the PRNG pool's content into the seed file with the following command. @item GCRYCTL_UPDATE_RANDOM_SEED_FILE; Arguments: none Write out the PRNG pool's content into the registered seed file. @item GCRYCTL_SET_VERBOSITY @item GCRYCTL_SET_DEBUG_FLAGS @item GCRYCTL_CLEAR_DEBUG_FLAGS @item GCRYCTL_DISABLE_INTERNAL_LOCKING @item GCRYCTL_ANY_INITIALIZATION_P @item GCRYCTL_INITIALIZATION_FINISHED_P @item GCRYCTL_INITIALIZATION_FINISHED @item GCRYCTL_SET_THREAD_CBS; Arguments: struct ath_ops *ath_ops This command registers a thread-callback structure. See section ``multi threading'' for more information on this command. @item GCRYCTL_FAST_POOL @end table @end deftypefun @node Modules @section Modules @acronym{Libgcrypt} supports the use of `extension modules', which implement algorithms in addition to those already built into the library directly. @deftp {Data type} gcry_module_t This data type represents a `module'. @end deftp Functions registering modules provided by the user take a `module specification structure' as input and return a value of @code{gcry_module_t} and an ID that is unique in the modules' category. This ID can be used to reference the newly registered module. After registering a module successfully, the new functionality should be able to be used through the normal functions provided by @acronym{Libgcrypt} until it is unregistered again. @c ********************************************************** @c ******************* Errors **************************** @c ********************************************************** @node Error Handling @section Error Handling Many functions in @acronym{Libgcrypt} can return an error if they fail. For this reason, the application should always catch the error condition and take appropriate measures, for example by releasing the resources and passing the error up to the caller, or by displaying a descriptive message to the user and cancelling the operation. Some error values do not indicate a system error or an error in the operation, but the result of an operation that failed properly. For example, if you try to decrypt a tempered message, the decryption will fail. Another error value actually means that the end of a data buffer or list has been reached. The following descriptions explain for many error codes what they mean usually. Some error values have specific meanings if returned by a certain functions. Such cases are described in the documentation of those functions. @acronym{Libgcrypt} uses the @code{libgpg-error} library. This allows to share the error codes with other components of the GnuPG system, and thus pass error values transparently from the crypto engine, or some helper application of the crypto engine, to the user. This way no information is lost. As a consequence, @acronym{Libgcrypt} does not use its own identifiers for error codes, but uses those provided by @code{libgpg-error}. They usually start with @code{GPG_ERR_}. However, @acronym{Libgcrypt} does provide aliases for the functions defined in libgpg-error, which might be preferred for name space consistency. Most functions in @acronym{Libgcrypt} return an error code in the case of failure. For this reason, the application should always catch the error condition and take appropriate measures, for example by releasing the resources and passing the error up to the caller, or by displaying a descriptive message to the user and canceling the operation. Some error values do not indicate a system error or an error in the operation, but the result of an operation that failed properly. GnuPG components, including Libgcrypt, use an extra library named libgpg-error to provide a common error handling scheme. For more information on libgpg-error, see the according manual. @menu * Error Values:: The error value and what it means. * Error Sources:: A list of important error sources. * Error Codes:: A list of important error codes. * Error Strings:: How to get a descriptive string from a value. @end menu @node Error Values @subsection Error Values @cindex error values @cindex error codes @cindex error sources @deftp {Data type} {gcry_err_code_t} The @code{gcry_err_code_t} type is an alias for the @code{libgpg-error} type @code{gpg_err_code_t}. The error code indicates the type of an error, or the reason why an operation failed. A list of important error codes can be found in the next section. @end deftp @deftp {Data type} {gcry_err_source_t} The @code{gcry_err_source_t} type is an alias for the @code{libgpg-error} type @code{gpg_err_source_t}. The error source has not a precisely defined meaning. Sometimes it is the place where the error happened, sometimes it is the place where an error was encoded into an error value. Usually the error source will give an indication to where to look for the problem. This is not always true, but it is attempted to achieve this goal. A list of important error sources can be found in the next section. @end deftp @deftp {Data type} {gcry_error_t} The @code{gcry_error_t} type is an alias for the @code{libgpg-error} type @code{gpg_error_t}. An error value like this has always two components, an error code and an error source. Both together form the error value. Thus, the error value can not be directly compared against an error code, but the accessor functions described below must be used. However, it is guaranteed that only 0 is used to indicate success (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of the error value are set to 0, too. Note that in @acronym{Libgcrypt}, the error source is used purely for diagnostic purposes. Only the error code should be checked to test for a certain outcome of a function. The manual only documents the error code part of an error value. The error source is left unspecified and might be anything. @end deftp @deftypefun {gcry_err_code_t} gcry_err_code (@w{gcry_error_t @var{err}}) The static inline function @code{gcry_err_code} returns the @code{gcry_err_code_t} component of the error value @var{err}. This function must be used to extract the error code from an error value in order to compare it with the @code{GPG_ERR_*} error code macros. @end deftypefun @deftypefun {gcry_err_source_t} gcry_err_source (@w{gcry_error_t @var{err}}) The static inline function @code{gcry_err_source} returns the @code{gcry_err_source_t} component of the error value @var{err}. This function must be used to extract the error source from an error value in order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros. @end deftypefun @deftypefun {gcry_error_t} gcry_err_make (@w{gcry_err_source_t @var{source}}, @w{gcry_err_code_t @var{code}}) The static inline function @code{gcry_err_make} returns the error value consisting of the error source @var{source} and the error code @var{code}. This function can be used in callback functions to construct an error value to return it to the library. @end deftypefun @deftypefun {gcry_error_t} gcry_error (@w{gcry_err_code_t @var{code}}) The static inline function @code{gcry_error} returns the error value consisting of the default error source and the error code @var{code}. For @acronym{GCRY} applications, the default error source is @code{GPG_ERR_SOURCE_USER_1}. You can define @code{GCRY_ERR_SOURCE_DEFAULT} before including @file{gcrypt.h} to change this default. This function can be used in callback functions to construct an error value to return it to the library. @end deftypefun The @code{libgpg-error} library provides error codes for all system error numbers it knows about. If @var{err} is an unknown error number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The following functions can be used to construct error values from system errno numbers. @deftypefun {gcry_error_t} gcry_err_make_from_errno (@w{gcry_err_source_t @var{source}}, @w{int @var{err}}) The function @code{gcry_err_make_from_errno} is like @code{gcry_err_make}, but it takes a system error like @code{errno} instead of a @code{gcry_err_code_t} error code. @end deftypefun @deftypefun {gcry_error_t} gcry_error_from_errno (@w{int @var{err}}) The function @code{gcry_error_from_errno} is like @code{gcry_error}, but it takes a system error like @code{errno} instead of a @code{gcry_err_code_t} error code. @end deftypefun Sometimes you might want to map system error numbers to error codes directly, or map an error code representing a system error back to the system error number. The following functions can be used to do that. @deftypefun {gcry_err_code_t} gcry_err_code_from_errno (@w{int @var{err}}) The function @code{gcry_err_code_from_errno} returns the error code for the system error @var{err}. If @var{err} is not a known system error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}. @end deftypefun @deftypefun {int} gcry_err_code_to_errno (@w{gcry_err_code_t @var{err}}) The function @code{gcry_err_code_to_errno} returns the system error for the error code @var{err}. If @var{err} is not an error code representing a system error, or if this system error is not defined on this system, the function returns @code{0}. @end deftypefun @node Error Sources @subsection Error Sources @cindex error codes, list of The library @code{libgpg-error} defines an error source for every component of the GnuPG system. The error source part of an error value is not well defined. As such it is mainly useful to improve the diagnostic error message for the user. If the error code part of an error value is @code{0}, the whole error value will be @code{0}. In this case the error source part is of course @code{GPG_ERR_SOURCE_UNKNOWN}. The list of error sources that might occur in applications using @acronym{Libgctypt} is: @table @code @item GPG_ERR_SOURCE_UNKNOWN The error source is not known. The value of this error source is @code{0}. @item GPG_ERR_SOURCE_GPGME The error source is @acronym{GPGME} itself. @item GPG_ERR_SOURCE_GPG The error source is GnuPG, which is the crypto engine used for the OpenPGP protocol. @item GPG_ERR_SOURCE_GPGSM The error source is GPGSM, which is the crypto engine used for the OpenPGP protocol. @item GPG_ERR_SOURCE_GCRYPT The error source is @code{libgcrypt}, which is used by crypto engines to perform cryptographic operations. @item GPG_ERR_SOURCE_GPGAGENT The error source is @command{gpg-agent}, which is used by crypto engines to perform operations with the secret key. @item GPG_ERR_SOURCE_PINENTRY The error source is @command{pinentry}, which is used by @command{gpg-agent} to query the passphrase to unlock a secret key. @item GPG_ERR_SOURCE_SCD The error source is the SmartCard Daemon, which is used by @command{gpg-agent} to delegate operations with the secret key to a SmartCard. @item GPG_ERR_SOURCE_KEYBOX The error source is @code{libkbx}, a library used by the crypto engines to manage local keyrings. @item GPG_ERR_SOURCE_USER_1 @item GPG_ERR_SOURCE_USER_2 @item GPG_ERR_SOURCE_USER_3 @item GPG_ERR_SOURCE_USER_4 These error sources are not used by any GnuPG component and can be used by other software. For example, applications using @acronym{Libgcrypt} can use them to mark error values coming from callback handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors created with @code{gcry_error} and @code{gcry_error_from_errno}, unless you define @code{GCRY_ERR_SOURCE_DEFAULT} before including @file{gcrypt.h}. @end table @node Error Codes @subsection Error Codes @cindex error codes, list of The library @code{libgpg-error} defines many error values. The following list includes the most important error codes. @table @code @item GPG_ERR_EOF This value indicates the end of a list, buffer or file. @item GPG_ERR_NO_ERROR This value indicates success. The value of this error code is @code{0}. Also, it is guaranteed that an error value made from the error code @code{0} will be @code{0} itself (as a whole). This means that the error source information is lost for this error code, however, as this error code indicates that no error occurred, this is generally not a problem. @item GPG_ERR_GENERAL This value means that something went wrong, but either there is not enough information about the problem to return a more useful error value, or there is no separate error value for this type of problem. @item GPG_ERR_ENOMEM This value means that an out-of-memory condition occurred. @item GPG_ERR_E... System errors are mapped to GPG_ERR_EFOO where FOO is the symbol for the system error. @item GPG_ERR_INV_VALUE This value means that some user provided data was out of range. @item GPG_ERR_UNUSABLE_PUBKEY This value means that some recipients for a message were invalid. @item GPG_ERR_UNUSABLE_SECKEY This value means that some signers were invalid. @item GPG_ERR_NO_DATA This value means that data was expected where no data was found. @item GPG_ERR_CONFLICT This value means that a conflict of some sort occurred. @item GPG_ERR_NOT_IMPLEMENTED This value indicates that the specific function (or operation) is not implemented. This error should never happen. It can only occur if you use certain values or configuration options which do not work, but for which we think that they should work at some later time. @item GPG_ERR_DECRYPT_FAILED This value indicates that a decryption operation was unsuccessful. @item GPG_ERR_WRONG_KEY_USAGE This value indicates that a key is not used appropriately. @item GPG_ERR_NO_SECKEY This value indicates that no secret key for the user ID is available. @item GPG_ERR_UNSUPPORTED_ALGORITHM This value means a verification failed because the cryptographic algorithm is not supported by the crypto backend. @item GPG_ERR_BAD_SIGNATURE This value means a verification failed because the signature is bad. @item GPG_ERR_NO_PUBKEY This value means a verification failed because the public key is not available. @item GPG_ERR_USER_1 @item GPG_ERR_USER_2 @item ... @item GPG_ERR_USER_16 These error codes are not used by any GnuPG component and can be freely used by other software. Applications using @acronym{Libgcrypt} might use them to mark specific errors returned by callback handlers if no suitable error codes (including the system errors) for these errors exist already. @end table @node Error Strings @subsection Error Strings @cindex error values, printing of @cindex error codes, printing of @cindex error sources, printing of @cindex error strings @deftypefun {const char *} gcry_strerror (@w{gcry_error_t @var{err}}) The function @code{gcry_strerror} returns a pointer to a statically allocated string containing a description of the error code contained in the error value @var{err}. This string can be used to output a diagnostic message to the user. @end deftypefun @deftypefun {const char *} gcry_strsource (@w{gcry_error_t @var{err}}) The function @code{gcry_strerror} returns a pointer to a statically allocated string containing a description of the error source contained in the error value @var{err}. This string can be used to output a diagnostic message to the user. @end deftypefun The following example illustrates the use of the functions described above: @example @{ gcry_cipher_hd_t handle; gcry_error_t err = 0; err = gcry_cipher_open (&handle, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0); if (err) @{ fprintf (stderr, "Failure: %s/%s\n", gcry_strsource (err), gcry_strerror (err)); @} @} @end example @c ********************************************************** @c ******************* General **************************** @c ********************************************************** @node Handler Functions @chapter Handler Functions @acronym{Libgcrypt} makes it possible to install so called `handler functions', which get called by @acronym{Libgcrypt} in case of certain events. @menu * Progress handler:: Using a progress handler function. * Allocation handler:: Using special memory allocation functions. * Error handler:: Using error handler functions. * Logging handler:: Using a special logging function. @end menu @node Progress handler @section Progress handler It is often useful to retrieve some feedback while long running operations are performed. @deftp {Data type} gcry_handler_progress_t Progress handler functions have to be of the type @code{gcry_handler_progress_t}, which is defined as: @code{void (*gcry_handler_progress_t) (void *, const char *, int, int, int)} @end deftp The following function may be used to register a handler function for this purpose. @deftypefun void gcry_set_progress_handler (gcry_handler_progress_t @var{cb}, void *@var{cb_data}) This function installs @var{cb} as the `Progress handler' function. @var{cb} must be defined as follows: @example void my_progress_handler (void *@var{cb_data}, const char *@var{what}, int @var{printchar}, int @var{current}, int @var{total}) @{ /* Do something. */ @} @end example A description of the arguments of the progress handler function follows. @table @var @item cb_data The argument provided in the call to @code{gcry_set_progress_handler}. @item what A string identifying the type of the progress output. The following values for @var{what} are defined: @table @code @item need_entropy Not enough entropy is available. @var{total} holds the number of required bytes. @item primegen Values for @var{printchar}: @table @code @item \n Prime generated. @item ! Need to refresh the pool of prime numbers. @item <, > Number of bits adjusted. @item ^ Searching for a generator. @item . Fermat test on 10 candidates failed. @item : Restart with a new random value. @item + Rabin Miller test passed. @end table @end table @end table @end deftypefun @node Allocation handler @section Allocation handler It is possible to make @acronym{Libgcrypt} use special memory allocation functions instead of the built-in ones. Memory allocation functions are of the following types: @deftp {Data type} gcry_handler_alloc_t This type is defined as: @code{void *(*gcry_handler_alloc_t) (size_t n)}. @end deftp @deftp {Data type} gcry_handler_secure_check_t This type is defined as: @code{int *(*gcry_handler_secure_check_t) (const void *)}. @end deftp @deftp {Data type} gcry_handler_realloc_t This type is defined as: @code{void *(*gcry_handler_realloc_t) (void *p, size_t n)}. @end deftp @deftp {Data type} gcry_handler_free_t This type is defined as: @code{void *(*gcry_handler_free_t) (void *)}. @end deftp Special memory allocation functions can be installed with the following function: @deftypefun void gcry_set_allocation_handler (gcry_handler_alloc_t @var{func_alloc}, gcry_handler_alloc_t @var{func_alloc_secure}, gcry_handler_secure_check_t @var{func_secure_check}, gcry_handler_realloc_t @var{func_realloc}, gcry_handler_free_t @var{func_free}) Install the provided functions and use them instead of the built-in functions for doing memory allocation. @end deftypefun @node Error handler @section Error handler The following functions may be used to register handler functions that are called by @acronym{Libgcrypt} in case certain error conditions occur. @deftp {Data type} gcry_handler_no_mem_t This type is defined as: @code{void (*gcry_handler_no_mem_t) (void *, size_t, unsigned int)} @end deftp @deftypefun void gcry_set_outofcore_handler (gcry_handler_no_mem_t @var{func_no_mem}, void *@var{cb_data}) This function registers @var{func_no_mem} as `out-of-core handler', which means that it will be called in the case of not having enough memory available. @end deftypefun @deftp {Data type} gcry_handler_error_t This type is defined as: @code{void (*gcry_handler_error_t) (void *, int, const char *)} @end deftp @deftypefun void gcry_set_fatalerror_handler (gcry_handler_error_t @var{func_error}, void *@var{cb_data}) This function registers @var{func_error} as `error handler', which means that it will be called in error conditions. @end deftypefun @node Logging handler @section Logging handler @deftp {Data type} gcry_handler_log_t This type is defined as: @code{void (*gcry_handler_log_t) (void *, int, const char *, va_list)} @end deftp @deftypefun void gcry_set_log_handler (gcry_handler_log_t @var{func_log}, void *@var{cb_data}) This function registers @var{func_log} as `logging handler', which means that it will be called in case @acronym{Libgcrypt} wants to log a message. @end deftypefun @c ********************************************************** @c ******************* Ciphers **************************** @c ********************************************************** @c @include cipher-ref.texi @node Symmetric cryptography @chapter Symmetric cryptography The cipher functions are used for symmetrical cryptography, i.e. cryptography using a shared key. The programming model follows an open/process/close paradigm and is in that similar to other building blocks provided by @acronym{Libgcrypt}. @menu * Available ciphers:: List of ciphers supported by the library. * Cipher modules:: How to work with cipher modules. * Available cipher modes:: List of cipher modes supported by the library. * Working with cipher handles:: How to perform operations related to cipher handles. * General cipher functions:: General cipher functions independent of cipher handles. @end menu @node Available ciphers @section Available ciphers @table @code @item GCRY_CIPHER_NONE This is not a real algorithm but used by some functions as error return. The value always evaluates to false. @item GCRY_CIPHER_IDEA This is the IDEA algorithm. The constant is provided but there is currently no implementation for it because the algorithm is patented. @item GCRY_CIPHER_3DES Triple-DES with 3 Keys as EDE. The key size of this algorithm is 168 but you have to pass 192 bits because the most significant bits of each byte are ignored. @item GCRY_CIPHER_CAST5 CAST128-5 block cipher algorithm. The key size is 128 bits. @item GCRY_CIPHER_BLOWFISH The blowfish algorithm. The current implementation allows only for a key size of 128 bits. @item GCRY_CIPHER_SAFER_SK128 Reserved and not currently implemented. @item GCRY_CIPHER_DES_SK Reserved and not currently implemented. @item GCRY_CIPHER_AES @itemx GCRY_CIPHER_AES128 @itemx GCRY_CIPHER_RIJNDAEL @itemx GCRY_CIPHER_RIJNDAEL128 AES (Rijndael) with a 128 bit key. @item GCRY_CIPHER_AES192 @itemx GCRY_CIPHER_RIJNDAEL192 AES (Rijndael) with a 192 bit key. @item GCRY_CIPHER_AES256 @itemx GCRY_CIPHER_RIJNDAEL256 AES (Rijndael) with a 256 bit key. @item GCRY_CIPHER_TWOFISH The Twofish algorithm with a 256 bit key. @item GCRY_CIPHER_TWOFISH128 The Twofish algorithm with a 128 bit key. @item GCRY_CIPHER_ARCFOUR An algorithm which is 100% compatible with RSA Inc.'s RC4 algorithm. Note that this is a stream cipher and must be used very carefully to avoid a couple of weaknesses. @item GCRY_CIPHER_DES Standard DES with a 56 bit key. You need to pass 64 bit but the high bits of each byte are ignored. Note, that this is a weak algorithm which can be broken in reasonable time using a brute force approach. @item GCRY_CIPHER_SERPENT128 @itemx GCRY_CIPHER_SERPENT192 @itemx GCRY_CIPHER_SERPENT256 The Serpent cipher from the AES contest. @item GCRY_CIPHER_RFC2268_40 @itemx GCRY_CIPHER_RFC2268_128 Ron's Cipher 2 in the 40 and 128 bit variants. Note, that we currently only support the 40 bit variant. The identifier for 128 is reserved for future use. @item GCRY_CIPHER_SEED A 128 bit cipher as described by RFC4269. @end table @node Cipher modules @section Cipher modules @acronym{Libgcrypt} makes it possible to load additional `cipher modules'; these cipher can be used just like the cipher algorithms that are built into the library directly. For an introduction into extension modules, see @xref{Modules}. @deftp {Data type} gcry_cipher_spec_t This is the `module specification structure' needed for registering cipher modules, which has to be filled in by the user before it can be used to register a module. It contains the following members: @table @code @item const char *name The primary name of the algorithm. @item const char **aliases A list of strings that are `aliases' for the algorithm. The list must be terminated with a NULL element. @item gcry_cipher_oid_spec_t *oids A list of OIDs that are to be associated with the algorithm. The list's last element must have it's `oid' member set to NULL. See below for an explanation of this type. @item size_t blocksize The block size of the algorithm, in bytes. @item size_t keylen The length of the key, in bits. @item size_t contextsize The size of the algorithm-specific `context', that should be allocated for each handle. @item gcry_cipher_setkey_t setkey The function responsible for initializing a handle with a provided key. See below for a description of this type. @item gcry_cipher_encrypt_t encrypt The function responsible for encrypting a single block. See below for a description of this type. @item gcry_cipher_decrypt_t decrypt The function responsible for decrypting a single block. See below for a description of this type. @item gcry_cipher_stencrypt_t stencrypt Like `encrypt', for stream ciphers. See below for a description of this type. @item gcry_cipher_stdecrypt_t stdecrypt Like `decrypt', for stream ciphers. See below for a description of this type. @end table @end deftp @deftp {Data type} gcry_cipher_oid_spec_t This type is used for associating a user-provided algorithm implementation with certain OIDs. It contains the following members: @table @code @item const char *oid Textual representation of the OID. @item int mode Cipher mode for which this OID is valid. @end table @end deftp @deftp {Data type} gcry_cipher_setkey_t Type for the `setkey' function, defined as: gcry_err_code_t (*gcry_cipher_setkey_t) (void *c, const unsigned char *key, unsigned keylen) @end deftp @deftp {Data type} gcry_cipher_encrypt_t Type for the `encrypt' function, defined as: gcry_err_code_t (*gcry_cipher_encrypt_t) (void *c, const unsigned char *outbuf, const unsigned char *inbuf) @end deftp @deftp {Data type} gcry_cipher_decrypt_t Type for the `decrypt' function, defined as: gcry_err_code_t (*gcry_cipher_decrypt_t) (void *c, const unsigned char *outbuf, const unsigned char *inbuf) @end deftp @deftp {Data type} gcry_cipher_stencrypt_t Type for the `stencrypt' function, defined as: gcry_err_code_t (*gcry_cipher_stencrypt_t) (void *c, const unsigned char *outbuf, const unsigned char *, unsigned int n) @end deftp @deftp {Data type} gcry_cipher_stdecrypt_t Type for the `stdecrypt' function, defined as: gcry_err_code_t (*gcry_cipher_stdecrypt_t) (void *c, const unsigned char *outbuf, const unsigned char *, unsigned int n) @end deftp @deftypefun gcry_error_t gcry_cipher_register (gcry_cipher_spec_t *@var{cipher}, unsigned int *algorithm_id, gcry_module_t *@var{module}) Register a new cipher module whose specification can be found in @var{cipher}. On success, a new algorithm ID is stored in @var{algorithm_id} and a pointer representing this module is stored in @var{module}. @end deftypefun @deftypefun void gcry_cipher_unregister (gcry_module_t @var{module}) Unregister the cipher identified by @var{module}, which must have been registered with gcry_cipher_register. @end deftypefun @deftypefun gcry_error_t gcry_cipher_list (int *@var{list}, int *@var{list_length}) Get a list consisting of the IDs of the loaded cipher modules. If @var{list} is zero, write the number of loaded cipher modules to @var{list_length} and return. If @var{list} is non-zero, the first *@var{list_length} algorithm IDs are stored in @var{list}, which must be of according size. In case there are less cipher modules than *@var{list_length}, *@var{list_length} is updated to the correct number. @end deftypefun @node Available cipher modes @section Available cipher modes @table @code @item GCRY_CIPHER_MODE_NONE No mode specified, may be set later using other functions. The value of this constant is always 0. @item GCRY_CIPHER_MODE_ECB Electronic Codebook mode. @item GCRY_CIPHER_MODE_CFB Cipher Feedback mode. @item GCRY_CIPHER_MODE_CBC Cipher Block Chaining mode. @item GCRY_CIPHER_MODE_STREAM Stream mode, only to be used with stream cipher algorithms. @item GCRY_CIPHER_MODE_OFB Output Feedback mode. @item GCRY_CIPHER_MODE_CTR Counter mode. @end table @node Working with cipher handles @section Working with cipher handles To use a cipher algorithm, you must first allocate an according handle. This is to be done using the open function: @deftypefun gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *@var{hd}, int @var{algo}, int @var{mode}, unsigned int @var{flags}) This function creates the context handle required for most of the other cipher functions and returns a handle to it in `hd'. In case of an error, an according error code is returned. The ID of algorithm to use must be specified via @var{algo}. See @xref{Available ciphers}, for a list of supported ciphers and the according constants. Besides using the constants directly, the function @code{gcry_cipher_map_name} may be used to convert the textual name of an algorithm into the according numeric ID. The cipher mode to use must be specified via @var{mode}. See @xref{Available cipher modes}, for a list of supported cipher modes and the according constants. Note that some modes are incompatible with some algorithms - in particular, stream mode (GCRY_CIPHER_MODE_STREAM) only works with stream ciphers. Any block cipher mode (GCRY_CIPHER_MODE_ECB, GCRY_CIPHER_MODE_CBC, GCRY_CIPHER_MODE_CFB, GCRY_CIPHER_MODE_OFB or GCRY_CIPHER_MODE_CTR) will work with any block cipher algorithm. The third argument @var{flags} can either be passed as @code{0} or as the bit-wise OR of the following constants. @table @code @item GCRY_CIPHER_SECURE Make sure that all operations are allocated in secure memory. This is useful, when the key material is highly confidential. @item GCRY_CIPHER_ENABLE_SYNC This flag enables the CFB sync mode, which is a special feature of @acronym{Libgcrypt}'s CFB mode implementation to allow for OpenPGP's CFB variant. See @code{gcry_cipher_sync}. @item GCRY_CIPHER_CBC_CTS Enable cipher text stealing (CTS) for the CBC mode. Cannot be used simultaneous as GCRY_CIPHER_CBC_MAC. CTS mode makes it possible to transform data of almost arbitrary size (only limitation is that it must be greater than the algorithm's block size). @item GCRY_CIPHER_CBC_MAC Compute CBC-MAC keyed checksums. This is the same as CBC mode, but only output the last block. Cannot be used simultaneous as GCRY_CIPHER_CBC_CTS. @end table @end deftypefun Use the following function to release an existing handle: @deftypefun void gcry_cipher_close (gcry_cipher_hd_t @var{h}) This function releases the context created by @code{gcry_cipher_open}. @end deftypefun In order to use a handle for performing cryptographic operations, a `key' has to be set first: @deftypefun gcry_error_t gcry_cipher_setkey (gcry_cipher_hd_t @var{h}, void *@var{k}, size_t @var{l}) Set the key @var{k} used for encryption or decryption in the context denoted by the handle @var{h}. The length @var{l} of the key @var{k} must match the required length of the algorithm set for this context or be in the allowed range for algorithms with variable key size. The function checks this and returns an error if there is a problem. A caller should always check for an error. Note, this is currently implemented as a macro but may be changed to a function in the future. @end deftypefun Most crypto modes requires an initialization vector (IV), which usually is a non-secret random string acting as a kind of salt value. The CTR mode requires a counter, which is also similar to a salt value. To set the IV or CTR, use these functions: @deftypefun gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t @var{h}, void *@var{k}, size_t @var{l}) Set the initialization vector used for encryption or decryption. The vector is passed as the buffer @var{K} of length @var{l} and copied to internal data structures. The function checks that the IV matches the requirement of the selected algorithm and mode. Note, that this is implemented as a macro. @end deftypefun @deftypefun gcry_error_t gcry_cipher_setctr (gcry_cipher_hd_t @var{h}, void *@var{c}, size_t @var{l}) Set the counter vector used for encryption or decryption. The counter is passed as the buffer @var{c} of length @var{l} and copied to internal data structures. The function checks that the counter matches the requirement of the selected algorithm (i.e., it must be the same size as the block size). Note, that this is implemented as a macro. @end deftypefun @deftypefun gcry_error_t gcry_cipher_reset (gcry_cipher_hd_t @var{h}) Set the given handle's context back to the state it had after the last call to gcry_cipher_setkey and clear the initialization vector. Note, that gcry_cipher_reset is implemented as a macro. @end deftypefun The actual encryption and decryption is done by using one of the following functions. They may be used as often as required to process all the data. @deftypefun gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t @var{h}, unsigned char *{out}, size_t @var{outsize}, const unsigned char *@var{in}, size_t @var{inlen}) @code{gcry_cipher_encrypt} is used to encrypt the data. This function can either work in place or with two buffers. It uses the cipher context already setup and described by the handle @var{h}. There are 2 ways to use the function: If @var{in} is passed as @code{NULL} and @var{inlen} is @code{0}, in-place encryption of the data in @var{out} or length @var{outsize} takes place. With @var{in} being not @code{NULL}, @var{inlen} bytes are encrypted to the buffer @var{out} which must have at least a size of @var{inlen}. @var{outsize} must be set to the allocated size of @var{out}, so that the function can check that there is sufficient space. Note, that overlapping buffers are not allowed. Depending on the selected algorithms and encryption mode, the length of the buffers must be a multiple of the block size. The function returns @code{0} on success or an error code. @end deftypefun @deftypefun gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t @var{h}, unsigned char *{out}, size_t @var{outsize}, const unsigned char *@var{in}, size_t @var{inlen}) @code{gcry_cipher_decrypt} is used to decrypt the data. This function can either work in place or with two buffers. It uses the cipher context already setup and described by the handle @var{h}. There are 2 ways to use the function: If @var{in} is passed as @code{NULL} and @var{inlen} is @code{0}, in-place decryption of the data in @var{out} or length @var{outsize} takes place. With @var{in} being not @code{NULL}, @var{inlen} bytes are decrypted to the buffer @var{out} which must have at least a size of @var{inlen}. @var{outsize} must be set to the allocated size of @var{out}, so that the function can check that there is sufficient space. Note, that overlapping buffers are not allowed. Depending on the selected algorithms and encryption mode, the length of the buffers must be a multiple of the block size. The function returns @code{0} on success or an error code. @end deftypefun OpenPGP (as defined in RFC-2440) requires a special sync operation in some places, the following function is used for this: @deftypefun gcry_error_t gcry_cipher_sync (gcry_cipher_hd_t @var{h}) Perform the OpenPGP sync operation on context @var{h}. Note, that this is a no-op unless the context was created with the flag @code{GCRY_CIPHER_ENABLE_SYNC} @end deftypefun Some of the described functions are implemented as macros utilizing a catch-all control function. This control function is rarely used directly but there is nothing which would inhibit it: @deftypefun gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t @var{h}, int @var{cmd}, void *@var{buffer}, size_t @var{buflen}) @code{gcry_cipher_ctl} controls various aspects of the cipher module and specific cipher contexts. Usually some more specialized functions or macros are used for this purpose. The semantics of the function and its parameters depends on the the command @var{cmd} and the passed context handle @var{h}. Please see the comments in the source code (@code{src/global.c}) for details. @end deftypefun @deftypefun gcry_error_t gcry_cipher_info (gcry_cipher_hd_t @var{h}, int @var{what}, void *@var{buffer}, size_t *@var{nbytes}) @code{gcry_cipher_info} is used to retrieve various information about a cipher context or the cipher module in general. Currently no information is available. @end deftypefun @node General cipher functions @section General cipher functions To work with the algorithms, several functions are available to map algorithm names to the internal identifiers, as well as ways to retrieve information about an algorithm or the current cipher context. @deftypefun gcry_error_t gcry_cipher_algo_info (int @var{algo}, int @var{what}, void *@var{buffer}, size_t *@var{nbytes}) This function is used to retrieve information on a specific algorithm. You pass the cipher algorithm ID as @var{algo} and the type of information requested as @var{what}. The result is either returned as the return code of the function or copied to the provided @var{buffer} whose allocated length must be available in an integer variable with the address passed in @var{nbytes}. This variable will also receive the actual used length of the buffer. Here is a list of supported codes for @var{what}: @c begin constants for gcry_cipher_algo_info @table @code @item GCRYCTL_GET_KEYLEN: Return the length of the key. If the algorithm supports multiple key lengths, the maximum supported value is returned. The length is returned as number of octets (bytes) and not as number of bits in @var{nbytes}; @var{buffer} must be zero. @item GCRYCTL_GET_BLKLEN: Return the block length of the algorithm. The length is returned as a number of octets in @var{nbytes}; @var{buffer} must be zero. @item GCRYCTL_TEST_ALGO: Returns @code{0} when the specified algorithm is available for use. @var{buffer} and @var{nbytes} must be zero. @end table @c end constants for gcry_cipher_algo_info @end deftypefun @c end gcry_cipher_algo_info @deftypefun const char *gcry_cipher_algo_name (int @var{algo}) @code{gcry_cipher_algo_name} returns a string with the name of the cipher algorithm @var{algo}. If the algorithm is not known or another -error occurred, an empty string is returned. This function will never -return @code{NULL}. +error occurred, the string @code{"?"} is returned. This function should +not be used to test for the availability of an algorithm. @end deftypefun @deftypefun int gcry_cipher_map_name (const char *@var{name}) @code{gcry_cipher_map_name} returns the algorithm identifier for the cipher algorithm described by the string @var{name}. If this algorithm is not available @code{0} is returned. @end deftypefun @deftypefun int gcry_cipher_mode_from_oid (const char *@var{string}) Return the cipher mode associated with an @acronym{ASN.1} object identifier. The object identifier is expected to be in the @acronym{IETF}-style dotted decimal notation. The function returns @code{0} for an unknown object identifier or when no mode is associated with it. @end deftypefun @c ********************************************************** @c ******************* Hash Functions ********************* @c ********************************************************** @node Hashing @chapter Hashing @acronym{Libgcrypt} provides an easy and consistent to use interface for hashing. Hashing is buffered and several hash algorithms can be updated at once. It is possible to calculate a MAC using the same routines. The programming model follows an open/process/close paradigm and is in that similar to other building blocks provided by @acronym{Libgcrypt}. For convenience reasons, a few cyclic redundancy check value operations are also supported. @menu * Available hash algorithms:: List of hash algorithms supported by the library. * Hash algorithm modules:: How to work with hash algorithm modules. * Working with hash algorithms:: List of functions related to hashing. @end menu @node Available hash algorithms @section Available hash algorithms @c begin table of hash algorithms @table @code @item GCRY_MD_NONE This is not a real algorithm but used by some functions as an error return value. This constant is guaranteed to have the value @code{0}. @item GCRY_MD_SHA1 This is the SHA-1 algorithm which yields a message digest of 20 bytes. @item GCRY_MD_RMD160 This is the 160 bit version of the RIPE message digest (RIPE-MD-160). Like SHA-1 it also yields a digest of 20 bytes. @item GCRY_MD_MD5 This is the well known MD5 algorithm, which yields a message digest of 16 bytes. @item GCRY_MD_MD4 This is the MD4 algorithm, which yields a message digest of 16 bytes. @item GCRY_MD_MD2 This is an reserved identifier for MD-2; there is no implementation yet. @item GCRY_MD_TIGER This is the TIGER/192 algorithm which yields a message digest of 24 bytes. @item GCRY_MD_HAVAL This is an reserved for the HAVAL algorithm with 5 passes and 160 bit. It yields a message digest of 20 bytes. Note that there is no implementation yet available. @item GCRY_MD_SHA224 This is the SHA-224 algorithm which yields a message digest of 28 bytes. See Change Notice 1 for FIPS 180-2 for the specification. @item GCRY_MD_SHA256 This is the SHA-256 algorithm which yields a message digest of 32 bytes. See FIPS 180-2 for the specification. @item GCRY_MD_SHA384 This is the SHA-384 algorithm which yields a message digest of 48 bytes. See FIPS 180-2 for the specification. @item GCRY_MD_SHA512 This is the SHA-384 algorithm which yields a message digest of 64 bytes. See FIPS 180-2 for the specification. @item GCRY_MD_CRC32 This is the ISO 3309 and ITU-T V.42 cyclic redundancy check. It yields an output of 4 bytes. @item GCRY_MD_CRC32_RFC1510 This is the above cyclic redundancy check function, as modified by RFC 1510. It yields an output of 4 bytes. @item GCRY_MD_CRC24_RFC2440 This is the OpenPGP cyclic redundancy check function. It yields an output of 3 bytes. @item GCRY_MD_WHIRLPOOL This is the Whirlpool algorithm which yields a message digest of 64 bytes. @end table @c end table of hash algorithms @node Hash algorithm modules @section Hash algorithm modules @acronym{Libgcrypt} makes it possible to load additional `message digest modules'; these digests can be used just like the message digest algorithms that are built into the library directly. For an introduction into extension modules, see @xref{Modules}. @deftp {Data type} gcry_md_spec_t This is the `module specification structure' needed for registering message digest modules, which has to be filled in by the user before it can be used to register a module. It contains the following members: @table @code @item const char *name The primary name of this algorithm. @item unsigned char *asnoid Array of bytes that form the ASN OID. @item int asnlen Length of bytes in `asnoid'. @item gcry_md_oid_spec_t *oids A list of OIDs that are to be associated with the algorithm. The list's last element must have it's `oid' member set to NULL. See below for an explanation of this type. See below for an explanation of this type. @item int mdlen Length of the message digest algorithm. See below for an explanation of this type. @item gcry_md_init_t init The function responsible for initializing a handle. See below for an explanation of this type. @item gcry_md_write_t write The function responsible for writing data into a message digest context. See below for an explanation of this type. @item gcry_md_final_t final The function responsible for `finalizing' a message digest context. See below for an explanation of this type. @item gcry_md_read_t read The function responsible for reading out a message digest result. See below for an explanation of this type. @item size_t contextsize The size of the algorithm-specific `context', that should be allocated for each handle. @end table @end deftp @deftp {Data type} gcry_md_oid_spec_t This type is used for associating a user-provided algorithm implementation with certain OIDs. It contains the following members: @table @code @item const char *oidstring Textual representation of the OID. @end table @end deftp @deftp {Data type} gcry_md_init_t Type for the `init' function, defined as: void (*gcry_md_init_t) (void *c) @end deftp @deftp {Data type} gcry_md_write_t Type for the `write' function, defined as: void (*gcry_md_write_t) (void *c, unsigned char *buf, size_t nbytes) @end deftp @deftp {Data type} gcry_md_final_t Type for the `final' function, defined as: void (*gcry_md_final_t) (void *c) @end deftp @deftp {Data type} gcry_md_read_t Type for the `read' function, defined as: unsigned char *(*gcry_md_read_t) (void *c) @end deftp @deftypefun gcry_error_t gcry_md_register (gcry_md_spec_t *@var{digest}, unsigned int *algorithm_id, gcry_module_t *@var{module}) Register a new digest module whose specification can be found in @var{digest}. On success, a new algorithm ID is stored in @var{algorithm_id} and a pointer representing this module is stored in @var{module}. @end deftypefun @deftypefun void gcry_md_unregister (gcry_module_t @var{module}) Unregister the digest identified by @var{module}, which must have been registered with gcry_md_register. @end deftypefun @deftypefun gcry_error_t gcry_md_list (int *@var{list}, int *@var{list_length}) Get a list consisting of the IDs of the loaded message digest modules. If @var{list} is zero, write the number of loaded message digest modules to @var{list_length} and return. If @var{list} is non-zero, the first *@var{list_length} algorithm IDs are stored in @var{list}, which must be of according size. In case there are less message digests modules than *@var{list_length}, *@var{list_length} is updated to the correct number. @end deftypefun @node Working with hash algorithms @section Working with hash algorithms To use most of these function it is necessary to create a context; this is done using: @deftypefun gcry_error_t gcry_md_open (gcry_md_hd_t *@var{hd}, int @var{algo}, unsigned int @var{flags}) Create a message digest object for algorithm @var{algo}. @var{flags} may be given as an bitwise OR of constants described below. @var{algo} may be given as @code{0} if the algorithms to use are later set using @code{gcry_md_enable}. @var{hd} is guaranteed to either receive a valid handle or NULL. For a list of supported algorithms, see @xref{Available hash algorithms}. The flags allowed for @var{mode} are: @c begin table of hash flags @table @code @item GCRY_MD_FLAG_SECURE Allocate all buffers and the resulting digest in "secure memory". Use this is the hashed data is highly confidential. @item GCRY_MD_FLAG_HMAC Turn the algorithm into a HMAC message authentication algorithm. This only works if just one algorithm is enabled for the handle. Note that the function @code{gcry_md_setkey} must be used to set the MAC key. If you want CBC message authentication codes based on a cipher, see @xref{Working with cipher handles}. @end table @c begin table of hash flags You may use the function @code{gcry_md_is_enabled} to later check whether an algorithm has been enabled. @end deftypefun @c end function gcry_md_open If you want to calculate several hash algorithms at the same time, you have to use the following function right after the @code{gcry_md_open}: @deftypefun gcry_error_t gcry_md_enable (gcry_md_hd_t @var{h}, int @var{algo}) Add the message digest algorithm @var{algo} to the digest object described by handle @var{h}. Duplicated enabling of algorithms is detected and ignored. @end deftypefun If the flag @code{GCRY_MD_FLAG_HMAC} was used, the key for the MAC must be set using the function: @deftypefun gcry_error_t gcry_md_setkey (gcry_md_hd_t @var{h}, const void *@var{key}, size_t @var{keylen}) For use with the HMAC feature, set the MAC key to the value of @var{key} of length @var{keylen}. @end deftypefun After you are done with the hash calculation, you should release the resources by using: @deftypefun void gcry_md_close (gcry_md_hd_t @var{h}) Release all resources of hash context @var{h}. @var{h} should not be used after a call to this function. A @code{NULL} passed as @var{h} is ignored. @end deftypefun Often you have to do several hash operations using the same algorithm. To avoid the overhead of creating and releasing context, a reset function is provided: @deftypefun void gcry_md_reset (gcry_md_hd_t @var{h}) Reset the current context to its initial state. This is effectively identical to a close followed by an open and enabling all currently active algorithms. @end deftypefun Often it is necessary to start hashing some data and then continue to hash different data. To avoid hashing the same data several times (which might not even be possible if the data is received from a pipe), a snapshot of the current hash context can be taken and turned into a new context: @deftypefun gcry_error_t gcry_md_copy (gcry_md_hd_t *@var{handle_dst}, gcry_md_hd_t @var{handle_src}) Create a new digest object as an exact copy of the object described by handle @var{handle_src} and store it in @var{handle_dst}. The context is not reset and you can continue to hash data using this context and independently using the original context. @end deftypefun Now that we have prepared everything to calculate hashes, it is time to see how it is actually done. There are two ways for this, one to update the hash with a block of memory and one macro to update the hash by just one character. Both methods can be used on the same hash context. @deftypefun void gcry_md_write (gcry_md_hd_t @var{h}, const void *@var{buffer}, size_t @var{length}) Pass @var{length} bytes of the data in @var{buffer} to the digest object with handle @var{h} to update the digest values. This function should be used for large blocks of data. @end deftypefun @deftypefun void gcry_md_putc (gcry_md_hd_t @var{h}, int @var{c}) Pass the byte in @var{c} to the digest object with handle @var{h} to update the digest value. This is an efficient function, implemented as a macro to buffer the data before an actual update. @end deftypefun The semantics of the hash functions do not provide for reading out intermediate message digests because the calculation must be finalized first. This finalization may for example include the number of bytes hashed in the message digest or some padding. @deftypefun void gcry_md_final (gcry_md_hd_t @var{h}) Finalize the message digest calculation. This is not really needed because @code{gcry_md_read} does this implicitly. After this has been done no further updates (by means of @code{gcry_md_write} or @code{gcry_md_putc} are allowed. Only the first call to this function has an effect. It is implemented as a macro. @end deftypefun The way to read out the calculated message digest is by using the function: @deftypefun unsigned char *gcry_md_read (gcry_md_hd_t @var{h}, int @var{algo}) @code{gcry_md_read} returns the message digest after finalizing the calculation. This function may be used as often as required but it will always return the same value for one handle. The returned message digest is allocated within the message context and therefore valid until the handle is released or reseted (using @code{gcry_md_close} or @code{gcry_md_reset}. @var{algo} may be given as 0 to return the only enabled message digest or it may specify one of the enabled algorithms. The function does return @code{NULL} if the requested algorithm has not been enabled. @end deftypefun Because it is often necessary to get the message digest of one block of memory, a fast convenience function is available for this task: @deftypefun void gcry_md_hash_buffer (int @var{algo}, void *@var{digest}, const void *@var{buffer}, size_t @var{length}); @code{gcry_md_hash_buffer} is a shortcut function to calculate a message digest of a buffer. This function does not require a context and immediately returns the message digest of the @var{length} bytes at @var{buffer}. @var{digest} must be allocated by the caller, large enough to hold the message digest yielded by the the specified algorithm @var{algo}. This required size may be obtained by using the function @code{gcry_md_get_algo_dlen}. Note, that this function will abort the process if an unavailable algorithm is used. @end deftypefun @c *********************************** @c ***** MD info functions *********** @c *********************************** Hash algorithms are identified by internal algorithm numbers (see @code{gcry_md_open} for a list). However, in most applications they are used by names, so two functions are available to map between string representations and hash algorithm identifiers. @deftypefun const char *gcry_md_algo_name (int @var{algo}) Map the digest algorithm id @var{algo} to a string representation of the -algorithm name. For unknown algorithms this function returns an -empty string. This function should not be used to test for the +algorithm name. For unknown algorithms this function returns the +string @code{"?"}. This function should not be used to test for the availability of an algorithm. @end deftypefun @deftypefun int gcry_md_map_name (const char *@var{name}) Map the algorithm with @var{name} to a digest algorithm identifier. Returns 0 if the algorithm name is not known. Names representing @acronym{ASN.1} object identifiers are recognized if the @acronym{IETF} dotted format is used and the OID is prefixed with either "@code{oid.}" or "@code{OID.}". For a list of supported OIDs, see the source code at @file{cipher/md.c}. This function should not be used to test for the availability of an algorithm. @end deftypefun @deftypefun gcry_error_t gcry_md_get_asnoid (int @var{algo}, void *@var{buffer}, size_t *@var{length}) Return an DER encoded ASN.1 OID for the algorithm @var{algo} in the user allocated @var{buffer}. @var{length} must point to variable with the available size of @var{buffer} and receives after return the actual size of the returned OID. The returned error code may be @code{GPG_ERR_TOO_SHORT} if the provided buffer is to short to receive the OID; it is possible to call the function with @code{NULL} for @var{buffer} to have it only return the required size. The function returns 0 on success. @end deftypefun To test whether an algorithm is actually available for use, the following macro should be used: @deftypefun gcry_error_t gcry_md_test_algo (int @var{algo}) The macro returns 0 if the algorithm @var{algo} is available for use. @end deftypefun If the length of a message digest is not known, it can be retrieved using the following function: @deftypefun unsigned int gcry_md_get_algo_dlen (int @var{algo}) Retrieve the length in bytes of the digest yielded by algorithm @var{algo}. This is often used prior to @code{gcry_md_read} to allocate sufficient memory for the digest. @end deftypefun In some situations it might be hard to remember the algorithm used for the ongoing hashing. The following function might be used to get that information: @deftypefun int gcry_md_get_algo (gcry_md_hd_t @var{h}) Retrieve the algorithm used with the handle @var{h}. Note, that this does not work reliable if more than one algorithm is enabled in @var{h}. @end deftypefun The following macro might also be useful: @deftypefun int gcry_md_is_secure (gcry_md_hd_t @var{h}) This function returns true when the digest object @var{h} is allocated in "secure memory"; i.e. @var{h} was created with the @code{GCRY_MD_FLAG_SECURE}. @end deftypefun @deftypefun int gcry_md_is_enabled (gcry_md_hd_t @var{h}, int @var{algo}) This function returns true when the algorithm @var{algo} has been enabled for the digest object @var{h}. @end deftypefun Tracking bugs related to hashing is often a cumbersome task which requires to add a lot of printf statements into the code. @acronym{Libgcrypt} provides an easy way to avoid this. The actual data hashed can be written to files on request. @deftypefun void gcry_md_debug (gcry_md_hd_t @var{h}, const char *@var{suffix}) Enable debugging for the digest object with handle @var{h}. This creates create files named @file{dbgmd-.} while doing the actual hashing. @var{suffix} is the string part in the filename. The number is a counter incremented for each new hashing. The data in the file is the raw data as passed to @code{gcry_md_write} or @code{gcry_md_putc}. If @code{NULL} is used for @var{suffix}, the debugging is stopped and the file closed. This is only rarely required because @code{gcry_md_close} implicitly stops debugging. @end deftypefun The following two deprecated macros are used for debugging by old code. They shopuld be replaced by @code{gcry_md_debug}. @deftypefun void gcry_md_start_debug (gcry_md_hd_t @var{h}, const char *@var{suffix}) Enable debugging for the digest object with handle @var{h}. This creates create files named @file{dbgmd-.} while doing the actual hashing. @var{suffix} is the string part in the filename. The number is a counter incremented for each new hashing. The data in the file is the raw data as passed to @code{gcry_md_write} or @code{gcry_md_putc}. @end deftypefun @deftypefun void gcry_md_stop_debug (gcry_md_hd_t @var{h}, int @var{reserved}) Stop debugging on handle @var{h}. @var{reserved} should be specified as 0. This function is usually not required because @code{gcry_md_close} does implicitly stop debugging. @end deftypefun @c ********************************************************** @c ******************* Public Key ************************* @c ********************************************************** @node Public Key cryptography (I) @chapter Public Key cryptography (I) Public key cryptography, also known as asymmetric cryptography, is an easy way for key management and to provide digital signatures. @acronym{Libgcrypt} provides two completely different interfaces to public key cryptography, this chapter explains the one based on S-expressions. @menu * Available algorithms:: Algorithms supported by the library. * Used S-expressions:: Introduction into the used S-expression. * Public key modules:: How to work with public key modules. * Cryptographic Functions:: Functions for performing the cryptographic actions. * General public-key related Functions:: General functions, not implementing any cryptography. @end menu @node Available algorithms @section Available algorithms @acronym{Libgcrypt} supports the RSA (Rivest-Shamir-Adleman) algorithms as well as DSA (Digital Signature Algorithm) and ElGamal. The versatile interface allows to add more algorithms in the future. @node Used S-expressions @section Used S-expressions @acronym{Libgcrypt}'s API for asymmetric cryptography is based on data structures called S-expressions (see XXXX) and does not work with contexts as most of the other building blocks of @acronym{Libgcrypt} do. The following information are stored in S-expressions: @table @asis @item keys @item plain text data @item encrypted data @item signatures @end table @noindent To describe how @acronym{Libgcrypt} expect keys, we use some examples. Note that words in @ifnottex uppercase @end ifnottex @iftex italics @end iftex indicate parameters whereas lowercase words are literals. @example (private-key (dsa (p @var{p-mpi}) (q @var{q-mpi}) (g @var{g-mpi}) (y @var{y-mpi}) (x @var{x-mpi}))) @end example @noindent This specifies a DSA private key with the following parameters: @table @var @item p-mpi DSA prime @math{p}. @item q-mpi DSA group order @math{q} (which is a prime divisor of @math{p-1}). @item g-mpi DSA group generator @math{g}. @item y-mpi DSA public key value @math{y = g^x \bmod p}. @item x-mpi DSA secret exponent x. @end table All the MPI values are expected to be in @code{GCRYMPI_FMT_USG} format. The public key is similar with "private-key" replaced by "public-key" and no @var{x-mpi}. An easy way to create such an S-expressions is by using @code{gcry_sexp_build} which allows to pass a string with printf-like escapes to insert MPI values. @noindent Here is an example for an RSA key: @example (private-key (rsa (n @var{n-mpi}) (e @var{e-mpi}) (d @var{d-mpi}) (p @var{p-mpi}) (q @var{q-mpi}) (u @var{u-mpi}) @end example @noindent with @table @var @item n-mpi RSA public modulus @math{n}. @item e-mpi RSA public exponent @math{e}. @item d-mpi RSA secret exponent @math{d = e^{-1} \bmod (p-1)(q-1)}. @item p-mpi RSA secret prime @math{p}. @item q-mpi RSA secret prime @math{q} with @math{q > p}. @item u-mpi multiplicative inverse @math{u = p^{-1} \bmod q}. @end table @node Public key modules @section Public key modules @acronym{Libgcrypt} makes it possible to load additional `public key modules'; these public key algorithms can be used just like the algorithms that are built into the library directly. For an introduction into extension modules, see @xref{Modules}. @deftp {Data type} gcry_pk_spec_t This is the `module specification structure' needed for registering public key modules, which has to be filled in by the user before it can be used to register a module. It contains the following members: @table @code @item const char *name The primary name of this algorithm. @item char **aliases A list of strings that are `aliases' for the algorithm. The list must be terminated with a NULL element. @item const char *elements_pkey String containing the one-letter names of the MPI values contained in a public key. @item const char *element_skey String containing the one-letter names of the MPI values contained in a secret key. @item const char *elements_enc String containing the one-letter names of the MPI values that are the result of an encryption operation using this algorithm. @item const char *elements_sig String containing the one-letter names of the MPI values that are the result of a sign operation using this algorithm. @item const char *elements_grip String containing the one-letter names of the MPI values that are to be included in the `key grip'. @item int use The bitwise-OR of the following flags, depending on the abilities of the algorithm: @table @code @item GCRY_PK_USAGE_SIGN The algorithm supports signing and verifying of data. @item GCRY_PK_USAGE_ENCR The algorithm supports the encryption and decryption of data. @end table @item gcry_pk_generate_t generate The function responsible for generating a new key pair. See below for a description of this type. @item gcry_pk_check_secret_key_t check_secret_key The function responsible for checking the sanity of a provided secret key. See below for a description of this type. @item gcry_pk_encrypt_t encrypt The function responsible for encrypting data. See below for a description of this type. @item gcry_pk_decrypt_t decrypt The function responsible for decrypting data. See below for a description of this type. @item gcry_pk_sign_t sign The function responsible for signing data. See below for a description of this type. @item gcry_pk_verify_t verify The function responsible for verifying that the provided signature matches the provided data. See below for a description of this type. @item gcry_pk_get_nbits_t get_nbits The function responsible for returning the number of bits of a provided key. See below for a description of this type. @end table @end deftp @deftp {Data type} gcry_pk_generate_t Type for the `generate' function, defined as: gcry_err_code_t (*gcry_pk_generate_t) (int algo, unsigned int nbits, unsigned long use_e, gcry_mpi_t *skey, gcry_mpi_t **retfactors) @end deftp @deftp {Data type} gcry_pk_check_secret_key_t Type for the `check_secret_key' function, defined as: gcry_err_code_t (*gcry_pk_check_secret_key_t) (int algo, gcry_mpi_t *skey) @end deftp @deftp {Data type} gcry_pk_encrypt_t Type for the `encrypt' function, defined as: gcry_err_code_t (*gcry_pk_encrypt_t) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey, int flags) @end deftp @deftp {Data type} gcry_pk_decrypt_t Type for the `decrypt' function, defined as: gcry_err_code_t (*gcry_pk_decrypt_t) (int algo, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, int flags) @end deftp @deftp {Data type} gcry_pk_sign_t Type for the `sign' function, defined as: gcry_err_code_t (*gcry_pk_sign_t) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey) @end deftp @deftp {Data type} gcry_pk_verify_t Type for the `verify' function, defined as: gcry_err_code_t (*gcry_pk_verify_t) (int algo, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey, int (*cmp) (void *, gcry_mpi_t), void *opaquev) @end deftp @deftp {Data type} gcry_pk_get_nbits_t Type for the `get_nbits' function, defined as: unsigned (*gcry_pk_get_nbits_t) (int algo, gcry_mpi_t *pkey) @end deftp @deftypefun gcry_error_t gcry_pk_register (gcry_pk_spec_t *@var{pubkey}, unsigned int *algorithm_id, gcry_module_t *@var{module}) Register a new public key module whose specification can be found in @var{pubkey}. On success, a new algorithm ID is stored in @var{algorithm_id} and a pointer representing this module is stored in @var{module}. @end deftypefun @deftypefun void gcry_pk_unregister (gcry_module_t @var{module}) Unregister the public key module identified by @var{module}, which must have been registered with gcry_pk_register. @end deftypefun @deftypefun gcry_error_t gcry_pk_list (int *@var{list}, int *@var{list_length}) Get a list consisting of the IDs of the loaded pubkey modules. If @var{list} is zero, write the number of loaded pubkey modules to @var{list_length} and return. If @var{list} is non-zero, the first *@var{list_length} algorithm IDs are stored in @var{list}, which must be of according size. In case there are less pubkey modules than *@var{list_length}, *@var{list_length} is updated to the correct number. @end deftypefun @node Cryptographic Functions @section Cryptographic Functions @noindent Note, that we will in future allow to use keys without p,q and u specified and may also support other parameters for performance reasons. @noindent Some functions operating on S-expressions support `flags', that influence the operation. These flags have to be listed in a sub-S-expression named `flags'; the following flags are known: @table @code @item pkcs1 Use PKCS#1 block type 2 padding. @item no-blinding Do not use a technique called `blinding', which is used by default in order to prevent leaking of secret information. Blinding is only implemented by RSA, but it might be implemented by other algorithms in the future as well, when necessary. @end table @noindent Now that we know the key basics, we can carry on and explain how to encrypt and decrypt data. In almost all cases the data is a random session key which is in turn used for the actual encryption of the real data. There are 2 functions to do this: @deftypefun gcry_error_t gcry_pk_encrypt (@w{gcry_sexp_t *@var{r_ciph},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{pkey}}) Obviously a public key must be provided for encryption. It is expected as an appropriate S-expression (see above) in @var{pkey}. The data to be encrypted can either be in the simple old format, which is a very simple S-expression consisting only of one MPI, or it may be a more complex S-expression which also allows to specify flags for operation, like e.g. padding rules. @noindent If you don't want to let @acronym{Libgcrypt} handle the padding, you must pass an appropriate MPI using this expression for @var{data}: @example (data (flags raw) (value @var{mpi})) @end example @noindent This has the same semantics as the old style MPI only way. @var{MPI} is the actual data, already padded appropriate for your protocol. Most systems however use PKCS#1 padding and so you can use this S-expression for @var{data}: @example (data (flags pkcs1) (value @var{block})) @end example @noindent Here, the "flags" list has the "pkcs1" flag which let the function know that it should provide PKCS#1 block type 2 padding. The actual data to be encrypted is passed as a string of octets in @var{block}. The function checks that this data actually can be used with the given key, does the padding and encrypts it. If the function could successfully perform the encryption, the return value will be 0 and a a new S-expression with the encrypted result is allocated and assign to the variable at the address of @var{r_ciph}. The caller is responsible to release this value using @code{gcry_sexp_release}. In case of an error, an error code is returned and @var{r_ciph} will be set to @code{NULL}. @noindent The returned S-expression has this format when used with RSA: @example (enc-val (rsa (a @var{a-mpi}))) @end example @noindent Where @var{a-mpi} is an MPI with the result of the RSA operation. When using the ElGamal algorithm, the return value will have this format: @example (enc-val (elg (a @var{a-mpi}) (b @var{b-mpi}))) @end example @noindent Where @var{a-mpi} and @var{b-mpi} are MPIs with the result of the ElGamal encryption operation. @end deftypefun @c end gcry_pk_encrypt @deftypefun gcry_error_t gcry_pk_decrypt (@w{gcry_sexp_t *@var{r_plain},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{skey}}) Obviously a private key must be provided for decryption. It is expected as an appropriate S-expression (see above) in @var{skey}. The data to be decrypted must match the format of the result as returned by @code{gcry_pk_encrypt}, but should be enlarged with a @code{flags} element: @example (enc-val (flags) (elg (a @var{a-mpi}) (b @var{b-mpi}))) @end example @noindent Note, that this function currently does not know of any padding methods and the caller must do any un-padding on his own. @noindent The function returns 0 on success or an error code. The variable at the address of @var{r_plain} will be set to NULL on error or receive the decrypted value on success. The format of @var{r_plain} is a simple S-expression part (i.e. not a valid one) with just one MPI if there was no @code{flags} element in @var{data}; if at least an empty @code{flags} is passed in @var{data}, the format is: @example (value @var{plaintext}) @end example @end deftypefun @c end gcry_pk_decrypt Another operation commonly performed using public key cryptography is signing data. In some sense this is even more important than encryption because digital signatures are an important instrument for key management. @acronym{Libgcrypt} supports digital signatures using 2 functions, similar to the encryption functions: @deftypefun gcry_error_t gcry_pk_sign (@w{gcry_sexp_t *@var{r_sig},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{skey}}) This function creates a digital signature for @var{data} using the private key @var{skey} and place it into the variable at the address of @var{r_sig}. @var{data} may either be the simple old style S-expression with just one MPI or a modern and more versatile S-expression which allows to let @acronym{Libgcrypt} handle padding: @example (data (flags pkcs1) (hash @var{hash-algo} @var{block})) @end example @noindent This example requests to sign the data in @var{block} after applying PKCS#1 block type 1 style padding. @var{hash-algo} is a string with the hash algorithm to be encoded into the signature, this may be any hash algorithm name as supported by @acronym{Libgcrypt}. Most likely, this will be "sha1", "rmd160" or "md5". It is obvious that the length of @var{block} must match the size of that message digests; the function checks that this and other constraints are valid. @noindent If PKCS#1 padding is not required (because the caller does already provide a padded value), either the old format or better the following format should be used: @example (data (flags raw) (value @var{mpi})) @end example @noindent Here, the data to be signed is directly given as an @var{MPI}. @noindent The signature is returned as a newly allocated S-expression in @var{r_sig} using this format for RSA: @example (sig-val (rsa (s @var{s-mpi}))) @end example Where @var{s-mpi} is the result of the RSA sign operation. For DSA the S-expression returned is: @example (sig-val (dsa (r @var{r-mpi}) (s @var{s-mpi}))) @end example Where @var{r-mpi} and @var{s-mpi} are the result of the DSA sign operation. For ElGamal signing (which is slow, yields large numbers and probably is not as secure as the other algorithms), the same format is used with "elg" replacing "dsa". @end deftypefun @c end gcry_pk_sign @noindent The operation most commonly used is definitely the verification of a signature. @acronym{Libgcrypt} provides this function: @deftypefun gcry_error_t gcry_pk_verify (@w{gcry_sexp_t @var{sig}}, @w{gcry_sexp_t @var{data}}, @w{gcry_sexp_t @var{pkey}}) This is used to check whether the signature @var{sig} matches the @var{data}. The public key @var{pkey} must be provided to perform this verification. This function is similar in its parameters to @code{gcry_pk_sign} with the exceptions that the public key is used instead of the private key and that no signature is created but a signature, in a format as created by @code{gcry_pk_sign}, is passed to the function in @var{sig}. @noindent The result is 0 for success (i.e. the data matches the signature), or an error code where the most relevant code is @code{GCRYERR_BAD_SIGNATURE} to indicate that the signature does not match the provided data. @end deftypefun @c end gcry_pk_verify @node General public-key related Functions @section General public-key related Functions @noindent A couple of utility functions are available to retrieve the length of the key, map algorithm identifiers and perform sanity checks: @deftypefun {const char *} gcry_pk_algo_name (int @var{algo}) Map the public key algorithm id @var{algo} to a string representation of -the algorithm name. For unknown algorithms this functions returns an -empty string. +the algorithm name. For unknown algorithms this functions returns the +string @code{"?"}. This function should not be used to test for the +availability of an algorithm. @end deftypefun @deftypefun int gcry_pk_map_name (const char *@var{name}) Map the algorithm @var{name} to a public key algorithm Id. Returns 0 if the algorithm name is not known. @end deftypefun @deftypefun int gcry_pk_test_algo (int @var{algo}) Return 0 if the public key algorithm @var{algo} is available for use. Note, that this is implemented as a macro. @end deftypefun @deftypefun {unsigned int} gcry_pk_get_nbits (gcry_sexp_t @var{key}) Return what is commonly referred as the key length for the given public or private in @var{key}. @end deftypefun @deftypefun {unsigned char *} gcry_pk_get_keygrip (@w{gcry_sexp_t @var{key}}, @w{unsigned char *@var{array}}) Return the so called "keygrip" which is the SHA-1 hash of the public key parameters expressed in a way depended on the algorithm. @var{array} must either provide space for 20 bytes or be @code{NULL}. In the latter case a newly allocated array of that size is returned. On success a pointer to the newly allocated space or to @var{array} is returned. @code{NULL} is returned to indicate an error which is most likely an unknown algorithm or one where a "keygrip" has not yet been defined. The function accepts public or secret keys in @var{key}. @end deftypefun @deftypefun gcry_error_t gcry_pk_testkey (gcry_sexp_t @var{key}) Return zero if the private key @var{key} is `sane', an error code otherwise. Note, that it is not possible to check the `saneness' of a public key. @end deftypefun @deftypefun gcry_error_t gcry_pk_algo_info (@w{int @var{algo}}, @w{int @var{what}}, @w{void *@var{buffer}}, @w{size_t *@var{nbytes}}) Depending on the value of @var{what} return various information about the public key algorithm with the id @var{algo}. Note, that the function returns @code{-1} on error and the actual error code must be retrieved using the function @code{gcry_errno}. The currently defined values for @var{what} are: @table @code @item GCRYCTL_TEST_ALGO: Return 0 when the specified algorithm is available for use. @var{buffer} must be @code{NULL}, @var{nbytes} may be passed as @code{NULL} or point to a variable with the required usage of the algorithm. This may be 0 for "don't care" or the bit-wise OR of these flags: @table @code @item GCRY_PK_USAGE_SIGN Algorithm is usable for signing. @item GCRY_PK_USAGE_ENCR Algorithm is usable for encryption. @end table @item GCRYCTL_GET_ALGO_USAGE: Return the usage flags for the given algorithm. An invalid algorithm return 0. Disabled algorithms are ignored here because we want to know whether the algorithm is at all capable of a certain usage. @item GCRYCTL_GET_ALGO_NPKEY Return the number of elements the public key for algorithm @var{algo} consist of. Return 0 for an unknown algorithm. @item GCRYCTL_GET_ALGO_NSKEY Return the number of elements the private key for algorithm @var{algo} consist of. Note that this value is always larger than that of the public key. Return 0 for an unknown algorithm. @item GCRYCTL_GET_ALGO_NSIGN Return the number of elements a signature created with the algorithm @var{algo} consists of. Return 0 for an unknown algorithm or for an algorithm not capable of creating signatures. @item GCRYCTL_GET_ALGO_NENC Return the number of elements a encrypted message created with the algorithm @var{algo} consists of. Return 0 for an unknown algorithm or for an algorithm not capable of encryption. @end table @noindent Please note that parameters not required should be passed as @code{NULL}. @end deftypefun @c end gcry_pk_algo_info @deftypefun gcry_error_t gcry_pk_ctl (@w{int @var{cmd}}, @w{void *@var{buffer}}, @w{size_t @var{buflen}}) This is a general purpose function to perform certain control operations. @var{cmd} controls what is to be done. The return value is 0 for success or an error code. Currently supported values for @var{cmd} are: @table @code @item GCRYCTL_DISABLE_ALGO Disable the algorithm given as an algorithm id in @var{buffer}. @var{buffer} must point to an @code{int} variable with the algorithm id and @var{buflen} must have the value @code{sizeof (int)}. @end table @end deftypefun @c end gcry_pk_ctl @noindent @acronym{Libgcrypt} also provides a function for generating public key pairs: @deftypefun gcry_error_t gcry_pk_genkey (@w{gcry_sexp_t *@var{r_key}}, @w{gcry_sexp_t @var{parms}}) This function create a new public key pair using information given in the S-expression @var{parms} and stores the private and the public key in one new S-expression at the address given by @var{r_key}. In case of an error, @var{r_key} is set to @code{NULL}. The return code is 0 for success or an error code otherwise. @noindent Here is an example for @var{parms} for creating a 1024 bit RSA key: @example (genkey (rsa (nbits 4:1024))) @end example @noindent To create an ElGamal key, substitute "elg" for "rsa" and to create a DSA key use "dsa". Valid ranges for the key length depend on the algorithms; all commonly used key lengths are supported. Currently supported parameters are: @table @code @item nbits This is always required to specify the length of the key. The argument is a string with a number in C-notation. The value should be a multiple of 8. @item rsa-use-e This is only used with RSA to give a hint for the public exponent. The value will be used as a base to test for a usable exponent. Some values are special: @table @samp @item 0 Use a secure and fast value. This is currently the number 41. @item 1 Use a secure value as required by some specification. This is currently the number 65537. @item 2 Reserved @end table @noindent If this parameter is not used, @acronym{Libgcrypt} uses for historic reasons 65537. @item qbits This is only meanigful for DSA keys. If it is given the DSA key is generated with a Q parameyer of this size. If it is not given or zero Q is deduced from NBITS in this way: @table @samp @item 512 <= N <= 1024 Q = 160 @item N = 2048 Q = 224 @item N = 3072 Q = 256 @item N = 7680 Q = 384 w@item N = 15360 Q = 512 @end table Note, that in this case only the values for N, as given in the table, are allowed. When specifying Q all values of N in the range 512 to 15680 are valid as long as they are multiples of 8. @end table @c end table of parameters @noindent The key pair is returned in a format depending on the algorithm. Both private and public keys are returned in one container and may be accompanied by some miscellaneous information. @noindent As an example, here is what the ElGamal key generation returns: @example (key-data (public-key (elg (p @var{p-mpi}) (g @var{g-mpi}) (y @var{y-mpi}))) (private-key (elg (p @var{p-mpi}) (g @var{g-mpi}) (y @var{y-mpi}) (x @var{x-mpi}))) (misc-key-info (pm1-factors @var{n1 n2 ... nn}))) @end example @noindent As you can see, some of the information is duplicated, but this provides an easy way to extract either the public or the private key. Note that the order of the elements is not defined, e.g. the private key may be stored before the public key. @var{n1 n2 ... nn} is a list of prime numbers used to composite @var{p-mpi}; this is in general not a very useful information. @end deftypefun @c end gcry_pk_genkey @node Public Key cryptography (II) @chapter Public Key cryptography (II) This chapter documents the alternative interface to asymmetric cryptography (ac) that is not based on S-expressions, but on native C data structures. As opposed to the pk interface described in the former chapter, this one follows an open/use/close paradigm like other building blocks of the library. @menu * Available asymmetric algorithms:: List of algorithms supported by the library. * Working with sets of data:: How to work with sets of data. * Working with IO objects:: How to work with IO objects. * Working with handles:: How to use handles. * Working with keys:: How to work with keys. * Using cryptographic functions:: How to perform cryptographic operations. * Handle-independent functions:: General functions independent of handles. @end menu @node Available asymmetric algorithms @section Available asymmetric algorithms @acronym{Libgcrypt} supports the RSA (Rivest-Shamir-Adleman) algorithms as well as DSA (Digital Signature Algorithm) and ElGamal. The versatile interface allows to add more algorithms in the future. @deftp {Data type} gcry_ac_id_t The following constants are defined for this type: @table @code @item GCRY_AC_RSA Riven-Shamir-Adleman @item GCRY_AC_DSA Digital Signature Algorithm @item GCRY_AC_ELG ElGamal @item GCRY_AC_ELG_E ElGamal, encryption only. @end table @end deftp @node Working with sets of data @section Working with sets of data In the context of this interface the term `data set' refers to a list of `named MPI values' that is used by functions performing cryptographic operations; a named MPI value is a an MPI value, associated with a label. Such data sets are used for representing keys, since keys simply consist of a variable amount of numbers. Furthermore some functions return data sets to the caller that are to be provided to other functions. This section documents the data types, symbols and functions that are relevant for working with data sets. @deftp {Data type} gcry_ac_data_t A single data set. @end deftp The following flags are supported: @table @code @item GCRY_AC_FLAG_DEALLOC Used for storing data in a data set. If given, the data will be released by the library. Note that whenever one of the ac functions is about to release objects because of this flag, the objects are expected to be stored in memory allocated through the Libgcrypt memory management. In other words: gcry_free() is used instead of free(). @item GCRY_AC_FLAG_COPY Used for storing/retrieving data in/from a data set. If given, the library will create copies of the provided/contained data, which will then be given to the user/associated with the data set. @end table @deftypefun gcry_error_t gcry_ac_data_new (gcry_ac_data_t *@var{data}) Creates a new, empty data set and stores it in @var{data}. @end deftypefun @deftypefun void gcry_ac_data_destroy (gcry_ac_data_t @var{data}) Destroys the data set @var{data}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_set (gcry_ac_data_t @var{data}, unsigned int @var{flags}, char *@var{name}, gcry_mpi_t @var{mpi}) Add the value @var{mpi} to @var{data} with the label @var{name}. If @var{flags} contains GCRY_AC_FLAG_DATA_COPY, the data set will contain copies of @var{name} and @var{mpi}. If @var{flags} contains GCRY_AC_FLAG_DATA_DEALLOC or GCRY_AC_FLAG_DATA_COPY, the values contained in the data set will be deallocated when they are to be removed from the data set. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_copy (gcry_ac_data_t *@var{data_cp}, gcry_ac_data_t @var{data}) Create a copy of the data set @var{data} and store it in @var{data_cp}. FIXME: exact semantics undefined. @end deftypefun @deftypefun unsigned int gcry_ac_data_length (gcry_ac_data_t @var{data}) Returns the number of named MPI values inside of the data set @var{data}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t @var{data}, unsigned int @var{flags}, char *@var{name}, gcry_mpi_t *@var{mpi}) Store the value labelled with @var{name} found in @var{data} in @var{mpi}. If @var{flags} contains GCRY_AC_FLAG_COPY, store a copy of the @var{mpi} value contained in the data set. @var{mpi} may be NULL (this might be useful for checking the existence of an MPI with extracting it). @end deftypefun @deftypefun gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t @var{data}, unsigned int flags, unsigned int @var{index}, const char **@var{name}, gcry_mpi_t *@var{mpi}) Stores in @var{name} and @var{mpi} the named @var{mpi} value contained in the data set @var{data} with the index @var{idx}. If @var{flags} contains GCRY_AC_FLAG_COPY, store copies of the values contained in the data set. @var{name} or @var{mpi} may be NULL. @end deftypefun @deftypefun void gcry_ac_data_clear (gcry_ac_data_t @var{data}) Destroys any values contained in the data set @var{data}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_to_sexp (gcry_ac_data_t @var{data}, gcry_sexp_t *@var{sexp}, const char **@var{identifiers}) This function converts the data set @var{data} into a newly created S-Expression, which is to be stored in @var{sexp}; @var{identifiers} is a NULL terminated list of C strings, which specifies the structure of the S-Expression. Example: If @var{identifiers} is a list of pointers to the strings ``foo'' and ``bar'' and if @var{data} is a data set containing the values ``val1 = 0x01'' and ``val2 = 0x02'', then the resulting S-Expression will look like this: (foo (bar ((val1 0x01) (val2 0x02))). @end deftypefun @deftypefun gcry_error gcry_ac_data_from_sexp (gcry_ac_data_t *@var{data}, gcry_sexp_t @var{sexp}, const char **@var{identifiers}) This function converts the S-Expression @var{sexp} into a newly created data set, which is to be stored in @var{data}; @var{identifiers} is a NULL terminated list of C strings, which specifies the structure of the S-Expression. If the list of identifiers does not match the structure of the S-Expression, the function fails. @end deftypefun @node Working with IO objects @section Working with IO objects Note: IO objects are currently only used in the context of message encoding/decoding and encryption/signature schemes. @deftp {Data type} {gcry_ac_io_t} @code{gcry_ac_io_t} is the type to be used for IO objects. @end deftp IO objects provide an uniform IO layer on top of different underlying IO mechanisms; either they can be used for providing data to the library (mode is GCRY_AC_IO_READABLE) or they can be used for retrieving data from the library (mode is GCRY_AC_IO_WRITABLE). IO object need to be initialized by calling on of the following functions: @deftypefun void gcry_ac_io_init (gcry_ac_io_t *@var{ac_io}, gcry_ac_io_mode_t @var{mode}, gcry_ac_io_type_t @var{type}, ...); Initialize @var{ac_io} according to @var{mode}, @var{type} and the variable list of arguments. The list of variable arguments to specify depends on the given @var{type}. @end deftypefun @deftypefun void gcry_ac_io_init_va (gcry_ac_io_t *@var{ac_io}, gcry_ac_io_mode_t @var{mode}, gcry_ac_io_type_t @var{type}, va_list @var{ap}); Initialize @var{ac_io} according to @var{mode}, @var{type} and the variable list of arguments @var{ap}. The list of variable arguments to specify depends on the given @var{type}. @end deftypefun The following types of IO objects exist: @table @code @item GCRY_AC_IO_STRING In case of GCRY_AC_IO_READABLE the IO object will provide data from a memory string. Arguments to specify at initialization time: @table @code @item unsigned char * Pointer to the beginning of the memory string @item size_t Size of the memory string @end table In case of GCRY_AC_IO_WRITABLE the object will store retrieved data in a newly allocated memory string. Arguments to specify at initialization time: @table @code @item unsigned char ** Pointer to address, at which the pointer to the newly created memory string is to be stored @item size_t * Pointer to address, at which the size of the newly created memory string is to be stored @end table @item GCRY_AC_IO_CALLBACK In case of GCRY_AC_IO_READABLE the object will forward read requests to a provided callback function. Arguments to specify at initialization time: @table @code @item gcry_ac_data_read_cb_t Callback function to use @item void * Opaque argument to provide to the callback function @end table In case of GCRY_AC_IO_WRITABLE the object will forward write requests to a provided callback function. Arguments to specify at initialization time: @table @code @item gcry_ac_data_write_cb_t Callback function to use @item void * Opaque argument to provide to the callback function @end table @end table @node Working with handles @section Working with handles In order to use an algorithm, an according handle must be created. This is done using the following function: @deftypefun gcry_error_t gcry_ac_open (gcry_ac_handle_t *@var{handle}, int @var{algorithm}, int @var{flags}) Creates a new handle for the algorithm @var{algorithm} and stores it in @var{handle}. @var{flags} is not used currently. @var{algorithm} must be a valid algorithm ID, see @xref{Available algorithms}, for a list of supported algorithms and the according constants. Besides using the listed constants directly, the functions -@code{gcry_ac_name_to_id} may be used to convert the textual name of +@code{gcry_pk_name_to_id} may be used to convert the textual name of an algorithm into the according numeric ID. @end deftypefun @deftypefun void gcry_ac_close (gcry_ac_handle_t @var{handle}) Destroys the handle @var{handle}. @end deftypefun @node Working with keys @section Working with keys @deftp {Data type} gcry_ac_key_type_t Defined constants: @table @code @item GCRY_AC_KEY_TYPE_SECRET Specifies a secret key. @item GCRY_AC_KEY_TYPE_PUBLIC Specifies a public key. @end table @end deftp @deftp {Data type} gcry_ac_key_t This type represents a single `key', either a secret one or a public one. @end deftp @deftp {Data type} gcry_ac_key_pair_t This type represents a `key pair' containing a secret and a public key. @end deftp Key data structures can be created in two different ways; a new key pair can be generated, resulting in ready-to-use key. Alternatively a key can be initialized from a given data set. @deftypefun gcry_error_t gcry_ac_key_init (gcry_ac_key_t *@var{key}, gcry_ac_handle_t @var{handle}, gcry_ac_key_type_t @var{type}, gcry_ac_data_t @var{data}) Creates a new key of type @var{type}, consisting of the MPI values contained in the data set @var{data} and stores it in @var{key}. @end deftypefun @deftypefun gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t @var{handle}, unsigned int @var{nbits}, void *@var{key_spec}, gcry_ac_key_pair_t *@var{key_pair}, gcry_mpi_t **@var{misc_data}) Generates a new key pair via the handle @var{handle} of @var{NBITS} bits and stores it in @var{key_pair}. In case non-standard settings are wanted, a pointer to a structure of type @code{gcry_ac_key_spec__t}, matching the selected algorithm, can be given as @var{key_spec}. @var{misc_data} is not used yet. Such a structure does only exist for RSA. A descriptions of the members of the supported structures follows. @table @code @item gcry_ac_key_spec_rsa_t @table @code @item gcry_mpi_t e Generate the key pair using a special @code{e}. The value of @code{e} has the following meanings: @table @code @item = 0 Let @acronym{Libgcrypt} decide what exponent should be used. @item = 1 Request the use of a ``secure'' exponent; this is required by some specification to be 65537. @item > 2 Try starting at this value until a working exponent is found. Note, that the current implementation leaks some information about the private key because the incrementation used is not randomized. Thus, this function will be changed in the future to return a random exponent of the given size. @end table @end table @end table Example code: @example @{ gcry_ac_key_pair_t key_pair; gcry_ac_key_spec_rsa_t rsa_spec; rsa_spec.e = gcry_mpi_new (0); gcry_mpi_set_ui (rsa_spec.e, 1) err = gcry_ac_open (&handle, GCRY_AC_RSA, 0); assert (! err); err = gcry_ac_key_pair_generate (handle, &key_pair, 1024, (void *) &rsa_spec); assert (! err); @} @end example @end deftypefun @deftypefun gcry_ac_key_t gcry_ac_key_pair_extract (gcry_ac_key_pair_t @var{key_pair}, gcry_ac_key_type_t @var{which}) Returns the key of type @var{which} out of the key pair @var{key_pair}. @end deftypefun @deftypefun void gcry_ac_key_destroy (gcry_ac_key_t @var{key}) Destroys the key @var{key}. @end deftypefun @deftypefun void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t @var{key_pair}) Destroys the key pair @var{key_pair}. @end deftypefun @deftypefun gcry_ac_data_t gcry_ac_key_data_get (gcry_ac_key_t @var{key}) Returns the data set contained in the key @var{key}. @end deftypefun @deftypefun gcry_error_t gcry_ac_key_test (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}) Verifies that the private key @var{key} is sane via @var{handle}. @end deftypefun @deftypefun gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, unsigned int *@var{nbits}) Stores the number of bits of the key @var{key} in @var{nbits} via @var{handle}. @end deftypefun @deftypefun gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, unsigned char *@var{key_grip}) Writes the 20 byte long key grip of the key @var{key} to @var{key_grip} via @var{handle}. @end deftypefun @node Using cryptographic functions @section Using cryptographic functions The following flags might be relevant: @table @code @item GCRY_AC_FLAG_NO_BLINDING Disable any blinding, which might be supported by the chosen algorithm; blinding is the default. @end table There exist two kinds of cryptographic functions available through the ac interface: primitives, and high-level functions. Primitives deal with MPIs (data sets) directly; what they provide is direct access to the cryptographic operations provided by an algorithm implementation. High-level functions deal with octet strings, according to a specified ``scheme''. Schemes make use of ``encoding methods'', which are responsible for converting the provided octet strings into MPIs, which are then forwared to the cryptographic primitives. Since schemes are to be used for a special purpose in order to achieve a particular security goal, there exist ``encryption schemes'' and ``signature schemes''. Encoding methods can be used seperately or implicitly through schemes. What follows is a description of the cryptographic primitives. @deftypefun gcry_error_t gcry_ac_data_encrypt (gcry_ac_handle_t @var{handle}, unsigned int @var{flags}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data_plain}, gcry_ac_data_t **@var{data_encrypted}) Encrypts the plain text MPI value @var{data_plain} with the key public @var{key} under the control of the flags @var{flags} and stores the resulting data set into @var{data_encrypted}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_decrypt (gcry_ac_handle_t @var{handle}, unsigned int @var{flags}, gcry_ac_key_t @var{key}, gcry_mpi_t *@var{data_plain}, gcry_ac_data_t @var{data_encrypted}) Decrypts the encrypted data contained in the data set @var{data_encrypted} with the secret key KEY under the control of the flags @var{flags} and stores the resulting plain text MPI value in @var{DATA_PLAIN}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_sign (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data}, gcry_ac_data_t *@var{data_signature}) Signs the data contained in @var{data} with the secret key @var{key} and stores the resulting signature in the data set @var{data_signature}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_verify (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data}, gcry_ac_data_t @var{data_signature}) Verifies that the signature contained in the data set @var{data_signature} is indeed the result of signing the data contained in @var{data} with the secret key belonging to the public key @var{key}. @end deftypefun What follows is a description of the high-level functions. The type ``gcry_ac_em_t'' is used for specifying encoding methods; the following methods are supported: @table @code @item GCRY_AC_EME_PKCS_V1_5 PKCS-V1_5 Encoding Method for Encryption. Options must be provided through a pointer to a correctly initialized object of type gcry_ac_eme_pkcs_v1_5_t. @item GCRY_AC_EMSA_PKCS_V1_5 PKCS-V1_5 Encoding Method for Signatures with Appendix. Options must be provided through a pointer to a correctly initialized object of type gcry_ac_emsa_pkcs_v1_5_t. @end table Option structure types: @table @code @item gcry_ac_eme_pkcs_v1_5_t @table @code @item gcry_ac_key_t key @item gcry_ac_handle_t handle @end table @item gcry_ac_emsa_pkcs_v1_5_t @table @code @item gcry_md_algo_t md @item size_t em_n @end table @end table Encoding methods can be used directly through the following functions: @deftypefun gcry_error_t gcry_ac_data_encode (gcry_ac_em_t @var{method}, unsigned int @var{flags}, void *@var{options}, unsigned char *@var{m}, size_t @var{m_n}, unsigned char **@var{em}, size_t *@var{em_n}) Encodes the message contained in @var{m} of size @var{m_n} according to @var{method}, @var{flags} and @var{options}. The newly created encoded message is stored in @var{em} and @var{em_n}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_decode (gcry_ac_em_t @var{method}, unsigned int @var{flags}, void *@var{options}, unsigned char *@var{em}, size_t @var{em_n}, unsigned char **@var{m}, size_t *@var{m_n}) Decodes the message contained in @var{em} of size @var{em_n} according to @var{method}, @var{flags} and @var{options}. The newly created decoded message is stored in @var{m} and @var{m_n}. @end deftypefun The type ``gcry_ac_scheme_t'' is used for specifying schemes; the following schemes are supported: @table @code @item GCRY_AC_ES_PKCS_V1_5 PKCS-V1_5 Encryption Scheme. No options can be provided. @item GCRY_AC_SSA_PKCS_V1_5 PKCS-V1_5 Signature Scheme (with Appendix). Options can be provided through a pointer to a correctly initialized object of type gcry_ac_ssa_pkcs_v1_5_t. @end table Option structure types: @table @code @item gcry_ac_ssa_pkcs_v1_5_t @table @code @item gcry_md_algo_t md @end table @end table The functions implementing schemes: @deftypefun gcry_error_t gcry_ac_data_encrypt_scheme (gcry_ac_handle_t @var{handle}, gcry_ac_scheme_t @var{scheme}, unsigned int @var{flags}, void *@var{opts}, gcry_ac_key_t @var{key}, gcry_ac_io_t *@var{io_message}, gcry_ac_io_t *@var{io_cipher}) Encrypts the plain text readable from @var{io_message} through @var{handle} with the public key @var{key} according to @var{scheme}, @var{flags} and @var{opts}. If @var{opts} is not NULL, it has to be a pointer to a structure specific to the chosen scheme (gcry_ac_es_*_t). The encrypted message is written to @var{io_cipher}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_decrypt_scheme (gcry_ac_handle_t @var{handle}, gcry_ac_scheme_t @var{scheme}, unsigned int @var{flags}, void *@var{opts}, gcry_ac_key_t @var{key}, gcry_ac_io_t *@var{io_cipher}, gcry_ac_io_t *@var{io_message}) Decrypts the cipher text readable from @var{io_cipher} through @var{handle} with the secret key @var{key} according to @var{scheme}, @var{flags} and @var{opts}. If @var{opts} is not NULL, it has to be a pointer to a structure specific to the chosen scheme (gcry_ac_es_*_t). The decrypted message is written to @var{io_message}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_sign_scheme (gcry_ac_handle_t @var{handle}, gcry_ac_scheme_t @var{scheme}, unsigned int @var{flags}, void *@var{opts}, gcry_ac_key_t @var{key}, gcry_ac_io_t *@var{io_message}, gcry_ac_io_t *@var{io_signature}) Signs the message readable from @var{io_message} through @var{handle} with the secret key @var{key} according to @var{scheme}, @var{flags} and @var{opts}. If @var{opts} is not NULL, it has to be a pointer to a structure specific to the chosen scheme (gcry_ac_ssa_*_t). The signature is written to @var{io_signature}. @end deftypefun @deftypefun gcry_error_t gcry_ac_data_verify_scheme (gcry_ac_handle_t @var{handle}, gcry_ac_scheme_t @var{scheme}, unsigned int @var{flags}, void *@var{opts}, gcry_ac_key_t @var{key}, gcry_ac_io_t *@var{io_message}, gcry_ac_io_t *@var{io_signature}) Verifies through @var{handle} that the signature readable from @var{io_signature} is indeed the result of signing the message readable from @var{io_message} with the secret key belonging to the public key @var{key} according to @var{scheme} and @var{opts}. If @var{opts} is not NULL, it has to be an anonymous structure (gcry_ac_ssa_*_t) specific to the chosen scheme. @end deftypefun @node Handle-independent functions @section Handle-independent functions +These two functions are deprecated; do not use them for new code. + @deftypefun gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t @var{algorithm}, const char **@var{name}) Stores the textual representation of the algorithm whose id is given -in @var{algorithm} in @var{name}. +in @var{algorithm} in @var{name}. Deprecated; use @code{gcry_pk_algo_name}. @end deftypefun @deftypefun gcry_error_t gcry_ac_name_to_id (const char *@var{name}, gcry_ac_id_t *@var{algorithm}) Stores the numeric ID of the algorithm whose textual representation is -contained in @var{name} in @var{algorithm}. +contained in @var{name} in @var{algorithm}. Deprecated; use +@code{gcry_pk_map_name}. @end deftypefun @c ********************************************************** @c ******************* Random ***************************** @c ********************************************************** @node Random Numbers @chapter Random Numbers @menu * Quality of random numbers:: @acronym{Libgcrypt} uses different quality levels. * Retrieving random numbers:: How to retrieve random numbers. @end menu @node Quality of random numbers @section Quality of random numbers @acronym{Libgcypt} offers random numbers of different quality levels: @deftp {Data type} enum gcry_random_level The constants for the random quality levels are of this type. @end deftp @table @code @item GCRY_WEAK_RANDOM This should not anymore be used. It has recently been changed to an alias of GCRY_STRONG_RANDOM. Use @code{gcry_create_nonce} instead. @item GCRY_STRONG_RANDOM Use this level for e.g. session keys and similar purposes. @item GCRY_VERY_STRONG_RANDOM Use this level for e.g. key material. @end table @node Retrieving random numbers @section Retrieving random numbers @deftypefun void gcry_randomize (unsigned char *@var{buffer}, size_t @var{length}, enum gcry_random_level @var{level}) Fill @var{buffer} with @var{length} random bytes using a random quality as defined by @var{level}. @end deftypefun @deftypefun void * gcry_random_bytes (size_t @var{nbytes}, enum gcry_random_level @var{level}) Allocate a memory block consisting of @var{nbytes} fresh random bytes using a random quality as defined by @var{level}. @end deftypefun @deftypefun void * gcry_random_bytes_secure (size_t @var{nbytes}, enum gcry_random_level @var{level}) Allocate a memory block consisting of @var{nbytes} fresh random bytes using a random quality as defined by @var{level}. This function differs from @code{gcry_random_bytes} in that the returned buffer is allocated in a ``secure'' area of the memory. @end deftypefun @deftypefun void gcry_create_nonce (unsigned char *@var{buffer}, size_t @var{length}) Fill @var{buffer} with @var{length} unpredictable bytes. This is commonly called a nonce and may also be used for initialization vectors and padding. This is an extra function nearly independent of the other random function for 3 reasons: It better protects the regular random generator's internal state, provides better performance and does not drain the precious entropy pool. @end deftypefun @c ********************************************************** @c ******************* S-Expressions *********************** @c ********************************************************** @node S-expressions @chapter S-expressions S-expressions are used by the public key functions to pass complex data structures around. These LISP like objects are used by some cryptographic protocols (cf. RFC-2692) and @acronym{Libgcrypt} provides functions to parse and construct them. For detailed information, see @cite{Ron Rivest, code and description of S-expressions, @uref{http://theory.lcs.mit.edu/~rivest/sexp.html}}. @menu * Data types for S-expressions:: Data types related with S-expressions. * Working with S-expressions:: How to work with S-expressions. @end menu @node Data types for S-expressions @section Data types for S-expressions @deftp {Data type} gcry_sexp_t The @code{gcry_sexp_t} type describes an object with the @acronym{Libgcrypt} internal representation of an S-expression. @end deftp @node Working with S-expressions @section Working with S-expressions @noindent There are several functions to create an @acronym{Libgcrypt} S-expression object from its external representation or from a string template. There is also a function to convert the internal representation back into one of the external formats: @deftypefun gcry_error_t gcry_sexp_new (@w{gcry_sexp_t *@var{r_sexp}}, @w{const void *@var{buffer}}, @w{size_t @var{length}}, @w{int @var{autodetect}}) This is the generic function to create an new S-expression object from its external representation in @var{buffer} of @var{length} bytes. On success the result is stored at the address given by @var{r_sexp}. With @var{autodetect} set to 0, the data in @var{buffer} is expected to be in canonized format, with @var{autodetect} set to 1 the parses any of the defined external formats. If @var{buffer} does not hold a valid S-expression an error code is returned and @var{r_sexp} set to @code{NULL}. Note, that the caller is responsible for releasing the newly allocated S-expression using @code{gcry_sexp_release}. @end deftypefun @deftypefun gcry_error_t gcry_sexp_create (@w{gcry_sexp_t *@var{r_sexp}}, @w{void *@var{buffer}}, @w{size_t @var{length}}, @w{int @var{autodetect}}, @w{void (*@var{freefnc})(void*)}) This function is identical to @code{gcry_sexp_new} but has an extra argument @var{freefnc}, which, when not set to @code{NULL}, is expected to be a function to release the @var{buffer}; most likely the standard @code{free} function is used for this argument. This has the effect of transferring the ownership of @var{buffer} to the created object in @var{r_sexp}. The advantage of using this function is that @acronym{Libgcrypt} might decide to directly use the provided buffer and thus avoid extra copying. @end deftypefun @deftypefun gcry_error_t gcry_sexp_sscan (@w{gcry_sexp_t *@var{r_sexp}}, @w{size_t *@var{erroff}}, @w{const char *@var{buffer}}, @w{size_t @var{length}}) This is another variant of the above functions. It behaves nearly identical but provides an @var{erroff} argument which will receive the offset into the buffer where the parsing stopped on error. @end deftypefun @deftypefun gcry_error_t gcry_sexp_build (@w{gcry_sexp_t *@var{r_sexp}}, @w{size_t *@var{erroff}}, @w{const char *@var{format}, ...}) This function creates an internal S-expression from the string template @var{format} and stores it at the address of @var{r_sexp}. If there is a parsing error, the function returns an appropriate error code and stores the offset into @var{format} where the parsing stopped in @var{erroff}. The function supports a couple of printf-like formatting characters and expects arguments for some of these escape sequences right after @var{format}. The following format characters are defined: @table @samp @item %m The next argument is expected to be of type @code{gcry_mpi_t} and a copy of its value is inserted into the resulting S-expression. @item %s The next argument is expected to be of type @code{char *} and that string is inserted into the resulting S-expression. @item %d The next argument is expected to be of type @code{int} and its value is inserted into the resulting S-expression. @item %b The next argument is expected to be of type @code{int} directly followed by an argument of type @code{char *}. This represents a buffer of given length to be inserted into the resulting regular expression. @end table @noindent No other format characters are defined and would return an error. Note, that the format character @samp{%%} does not exists, because a percent sign is not a valid character in an S-expression. @end deftypefun @deftypefun void gcry_sexp_release (@w{gcry_sexp_t @var{sexp}}) Release the S-expression object @var{sexp}. @end deftypefun @noindent The next 2 functions are used to convert the internal representation back into a regular external S-expression format and to show the structure for debugging. @deftypefun size_t gcry_sexp_sprint (@w{gcry_sexp_t @var{sexp}}, @w{int @var{mode}}, @w{char *@var{buffer}}, @w{size_t @var{maxlength}}) Copies the S-expression object @var{sexp} into @var{buffer} using the format specified in @var{mode}. @var{maxlength} must be set to the allocated length of @var{buffer}. The function returns the actual length of valid bytes put into @var{buffer} or 0 if the provided buffer is too short. Passing @code{NULL} for @var{buffer} returns the required length for @var{buffer}. For convenience reasons an extra byte with value 0 is appended to the buffer. @noindent The following formats are supported: @table @code @item GCRYSEXP_FMT_DEFAULT Returns a convenient external S-expression representation. @item GCRYSEXP_FMT_CANON Return the S-expression in canonical format. @item GCRYSEXP_FMT_BASE64 Not currently supported. @item GCRYSEXP_FMT_ADVANCED Returns the S-expression in advanced format. @end table @end deftypefun @deftypefun void gcry_sexp_dump (@w{gcry_sexp_t @var{sexp}}) Dumps @var{sexp} in a format suitable for debugging to @acronym{Libgcrypt}'s logging stream. @end deftypefun @noindent Often canonical encoding is used in the external representation. The following function can be used to check for valid encoding and to learn the length of the S-expression" @deftypefun size_t gcry_sexp_canon_len (@w{const unsigned char *@var{buffer}}, @w{size_t @var{length}}, @w{size_t *@var{erroff}}, @w{int *@var{errcode}}) Scan the canonical encoded @var{buffer} with implicit length values and return the actual length this S-expression uses. For a valid S-expression it should never return 0. If @var{length} is not 0, the maximum length to scan is given; this can be used for syntax checks of data passed from outside. @var{errcode} and @var{erroff} may both be passed as @code{NULL}. @end deftypefun @noindent There are a couple of functions to parse S-expressions and retrieve elements: @deftypefun gcry_sexp_t gcry_sexp_find_token (@w{const gcry_sexp_t @var{list}}, @w{const char *@var{token}}, @w{size_t @var{toklen}}) Scan the S-expression for a sublist with a type (the car of the list) matching the string @var{token}. If @var{toklen} is not 0, the token is assumed to be raw memory of this length. The function returns a newly allocated S-expression consisting of the found sublist or @code{NULL} when not found. @end deftypefun @deftypefun int gcry_sexp_length (@w{const gcry_sexp_t @var{list}}) Return the length of the @var{list}. For a valid S-expression this should be at least 1. @end deftypefun @deftypefun gcry_sexp_t gcry_sexp_nth (@w{const gcry_sexp_t @var{list}}, @w{int @var{number}}) Create and return a new S-expression from the element with index @var{number} in @var{list}. Note that the first element has the index 0. If there is no such element, @code{NULL} is returned. @end deftypefun @deftypefun gcry_sexp_t gcry_sexp_car (@w{const gcry_sexp_t @var{list}}) Create and return a new S-expression from the first element in @var{list}; this called the "type" and should always exist and be a string. @code{NULL} is returned in case of a problem. @end deftypefun @deftypefun gcry_sexp_t gcry_sexp_cdr (@w{const gcry_sexp_t @var{list}}) Create and return a new list form all elements except for the first one. Note, that this function may return an invalid S-expression because it is not guaranteed, that the type exists and is a string. However, for parsing a complex S-expression it might be useful for intermediate lists. Returns @code{NULL} on error. @end deftypefun @deftypefun {const char *} gcry_sexp_nth_data (@w{const gcry_sexp_t @var{list}}, @w{int @var{number}}, @w{size_t *@var{datalen}}) This function is used to get data from a @var{list}. A pointer to the actual data with index @var{number} is returned and the length of this data will be stored to @var{datalen}. If there is no data at the given index or the index represents another list, @code{NULL} is returned. @strong{Caution:} The returned pointer is valid as long as @var{list} is not modified or released. @noindent Here is an example on how to extract and print the surname (Meier) from the S-expression @samp{(Name Otto Meier (address Burgplatz 3))}: @example size_t len; const char *name; name = gcry_sexp_nth_data (list, 2, &len); printf ("my name is %.*s\n", (int)len, name); @end example @end deftypefun @deftypefun gcry_mpi_t gcry_sexp_nth_mpi (@w{gcry_sexp_t @var{list}}, @w{int @var{number}}, @w{int @var{mpifmt}}) This function is used to get and convert data from a @var{list}. This data is assumed to be an MPI stored in the format described by @var{mpifmt} and returned as a standard @acronym{Libgcrypt} MPI. The caller must release this returned value using @code{gcry_mpi_release}. If there is no data at the given index, the index represents a list or the value can't be converted to an MPI, @code{NULL} is returned. @end deftypefun @c ********************************************************** @c ******************* MPIs ******** *********************** @c ********************************************************** @node MPI library @chapter MPI library @menu * Data types:: MPI related data types. * Basic functions:: First steps with MPI numbers. * MPI formats:: External representation of MPIs. * Calculations:: Performing MPI calculations. * Comparisons:: How to compare MPI values. * Bit manipulations:: How to access single bits of MPI values. * Miscellaneous:: Miscellaneous MPI functions. @end menu Public key cryptography is based on mathematics with large numbers. To implement the public key functions, a library for handling these large numbers is required. Because of the general usefulness of such a library, its interface is exposed by @acronym{Libgcrypt}. The implementation is based on an old release of GNU Multi-Precision Library (GMP) but in the meantime heavily modified and stripped down to what is required for cryptography. For a lot of CPUs, high performance assembler implementations of some very low level functions are used to gain much better performance than with the standard C implementation. @noindent In the context of @acronym{Libgcrypt} and in most other applications, these large numbers are called MPIs (multi-precision-integers). @node Data types @section Data types @deftp {Data type} gcry_mpi_t The @code{gcry_mpi_t} type represents an object to hold an MPI. @end deftp @node Basic functions @section Basic functions @noindent To work with MPIs, storage must be allocated and released for the numbers. This can be done with one of these functions: @deftypefun gcry_mpi_t gcry_mpi_new (@w{unsigned int @var{nbits}}) Allocate a new MPI object, initialize it to 0 and initially allocate enough memory for a number of at least @var{nbits}. This pre-allocation is only a small performance issue and not actually necessary because @acronym{Libgcrypt} automatically re-allocates the required memory. @end deftypefun @deftypefun gcry_mpi_t gcry_mpi_snew (@w{unsigned int @var{nbits}}) This is identical to @code{gcry_mpi_new} but allocates the MPI in the so called "secure memory" which in turn will take care that all derived values will also be stored in this "secure memory". Use this for highly confidential data like private key parameters. @end deftypefun @deftypefun gcry_mpi_t gcry_mpi_copy (@w{const gcry_mpi_t @var{a}}) Create a new MPI as the exact copy of @var{a}. @end deftypefun @deftypefun void gcry_mpi_release (@w{gcry_mpi_t @var{a}}) Release the MPI @var{a} and free all associated resources. Passing @code{NULL} is allowed and ignored. When a MPI stored in the "secure memory" is released, that memory gets wiped out immediately. @end deftypefun @noindent The simplest operations are used to assign a new value to an MPI: @deftypefun gcry_mpi_t gcry_mpi_set (@w{gcry_mpi_t @var{w}}, @w{const gcry_mpi_t @var{u}}) Assign the value of @var{u} to @var{w} and return @var{w}. If @code{NULL} is passed for @var{w}, a new MPI is allocated, set to the value of @var{u} and returned. @end deftypefun @deftypefun gcry_mpi_t gcry_mpi_set_ui (@w{gcry_mpi_t @var{w}}, @w{unsigned long @var{u}}) Assign the value of @var{u} to @var{w} and return @var{w}. If @code{NULL} is passed for @var{w}, a new MPI is allocated, set to the value of @var{u} and returned. This function takes an @code{unsigned int} as type for @var{u} and thus it is only possible to set @var{w} to small values (usually up to the word size of the CPU). @end deftypefun @deftypefun void gcry_mpi_swap (@w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{b}}) Swap the values of @var{a} and @var{b}. @end deftypefun @node MPI formats @section MPI formats @noindent The following functions are used to convert between an external representation of an MPI and the internal one of @acronym{Libgcrypt}. @deftypefun gcry_error_t gcry_mpi_scan (@w{gcry_mpi_t *@var{r_mpi}}, @w{enum gcry_mpi_format @var{format}}, @w{const unsigned char *@var{buffer}}, @w{size_t @var{buflen}}, @w{size_t *@var{nscanned}}) Convert the external representation of an integer stored in @var{buffer} with a length of @var{buflen} into a newly created MPI returned which will be stored at the address of @var{r_mpi}. For certain formats the length argument is not required and may be passed as @code{0}. After a successful operation the variable @var{nscanned} receives the number of bytes actually scanned unless @var{nscanned} was given as @code{NULL}. @var{format} describes the format of the MPI as stored in @var{buffer}: @table @code @item GCRYMPI_FMT_STD 2-complement stored without a length header. @item GCRYMPI_FMT_PGP As used by OpenPGP (only defined as unsigned). This is basically @code{GCRYMPI_FMT_STD} with a 2 byte big endian length header. @item GCRYMPI_FMT_SSH As used in the Secure Shell protocol. This is @code{GCRYMPI_FMT_STD} with a 4 byte big endian header. @item GCRYMPI_FMT_HEX Stored as a C style string with each byte of the MPI encoded as 2 hex digits. When using this format, @var{buflen} must be zero. @item GCRYMPI_FMT_USG Simple unsigned integer. @end table @noindent Note, that all of the above formats store the integer in big-endian format (MSB first). @end deftypefun @deftypefun gcry_error_t gcry_mpi_print (@w{enum gcry_mpi_format @var{format}}, @w{unsigned char *@var{buffer}}, @w{size_t @var{buflen}}, @w{size_t *@var{nwritten}}, @w{const gcry_mpi_t @var{a}}) Convert the MPI @var{a} into an external representation described by @var{format} (see above) and store it in the provided @var{buffer} which has a usable length of at least the @var{buflen} bytes. If @var{nwritten} is not NULL, it will receive the number of bytes actually stored in @var{buffer} after a successful operation. @end deftypefun @deftypefun gcry_error_t gcry_mpi_aprint (@w{enum gcry_mpi_format @var{format}}, @w{unsigned char **@var{buffer}}, @w{size_t *@var{nbytes}}, @w{const gcry_mpi_t @var{a}}) Convert the MPI @var{a} into an external representation described by @var{format} (see above) and store it in a newly allocated buffer which address will be stored in the variable @var{buffer} points to. The number of bytes stored in this buffer will be stored in the variable @var{nbytes} points to, unless @var{nbytes} is @code{NULL}. @end deftypefun @deftypefun void gcry_mpi_dump (@w{const gcry_mpi_t @var{a}}) Dump the value of @var{a} in a format suitable for debugging to Libgcrypt's logging stream. Note that one leading space but no trailing space or linefeed will be printed. It is okay to pass @code{NULL} for @var{a}. @end deftypefun @node Calculations @section Calculations @noindent Basic arithmetic operations: @deftypefun void gcry_mpi_add (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) @math{@var{w} = @var{u} + @var{v}}. @end deftypefun @deftypefun void gcry_mpi_add_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) @math{@var{w} = @var{u} + @var{v}}. Note, that @var{v} is an unsigned integer. @end deftypefun @deftypefun void gcry_mpi_addm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) @math{@var{w} = @var{u} + @var{v} \bmod @var{m}}. @end deftypefun @deftypefun void gcry_mpi_sub (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) @math{@var{w} = @var{u} - @var{v}}. @end deftypefun @deftypefun void gcry_mpi_sub_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) @math{@var{w} = @var{u} - @var{v}}. @var{v} is an unsigned integer. @end deftypefun @deftypefun void gcry_mpi_subm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) @math{@var{w} = @var{u} - @var{v} \bmod @var{m}}. @end deftypefun @deftypefun void gcry_mpi_mul (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) @math{@var{w} = @var{u} * @var{v}}. @end deftypefun @deftypefun void gcry_mpi_mul_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) @math{@var{w} = @var{u} * @var{v}}. @var{v} is an unsigned integer. @end deftypefun @deftypefun void gcry_mpi_mulm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) @math{@var{w} = @var{u} * @var{v} \bmod @var{m}}. @end deftypefun @deftypefun void gcry_mpi_mul_2exp (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{e}}) @c FIXME: I am in need for a real TeX{info} guru: @c I don't know why TeX can grok @var{e} here. @math{@var{w} = @var{u} * 2^e}. @end deftypefun @deftypefun void gcry_mpi_div (@w{gcry_mpi_t @var{q}}, @w{gcry_mpi_t @var{r}}, @w{gcry_mpi_t @var{dividend}}, @w{gcry_mpi_t @var{divisor}}, @w{int @var{round}}) @math{@var{q} = @var{dividend} / @var{divisor}}, @math{@var{r} = @var{dividend} \bmod @var{divisor}}. @var{q} and @var{r} may be passed as @code{NULL}. @var{round} should be negative or 0. @end deftypefun @deftypefun void gcry_mpi_mod (@w{gcry_mpi_t @var{r}}, @w{gcry_mpi_t @var{dividend}}, @w{gcry_mpi_t @var{divisor}}) @math{@var{r} = @var{dividend} \bmod @var{divisor}}. @end deftypefun @deftypefun void gcry_mpi_powm (@w{gcry_mpi_t @var{w}}, @w{const gcry_mpi_t @var{b}}, @w{const gcry_mpi_t @var{e}}, @w{const gcry_mpi_t @var{m}}) @c I don't know why TeX can grok @var{e} here. @math{@var{w} = @var{b}^e \bmod @var{m}}. @end deftypefun @deftypefun int gcry_mpi_gcd (@w{gcry_mpi_t @var{g}}, @w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{b}}) Set @var{g} to the greatest common divisor of @var{a} and @var{b}. Return true if the @var{g} is 1. @end deftypefun @deftypefun int gcry_mpi_invm (@w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{m}}) Set @var{x} to the multiplicative inverse of @math{@var{a} \bmod @var{m}}. Return true if the inverse exists. @end deftypefun @node Comparisons @section Comparisons @noindent The next 2 functions are used to compare MPIs: @deftypefun int gcry_mpi_cmp (@w{const gcry_mpi_t @var{u}}, @w{const gcry_mpi_t @var{v}}) Compare the big integer number @var{u} and @var{v} returning 0 for equality, a positive value for @var{u} > @var{v} and a negative for @var{u} < @var{v}. @end deftypefun @deftypefun int gcry_mpi_cmp_ui (@w{const gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) Compare the big integer number @var{u} with the unsigned integer @var{v} returning 0 for equality, a positive value for @var{u} > @var{v} and a negative for @var{u} < @var{v}. @end deftypefun @node Bit manipulations @section Bit manipulations @noindent There are a couple of functions to get information on arbitrary bits in an MPI and to set or clear them: @deftypefun {unsigned int} gcry_mpi_get_nbits (@w{gcry_mpi_t @var{a}}) Return the number of bits required to represent @var{a}. @end deftypefun @deftypefun int gcry_mpi_test_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) Return true if bit number @var{n} (counting from 0) is set in @var{a}. @end deftypefun @deftypefun void gcry_mpi_set_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) Set bit number @var{n} in @var{a}. @end deftypefun @deftypefun void gcry_mpi_clear_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) Clear bit number @var{n} in @var{a}. @end deftypefun @deftypefun void gcry_mpi_set_highbit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) Set bit number @var{n} in @var{a} and clear all bits greater than @var{n}. @end deftypefun @deftypefun void gcry_mpi_clear_highbit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) Clear bit number @var{n} in @var{a} and all bits greater than @var{n}. @end deftypefun @deftypefun void gcry_mpi_rshift (@w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) Shift the value of @var{a} by @var{n} bits to the right and store the result in @var{x}. @end deftypefun @node Miscellaneous @section Miscellaneous @deftypefun gcry_mpi_t gcry_mpi_set_opaque (@w{gcry_mpi_t @var{a}}, @w{void *@var{p}}, @w{unsigned int @var{nbits}}) Store @var{nbits} of the value @var{p} points to in @var{a} and mark @var{a} as an opaque value (i.e. an value that can't be used for any math calculation and is only used to store an arbitrary bit pattern in @var{a}). WARNING: Never use an opaque MPI for actual math operations. The only valid functions are gcry_mpi_get_opaque and gcry_mpi_release. Use gcry_mpi_scan to convert a string of arbitrary bytes into an MPI. @end deftypefun @deftypefun {void *} gcry_mpi_get_opaque (@w{gcry_mpi_t @var{a}}, @w{unsigned int *@var{nbits}}) Return a pointer to an opaque value stored in @var{a} and return its size in @var{nbits}. Note, that the returned pointer is still owned by @var{a} and that the function should never be used for an non-opaque MPI. @end deftypefun @deftypefun void gcry_mpi_set_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) Set the @var{flag} for the MPI @var{a}. Currently only the flag @code{GCRYMPI_FLAG_SECURE} is allowed to convert @var{a} into an MPI stored in "secure memory". @end deftypefun @deftypefun void gcry_mpi_clear_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) Clear @var{flag} for the big integer @var{a}. Note, that this function is currently useless as no flags are allowed. @end deftypefun @deftypefun int gcry_mpi_get_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) Return true when the @var{flag} is set for @var{a}. @end deftypefun @deftypefun void gcry_mpi_randomize (@w{gcry_mpi_t @var{w}}, @w{unsigned int @var{nbits}}, @w{enum gcry_random_level @var{level}}) Set the big integer @var{w} to a random value of @var{nbits}, using random data quality of level @var{level}. In case @var{nbits} is not a multiple of a byte, @var{nbits} is rounded up to the next byte boundary. @end deftypefun @c ********************************************************** @c ******************** Prime numbers *********************** @c ********************************************************** @node Prime numbers @chapter Prime numbers @menu * Generation:: Generation of new prime numbers. * Checking:: Checking if a given number is prime. @end menu @node Generation @section Generation @deftypefun gcry_error_t gcry_prime_generate (gcry_mpi_t *@var{prime},unsigned int @var{prime_bits}, unsigned int @var{factor_bits}, gcry_mpi_t **@var{factors}, gcry_prime_check_func_t @var{cb_func}, void *@var{cb_arg}, gcry_random_level_t @var{random_level}, unsigned int @var{flags}) Generate a new prime number of @var{prime_bits} bits and store it in @var{prime}. If @var{factor_bits} is non-zero, one of the prime factors of (@var{prime} - 1) / 2 must be @var{factor_bits} bits long. If @var{factors} is non-zero, allocate a new, @code{NULL}-terminated array holding the prime factors and store it in @var{factors}. @var{flags} might be used to influence the prime number generation process. @end deftypefun @deftypefun gcry_prime_group_generator (gcry_mpi_t *@var{r_g}, gcry_mpi_t @var{prime}, gcry_mpi_t *@var{factors}, gcry_mpi_t @var{start_g}) Find a generator for @var{prime} where the factorization of (@var{prime}-1) is in the @code{NULL} terminated array @var{factors}. Return the generator as a newly allocated MPI in @var{r_g}. If @var{start_g} is not NULL, use this as the start for the search. @end deftypefun @deftypefun void gcry_prime_release_factors (gcry_mpi_t *@var{factors}) Convenience function to release the @var{factors} array. @end deftypefun @node Checking @section Checking @deftypefun gcry_error_t gcry_prime_check (gcry_mpi_t @var{p}, unsigned int @var{flags}) Check wether the number @var{p} is prime. Returns zero in case @var{p} is indeed a prime, returns @code{GPG_ERR_NO_PRIME} in case @var{p} is not a prime and a different error code in case something went horribly wrong. @end deftypefun @c ********************************************************** @c ******************** Utilities *************************** @c ********************************************************** @node Utilities @chapter Utilities @menu * Memory allocation:: Functions related with memory allocation. @end menu @node Memory allocation @section Memory allocation @deftypefun void *gcry_malloc (size_t @var{n}) This function tries to allocate @var{n} bytes of memory. On success it returns a pointer to the memory area, in an out-of-core condition, it returns NULL. @end deftypefun @deftypefun void *gcry_malloc_secure (size_t @var{n}) Like @code{gcry_malloc}, but uses secure memory. @end deftypefun @deftypefun void *gcry_calloc (size_t @var{n}) This function tries to allocate @var{n} bytes of cleared memory (i.e. memory that is initialized with zero bytes). On success it returns a pointer to the memory area, in an out-of-core condition, it returns NULL. @end deftypefun @deftypefun void *gcry_calloc_secure (size_t @var{n}) Like @code{gcry_calloc}, but uses secure memory. @end deftypefun @deftypefun void *gcry_realloc (void *@var{p}, size_t @var{n}) This function tries to resize the memory area pointed to by @var{p} to @var{n} bytes. On success it returns a pointer to the new memory area, in an out-of-core condition, it returns NULL. Depending on whether the memory pointed to by @var{p} is secure memory or not, gcry_realloc tries to use secure memory as well. @end deftypefun @deftypefun void gcry_free (void *@var{p}) Release the memory area pointed to by @var{p}. @end deftypefun @c ********************************************************** @c ******************* Appendices ************************* @c ********************************************************** @include lgpl.texi @include gpl.texi @node Concept Index @unnumbered Concept Index @printindex cp @node Function and Data Index @unnumbered Function and Data Index @printindex fn @bye /* Version check should be the very first gcry call because it makes sure that constructor functions are run. */ if (!gcry_check_version (GCRYPT_VERSION)) die ("version mismatch\n"); /* Many applications don't require secure memory, so they should disable it right away. There won't be a problem unless one makes use of a feature which requires secure memory - in that case the process would abort because the secmem is not initialized. */ gcry_control (GCRYCTL_DISABLE_SECMEM, 0); /* .. add whatever initialization you want, but better don't make calls to libgcrypt from more than one thread ... */ /* Tell Libgcrypt that initialization has completed. */ gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); If you require secure memory, this code should be used: if (!gcry_check_version (GCRYPT_VERSION)) die ("version mismatch\n"); /* We don't want to see any warnings, e.g. because we have not yet parsed options which might be used to suppress such warnings */ gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); /* ... */ /* Allocate a pool of 16k secure memory. This also drops privileges on some systems. */ gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0); /* It is now okay to let Libgcrypt complain when there was/is a problem with the secure memory. */ gcry_control (GCRYCTL_RESUME_SECMEM_WARN); /* Tell Libgcrypt that initialization has completed. */ gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); This sounds a bit complicated but has the advantage that the caller must decide whether he wants secure memory or not - there is no default. It is important that this initialization is not done by a library but in the application. The library might want to check for finished initialization using: if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) return MYLIB_ERROR_LIBGCRYPT_NOT_INITIALIZED; @c LocalWords: int HD diff --git a/m4/ChangeLog b/m4/ChangeLog index 6a76f5a6..49c1b321 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,26 +1,30 @@ +2007-02-22 Werner Koch + + * noexecstack.m4: Change default to enable it. + 2007-02-20 Werner Koch * Makefile.am: New. * noexecstack.m4: New. Taken from gnupg 1.4 2006-10-11 Marcus Brinkmann * fallback.m4: Removed again. 2006-10-10 Marcus Brinkmann * fallback.m4: New file from Pth. 2006-07-04 Marcus Brinkmann * sys_socket_h.m4, socklen.m4, onceonly.m4: New files from gnulib. 2004-04-06 Werner Koch * libtool.m4: Updated from 1.5.4 2003-12-08 Werner Koch * libtool.m4: New. diff --git a/m4/noexecstack.m4 b/m4/noexecstack.m4 index 629e3513..f1924a79 100644 --- a/m4/noexecstack.m4 +++ b/m4/noexecstack.m4 @@ -1,55 +1,55 @@ # noexecstack.m4 dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. dnl dnl This library is free software; you can redistribute it and/or dnl modify it under the terms of the GNU Lesser General Public dnl License as published by the Free Software Foundation; either dnl version 2.1 of the License, or (at your option) any later version. dnl dnl This library is distributed in the hope that it will be useful, dnl but WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dnl Lesser General Public License for more details. dnl dnl You should have received a copy of the GNU Lesser General Public dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl Checks whether the stack can be marked nonexecutable by passing an dnl option to the C-compiler when acting on .s files. Returns that dnl option in NOEXECSTACK_FLAGS. dnl This macro is adapted from one found in GLIBC-2.3.5. AC_DEFUN([CL_AS_NOEXECSTACK],[ AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([AM_PROG_AS]) AC_MSG_CHECKING([whether non excutable stack support is requested]) AC_ARG_ENABLE(noexecstack, - AC_HELP_STRING([--enable-noexecstack], - [enable non executable stack support (gcc only)]), - noexecstack_support=$enableval, noexecstack_support=no) + AC_HELP_STRING([--disable-noexecstack], + [disable non executable stack support]), + noexecstack_support=$enableval, noexecstack_support=yes) AC_MSG_RESULT($noexecstack_support) AC_CACHE_CHECK([whether assembler supports --noexecstack option], cl_cv_as_noexecstack, [dnl cat > conftest.c </dev/null]) \ && grep -q .note.GNU-stack conftest.s \ && AC_TRY_COMMAND([${CCAS} $CCASFLAGS $CPPFLAGS -Wa,--noexecstack -c -o conftest.o conftest.s >/dev/null]) then cl_cv_as_noexecstack=yes else cl_cv_as_noexecstack=no fi rm -f conftest*]) if test "$noexecstack_support" = yes -a "$cl_cv_as_noexecstack" = yes; then NOEXECSTACK_FLAGS="-Wa,--noexecstack" else NOEXECSTACK_FLAGS= fi AC_SUBST(NOEXECSTACK_FLAGS) ]) diff --git a/src/ChangeLog b/src/ChangeLog index 783dc6f4..44eef502 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,1685 +1,1709 @@ +2007-02-22 Werner Koch + + * gcrypt.h.in (gcry_ac_id_to_name, gcry_ac_name_to_id): Mark as + deprecated. + + * libgcrypt.def (gcry_fast_random_poll): Removed - it is a macro. + (gcry_cipher_register, gcry_cipher_unregister): New. + (gcry_md_register, gcry_md_unregister): New. + (gcry_pk_register, gcry_pk_unregister): New. + (gcry_ac_data_from_sexp, gcry_ac_data_to_sexp): New. + (gcry_ac_io_init, gcry_ac_io_init_va): New. + (gcry_ac_data_encrypt_scheme, gcry_ac_data_decrypt_scheme): New. + (gcry_ac_data_sign_scheme, gcry_ac_data_verify_scheme): New. + + * missing-string.c: Include stdio.h for the vsprintf prototype. + + * ath.h (struct ath_ops) [_WIN32]: Use int instead of socklen_t. + 2007-02-21 Werner Koch + * libgcrypt.def (gcry_create_nonce, gcry_fast_random_poll) + (gcry_md_debug): New. + + * libgcrypt-config.in: Remove duplicates from --cflags and --libs. + Print a error for option --thread. + * gcrypt.h.in (gcry_sexp_sprint): Change BUFFER from char* to void*. (gcry_md_ctl): Change BUFFER from unsigned char* to void*. (gcry_md_debug): New. (gcry_cipher_encrypt, gcry_cipher_decrypt): Change buffer args to void*. (gcry_randomize): Change BUFFER to void. (gcry_create_nonce): Ditto. * libgcrypt.vers (gcry_md_debug): New. * sexp.c (gcry_sexp_sprint): Ditto. (normalize): Make P unsigned. (gcry_sexp_nth_data): Cast return value to char*. (sexp_sscan): Fix sign/unsigned conflicts. (whitespacep): Change P to char*. (unquote_string): Change STRING to char*. (convert_to_hex): Change DEST to char*. (convert_to_string): Change DEST and P to char*. (convert_to_token): Chnage DEST to char*. (gcry_sexp_canon_len): Change DISPHINT to unsigned char*. * gcrypt-module.h (gcry_pk_spec): Made ALIASES a const. (gcry_md_write_t): Changed BUF to a const void*. 2007-02-12 Werner Koch * gcrypt.h.in: Include stdlib.h for the sake fo the trheading macros. Suggested by Andreas Metzler. * secmem.c (ptr_into_pool_p): New. (_gcry_private_is_secure): Implement in terms of new function. (BLOCK_VALID): Removed. Replaced all users by new function. 2007-01-31 Werner Koch * secmem.c (_gcry_private_is_secure): Fixed severe implementation flaw. Might be the reason for some of the more obscure bugs. (MB_WIPE_OUT): Use wipememory2. 2006-10-23 Werner Koch * gcrypt.h.in (GCRY_THREAD_OPTION_PTHREAD_IMPL): Add some cast for use by C-doubleplus. In general I don't like this but due to public demand I give up ;-) 2006-10-19 Werner Koch * global.c (gcry_control) : Return an error if the memory could not be locked. * secmem.c (not_locked): New. (_gcry_secmem_get_flags): Return that flag. * secmem.h (GCRY_SECMEM_FLAG_NOT_LOCKED): New. 2006-10-05 Werner Koch * module.c (_gcry_module_id_new): Don't assign modules in the range the range of 1024..4096. * gcrypt.h (GCRY_MD_USER, GCRY_MD_USER_LAST): New (GCRY_PK_USER, GCRY_PK_USER_LAST): New. (GCRY_CIPHER_USER, GCRY_CIPHER_USER_LAST): New. 2006-10-12 Marcus Brinkmann * gcrypt.h.in: Replace socklen_t with gcry_socklen_t. 2006-10-11 Marcus Brinkmann * gcrypt.h.in: Replace version by @VERSION@. 2006-10-10 Marcus Brinkmann * gcrypt.h: Add fallback type for socklen_t. Move to ... * gcrypt.h.in: ... this file. * Makefile.am (EXTRA_DIST): Add gcrypt.h.in. 2006-09-04 Werner Koch * gcrypt.h: Removed some trailing comma in enums. 2006-08-29 Werner Koch * global.c (gcry_xrealloc): Pass secure flag to outofcore handler. * gcrypt.h (GCRY_CIPHER_SEED): New. 2006-08-21 Werner Koch * gcrypt.h (GCRYCTL_FAKED_RANDOM_P): New. 2006-07-29 Marcus Brinkmann * secmem.c (init_pool): Close FD after establishing the mapping. 2006-07-12 Marcus Brinkmann * ath.c (ath_mutex_destroy): Microoptimize destruction of unused statitically initialized mutexes. Suggested by Victor Stinner . * gcrypt.h (GCRY_THREAD_OPTION_PTHREAD_IMPL, (GCRY_THREAD_OPTION_PTH_IMPL): Add missing initializers to suppress gcc warning. Submitted by Victor Stinner . 2006-07-04 Marcus Brinkmann * ath.c: Avoid warning about double defined type byte and other hacks to let it build for W32 (backported from LIBGCRYPT-1-2-BRANCH). * ath.h, gcrypt.h, tests/benchmark.c, src/types.h: Likewise. * gcrypt.h: Revert last change, and instead: [_WIN32 || __WIN32__]: Do not include , but and . Suggested by Simon Josefsson . * Makefile.am (install-data-local, uninstall-local, %.lo, (install-def-file, uninstall-def-file): New targets. (LTRCCOMPILE, gcrypt_res, gcrypt_res_ldflag, no_undefined, (export_symbols, gcrypt_deps): New variables. * versioninfo.rc.in: New file. * libgcrypt.def: New file from ../w32-dll/libgcrypt.def. * gcrypt.h [!HAVE_SYS_SOCKET_H]: Do not include sys/socket.h, but the appropriate windows socket header. 2006-06-21 Werner Koch * global.c (gcry_xcalloc, gcry_xcalloc_secure): Made safe against integer overflow. * sexp.c (make_space): Return an error on out of core. (sexp_sscan): Remove all xmalloc style calls and return proper error codes on allocation failures. (gcry_sexp_find_token): Ditto. (gcry_sexp_nth): * sexp.c (gcry_sexp_find_token): Re-indented and removed a cruft "while(level);" which fortunately had no effect. 2006-04-28 Werner Koch * gcrypt.h (GCRY_MD_SHA224): Change value from 306 to 11 to match the use in OpenPGP. There has been no release yet, so we can safely do it. 2006-04-22 Moritz Schulte * gcrypt.h (gcry_ctl_cmds): New commands: GCRYCTL_SET_RANDOM_DAEMON_SOCKET, GCRYCTL_USE_RANDOM_DAEMON. * global.c (gcry_control): Handle new commands, calling _gcry_set_random_daemon_socket() and _gcry_use_random_daemon(). 2006-04-18 Werner Koch * gcrypt.h (GCRY_PK_USAGE_CERT, GCRY_PK_USAGE_AUTH) (GCRY_PK_USAGE_UNKN): New. 2006-04-01 Moritz Schulte * gcrypt.h (gcry_ac_eme_pkcs_v1_5): Removed members: key, handle; added member: key_size. * secmem.c (MB_FLAG_ACTIVE): Write braces around MB_FLAG_ACTIVE definition. 2006-03-15 Werner Koch * getrandom.c: New. 2006-03-14 Werner Koch * gcryptrnd.c: New. 2006-03-10 Werner Koch * gcrypt.h: Add GCRY_MD_SHA224. 2005-11-02 Moritz Schulte * gcrypt.h: Update comments for functions: gcry_cipher_algo_name, gcry_pk_algo_name. 2005-10-31 Moritz Schulte * global.c: Added documentation. 2005-10-16 Moritz Schulte * global.c (global_init): Use gcry_error_t instead of gcry_err_code_t; use goto instead of if constructs. * stdmem.c: Inserted description of the layered memory management in Libgcrypt. * g10lib.h: Removed G10_I18N_H related check; it seems to be a GnuPG relict (Libgcrypt does not define this symbol anywhere). (FLAG_MODULE_DISABLED): Don't forget parantheses around shifted value. Removed GCC_ATTR_PURE macro definitions, since gcrypt.h does already contain such a macro named _GCRY_GCC_ATTR_PURE, which we can use here as well. Likewise for GCC_ATTR_MALLOC and _GCRY_GCC_ATTR_MALLOC. * stdmem.h: Use _GCRY_GCC_ATTR_MALLOC instead of GCC_ATTR_MALLOC. * secmem.h: Likewise. 2005-10-09 Moritz Schulte * global.c (gcry_control): Call global_init() after passing thread cbs to ath. global_init() MUST to be called AFTER passing the cbs to ath and BEFORE calling library functions, which make use of ath. This change combines cbs installing with ath initialization and thus removes the need to call other library initialization functions inbetween like e.g. gcry_check_version(). 2005-10-01 Moritz Schulte * ath.c: Assign copyright to FSF. * ath.h: Likewise. 2005-06-25 Moritz Schulte * Makefile.am (pkgconfigdir, pkgconfig_DATA): Removed variables. * libgcrypt.pc.in: Removed file - we do not want to support a second, foreign configuration system. 2005-06-17 Moritz Schulte * global.c (gcry_xstrdup): Removed superfluous strcpy call. 2005-04-22 Moritz Schulte * Makefile.am (pkgconfigdir, pkgconfig_DATA): New; support for pkgconfig provided by Albert Chin. * libgcrypt.pc.in (Cflags): New file. 2005-04-16 Moritz Schulte * g10lib.h (_gcry_ac_init): Declare. * global.c (global_init): Call _gcry_ac_init; don't forget to set err. 2005-04-14 Werner Koch * sexp.c (whitespacep): New. (sexp_sscan): Replaced isdigit and isspace by whitespacep and digitp. 2005-04-11 Moritz Schulte * gcrypt.h (gcry_md_algos): Added: GCRY_MD_WHIRLPOOL. * cipher.h (_gcry_digest_spec_whirlpool): Declare. 2005-03-30 Moritz Schulte * libgcrypt.vers: Added: gcry_ac_io_init, gry_ac_io_init_va. * gcrypt.h (gcry_ac_data_read_cb_t, gcry_ac_data_write_cb_t, gcry_ac_io_mode_t, gcry_ac_io_type_t, gcry_ac_io_t): New types. (gcry_ac_io_init_va): Declare function. (gcry_ac_data_encode, gcry_ac_data_decode, gcry_ac_data_encrypt_scheme, gcry_ac_data_decrypt_scheme, gcry_ac_data_sign_scheme, gcry_ac_data_verify_scheme): Use gcry_ac_io_type_t objects instead of memory strings directly. 2005-03-03 Moritz Schulte * libgcrypt.vers: Added: gcry_ac_data_to_sexp() and gcry_ac_data_from_sexp(). 2005-02-22 Werner Koch * global.c (_gcry_malloc): Make sure ERRNO is set if we return NULL. Remove unneeded initialization of M to allow the compiler to catch errors. (gcry_realloc): Make sure ERRNO is set if we return NULL> 2005-02-13 Moritz Schulte * gcrypt.h: Declare new functions: gcry_ac_data_encrypt_scheme, gcry_ac_data_decrypt_scheme, gcry_ac_data_sign_scheme, gcry_ac_data_verify_scheme, gcry_ac_data_encode, gcry_ac_data_decode, gcry_ac_data_to_sexp, gcry_ac_data_from_sexp. New types: gcry_ac_emsa_pkcs_v1_5_t, gcry_ac_ssa_pkcs_v1_5_t, gcry_md_algo_t. New enumeration lists: gcry_ac_scheme_t, gcry_ac_em_t. * libgcrypt.vers: Added new ac functions. * g10lib.h: Declare function: _gcry_pk_get_elements. * mpi.h (mpi_get_ui): New macro. Declare function: _gcry_mpi_get_ui. 2004-11-09 Werner Koch * gcrypt.h: Removed 3 trailing commas from enums. Noted by Heiko Stamer. 2004-09-21 Werner Koch * sexp.c (sexp_sscan): Removed C++ style comments. Noted by Yoann Vandoorselaere. 2004-08-23 Moritz Schulte * global.c: Do not include . * sexp.c: Likewise. * module.c: Likewise. * misc.c: Likewise. 2004-08-18 Moritz Schulte * secmem.c (_gcry_secmem_init): Try to lock pool into core not only when running with root privileges. 2004-08-16 Werner Koch * secmem.h (_gcry_secmem_set_flags,_gcry_secmem_get_flags): Removed __pure__. (GCRY_SECMEM_FLAG_NO_WARNING): Put macro value into parens. * secmem.c (_gcry_secmem_init): Defer printing of the warning. 2004-08-10 Moritz Schulte * gcrypt.h: Include , thanks to Simon Josefsson. 2004-05-07 Werner Koch * gcrypt.h: Added GCRYCTL_FAST_POLL. (gcry_fast_random_poll): New. * global.c (gcry_control) : Do only basic random subsystem init. (gcry_control) : New. 2004-04-22 Marcus Brinkmann * libgcrypt.m4: Quote first argument to AC_DEFUN. 2004-04-15 Werner Koch * secmem.c (_gcry_secmem_malloc_internal): Removed old extra info error output. (_gcry_secmem_term): Use wipememory2 here. * misc.c (_gcry_burn_stack): Use wipememory to avoid optimizations. * string.c: Removed. Was never used. * global.c (gcry_strdup): Replaced by the version from string.c (gcry_xstrdup): Rewritten. * gcrypt.h: Removed duplicate prototype for gcry_strdup. 2004-03-29 Werner Koch * secmem.c (_gcry_secmem_realloc): Fixed double unlock; bug manifested itself due to the more rigorous checking in the changed ath.h * libgcrypt-config.in (Options): Ignore the obsolete --threads option for now. 2004-03-17 Marcus Brinkmann * libgcrypt-config.in (includedir, libdir): Quote'em. Use $gpg_error_cflags and $gpg_error_libs. Fix construction of $includes. 2004-03-14 Marcus Brinkmann * libgcrypt-config.in (includedir, libdir): New variables. For --cflags, don't test $cflags. Also check against /include for the GNU/Hurd. Don't overwrite but extend $cflags_final. Likewise for --libs. 2004-03-10 Marcus Brinkmann * Makefile.am (ltlib_libgcrypt_pthread, ltlib_libgcrypt_pth): Removed. (lib_LTLIBRARIES): Remove those variables from here. (libgcrypt_pthread_la_SOURCES, libgcrypt_pthread_la_LDFLAGS, (libgcrypt_pthread_la_DEPENDENCIES, libgcrypt_pthread_la_LIBADD, (libgcrypt_pth_la_SOURCES, libgcrypt_pth_la_LDFLAGS, (libgcrypt_pth_la_DEPENDENCIES, libgcrypt_pth_la_LIBADD, (noinst_LTLIBRARIES): Removed. (libgcrypt_real_la_SOURCES): Merge with ... (libgcrypt_la_SOURCES): ... likewise. (libgcrypt_real_la_DEPENDENCIES): Merge with ... (libgcrypt_la_DEPENDENCIES): ... this. (libgcrypt_real_la_LIBADD): Merge with ... (libgcrypt_la_LIBADD): ... this. * libgcrypt-config.in (libs_pthread, libs_pth, cflags_pth) (cflags_pthread, thread_module, thread_modules): Removed. (Options): Remove --thread option from help output. If the option is specified, output an error and exit. For --cflags and --libs option, remove pth and pthread from output. * gcrypt.h: Include and . (enum gcry_ctl_cmds): Add GCRYCTL_SET_THREAD_CBS. (gcry_thread_cbs): New struct. * global.c (gcry_control): Implement GCRYCTL_SET_THREAD_CBS. (global_init): Don't call ath_init here. * ath.h: Rewritten. * ath.c: Rewritten. 2004-03-06 Werner Koch * libgcrypt-config.in: s/--soname-number/--api-version/ * libgcrypt.m4: Changed test for API version. 2004-03-05 Werner Koch * libgcrypt.m4: Optionally check the SONAME number. * libgcrypt-config.in: Add option --soname-number 2004-03-01 Marcus Brinkmann * Makefile.am (libgcrypt_la_SOURCES): Add ath.c. * ath.c (ath_init): Add missing function. * Makefile.am (ath_pth_src): Removed. (ath_pthread_src): Removed. (libgcrypt_la_SOURCES): Remove ath-compat, $(ath_pth_src) and $(ath_pthread_src). * ath-compat.c, ath-pth-compat.c, ath-pthread-compat.c: Files removed. 2004-02-20 Werner Koch * gcrypt.h (GCRY_PRIME_CHECK_AT_GOT_PRIME) (GCRY_PRIME_CHECK_AT_FINISH), (GCRY_PRIME_CHECK_AT_MAYBE_PRIME): New. 2004-02-18 Werner Koch * libgcrypt-config.in: Ignore setting of --prefix. 2004-02-13 Werner Koch * gcrypt.h: Added GCRY_CIPHER_RFC2268_128, alsthough not yet supported. 2004-02-06 Werner Koch * gcrypt.h: Added GCRY_CIPHER_RFC2268_40. 2004-02-03 Werner Koch * secmem.c (_gcry_secmem_init): Do not print the "not locked into core warning" if the NO_WARNING flag has been set. * sexp.c (sexp_sscan): Allocate result in secure memory if BUFFER is in secure memory. Switch to secure memory for the a secure %b format item. Extra paranoid wipe on error. (gcry_sexp_release): Added paranoid wiping for securely allocated S-expressions. 2004-01-25 Moritz Schulte * ath.h: Include . 2004-01-12 Moritz Schulte * gcrypt.h: Adjusted declarations of: gcry_ac_data_set, gcry_ac_data_get_name, gcry_ac_data_get_index, gcry_ac_key_pair_generate, gcry_ac_key_test, gcry_ac_key_get_nbits, gcry_ac_key_get_grip. * gcrypt.h (GCRY_AC_FLAG_DATA_NO_BLINDING): Removed symbol. (GCRY_AC_FLAG_DEALLOC, GCRY_AC_FLAG_COPY) (GCRY_AC_FLAG_NO_BLINDING): New symbols. * global.c (gcry_strdup): Removed function. * string.c: New file. * Makefile.am (libgcrypt_real_la_SOURCES): Added: string.c. * string.c (gcry_strdup): New function. * gcrypt.h (gcry_strdup): Declare. 2003-12-19 Werner Koch * g10lib.h (wipememory, wipememory2): New; taken from gnupg. 2003-11-14 Werner Koch * global.c (gcry_strdup): Don't copy the string after a malloc error. 2003-11-11 Werner Koch * sexp.c (sexp_sscan): Implemented "%b" format specifier. 2003-11-11 Moritz Schulte * libgcrypt.m4: Do not set prefix when calling libgcrypt-config. Thanks to Nikos Mavroyanopoulos. 2003-11-08 Moritz Schulte * cipher.h (small_prime_numbers): Removed declaration. (PUBKEY_FLAG_NO_BLINDING): Put braces around shift. 2003-11-04 Werner Koch * cipher.h (_gcry_sha1_has_buffer): New. * gcrypt.h (gcry_create_nonce): New. 2003-10-31 Werner Koch * libgcrypt.vers (_gcry_generate_elg_prime): Removed this symbol; gnutls does not need it anymore. * secmem.c (mb_get_new): s/pool/block/ due to global pool. * misc.c (gcry_set_log_handler): s/logf/f/ to avoid shadowing warning against a builtin. * ath-pth-compat.c: cast pth_connect to get rid of the const prototype. 2003-10-27 Werner Koch * ath.h (ATH_MUTEX_INITIALIZER): Removed spurious semicolon. 2003-10-27 Moritz Schulte * libgcrypt-config.in: Include libs/cflags of libgpg-error. * sexp.c (sexp_sscan): Cleaned up, deallocate scanned sexp on error. * module.c (MODULE_ID_MIN): New symbol, use it. 2003-10-27 Werner Koch * gcrypt.h (gcry_pk_testkey): Doc fix. 2003-09-29 Moritz Schulte * libgcrypt-config.in: Fix --algorithms option. 2003-10-23 Werner Koch * gcrypt.h (gcry_err_code): Use GPG_ERR_INLINE instead of __inline__. * secmem.c (lock_pool): Don't print the warning for certain systems, handle ENOMEM. 2003-10-21 Werner Koch * secmem.c (_gcry_secmem_dump_stats): Fixed format sepcifier for a size_t. Reported by Stephane Corthesy. 2003-10-10 Werner Koch * global.c (_gcry_malloc): Handle the no_secure_memory option. * gcrypt.h (gcry_prime_group_generator): New. (gcry_prime_release_factors): New. 2003-10-07 Werner Koch * sexp.c (sexp_sscan): Check that parenthesis are matching. 2003-09-28 Moritz Schulte * g10lib.h: Declare: _gcry_malloc. (GCRY_ALLOC_FLAG_SECURE): New symbol. * global.c (_gcry_malloc): New function... (gcry_malloc): ... use it. (gcry_malloc_secure): Likewise. * ath.c: Change License to LGPL. * ath-pthread-compat.c: Likewise. * ath-pthread.c: Likewise. * ath-pth-compat.c: Likewise. * ath-pth.c: Likewise. * ath.h: Likewise. * ath-compat.c: Likewise. * secmem.c (_gcry_secmem_realloc): Do not forget to release secmem lock. Thanks to low halo for triggering this bug. 2003-09-04 Werner Koch * gcrypt.h (_GCRY_ERR_SOURCE_DEFAULT): Removed cruft. (gcry_prime_check_func_t): Renamed arg for clarity. 2003-09-02 Moritz Schulte * gcrypt.h (GCRY_PRIME_FLAG_SPECIAL_FACTOR): New symbol. 2003-09-01 Moritz Schulte * gcrypt.h (gcry_random_level_t): New type. (gcry_prime_check_func_t): Likewise. (GCRY_PRIME_FLAG_SECRET): New symbol. (gcry_prime_generate, gcry_prime_check): Declare functions. 2003-08-28 Werner Koch * Makefile.am (libgcrypt_pth_la_LDFLAGS): Removed PTH_CFLAGS cruft. 2003-08-27 Moritz Schulte * global.c (gcry_control): Remove call to ath_deinit. * Makefile.am (libgcrypt_real_la_DEPENDENCIES): Fixed. (libgcrypt_real_la_LIBADD): Fixed. Removed unecessary variables. * libgcrypt-config.in: Adjusted script for new thread handling. * Makefile.am: New version, based on GPGMEs Makefile.am. * ath.c, ath-compat.c, ath.h, ath-pth.c, ath-pth-compat.c, ath-pthread.c, ath-pthread-compat.c: New files, merged from GPGME. * ath.c, ath.h, ath-pthread.c, ath-pth.c: Removed files. 2003-08-08 Moritz Schulte * global.c (gcry_realloc): Remove FIXME about `clearing out realloced memory', since _gcry_secmem_realloc takes care of overwriting old memory. 2003-08-07 Werner Koch * module.c (_gcry_module_release): Don't act if module is NULL. 2003-07-30 Moritz Schulte * gcrypt.h (enum gcry_ac_id): Added: GCRY_AC_ELG_E. Reverted change: use gcry_md_flags enumeration list instead of defines. 2003-07-29 Werner Koch * global.c (gcry_control): Add GCRYCTL_SET_RANDOM_SEED_FILE and GCRYCTL_UPDATE_RANDOM_SEED_FILE. * gcrypt.h: Ditto. Renamed index to idx, so avoid warning related to the old index function. 2003-07-28 Moritz Schulte * global.c (gcry_err_code_from_errno, gcry_err_code_to_errno) (gcry_err_make_from_errno, gcry_error_from_errno): New functions. * gcrypt.h: Declared: gcry_err_code_from_errno, gcry_err_code_to_errno, gcry_err_make_from_errno, gcry_error_from_errno. * Makefile.am (include_HEADERS): Added: gcrypt-module.h. * gcrypt.h: Include . * gcrypt-module.h: New file. 2003-07-27 Werner Koch * gcrypt.h (gcry_mpi_scan, gcry_mpi_print): API change. (gcry_mpi_dump): New. 2003-07-21 Moritz Schulte * gcrypt.h: Declared: gcry_ac_key_data_get. (gcry_pk_spec): Renamed member `sexp_names' into `aliases'. 2003-07-20 Moritz Schulte * gcrypt.h (gcry_md_oid_spec_t): New type. (gcry_md_spec): New member: oids. 2003-07-19 Moritz Schulte * gcrypt.h (gcry_cipher_oid_spec_t): New type. (gcry_cipher_spec): New member: oids; 2003-07-18 Werner Koch * gcrypt.h (gcry_mpi_set_opaque): Add a warning comment. 2003-07-15 Moritz Schulte * secmem.c (compress_pool): Remove function, since unused blocks are automatically concatenad. * gcrypt.h: Bumped version number up to 1.1.42-cvs. 2003-07-14 Moritz Schulte * gcrypt.h (gcry_cipher_spec): New member: aliases. * Makefile.am (noinst_PROGRAMS, testapi_SOURCES, testapai_LDADD, benchmark_SOURCES, benchmark_LDADD): Removed. * benchmark.c, testapi.c: Removed files. * mpi.h: Removed disabled typedef. * g10lib.h: Likewise. * benchmark.c, g10lib.h, gcrypt.h, global.c, module.c, sexp.c: Used gcry_err* wrappers for libgpg-error symbols. 2003-07-12 Moritz Schulte * global.c: Likewise. * gcrypt.h: New type: gcry_error_t, gcry_err_code_t and gcry_err_source_t. (gcry_err_make, gcry_error, gcry_err_code, gcry_err_source): New functions. * global.c (gcry_strerror): New function. (gcry_strsource): New function. * gcrypt.h: New symbol: GCRY_CIPHER_TWOFISH128. 2003-07-09 Moritz Schulte * gcrypt.h (enum gcry_md_flags): Removed, used define instead, since that is more common than an enumeration list when it comes to flags that can be bitwise ORed. 2003-07-08 Moritz Schulte * global.c: Use new types for handlers. * gcrypt.h: Declare: gcry_ac_data_copy. 2003-07-07 Moritz Schulte * sexp.c (gcry_sexp_build_array): Use dummy argument pointer. Thanks to Simon Josefsson . * gcrypt.h: Declare: gcry_cipher_list, gcry_pk_list, gcry_md_list. 2003-07-05 Moritz Schulte * gcrypt.h: Declare: gcry_cipher_register, gcry_cipher_unregister, gcry_md_register, gcry_md_unregister, gcry_pk_register, gcry_pk_unregister. (gcry_cipher_spec): Removed member: algorithm. (gcry_pk_spec): Likewise. (gcry_md_spec): Likewise. Adjusted declarations: gcry_cipher_register, gcry_pk_register, gcry_md_register. * module.c: Replaced all occurences of `id' with `mod_id', since `id' is a keyword in obj-c. * gcrypt.h (gcry_cipher_spec): Renamed member `id' to `algorithm'. (gcry_pk_spec): Likewise. (gcry_md_spec): Likewise. * cipher.h: Removed types: gcry_pubkey_generate_t, gcry_pubkey_check_secret_key_t, gcry_pubkey_encrypt_t, gcry_pubkey_decrypt_t, gcry_pubkey_sign_t, gcry_pubkey_verify_t, gcry_pubkey_get_nbits_t, gcry_pk_spec_t, gcry_digest_init_t, gcry_digest_write_t, gcry_digest_final_t, gcry_digest_read_t, gcry_digest_spec_t, gcry_cipher_setkey_t, gcry_cipher_encrypt_t, gcry_cipher_decrypt_t, gcry_cipher_stencrypt_t, gcry_cipher_stdecrypt_t, gcry_cipher_spec_t. * gcrypt.h: New types: gcry_pk_generate_t, gcry_pk_check_secret_key_t, gcry_pk_encrypt_t, gcry_pk_decrypt_t, gcry_pk_sign_t, gcry_pk_verify_t, gcry_pk_get_nbits_t, gcry_pk_spec_t, gcry_md_init_t, gcry_md_write_t, gcry_md_final_t, gcry_md_read_t, gcry_md_spec_t, gcry_cipher_setkey_t, gcry_cipher_encrypt_t, gcry_cipher_decrypt_t, gcry_cipher_stencrypt_t, gcry_cipher_stdecrypt_t, gcry_cipher_spec_t, gcry_module_t. 2003-07-04 Moritz Schulte * module.c (_gcry_module_list): New function. 2003-07-02 Moritz Schulte * module.c (_gcry_module_lookup): Fixed typo. * gcrypt.h: Added all definitions and declarations necessary for the new ac interface. 2003-06-30 Moritz Schulte * g10lib.h: Added declarations: _gcry_pk_module_lookup, _gcry_pk_module_release. 2003-06-18 Werner Koch * benchmark.c (cipher_bench): Adjusted for new API of get_blklen and get_keylen. * gcrypt.h (gcry_cipher_get_algo_blklen) (gcry_cipher_get_algo_keylen): Replaced macro by funcion. 2003-06-18 Moritz Schulte * cipher.h: Renamed types GcryDigestSpec, GcryCipherSpec and GcryPubkeySpec into: gcry_digest_spec_t, gcry_cipher_spec_t and gcry_pubkey_spec_t. (gcry_pubkey_spec): Defined member `id' as unsigned. (gcry_digest_spec): Likewise. (gcry_cipher_spec): Likewise. * module.c (_gcry_module_id_new): New function. (_gcry_module_add): Generate a new ID via _gcry_module_id_new in case `id' is zero. * g10lib.h, module.c: Replace old type GcryModule with newer one: gcry_module_t. * module.c (_gcry_module_add): Added argument `id', use it. * g10lib.h: Added declaration: _gcry_module_lookup_id. (_gcry_module_add): Added argument `id'. * module.c (_gcry_module_lookup_id): New function. * g10lib.h (struct gcry_module): New member: id. * gcrypt.h: New type: gcry_handler_progress_t, gcry_handler_alloc_t, gcry_haandler_secure_check_t, gcry_handler_realloc_t, gcry_handler_free_t, gcry_handler_no_mem_t, gcry_handler_error_t, gcry_handler_log_t. Use new types. * cipher.h: Include . New types: gcry_pk_generate_t, gcry_pk_check_secret_key_t, gcry_pk_encrypt_t, gcry_pk_decrypt_t, gcry_pk_sign_t, gcry_pk_verify_t, gcry_pk_get_nbits_t, gcry_md_init_t, gcry_md_write_t, gcry_md_final_t, gcry_md_read_t, gcry_cipher_setkey_t, gcry_cipher_encrypt_t, gcry_cipher_decrypt_t, gcry_cipher_stencrypt_t, gcry_cipher_stdecrypt_t. Use new types. 2003-06-17 Moritz Schulte * Makefile.am (AM_CFLAGS): Added: @GPG_ERROR_CFLAGS@. 2003-06-16 Moritz Schulte * g10lib.h: Replace last occurences of old type names with newer names (i.e. replace MPI with gcry_mpi_t). * mpi.h: Likewise. * sexp.c: Likewise. 2003-06-15 Moritz Schulte * testapi.c (test_genkey): Use gpg_strerror instead of gcry_strerror. * global.c (gcry_control): Fixed typo. * misc.c (_gcry_fatal_error): Use gpg_strerror instead of gcry_strerror. * types.h (STRLIST): Removed type since it is not used. 2003-06-11 Moritz Schulte * global.c (global_init): Call: _gcry_cipher_init, _gcry_md_init, _gcry_pk_init. * g10lib.h: Declare: _gcry_cipher_init, _gcry_md_init, _gcry_pk_init. * global.c (gcry_strerror): Remove compatibility code. * Makefile.am: Remove support libgpg-error special handling. (AM_CPPFLAGS): Add @GPG_ERROR_CFLAGS@ * gcrypt.h: Likewise. 2003-06-13 Werner Koch * gcrypt.h (gcry_md_get_algo): Reverted to old API. This is a convenience function anyway and error checking is not approriate. (gcry_md_is_enabled): New. (gcry_md_is_secure): Replaced macro by function and reverted to old API. 2003-06-11 Werner Koch * gcrypt.h (GCRYERR): Define _GCRY_ERR_SOURCE_DEFAULT instead of GPG_ERR_SOURCE_DEFAULT, so that libgpg-error still works despite the use of the old gcrypt error codes. (gcry_md_copy): Swapped arguments. 2003-06-09 Moritz Schulte * Makefile.am: Support for libgpg-error. 2003-06-08 Moritz Schulte * sexp.c (gcry_sexp_create): Expect sane error values from gcry_sexp_canon_len instead of the `historical' values. 2003-06-07 Moritz Schulte * ath.c, ath.c, ath-pth.c, ath-pthread.c, benchmark.c, cipher.h, g10lib.h, gcrypt.h, global.c, misc.c, missing-string.c, module.c, mpi.h, secmem.c, secmem.h, sexp.c, stdmem.c, stdmem.h, testapi.c, types.h: Edited all preprocessor instructions to remove whitespace before the '#'. This is not required by C89, but there are some compilers out there that don't like it. Replaced any occurence of the now deprecated type names with the new ones. * gcrypt.h: Re-organized checking for gcc features; New macro: _GCRY_GCC_ATTR_DEPRECATED. Include copy of libgpg-error's gpg-error.h in order to make it easy to build libgcrypt without needing libgpg-error.h. (GCRY_MPI, GcryMPI, GCRY_SEXP, GcrySexp, GCRY_CIPHER_HD, GcryCipherHd, GCRY_MD_HD, GcryMDHd): Declared deprecated. (gcry_mpi_t, gcry_sexp_t, gcry_cipher_hd_t, gcry_md_hd_t): New types. 2003-06-04 Moritz Schulte * sexp.c (sexp_sscan): New argument: arg_list, adjusted all callers. (ARG_NEXT): New macro. (sexp_sscan): Use ARG_NEXT for receiving format string arguments. (gcry_sexp_build_array): New function. 2003-06-02 Moritz Schulte * gcrypt.h: Added some comments describing the gcry_sexp_* functions. Include instead of . 2003-06-01 Moritz Schulte * sexp.c (OLDPARSECODE): Removed macro... (gcry_sexp_canon_len): ... and do not use it. * gcrypt.h (gcry_errno): Removed declaration. * g10lib.h (string_to_pubkey_algo, pubkey_algo_to_string, pubkey_nbits): Removed declarations for non-existing functions. 2003-05-31 Moritz Schulte * cipher.h (is_RSA, is_ELGAMAL): Removed macros. * g10lib.h (set_lasterr): Removed macro. (_gcry_set_lasterr): Removed declaration. * gcrypt.h: Changed declarations for: gcry_pk_algo_info, gcry_md_open, gcry_md_copy, gcry_md_algo_info, gcry_md_info, gcry_md_get_algo, gcry_random_add_bytes. (gcry_md_is_secure): Adjust macro for new API. 2003-05-29 Moritz Schulte * gcrypt.h: Changed declarations for: gcry_cipher_open, gcry_cipher_info, gcry_cipher_algo_info. (gcry_cipher_get_algo_keylen): Adjuster for new gcry_cipher_algo_info interface. (gcry_cipher_get_algo_blklen): Likewise. * global.c (gcry_errno): Removed function. (gcry_strerror): Do not use gcry_errno. (_gcry_set_lasterr): Removed function. (last_ec): Removed variable. 2003-05-27 Moritz Schulte * gcrypt.h (enum gcry_cipher_algos): Make Serpent IDs do not conflict with OpenPGP. Reported by Timo Schulz. * global.c (gcry_control): Fixed name of enum list. 2003-05-25 Moritz Schulte * cipher.h (gcry_cipher_spec): Adjust return type of `setkey' for libgpg-error. (gcry_pubkey_spec): Adjust return type of `generate', `check_secret_key', `encrypt', `decrypt', `sign' and `verify' for libgpg-error. * sexp.c (gcry_sexp_canon_len): Adjusted for libgpg-error. (gcry_sexp_create): Likewise. (gcry_sexp_new): Likewise. (sexp_sscan): Likewise. (gcry_sexp_build): Likewise. (gcry_sexp_sscan): Likewise. * module.c (_gcry_module_add): Likewise. * global.c (last_ec): Change type to gpg_error_t. (gcry_control): Adjust for libgpg-error. (gcry_errno): Likewise. (gcry_strerror): Likewise. (_gcry_set_lasterr): Likewise. (gcry_xmalloc): Likewise. (gcry_xrealloc): Likewise. 2003-05-22 Moritz Schulte * types.h: Merged code from GnuPG regarding U64_C. * missing-string.c (strsep): Removed function. * g10lib.h: Removed declarations: strsep, strlwr. * secmem.c (secmem_lock): New variable. (SECMEM_LOCK, SECMEM_UNLOCK): New macros. (_gcry_secmem_set_flags): Use SECMEM_LOCK and SECMEM_UNLOCK. (_gcry_secmem_get_flags): Likewise. (_gcry_secmem_init): Likewie. (_gcry_secmem_malloc): Likewise. (_gcry_secmem_free): Likewise. (_gcry_secmem_malloc): Renamed to ... (_gcry_secmem_malloc_internal): ... this. (_gcry_secmem_malloc): New function, use SECMEM_LOCK, SECMEM_UNLOCK, call _gcry_secmem_malloc_internal. (_gcry_secmem_free): Renamed to ... (_gcry_secmem_free_internal): ... this. (_gcry_secmem_free): New function, use SECMEM_LOCK, SECMEM_UNLOCK, call _gcry_secmem_free_internal. (_gcry_secmem_realloc): Use SECMEM_LOCK, SECMEM_UNLOCK, call _gcry_secmem_malloc_internal and _gcry_secmem_free_internal. (_gcry_private_is_secure): Use SECMEM_LOCK, SECMEM_UNLOCK. (_gcry_secmem_dump_stats): Likewise. (_gcry_secmem_malloc_internal): Removed unused variable: compressed. Include "ath.h". 2003-05-21 Moritz Schulte * gcrypt.h (GCRY_CIPHER_SERPENT128, GCRY_CIPHER_SERPENT192, GCRY_CIPHER_SERPENT256): New symbols. 2003-05-19 Moritz Schulte * gcrypt.h: Reversed changes from 2003-03-03 since they would have been an unnecessary ABI break. 2003-05-13 Moritz Schulte * secmem.c (stats_update): New function. (BLOCK_HEAD_SIZE): New symbol. (MB_FLAG_ACTIVE): New symbol. (ADDR_TO_BLOCK, BLOCK_VALID): New macros. (mb_get_next): New function. (mb_get_prev): New function. (mb_merge): New function. (mb_get_new): New function. (unused_blocks): Removed variable. (init_pool): Initialize new memory pool. (_gcry_secmem_malloc): Use new heap management code. (_gcry_secmem_free): Likewise. (_gcry_secmem_realloc): Likewise. Renamed type MEMBLOCK to memblock_t. 2003-04-27 Moritz Schulte * cipher.h (gcry_pubkey_spec): New member: sexp_names. 2003-04-23 Moritz Schulte * cipher.h (gcry_pubkey_spec): Removed members: npkey, nskey, nenc, nsig. (gcry_pubkey_spec): Added members: elements_pkey, elements_skey, elements_enc, elements_sig, elements_grip. 2003-04-17 Moritz Schulte * g10lib.h (GcryModule): New typedef. * gcrypt.h (gcry_cipher_register, gcry_cipher_unregister, gcry_digest_register, gcry_digest_unregister, gcry_pubkey_register, gcry_pubkey_unregister): Function declarations removed - for now. * gcrypt.h (GcryModule): Declaration removed. * gcrypt.h (GcryPubkeySpec, GcryDigestSpec, GcryCipherSpec): Types Moved... * cipher.h: ... here. 2003-04-17 Moritz Schulte * cipher.h: Declare digest_spec_sha512 and digest_spec_384. 2003-04-16 Moritz Schulte * module.c (_gcry_module_use): New function. * g10lib.h (_gcry_module_use): Declare function. * libgcrypt-config.in: Support for --algorithms switch, which prints the algorithms included in the built libgcrypt. * global.c (gcry_set_progress_handler): Register progress functions depending on the enabled algorithms. 2003-04-07 Moritz Schulte * Makefile.am (libgcrypt_la_SOURCES): Added module.c * module.c: New file. (_gcry_module_add): New function. (_gcry_module_drop): New function. (_gcry_module_lookup): New function. (_gcry_module_release): New function. * g10lib.h (GcryModule): New types. (FLAG_MODULE_DISABLED): New symbol. Added declarations for _gcry_module_add, _gcry_module_release and _gcry_module_lookup. * gcrypt.h: New types: GcryPubkeySpec, GcryDigestSpec, GcryCipherSpec. Added declarations for: gcry_cipher_register, gcry_cipher_unregister, gcry_digest_register, gcry_digest_unregister, gcry_pubkey_register and gcry_pubkey_unregister. * cipher.h: Removed symbols: CIPHER_ALGO_NONE, CIPHER_ALGO_IDEA, CIPHER_ALGO_3DES, CIPHER_ALGO_CAST5, CIPHER_ALGO_BLOWFISH, CIPHER_ALGO_SAFER_SK128, CIPHER_ALGO_DES_SK, CIPHER_ALGO_TWOFISH, CIPHER_ALGO_TWOFISH_OLD, CIPHER_ALGO_DUMMY, PUBKEY_USAGE_SIG, PUBKEY_USAGE_ENC, DIGEST_ALGO_MD5, DIGEST_ALGO_SHA1, DIGEST_ALGO_RMD160, DIGEST_ALGO_TIGER, PUBKEY_ALGO_RSA, PUBKEY_ALGO_RSA_E, PUBKEY_ALGO_RSA_S, PUBKEY_ALGO_DSA, PUBKEY_ALGO_ELGAMAL, PUBKEY_ALGO_ELGAMAL_E. 2003-04-02 Moritz Schulte * benchmark.c (md_bench): Fix error message. 2003-03-31 Moritz Schulte * benchmark.c (cipher_bench): Added CTR mode. 2003-03-30 Simon Josefsson * gcrypt.h (enum gcry_control_cmds): Add GCRY_SET_CTR. (enum gcry_cipher_modes): Add GCRY_CIPHER_MODE_CTR. (gcry_cipher_setctr): New macro to set counter. 2003-03-19 Moritz Schulte * cipher.h (PUBKEY_FLAG_NO_BLINDING): New symbol. 2003-03-22 Simon Josefsson * gcrypt.h: Add GCRYCTL_SET_CBC_MAC and GCRY_CIPHER_CBC_MAC. 2003-03-19 Werner Koch * g10lib.h: Adjusted primegen.c prototypes. 2003-03-12 Werner Koch * sexp.c (sexp_sscan): Initialize NM. Thanks to Ian Peters for valgrinding this. 2003-03-06 Moritz Schulte * secmem.h (GCRY_SECMEM_FLAG_NO_WARNING, GCRY_SECMEM_FLAG_SUSPEND_WARNING): New symbols. * global.c (gcry_control): Use GCRY_SECMEM_FLAG_{NO,SUSPEND}_WARNING, instead of hard-coded values. * secmem.c (_gcry_secmem_set_flags): Likewise. * secmem.c (_gcry_secmem_get_flags): Likewise. 2003-03-03 Moritz Schulte * misc.c: Removed old FIXME, since there is already a function to set the value of `verbosity_level'. * gcrypt.h: Removed enumeration list: gcry_ctl_cmds. New enumeration lists: gcry_global_control_cmds, gcry_control_cmds, gcry_info_cmds, gcry_algo_info_cmds. 2003-03-02 Moritz Schulte * gcrypt.h (gcry_cipher_reset): New macro for resetting a handle. 2003-02-28 Moritz Schulte * secmem.c (DEFAULT_PAGESIZE): New symbol. (init_pool): Use DEFAULT_PAGESIZE. 2003-02-23 Moritz Schulte * secmem.h: Fix typo in declaration of _gcry_secmem_term. * sexp.c: Move macro definitions of `digitp', `octdigit', `alphap' and `hexdigit' ... * g10lib.h: ... here. * misc.c (_gcry_burn_stack): New function (former name: burn_stack). * g10lib.h (burn_stack): Declare _gcry_burn_stack(). 2003-01-24 Werner Koch * global.c (gcry_set_progress_handler): Register a random progress handler. 2003-01-23 Werner Koch * gcrypt.h (GCRY_ENABLE_QUICK_RANDOM): New. * global.c (gcry_control): Make use of it. 2003-01-21 Werner Koch * gcrypt.h (gcry_random_add_bytes): Add QUALITY argument. 2003-01-21 Timo Schulz * gcrypt.h (gcry_random_add_bytes): New. 2003-01-20 Simon Josefsson * gcrypt.h (gcry_md_algos): Add GCRY_MD_CRC32, GCRY_MD_CRC32_RFC1510, GCRY_MD_CRC24_RFC2440. 2003-01-16 Werner Koch * gcrypt.h (gcry_md_write): Changed type of 2nd argument to void*. (gcry_md_hash_buffer): Changed type of both buffers to void*. (gcry_md_setkey): Changed type of 2nd argument to void*. (gcry_md_get_asnoid): New. 2003-01-15 Werner Koch * sexp.c (gcry_sexp_length): Fixed. This was seriously broken. 2003-01-14 Werner Koch * gcrypt.h (GCRYERR_INV_FLAG), global.c (gcry_strerror): New. 2003-01-02 Werner Koch * libgcrypt.vers: Temporary export _gcry_generate_elg_prime for use by GNUTLS. 2002-12-21 Werner Koch * gcrypt.h: Make use of gcc's pure and malloc attributes (gcry_md_putc): Use a helper variable to avoid multiple evaluation of H. * g10lib.h, stdmem.h, secmem.h: Use gcc attributes pure and malloc. * stdmem.c (use_m_guard): Don't default to yes. 2002-12-19 Werner Koch * global.c (global_init): The meat was never run due to a faulty check. Thanks to Nikos for pointing this out. * global.c (gcry_control): Return 1 and not -1 for the initialization tests. * libgcrypt.vers: New. * Makefile.am: Use this instead of the build symbol file. * global.c (gcry_control) : Call the random module initializer to make sure that the pool lock flag has been initialized. 2002-12-09 Werner Koch * global.c (gcry_calloc,gcry_calloc_secure): Check for overflow. Noted by Florian Weimer. 2002-11-10 Simon Josefsson * gcrypt.h (gcry_ctl_cmds): New GCRYCTL_SET_CBC_CTS control flag. (gcry_cipher_flags): New GCRY_CIPHER_CBC_CTS gcry_cipher_open() flag. (gcry_cipher_cts): New macro for toggling CTS. 2002-11-10 Werner Koch * gcrypt.h (GCRY_MD_MD4): New. We use a non OpenPGP value here. 2002-09-20 Werner Koch * ath.c: Include sys.time.h if sys/select.h does not exist. (ath_select, ath_waitpid): Shortcut for Windows. * ath.h: Include some Windows headers. By Timo. 2002-09-18 Werner Koch * ath.h: Prefix ath_deinit. 2002-09-17 Werner Koch * benchmark.c: New. (mpi_bench, do_powm): Add a a simple test for RSA. * global.c (global_init): New. Use it instead of the setting any_init_done. Initialize the ATH system. (gcry_check_version): Hook global_init in. This is the suggested way to initialize the library. (_gcry_no_internal_locking): Removed. We simply call a ath_deinit and leave it to ATH to disbale the locking. * ath.c, ath.h, ath-pth.c, ath-pthread.c: New. Taken from GPGME. * mutex.h: Removed. * Makefile.am (ath_components): New. 2002-09-16 Werner Koch * secmem.c (_gcry_secmem_dump_stats): Replaced fprintf by log_*. 2002-08-23 Werner Koch * missing-string.c: Removed unneeded strlwr. * libgcrypt.m4: Made much more simple. * libgcrypt-config.in: Made --prefix work for --libs. 2002-08-14 Werner Koch * gcrypt.h: Add GCRY_CIPGER_DES. Included string.h for size_t. Suggested by Simon Josefsson. 2002-07-25 Werner Koch * cipher.h: Added prototypes for progress functions. * global.c: Include cipher.h for those prototypes. * stdmem.c (_gcry_private_realloc): Replaced void* by char * for pointer arithmetic reasons. Noted by Stephan Austermuehle. 2002-06-24 Werner Koch * missing-string.c: Include ctype.h. * gcrypt.h (gcry_mpi_invm, gcry_mpi_div, gcry_mpi_mod) (gcry_mpi_swap): New. 2002-06-18 Werner Koch * gcrypt.h: Added a bunch of brief function descriptions. 2002-05-21 Werner Koch * misc.c (_gcry_log_printf): Don't initialize a va_list. Noted by Jeff Johnson. * global.c (gcry_set_progress_handler): New. * gcrypt.h: Replaced the typedef for byte. 2002-05-16 Werner Koch * missing-string.c: New. * gcrypt.h: Add new error codes GCRYERR_SEXP_ and typedefs GcryMPI, GcrySexp, GcryCipherHd, GcryMDHd as aliases for the old ones using an underscore. * global.c (gcry_strerror): Add strings fro the new error codes. * sexp.c (gcry_sexp_canon_len): Use a macro to convert from new to old error codes. (gcry_sexp_create,gcry_sexp_new): New. 2002-05-15 Werner Koch * mutex.h (DEFINE_LOCAL_MUTEX): Macro to define a mutex and initialize it so that we can detect an unitialized mutex and don't read from stdin. 2002-05-14 Werner Koch Changed license of all files to the LGPL. 2002-05-07 Werner Koch * global.c (gcry_control): Add commands GCRYCTL_ANY_INITIALIZATION_P and GCRYCTL_INITIALIZATION_FINISHED_P so that other libraries are able to check for required initializations. 2002-05-02 Werner Koch * gcrypt.h (GCRYCTL_DISABLE_INTERNAL_LOCKING): New. * global.c (gcry_control): Implement it. (_gcry_no_internal_locking): New. * mutex.h: Prefixed all fucntions with _gcry_. Bypass all functions when desired. * gcrypt.h (GCRYCTL_DISABLE_SECMEM): New. * global.c (gcry_control,gcry_malloc_secure,gcry_is_secure): Implement it here. * secmem.c (_gcry_private_is_secure): Return false if the pool is not initialized. * gcrypt.h (GCRYCTL_INITIALIZATION_FINISHED): New. * gcrypt.h (gcry_cipher_algos): Replaced RINDAEL by AES and change the macros to expand from rijdael to aes. * stdmem.c (_gcry_private_malloc): Return NULL for 0 byte allocation. (_gcry_private_malloc_secure): Ditto. * g10lib.h: Copied the JNLIB_GCC macros from ../jnlib/mischelp.h and removed the inclusion of that file. 2002-04-15 Werner Koch * global.c (gcry_strdup): New. 2002-03-18 Werner Koch * mutex.h: New file with a portable thread mutex implementation written by Marcus Brinkmann. Taken from GPGME. 2002-02-18 Werner Koch * sexp.c (gcry_sexp_sscan): Don't initialize the dummy variable. Suggested by Jordi Mallach. 2002-01-31 Werner Koch * sexp.c (suitable_encoding,convert_to_hex,convert_to_string) (convert_to_token): New. (gcry_sexp_sprint): Better formatting of advanced encoding, does now insert LFs and escapes all unprintable characters. (unquote_string): New. (sexp_sscan): Implemented the missing conversion of quoted strings. 2002-01-26 Werner Koch * libgcrypt-config.in: Add copyright notice. 2002-01-11 Werner Koch * sexp.c (gcry_sexp_canon_len): Fixed last change. 2002-01-01 Timo Schulz * stdmem.c (_gcry_private_realloc): If pointer is NULL now realloc behaves like malloc. 2001-12-20 Werner Koch * sexp.c (gcry_sexp_canon_len): Describe the error codes and return an error if this is not a S-Exp; i.e. it does not start with an open parenthesis. 2001-12-18 Werner Koch * sexp.c (gcry_sexp_canon_len): Fixed the test on NULL buffer. * Makefile.am (DISTCLEANFILES): Include libgcrypt.sym * sexp.c: Removed the commented test code because we now have a test in ../tests/ 2001-12-17 Werner Koch * sexp.c (gcry_sexp_canon_len): New. 2001-12-11 Werner Koch * gcrypt.h: Fixed AES128 macro, add enum for OFB mode. 2001-12-05 Werner Koch * misc.c (_gcry_log_printf): New. * sexp.c (dump_string,gcry_sexp_dump): Use logging functions instead of stderr. 2001-11-16 Werner Koch * gcrypt.h: New constant GCRYCTL_IS_ALGO_ENABLED. 2001-10-02 Werner Koch * gcrypt.h: Removed a couple of trailing commas. 2001-08-28 Werner Koch * sexp.c (sexp_sscan): Add an argument to enable the arg_ptr. Changed all callers. Suggested by Tom Holroyd. 2001-08-03 Werner Koch * global.c (gcry_strerror): Updated list of error codes. 2001-07-23 Werner Koch * gcrypt.h: Replaced the last ulong. Noted by Rami Lehti. 2001-05-31 Werner Koch * gcrypt.h, mpi.h: Made some mpi functions public. * wrapper.c: Removed. * global.c: Renamed all g10_ prefixed functions which had wrappers to gcry_xxx. So we now use the exported memory functions inernally. Renamed all g10_ prefixed functions to _gcry_ prefixed ones. * g10lib.h (_GCRYPT_IN_LIBGCRYPT): Replace defintion by a test on it. 2001-05-28 Werner Koch * libgcrypt.m4: Check GCRYPT_VERSION macro and not LIBGCRYPT_VERSION. * mpi.h: Removed mpi_fromstr prototype. 2001-01-11 Werner Koch * Makefile.am (libgcrypt_la_SOURCES): Add mpi.h 2000-12-19 Werner Koch * types.h: Moved from ../include to here. Major change: Removed all GnuPG stuff and renamed this piece of software to gcrypt. 2000-11-14 Werner Koch * mpi.h: Moved to ../mpi. * Makefile.am (OMIT_DEPENDENCIES): Hack to work around dependency problems. 2000-10-11 Werner Koch * mpi.h: Changed the way mpi_limb_t is defined. 2000-10-10 Werner Koch * Makefile.am: Take version-info from configure. 2000-10-09 Werner Koch * gcrypt.h: New cipher mode, new algo Arcfour and new error code GCRYERR_INV_CIPHER_MODE. * global.c (gcry_strerror): New errorcode. Wed Oct 4 13:16:18 CEST 2000 Werner Koch * gcrypt.h (gcry_md_setkey): Replaced macro by function prototype. Mon Sep 18 16:35:45 CEST 2000 Werner Koch * gcrypt.h (GCRYCTL_GET_ALGO_USAGE): New. * secmem.c (secmem_realloc): check for failed secmem_malloc. By Matt Kraai. Mon Jul 31 10:04:47 CEST 2000 Werner Koch * sexp.c: Removed the datalen fields from list tags. (gcry_sexp_car_data,gcry_sexp_cdr_data,gcry_sexp_car_mpi, gcry_sexp_cdr_mpi): Removed. (gcry_sexp_nth,gcry_sexp_nth_data,gcry_sexp_nth_mpi): New. Fri Jul 28 18:19:11 CEST 2000 Werner Koch * sexp.c (sexp_sscan): Fixed reallocation to secure memory. (new_empty_list): Removed (gcry_sexp_length): New. (gcry_sexp_enum): Removed. (normalize): New. Reworked the whole thing to use NULL for an empty list. (make_space): New instead of the macro. Tue Jul 25 17:44:15 CEST 2000 Werner Koch * sexp.c: Major rewrite. (gcry_sexp_sscan): Reordered arguments. Moved functionality to .. (sexp_sscan): .. this. (gcry_sexp_build): New. (gcry_sexp_new_name_mpi, gcry_sexp_new_name_data, gcry_sexp_new_data, gcry_sexp_new_mpi): Removed. Fri Jul 14 19:38:23 CEST 2000 Werner Koch * gcrypt.h (gcry_md_start_debug, gcry_md_stop_debug): New. (gcry_ctl_cmds): New control values * sexp.c (gcry_sexp_sscan): Add hex format parsing. * secmem.c (lock_pool): Check for ENOSYS return my mlock() on old SCOs. (pool_is_mmapped): Made volatile. (lock_pool): No more warning for QNX. By Sam Roberts. (lock_pool,secmem_init): Additional check for dropped privs. 2000-03-21 09:18:48 Werner Koch (wk@habibti.gnupg.de) * gcrypt.h (gcry_md_setkey): New. (GCRY_MD_FLAG_HMAC): New. Mon Jan 31 16:37:34 CET 2000 Werner Koch * Makefile.am: Add g10lib.h Thu Jan 27 18:00:44 CET 2000 Werner Koch * sexp.c (gcry_sexp_sscan): Allow NULL for erroff. Mon Jan 24 22:24:38 CET 2000 Werner Koch * sexp.c (gcry_sexp_alist): New. Mon Jan 24 13:04:28 CET 2000 Werner Koch * secmem.c: Moved from ../util to here. * secmem.h: New. * stdmem.c: New. Based on the old ../util/memory.c. * stdmem.h: New. Wed Dec 8 21:58:32 CET 1999 Werner Koch * gcrypt.m4: New. * gcrypt-config: New. * mpi.h (mpi_get_nbit_info): Removed (mpi_set_nbit_info): Removed. (struct gcry_mpi): Removed the nbits field. * misc.c (g10_log_verbosity): New. * global.c (g10_xstrdup): New. * mpiapi.c: Removed. * mpi.h: Moved from ../include to here. Removed some obsolete prototypes and the iobuf.h header. * cipher.h: Moved from ../include to here. Removed the mpi.h header. * g10lib.h: Moved from ../include to here. Fri Nov 19 17:15:20 CET 1999 Werner Koch * sexp.c (dump_string): New. Taken from gnupg/util/miscutil.c. (do_dump_list): s/print_string/dump_string/. * testapi.c: New. * mpiapi.c (gcry_mpi_randomize): Use new random API. Sat Nov 13 17:44:23 CET 1999 Werner Koch * gloabl.c (gcry_control): Add cases for dumping random and secmem stats. Tue Oct 26 14:10:21 CEST 1999 Werner Koch * pkapi.c: Removed. * symapi.c: Removed. * g10lib.h: Moved to ../include. * mdapi.c: Removed. Wed Jul 7 13:08:40 CEST 1999 Werner Koch * sexp.c: New. Tue Dec 8 13:15:16 CET 1998 Werner Koch * gcrypt.h: New * mpiapi.c: New Copyright (C) 1998,1999,2000,2001,2002,2003 2004, 2005 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without modifications, as long as this notice is preserved. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/src/Makefile.am b/src/Makefile.am index a5f3e4f0..09aeff1d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,95 +1,106 @@ -# Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006 Free Software Foundation, Inc. +# Makefile.am - for gcrypt/src +# Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +# 2006, 2007 Free Software Foundation, Inc. # # This file is part of Libgcrypt. # # Libgcrypt is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # # Libgcrypt is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA ## Process this file with automake to produce Makefile.in EXTRA_DIST = Manifest libgcrypt-config.in libgcrypt.m4 libgcrypt.vers \ gcrypt.h.in bin_SCRIPTS = libgcrypt-config m4datadir = $(datadir)/aclocal m4data_DATA = libgcrypt.m4 include_HEADERS = gcrypt.h gcrypt-module.h lib_LTLIBRARIES = libgcrypt.la +if USE_RANDOM_DAEMON sbin_PROGRAMS = gcryptrnd bin_PROGRAMS = getrandom +endif USE_RANDOM_DAEMON if HAVE_LD_VERSION_SCRIPT libgcrypt_version_script_cmd = -Wl,--version-script=$(srcdir)/libgcrypt.vers else libgcrypt_version_script_cmd = endif libgcrypt_la_CFLAGS = @GPG_ERROR_CFLAGS@ libgcrypt_la_SOURCES = g10lib.h types.h cipher.h \ misc.c global.c sexp.c \ stdmem.c stdmem.h secmem.c secmem.h \ mpi.h missing-string.c module.c \ ath.h ath.c if HAVE_W32_SYSTEM LTRCCOMPILE = $(LIBTOOL) --mode=compile $(RC) \ `echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \ sed -e 's/-I/--include-dir /g;s/-D/--define /g'` %.lo : %.rc $(LTRCCOMPILE) -i $< -o $@ gcrypt_res = versioninfo.lo gcrypt_res_ldflag = -Wl,.libs/versioninfo.o no_undefined = -no-undefined export_symbols = -export-symbols $(srcdir)/libgcrypt.def install-def-file: $(INSTALL) $(srcdir)/libgcrypt.def $(DESTDIR)$(libdir)/libgcrypt.def uninstall-def-file: -rm $(DESTDIR)$(libdir)/libgcrypt.def gcrypt_deps = $(gcrypt_res) libgcrypt.def -else +else !HAVE_W32_SYSTEM + gcrypt_res = gcrypt_res_ldflag = no_undefined = export_symbols = install-def-file: uninstall-def-file: gcrypt_deps = -endif + +endif !HAVE_W32_SYSTEM + libgcrypt_la_LDFLAGS = $(gcrypt_res_ldflag) $(no_undefined) $(export_symbols) \ $(libgcrypt_version_script_cmd) -version-info \ @LIBGCRYPT_LT_CURRENT@:@LIBGCRYPT_LT_REVISION@:@LIBGCRYPT_LT_AGE@ libgcrypt_la_DEPENDENCIES = ../cipher/libcipher.la ../mpi/libmpi.la \ $(srcdir)/libgcrypt.vers $(gcrypt_deps) libgcrypt_la_LIBADD = ../cipher/libcipher.la ../mpi/libmpi.la \ @LTLIBOBJS@ @GPG_ERROR_LIBS@ + +if USE_RANDOM_DAEMON gcryptrnd_SOURCES = gcryptrnd.c gcryptrnd_CFLAGS = $(GPG_ERROR_CFLAGS) $(PTH_CFLAGS) gcryptrnd_LDADD = ../src/libgcrypt.la $(PTH_LIBS) getrandom_SOURCES = getrandom.c +endif USE_RANDOM_DAEMON + install-data-local: install-def-file uninstall-local: uninstall-def-file diff --git a/src/ath.c b/src/ath.c index 2768d8e8..66fa50ac 100644 --- a/src/ath.c +++ b/src/ath.c @@ -1,338 +1,338 @@ /* ath.c - Thread-safeness library. Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of Libgcrypt. Libgcrypt is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. Libgcrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Libgcrypt; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #ifdef HAVE_SYS_SELECT_H # include #else # include #endif #include #ifndef _WIN32 #include #endif #include #include "ath.h" /* The interface table. */ static struct ath_ops ops; /* True if we should use the external callbacks. */ static int ops_set; /* For the dummy interface. */ #define MUTEX_UNLOCKED ((ath_mutex_t) 0) #define MUTEX_LOCKED ((ath_mutex_t) 1) #define MUTEX_DESTROYED ((ath_mutex_t) 2) /* The lock we take while checking for lazy lock initialization. */ static ath_mutex_t check_init_lock = ATH_MUTEX_INITIALIZER; int ath_init (void) { int err = 0; if (ops_set) { if (ops.init) err = (*ops.init) (); if (err) return err; err = (*ops.mutex_init) (&check_init_lock); } return err; } /* Initialize the locking library. Returns 0 if the operation was successful, EINVAL if the operation table was invalid and EBUSY if we already were initialized. */ gpg_err_code_t ath_install (struct ath_ops *ath_ops, int check_only) { if (check_only) { enum ath_thread_option option = ATH_THREAD_OPTION_DEFAULT; /* Check if the requested thread option is compatible to the thread option we are already committed to. */ if (ath_ops) option = ath_ops->option; if (!ops_set && option) return GPG_ERR_NOT_SUPPORTED; if (ops.option == ATH_THREAD_OPTION_USER || option == ATH_THREAD_OPTION_USER || ops.option != option) return GPG_ERR_NOT_SUPPORTED; return 0; } if (ath_ops) { /* It is convenient to not require DESTROY. */ if (!ath_ops->mutex_init || !ath_ops->mutex_lock || !ath_ops->mutex_unlock) return GPG_ERR_INV_ARG; ops = *ath_ops; ops_set = 1; } else ops_set = 0; return 0; } static int mutex_init (ath_mutex_t *lock, int just_check) { int err = 0; if (just_check) (*ops.mutex_lock) (&check_init_lock); if (*lock == ATH_MUTEX_INITIALIZER || !just_check) err = (*ops.mutex_init) (lock); if (just_check) (*ops.mutex_unlock) (&check_init_lock); return err; } int ath_mutex_init (ath_mutex_t *lock) { if (ops_set) return mutex_init (lock, 0); #ifndef NDEBUG *lock = MUTEX_UNLOCKED; #endif return 0; } int ath_mutex_destroy (ath_mutex_t *lock) { if (ops_set) { if (!ops.mutex_destroy) return 0; (*ops.mutex_lock) (&check_init_lock); if (*lock == ATH_MUTEX_INITIALIZER) { (*ops.mutex_unlock) (&check_init_lock); return 0; } (*ops.mutex_unlock) (&check_init_lock); return (*ops.mutex_destroy) (lock); } #ifndef NDEBUG assert (*lock == MUTEX_UNLOCKED); *lock = MUTEX_DESTROYED; #endif return 0; } int ath_mutex_lock (ath_mutex_t *lock) { if (ops_set) { int ret = mutex_init (lock, 1); if (ret) return ret; return (*ops.mutex_lock) (lock); } #ifndef NDEBUG assert (*lock == MUTEX_UNLOCKED); *lock = MUTEX_LOCKED; #endif return 0; } int ath_mutex_unlock (ath_mutex_t *lock) { if (ops_set) { int ret = mutex_init (lock, 1); if (ret) return ret; return (*ops.mutex_unlock) (lock); } #ifndef NDEBUG assert (*lock == MUTEX_LOCKED); *lock = MUTEX_UNLOCKED; #endif return 0; } ssize_t ath_read (int fd, void *buf, size_t nbytes) { if (ops_set && ops.read) return (*ops.read) (fd, buf, nbytes); else return read (fd, buf, nbytes); } ssize_t ath_write (int fd, const void *buf, size_t nbytes) { if (ops_set && ops.write) return (*ops.write) (fd, buf, nbytes); else return write (fd, buf, nbytes); } ssize_t #ifdef _WIN32 ath_select (int nfd, void *rset, void *wset, void *eset, struct timeval *timeout) #else ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, struct timeval *timeout) #endif { if (ops_set && ops.select) return (*ops.select) (nfd, rset, wset, eset, timeout); else #ifdef _WIN32 return -1; #else return select (nfd, rset, wset, eset, timeout); #endif } ssize_t ath_waitpid (pid_t pid, int *status, int options) { if (ops_set && ops.waitpid) return (*ops.waitpid) (pid, status, options); else #ifdef _WIN32 return -1; #else return waitpid (pid, status, options); #endif } int #ifdef _WIN32 ath_accept (int s, void *addr, int *length_ptr) #else ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr) #endif { if (ops_set && ops.accept) return (*ops.accept) (s, addr, length_ptr); else #ifdef _WIN32 return -1; #else return accept (s, addr, length_ptr); #endif } int #ifdef _WIN32 -ath_connect (int s, void *addr, socklen_t length) +ath_connect (int s, void *addr, int length) #else ath_connect (int s, struct sockaddr *addr, socklen_t length) #endif { if (ops_set && ops.connect) return (*ops.connect) (s, addr, length); else #ifdef _WIN32 return -1; #else return connect (s, addr, length); #endif } int #ifdef _WIN32 ath_sendmsg (int s, const void *msg, int flags) #else ath_sendmsg (int s, const struct msghdr *msg, int flags) #endif { if (ops_set && ops.sendmsg) return (*ops.sendmsg) (s, msg, flags); else #ifdef _WIN32 return -1; #else return sendmsg (s, msg, flags); #endif } int #ifdef _WIN32 ath_recvmsg (int s, void *msg, int flags) #else ath_recvmsg (int s, struct msghdr *msg, int flags) #endif { if (ops_set && ops.recvmsg) return (*ops.recvmsg) (s, msg, flags); else #ifdef _WIN32 return -1; #else return recvmsg (s, msg, flags); #endif } diff --git a/src/ath.h b/src/ath.h index 38a046f3..a75c4f1c 100644 --- a/src/ath.h +++ b/src/ath.h @@ -1,132 +1,132 @@ /* ath.h - Thread-safeness library. Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of Libgcrypt. Libgcrypt is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. Libgcrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Libgcrypt; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef ATH_H #define ATH_H #ifdef _WIN32 #include #else #include #include #endif #include #include /* Define _ATH_EXT_SYM_PREFIX if you want to give all external symbols a prefix. */ #define _ATH_EXT_SYM_PREFIX _gcry_ #ifdef _ATH_EXT_SYM_PREFIX #define _ATH_PREFIX1(x,y) x ## y #define _ATH_PREFIX2(x,y) _ATH_PREFIX1(x,y) #define _ATH_PREFIX(x) _ATH_PREFIX2(_ATH_EXT_SYM_PREFIX,x) #define ath_install _ATH_PREFIX(ath_install) #define ath_init _ATH_PREFIX(ath_init) #define ath_mutex_init _ATH_PREFIX(ath_mutex_init) #define ath_mutex_destroy _ATH_PREFIX(ath_mutex_destroy) #define ath_mutex_lock _ATH_PREFIX(ath_mutex_lock) #define ath_mutex_unlock _ATH_PREFIX(ath_mutex_unlock) #define ath_read _ATH_PREFIX(ath_read) #define ath_write _ATH_PREFIX(ath_write) #define ath_select _ATH_PREFIX(ath_select) #define ath_waitpid _ATH_PREFIX(ath_waitpid) #define ath_connect _ATH_PREFIX(ath_connect) #define ath_accept _ATH_PREFIX(ath_accept) #define ath_sendmsg _ATH_PREFIX(ath_sendmsg) #define ath_recvmsg _ATH_PREFIX(ath_recvmsg) #endif enum ath_thread_option { ATH_THREAD_OPTION_DEFAULT = 0, ATH_THREAD_OPTION_USER = 1, ATH_THREAD_OPTION_PTH = 2, ATH_THREAD_OPTION_PTHREAD = 3 }; struct ath_ops { enum ath_thread_option option; int (*init) (void); int (*mutex_init) (void **priv); int (*mutex_destroy) (void *priv); int (*mutex_lock) (void *priv); int (*mutex_unlock) (void *priv); ssize_t (*read) (int fd, void *buf, size_t nbytes); ssize_t (*write) (int fd, const void *buf, size_t nbytes); #ifdef _WIN32 ssize_t (*select) (int nfd, void *rset, void *wset, void *eset, struct timeval *timeout); ssize_t (*waitpid) (pid_t pid, int *status, int options); int (*accept) (int s, void *addr, int *length_ptr); - int (*connect) (int s, void *addr, socklen_t length); + int (*connect) (int s, void *addr, int length); int (*sendmsg) (int s, const void *msg, int flags); int (*recvmsg) (int s, void *msg, int flags); #else ssize_t (*select) (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, struct timeval *timeout); ssize_t (*waitpid) (pid_t pid, int *status, int options); int (*accept) (int s, struct sockaddr *addr, socklen_t *length_ptr); int (*connect) (int s, struct sockaddr *addr, socklen_t length); int (*sendmsg) (int s, const struct msghdr *msg, int flags); int (*recvmsg) (int s, struct msghdr *msg, int flags); #endif }; gpg_err_code_t ath_install (struct ath_ops *ath_ops, int check_only); int ath_init (void); /* Functions for mutual exclusion. */ typedef void *ath_mutex_t; #define ATH_MUTEX_INITIALIZER 0 int ath_mutex_init (ath_mutex_t *mutex); int ath_mutex_destroy (ath_mutex_t *mutex); int ath_mutex_lock (ath_mutex_t *mutex); int ath_mutex_unlock (ath_mutex_t *mutex); /* Replacement for the POSIX functions, which can be used to allow other (user-level) threads to run. */ ssize_t ath_read (int fd, void *buf, size_t nbytes); ssize_t ath_write (int fd, const void *buf, size_t nbytes); #ifdef _WIN32 ssize_t ath_select (int nfd, void *rset, void *wset, void *eset, struct timeval *timeout); ssize_t ath_waitpid (pid_t pid, int *status, int options); int ath_accept (int s, void *addr, int *length_ptr); int ath_connect (int s, void *addr, int length); int ath_sendmsg (int s, const void *msg, int flags); int ath_recvmsg (int s, void *msg, int flags); #else ssize_t ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, struct timeval *timeout); ssize_t ath_waitpid (pid_t pid, int *status, int options); int ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr); int ath_connect (int s, struct sockaddr *addr, socklen_t length); int ath_sendmsg (int s, const struct msghdr *msg, int flags); int ath_recvmsg (int s, struct msghdr *msg, int flags); #endif #endif /* ATH_H */ diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index b53276b6..de6c7cc8 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -1,1740 +1,1742 @@ /* gcrypt.h - GNU Cryptographic Library Interface -*- c -*- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc. This file is part of Libgcrypt. Libgcrypt is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. Libgcrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. File: @configure_input@ */ #ifndef _GCRYPT_H #define _GCRYPT_H #include #include #include #include #include #if defined _WIN32 || defined __WIN32__ # include # include #else # include #endif /*!_WIN32*/ @FALLBACK_SOCKLEN_T@ #include /* This is required for error code compatibility. */ #define _GCRY_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_GCRYPT #ifdef __cplusplus extern "C" { #if 0 /* keep Emacsens' auto-indent happy */ } #endif #endif /* The version of this header should match the one of the library. It should not be used by a program because gcry_check_version() should return the same version. The purpose of this macro is to let autoconf (using the AM_PATH_GCRYPT macro) check that this header matches the installed library. */ #define GCRYPT_VERSION "@VERSION@" /* Internal: We can't use the convenience macros for the multi precision integer functions when building this library. */ #ifdef _GCRYPT_IN_LIBGCRYPT #ifndef GCRYPT_NO_MPI_MACROS #define GCRYPT_NO_MPI_MACROS 1 #endif #endif /* We want to use gcc attributes when possible. Warning: Don't use these macros in your programs: As indicated by the leading underscore they are subject to change without notice. */ #ifdef __GNUC__ #define _GCRY_GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) #if _GCRY_GCC_VERSION >= 30100 #define _GCRY_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__)) #endif #if _GCRY_GCC_VERSION >= 29600 #define _GCRY_GCC_ATTR_PURE __attribute__ ((__pure__)) #endif #if _GCRY_GCC_VERSION >= 300200 #define _GCRY_GCC_ATTR_MALLOC __attribute__ ((__malloc__)) #endif #endif /*__GNUC__*/ #ifndef _GCRY_GCC_ATTR_DEPRECATED #define _GCRY_GCC_ATTR_DEPRECATED #endif #ifndef _GCRY_GCC_ATTR_PURE #define _GCRY_GCC_ATTR_PURE #endif #ifndef _GCRY_GCC_ATTR_MALLOC #define _GCRY_GCC_ATTR_MALLOC #endif /* Wrappers for the libgpg-error library. */ typedef gpg_error_t gcry_error_t; typedef gpg_err_code_t gcry_err_code_t; typedef gpg_err_source_t gcry_err_source_t; static GPG_ERR_INLINE gcry_error_t gcry_err_make (gcry_err_source_t source, gcry_err_code_t code) { return gpg_err_make (source, code); } /* The user can define GPG_ERR_SOURCE_DEFAULT before including this file to specify a default source for gpg_error. */ #ifndef GCRY_ERR_SOURCE_DEFAULT #define GCRY_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1 #endif static GPG_ERR_INLINE gcry_error_t gcry_error (gcry_err_code_t code) { return gcry_err_make (GCRY_ERR_SOURCE_DEFAULT, code); } static GPG_ERR_INLINE gcry_err_code_t gcry_err_code (gcry_error_t err) { return gpg_err_code (err); } static GPG_ERR_INLINE gcry_err_source_t gcry_err_source (gcry_error_t err) { return gpg_err_source (err); } /* Return a pointer to a string containing a description of the error code in the error value ERR. */ const char *gcry_strerror (gcry_error_t err); /* Return a pointer to a string containing a description of the error source in the error value ERR. */ const char *gcry_strsource (gcry_error_t err); /* Retrieve the error code for the system error ERR. This returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report this). */ gcry_err_code_t gcry_err_code_from_errno (int err); /* Retrieve the system error for the error code CODE. This returns 0 if CODE is not a system error code. */ int gcry_err_code_to_errno (gcry_err_code_t code); /* Return an error value with the error source SOURCE and the system error ERR. */ gcry_error_t gcry_err_make_from_errno (gcry_err_source_t source, int err); /* Return an error value with the system error ERR. */ gcry_err_code_t gcry_error_from_errno (int err); enum gcry_thread_option { GCRY_THREAD_OPTION_DEFAULT = 0, GCRY_THREAD_OPTION_USER = 1, GCRY_THREAD_OPTION_PTH = 2, GCRY_THREAD_OPTION_PTHREAD = 3 }; /* Wrapper for struct ath_ops. */ struct gcry_thread_cbs { enum gcry_thread_option option; int (*init) (void); int (*mutex_init) (void **priv); int (*mutex_destroy) (void **priv); int (*mutex_lock) (void **priv); int (*mutex_unlock) (void **priv); ssize_t (*read) (int fd, void *buf, size_t nbytes); ssize_t (*write) (int fd, const void *buf, size_t nbytes); #ifdef _WIN32 ssize_t (*select) (int nfd, void *rset, void *wset, void *eset, struct timeval *timeout); ssize_t (*waitpid) (pid_t pid, int *status, int options); int (*accept) (int s, void *addr, int *length_ptr); int (*connect) (int s, void *addr, gcry_socklen_t length); int (*sendmsg) (int s, const void *msg, int flags); int (*recvmsg) (int s, void *msg, int flags); #else ssize_t (*select) (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, struct timeval *timeout); ssize_t (*waitpid) (pid_t pid, int *status, int options); int (*accept) (int s, struct sockaddr *addr, gcry_socklen_t *length_ptr); int (*connect) (int s, struct sockaddr *addr, gcry_socklen_t length); int (*sendmsg) (int s, const struct msghdr *msg, int flags); int (*recvmsg) (int s, struct msghdr *msg, int flags); #endif }; #define GCRY_THREAD_OPTION_PTH_IMPL \ static int gcry_pth_init (void) \ { return (pth_init () == FALSE) ? errno : 0; } \ static int gcry_pth_mutex_init (void **priv) \ { \ int err = 0; \ pth_mutex_t *lock = malloc (sizeof (pth_mutex_t)); \ \ if (!lock) \ err = ENOMEM; \ if (!err) \ { \ err = pth_mutex_init (lock); \ if (err == FALSE) \ err = errno; \ else \ err = 0; \ if (err) \ free (lock); \ else \ *priv = lock; \ } \ return err; \ } \ static int gcry_pth_mutex_destroy (void **lock) \ { /* GNU Pth has no destructor function. */ free (*lock); return 0; } \ static int gcry_pth_mutex_lock (void **lock) \ { return ((pth_mutex_acquire (*lock, 0, NULL)) == FALSE) \ ? errno : 0; } \ static int gcry_pth_mutex_unlock (void **lock) \ { return ((pth_mutex_release (*lock)) == FALSE) \ ? errno : 0; } \ static ssize_t gcry_pth_read (int fd, void *buf, size_t nbytes) \ { return pth_read (fd, buf, nbytes); } \ static ssize_t gcry_pth_write (int fd, const void *buf, size_t nbytes) \ { return pth_write (fd, buf, nbytes); } \ static ssize_t gcry_pth_select (int nfd, fd_set *rset, fd_set *wset, \ fd_set *eset, struct timeval *timeout) \ { return pth_select (nfd, rset, wset, eset, timeout); } \ static ssize_t gcry_pth_waitpid (pid_t pid, int *status, int options) \ { return pth_waitpid (pid, status, options); } \ static int gcry_pth_accept (int s, struct sockaddr *addr, \ gcry_socklen_t *length_ptr) \ { return pth_accept (s, addr, length_ptr); } \ static int gcry_pth_connect (int s, struct sockaddr *addr, \ gcry_socklen_t length) \ { return pth_connect (s, addr, length); } \ \ /* FIXME: GNU Pth is missing pth_sendmsg and pth_recvmsg. */ \ static struct gcry_thread_cbs gcry_threads_pth = { GCRY_THREAD_OPTION_PTH, \ gcry_pth_init, gcry_pth_mutex_init, gcry_pth_mutex_destroy, \ gcry_pth_mutex_lock, gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write, \ gcry_pth_select, gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect, \ NULL, NULL } #define GCRY_THREAD_OPTION_PTHREAD_IMPL \ static int gcry_pthread_mutex_init (void **priv) \ { \ int err = 0; \ pthread_mutex_t *lock = (pthread_mutex_t*)malloc (sizeof (pthread_mutex_t));\ \ if (!lock) \ err = ENOMEM; \ if (!err) \ { \ err = pthread_mutex_init (lock, NULL); \ if (err) \ free (lock); \ else \ *priv = lock; \ } \ return err; \ } \ static int gcry_pthread_mutex_destroy (void **lock) \ { int err = pthread_mutex_destroy ((phread_mutex_t*)*lock); \ free (*lock); return err; } \ static int gcry_pthread_mutex_lock (void **lock) \ { return pthread_mutex_lock ((phread_mutex_t*)*lock); } \ static int gcry_pthread_mutex_unlock (void **lock) \ { return pthread_mutex_unlock ((phread_mutex_t*)*lock); } \ \ static struct gcry_thread_cbs gcry_threads_pthread = \ { GCRY_THREAD_OPTION_PTHREAD, NULL, \ gcry_pthread_mutex_init, gcry_pthread_mutex_destroy, \ gcry_pthread_mutex_lock, gcry_pthread_mutex_unlock, \ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } /* The data object used to hold a multi precision integer. */ struct gcry_mpi; typedef struct gcry_mpi *gcry_mpi_t; typedef struct gcry_mpi *GCRY_MPI _GCRY_GCC_ATTR_DEPRECATED; typedef struct gcry_mpi *GcryMPI _GCRY_GCC_ATTR_DEPRECATED; /* Check that the library fulfills the version requirement. */ const char *gcry_check_version (const char *req_version); /* Codes for function dispatchers. */ /* Codes used with the gcry_control function. */ enum gcry_ctl_cmds { GCRYCTL_SET_KEY = 1, GCRYCTL_SET_IV = 2, GCRYCTL_CFB_SYNC = 3, GCRYCTL_RESET = 4, /* e.g. for MDs */ GCRYCTL_FINALIZE = 5, GCRYCTL_GET_KEYLEN = 6, GCRYCTL_GET_BLKLEN = 7, GCRYCTL_TEST_ALGO = 8, GCRYCTL_IS_SECURE = 9, GCRYCTL_GET_ASNOID = 10, GCRYCTL_ENABLE_ALGO = 11, GCRYCTL_DISABLE_ALGO = 12, GCRYCTL_DUMP_RANDOM_STATS = 13, GCRYCTL_DUMP_SECMEM_STATS = 14, GCRYCTL_GET_ALGO_NPKEY = 15, GCRYCTL_GET_ALGO_NSKEY = 16, GCRYCTL_GET_ALGO_NSIGN = 17, GCRYCTL_GET_ALGO_NENCR = 18, GCRYCTL_SET_VERBOSITY = 19, GCRYCTL_SET_DEBUG_FLAGS = 20, GCRYCTL_CLEAR_DEBUG_FLAGS = 21, GCRYCTL_USE_SECURE_RNDPOOL= 22, GCRYCTL_DUMP_MEMORY_STATS = 23, GCRYCTL_INIT_SECMEM = 24, GCRYCTL_TERM_SECMEM = 25, GCRYCTL_DISABLE_SECMEM_WARN = 27, GCRYCTL_SUSPEND_SECMEM_WARN = 28, GCRYCTL_RESUME_SECMEM_WARN = 29, GCRYCTL_DROP_PRIVS = 30, GCRYCTL_ENABLE_M_GUARD = 31, GCRYCTL_START_DUMP = 32, GCRYCTL_STOP_DUMP = 33, GCRYCTL_GET_ALGO_USAGE = 34, GCRYCTL_IS_ALGO_ENABLED = 35, GCRYCTL_DISABLE_INTERNAL_LOCKING = 36, GCRYCTL_DISABLE_SECMEM = 37, GCRYCTL_INITIALIZATION_FINISHED = 38, GCRYCTL_INITIALIZATION_FINISHED_P = 39, GCRYCTL_ANY_INITIALIZATION_P = 40, GCRYCTL_SET_CBC_CTS = 41, GCRYCTL_SET_CBC_MAC = 42, GCRYCTL_SET_CTR = 43, GCRYCTL_ENABLE_QUICK_RANDOM = 44, GCRYCTL_SET_RANDOM_SEED_FILE = 45, GCRYCTL_UPDATE_RANDOM_SEED_FILE = 46, GCRYCTL_SET_THREAD_CBS = 47, GCRYCTL_FAST_POLL = 48, GCRYCTL_SET_RANDOM_DAEMON_SOCKET = 49, GCRYCTL_USE_RANDOM_DAEMON = 50, GCRYCTL_FAKED_RANDOM_P = 51 }; /* Perform various operations defined by CMD. */ gcry_error_t gcry_control (enum gcry_ctl_cmds CMD, ...); /* S-expression management. */ /* The object to represent an S-expression as used with the public key functions. */ struct gcry_sexp; typedef struct gcry_sexp *gcry_sexp_t; typedef struct gcry_sexp *GCRY_SEXP _GCRY_GCC_ATTR_DEPRECATED; typedef struct gcry_sexp *GcrySexp _GCRY_GCC_ATTR_DEPRECATED; /* The possible values for the S-expression format. */ enum gcry_sexp_format { GCRYSEXP_FMT_DEFAULT = 0, GCRYSEXP_FMT_CANON = 1, GCRYSEXP_FMT_BASE64 = 2, GCRYSEXP_FMT_ADVANCED = 3 }; /* Create an new S-expression object from BUFFER of size LENGTH and return it in RETSEXP. With AUTODETECT set to 0 the data in BUFFER is expected to be in canonized format. */ gcry_error_t gcry_sexp_new (gcry_sexp_t *retsexp, const void *buffer, size_t length, int autodetect); /* Same as gcry_sexp_new but allows to pass a FREEFNC which has the effect to transfer ownership of BUFFER to the created object. */ gcry_error_t gcry_sexp_create (gcry_sexp_t *retsexp, void *buffer, size_t length, int autodetect, void (*freefnc) (void *)); /* Scan BUFFER and return a new S-expression object in RETSEXP. This function expects a printf like string in BUFFER. */ gcry_error_t gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff, const char *buffer, size_t length); /* Same as gcry_sexp_sscan but expects a string in FORMAT and can thus only be used for certain encodings. */ gcry_error_t gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff, const char *format, ...); /* Like gcry_sexp_build, but uses an array instead of variable function arguments. */ gcry_error_t gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff, const char *format, void **arg_list); /* Release the S-expression object SEXP */ void gcry_sexp_release (gcry_sexp_t sexp); /* Calculate the length of an canonized S-expresion in BUFFER and check for a valid encoding. */ size_t gcry_sexp_canon_len (const unsigned char *buffer, size_t length, size_t *erroff, gcry_error_t *errcode); /* Copies the S-expression object SEXP into BUFFER using the format specified in MODE. */ size_t gcry_sexp_sprint (gcry_sexp_t sexp, int mode, void *buffer, size_t maxlength); /* Dumps the S-expression object A in a aformat suitable for debugging to Libgcrypt's logging stream. */ void gcry_sexp_dump (const gcry_sexp_t a); gcry_sexp_t gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b); gcry_sexp_t gcry_sexp_alist (const gcry_sexp_t *array); gcry_sexp_t gcry_sexp_vlist (const gcry_sexp_t a, ...); gcry_sexp_t gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n); gcry_sexp_t gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n); /* Scan the S-expression for a sublist with a type (the car of the list) matching the string TOKEN. If TOKLEN is not 0, the token is assumed to be raw memory of this length. The function returns a newly allocated S-expression consisting of the found sublist or `NULL' when not found. */ gcry_sexp_t gcry_sexp_find_token (gcry_sexp_t list, const char *tok, size_t toklen); /* Return the length of the LIST. For a valid S-expression this should be at least 1. */ int gcry_sexp_length (const gcry_sexp_t list); /* Create and return a new S-expression from the element with index NUMBER in LIST. Note that the first element has the index 0. If there is no such element, `NULL' is returned. */ gcry_sexp_t gcry_sexp_nth (const gcry_sexp_t list, int number); /* Create and return a new S-expression from the first element in LIST; this called the "type" and should always exist and be a string. `NULL' is returned in case of a problem. */ gcry_sexp_t gcry_sexp_car (const gcry_sexp_t list); /* Create and return a new list form all elements except for the first one. Note, that this function may return an invalid S-expression because it is not guaranteed, that the type exists and is a string. However, for parsing a complex S-expression it might be useful for intermediate lists. Returns `NULL' on error. */ gcry_sexp_t gcry_sexp_cdr (const gcry_sexp_t list); gcry_sexp_t gcry_sexp_cadr (const gcry_sexp_t list); /* This function is used to get data from a LIST. A pointer to the actual data with index NUMBER is returned and the length of this data will be stored to DATALEN. If there is no data at the given index or the index represents another list, `NULL' is returned. *Note:* The returned pointer is valid as long as LIST is not modified or released. */ const char *gcry_sexp_nth_data (const gcry_sexp_t list, int number, size_t *datalen); /* This function is used to get and convert data from a LIST. This data is assumed to be an MPI stored in the format described by MPIFMT and returned as a standard Libgcrypt MPI. The caller must release this returned value using `gcry_mpi_release'. If there is no data at the given index, the index represents a list or the value can't be converted to an MPI, `NULL' is returned. */ gcry_mpi_t gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt); /******************************************* * * * multi precision integer functions * * * *******************************************/ /* Different formats of external big integer representation. */ enum gcry_mpi_format { GCRYMPI_FMT_NONE= 0, GCRYMPI_FMT_STD = 1, /* twos complement stored without length */ GCRYMPI_FMT_PGP = 2, /* As used by OpenPGP (only defined as unsigned)*/ GCRYMPI_FMT_SSH = 3, /* As used by SSH (same as 1 but with length)*/ GCRYMPI_FMT_HEX = 4, /* hex format */ GCRYMPI_FMT_USG = 5 /* like STD but this is an unsigned one */ }; /* Flags used for creating big integers. */ enum gcry_mpi_flag { GCRYMPI_FLAG_SECURE = 1, /* Allocate the number in "secure" memory. */ GCRYMPI_FLAG_OPAQUE = 2 /* The number is not a real one but just a way to store some bytes. This is useful for encrypted big integers. */ }; /* Allocate a new big integer object, initialize it with 0 and initially allocate memory for a number of at least NBITS. */ gcry_mpi_t gcry_mpi_new (unsigned int nbits); /* Same as gcry_mpi_new() but allocate in "secure" memory. */ gcry_mpi_t gcry_mpi_snew (unsigned int nbits); /* Release the number A and free all associated resources. */ void gcry_mpi_release (gcry_mpi_t a); /* Create a new number with the same value as A. */ gcry_mpi_t gcry_mpi_copy (const gcry_mpi_t a); /* Store the big integer value U in W. */ gcry_mpi_t gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u); /* Store the unsigned integer value U in W. */ gcry_mpi_t gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u); /* Swap the values of A and B. */ void gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b); /* Compare the big integer number U and V returning 0 for equality, a positive value for U > V and a negative for U < V. */ int gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v); /* Compare the big integer number U with the unsigned integer V returning 0 for equality, a positive value for U > V and a negative for U < V. */ int gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v); /* Convert the external representation of an integer stored in BUFFER with a length of BUFLEN into a newly create MPI returned in RET_MPI. If NSCANNED is not NULL, it will receive the number of bytes actually scanned after a successful operation. */ gcry_error_t gcry_mpi_scan (gcry_mpi_t *ret_mpi, enum gcry_mpi_format format, const void *buffer, size_t buflen, size_t *nscanned); /* Convert the big integer A into the external representation described by FORMAT and store it in the provided BUFFER which has been allocated by the user with a size of BUFLEN bytes. NWRITTEN receives the actual length of the external representation unless it has been passed as NULL. */ gcry_error_t gcry_mpi_print (enum gcry_mpi_format format, unsigned char *buffer, size_t buflen, size_t *nwritten, const gcry_mpi_t a); /* Convert the big integer A int the external representation described by FORMAT and store it in a newly allocated buffer which address will be put into BUFFER. NWRITTEN receives the actual lengths of the external representation. */ gcry_error_t gcry_mpi_aprint (enum gcry_mpi_format format, unsigned char **buffer, size_t *nwritten, const gcry_mpi_t a); /* Dump the value of A in a format suitable for debugging to Libgcrypt's logging stream. Note that one leading space but no trailing space or linefeed will be printed. It is okay to pass NULL for A. */ void gcry_mpi_dump (const gcry_mpi_t a); /* W = U + V. */ void gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); /* W = U + V. V is an unsigned integer. */ void gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v); /* W = U + V mod M. */ void gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); /* W = U - V. */ void gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); /* W = U - V. V is an unsigned integer. */ void gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v ); /* W = U - V mod M */ void gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); /* W = U * V. */ void gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); /* W = U * V. V is an unsigned integer. */ void gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v ); /* W = U * V mod M. */ void gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); /* W = U * (2 ^ CNT). */ void gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt); /* Q = DIVIDEND / DIVISOR, R = DIVIDEND % DIVISOR, Q or R may be passed as NULL. ROUND should be negative or 0. */ void gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor, int round); /* R = DIVIDEND % DIVISOR */ void gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor); /* W = B ^ E mod M. */ void gcry_mpi_powm (gcry_mpi_t w, const gcry_mpi_t b, const gcry_mpi_t e, const gcry_mpi_t m); /* Set G to the greatest common divisor of A and B. Return true if the G is 1. */ int gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b); /* Set X to the multiplicative inverse of A mod M. Return true if the value exists. */ int gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m); /* Return the number of bits required to represent A. */ unsigned int gcry_mpi_get_nbits (gcry_mpi_t a); /* Return true when bit number N (counting from 0) is set in A. */ int gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n); /* Set bit number N in A. */ void gcry_mpi_set_bit (gcry_mpi_t a, unsigned int n); /* Clear bit number N in A. */ void gcry_mpi_clear_bit (gcry_mpi_t a, unsigned int n); /* Set bit number N in A and clear all bits greater than N. */ void gcry_mpi_set_highbit (gcry_mpi_t a, unsigned int n); /* Clear bit number N in A and all bits greater than N. */ void gcry_mpi_clear_highbit (gcry_mpi_t a, unsigned int n); /* Shift the value of A by N bits to the right and store the result in X. */ void gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n); /* Store NBITS of the value P points to in A and mark A as an opaque value. WARNING: Never use an opaque MPI for anything thing else then gcry_mpi_release, gcry_mpi_get_opaque. */ gcry_mpi_t gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits); /* Return a pointer to an opaque value stored in A and return its size in NBITS. Note that the returned pointer is still owned by A and that the function should never be used for an non-opaque MPI. */ void *gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits); /* Set the FLAG for the big integer A. Currently only the flag GCRYMPI_FLAG_SECURE is allowed to convert A into an big intger stored in "secure" memory. */ void gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); /* Clear FLAG for the big integer A. Note that this function is currently useless as no flags are allowed. */ void gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); /* Return true when the FLAG is set for A. */ int gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); /* Unless the GCRYPT_NO_MPI_MACROS is used, provide a couple of convenience macors for the big integer functions. */ #ifndef GCRYPT_NO_MPI_MACROS #define mpi_new(n) gcry_mpi_new( (n) ) #define mpi_secure_new( n ) gcry_mpi_snew( (n) ) #define mpi_release(a) \ do \ { \ gcry_mpi_release ((a)); \ (a) = NULL; \ } \ while (0) #define mpi_copy( a ) gcry_mpi_copy( (a) ) #define mpi_set( w, u) gcry_mpi_set( (w), (u) ) #define mpi_set_ui( w, u) gcry_mpi_set_ui( (w), (u) ) #define mpi_cmp( u, v ) gcry_mpi_cmp( (u), (v) ) #define mpi_cmp_ui( u, v ) gcry_mpi_cmp_ui( (u), (v) ) #define mpi_add_ui(w,u,v) gcry_mpi_add_ui((w),(u),(v)) #define mpi_add(w,u,v) gcry_mpi_add ((w),(u),(v)) #define mpi_addm(w,u,v,m) gcry_mpi_addm ((w),(u),(v),(m)) #define mpi_sub_ui(w,u,v) gcry_mpi_sub_ui ((w),(u),(v)) #define mpi_sub(w,u,v) gcry_mpi_sub ((w),(u),(v)) #define mpi_subm(w,u,v,m) gcry_mpi_subm ((w),(u),(v),(m)) #define mpi_mul_ui(w,u,v) gcry_mpi_mul_ui ((w),(u),(v)) #define mpi_mul_2exp(w,u,v) gcry_mpi_mul_2exp ((w),(u),(v)) #define mpi_mul(w,u,v) gcry_mpi_mul ((w),(u),(v)) #define mpi_mulm(w,u,v,m) gcry_mpi_mulm ((w),(u),(v),(m)) #define mpi_powm(w,b,e,m) gcry_mpi_powm ( (w), (b), (e), (m) ) #define mpi_tdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), 0) #define mpi_fdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), -1) #define mpi_mod(r,a,m) gcry_mpi_mod ((r), (a), (m)) #define mpi_gcd(g,a,b) gcry_mpi_gcd ( (g), (a), (b) ) #define mpi_invm(g,a,b) gcry_mpi_invm ( (g), (a), (b) ) #define mpi_get_nbits(a) gcry_mpi_get_nbits ((a)) #define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b)) #define mpi_set_bit(a,b) gcry_mpi_set_bit ((a),(b)) #define mpi_set_highbit(a,b) gcry_mpi_set_highbit ((a),(b)) #define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b)) #define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b)) #define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c)) #define mpi_set_opaque(a,b,c) gcry_mpi_set_opaque( (a), (b), (c) ) #define mpi_get_opaque(a,b) gcry_mpi_get_opaque( (a), (b) ) #endif /* GCRYPT_NO_MPI_MACROS */ /************************************ * * * symmetric cipher functions * * * ************************************/ /* The data object used to hold a handle to an encryption object. */ struct gcry_cipher_handle; typedef struct gcry_cipher_handle *gcry_cipher_hd_t; typedef struct gcry_cipher_handle *GCRY_CIPHER_HD _GCRY_GCC_ATTR_DEPRECATED; typedef struct gcry_cipher_handle *GcryCipherHd _GCRY_GCC_ATTR_DEPRECATED; /* All symmetric encryption algorithms are identified by their IDs. More IDs may be registered at runtime. */ enum gcry_cipher_algos { GCRY_CIPHER_NONE = 0, GCRY_CIPHER_IDEA = 1, GCRY_CIPHER_3DES = 2, GCRY_CIPHER_CAST5 = 3, GCRY_CIPHER_BLOWFISH = 4, GCRY_CIPHER_SAFER_SK128 = 5, GCRY_CIPHER_DES_SK = 6, GCRY_CIPHER_AES = 7, GCRY_CIPHER_AES192 = 8, GCRY_CIPHER_AES256 = 9, GCRY_CIPHER_TWOFISH = 10, /* Other cipher numbers are above 300 for OpenPGP reasons. */ GCRY_CIPHER_ARCFOUR = 301, /* Fully compatible with RSA's RC4 (tm). */ GCRY_CIPHER_DES = 302, /* Yes, this is single key 56 bit DES. */ GCRY_CIPHER_TWOFISH128 = 303, GCRY_CIPHER_SERPENT128 = 304, GCRY_CIPHER_SERPENT192 = 305, GCRY_CIPHER_SERPENT256 = 306, GCRY_CIPHER_RFC2268_40 = 307, /* Ron's Cipher 2 (40 bit). */ GCRY_CIPHER_RFC2268_128 = 308, /* Ron's Cipher 2 (128 bit). */ GCRY_CIPHER_SEED = 309 /* 128 bit cipher described in RFC4269. */ }; /* The Rijndael algorithm is basically AES, so provide some macros. */ #define GCRY_CIPHER_AES128 GCRY_CIPHER_AES #define GCRY_CIPHER_RIJNDAEL GCRY_CIPHER_AES #define GCRY_CIPHER_RIJNDAEL128 GCRY_CIPHER_AES128 #define GCRY_CIPHER_RIJNDAEL192 GCRY_CIPHER_AES192 #define GCRY_CIPHER_RIJNDAEL256 GCRY_CIPHER_AES256 /* The supported encryption modes. Note that not all of them are supported for each algorithm. */ enum gcry_cipher_modes { GCRY_CIPHER_MODE_NONE = 0, /* Not yet specified. */ GCRY_CIPHER_MODE_ECB = 1, /* Electronic codebook. */ GCRY_CIPHER_MODE_CFB = 2, /* Cipher feedback. */ GCRY_CIPHER_MODE_CBC = 3, /* Cipher block chaining. */ GCRY_CIPHER_MODE_STREAM = 4, /* Used with stream ciphers. */ GCRY_CIPHER_MODE_OFB = 5, /* Outer feedback. */ GCRY_CIPHER_MODE_CTR = 6 /* Counter. */ }; /* Flags used with the open function. */ enum gcry_cipher_flags { GCRY_CIPHER_SECURE = 1, /* Allocate in secure memory. */ GCRY_CIPHER_ENABLE_SYNC = 2, /* Enable CFB sync mode. */ GCRY_CIPHER_CBC_CTS = 4, /* Enable CBC cipher text stealing (CTS). */ GCRY_CIPHER_CBC_MAC = 8 /* Enable CBC message auth. code (MAC). */ }; /* Create a handle for algorithm ALGO to be used in MODE. FLAGS may be given as an bitwise OR of the gcry_cipher_flags values. */ gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *handle, int algo, int mode, unsigned int flags); /* Close the cioher handle H and release all resource. */ void gcry_cipher_close (gcry_cipher_hd_t h); /* Perform various operations on the cipher object H. */ gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer, size_t buflen); /* Retrieve various information about the cipher object H. */ gcry_error_t gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer, size_t *nbytes); /* Retrieve various information about the cipher algorithm ALGO. */ gcry_error_t gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes); /* Map the cipher algorithm whose ID is contained in ALGORITHM to a string representation of the algorithm name. For unknown algorithm IDs this function returns "?". */ const char *gcry_cipher_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE; /* Map the algorithm name NAME to an cipher algorithm ID. Return 0 if the algorithm name is not known. */ int gcry_cipher_map_name (const char *name) _GCRY_GCC_ATTR_PURE; /* Given an ASN.1 object identifier in standard IETF dotted decimal format in STRING, return the encryption mode associated with that OID or 0 if not known or applicable. */ int gcry_cipher_mode_from_oid (const char *string) _GCRY_GCC_ATTR_PURE; /* Encrypt the plaintext of size INLEN in IN using the cipher handle H into the buffer OUT which has an allocated length of OUTSIZE. For most algorithms it is possible to pass NULL for in and 0 for INLEN and do a in-place decryption of the data provided in OUT. */ gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t h, void *out, size_t outsize, const void *in, size_t inlen); /* The counterpart to gcry_cipher_encrypt. */ gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t h, void *out, size_t outsize, const void *in, size_t inlen); /* Set key K of length L for the cipher handle H. (We have to cast away a const char* here - this catch-all ctl function was probably not the best choice) */ #define gcry_cipher_setkey(h,k,l) gcry_cipher_ctl( (h), GCRYCTL_SET_KEY, \ (char*)(k), (l) ) /* Set initialization vector K of length L for the cipher handle H. */ #define gcry_cipher_setiv(h,k,l) gcry_cipher_ctl( (h), GCRYCTL_SET_IV, \ (char*)(k), (l) ) /* Reset the handle to the state after open. */ #define gcry_cipher_reset(h) gcry_cipher_ctl ((h), GCRYCTL_RESET, NULL, 0) /* Perform the the OpenPGP sync operation if this is enabled for the cipher handle H. */ #define gcry_cipher_sync(h) gcry_cipher_ctl( (h), GCRYCTL_CFB_SYNC, \ NULL, 0 ) /* Enable or disable CTS in future calls to gcry_encrypt(). CBC mode only. */ #define gcry_cipher_cts(h,on) gcry_cipher_ctl( (h), GCRYCTL_SET_CBC_CTS, \ NULL, on ) /* Set counter for CTR mode. (K,L) must denote a buffer of block size length, or (NULL,0) to set the CTR to the all-zero block. */ #define gcry_cipher_setctr(h,k,l) gcry_cipher_ctl( (h), GCRYCTL_SET_CTR, \ (char*)(k), (l) ) /* Retrieved the key length used with algorithm A. */ size_t gcry_cipher_get_algo_keylen (int algo); /* Retrieve the block length used with algorithm A. */ size_t gcry_cipher_get_algo_blklen (int algo); /* Return 0 if the algorithm A is available for use. */ #define gcry_cipher_test_algo(a) \ gcry_cipher_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL ) /* Get a list consisting of the IDs of the loaded cipher modules. If LIST is zero, write the number of loaded cipher modules to LIST_LENGTH and return. If LIST is non-zero, the first *LIST_LENGTH algorithm IDs are stored in LIST, which must be of according size. In case there are less cipher modules than *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */ gcry_error_t gcry_cipher_list (int *list, int *list_length); /************************************ * * * asymmetric cipher functions * * * ************************************/ /* The algorithms and their IDs we support. */ enum gcry_pk_algos { GCRY_PK_RSA = 1, GCRY_PK_RSA_E = 2, /* deprecated */ GCRY_PK_RSA_S = 3, /* deprecated */ GCRY_PK_ELG_E = 16, /* use only for OpenPGP */ GCRY_PK_DSA = 17, GCRY_PK_ELG = 20 }; /* Flags describing usage capabilities of a PK algorithm. */ #define GCRY_PK_USAGE_SIGN 1 /* Good for signatures. */ #define GCRY_PK_USAGE_ENCR 2 /* Good for encryption. */ #define GCRY_PK_USAGE_CERT 4 /* Good to certify other keys. */ #define GCRY_PK_USAGE_AUTH 8 /* Good for authentication. */ #define GCRY_PK_USAGE_UNKN 128 /* Unknown usage flag. */ /* Encrypt the DATA using the public key PKEY and store the result as a newly created S-expression at RESULT. */ gcry_error_t gcry_pk_encrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t pkey); /* Decrypt the DATA using the private key SKEY and store the result as a newly created S-expression at RESULT. */ gcry_error_t gcry_pk_decrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey); /* Sign the DATA using the private key SKEY and store the result as a newly created S-expression at RESULT. */ gcry_error_t gcry_pk_sign (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey); /* Check the signature SIGVAL on DATA using the public key PKEY. */ gcry_error_t gcry_pk_verify (gcry_sexp_t sigval, gcry_sexp_t data, gcry_sexp_t pkey); /* Check that private KEY is sane. */ gcry_error_t gcry_pk_testkey (gcry_sexp_t key); /* Generate a new key pair according to the parameters given in S_PARMS. The new key pair is returned in as an S-expression in R_KEY. */ gcry_error_t gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms); /* Catch all function for miscellaneous operations. */ gcry_error_t gcry_pk_ctl (int cmd, void *buffer, size_t buflen); /* Retrieve information about the public key algorithm ALGO. */ gcry_error_t gcry_pk_algo_info (int algo, int what, void *buffer, size_t *nbytes); /* Map the public key algorithm whose ID is contained in ALGORITHM to a string representation of the algorithm name. For unknown algorithm IDs this functions returns "?". */ const char *gcry_pk_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE; /* Map the algorithm NAME to a public key algorithm Id. Return 0 if the algorithm name is not known. */ int gcry_pk_map_name (const char* name) _GCRY_GCC_ATTR_PURE; /* Return what is commonly referred as the key length for the given public or private KEY. */ unsigned int gcry_pk_get_nbits (gcry_sexp_t key) _GCRY_GCC_ATTR_PURE; /* Please note that keygrip is still experimental and should not be used without contacting the author. */ unsigned char *gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array); /* Return 0 if the public key algorithm A is available for use. */ #define gcry_pk_test_algo(a) \ gcry_pk_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL ) /* Get a list consisting of the IDs of the loaded pubkey modules. If LIST is zero, write the number of loaded pubkey modules to LIST_LENGTH and return. If LIST is non-zero, the first *LIST_LENGTH algorithm IDs are stored in LIST, which must be of according size. In case there are less pubkey modules than *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */ gcry_error_t gcry_pk_list (int *list, int *list_length); /************************************ * * * cryptograhic hash functions * * * ************************************/ /* Algorithm IDs for the hash functions we know about. Not all of them are implemnted. */ enum gcry_md_algos { GCRY_MD_NONE = 0, GCRY_MD_MD5 = 1, GCRY_MD_SHA1 = 2, GCRY_MD_RMD160 = 3, GCRY_MD_MD2 = 5, GCRY_MD_TIGER = 6, /* TIGER/192. */ GCRY_MD_HAVAL = 7, /* HAVAL, 5 pass, 160 bit. */ GCRY_MD_SHA256 = 8, GCRY_MD_SHA384 = 9, GCRY_MD_SHA512 = 10, GCRY_MD_SHA224 = 11, GCRY_MD_MD4 = 301, GCRY_MD_CRC32 = 302, GCRY_MD_CRC32_RFC1510 = 303, GCRY_MD_CRC24_RFC2440 = 304, GCRY_MD_WHIRLPOOL = 305 }; /* Flags used with the open function. */ enum gcry_md_flags { GCRY_MD_FLAG_SECURE = 1, /* Allocate all buffers in "secure" memory. */ GCRY_MD_FLAG_HMAC = 2 /* Make an HMAC out of this algorithm. */ }; /* Forward declaration. */ struct gcry_md_context; /* This object is used to hold a handle to a message digest object. This structure is private - only to be used by the public gcry_md_* macros. */ typedef struct gcry_md_handle { /* Actual context. */ struct gcry_md_context *ctx; /* Buffer management. */ int bufpos; int bufsize; unsigned char buf[1]; } *gcry_md_hd_t; /* Compatibility types, do not use them. */ typedef struct gcry_md_handle *GCRY_MD_HD _GCRY_GCC_ATTR_DEPRECATED; typedef struct gcry_md_handle *GcryMDHd _GCRY_GCC_ATTR_DEPRECATED; /* Create a message digest object for algorithm ALGO. FLAGS may be given as an bitwise OR of the gcry_md_flags values. ALGO may be given as 0 if the algorithms to be used are later set using gcry_md_enable. */ gcry_error_t gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags); /* Release the message digest object HD. */ void gcry_md_close (gcry_md_hd_t hd); /* Add the message digest algorithm ALGO to the digest object HD. */ gcry_error_t gcry_md_enable (gcry_md_hd_t hd, int algo); /* Create a new digest object as an exact copy of the object HD. */ gcry_error_t gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd); /* Reset the digest object HD to its initial state. */ void gcry_md_reset (gcry_md_hd_t hd); /* Perform various operations on the digest object HD. */ gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd, void *buffer, size_t buflen); /* Pass LENGTH bytes of data in BUFFER to the digest object HD so that it can update the digest values. This is the actual hash function. */ void gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length); /* Read out the final digest from HD return the digest value for algorithm ALGO. */ unsigned char *gcry_md_read (gcry_md_hd_t hd, int algo); /* Convenience function to calculate the hash from the data in BUFFER of size LENGTH using the algorithm ALGO avoiding the creating of a hash object. The hash is returned in the caller provided buffer DIGEST which must be large enough to hold the digest of the given algorithm. */ void gcry_md_hash_buffer (int algo, void *digest, const void *buffer, size_t length); /* Retrieve the algorithm used with HD. This does not work reliable if more than one algorithm is enabled in HD. */ int gcry_md_get_algo (gcry_md_hd_t hd); /* Retrieve the length in bytes of the digest yielded by algorithm ALGO. */ unsigned int gcry_md_get_algo_dlen (int algo); /* Return true if the the algorithm ALGO is enabled in the digest object A. */ int gcry_md_is_enabled (gcry_md_hd_t a, int algo); /* Return true if the digest object A is allocated in "secure" memory. */ int gcry_md_is_secure (gcry_md_hd_t a); /* Retrieve various information about the object H. */ gcry_error_t gcry_md_info (gcry_md_hd_t h, int what, void *buffer, size_t *nbytes); /* Retrieve various information about the algorithm ALGO. */ gcry_error_t gcry_md_algo_info (int algo, int what, void *buffer, size_t *nbytes); /* Map the digest algorithm id ALGO to a string representation of the - algorithm name. For unknown algorithms this functions returns an - empty string. */ + algorithm name. For unknown algorithms this functions returns + "?". */ const char *gcry_md_algo_name (int algo) _GCRY_GCC_ATTR_PURE; /* Map the algorithm NAME to a digest algorithm Id. Return 0 if the algorithm name is not known. */ int gcry_md_map_name (const char* name) _GCRY_GCC_ATTR_PURE; /* For use with the HMAC feature, the set MAC key to the KEY of KEYLEN. */ gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen); /* Start or stop debugging for digest handle HD; i.e. create a file named dbgmd-. while hashing. If SUFFIX is NULL, debugging stops and the file will be closed. */ void gcry_md_debug (gcry_md_hd_t hd, const char *suffix); /* Update the hash(s) of H with the character C. This is a buffered version of the gcry_md_write function. */ #define gcry_md_putc(h,c) \ do { \ gcry_md_hd_t h__ = (h); \ if( (h__)->bufpos == (h__)->bufsize ) \ gcry_md_write( (h__), NULL, 0 ); \ (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \ } while(0) /* Finalize the digest calculation. This is not really needed because gcry_md_read() does this implicitly. */ #define gcry_md_final(a) \ gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0) /* Return 0 if the algorithm A is available for use. */ #define gcry_md_test_algo(a) \ gcry_md_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL ) /* Return an DER encoded ASN.1 OID for the algorithm A in buffer B. N must point to size_t variable with the available size of buffer B. After return it will receive the actual size of the returned OID. */ #define gcry_md_get_asnoid(a,b,n) \ gcry_md_algo_info((a), GCRYCTL_GET_ASNOID, (b), (n)) /* Enable debugging for digest object A; i.e. create files named dbgmd-. while hashing. B is a string used as the suffix for the filename. This macro is deprecated, use gcry_md_debug. */ #define gcry_md_start_debug(a,b) \ gcry_md_ctl( (a), GCRYCTL_START_DUMP, (b), 0 ) /* Disable the debugging of A. This macro is deprecated, use gcry_md_debug. */ #define gcry_md_stop_debug(a,b) \ gcry_md_ctl( (a), GCRYCTL_STOP_DUMP, (b), 0 ) /* Get a list consisting of the IDs of the loaded message digest modules. If LIST is zero, write the number of loaded message digest modules to LIST_LENGTH and return. If LIST is non-zero, the first *LIST_LENGTH algorithm IDs are stored in LIST, which must be of according size. In case there are less message digest modules than *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */ gcry_error_t gcry_md_list (int *list, int *list_length); /* Alternative interface for asymetric cryptography. */ /* The algorithm IDs. */ typedef enum gcry_ac_id { GCRY_AC_RSA = 1, GCRY_AC_DSA = 17, GCRY_AC_ELG = 20, GCRY_AC_ELG_E = 16 } gcry_ac_id_t; /* Key types. */ typedef enum gcry_ac_key_type { GCRY_AC_KEY_SECRET, GCRY_AC_KEY_PUBLIC } gcry_ac_key_type_t; /* Encoding methods. */ typedef enum gcry_ac_em { GCRY_AC_EME_PKCS_V1_5, GCRY_AC_EMSA_PKCS_V1_5, } gcry_ac_em_t; /* Encryption and Signature schemes. */ typedef enum gcry_ac_scheme { GCRY_AC_ES_PKCS_V1_5, GCRY_AC_SSA_PKCS_V1_5, } gcry_ac_scheme_t; /* AC data. */ #define GCRY_AC_FLAG_DEALLOC (1 << 0) #define GCRY_AC_FLAG_COPY (1 << 1) #define GCRY_AC_FLAG_NO_BLINDING (1 << 2) /* This type represents a `data set'. */ typedef struct gcry_ac_data *gcry_ac_data_t; /* This type represents a single `key', either a secret one or a public one. */ typedef struct gcry_ac_key *gcry_ac_key_t; /* This type represents a `key pair' containing a secret and a public key. */ typedef struct gcry_ac_key_pair *gcry_ac_key_pair_t; /* This type represents a `handle' that is needed by functions performing cryptographic operations. */ typedef struct gcry_ac_handle *gcry_ac_handle_t; typedef gpg_error_t (*gcry_ac_data_read_cb_t) (void *opaque, unsigned char *buffer, size_t *buffer_n); typedef gpg_error_t (*gcry_ac_data_write_cb_t) (void *opaque, unsigned char *buffer, size_t buffer_n); typedef enum { GCRY_AC_IO_READABLE, GCRY_AC_IO_WRITABLE } gcry_ac_io_mode_t; typedef enum { GCRY_AC_IO_STRING, GCRY_AC_IO_CALLBACK } gcry_ac_io_type_t; typedef struct gcry_ac_io { /* This is an INTERNAL structure, do NOT use manually. */ gcry_ac_io_mode_t mode; gcry_ac_io_type_t type; union { union { struct { gcry_ac_data_read_cb_t cb; void *opaque; } callback; struct { unsigned char *data; size_t data_n; } string; void *opaque; } readable; union { struct { gcry_ac_data_write_cb_t cb; void *opaque; } callback; struct { unsigned char **data; size_t *data_n; } string; void *opaque; } writable; }; } gcry_ac_io_t; /* The caller of gcry_ac_key_pair_generate can provide one of these structures in order to influence the key generation process in an algorithm-specific way. */ typedef struct gcry_ac_key_spec_rsa { gcry_mpi_t e; /* E to use. */ } gcry_ac_key_spec_rsa_t; /* Structure used for passing data to the implementation of the `EME-PKCS-V1_5' encoding method. */ typedef struct gcry_ac_eme_pkcs_v1_5 { size_t key_size; } gcry_ac_eme_pkcs_v1_5_t; typedef enum gcry_md_algos gcry_md_algo_t; /* Structure used for passing data to the implementation of the `EMSA-PKCS-V1_5' encoding method. */ typedef struct gcry_ac_emsa_pkcs_v1_5 { gcry_md_algo_t md; size_t em_n; } gcry_ac_emsa_pkcs_v1_5_t; /* Structure used for passing data to the implementation of the `SSA-PKCS-V1_5' signature scheme. */ typedef struct gcry_ac_ssa_pkcs_v1_5 { gcry_md_algo_t md; } gcry_ac_ssa_pkcs_v1_5_t; /* Returns a new, empty data set in DATA. */ gcry_error_t gcry_ac_data_new (gcry_ac_data_t *data); /* Destroy the data set DATA. */ void gcry_ac_data_destroy (gcry_ac_data_t data); /* Create a copy of the data set DATA and store it in DATA_CP. */ gcry_error_t gcry_ac_data_copy (gcry_ac_data_t *data_cp, gcry_ac_data_t data); /* Return the number of named MPI values inside of the data set DATA. */ unsigned int gcry_ac_data_length (gcry_ac_data_t data); /* Destroy any values contained in the data set DATA. */ void gcry_ac_data_clear (gcry_ac_data_t data); /* Add the value MPI to DATA with the label NAME. If FLAGS contains GCRY_AC_FLAG_DATA_COPY, the data set will contain copies of NAME and MPI. If FLAGS contains GCRY_AC_FLAG_DATA_DEALLOC or GCRY_AC_FLAG_DATA_COPY, the values contained in the data set will be deallocated when they are to be removed from the data set. */ gcry_error_t gcry_ac_data_set (gcry_ac_data_t data, unsigned int flags, const char *name, gcry_mpi_t mpi); /* Store the value labelled with NAME found in DATA in MPI. If FLAGS contains GCRY_AC_FLAG_COPY, store a copy of the MPI value contained in the data set. MPI may be NULL. */ gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t data, unsigned int flags, const char *name, gcry_mpi_t *mpi); /* Stores in NAME and MPI the named MPI value contained in the data set DATA with the index IDX. If FLAGS contains GCRY_AC_FLAG_COPY, store copies of the values contained in the data set. NAME or MPI may be NULL. */ gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t data, unsigned int flags, unsigned int idx, const char **name, gcry_mpi_t *mpi); /* Convert the data set DATA into a new S-Expression, which is to be stored in SEXP, according to the identifiers contained in IDENTIFIERS. */ gcry_error_t gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp, const char **identifiers); /* Create a new data set, which is to be stored in DATA_SET, from the S-Expression SEXP, according to the identifiers contained in IDENTIFIERS. */ gcry_error_t gcry_ac_data_from_sexp (gcry_ac_data_t *data, gcry_sexp_t sexp, const char **identifiers); /* Initialize AC_IO according to MODE, TYPE and the variable list of arguments. The list of variable arguments to specify depends on the given TYPE. */ void gcry_ac_io_init (gcry_ac_io_t *ac_io, gcry_ac_io_mode_t mode, gcry_ac_io_type_t type, ...); /* Initialize AC_IO according to MODE, TYPE and the variable list of arguments AP. The list of variable arguments to specify depends on the given TYPE. */ void gcry_ac_io_init_va (gcry_ac_io_t *ac_io, gcry_ac_io_mode_t mode, gcry_ac_io_type_t type, va_list ap); /* Create a new ac handle. */ gcry_error_t gcry_ac_open (gcry_ac_handle_t *handle, gcry_ac_id_t algorithm, unsigned int flags); /* Destroy an ac handle. */ void gcry_ac_close (gcry_ac_handle_t handle); /* Initialize a key from a given data set. */ gcry_error_t gcry_ac_key_init (gcry_ac_key_t *key, gcry_ac_handle_t handle, gcry_ac_key_type_t type, gcry_ac_data_t data); /* Generates a new key pair via the handle HANDLE of NBITS bits and stores it in KEY_PAIR. In case non-standard settings are wanted, a pointer to a structure of type gcry_ac_key_spec__t, matching the selected algorithm, can be given as KEY_SPEC. MISC_DATA is not used yet. */ gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t handle, unsigned int nbits, void *spec, gcry_ac_key_pair_t *key_pair, gcry_mpi_t **misc_data); /* Returns the key of type WHICH out of the key pair KEY_PAIR. */ gcry_ac_key_t gcry_ac_key_pair_extract (gcry_ac_key_pair_t key_pair, gcry_ac_key_type_t which); /* Returns the data set contained in the key KEY. */ gcry_ac_data_t gcry_ac_key_data_get (gcry_ac_key_t key); /* Verifies that the key KEY is sane via HANDLE. */ gcry_error_t gcry_ac_key_test (gcry_ac_handle_t handle, gcry_ac_key_t key); /* Stores the number of bits of the key KEY in NBITS via HANDLE. */ gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t handle, gcry_ac_key_t key, unsigned int *nbits); /* Writes the 20 byte long key grip of the key KEY to KEY_GRIP via HANDLE. */ gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t handle, gcry_ac_key_t key, unsigned char *key_grip); /* Destroy a key. */ void gcry_ac_key_destroy (gcry_ac_key_t key); /* Destroy a key pair. */ void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t key_pair); /* Encodes a message according to the encoding method METHOD. OPTIONS must be a pointer to a method-specific structure (gcry_ac_em*_t). */ gcry_error_t gcry_ac_data_encode (gcry_ac_em_t method, unsigned int flags, void *options, gcry_ac_io_t *io_read, gcry_ac_io_t *io_write); /* Decodes a message according to the encoding method METHOD. OPTIONS must be a pointer to a method-specific structure (gcry_ac_em*_t). */ gcry_error_t gcry_ac_data_decode (gcry_ac_em_t method, unsigned int flags, void *options, gcry_ac_io_t *io_read, gcry_ac_io_t *io_write); /* Encrypt the plain text MPI value DATA_PLAIN with the key KEY under the control of the flags FLAGS and store the resulting data set into DATA_ENCRYPTED. */ gcry_error_t gcry_ac_data_encrypt (gcry_ac_handle_t handle, unsigned int flags, gcry_ac_key_t key, gcry_mpi_t data_plain, gcry_ac_data_t *data_encrypted); /* Decrypt the decrypted data contained in the data set DATA_ENCRYPTED with the key KEY under the control of the flags FLAGS and store the resulting plain text MPI value in DATA_PLAIN. */ gcry_error_t gcry_ac_data_decrypt (gcry_ac_handle_t handle, unsigned int flags, gcry_ac_key_t key, gcry_mpi_t *data_plain, gcry_ac_data_t data_encrypted); /* Sign the data contained in DATA with the key KEY and store the resulting signature in the data set DATA_SIGNATURE. */ gcry_error_t gcry_ac_data_sign (gcry_ac_handle_t handle, gcry_ac_key_t key, gcry_mpi_t data, gcry_ac_data_t *data_signature); /* Verify that the signature contained in the data set DATA_SIGNATURE is indeed the result of signing the data contained in DATA with the secret key belonging to the public key KEY. */ gcry_error_t gcry_ac_data_verify (gcry_ac_handle_t handle, gcry_ac_key_t key, gcry_mpi_t data, gcry_ac_data_t data_signature); /* Encrypts the plain text readable from IO_MESSAGE through HANDLE with the public key KEY according to SCHEME, FLAGS and OPTS. If OPTS is not NULL, it has to be a pointer to a structure specific to the chosen scheme (gcry_ac_es_*_t). The encrypted message is written to IO_CIPHER. */ gcry_error_t gcry_ac_data_encrypt_scheme (gcry_ac_handle_t handle, gcry_ac_scheme_t scheme, unsigned int flags, void *opts, gcry_ac_key_t key, gcry_ac_io_t *io_message, gcry_ac_io_t *io_cipher); /* Decrypts the cipher text readable from IO_CIPHER through HANDLE with the secret key KEY according to SCHEME, @var{flags} and OPTS. If OPTS is not NULL, it has to be a pointer to a structure specific to the chosen scheme (gcry_ac_es_*_t). The decrypted message is written to IO_MESSAGE. */ gcry_error_t gcry_ac_data_decrypt_scheme (gcry_ac_handle_t handle, gcry_ac_scheme_t scheme, unsigned int flags, void *opts, gcry_ac_key_t key, gcry_ac_io_t *io_cipher, gcry_ac_io_t *io_message); /* Signs the message readable from IO_MESSAGE through HANDLE with the secret key KEY according to SCHEME, FLAGS and OPTS. If OPTS is not NULL, it has to be a pointer to a structure specific to the chosen scheme (gcry_ac_ssa_*_t). The signature is written to IO_SIGNATURE. */ gcry_error_t gcry_ac_data_sign_scheme (gcry_ac_handle_t handle, gcry_ac_scheme_t scheme, unsigned int flags, void *opts, gcry_ac_key_t key, gcry_ac_io_t *io_message, gcry_ac_io_t *io_signature); /* Verifies through HANDLE that the signature readable from IO_SIGNATURE is indeed the result of signing the message readable from IO_MESSAGE with the secret key belonging to the public key KEY according to SCHEME and OPTS. If OPTS is not NULL, it has to be an anonymous structure (gcry_ac_ssa_*_t) specific to the chosen scheme. */ gcry_error_t gcry_ac_data_verify_scheme (gcry_ac_handle_t handle, gcry_ac_scheme_t scheme, unsigned int flags, void *opts, gcry_ac_key_t key, gcry_ac_io_t *io_message, gcry_ac_io_t *io_signature); /* Store the textual representation of the algorithm whose id is given - in ALGORITHM in NAME. */ + in ALGORITHM in NAME. This function is deprecated; use + gcry_pk_algo_name. */ gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t algorithm, - const char **name); - + const char **name) _GCRY_GCC_ATTR_DEPRECATED; /* Store the numeric ID of the algorithm whose textual representation - is contained in NAME in ALGORITHM. */ + is contained in NAME in ALGORITHM. This function is deprecated; + use gcry_pk_map_name. */ gcry_error_t gcry_ac_name_to_id (const char *name, - gcry_ac_id_t *algorithm); + gcry_ac_id_t *algorithm + ) _GCRY_GCC_ATTR_DEPRECATED;; /************************************ * * * random generating functions * * * ************************************/ /* The possible values for the random quality. The rule of thumb is to use STRONG for session keys and VERY_STRONG for key material. WEAK is currently an alias for STRONG and should not be used anymore - use gcry_create_nonce instead. */ typedef enum gcry_random_level { GCRY_WEAK_RANDOM = 0, GCRY_STRONG_RANDOM = 1, GCRY_VERY_STRONG_RANDOM = 2 } gcry_random_level_t; /* Fill BUFFER with LENGTH bytes of random, using random numbers of quality LEVEL. */ void gcry_randomize (void *buffer, size_t length, enum gcry_random_level level); /* Add the external random from BUFFER with LENGTH bytes into the pool. QUALITY should either be -1 for unknown or in the range of 0 to 100 */ gcry_error_t gcry_random_add_bytes (const void *buffer, size_t length, int quality); /* If random numbers are used in an application, this macro should be called from time to time so that new stuff gets added to the internal pool of the RNG. */ #define gcry_fast_random_poll() gcry_control (GCRYCTL_FAST_POLL, NULL) /* Return NBYTES of allocated random using a random numbers of quality LEVEL. */ void *gcry_random_bytes (size_t nbytes, enum gcry_random_level level) _GCRY_GCC_ATTR_MALLOC; /* Return NBYTES of allocated random using a random numbers of quality LEVEL. The random numbers are created returned in "secure" memory. */ void *gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level) _GCRY_GCC_ATTR_MALLOC; /* Set the big integer W to a random value of NBITS using a random generator with quality LEVEL. */ void gcry_mpi_randomize (gcry_mpi_t w, unsigned int nbits, enum gcry_random_level level); /* Create an unpredicable nonce of LENGTH bytes in BUFFER. */ void gcry_create_nonce (void *buffer, size_t length); /* Prime interface. */ /* Mode values passed to a gcry_prime_check_func_t. */ #define GCRY_PRIME_CHECK_AT_FINISH 0 #define GCRY_PRIME_CHECK_AT_GOT_PRIME 1 #define GCRY_PRIME_CHECK_AT_MAYBE_PRIME 2 /* The function should return 1 if the operation shall continue, 0 to reject the prime candidate. */ typedef int (*gcry_prime_check_func_t) (void *arg, int mode, gcry_mpi_t candidate); /* Flags for gcry_prime_generate(): */ /* Allocate prime numbers and factors in secure memory. */ #define GCRY_PRIME_FLAG_SECRET (1 << 0) /* Make sure that at least one prime factor is of size `FACTOR_BITS'. */ #define GCRY_PRIME_FLAG_SPECIAL_FACTOR (1 << 1) /* Generate a new prime number of PRIME_BITS bits and store it in PRIME. If FACTOR_BITS is non-zero, one of the prime factors of (prime - 1) / 2 must be FACTOR_BITS bits long. If FACTORS is non-zero, allocate a new, NULL-terminated array holding the prime factors and store it in FACTORS. FLAGS might be used to influence the prime number generation process. */ gcry_error_t gcry_prime_generate (gcry_mpi_t *prime, unsigned int prime_bits, unsigned int factor_bits, gcry_mpi_t **factors, gcry_prime_check_func_t cb_func, void *cb_arg, gcry_random_level_t random_level, unsigned int flags); /* Find a generator for PRIME where the factorization of (prime-1) is in the NULL terminated array FACTORS. Return the generator as a newly allocated MPI in R_G. If START_G is not NULL, use this as teh start for the search. */ gcry_error_t gcry_prime_group_generator (gcry_mpi_t *r_g, gcry_mpi_t prime, gcry_mpi_t *factors, gcry_mpi_t start_g); /* Convenience function to release the FACTORS array. */ void gcry_prime_release_factors (gcry_mpi_t *factors); /* Check wether the number X is prime. */ gcry_error_t gcry_prime_check (gcry_mpi_t x, unsigned int flags); /************************************ * * * miscellaneous stuff * * * ************************************/ /* Log levels used by the internal logging facility. */ enum gcry_log_levels { GCRY_LOG_CONT = 0, /* continue the last log line */ GCRY_LOG_INFO = 10, GCRY_LOG_WARN = 20, GCRY_LOG_ERROR = 30, GCRY_LOG_FATAL = 40, GCRY_LOG_BUG = 50, GCRY_LOG_DEBUG = 100 }; /* Type for progress handlers. */ typedef void (*gcry_handler_progress_t) (void *, const char *, int, int, int); /* Type for memory allocation handlers. */ typedef void *(*gcry_handler_alloc_t) (size_t n); /* Type for secure memory check handlers. */ typedef int (*gcry_handler_secure_check_t) (const void *); /* Type for memory reallocation handlers. */ typedef void *(*gcry_handler_realloc_t) (void *p, size_t n); /* Type for memory free handlers. */ typedef void (*gcry_handler_free_t) (void *); /* Type for out-of-memory handlers. */ typedef int (*gcry_handler_no_mem_t) (void *, size_t, unsigned int); /* Type for fatal error handlers. */ typedef void (*gcry_handler_error_t) (void *, int, const char *); /* Type for logging handlers. */ typedef void (*gcry_handler_log_t) (void *, int, const char *, va_list); /* Certain operations can provide progress information. This function is used to register a handler for retrieving these information. */ void gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data); /* Register a custom memory allocation functions. */ void gcry_set_allocation_handler ( gcry_handler_alloc_t func_alloc, gcry_handler_alloc_t func_alloc_secure, gcry_handler_secure_check_t func_secure_check, gcry_handler_realloc_t func_realloc, gcry_handler_free_t func_free); /* Register a function used instead of the internal out of memory handler. */ void gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque); /* Register a function used instead of the internal fatal error handler. */ void gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque); /* Register a function used instead of the internal logging facility. */ void gcry_set_log_handler (gcry_handler_log_t f, void *opaque); /* Reserved for future use. */ void gcry_set_gettext_handler (const char *(*f)(const char*)); /* Libgcrypt uses its own memory allocation. It is important to use gcry_free () to release memory allocated by libgcrypt. */ void *gcry_malloc (size_t n) _GCRY_GCC_ATTR_MALLOC; void *gcry_calloc (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC; void *gcry_malloc_secure (size_t n) _GCRY_GCC_ATTR_MALLOC; void *gcry_calloc_secure (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC; void *gcry_realloc (void *a, size_t n); char *gcry_strdup (const char *string) _GCRY_GCC_ATTR_MALLOC; void *gcry_xmalloc (size_t n) _GCRY_GCC_ATTR_MALLOC; void *gcry_xcalloc (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC; void *gcry_xmalloc_secure (size_t n) _GCRY_GCC_ATTR_MALLOC; void *gcry_xcalloc_secure (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC; void *gcry_xrealloc (void *a, size_t n); char *gcry_xstrdup (const char * a) _GCRY_GCC_ATTR_MALLOC; void gcry_free (void *a); /* Return true if A is allocated in "secure" memory. */ int gcry_is_secure (const void *a) _GCRY_GCC_ATTR_PURE; /* Include support for Libgcrypt modules. */ #include #if 0 /* keep Emacsens' auto-indent happy */ { #endif #ifdef __cplusplus } #endif #endif /* _GCRYPT_H */ diff --git a/src/libgcrypt-config.in b/src/libgcrypt-config.in index eac12aa2..be6df8ac 100644 --- a/src/libgcrypt-config.in +++ b/src/libgcrypt-config.in @@ -1,163 +1,177 @@ #!/bin/sh # Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc. # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # This file is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# File: @configure_input@ # General. prefix="@prefix@" exec_prefix="@exec_prefix@" version="@VERSION@" includedir="@includedir@" libdir="@libdir@" gpg_error_libs="@GPG_ERROR_LIBS@" gpg_error_cflags="@GPG_ERROR_CFLAGS@" # libgcrypt values. libs="@LIBGCRYPT_CONFIG_LIBS@" cflags="@LIBGCRYPT_CONFIG_CFLAGS@" # API info api_version="@LIBGCRYPT_CONFIG_API_VERSION@" # Misc information. symmetric_ciphers="@LIBGCRYPT_CIPHERS@" asymmetric_ciphers="@LIBGCRYPT_PUBKEY_CIPHERS@" digests="@LIBGCRYPT_DIGESTS@" # State variables. echo_libs=no echo_cflags=no echo_prefix=no echo_algorithms=no echo_exec_prefix=no echo_version=no echo_api_version=no # Prints usage information. usage() { cat <&2 fi while test $# -gt 0; do case "$1" in # Set up `optarg'. --*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) optarg="" ;; esac case $1 in --thread=*) echo "$0: --thread option obsolete: use the thread callback interface" 1>&2 - # exit 1 <-- enable this for 1.2.0. + exit 1 ;; --prefix=*) # For compatibility reasons with old M4 macros, we ignore # setting of prefix. ;; --prefix) echo_prefix=yes ;; --exec-prefix=*) ;; --exec-prefix) echo_exec_prefix=yes ;; --version) echo_version=yes ;; --api-version) echo_api_version=yes ;; --cflags) echo_cflags=yes ;; --libs) echo_libs=yes ;; --algorithms) echo_algorithms=yes ;; *) usage 1 1>&2 ;; esac shift done if test "$echo_prefix" = "yes"; then echo "$prefix" fi if test "$echo_exec_prefix" = "yes"; then echo "$exec_prefix" fi if test "$echo_cflags" = "yes"; then includes="" cflags_final="$cflags" # Set up `includes'. if test "x$includedir" != "x/usr/include" -a "x$includedir" != "x/include"; then includes="-I$includedir" fi # Set up `cflags_final'. cflags_final="$cflags_final $gpg_error_cflags" - echo "$includes $cflags_final" + tmp="" + for i in $includes $cflags_final; do + if echo "$tmp" | fgrep -v -- "$i" >/dev/null; then + tmp="$tmp $i" + fi + done + echo $tmp fi if test "$echo_libs" = "yes"; then libdirs="" libs_final="$libs" # Set up `libdirs'. if test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/lib"; then libdirs="-L$libdir" fi # Set up `libs_final'. libs_final="$libs_final $gpg_error_libs" - echo "$libdirs $libs_final" + tmp="" + for i in $libdirs $libs_final; do + if echo "$tmp" | fgrep -v -- "$i" >/dev/null; then + tmp="$tmp $i" + fi + done + echo $tmp fi if test "$echo_version" = "yes"; then echo "$version" fi if test "$echo_api_version" = "yes"; then echo "$api_version" fi if test "$echo_algorithms" = "yes"; then echo "Symmetric cipher algorithms: $symmetric_ciphers" echo "Public-key cipher algorithms: $asymmetric_ciphers" echo "Message digest algorithms: $digests" fi diff --git a/src/libgcrypt.def b/src/libgcrypt.def index eb82fe77..7c2adcee 100644 --- a/src/libgcrypt.def +++ b/src/libgcrypt.def @@ -1,206 +1,226 @@ ;; libgcrypt.defs - Exported symbols for W32 -;; Copyright (C) 2003 Free Software Foundation, Inc. +;; Copyright (C) 2003, 2007 Free Software Foundation, Inc. ;; ;; This file is part of Libgcrypt. ;; ;; Libgcrypt is free software; you can redistribute it and/or modify ;; it under the terms of the GNU Lesser General Public License as ;; published by the Free Software Foundation; either version 2.1 of ;; the License, or (at your option) any later version. ;; ;; Libgcrypt is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU Lesser General Public License for more details. ;; ;; You should have received a copy of the GNU Lesser General Public ;; License along with this program; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA ;; ;; Note: This file should be updated manually and the ordinals shall ;; never be changed. EXPORTS gcry_check_version @1 gcry_control @2 gcry_malloc @3 gcry_calloc @4 gcry_malloc_secure @5 gcry_calloc_secure @6 gcry_realloc @7 gcry_strdup @8 gcry_xmalloc @9 gcry_xcalloc @10 gcry_xmalloc_secure @11 gcry_xcalloc_secure @12 gcry_xrealloc @13 gcry_xstrdup @14 gcry_is_secure @15 gcry_free @16 gcry_set_progress_handler @17 gcry_set_allocation_handler @18 gcry_set_outofcore_handler @19 gcry_set_fatalerror_handler @20 gcry_set_log_handler @21 gcry_set_gettext_handler @22 gcry_strerror @23 gcry_strsource @24 gcry_err_code_from_errno @25 gcry_err_code_to_errno @26 gcry_err_make_from_errno @27 gcry_error_from_errno @28 gcry_sexp_new @29 gcry_sexp_create @30 gcry_sexp_sscan @31 gcry_sexp_build @32 gcry_sexp_build_array @33 gcry_sexp_release @34 gcry_sexp_canon_len @35 gcry_sexp_sprint @36 gcry_sexp_dump @37 gcry_sexp_cons @38 gcry_sexp_alist @39 gcry_sexp_vlist @40 gcry_sexp_append @41 gcry_sexp_prepend @42 gcry_sexp_find_token @43 gcry_sexp_length @44 gcry_sexp_nth @45 gcry_sexp_car @46 gcry_sexp_cdr @47 gcry_sexp_cadr @48 gcry_sexp_nth_data @49 gcry_sexp_nth_mpi @50 gcry_mpi_new @51 gcry_mpi_snew @52 gcry_mpi_release @53 gcry_mpi_copy @54 gcry_mpi_set @55 gcry_mpi_set_ui @56 gcry_mpi_swap @57 gcry_mpi_cmp @58 gcry_mpi_cmp_ui @59 gcry_mpi_scan @60 gcry_mpi_print @61 gcry_mpi_aprint @62 gcry_mpi_dump @63 gcry_mpi_add @64 gcry_mpi_add_ui @65 gcry_mpi_addm @66 gcry_mpi_sub @67 gcry_mpi_sub_ui @68 gcry_mpi_subm @69 gcry_mpi_mul @70 gcry_mpi_mul_ui @71 gcry_mpi_mulm @72 gcry_mpi_mul_2exp @73 gcry_mpi_div @74 gcry_mpi_mod @75 gcry_mpi_powm @76 gcry_mpi_gcd @77 gcry_mpi_invm @78 gcry_mpi_get_nbits @79 gcry_mpi_test_bit @80 gcry_mpi_set_bit @81 gcry_mpi_clear_bit @82 gcry_mpi_set_highbit @83 gcry_mpi_clear_highbit @84 gcry_mpi_rshift @85 gcry_mpi_set_opaque @86 gcry_mpi_get_opaque @87 gcry_mpi_set_flag @88 gcry_mpi_clear_flag @89 gcry_mpi_get_flag @90 gcry_cipher_open @92 gcry_cipher_close @93 gcry_cipher_ctl @94 gcry_cipher_info @95 gcry_cipher_algo_info @96 gcry_cipher_algo_name @97 gcry_cipher_map_name @98 gcry_cipher_mode_from_oid @99 gcry_cipher_encrypt @100 gcry_cipher_decrypt @101 gcry_cipher_get_algo_keylen @102 gcry_cipher_get_algo_blklen @103 gcry_cipher_list @104 gcry_pk_encrypt @105 gcry_pk_decrypt @106 gcry_pk_sign @107 gcry_pk_verify @108 gcry_pk_testkey @109 gcry_pk_genkey @110 gcry_pk_ctl @111 gcry_pk_algo_info @112 gcry_pk_algo_name @113 gcry_pk_map_name @114 gcry_pk_get_nbits @115 gcry_pk_get_keygrip @116 gcry_pk_list @117 gcry_ac_data_new @118 gcry_ac_data_destroy @119 gcry_ac_data_set @120 gcry_ac_data_copy @121 gcry_ac_data_length @122 gcry_ac_data_get_name @123 gcry_ac_data_get_index @124 gcry_ac_data_clear @125 gcry_ac_open @126 gcry_ac_close @127 gcry_ac_key_init @128 gcry_ac_key_pair_generate @129 gcry_ac_key_pair_extract @130 gcry_ac_key_data_get @131 gcry_ac_key_test @132 gcry_ac_key_get_nbits @133 gcry_ac_key_get_grip @134 gcry_ac_key_destroy @135 gcry_ac_key_pair_destroy @136 gcry_ac_data_encrypt @137 gcry_ac_data_decrypt @138 gcry_ac_data_sign @139 gcry_ac_data_verify @140 gcry_ac_id_to_name @141 gcry_ac_name_to_id @142 gcry_md_open @143 gcry_md_close @144 gcry_md_enable @145 gcry_md_copy @146 gcry_md_reset @147 gcry_md_ctl @148 gcry_md_write @149 gcry_md_read @150 gcry_md_hash_buffer @151 gcry_md_get_algo @152 gcry_md_get_algo_dlen @153 gcry_md_is_enabled @154 gcry_md_is_secure @155 gcry_md_info @156 gcry_md_algo_info @157 gcry_md_algo_name @158 gcry_md_map_name @159 gcry_md_setkey @160 gcry_md_list @161 gcry_randomize @162 gcry_random_add_bytes @163 gcry_random_bytes @164 gcry_random_bytes_secure @165 gcry_mpi_randomize @166 gcry_prime_generate @167 gcry_prime_group_generator @168 gcry_prime_release_factors @169 gcry_prime_check @170 + + gcry_create_nonce @171 + + gcry_md_debug @172 + + gcry_cipher_register @173 + gcry_cipher_unregister @174 + gcry_md_register @175 + gcry_md_unregister @176 + gcry_pk_register @177 + gcry_pk_unregister @178 + + gcry_ac_data_from_sexp @179 + gcry_ac_data_to_sexp @180 + gcry_ac_io_init @181 + gcry_ac_io_init_va @182 + gcry_ac_data_encrypt_scheme @183 + gcry_ac_data_decrypt_scheme @184 + gcry_ac_data_sign_scheme @185 + gcry_ac_data_verify_scheme @186 diff --git a/src/missing-string.c b/src/missing-string.c index 80ff0521..5e43b2a8 100644 --- a/src/missing-string.c +++ b/src/missing-string.c @@ -1,151 +1,152 @@ /* missing-string.c - missing string utilities * Copyright (C) 1994, 1998, 1999, 2000, 2001, * 2003 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include +#include #include #include #include #include "g10lib.h" #ifndef HAVE_STPCPY char * stpcpy(char *a,const char *b) { while( *b ) *a++ = *b++; *a = 0; return (char*)a; } #endif #ifndef HAVE_STRCASECMP int strcasecmp( const char *a, const char *b ) { for( ; *a && *b; a++, b++ ) { if( *a != *b && toupper(*a) != toupper(*b) ) break; } return *(const byte*)a - *(const byte*)b; } #endif #ifdef __MINGW32__ /* * Like vsprintf but provides a pointer to malloc'd storage, which * must be freed by the caller (gcry_free). Taken from libiberty as * found in gcc-2.95.2 and a little bit modernized. * FIXME: Write a new CRT for W32. */ int vasprintf ( char **result, const char *format, va_list args) { const char *p = format; /* Add one to make sure that it is never zero, which might cause malloc to return NULL. */ int total_width = strlen (format) + 1; va_list ap; /* this is not really portable but works under Windows */ memcpy ( &ap, &args, sizeof (va_list)); while (*p != '\0') { if (*p++ == '%') { while (strchr ("-+ #0", *p)) ++p; if (*p == '*') { ++p; total_width += abs (va_arg (ap, int)); } else { char *endp; total_width += strtoul (p, &endp, 10); p = endp; } if (*p == '.') { ++p; if (*p == '*') { ++p; total_width += abs (va_arg (ap, int)); } else { char *endp; total_width += strtoul (p, &endp, 10); p = endp; } } while (strchr ("hlL", *p)) ++p; /* Should be big enough for any format specifier except %s and floats. */ total_width += 30; switch (*p) { case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': case 'c': (void) va_arg (ap, int); break; case 'f': case 'e': case 'E': case 'g': case 'G': (void) va_arg (ap, double); /* Since an ieee double can have an exponent of 307, we'll make the buffer wide enough to cover the gross case. */ total_width += 307; case 's': total_width += strlen (va_arg (ap, char *)); break; case 'p': case 'n': (void) va_arg (ap, char *); break; } } } *result = gcry_malloc (total_width); if (*result != NULL) return vsprintf (*result, format, args); else return 0; } #endif /*__MINGW32__*/ diff --git a/src/versioninfo.rc.in b/src/versioninfo.rc.in index 53905139..da86b97b 100644 --- a/src/versioninfo.rc.in +++ b/src/versioninfo.rc.in @@ -1,52 +1,53 @@ /* versioninfo.rc.in - for libgcrypt * Copyright (C) 2005, 2006 g10 Code GmbH * * This file is free software; as a special exception the author gives * unlimited permission to copy and/or distribute it, with or without * modifications, as long as this notice is preserved. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* This file is processed by configure to create versioninfo.rc */ #line __LINE__ "versioninfo.rc.in" #include VS_VERSION_INFO VERSIONINFO FILEVERSION @LIBGCRYPT_LT_CURRENT@,@LIBGCRYPT_LT_AGE@,@LIBGCRYPT_LT_REVISION@,@BUILD_REVISION@ PRODUCTVERSION @BUILD_FILEVERSION@ FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x21L #else FILEFLAGS 0x20L #endif FILEOS 0x40004L FILETYPE 0x1L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN - VALUE "Comments", "Provided under the terms of the GNU Lesser General Public License.\0" + /* Note that the Windows versioin falls under the GPL. */ + VALUE "Comments", "Provided under the terms of the GNU General Public License.\0" VALUE "CompanyName", "g10 Code GmbH\0" - VALUE "FileDescription", "libgcrypt - The GNU crypto library\0" + VALUE "FileDescription", "Libgcrypt - The GNU Crypto Library\0" VALUE "FileVersion", "@LIBGCRYPT_LT_CURRENT@.@LIBGCRYPT_LT_AGE@.@LIBGCRYPT_LT_REVISION@.@BUILD_REVISION@\0" VALUE "InternalName", "libgcrypt\0" - VALUE "LegalCopyright", "Copyright © 2005, 2006 g10 Code GmbH\0" + VALUE "LegalCopyright", "Copyright © 2007 Free Software Foundation, Inc.\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "libgcrypt.dll\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "libgcrypt\0" VALUE "ProductVersion", "@VERSION@\0" VALUE "SpecialBuild", "@BUILD_TIMESTAMP@\0" END END END diff --git a/tests/ChangeLog b/tests/ChangeLog index 8e619fd4..4dd2da24 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,432 +1,437 @@ +2007-02-22 Werner Koch + + * Makefile.am (TESTS) [W32]: Removed pkbench for now. + * pkbench.c (benchmark): Fixed for W32. + 2007-02-21 Werner Koch * hmac.c (check_one_mac): Make pointer args const. * basic.c (check_one_md): Ditto. (check_one_hmac): Ditto. * keygen.c (progress_cb): Filter out line feeds. * basic.c (progress_handler): Ditto. 2006-12-18 Werner Koch * Makefile.am (AM_CFLAGS, AM_CPPFLAGS): Splitted and merged with Moritz' changes. (INCLUDES): Removed. * keygen.c (progress_handler): New. (main): Use it in verbose mode. 2006-11-05 Moritz Schulte * Makefile.am (AM_CFLAGS): Added -I$(top_builddir)/src so that the new gcrypt.h is used, not the one installed in the system. 2006-10-17 Werner Koch * keygen.c (check_rsa_keys): Also create an 1536 bit DSA key. 2006-08-03 Werner Koch * t-mpi-bit.c: New. 2006-07-06 Werner Koch * benchmark.c (main): New option --use-random-daemon. New command strongrandom. (random_bench): New arg VERY_STRONG. 2006-03-14 Werner Koch * benchmark.c (main): Allow for seed file argument to random bench. * basic.c (main): Use progress handler only in verbose mode. (main): Speed up test key generation. * ac-data.c (check_sexp_conversion, check_run): Take care of VERBOSE. * ac.c (main): Ditto. * pubkey.c (main): Ditto. * pkbench.c (main): Ditto. * keygen.c (main): Ditto. (check_rsa_keys): Print key only in verbose mode. 2006-03-10 Brad Hards (wk, patch 2006-02-18) * basic.c (check_one_hmac, check_hmac): New. 2006-03-07 Werner Koch * benchmark.c (cipher_bench): Add OFB mode. 2006-01-18 Brad Hards (wk 2006-03-07) * basic.c: Added test cases for OFB and CFB modes. Fixed some compiler warnings for signedness. 2005-11-12 Moritz Schulte * ac-data.c: Added way more test cases. 2005-09-15 Moritz Schulte * Makefile.am (TESTS): Added keygrip. * keygrip.c: New. 2005-09-19 Werner Koch * benchmark.c (dsa_bench): New. 2005-08-19 Werner Koch * hmac.c (main): Added all FIPS tests. 2005-08-18 Werner Koch * hmac.c: New. 2005-04-22 Moritz Schulte * tsexp.c: Include in case HAVE_CONFIG_H is defined; thanks to Albert Chin. * testapi.c: Likewise. * register.c: Likewise. * pubkey.c: Likewise. * prime.c: Likewise. * pkbench.c: Likewise. * keygen.c: Likewise. * benchmark.c: Likewise. * basic.c: Likewise. * ac-schemes.c: Likewise. * ac-data.c: Likewise. * ac.c: Likewise. 2005-04-16 Moritz Schulte * ac-data.c (check_run): Include new test. 2005-04-11 Moritz Schulte * basic.c (check_digests): Add tests for Whirlpool. 2005-03-30 Moritz Schulte * ac-schemes.c: New file. * ac-data.c: New file. * Makefile.am (TESTS): Added ac-schemes and ac-data. 2004-09-15 Moritz Schulte * pkbench.c: Include . 2004-08-24 Moritz Schulte * pkbench.c (context_init): Improve generation of test data. 2004-08-23 Moritz Schulte * Makefile.am (TESTS): Added: pkbench. * pkbench.c: New file. 2004-02-25 Werner Koch * Makefile.am (TEST): Add benchmark. * benchmark.c (md_bench, cipher_bench): Allow NULL arg to to run tests for all algorithms. (main): Run all tests by default. 2004-02-03 Werner Koch * tsexp.c (basic): New pass to check secure memory switching. 2004-01-12 Moritz Schulte * ac.c (check_one): Adjust to new ac API. 2003-11-22 Werner Koch * pubkey.c (check_keys_crypt): Fixed my last patch. 2003-11-11 Werner Koch * tsexp.c (basic): Add pass structure and a test for the %b format. 2003-11-04 Werner Koch * Makefile.am (noinst_PROGRAMS): Use this so that test programs get always build. * keygen.c (check_nonce): New. (main): Add a basic check for the nocen function. 2003-10-31 Werner Koch * basic.c (check_aes128_cbc_cts_cipher): Make it a prototype * ac.c (check_run): Comment unused variable. 2003-10-10 Werner Koch * prime.c (check_primes): Generate a generator and avoid printing unless in verbose mode. 2003-10-07 Werner Koch * tsexp.c (check_sscan): New. 2003-09-04 Werner Koch * pubkey.c (check_keys_crypt): Fix for compatibility mode. 2003-09-02 Moritz Schulte * Makefile.am (TESTS): Added: prime. * prime.c: New file. 2003-08-27 Moritz Schulte * basic.c (check_ciphers): Added: Serpent. Write braces around flags. 2003-08-04 Moritz Schulte * benchmark.c (do_powm): Adjust for new gcry_mpi_scan interface. 2003-07-23 Moritz Schulte * ac.c (key_copy): New function... (check_one): ... use it. 2003-07-22 Moritz Schulte * basic.c (check_ciphers): Use gcry_cipher_map_name. 2003-07-18 Moritz Schulte * ac.c (check_run): Renamed to ... (check_one): ... this, changed calling interface. (check_run): New function. * register.c: Adjust gcry_cipher_spec_t structure. 2003-07-14 Moritz Schulte * register.c: Adjust cipher specification structure. * benchmark.c: New file. * testapi.c: New file. * Makefile.am (EXTRA_PROGRAMS): Set to: benchmark testapi. (check_PROGRAMS): Set to: $(TESTS). 2003-07-12 Moritz Schulte * ac.c, basic.c, keygen.c, register.c, sexp.c, tsexp.c: Used gcry_err* wrappers for libgpg symbols. * basic.c (check_ciphers): Added: GCRY_CIPHER_TWOFISH128. 2003-07-08 Moritz Schulte * Makefile.am (LIBS): Remove: -lpthread. * basic.c (check_one_cipher): Fix variable initialization. Thanks to Simon Joseffson . 2003-07-07 Moritz Schulte * Makefile.am (TESTS): Added: register. 2003-07-05 Moritz Schulte * register.c (check_run): Adjusted for new gcry_cipher_register API. 2003-07-02 Moritz Schulte * Makefile.am (TESTS): Added: ac. * ac.c: New file. 2003-06-18 Werner Koch * basic.c (check_cbc_mac_cipher): Adjusted for new API of get_blklen and get_keylen. (check_ctr_cipher): Ditto. (check_one_cipher): Ditto. (check_one_md): Adjusted for new API of gcry_md_copy. 2003-06-18 Moritz Schulte * register.c: Replace old type GcryModule with newer one: gcry_module_t. Adjusted for new API. * Makefile.am (AM_CFLAGS): Added: @GPG_ERROR_CFLAGS@. 2003-06-15 Moritz Schulte * basic.c (get_keys_new): New function. (do_check_one_pubkey): New function ... (check_one_pubkey): ... use it. (progress_handler): New function. (main): Use gcry_set_progress_handler. 2003-06-14 Moritz Schulte * basic.c: Replaced calls to gcry_strerror with calls to gpg_strerror. (check_one_md): Adjust for new gcry_md_copy API. * tsexp.c: Likewise. * keygen.c: Likewise. 2003-06-12 Moritz Schulte * basic.c: Changed here and there, reorganized pubkey checks, added DSA and ELG keys. 2003-06-09 Moritz Schulte * basic.c, keygen.c, pubkey.c, register.c, tsexp.c: Changed to use new API. 2003-06-01 Moritz Schulte * tsexp.c (canon_len): Adjust for new gcry_sexp_canon_len API. 2003-05-26 Moritz Schulte * basic.c (verify_one_signature): Adjust for libgpg-error. (check_pubkey_sign): Likewise. (check_pubkey): Likewise. * basic.c (check_pubkey_sign): Likewise. * tsexp.c (canon_len): Likewise. (back_and_forth_one): Likewise. 2003-04-27 Moritz Schulte * pubkey.c: Changed the sample private key to contain the identifier `openpgp-rsa' instead of `rsa'. * basic.c (check_digests): Enabled/fixed some tests for TIGER. 2003-04-17 Moritz Schulte * Makefile.am (TESTS): Removed `register' for now. 2003-04-17 Moritz Schulte * basic.c (check_digests): Include checks for SHA512 and SHA384. 2003-04-16 Moritz Schulte * basic.c (check_one_md): Also test md_copy. 2003-04-07 Moritz Schulte * Makefile.am (TESTS): Added register. * register.c: New file. 2003-03-30 Simon Josefsson * basic.c (check_one_cipher): New. Test CTR. (main): Call it. (check_ciphers): Check CTR mode. 2003-03-26 Moritz Schulte * Makefile.am (TESTS): Added pubkey. * pubkey.c: New file. 2003-03-22 Simon Josefsson * basic.c (check_cbc_mac_cipher): New. (main): Use it. 2003-03-19 Werner Koch * keygen.c (check_rsa_keys): Don't expect an exponent when asking for e=0. (check_generated_rsa_key): Just print exponent if EXPECTED_E is 0. 2003-03-02 Moritz Schulte * basic.c (check_one_cipher): Use gcry_cipher_reset() instead of gcry_cipher_close(), gcry_cipher_open and gcry_cipher_setkey(). 2003-01-23 Werner Koch * keygen.c: New. 2003-01-20 Simon Josefsson * basic.c (check_digests): Add CRC. (check_one_md): Print computed and expected values on error. 2003-01-20 Werner Koch * basic.c (check_one_md): Kludge to check a one million "a". (check_digests): Add checks for SHA-256. 2003-01-20 Werner Koch * basic.c (check_pubkey): Check the keygrip for the sample key. 2003-01-15 Werner Koch * basic.c (verify_one_signature,check_pubkey_sign) (check_pubkey): New. (main): Check public key functions. Add a --debug option. 2002-11-23 Werner Koch * basic.c (check_digests): Add another test for MD4. By Simon Josefsson. 2002-11-10 Simon Josefsson * basic.c (check_aes128_cbc_cts_cipher): New function. (check_one_cipher): Add flags parameter. (check_ciphers): Support flags parameter. (main): Check CTS. 2002-11-10 Werner Koch * basic.c (check_one_md): New. By Simon Josefsson. (check_digests): New tests for MD4. By Simon. 2002-08-26 Werner Koch * basic.c (check_ciphers): Check simple DES. 2002-05-16 Werner Koch * tsexp.c (back_and_forth): Very minimal test of the new functions. 2002-05-14 Werner Koch Changed license of all files to the LGPL. 2002-05-02 Werner Koch * basic.c: Add option --verbose. 2002-01-11 Werner Koch * tsexp.c (canon_len): Fixed tests. 2001-12-18 Werner Koch * tsexp.c: New. Copyright 2001, 2002, 2003 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without modifications, as long as this notice is preserved. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/tests/Makefile.am b/tests/Makefile.am index ecaa6d8c..6539d885 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,33 +1,40 @@ # Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. # # This file is part of Libgcrypt. # # Libgcrypt is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # # Libgcrypt is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA ## Process this file with automake to produce Makefile.in TESTS = t-mpi-bit prime register ac ac-schemes ac-data basic \ - tsexp keygen pubkey benchmark pkbench hmac keygrip + tsexp keygen pubkey benchmark hmac keygrip + +# pkbench uses mmap for no good reason. Needs to be fixed. Code for +# this can be found in libksba/tests. +if !HAVE_W32_SYSTEM +TESTS += pkbench +endif + # Need to include ../src in addition to top_srcdir because gcrypt.h is # a built header. AM_CPPFLAGS = -I../src -I$(top_srcdir)/src AM_CFLAGS = $(GPG_ERROR_CFLAGS) LDADD = ../src/libgcrypt.la EXTRA_PROGRAMS = testapi noinst_PROGRAMS = $(TESTS) diff --git a/tests/pkbench.c b/tests/pkbench.c index 372fa0c9..5ce9b0e2 100644 --- a/tests/pkbench.c +++ b/tests/pkbench.c @@ -1,366 +1,376 @@ /* pkbench.c - Pubkey menchmarking * Copyright (C) 2004, 2005 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include +#ifndef HAVE_W32_SYSTEM #include +#endif HAVE_W32_SYSTEM #include #include #include typedef struct context { gcry_sexp_t key_secret; gcry_sexp_t key_public; gcry_sexp_t data; gcry_sexp_t data_encrypted; gcry_sexp_t data_signed; } *context_t; typedef int (*work_t) (context_t context, unsigned int final); static void benchmark (work_t worker, context_t context) { clock_t timer_start, timer_stop; unsigned int loop = 10; unsigned int i = 0; struct tms timer; int ret = 0; +#ifdef HAVE_W32_SYSTEM + timer_start = clock (); +#else times (&timer); timer_start = timer.tms_utime; +#endif for (i = 0; i < loop; i++) { ret = (*worker) (context, (i + 1) == loop); if (! ret) break; } +#ifdef HAVE_W32_SYSTEM + timer_stop = clock (); +#else times (&timer); timer_stop = timer.tms_utime; +#endif if (ret) printf ("%.0f ms\n", (((double) ((timer_stop - timer_start) / loop)) / CLOCKS_PER_SEC) * 10000000); else printf ("[skipped]\n"); } static int work_encrypt (context_t context, unsigned int final) { gcry_error_t err = GPG_ERR_NO_ERROR; gcry_sexp_t data_encrypted = NULL; int ret = 1; err = gcry_pk_encrypt (&data_encrypted, context->data, context->key_public); if (gpg_err_code (err) == GPG_ERR_NOT_IMPLEMENTED) { err = GPG_ERR_NO_ERROR; ret = 0; } else { assert (! err); if (final) context->data_encrypted = data_encrypted; else gcry_sexp_release (data_encrypted); } return ret; } static int work_decrypt (context_t context, unsigned int final) { gcry_error_t err = GPG_ERR_NO_ERROR; int ret = 1; if (! context->data_encrypted) ret = 0; else { gcry_sexp_t data_decrypted = NULL; err = gcry_pk_decrypt (&data_decrypted, context->data_encrypted, context->key_secret); assert (! err); if (final) { gcry_sexp_release (context->data_encrypted); context->data_encrypted = NULL; } gcry_sexp_release (data_decrypted); } return ret; } static int work_sign (context_t context, unsigned int final) { gcry_error_t err = GPG_ERR_NO_ERROR; gcry_sexp_t data_signed = NULL; int ret = 1; err = gcry_pk_sign (&data_signed, context->data, context->key_secret); if (gpg_err_code (err) == GPG_ERR_NOT_IMPLEMENTED) { err = GPG_ERR_NO_ERROR; ret = 0; } else { assert (! err); if (final) context->data_signed = data_signed; else gcry_sexp_release (data_signed); } return ret; } static int work_verify (context_t context, unsigned int final) { gcry_error_t err = GPG_ERR_NO_ERROR; int ret = 1; if (! context->data_signed) ret = 0; else { err = gcry_pk_verify (context->data_signed, context->data, context->key_public); assert (! err); if (final) { gcry_sexp_release (context->data_signed); context->data_signed = NULL; } } return ret; } static void process_key_pair (context_t context) { struct { work_t worker; const char *identifier; } worker_functions[] = { { work_encrypt, "encrypt" }, { work_decrypt, "decrypt" }, { work_sign, "sign" }, { work_verify, "verify" } }; unsigned int i = 0; for (i = 0; i < (sizeof (worker_functions) / sizeof (*worker_functions)); i++) { printf ("%s: ", worker_functions[i].identifier); benchmark (worker_functions[i].worker, context); } } static void context_init (context_t context, gcry_sexp_t key_secret, gcry_sexp_t key_public) { gcry_error_t err = GPG_ERR_NO_ERROR; unsigned int key_size = 0; gcry_mpi_t data = NULL; gcry_sexp_t data_sexp = NULL; key_size = gcry_pk_get_nbits (key_secret); assert (key_size); data = gcry_mpi_new (key_size); assert (data); gcry_mpi_randomize (data, key_size, GCRY_STRONG_RANDOM); gcry_mpi_clear_bit (data, key_size - 1); err = gcry_sexp_build (&data_sexp, NULL, "(data (flags raw) (value %m))", data); assert (! err); gcry_mpi_release (data); context->key_secret = key_secret; context->key_public = key_public; context->data = data_sexp; context->data_encrypted = NULL; context->data_signed = NULL; } static void context_destroy (context_t context) { gcry_sexp_release (context->key_secret); gcry_sexp_release (context->key_public); gcry_sexp_release (context->data); } static void process_key_pair_file (const char *key_pair_file) { gcry_error_t err = GPG_ERR_NO_ERROR; void *key_pair_buffer = NULL; gcry_sexp_t key_pair_sexp = NULL; gcry_sexp_t key_secret_sexp = NULL; gcry_sexp_t key_public_sexp = NULL; struct context context = { NULL }; struct stat statbuf; int key_pair_fd = -1; int ret = 0; ret = stat (key_pair_file, &statbuf); assert (! ret); key_pair_fd = open (key_pair_file, O_RDONLY); assert (key_pair_fd != -1); key_pair_buffer = mmap (NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, key_pair_fd, 0); assert (key_pair_buffer != MAP_FAILED); err = gcry_sexp_sscan (&key_pair_sexp, NULL, key_pair_buffer, statbuf.st_size); assert (! err); key_secret_sexp = gcry_sexp_find_token (key_pair_sexp, "private-key", 0); assert (key_secret_sexp); key_public_sexp = gcry_sexp_find_token (key_pair_sexp, "public-key", 0); assert (key_public_sexp); gcry_sexp_release (key_pair_sexp); ret = munmap (key_pair_buffer, statbuf.st_size); assert (! ret); ret = close (key_pair_fd); assert (! ret); context_init (&context, key_secret_sexp, key_public_sexp); printf ("Key file: %s\n", key_pair_file); process_key_pair (&context); printf ("\n"); context_destroy (&context); } static const char *program_name = NULL; static void print_usage (int err) { fprintf (err ? stderr : stdout, "Usage: %s [--help ] [ --genkey , ] \n\n", program_name); exit (err); } static void generate_key (const char *algorithm, const char *key_size) { gcry_error_t err = GPG_ERR_NO_ERROR; size_t key_pair_buffer_size = 0; char *key_pair_buffer = NULL; gcry_sexp_t key_spec = NULL; gcry_sexp_t key_pair = NULL; err = gcry_sexp_build (&key_spec, NULL, "(genkey (%s (nbits %s)))", algorithm, key_size); assert (! err); err = gcry_pk_genkey (&key_pair, key_spec); assert (! err); key_pair_buffer_size = gcry_sexp_sprint (key_pair, GCRYSEXP_FMT_ADVANCED, NULL, 0); key_pair_buffer = malloc (key_pair_buffer_size); assert (key_pair_buffer); gcry_sexp_sprint (key_pair, GCRYSEXP_FMT_ADVANCED, key_pair_buffer, key_pair_buffer_size); printf ("%.*s", key_pair_buffer_size, key_pair_buffer); } int main (int argc, char **argv) { program_name = argc ? argv[0] : ""; gcry_control (GCRYCTL_DISABLE_SECMEM); if (argv[1] && ((! strcmp (argv[1], "--help")) || (! strcmp (argv[1], "-h")))) print_usage (0); else if (argv[1] && ((! strcmp (argv[1], "--genkey")) || (! strcmp (argv[1], "-g")))) { char *algorithm = NULL; char *key_size = NULL; /* No valuable keys are create, so we can speed up our RNG. */ gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); if (argv[2]) { algorithm = argv[2]; key_size = strchr (algorithm, ','); if (key_size) { *key_size = 0; key_size++; } } if (algorithm && key_size) generate_key (algorithm, key_size); else print_usage (EXIT_FAILURE); } else { unsigned int i = 0; for (i = 1; (i < argc); i++) process_key_pair_file (argv[i]); } return EXIT_SUCCESS; } diff --git a/tests/tsexp.c b/tests/tsexp.c index 1d71208e..530aa4c8 100644 --- a/tests/tsexp.c +++ b/tests/tsexp.c @@ -1,430 +1,431 @@ /* tsexp.c - S-expression regression tests * Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "../src/gcrypt.h" #define PGMNAME "tsexp" static int verbose; static int error_count; static void info (const char *format, ...) { va_list arg_ptr; if (verbose) { va_start( arg_ptr, format ) ; vfprintf (stderr, format, arg_ptr ); va_end(arg_ptr); } } static void fail ( const char *format, ... ) { va_list arg_ptr ; fputs (PGMNAME ": ", stderr); va_start( arg_ptr, format ) ; vfprintf (stderr, format, arg_ptr ); va_end(arg_ptr); error_count++; } /* fixme: we need better tests */ static void basic (void) { int pass; gcry_sexp_t sexp; int idx; char *secure_buffer; size_t secure_buffer_len; const char *string; static struct { const char *token; const char *parm; } values[] = { { "public-key", NULL }, { "dsa", NULL }, { "dsa", "p" }, { "dsa", "y" }, { "dsa", "q" }, { "dsa", "g" }, { NULL } }; info ("doing some pretty pointless tests\n"); secure_buffer_len = 99; secure_buffer = gcry_xmalloc_secure (secure_buffer_len); memset (secure_buffer, 'G', secure_buffer_len); for (pass=0;;pass++) { switch (pass) { case 0: string = ("(public-key (dsa (p #41424344#) (y this_is_y) " "(q #61626364656667#) (g %m)))"); if ( gcry_sexp_build (&sexp, NULL, string, gcry_mpi_set_ui (NULL, 42)) ) { fail (" scanning `%s' failed\n", string); return; } break; case 1: string = ("(public-key (dsa (p #41424344#) (y this_is_y) " "(q %b) (g %m)))"); if ( gcry_sexp_build (&sexp, NULL, string, 15, "foo\0\x01\0x02789012345", gcry_mpi_set_ui (NULL, 42)) ) { fail (" scanning `%s' failed\n", string); return; } break; case 2: string = ("(public-key (dsa (p #41424344#) (y silly_y_value) " "(q %b) (g %m)))"); if ( gcry_sexp_build (&sexp, NULL, string, secure_buffer_len, secure_buffer, gcry_mpi_set_ui (NULL, 17)) ) { fail (" scanning `%s' failed\n", string); return; } if (!gcry_is_secure (sexp)) fail ("gcry_sexp_build did not switch to secure memory\n"); break; default: return; /* Ready. */ } /* now find something */ for (idx=0; values[idx].token; idx++) { const char *token = values[idx].token; const char *parm = values[idx].parm; gcry_sexp_t s1, s2; gcry_mpi_t a; const char *p; size_t n; s1 = gcry_sexp_find_token (sexp, token, strlen(token) ); if (!s1) { fail ("didn't found `%s'\n", token); continue; } p = gcry_sexp_nth_data (s1, 0, &n); if (!p) { fail ("no car for `%s'\n", token); continue; } info ("car=`%.*s'\n", (int)n, p); s2 = gcry_sexp_cdr (s1); if (!s2) { fail ("no cdr for `%s'\n", token); continue; } p = gcry_sexp_nth_data (s2, 0, &n); if (p) { fail ("data at car of `%s'\n", token); continue; } if (parm) { s2 = gcry_sexp_find_token (s1, parm, strlen (parm)); if (!s2) { fail ("didn't found `%s'\n", parm); continue; } p = gcry_sexp_nth_data (s2, 0, &n); if (!p) { fail("no car for `%s'\n", parm ); continue; } info ("car=`%.*s'\n", (int)n, p); p = gcry_sexp_nth_data (s2, 1, &n); if (!p) { fail("no cdr for `%s'\n", parm ); continue; } info ("cdr=`%.*s'\n", (int)n, p); a = gcry_sexp_nth_mpi (s2, 0, GCRYMPI_FMT_USG); if (!a) { fail("failed to cdr the mpi for `%s'\n", parm); continue; } } } gcry_sexp_release (sexp); sexp = NULL; } gcry_free (secure_buffer); } static void canon_len (void) { static struct { size_t textlen; /* length of the buffer */ size_t expected;/* expected length or 0 on error and then ... */ size_t erroff; /* ... and at this offset */ gcry_error_t errcode; /* ... with this error code */ const char *text; } values[] = { { 14, 13, 0, GPG_ERR_NO_ERROR, "(9:abcdefghi) " }, { 16, 15, 0, GPG_ERR_NO_ERROR, "(10:abcdefghix)" }, { 14, 0,14, GPG_ERR_SEXP_STRING_TOO_LONG, "(10:abcdefghi)" }, { 15, 0, 1, GPG_ERR_SEXP_ZERO_PREFIX, "(010:abcdefghi)" }, { 2, 0, 0, GPG_ERR_SEXP_NOT_CANONICAL, "1:"}, { 4, 0, 4, GPG_ERR_SEXP_STRING_TOO_LONG, "(1:)"}, { 5, 5, 0, GPG_ERR_NO_ERROR, "(1:x)"}, { 2, 2, 0, GPG_ERR_NO_ERROR, "()"}, { 4, 2, 0, GPG_ERR_NO_ERROR, "()()"}, { 4, 4, 0, GPG_ERR_NO_ERROR, "(())"}, { 3, 0, 3, GPG_ERR_SEXP_STRING_TOO_LONG, "(()"}, { 3, 0, 1, GPG_ERR_SEXP_BAD_CHARACTER, "( )"}, { 9, 9, 0, GPG_ERR_NO_ERROR, "(3:abc())"}, { 10, 0, 6, GPG_ERR_SEXP_BAD_CHARACTER, "(3:abc ())"}, /* fixme: we need much more cases */ { 0 }, }; int idx; gcry_error_t errcode; size_t n, erroff; info ("checking canoncial length test function\n"); for (idx=0; values[idx].text; idx++) { - n = gcry_sexp_canon_len (values[idx].text, values[idx].textlen, + n = gcry_sexp_canon_len ((const unsigned char*)values[idx].text, + values[idx].textlen, &erroff, &errcode); if (n && n == values[idx].expected) ; /* success */ else if (!n && !values[idx].expected) { /* we expected an error - check that this is the right one */ if (values[idx].erroff != erroff) fail ("canonical length test %d - wrong error offset %u\n", idx, (unsigned int)erroff); if (gcry_err_code (errcode) != values[idx].errcode) fail ("canonical length test %d - wrong error code %d\n", idx, errcode); } else fail ("canonical length test %d failed - n=%u, off=%u, err=%d\n", idx, (unsigned int)n, (unsigned int)erroff, errcode); } } static void back_and_forth_one (int testno, const char *buffer, size_t length) { gcry_error_t rc; gcry_sexp_t se, se1; size_t n, n1; char *p1; rc = gcry_sexp_new (&se, buffer, length, 1); if (rc) { fail ("baf %d: gcry_sexp_new failed: %s\n", testno, gpg_strerror (rc)); return; } n1 = gcry_sexp_sprint (se, GCRYSEXP_FMT_CANON, NULL, 0); if (!n1) { fail ("baf %d: get required length for canon failed\n", testno); return; } p1 = gcry_xmalloc (n1); n = gcry_sexp_sprint (se, GCRYSEXP_FMT_CANON, p1, n1); if (n1 != n+1) /* sprints adds an extra 0 but dies not return it */ { fail ("baf %d: length mismatch for canon\n", testno); return; } rc = gcry_sexp_create (&se1, p1, n, 0, gcry_free); if (rc) { fail ("baf %d: gcry_sexp_create failed: %s\n", testno, gpg_strerror (rc)); return; } gcry_sexp_release (se1); /* Again but with memory checking. */ p1 = gcry_xmalloc (n1+2); *p1 = '\x55'; p1[n1+1] = '\xaa'; n = gcry_sexp_sprint (se, GCRYSEXP_FMT_CANON, p1+1, n1); if (n1 != n+1) /* sprints adds an extra 0 but does not return it */ { fail ("baf %d: length mismatch for canon\n", testno); return; } if (*p1 != '\x55' || p1[n1+1] != '\xaa') fail ("baf %d: memory corrupted (1)\n", testno); rc = gcry_sexp_create (&se1, p1+1, n, 0, NULL); if (rc) { fail ("baf %d: gcry_sexp_create failed: %s\n", testno, gpg_strerror (rc)); return; } if (*p1 != '\x55' || p1[n1+1] != '\xaa') fail ("baf %d: memory corrupted (2)\n", testno); gcry_sexp_release (se1); if (*p1 != '\x55' || p1[n1+1] != '\xaa') fail ("baf %d: memory corrupted (3)\n", testno); gcry_free (p1); /* FIXME: we need a lot more tests */ gcry_sexp_release (se); } static void back_and_forth (void) { static struct { const char *buf; int len; } tests[] = { { "(7:g34:fgh1::2:())", 0 }, { "(7:g34:fgh1::2:())", 18 }, { "(protected-private-key \n" " (rsa \n" " (n #00BE8A536204687149A48FF9F1715FF3530AD9A836D62102BF4065E5CF5953236DB94F1DF2FF4D525CD4CE7966DDC3C839968E8BAC2948934DF047CC65287CD79F6C23C93E55D7F9231E3942BD496DE383469977635A51ADF4AF747DB958CA02E9940DFC1DC0FC7FC755E7EB6618FEE6DA54B8A06E0CBF9D9257443F9992261435#)\n" " (e #010001#)\n" " (protected openpgp-s2k3-sha1-aes-cbc \n" " (\n" " (sha1 #C2A5673BD3882405# \"96\")\n" " #8D08AAF6A9209ED69D71EB7E64D78715#)\n" " #F7B0B535F8F8E22F4F3DA031224070303F82F9207D42952F1ACF21A4AB1C50304EBB25527992C7B265A9E9FF702826FB88759BDD55E4759E9FCA6C879538C9D043A9C60A326CB6681090BAA731289BD880A7D5774D9999F026E5E7963BFC8C0BDC9F061393CB734B4F259725C0A0A0B15BA39C39146EF6A1B3DC4DF30A22EBE09FD05AE6CB0C8C6532951A925F354F4E26A51964F5BBA50081690C421C8385C4074E9BAB9297D081B857756607EAE652415275A741C89E815558A50AC638EDC5F5030210B4395E3E1A40FF38DCCCB333A19EA88EFE7E4D51B54128C6DF27395646836679AC21B1B25C1DA6F0A7CE9F9BE078EFC7934FA9AE202CBB0AA06C20DFAF9A66FAB7E9073FBE96B9A7F25C3BA45EC3EECA65796AEE313BA148DE5314F30345B452B50B17C4D841A7F27397126E8C10BD0CE3B50A82C0425AAEE7798031671407B681F52916256F78CAF92A477AC27BCBE26DAFD1BCE386A853E2A036F8314BB2E8E5BB1F196434232EFB0288331C2AB16DBC5457CC295EB966CAC5CE73D5DA5D566E469F0EFA82F9A12B8693E0#)\n" " )\n" " )\n", 0 }, { NULL, 0 } }; int idx; for (idx=0; tests[idx].buf; idx++) back_and_forth_one (idx, tests[idx].buf, tests[idx].len); } static void check_sscan (void) { static struct { const char *text; gcry_error_t expected_err; } values[] = { /* Bug reported by Olivier L'Heureux 2003-10-07 */ { "(7:sig-val(3:dsa" "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e)))", GPG_ERR_NO_ERROR }, { "(7:sig-val(3:dsa" "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e))", GPG_ERR_SEXP_UNMATCHED_PAREN }, { "(7:sig-val(3:dsa" "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e))))", GPG_ERR_SEXP_UNMATCHED_PAREN }, { NULL, 0 } }; int idx; gcry_error_t err; gcry_sexp_t s; info ("checking gcry_sexp_sscan\n"); for (idx=0; values[idx].text; idx++) { err = gcry_sexp_sscan (&s, NULL, values[idx].text, strlen (values[idx].text)); if (gpg_err_code (err) != values[idx].expected_err) fail ("gcry_sexp_sscan test %d failed: %s\n", idx, gpg_strerror (err)); gcry_sexp_release (s); } } int main (int argc, char **argv) { if (argc > 1 && !strcmp (argv[1], "-v")) verbose = 1; gcry_control (GCRYCTL_DISABLE_SECMEM_WARN); gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0); basic (); canon_len (); back_and_forth (); check_sscan (); return error_count? 1:0; }