diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 1588e94e..70f1cf8b 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3003 +1,3022 @@
+2006-04-22  Moritz Schulte  <moritz@g10code.com>
+
+	* 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  <moritz@g10code.com>
 
 	* 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  <wk@g10code.com>
 
 	* 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  <wk@g10code.com>
 
 	* 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  <bradh@frogmouth.net>  (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  <bradh@frogmouth.net>  (wk, patch 2005-04-22)
 
 	* md.c, sha256.c:  Add support for SHA-224.
 	(sha224_init): New.
 	
 2006-01-18  Brad Hards  <bradh@frogmouth.net>  (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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* pubkey.c (gcry_pk_algo_info): Don't forget to break after switch
 	case.
 
 2005-09-19  Werner Koch  <wk@g10code.com>
 
 	* 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  <wk@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* ac.c (_gcry_ac_init): New function.
 
 2005-04-12  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@g10code.com>
 
 	* pubkey.c (gcry_pk_get_keygrip): Allow for shadowed-private-key.
 
 2005-02-13  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* ac.c: Major parts rewritten.
 	* pubkey.c (_gcry_pk_get_elements): New function.
 
 2004-12-09  Werner Koch  <wk@g10code.com>
 
 	* serpent.c (serpent_setkey): Moved prototype of serpent_test to
 	outer scope.
 
 2004-09-11  Moritz Schulte  <moritz@g10code.com>
 
 	* pubkey.c (pubkey_table): Added an alias entry for GCRY_PK_ELG_E.
 
 2004-08-23  Moritz Schulte  <moritz@g10code.com>
 
 	* ac.c: Do not include <assert.h>.
 	* 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  <wk@g10code.de>
 
 	* 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  <moritz@g10code.com>
 
 	* pubkey.c (gcry_pk_sign): Fixed memory leak; fix provided by
 	Modestas Vainius.
 
 2004-07-16  Werner Koch  <wk@gnupg.org>
 
 	* 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  <moritz@g10code.com>
 
 	* rsa.c (_gcry_rsa_decrypt): Don't forget to free "a".  Thanks to
 	Nikos Mavroyanopoulos.
 
 2004-05-09  Werner Koch  <wk@gnupg.org>
 
 	* random.c (read_pool): Mix the PID in to better protect after a
 	fork.
 
 2004-07-04  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <moritz@g10code.de>
 
 	* ac.c (gcry_ac_open): Do not dereference NULL pointer.  Reported
 	by Umberto Salsi.
 
 2004-02-20  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <mo@g10code.com>
 
 	* 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  <mo@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* primegen.c (is_prime): Release A2.
 
 2003-12-19  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* primegen.c (gen_prime): Doc fix.  Thanks to Newton Hammet.
 
 2003-12-11  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* cipher.c: Documentation cleanups.
 	(gcry_cipher_mode_from_oid): Allow NULL for STRING.
 
 2003-12-03  Werner Koch  <wk@gnupg.org>
 
 	* elgamal.c (sign, do_encrypt, gen_k): Make sure that a small K is
 	only used for encryption.
 
 2003-11-18  Werner Koch  <wk@gnupg.org>
 
 	* random.h (rndw32_set_dll_name): Removed unused prototype.
 
 	* Makefile.am (EXTRA_DIST): Added Manifest.
 
 2003-11-11  Werner Koch  <wk@gnupg.org>
 
 	* Manifest: New.
 
 2003-11-04  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <mo@g10code.com>
 
 	* pubkey.c (gcry_pk_encrypt): Don't forget to deallocate pkey.
 
 2003-10-27  Werner Koch  <wk@gnupg.org>
 
 	* 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  <mo@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* primegen.c (gen_prime): Assert that NBITS is never zero, it
 	would cause a segv.
 
 2003-09-28  Moritz Schulte  <mo@g10code.com>
 
 	* ac.c: Include "cipher.h".
 
 2003-09-27  Moritz Schulte  <mo@g10code.com>
 
 	* rndegd.c (do_read): Return nread instead of nbytes; thanks to
 	Michael Caerwyn.
 
 2003-09-04  Werner Koch  <wk@gnupg.org>
 
 	* 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  <mo@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <mo@g10code.com>
 
 	* cipher.c: Add support for Serpent
 	* serpent.c: New file.
 
 2003-08-10  Moritz Schulte  <moritz@g10code.com>
 
 	* rsa.c (_gcry_rsa_blind, _gcry_rsa_unblind): Declare static.
 
 2003-08-09  Timo Schulz  <twoaday@freakmail.de>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* md.c (gcry_md_lookup_func_oid): Allow for empty OID lists.
 
 2003-07-23  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* md.c (gcry_md_hash_buffer): Convert ERR to gpg_error_t in
 	gpg_strerror.
 
 2003-07-14  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* ac.c (gcry_ac_data_set): Only release old MPI value if it is
 	different from the new value.  Bug reported by Simon Josefsson
 	<jas@extundo.com>.
 
 	* 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  <moritz@g10code.com>
 
 	* 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 <jas@extundo.com>.
 
 	* 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 <jas@extunde.com>.
 
 2003-07-04  Moritz Schulte  <moritz@g10code.com>
 
 	* cipher.c (gcry_cipher_list): New function.
 
 2003-07-01  Moritz Schulte  <moritz@g10code.com>
 
 	* pubkey.c (sexp_to_sig): Accept a `flags' S-expression to be more
 	consistent with sexp_to_enc.
 
 2003-06-30  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* ac.c: New file.
 
 2003-06-26  Werner Koch  <wk@gnupg.org>
 
 	* md.c (gcry_md_hash_buffer): Trigger BUG correcly with new API.
 
 2003-06-19  Werner Koch  <wk@gnupg.org>
 
 	* md.c (gcry_md_is_enabled): Fixed. 
 
 2003-06-18  Werner Koch  <wk@gnupg.org>
 
 	* cipher.c (gcry_cipher_get_algo_keylen): New.
 	(gcry_cipher_get_algo_blklen): New.
 
 2003-06-18  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* cipher.c (gcry_cipher_open): Make sure HANDLE is set to NULL on
 	error.
 
 2003-06-11  Werner Koch  <wk@gnupg.org>
 
 	* 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  <moritz@g10code.com>
 
 	* Makefile.am: Removed rules serpent, since that is not commited
 	yet.
 
 2003-06-08  Moritz Schulte  <moritz@g10code.com>
 
 	* pubkey.c (gcry_pk_encrypt): Improve calculation for size of the
 	format string.
 
 2003-06-07  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* tiger.c: Merged code ussing the U64_C macro from GnuPG.
 
 	* sha512.c: Likewise.
 
 2003-05-17  Moritz Schulte  <moritz@g10code.com>
 
 	* pubkey.c (gcry_pk_genkey): Fix type: acquire a lock, instead of
 	releasing it.
 
 2003-05-11  Moritz Schulte  <moritz@g10code.com>
 
 	* pubkey.c (gcry_pk_testkey): Call REGISTER_DEFAULT_CIPHERS.
 	(gcry_pk_ctl): Likewise.
 
 2003-04-27  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 	
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* des.c: Removed checks for GCRY_CIPHER_3DES and GCRY_CIPHER_DES.
 
 2003-03-31  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <jas@extundo.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <jas@extundo.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <moritz@g10code.com>
 
 	* primegen.c: Initialize `no_of_small_prime_numbers' statically.
 	(gen_prime): Remove calculation of `no_of_small_prime_numbers'.
 
 2003-03-03  Moritz Schulte  <moritz@g10code.com>
 
 	* md.c (gcry_md_ctl): Rewritten to use same style like the other
 	functions dispatchers.
 
 2003-03-02  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <twoaday@freakmail.de>
 
 	* random.c (gcry_random_add_bytes): New. Function to add external
 	random to the pool.
 	
 2003-01-20  Simon Josefsson  <jas@extundo.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* pubkey.c (gcry_pk_get_keygrip): Implemented keygrips for DSA
 	and ElGamal.
 
 2003-01-17  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* random.c (_gcry_random_initialize): New.
 
 2002-12-16  Werner Koch  <wk@gnupg.org>
 
 	* cipher.c: Added a Teletrust specific OID for 3DES.
 
 2002-12-12  Werner Koch  <wk@gnupg.org>
 
 	* md.c: Added another oddball OIW OID (sha-1WithRSAEncryption).
 
 2002-11-23  Werner Koch  <wk@gnupg.org>
 
 	* 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  <jas@extundo.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* arcfour.c (do_encrypt_stream): Don't use increment op when
 	assigning to the same variable.
 
 2002-10-10  Timo Schulz  <ts@winpt.org>
 
 	* 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  <wk@gnupg.org>
 
 	* md.c: Include an OID for TIGER.
 	* tiger.c (tiger_get_info): Use a regular OID.
 
 2002-09-17  Werner Koch  <wk@gnupg.org>
 
 	* random.c: Replaced mutex.h by the new ath.h.  Changed all calls.
 
 2002-09-16  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* pubkey.c: Enable keygrip calculation for "openpgp-rsa".
 
 2002-08-17  Werner Koch  <wk@gnupg.org>
 
 	* cipher.c (setup_cipher_table): Don't overwrite the DES entry
 	with the entry for DUMMY.
 
 2002-08-14  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* rndunix.c (_gcry_rndunix_constructor): Prefixed with _gcry_.
 	Noted by Stephan Austermuehle.
 
 2002-07-08  Timo Schulz  <ts@winpt.org>
 
 	* rndw32.c: Replaced the m_ memory functions with the real 
 	gcry_ functions. Renamed all g10_ prefixed functions to log_.
 	
 2002-06-12  Werner Koch  <wk@gnupg.org>
 
 	* rsa.c (generate): Use e = 65537 for now.
 
 2002-06-11  Werner Koch  <wk@gnupg.org>
 
 	* pubkey.c (gcry_pk_get_keygrip): Allow a "protected-private-key".
 
 2002-06-05  Timo Schulz  <ts@winpt.org>
 
 	* cipher.c (gcry_cipher_encrypt, gcry_cipher_decrypt):
 	Check that the input size is a multiple of the blocksize.
 	
 2002-05-23  Werner Koch  <wk@gnupg.org>
 
 	* md.c (oid_table): Add an rsadsi OID for MD5.
 
 2002-05-21  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* random.c (gcry_random_bytes,gcry_random_bytes_secure)
 	(gcry_randomize): Make sure we are initialized.
 
 2002-05-14  Werner Koch  <wk@gnupg.org>
 
 	Changed license of most files to the LGPL.
 
 2002-05-02  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* cipher.c: Fixed list of copyright years.
 
 2002-03-18  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* md.c: Add rsaSignatureWithripemd160 to OID table.
 
 2002-02-20  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* rndunix.c (rndunix_constructor): Use the the new prefixed
 	function name.  Reported by Jordi Mallach.
 
 2002-02-10  Werner Koch  <wk@gnupg.org>
 
 	* random.c (mix_pool): Carry an extra failsafe_digest buffer
 	around to make the function more robust.
 
 2002-02-08  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* pubkey.c (gcry_pk_get_keygrip): New - experimental.
 
 2001-12-11  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* cipher.c (gcry_cipher_map_name): Look also for OIDs prefixed
 	with "oid."  or "OID.".
 
 2001-12-05  Werner Koch  <wk@gnupg.org>
 
 	* pubkey.c (algo_info_table): Fixed entry for openpgp-rsa. 
 
 2001-11-24  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* md.c (gcry_md_info): New operator GCRYCTL_IS_ALGO_ENABLED.
 
 2001-11-07  Werner Koch  <wk@gnupg.org>
 
 	* md.c (gcry_md_hash_buffer): Close the handle which was left open
 	for algorithms other than rmd160.
 
 2001-08-08  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* rndegd.c (gather_random): Removed the use of tty_printf.
 
 2001-03-29  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* cipher.c (cipher_encrypt,gcry_cipher_encrypt): Use blocksize and
 	not 8.
 
 2000-12-19  Werner Koch  <wk@gnupg.org>
 
  	Major change:
 	Removed all GnuPG stuff and renamed this piece of software
 	to gcrypt. 
 
 2000-11-14  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@openit.de>
 
         * 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  <wk@openit.de>
 
         * 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  <wk@openit.de>
 
   * 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  <wk@openit.de>
 
   * 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  <wk@>
 
   * random.c (gather_faked): Replaced make_timestamp by time(2) again.
 
 Fri Jul 14 19:38:23 CEST 2000  Werner Koch  <wk@>
 
   * 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  <wk@openit.de>
 
 	* 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  <wk@openit.de>
 
 	* md.c (gcry_md_hash_buffer): Add support for the other algorithms.
 
 Mon Jan 31 16:37:34 CET 2000  Werner Koch  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* pubkey.c (sexp_to_key): Fixed mem leaks in case of errors.
 
 Mon Jan 24 22:24:38 CET 2000  Werner Koch  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* 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 <mroth@nessie.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* rndw32.c: New.
 
 Mon Sep 13 10:51:29 CEST 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* Makefile.am: Fixed seds for latest egcc. By Ollivier Robert.
 
 Mon Sep  6 19:59:08 CEST 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* des.c (selftest): Add some testpattern
 
 Mon Aug 30 20:38:33 CEST 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* md5.c (md5_final): Fix for a SCO cpp bug.
 
 Thu Jul 15 10:15:35 CEST 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* Makefile.am: Support for libtool.
 
 Fri Jul  2 11:45:54 CEST 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* dynload.c (register_internal_cipher_extension): Minor init fix.
 
 Tue May  4 15:47:53 CEST 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* rndlinux.c (tty_printf) [IS_MODULE]: Removed.
 
 	* rndegd.c (gather_random): Some fixes.
 
 Wed Mar 17 13:09:03 CET 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* rndegd.c (do_read): New.
 	(gather_random): Changed the implementation.
 
 Mon Mar  8 20:47:17 CET 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* dynload.c (DLSYM_NEEDS_UNDERSCORE): Renamed.
 
 Fri Feb 26 17:55:41 CET 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* md.c: Nearly a total rewrote.
 
 Wed Feb 24 11:07:27 CET 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* cipher.c (context): Fixed alignment
 	* md.c: Ditto.
 
 	* rndegd.c: New
 
 Mon Feb 22 20:04:00 CET 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* rndegd.c: New.
 
 Wed Feb 10 17:15:39 CET 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* rndunix.c (gather_random): Fix to avoid infinite loop.
 
 Sun Jan 17 11:04:33 CET 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* rndunix.c (start_gatherer): Fixed stupid ==/= bug
 
 1998-12-31  Geoff Keating  <geoffk@ozemail.com.au>
 
 	* des.c (is_weak_key): Rewrite loop end condition.
 
 Tue Dec 29 14:41:47 CET 1998  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* random.c: add unistd.h for getpid().
 	(RAND_MAX): Fallback value for Sun.
 
 Wed Dec 23 17:12:24 CET 1998  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* md.c (md_copy): Reset debug.
 
 Mon Dec 14 21:18:49 CET 1998  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <wk@isil.d.shuttle.de>
 
 	* 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  <steve@altair.xemacs.org>
 
 	* 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 <mroth@nessie.de>
 
 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 conatin 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/random-daemon.c b/cipher/random-daemon.c
index b659caaa..6a42d551 100644
--- a/cipher/random-daemon.c
+++ b/cipher/random-daemon.c
@@ -1,108 +1,365 @@
 /* random-daemon.c  - Access to the external random daemon
  * Copyright (C) 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
  */
 
 /*
    The functions here are used by random.c to divert calls to an
    external random number daemon.  The actual daemon we use is
    gcryptrnd.  Such a daemon is useful to keep a persistent pool in
    memory over invocations of a single application and to allow
    prioritizing access to the actual entropy sources.  The drawback is
    that we need to use IPC (i.e. unxi domain socket) to convey
    sensitive data.
  */
 
 
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <unistd.h>
 
 #include "g10lib.h"
 #include "random.h"
 #include "ath.h"
 
+
 
-/* The lock taken while talking to the daemon.  */
+/* This is default socket name we use in case the provided socket name
+   is NULL.  */
+#define RANDOM_DAEMON_SOCKET "/var/run/libgcrypt/S.gcryptrnd"
+
+/* The lock serializing access to the daemon.  */
 static ath_mutex_t daemon_lock = ATH_MUTEX_INITIALIZER;
 
+/* The socket connected to the daemon.  */
+static int daemon_socket = -1; 
+
+/* Creates a socket connected to the daemon.  On success, store the
+   socket fd in *SOCK.  Returns error code.  */
+static gcry_error_t
+connect_to_socket (const char *socketname, int *sock)
+{
+  struct sockaddr_un *srvr_addr;
+  socklen_t addrlen;
+  gcry_error_t err;
+  int fd;
+  int rc;
+
+  srvr_addr = NULL;
+
+  /* Create a socket. */
+  fd = socket (AF_UNIX, SOCK_STREAM, 0);
+  if (fd == -1)
+    {
+      log_error ("can't create socket: %s\n", strerror (errno));
+      err = gcry_error_from_errno (errno);
+      goto out;
+    }
+
+  /* Set up address.  */
+  srvr_addr = gcry_malloc (sizeof *srvr_addr); 
+  if (! srvr_addr)
+    {
+      log_error ("malloc failed: %s\n", strerror (errno));
+      err = gcry_error_from_errno (errno);
+      goto out;
+    }
+  memset (srvr_addr, 0, sizeof *srvr_addr);
+  srvr_addr->sun_family = AF_UNIX;
+  if (strlen (socketname) + 1 >= sizeof (srvr_addr->sun_path))
+    {
+      log_error ("socket name `%s' too long\n", socketname);
+      err = gcry_error (GPG_ERR_INTERNAL); /* FIXME? */
+      goto out;
+    }
+  strcpy (srvr_addr->sun_path, socketname);
+  addrlen = (offsetof (struct sockaddr_un, sun_path)
+             + strlen (srvr_addr->sun_path) + 1);
+
+  /* Connect socket.  */
+  rc = connect (fd, (struct sockaddr *) srvr_addr, addrlen);
+  if (rc == -1)
+    {
+      log_error ("error connecting socket `%s': %s\n",
+		 srvr_addr->sun_path, strerror (errno));
+      err = gcry_error_from_errno (errno);
+      goto out;
+    }
+
+  err = 0;
+
+ out:
+
+  *sock = fd;
+  gcry_free (srvr_addr);
+
+  if (err)
+    close (fd);
+
+  return err;
+}
 
 
 /* Initialize basics of this module. This should be viewed as a
    constroctur to prepare locking. */
 void
-_gcry_daemon_initialize_basics (void)
+_gcry_daemon_initialize_basics (const char *socketname)
 {
   static int initialized;
   int err;
 
   if (!initialized)
     {
       initialized = 1;
       err = ath_mutex_init (&daemon_lock);
       if (err)
         log_fatal ("failed to create the daemon lock: %s\n", strerror (err) );
+
+      err = connect_to_socket (socketname ? socketname : RANDOM_DAEMON_SOCKET,
+			       &daemon_socket);
+      if (err)
+	log_info ("not using random daemon\n");
     }
 }
 
+
 
+/* Send LENGTH bytes of BUFFER to file descriptor FD.  Returns 0 on
+   success or another value on write error. */
+static int
+writen (int fd, const void *buffer, size_t length)
+{
+  ssize_t n;
+      
+  while (length)
+    {
+      do
+        n = ath_write (fd, buffer, length);
+      while (n < 0 && errno == EINTR);
+      if (n < 0)
+         {
+           log_error ("write error: %s\n", strerror (errno));
+           return -1; /* write error */
+         }
+      length -= n;
+      buffer += n;
+    }
+  return 0;  /* Okay */
+}
+
+static int
+readn (int fd, void *buf, size_t buflen, size_t *ret_nread)
+{
+  size_t nleft = buflen;
+  int nread;
+  char *p;
+  
+  p = buf;
+  while (nleft > 0)
+    {
+      nread = ath_read (fd, buf, nleft);
+      if (nread < 0)
+        {
+          if (nread == EINTR)
+            nread = 0;
+          else 
+            return -1;
+        }
+      else if (!nread)
+        break; /* EOF */
+      nleft -= nread;
+      buf = (char*)buf + nread;
+    }
+  if (ret_nread)
+    *ret_nread = buflen - nleft;
+  return 0;
+}
+
+/* This functions requests REQ_NBYTES from the daemon.  If NONCE is
+   true, the data should be suited for a nonce.  If NONCE is FALSE,
+   data of random level LEVEL will be generated.  The retrieved random
+   data will be stored in BUFFER.  Returns error code.  */
+static gcry_error_t
+call_daemon (void *buffer, size_t req_nbytes, int nonce,
+	     enum gcry_random_level level)
+{
+  unsigned char buf[255];
+  gcry_error_t err;
+  size_t nbytes;
+  size_t nread;
+  int rc;
 
+  err = 0;
 
+  if (! req_nbytes)
+    return 0;
 
+  ath_mutex_lock (&daemon_lock);
 
+  do
+    {
+      /* Process in chunks.  */
+      nbytes = req_nbytes > sizeof (buf) ? sizeof (buf) : req_nbytes;
+      req_nbytes -= nbytes;
 
+      /* Construct request.  */
+      buf[0] = 3;
+      if (nonce)
+	buf[1] = 10;
+      else if (level == GCRY_VERY_STRONG_RANDOM)
+	buf[1] = 12;
+      else if (level == GCRY_STRONG_RANDOM)
+	buf[1] = 11;
+      buf[2] = nbytes;
 
+      /* Send request.  */
+      rc = writen (daemon_socket, buf, 3);
+      if (rc == -1)
+	{
+	  err = gcry_error_from_errno (errno);
+	  break;
+	}
+	
+      /* Retrieve response.  */
 
+      rc = readn (daemon_socket, buf, 2, &nread);
+      if (rc == -1)
+	{
+	  err = gcry_error_from_errno (errno);
+	  log_error ("read error: %s\n", gcry_strerror (err));
+	  break;
+	}
+      if (nread && buf[0])
+	{
+	  log_error ("random daemon returned error code %d\n", buf[0]);
+	  err = gcry_error (GPG_ERR_INTERNAL); /* ? */
+	  break;
+	}
+      if (nread != 2)
+	{
+	  log_error ("response too small\n");
+	  err = gcry_error (GPG_ERR_PROTOCOL_VIOLATION); /* ? */
+	  break;
+	}
 
+      //      if (1)			/* FIXME, verbose */
+      //	log_info ("received response with %d bytes of data\n", buf[1]);
 
+      if (buf[1] < nbytes)
+	{
+	  log_error ("error: server returned less bytes than requested\n");
+	  err = gcry_error (GPG_ERR_PROTOCOL_VIOLATION); /* ? */
+	  break;
+	}
+      else if (buf[1] > nbytes)
+	{
+	  log_error ("warning: server returned more bytes than requested\n");
+	  err = gcry_error (GPG_ERR_PROTOCOL_VIOLATION); /* ? */
+	  break;
+	}
 
+      assert (nbytes <= sizeof (buf));
 
+      rc = readn (daemon_socket, buf, nbytes, &nread);
+      if (rc == -1)
+	{
+	  err = gcry_error_from_errno (errno);
+	  log_error ("read error: %s\n", gcry_strerror (err));
+	  break;
+	}
+      
+      if (nread != nbytes)
+	{
+	  log_error ("too little random data read\n");
+	  err = gcry_error (GPG_ERR_INTERNAL);
+	  break;
+	}
 
+      /* Successfuly read another chunk of data.  */
+      memcpy (buffer, buf, nbytes);
+      buffer = ((char *) buffer) + nbytes;
+    }
+  while (req_nbytes);
 
+  ath_mutex_unlock (&daemon_lock);
 
+  return err;
+}
 
 /* Internal function to fill BUFFER with LENGTH bytes of random.  We
    support GCRY_STRONG_RANDOM and GCRY_VERY_STRONG_RANDOM here.
    Return 0 on success. */
 int
 _gcry_daemon_randomize (void *buffer, size_t length,
                         enum gcry_random_level level)
 {
-  return -1;
+  gcry_error_t err;
+
+  err = call_daemon (buffer, length, 0, level);
+
+  return err ? -1 : 0;
 }
 
 /* Internal function to return a pointer to a randomized buffer of
    LEVEL and NBYTES length.  Caller must free the buffer. With SECURE
    passed as TRUE, allocate the rwanom in secure memory - however note
    that the IPC mechanism might have not stored it there.  Return a
    pointer to a newly alloced memory or NULL if it failed.  */
 void *
 _gcry_daemon_get_random_bytes (size_t nbytes, int level, int secure)
 {
-  return NULL;
+  gcry_error_t err;
+  void *p;
+
+  err = _gcry_malloc (nbytes, secure ? GCRY_ALLOC_FLAG_SECURE : 0, &p);
+  if (err)
+    goto out;
+
+  err = call_daemon (p, nbytes, 0, level);
+
+ out:
+
+  if (err)
+    {
+      gcry_free (p);
+      p = NULL;
+    }
+
+  return p;
 }
 
 
 /* Internal function to fill BUFFER with NBYTES of data usable for a
    nonce.  Returns 0 on success. */
 int
 _gcry_daemon_create_nonce (void *buffer, size_t length)
 {
-  return -1;
+  gcry_error_t err;
+
+  err = call_daemon (buffer, length, 1, 0);
+
+  return err ? -1 : 0;
 }
+
+/* END */
diff --git a/cipher/random.c b/cipher/random.c
index ea69f4c9..039997d4 100644
--- a/cipher/random.c
+++ b/cipher/random.c
@@ -1,1281 +1,1292 @@
 /* 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 <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
 #include <errno.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
 #ifdef	HAVE_GETHRTIME
 #include <sys/times.h>
 #endif
 #ifdef HAVE_GETTIMEOFDAY
 #include <sys/times.h>
 #endif
 #ifdef HAVE_GETRUSAGE
 #include <sys/resource.h>
 #endif
 #ifdef __MINGW32__
 #include <process.h>
 #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 char *rndpool;	/* allocated size is POOLSIZE+BLOCKLEN */
 static 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;
 
 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) );
-      _gcry_daemon_initialize_basics ();
+      _gcry_daemon_initialize_basics (daemon_socket_name);
     }
 }
 
 
 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)
+{
+  if (daemon_socket_name)
+    BUG ();
+
+  daemon_socket_name = gcry_xstrdup (socketname);
+}
+
 /* 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)
 {
   int last;
-
+  
   /* FIXME: This is not really thread safe. */
   last = allow_daemon;
   if (onoff != -1)
     allow_daemon = onoff;
+
   return last;
 }
 
 
 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);
 
   if (allow_daemon && (p=_gcry_daemon_get_random_bytes (nbytes, level,secure)))
     return p; /* The daemon succeeded. */
 
   /* 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 (byte *buffer, size_t length, enum gcry_random_level level)
 {
   byte *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);
 
   if (allow_daemon && !_gcry_daemon_randomize (buffer, length, level))
     return; /* The daemon succeeded. */
 
   /* 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, that this function muts only be called with a locked pool.
  */
 static void
 mix_pool(byte *pool)
 {
   static unsigned char failsafe_digest[DIGESTLEN];
   static int failsafe_digest_valid;
 
   char *hashbuf = pool + POOLSIZE;
   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 && (char *)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 
         {
           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 ( (char*)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;
 
     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 (unsigned char *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. */
   unsigned char *p;
   size_t n;
   int err;
 
   /* Make sure we are initialized. */
   if (!is_initialized)
     initialize ();
 
   if (allow_daemon && !_gcry_daemon_create_nonce (buffer, length))
     return; /* The daemon succeeded. */
 
   /* 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));
 
   /* The first time intialize our buffer. */
   if (!nonce_buffer_initialized)
     {
       pid_t apid = getpid ();
       time_t atime = time (NULL);
 
       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, &apid, sizeof apid);
       p += sizeof apid;
       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 != getpid () )
     {
       /* 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);
     }
 
   /* 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 c87f46e3..afed64c7 100644
--- a/cipher/random.h
+++ b/cipher/random.h
@@ -1,51 +1,52 @@
 /* random.h - random functions
- *	Copyright (C) 1998, 2002 Free Software Foundation, Inc.
+ *	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);
 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) --*/
-void _gcry_daemon_initialize_basics (void);
+void _gcry_set_random_daemon_socket (const char *socketname);
+void _gcry_daemon_initialize_basics (const char *socketname);
 int _gcry_daemon_randomize (void *buffer, size_t length,
                             enum gcry_random_level level);
 void *_gcry_daemon_get_random_bytes (size_t nbytes, int level, int secure);
 int _gcry_daemon_create_nonce (void *buffer, size_t length);
 
 
 #endif /*G10_RANDOM_H*/
 
 
 
 
diff --git a/src/ChangeLog b/src/ChangeLog
index a2fb5cd3..f7c638cb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,1526 +1,1533 @@
+2006-04-22  Moritz Schulte  <moritz@g10code.com>
+
+	* gcrypt.h (enum 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-01  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <wk@g10code.com>
 
 	* getrandom.c: New.
 
 2006-03-14  Werner Koch  <wk@g10code.com>
 
 	* gcryptrnd.c: New.
 
 2006-03-10  Werner Koch  <wk@g10code.com>
 
 	* gcrypt.h: Add GCRY_MD_SHA224.
 
 2005-11-02  Moritz Schulte  <moritz@g10code.com>
 
 	* gcrypt.h: Update comments for functions: gcry_cipher_algo_name,
 	gcry_pk_algo_name.
 
 2005-10-31  Moritz Schulte  <moritz@g10code.com>
 
 	* global.c: Added documentation.
 
 2005-10-16  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* ath.c: Assign copyright to FSF.
 	* ath.h: Likewise.
 
 2005-06-25  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* global.c (gcry_xstrdup): Removed superfluous strcpy call.
 
 2005-04-22  Moritz Schulte  <moritz@g10code.com>
 
 	* Makefile.am (pkgconfigdir, pkgconfig_DATA): New; support for
 	pkgconfig provided by Albert Chin.
 	* libgcrypt.pc.in (Cflags): New file.
 
 2005-04-16  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <wk@g10code.com>
 
 	* sexp.c (whitespacep): New.
 	(sexp_sscan): Replaced isdigit and isspace by whitespacep and
 	digitp.
 
 2005-04-11  Moritz Schulte  <moritz@g10code.com>
 
 	* gcrypt.h (gcry_md_algos): Added: GCRY_MD_WHIRLPOOL.
 	* cipher.h (_gcry_digest_spec_whirlpool): Declare.
 
 2005-03-30  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* libgcrypt.vers: Added: gcry_ac_data_to_sexp() and
 	gcry_ac_data_from_sexp().
 
 2005-02-22  Werner Koch  <wk@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@g10code.com>
 
 	* gcrypt.h: Removed 3 trailing commas from enums.  Noted by Heiko
 	Stamer.
 
 2004-09-21  Werner Koch  <wk@g10code.de>
 
 	* sexp.c (sexp_sscan): Removed C++ style comments.  Noted by Yoann
 	Vandoorselaere.
 
 2004-08-23  Moritz Schulte  <moritz@g10code.com>
 
 	* global.c: Do not include <assert.h>. 
 	* sexp.c: Likewise.
 	* module.c: Likewise.
 	* misc.c: Likewise.
 
 2004-08-18  Moritz Schulte  <moritz@g10code.com>
 
 	* secmem.c (_gcry_secmem_init): Try to lock pool into core not
 	only when running with root privileges.
 
 2004-08-16  Werner Koch  <wk@g10code.de>
 
 	* 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  <moritz@g10code.com>
 
 	* gcrypt.h: Include <sys/time.h>, thanks to Simon Josefsson.
 
 2004-05-07  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h: Added GCRYCTL_FAST_POLL.
 	(gcry_fast_random_poll): New.
 	* global.c (gcry_control) <INITIALIZATION_FINISHED>: Do only basic
 	random subsystem init.
 	(gcry_control) <FAST_POLL>: New.
 
 2004-04-22  Marcus Brinkmann  <marcus@g10code.de>
 
 	* libgcrypt.m4: Quote first argument to AC_DEFUN.
 
 2004-04-15  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <marcus@g10code.de>
 
 	* libgcrypt-config.in (includedir, libdir): Quote'em.  Use
 	$gpg_error_cflags and $gpg_error_libs.  Fix construction of
 	$includes.
 
 2004-03-14  Marcus Brinkmann  <marcus@g10code.de>
 
 	* 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  <marcus@g10code.de>
 
 	* 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 <sys/types.h> and <sys/socket.h>.
 	(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  <wk@gnupg.org>
 
 	* libgcrypt-config.in: s/--soname-number/--api-version/
 	* libgcrypt.m4: Changed test for API version.
 
 2004-03-05  Werner Koch  <wk@gnupg.org>
 
 	* libgcrypt.m4: Optionally check the SONAME number.
 
 	* libgcrypt-config.in: Add option --soname-number
 
 2004-03-01  Marcus Brinkmann  <marcus@g10code.de>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* libgcrypt-config.in: Ignore setting of --prefix.
 
 2004-02-13  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h: Added GCRY_CIPHER_RFC2268_128, alsthough not yet
 	supported.
 
 2004-02-06  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h: Added GCRY_CIPHER_RFC2268_40.
 
 2004-02-03  Werner Koch  <wk@gnupg.org>
 
 	* 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  <mo@g10code.com>
 
 	* ath.h: Include <config.h>.
 
 2004-01-12  Moritz Schulte  <mo@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* g10lib.h (wipememory, wipememory2): New; taken from gnupg.
 
 2003-11-14  Werner Koch  <wk@gnupg.org>
 
 	* global.c (gcry_strdup): Don't copy the string after a malloc
 	error.
 
 2003-11-11  Werner Koch  <wk@gnupg.org>
 
 	* sexp.c (sexp_sscan): Implemented "%b" format specifier.
 
 2003-11-11  Moritz Schulte  <mo@g10code.com>
 
 	* libgcrypt.m4: Do not set prefix when calling libgcrypt-config.
 	Thanks to Nikos Mavroyanopoulos.
 
 2003-11-08  Moritz Schulte  <mo@g10code.com>
 
 	* cipher.h (small_prime_numbers): Removed declaration.
 	(PUBKEY_FLAG_NO_BLINDING): Put braces around shift.
 
 2003-11-04  Werner Koch  <wk@gnupg.org>
 
 	* cipher.h (_gcry_sha1_has_buffer): New.
 
 	* gcrypt.h (gcry_create_nonce): New.
 
 2003-10-31  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* ath.h (ATH_MUTEX_INITIALIZER): Removed spurious semicolon.
 
 2003-10-27  Moritz Schulte  <mo@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* gcrypt.h (gcry_pk_testkey): Doc fix.
 
 2003-09-29  Moritz Schulte  <mo@g10code.com>
 
 	* libgcrypt-config.in: Fix --algorithms option.
 
 2003-10-23  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* secmem.c (_gcry_secmem_dump_stats): Fixed format sepcifier for a
 	size_t.  Reported by Stephane Corthesy.
 
 2003-10-10  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* sexp.c (sexp_sscan): Check that parenthesis are matching.
 
 2003-09-28  Moritz Schulte  <mo@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* gcrypt.h (_GCRY_ERR_SOURCE_DEFAULT): Removed cruft.
 	(gcry_prime_check_func_t): Renamed arg for clarity.
 
 2003-09-02  Moritz Schulte  <mo@g10code.com>
 
 	* gcrypt.h (GCRY_PRIME_FLAG_SPECIAL_FACTOR): New symbol.
 
 2003-09-01  Moritz Schulte  <mo@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* Makefile.am (libgcrypt_pth_la_LDFLAGS): Removed PTH_CFLAGS cruft.
 
 2003-08-27  Moritz Schulte  <mo@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* module.c (_gcry_module_release): Don't act if module is NULL.
 
 2003-07-30  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <moritz@g10code.com>
 
 	* 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>.
 
 	* gcrypt-module.h: New file.
 
 2003-07-27  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h (gcry_mpi_scan, gcry_mpi_print): API change.
 	(gcry_mpi_dump): New.
 
 2003-07-21  Moritz Schulte  <moritz@g10code.com>
 
 	* gcrypt.h: Declared: gcry_ac_key_data_get.
 	(gcry_pk_spec): Renamed member `sexp_names' into `aliases'.
 
 2003-07-20  Moritz Schulte  <moritz@g10code.com>
 
 	* gcrypt.h (gcry_md_oid_spec_t): New type.
 	(gcry_md_spec): New member: oids.
 
 2003-07-19  Moritz Schulte  <moritz@g10code.com>
 
 	* gcrypt.h (gcry_cipher_oid_spec_t): New type.
 	(gcry_cipher_spec): New member: oids;
 
 2003-07-18  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h (gcry_mpi_set_opaque): Add a warning comment.
 
 2003-07-15  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* global.c: Use new types for handlers.
 
 	* gcrypt.h: Declare: gcry_ac_data_copy.
 
 2003-07-07  Moritz Schulte  <moritz@g10code.com>
 
 	* sexp.c (gcry_sexp_build_array): Use dummy argument pointer.
 	Thanks to Simon Josefsson <jas@extunde.com>.
 
 	* gcrypt.h: Declare: gcry_cipher_list, gcry_pk_list, gcry_md_list.
 	
 2003-07-05  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* module.c (_gcry_module_list): New function.
 
 2003-07-02  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* g10lib.h: Added declarations: _gcry_pk_module_lookup,
 	_gcry_pk_module_release.
 
 2003-06-18  Werner Koch  <wk@gnupg.org>
 
 	* 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  <moritz@g10code.com>
 
 	* 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 <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_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  <moritz@g10code.com>
 
 	* Makefile.am (AM_CFLAGS): Added: @GPG_ERROR_CFLAGS@.
 
 2003-06-16  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <moritz@g10code.com>
 
 	* Makefile.am: Support for libgpg-error.
 
 2003-06-08  Moritz Schulte  <moritz@g10code.com>
 
 	* sexp.c (gcry_sexp_create): Expect sane error values from
 	gcry_sexp_canon_len instead of the `historical' values.
 
 2003-06-07  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* gcrypt.h: Added some comments describing the gcry_sexp_*
 	functions.
 	Include <gpg-error.h> instead of <gpg/error.h>.
 
 2003-06-01  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* gcrypt.h (GCRY_CIPHER_SERPENT128, GCRY_CIPHER_SERPENT192,
 	GCRY_CIPHER_SERPENT256): New symbols.
 
 2003-05-19  Moritz Schulte  <moritz@g10code.com>
 
 	* gcrypt.h: Reversed changes from 2003-03-03 since they would have
 	been an unnecessary ABI break.
 
 2003-05-13  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* cipher.h (gcry_pubkey_spec): New member: sexp_names.
 
 2003-04-23  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* cipher.h: Declare digest_spec_sha512 and digest_spec_384.
 
 2003-04-16  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* benchmark.c (md_bench): Fix error message.
 
 2003-03-31  Moritz Schulte  <moritz@g10code.com>
 
 	* benchmark.c (cipher_bench): Added CTR mode.
 
 2003-03-30  Simon Josefsson  <jas@extundo.com>
 
 	* 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  <moritz@g10code.com>
 
 	* cipher.h (PUBKEY_FLAG_NO_BLINDING): New symbol.
 
 2003-03-22  Simon Josefsson  <jas@extundo.com>
 
 	* gcrypt.h: Add GCRYCTL_SET_CBC_MAC and GCRY_CIPHER_CBC_MAC.
 
 2003-03-19  Werner Koch  <wk@gnupg.org>
 
 	* g10lib.h: Adjusted primegen.c prototypes.
 
 2003-03-12  Werner Koch  <wk@gnupg.org>
 
 	* sexp.c (sexp_sscan): Initialize NM.  Thanks to Ian Peters for
 	valgrinding this.
 
 2003-03-06  Moritz Schulte  <mo@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* 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  <moritz@g10code.com>
 
 	* gcrypt.h (gcry_cipher_reset): New macro for resetting a handle.
 
 2003-02-28  Moritz Schulte  <moritz@g10code.com>
 
 	* secmem.c (DEFAULT_PAGESIZE): New symbol.
 	(init_pool): Use DEFAULT_PAGESIZE.
 
 2003-02-23  Moritz Schulte  <moritz@g10code.com>
 
 	* 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  <wk@gnupg.org>
 
 	* global.c (gcry_set_progress_handler): Register a random progress
 	handler.
 
 2003-01-23  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h (GCRY_ENABLE_QUICK_RANDOM): New. 
 	* global.c (gcry_control): Make use of it.
 
 2003-01-21  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h (gcry_random_add_bytes): Add QUALITY argument.
 
 2003-01-21  Timo Schulz  <twoaday@freakmail.de>
 
 	* gcrypt.h (gcry_random_add_bytes): New.
 	
 2003-01-20  Simon Josefsson  <jas@extundo.com>
 
 	* gcrypt.h (gcry_md_algos): Add GCRY_MD_CRC32,
 	GCRY_MD_CRC32_RFC1510, GCRY_MD_CRC24_RFC2440.
 
 2003-01-16  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* sexp.c (gcry_sexp_length): Fixed.  This was seriously broken.
 
 2003-01-14  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h (GCRYERR_INV_FLAG), global.c (gcry_strerror): New.
 
 2003-01-02  Werner Koch  <wk@gnupg.org>
 
 	* libgcrypt.vers: Temporary export _gcry_generate_elg_prime for
 	use by GNUTLS. 
 
 2002-12-21  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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) <initialization>: Call the random module
 	initializer to make sure that the pool lock flag has been
 	initialized.
 
 2002-12-09  Werner Koch  <wk@gnupg.org>
 
 	* global.c (gcry_calloc,gcry_calloc_secure): Check for overflow.
 	Noted by Florian Weimer. 
 
 2002-11-10  Simon Josefsson  <jas@extundo.com>
 
 	* 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  <wk@gnupg.org>
 
 	* gcrypt.h (GCRY_MD_MD4): New.  We use a non OpenPGP value here. 
 
 2002-09-20  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* ath.h: Prefix ath_deinit.
 
 2002-09-17  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* secmem.c (_gcry_secmem_dump_stats): Replaced fprintf by log_*.
 
 2002-08-23  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* gcrypt.h: Add GCRY_CIPGER_DES.  Included string.h for size_t.
 	Suggested by Simon Josefsson.
 
 2002-07-25  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* gcrypt.h: Added a bunch of brief function descriptions.
 
 2002-05-21  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	Changed license of all files to the LGPL.
 
 2002-05-07  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* global.c (gcry_strdup): New.
 
 2002-03-18  Werner Koch  <wk@gnupg.org>
 
 	* mutex.h: New file with a portable thread mutex implementation
 	written by Marcus Brinkmann.  Taken from GPGME.
 
 2002-02-18  Werner Koch  <wk@gnupg.org>
 
 	* sexp.c (gcry_sexp_sscan): Don't initialize the dummy
 	variable.  Suggested by Jordi Mallach.
 
 2002-01-31  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* libgcrypt-config.in: Add copyright notice.
 
 2002-01-11  Werner Koch  <wk@gnupg.org>
 
 	* sexp.c (gcry_sexp_canon_len): Fixed last change.
 
 2002-01-01  Timo Schulz <ts@winpt.org>
 
 	* stdmem.c (_gcry_private_realloc): If pointer is NULL now realloc
 	behaves like malloc.
 
 2001-12-20  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* sexp.c (gcry_sexp_canon_len): New.
 
 2001-12-11  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h: Fixed AES128 macro, add enum for OFB mode.
 
 2001-12-05  Werner Koch  <wk@gnupg.org>
 
 	* misc.c (_gcry_log_printf): New.
 	* sexp.c (dump_string,gcry_sexp_dump): Use logging functions
 	instead of stderr.
 
 2001-11-16  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h: New constant GCRYCTL_IS_ALGO_ENABLED.
 
 2001-10-02  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h: Removed a couple of trailing commas.
 
 2001-08-28  Werner Koch  <wk@gnupg.org>
 
 	* sexp.c (sexp_sscan): Add an argument to enable the
 	arg_ptr. Changed all callers.  Suggested by Tom Holroyd.
 
 2001-08-03  Werner Koch  <wk@gnupg.org>
 
 	* global.c (gcry_strerror): Updated list of error codes.
 
 2001-07-23  Werner Koch  <wk@gnupg.org>
 
 	* gcrypt.h: Replaced the last ulong.  Noted by Rami Lehti.
 
 2001-05-31  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* libgcrypt.m4: Check GCRYPT_VERSION macro and not LIBGCRYPT_VERSION.
 
 	* mpi.h: Removed mpi_fromstr prototype.
 
 2001-01-11  Werner Koch  <wk@gnupg.org>
 
 	* Makefile.am (libgcrypt_la_SOURCES): Add mpi.h
 
 2000-12-19  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@gnupg.org>
 
 	* mpi.h: Moved to ../mpi.
 
 	* Makefile.am (OMIT_DEPENDENCIES): Hack to work around dependency
 	problems.
 
 2000-10-11  Werner Koch  <wk@gnupg.org>
 
 	* mpi.h: Changed the way mpi_limb_t is defined.
 
 2000-10-10  Werner Koch  <wk@gnupg.org>
 
 	* Makefile.am: Take version-info from configure.
 
 2000-10-09  Werner Koch  <wk@gnupg.org>
 
 	* 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  <wk@openit.de>
 
         * gcrypt.h (gcry_md_setkey): Replaced macro by function prototype.
 
 Mon Sep 18 16:35:45 CEST 2000  Werner Koch  <wk@openit.de>
 
         * 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  <wk@openit.de>
 
   * 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  <wk@openit.de>
 
   * 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  <wk@openit.de>
 
   * 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  <wk@>
 
   * 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  <wk@gnupg.de>
 
 	* Makefile.am: Add g10lib.h
 
 Thu Jan 27 18:00:44 CET 2000  Werner Koch  <wk@gnupg.de>
 
 	* sexp.c (gcry_sexp_sscan): Allow NULL for erroff.
 
 Mon Jan 24 22:24:38 CET 2000  Werner Koch  <wk@gnupg.de>
 
 	* sexp.c (gcry_sexp_alist): New.
 
 Mon Jan 24 13:04:28 CET 2000  Werner Koch  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* 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  <wk@gnupg.de>
 
 	* gloabl.c (gcry_control): Add cases for dumping random
 	and secmem stats.
 
 Tue Oct 26 14:10:21 CEST 1999  Werner Koch  <wk@gnupg.de>
 
 	* pkapi.c: Removed.
 
 	* symapi.c: Removed.
 
 	* g10lib.h:  Moved to ../include.
 
 	* mdapi.c: Removed.
 
 Wed Jul  7 13:08:40 CEST 1999  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* sexp.c: New.
 
 Tue Dec  8 13:15:16 CET 1998  Werner Koch  <wk@isil.d.shuttle.de>
 
 	* 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/gcrypt.h b/src/gcrypt.h
index 30368a72..ba385623 100644
--- a/src/gcrypt.h
+++ b/src/gcrypt.h
@@ -1,1701 +1,1703 @@
 /* gcrypt.h -  GNU cryptographic library interface
  * 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
  */
 
 #ifndef _GCRYPT_H
 #define _GCRYPT_H
 
 #include <stdarg.h>
 #include <string.h>
 
 #include <gpg-error.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 
 /* 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.  Note: Do not edit the next line as
    configure may fix the string here.  */
 #define GCRYPT_VERSION "1.3.0-cvs"
 
 /* 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);
   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);
 };
 
 #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,		      \
 			    socklen_t *length_ptr)			      \
   { return pth_accept (s, addr, length_ptr); }				      \
 static int gcry_pth_connect (int s, struct sockaddr *addr, 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 }
 
 #define GCRY_THREAD_OPTION_PTHREAD_IMPL					      \
 static int gcry_pthread_mutex_init (void **priv)			      \
 {									      \
   int err = 0;								      \
   pthread_mutex_t *lock = 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 (*lock);  free (*lock); return err; }     \
 static int gcry_pthread_mutex_lock (void **lock)			      \
   { return pthread_mutex_lock (*lock); }				      \
 static int gcry_pthread_mutex_unlock (void **lock)			      \
   { return pthread_mutex_unlock (*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 }
 
 
 /* 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_FAST_POLL = 48,
+    GCRYCTL_SET_RANDOM_DAEMON_SOCKET = 49,
+    GCRYCTL_USE_RANDOM_DAEMON = 50
   };
 
 /* 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, char *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 unsigned char *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). */
   };
 
 /* 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,
                                  unsigned char *out, size_t outsize,
                                  const unsigned char *in, size_t inlen);
 
 /* The counterpart to gcry_cipher_encrypt.  */
 gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t h,
                                  unsigned char *out, size_t outsize,
                                  const unsigned char *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
 #define GCRY_PK_USAGE_ENCR 2
 
 /* 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_MD4     = 301,
     GCRY_MD_CRC32               = 302,
     GCRY_MD_CRC32_RFC1510       = 303,
     GCRY_MD_CRC24_RFC2440       = 304,
     GCRY_MD_WHIRLPOOL = 305,
     GCRY_MD_SHA224  = 306
   };
 
 /* 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 digets object HD. */
 gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd, unsigned char *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. */
 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);
 
 /* 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 digets object A; i.e. create files named
    dbgmd-<n>.<string> while hashing.  B is a string used as the suffix
    for the filename. */
 #define gcry_md_start_debug(a,b) \
             gcry_md_ctl( (a), GCRYCTL_START_DUMP, (b), 0 )
 
 /* Disable the debugging of A. */
 #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_<algorithm>_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.  */
 gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t algorithm,
                                 const char **name);
 
 /* Store the numeric ID of the algorithm whose textual representation
    is contained in NAME in ALGORITHM.  */
 gcry_error_t gcry_ac_name_to_id (const char *name,
                                 gcry_ac_id_t *algorithm);
 
 
 
 /************************************
  *                                  *
  *   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 (unsigned char *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 (unsigned char *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 <gcrypt-module.h>
 
 #if 0 /* keep Emacsens' auto-indent happy */
 {
 #endif
 #ifdef __cplusplus
 }
 #endif
 #endif /* _GCRYPT_H */
diff --git a/src/global.c b/src/global.c
index 8dd2657c..399fc769 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1,745 +1,756 @@
 /* global.c  -	global control functions
  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
  *               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
  */
 
 #include <config.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
 #include <ctype.h>
 #include <limits.h>
 #include <errno.h>
 
 #include "g10lib.h"
 #include "cipher.h"
 #include "stdmem.h" /* our own memory allocator */
 #include "secmem.h" /* our own secmem allocator */
 #include "ath.h"
 
 
 
 /****************
  * flag bits: 0 : general cipher debug
  *	      1 : general MPI debug
  */
 static unsigned int debug_flags;
 
 /* Controlled by global_init().  */
 static int any_init_done;
 
 /* Memory management. */
 
 static gcry_handler_alloc_t alloc_func;
 static gcry_handler_alloc_t alloc_secure_func;
 static gcry_handler_secure_check_t is_secure_func;
 static gcry_handler_realloc_t realloc_func;
 static gcry_handler_free_t free_func;
 static gcry_handler_no_mem_t outofcore_handler;
 static void *outofcore_handler_value;
 static int no_secure_memory;
 
 
 
 /* This is our handmade constructor.  It gets called by any function
    likely to be called at startup.  The suggested way for an
    application to make sure that this has been called is by using
    gcry_check_version. */
 static void
 global_init (void)
 {
   gcry_error_t err = 0;
 
   if (any_init_done)
     return;
   any_init_done = 1;
 
   err = ath_init ();
   if (err)
     goto fail;
   err = _gcry_cipher_init ();
   if (err)
     goto fail;
   err = _gcry_md_init ();
   if (err)
     goto fail;
   err = _gcry_pk_init ();
   if (err)
     goto fail;
 #if 0
   /* FIXME? */
   err = _gcry_ac_init ();
   if (err)
     goto fail;
 #endif
 
   return;
 
  fail:
   /* FIXME: use `err'?  */
   BUG ();
 }
 
 
 
 /* Version number parsing.  */
 
 /* This function parses the first portion of the version number S and
    stores it in *NUMBER.  On sucess, this function returns a pointer
    into S starting with the first character, which is not part of the
    initial number portion; on failure, NULL is returned.  */
 static const char*
 parse_version_number( const char *s, int *number )
 {
     int val = 0;
 
     if( *s == '0' && isdigit(s[1]) )
 	return NULL; /* leading zeros are not allowed */
     for ( ; isdigit(*s); s++ ) {
 	val *= 10;
 	val += *s - '0';
     }
     *number = val;
     return val < 0? NULL : s;
 }
 
 /* This function breaks up the complete string-representation of the
    version number S, which is of the following struture: <major
    number>.<minor number>.<micro number><patch level>.  The major,
    minor and micro number components will be stored in *MAJOR, *MINOR
    and *MICRO.
 
    On success, the last component, the patch level, will be returned;
    in failure, NULL will be returned.  */
 
 static const char *
 parse_version_string( const char *s, int *major, int *minor, int *micro )
 {
     s = parse_version_number( s, major );
     if( !s || *s != '.' )
 	return NULL;
     s++;
     s = parse_version_number( s, minor );
     if( !s || *s != '.' )
 	return NULL;
     s++;
     s = parse_version_number( s, micro );
     if( !s )
 	return NULL;
     return s; /* patchlevel */
 }
 
 /* If REQ_VERSION is non-NULL, check that the version of the library
    is at minimum the requested one.  Returns the string representation
    of the library version if the condition is satisfied; return NULL
    if the requested version is newer than that of the library.
 
    If a NULL is passed to this function, no check is done, but the
    string representation of the library is simply returned.  */
 const char *
 gcry_check_version( const char *req_version )
 {
     const char *ver = VERSION;
     int my_major, my_minor, my_micro;
     int rq_major, rq_minor, rq_micro;
     const char *my_plvl, *rq_plvl;
 
     /* Initialize library.  */
     global_init ();
 
     if ( !req_version )
         /* Caller wants our version number.  */
 	return ver;
 
     /* Parse own version number.  */
     my_plvl = parse_version_string( ver, &my_major, &my_minor, &my_micro );
     if ( !my_plvl )
         /* very strange our own version is bogus.  Shouldn't we use
 	   assert() here and bail out in case this happens?  -mo.  */
 	return NULL;
 
   /* Parse requested version number.  */
     rq_plvl = parse_version_string( req_version, &rq_major, &rq_minor,
 								&rq_micro );
     if ( !rq_plvl )
         /* req version string is invalid, this can happen.  */
 	return NULL;
 
     /* Compare version numbers.  */
     if ( my_major > rq_major
 	|| (my_major == rq_major && my_minor > rq_minor)
 	|| (my_major == rq_major && my_minor == rq_minor
 				 && my_micro > rq_micro)
 	|| (my_major == rq_major && my_minor == rq_minor
 				 && my_micro == rq_micro
 				 && strcmp( my_plvl, rq_plvl ) >= 0) ) {
 	return ver;
     }
 
     return NULL;
 }
 
 
 
 /* Command dispatcher function, acting as general control
    function.  */
 gcry_error_t
 gcry_control (enum gcry_ctl_cmds cmd, ...)
 {
   gcry_err_code_t err = GPG_ERR_NO_ERROR;
   static int init_finished = 0;
   va_list arg_ptr;
   
   va_start (arg_ptr, cmd);
   switch (cmd)
     {
     case GCRYCTL_ENABLE_M_GUARD:
       _gcry_private_enable_m_guard ();
       break;
 
     case GCRYCTL_ENABLE_QUICK_RANDOM:
       _gcry_quick_random_gen (1);
       break;
 
     case GCRYCTL_DUMP_RANDOM_STATS:
       _gcry_random_dump_stats ();
       break;
 
     case GCRYCTL_DUMP_MEMORY_STATS:
       /*m_print_stats("[fixme: prefix]");*/
       break;
 
     case GCRYCTL_DUMP_SECMEM_STATS:
       _gcry_secmem_dump_stats ();
       break;
 
     case GCRYCTL_DROP_PRIVS:
       global_init ();
       _gcry_secmem_init (0);
       break;
 
     case GCRYCTL_DISABLE_SECMEM:
       global_init ();
       no_secure_memory = 1;
       break;    
 
     case GCRYCTL_INIT_SECMEM:
       global_init ();
       _gcry_secmem_init (va_arg (arg_ptr, unsigned int));
       break;
 
     case GCRYCTL_TERM_SECMEM:
       global_init ();
       _gcry_secmem_term ();
       break;
 
     case GCRYCTL_DISABLE_SECMEM_WARN:
       _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
 			       | GCRY_SECMEM_FLAG_NO_WARNING));
       break;
 
     case GCRYCTL_SUSPEND_SECMEM_WARN:
       _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
 			       | GCRY_SECMEM_FLAG_SUSPEND_WARNING));
       break;
 
     case GCRYCTL_RESUME_SECMEM_WARN:
       _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
 			       & ~GCRY_SECMEM_FLAG_SUSPEND_WARNING));
       break;
 
     case GCRYCTL_USE_SECURE_RNDPOOL:
       global_init ();
       _gcry_secure_random_alloc (); /* put random number into secure memory */
       break;
 
     case GCRYCTL_SET_RANDOM_SEED_FILE:
       _gcry_set_random_seed_file (va_arg (arg_ptr, const char *));
       break;
 
     case GCRYCTL_UPDATE_RANDOM_SEED_FILE:
       _gcry_update_random_seed_file ();
       break;
 
     case GCRYCTL_SET_VERBOSITY:
       _gcry_set_log_verbosity (va_arg (arg_ptr, int));
       break;
 
     case GCRYCTL_SET_DEBUG_FLAGS:
       debug_flags |= va_arg (arg_ptr, unsigned int);
       break;
 
     case GCRYCTL_CLEAR_DEBUG_FLAGS:
       debug_flags &= ~va_arg (arg_ptr, unsigned int);
       break;
 
     case GCRYCTL_DISABLE_INTERNAL_LOCKING:
       global_init ();
       break;
 
     case GCRYCTL_ANY_INITIALIZATION_P:
       if (any_init_done)
 	err = GPG_ERR_GENERAL;
       break;
 
     case GCRYCTL_INITIALIZATION_FINISHED_P:
       if (init_finished)
 	err = GPG_ERR_GENERAL;
       break;
 
     case GCRYCTL_INITIALIZATION_FINISHED:
       /* This is a hook which should be used by an application after
 	 all initialization has been done and right before any threads
 	 are started.  It is not really needed but the only way to be
 	 really sure that all initialization for thread-safety has
 	 been done. */
         if (! init_finished)
 	  {
             global_init ();
             /* Do only a basic random initialization, i.e. init the
                mutexes. */
             _gcry_random_initialize (0);
             init_finished = 1;
 	  }
         break;
 
     case GCRYCTL_SET_THREAD_CBS:
       err = ath_install (va_arg (arg_ptr, void *), any_init_done);
       if (! err)
 	global_init ();
       break;
 
     case GCRYCTL_FAST_POLL:
       /* We need to do make sure that the random pool is really
          initialized so that the poll fucntion is not a NOP. */
       _gcry_random_initialize (1);
       _gcry_fast_random_poll (); 
       break;
 
+    case GCRYCTL_SET_RANDOM_DAEMON_SOCKET:
+      _gcry_set_random_daemon_socket (va_arg (arg_ptr, const char *));
+      break;
+
+    case GCRYCTL_USE_RANDOM_DAEMON:
+      /* We need to do make sure that the random pool is really
+         initialized so that the poll fucntion is not a NOP. */
+      _gcry_random_initialize (1);
+      _gcry_use_random_daemon (!! va_arg (arg_ptr, int));
+      break;
+
     default:
       err = GPG_ERR_INV_OP;
     }
 
   va_end(arg_ptr);
   return gcry_error (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 gpg_strerror (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)
 {
   return gpg_strsource (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)
 {
   return gpg_err_code_from_errno (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 gpg_err_code_from_errno (code);
 }
 
   
 /* Return an error value with the error source SOURCE and the system
    error ERR.  */
 gcry_error_t
 gcry_err_make_from_errno (gpg_err_source_t source, int err)
 {
   return gpg_err_make_from_errno (source, err);
 }
 
 
 /* Return an error value with the system error ERR.  */
 gcry_err_code_t
 gcry_error_from_errno (int err)
 {
   return gcry_error (gpg_err_code_from_errno (err));
 }
 
 /****************
  * NOTE: All 5 functions should be set.  */
 void
 gcry_set_allocation_handler (gcry_handler_alloc_t new_alloc_func,
 			     gcry_handler_alloc_t new_alloc_secure_func,
 			     gcry_handler_secure_check_t new_is_secure_func,
 			     gcry_handler_realloc_t new_realloc_func,
 			     gcry_handler_free_t new_free_func)
 {
   global_init ();
 
   alloc_func = new_alloc_func;
   alloc_secure_func = new_alloc_secure_func;
   is_secure_func = new_is_secure_func;
   realloc_func = new_realloc_func;
   free_func = new_free_func;
 }
 
 
 
 /****************
  * Set an optional handler which is called in case the xmalloc functions
  * ran out of memory.  This handler may do one of these things:
  *   o free some memory and return true, so that the xmalloc function
  *     tries again.
  *   o Do whatever it like and return false, so that the xmalloc functions
  *     use the default fatal error handler.
  *   o Terminate the program and don't return.
  *
  * The handler function is called with 3 arguments:  The opaque value set with
  * this function, the requested memory size, and a flag with these bits
  * currently defined:
  *	bit 0 set = secure memory has been requested.
  */
 void
 gcry_set_outofcore_handler( int (*f)( void*, size_t, unsigned int ),
 							void *value )
 {
     global_init ();
 
     outofcore_handler = f;
     outofcore_handler_value = value;
 }
 
 gcry_err_code_t
 _gcry_malloc (size_t n, unsigned int flags, void **mem)
 {
   gcry_err_code_t err = 0;
   void *m;
 
   if ((flags & GCRY_ALLOC_FLAG_SECURE) && !no_secure_memory)
     {
       if (alloc_secure_func)
 	m = (*alloc_secure_func) (n);
       else
 	m = _gcry_private_malloc_secure (n);
     }
   else
     {
       if (alloc_func)
 	m = (*alloc_func) (n);
       else
 	m = _gcry_private_malloc (n);
     }
 
   if (!m)
     {
       /* Make sure that ERRNO has been set in case a user supplied
          memory handler didn't it correctly. */
       if (!errno)
         errno = ENOMEM;
       err = gpg_err_code_from_errno (errno);
     }
   else
     *mem = m;
 
   return err;
 }
   
 void *
 gcry_malloc (size_t n)
 {
   void *mem = NULL;
 
   _gcry_malloc (n, 0, &mem);
 
   return mem;
 }
 
 void *
 gcry_malloc_secure (size_t n)
 {
   void *mem = NULL;
 
   _gcry_malloc (n, GCRY_ALLOC_FLAG_SECURE, &mem);
 
   return mem;
 }
 
 int
 gcry_is_secure (const void *a)
 {
   if (no_secure_memory)
     return 0;
   if (is_secure_func)
     return is_secure_func (a) ;
   return _gcry_private_is_secure (a);
 }
 
 void
 _gcry_check_heap( const void *a )
 {
     /* FIXME: implement this*/
 #if 0
     if( some_handler )
 	some_handler(a)
     else
 	_gcry_private_check_heap(a)
 #endif
 }
 
 void *
 gcry_realloc (void *a, size_t n)
 {
   void *p;
 
   if (realloc_func)
     p = realloc_func (a, n);
   else
     p =  _gcry_private_realloc (a, n);
   if (!p && !errno)
     errno = ENOMEM;
   return p;
 }
 
 void
 gcry_free( void *p )
 {
   if( !p )
     return;
 
   if (free_func)
     free_func (p);
   else
     _gcry_private_free (p);
 }
 
 void *
 gcry_calloc (size_t n, size_t m)
 {
   size_t bytes;
   void *p;
 
   bytes = n * m; /* size_t is unsigned so the behavior on overflow is
                     defined. */
   if (m && bytes / m != n) 
     {
       errno = ENOMEM;
       return NULL;
     }
 
   p = gcry_malloc (bytes);
   if (p)
     memset (p, 0, bytes);
   return p;
 }
 
 void *
 gcry_calloc_secure (size_t n, size_t m)
 {
   size_t bytes;
   void *p;
 
   bytes = n * m; /* size_t is unsigned so the behavior on overflow is
                     defined. */
   if (m && bytes / m != n) 
     {
       errno = ENOMEM;
       return NULL;
     }
   
   p = gcry_malloc_secure (bytes);
   if (p)
     memset (p, 0, bytes);
   return p;
 }
 
 
 /* Create and return a copy of the null-terminated string STRING.  If
    it is contained in secure memory, the copy will be contained in
    secure memory as well.  In an out-of-memory condition, NULL is
    returned.  */
 char *
 gcry_strdup (const char *string)
 {
   char *string_cp = NULL;
   size_t string_n = 0;
 
   string_n = strlen (string);
 
   if (gcry_is_secure (string))
     string_cp = gcry_malloc_secure (string_n + 1);
   else
     string_cp = gcry_malloc (string_n + 1);
   
   if (string_cp)
     strcpy (string_cp, string);
 
   return string_cp;
 }
 
 
 void *
 gcry_xmalloc( size_t n )
 {
     void *p;
 
     while ( !(p = gcry_malloc( n )) ) {
 	if( !outofcore_handler
 	    || !outofcore_handler( outofcore_handler_value, n, 0 ) ) {
 	    _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL );
 	}
     }
     return p;
 }
 
 void *
 gcry_xrealloc( void *a, size_t n )
 {
     void *p;
 
     while ( !(p = gcry_realloc( a, n )) ) {
 	if( !outofcore_handler
 	    || !outofcore_handler( outofcore_handler_value, n, 2 ) ) {
 	    _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL );
 	}
     }
     return p;
 }
 
 void *
 gcry_xmalloc_secure( size_t n )
 {
     void *p;
 
     while ( !(p = gcry_malloc_secure( n )) ) {
 	if( !outofcore_handler
 	    || !outofcore_handler( outofcore_handler_value, n, 1 ) ) {
 	    _gcry_fatal_error(gpg_err_code_from_errno (errno),
 			     _("out of core in secure memory"));
 	}
     }
     return p;
 }
 
 void *
 gcry_xcalloc( size_t n, size_t m )
 {
     void *p = gcry_xmalloc( n*m );
     memset( p, 0, n*m );
     return p;
 }
 
 void *
 gcry_xcalloc_secure( size_t n, size_t m )
 {
     void *p = gcry_xmalloc_secure( n* m );
     memset( p, 0, n*m );
     return p;
 }
 
 char *
 gcry_xstrdup (const char *string)
 {
   char *p;
 
   while ( !(p = gcry_strdup (string)) ) 
     {
       size_t n = strlen (string);
       int is_sec = !!gcry_is_secure (string);
 
       if (!outofcore_handler
           || !outofcore_handler (outofcore_handler_value, n, is_sec) ) 
         {
           _gcry_fatal_error (gpg_err_code_from_errno (errno),
                              is_sec? _("out of core in secure memory"):NULL);
 	}
     }
 
   return p;
 }
 
 
 int
 _gcry_get_debug_flag( unsigned int mask )
 {
     return debug_flags & mask;
 }
 
 
 
 /* It is often useful to get some feedback of long running operations.
    This function may be used to register a handler for this. 
    The callback function CB is used as:
 
    void cb (void *opaque, const char *what, int printchar,
            int current, int total);
 
    Where WHAT is a string identifying the the type of the progress
    output, PRINTCHAR the character usually printed, CURRENT the amount
    of progress currently done and TOTAL the expected amount of
    progress.  A value of 0 for TOTAL indicates that there is no
    estimation available.
 
    Defined values for WHAT:
 
    "need_entropy"  X    0  number-of-bytes-required
             When running low on entropy
    "primegen"      '\n'  0 0
            Prime generated
                    '!'
            Need to refresh the prime pool
                    '<','>'
            Number of bits adjusted
                    '^'
            Looking for a generator
                    '.'
            Fermat tests on 10 candidates failed
                   ':'
            Restart with a new random value
                   '+'
            Rabin Miller test passed          
    "pk_elg"        '+','-','.','\n'   0  0
             Only used in debugging mode.
    "pk_dsa"       
             Only used in debugging mode.
 */
 void
 gcry_set_progress_handler (void (*cb)(void *,const char*,int, int, int),
                            void *cb_data)
 {
 #if USE_DSA
   _gcry_register_pk_dsa_progress (cb, cb_data);
 #endif
 #if USE_ELGAMAL
   _gcry_register_pk_elg_progress (cb, cb_data);
 #endif
   _gcry_register_primegen_progress (cb, cb_data);
   _gcry_register_random_progress (cb, cb_data);
 }