summaryrefslogtreecommitdiff
path: root/random/random.c
AgeCommit message (Collapse)AuthorFilesLines
2016-02-19random: Use our symbol name pattern also for drbg functions.Werner Koch1-10/+10
* random/random-drbg.c: Rename global functions from _gcry_drbg_* to _gcry_rngdrbg_*. * random/random.c: Adjust for this change. * src/global.c: Ditto. Signed-off-by: Werner Koch <wk@gnupg.org>
2016-02-18random: Add SP800-90A DRBGStephan Mueller1-49/+10
* random/drbg.c: New. * random/random.c (_gcry_random_initialize): Replace rngfips init by drbg init. (__gcry_random_close_fds): Likewise. (_gcry_random_dump_stats): Likewise. (_gcry_random_is_faked): Likewise. (do_randomize): Likewise. (_gcry_random_selftest): Likewise. (_gcry_create_nonce): Replace rngfips_create_noce by drbg_randomize. (_gcry_random_init_external_test): Remove. (_gcry_random_run_external_test): Remove. (_gcry_random_deinit_external_test): Remove. * random/random.h (struct gcry_drbg_test_vector): New. * src/gcrypt.h.in (struct gcry_drbg_gen): New. (struct gcry_drbg_string): New. (gcry_drbg_string_fill): New. (gcry_randomize_drbg): New. (GCRY_DRBG_): Lots of new macros. * src/global.c (_gcry_vcontrol) <Init external random test>: Turn into a nop. (_gcry_vcontrol) <Deinit external random test>: Ditto. (_gcry_vcontrol) <Run external random test>: Change. (_gcry_vcontrol) <GCRYCTL_DRBG_REINIT>: New. -- This patch set adds the SP800-90A DRBG for AES128, AES192, AES256 with derivation function, SHA-1 through SHA-512 with derivation function, HMAC SHA-1 through HMAC SHA-512. All DRBGs are provided with and without prediction resistance. In addition, all DRBGs allow reseeding by the caller. The default DRBG is HMAC SHA-256 without prediction resistance. The caller may re-initialize the DRBG with the control GCRYCTL_DRBG_REINIT: The patch replaces the invocation of the existing ANSI X9.31 DRNG. This covers the control calls of 58 through 60. Control call 58 and 60 are simply deactivated. Control 59 is replaced with the DRBG CAVS test interface. Signed-off-by: Stephan Mueller <smueller@chronox.de> ChangeLog entries added by -wk
2014-01-16Replace ath based mutexes by gpgrt based locks.Werner Koch1-18/+5
* configure.ac (NEED_GPG_ERROR_VERSION): Require 1.13. (gl_LOCK): Remove. * src/ath.c, src/ath.h: Remove. Remove from all files. Replace all mutexes by gpgrt based statically initialized locks. * src/global.c (global_init): Remove ath_init. (_gcry_vcontrol): Make ath install a dummy function. (print_config): Remove threads info line. * doc/gcrypt.texi: Simplify the multi-thread related documentation. -- The current code does only work on ELF systems with weak symbol support. In particular no locks were used under Windows. With the new gpgrt_lock functions from the soon to be released libgpg-error 1.13 we have a better portable scheme which also allows for static initialized mutexes. Signed-off-by: Werner Koch <wk@gnupg.org>
2013-12-12Remove macro hacks for internal vs. external functions. Part 2 and last.Werner Koch1-2/+2
* src/visibility.h: Remove remaining define/undef hacks for symbol visibility. Add macros to detect the use of the public functions. Change all affected functions by replacing them by the x-macros. * src/g10lib.h: Add internal prototypes. (xtrymalloc, xtrycalloc, xtrymalloc_secure, xtrycalloc_secure) (xtryrealloc, xtrystrdup, xmalloc, xcalloc, xmalloc_secure) (xcalloc_secure, xrealloc, xstrdup, xfree): New macros. -- The use of xmalloc/xtrymalloc/xfree is a more common pattern than the gcry_free etc. functions. Those functions behave like those defined by C and thus for better readability we use these macros and not the underscore prefixed functions. Signed-off-by: Werner Koch <wk@gnupg.org>
2013-12-11random: Add a feature to close device file descriptors.Werner Koch1-0/+21
* src/gcrypt.h.in (GCRYCTL_CLOSE_RANDOM_DEVICE): New. * src/global.c (_gcry_vcontrol): Call _gcry_random_close_fds. * random/random.c (_gcry_random_close_fds): New. * random/random-csprng.c (_gcry_rngcsprng_close_fds): New. * random/random-fips.c (_gcry_rngfips_close_fds): New. * random/random-system.c (_gcry_rngsystem_close_fds): New. * random/rndlinux.c (open_device): Add arg retry. (_gcry_rndlinux_gather_random): Add mode to close open fds. * tests/random.c (check_close_random_device): New. (main): Call new test. Signed-off-by: Werner Koch <wk@gnupg.org>
2013-12-05Remove macro hacks for internal vs. external functions. Part 1.Werner Koch1-9/+9
* src/visibility.h: Remove almost all define/undef hacks for symbol visibility. Add macros to detect the use of the public functions. Change all affected functions by prefixing them explicitly with an underscore and change all internal callers to call the underscore prefixed versions. Provide convenience macros from sexp and mpi functions. * src/visibility.c: Change all functions to use only gpg_err_code_t and translate to gpg_error_t only in visibility.c. -- The use of the macro magic made if hard to follow the function calls in the source. It was not easy to see if an internal or external function (as defined by visibility.c) was called. The change is quite large but hopefully makes Libgcrypt easier to maintain. Some function have not yet been fixed; this will be done soon. Because Libgcrypt does no make use of any other libgpg-error using libraries it is useless to always translate between gpg_error_t and gpg_err_code_t (i.e with and w/o error source identifier). This translation has no mostly be moved to the function wrappers in visibility.c. An additional advantage of using gpg_err_code_t is that comparison can be done without using gpg_err_code(). I am sorry for that large patch, but a series of patches would actually be more work to audit. Signed-off-by: Werner Koch <wk@gnupg.org>
2012-12-03random: Add a RNG selection interface and system RNG wrapper.Werner Koch1-5/+121
* random/random-system.c: New. * random/Makefile.am (librandom_la_SOURCES): Add new module. * random/random.c (struct rng_types): New. (_gcry_set_preferred_rng_type, _gcry_get_rng_type): New. (_gcry_random_initialize, gcry_random_add_bytes, do_randomize) (_gcry_set_random_seed_file, _gcry_update_random_seed_file) (_gcry_fast_random_poll): Dispatch to the actual RNG. * src/gcrypt.h.in (GCRYCTL_SET_PREFERRED_RNG_TYPE): New. GCRYCTL_GET_CURRENT_RNG_TYPE): New. (gcry_rng_types): New. * src/global.c (print_config): Print the TNG type. (global_init, _gcry_vcontrol): Implement the new control codes. * doc/gcrypt.texi (Controlling the library): Document the new control codes. * tests/benchmark.c (main): Add options to test the RNG types. * tests/random.c (main): Add new options. (print_hex): Print to stderr. (progress_cb, rng_type): New. (check_rng_type_switching, check_early_rng_type_switching): New. (run_all_rng_tests): New. -- The purpose of this change is to allow applications with moderate random requirements to use the system's RNG (e.g. /dev/urandom). The type switching logic makes sure that existing applications won't be affected by this change. A library is in almost all cases not able to degrade the quality of the RNG. The definition of "degrade" comes from our own assertion of the quality/trustworthiness of the RNGs: The most trustworthy RNG is the CSPRNG which dates back to the early GnuPG days. It is quite conservative and often requires more seeding than might be justified. GCRY_RNG_TYPE_STANDARD is the default unless the process is in FIPS mode. The second trustworthy RNG is the FIPS recommended X9.81 AES based implementation. It is seeded by the system's RNG. GCRY_RNG_TYPE_FIPS is the only available RNG if running in FIPS mode. The third trustworthy RNG is a mere wrapper around the system's native RNG. Thus there is no extra step on top of what, for example, /dev/random provides. GCRY_RNG_TYPE_SYSTEM may be used by applications which would use /dev/random or /dev/urandom instead.
2012-12-03Move nonce creation from csprng backend to random main module.Werner Koch1-4/+103
* random/random-csprng.c (_gcry_rngcsprng_create_nonce): Remove. (nonce_buffer_lock): Remove. (initialize_basics): Remove init of nonce_buffer_lock. * random/random.c: Add a few header files. (nonce_buffer_lock): New. (_gcry_random_initialize): Init nonce_buffer_lock. (gcry_create_nonce): Add code from _gcry_rngcsprng_create_nonce. * random/random-daemon.c (_gcry_daemon_create_nonce): Remove. -- The nonce generation code is useful for all RNG types and thus it should be in random.c. The only exception is the fips-mode, which requires the use of the fips nonce generator.
2011-02-04Nuked almost all trailing whitespace.Werner Koch1-4/+4
Check and install the standard git pre-commit hook.
2010-11-04Doc fixes.Werner Koch1-2/+2
Started some work on dumpsexp.
2010-04-12Applied spelling fixes and more verbose test diagnositcs by Brad Hards.Werner Koch1-4/+4
2009-01-22PreparingWerner Koch1-1/+1
2008-09-16Another tweak for the RNG test code.Werner Koch1-1/+1
2008-09-15Use syslog to log important messages.Werner Koch1-0/+38
Add an external RNG test hook.
2008-09-05Let the test suite run the selftests even in non-fips mode.Werner Koch1-1/+1
2008-08-22Completed the RNG implementaion switching.Werner Koch1-25/+49
Added framework for running RNG tests. Added an experimental option --enable-hmac-binary-check to configure. --This line, and those below, will be ignored-- M src/fips.c M src/cipher-proto.h M src/global.c M src/hmac256.c M src/ChangeLog M src/hmac256.h M src/Makefile.am M tests/Makefile.am M configure.ac M doc/gcrypt.texi M random/random-fips.c M random/random.c M random/rand-internal.h M random/random.h M random/ChangeLog M ChangeLog M README
2008-08-21Finished the X9.31 RNG implementations.Werner Koch1-1/+1
2008-08-20Replace assert calls by a new gcry_assert at most places.Werner Koch1-1/+0
2008-08-19A whole bunch of changes to eventually support Werner Koch1-1263/+79
FIPS restricted mode. Also some documentation improvements and other minor enhancements. See the ChangeLogs. Stay tuned.
2008-07-05Moved random stuff into its own directory.Werner Koch1-0/+1446