summaryrefslogtreecommitdiff
path: root/lib/random.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-08-09 08:24:59 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-08-16 09:39:52 +0200
commitd2e49df8ebc1b3a7e3a28059c099174365e0a546 (patch)
tree6078fd18d2ac02783e64ed0f93cacedf883dc327 /lib/random.c
parent11196e76849d671284936540f063846aeab21604 (diff)
downloadgnutls-d2e49df8ebc1b3a7e3a28059c099174365e0a546.tar.gz
fuzzer: added a fuzzer target
This allows to compile the library with flags which will add predictable random generation and eliminate some crypto checks, in order for the library to be used for testing (fuzzying). Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/random.c')
-rw-r--r--lib/random.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/random.c b/lib/random.c
index 2fe82adc7d..0c05dbe187 100644
--- a/lib/random.c
+++ b/lib/random.c
@@ -37,6 +37,9 @@
# error Unsupported platform
#endif
+#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
+extern gnutls_crypto_rnd_st _gnutls_fuzz_rnd_ops;
+#endif
/* Per thread context of random generator, and a flag to indicate initialization */
static _Thread_local void *gnutls_rnd_ctx;
@@ -100,7 +103,13 @@ int _gnutls_rnd_preinit(void)
{
int ret;
-#ifdef ENABLE_FIPS140
+#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
+# warning Insecure PRNG is enabled
+ ret = gnutls_crypto_rnd_register(100, &_gnutls_fuzz_rnd_ops);
+ if (ret < 0)
+ return ret;
+
+#elif defined(ENABLE_FIPS140)
/* The FIPS140 random generator is only enabled when we are compiled
* with FIPS support, _and_ the system requires FIPS140.
*/