]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added gnutls_rnd_refresh().
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 27 Jan 2013 10:51:05 +0000 (11:51 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 27 Jan 2013 10:52:25 +0000 (11:52 +0100)
NEWS
lib/crypto-backend.h
lib/gnutls_state.c
lib/includes/gnutls/crypto.h
lib/nettle/rnd.c
lib/random.c
lib/random.h

diff --git a/NEWS b/NEWS
index 9f5c9c8f02053eca9002c1b82709db2eac21193d..68c924e0cc841fbd70a3cc457767da29aea4f188 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,7 +14,8 @@ in a template from an RFC4514 string.
 ** libgnutls: Added functions to directly set the DN in a certificate
 or request from an RFC4514 string.
 
-** libgnutls: Optimizations in the nonce level of the random generator.
+** libgnutls: Optimizations in the random generator. The re-seeding of
+it is now explicitly done on every session deinit.
 
 ** libgnutls: Simplified the DTLS sliding window implementation.
 
@@ -53,6 +54,7 @@ gnutls_range_split: Added
 gnutls_record_send_range: Added
 gnutls_record_set_max_empty_records: Added
 gnutls_record_can_use_length_hiding: Added
+gnutls_rnd_refresh: Added
 GNUTLS_SEC_PARAM_EXPORT: Added
 GNUTLS_SEC_PARAM_VERY_WEAK: Added
 
index 58c7530c0efb56a5668a50af872e6378c5ffe6e2..f807ce5d203cfcb1825952b72b548398f897d59a 100644 (file)
@@ -80,6 +80,7 @@
   {
     int (*init) (void **ctx);
     int (*rnd) (void *ctx, int level, void *data, size_t datasize);
+    void (*rnd_refresh) (void *ctx);
     void (*deinit) (void *ctx);
   } gnutls_crypto_rnd_st;
 
index 06560328ce2169e724daecb2f6c97f46f1fc9514..652b46e30aba861a6af53e5cd19680835a767367 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002-2012 Free Software Foundation, Inc.
+ * Copyright (C) 2002-2013 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -45,6 +45,7 @@
 #include <gnutls_rsa_export.h>
 #include <gnutls_extensions.h>
 #include <system.h>
+#include <random.h>
 #include <gnutls/dtls.h>
 #include <timespec.h>
 
@@ -432,6 +433,8 @@ gnutls_deinit (gnutls_session_t session)
   if (session == NULL)
     return;
 
+  _gnutls_rnd_refresh();
+
   /* remove auth info firstly */
   _gnutls_free_auth_info (session);
 
index c8d5755e4e7703eac016d30ac6daa533a694b58f..93db48ce96026bed5ec0ce98eb2294ca6d2f9c2d 100644 (file)
@@ -99,6 +99,8 @@ extern "C"
 
   int gnutls_rnd (gnutls_rnd_level_t level, void *data, size_t len);
 
+  void gnutls_rnd_refresh (void);
+
 #ifdef __cplusplus
 }
 #endif
index 0894473f1faf51f75f84fb6549f5aa1a90457a85..a1c6b4ec6314553feade1dc580764bb64281472e 100644 (file)
@@ -437,15 +437,16 @@ wrap_nettle_rnd (void *_ctx, int level, void *data, size_t datasize)
   int ret;
 
   RND_LOCK;
-  gettime(&current_time);
 
   /* update state only when having a non-nonce or if nonce
    * and nsecs%4096 == 0, i.e., one out of 4096 times called .
    *
    * The reason we do that is to avoid any delays when generating nonces.
    */
-  if (level != GNUTLS_RND_NONCE || ((current_time.tv_nsec & 0x0fff) == 0))
+  if (level != GNUTLS_RND_NONCE)
     {
+      gettime(&current_time);
+
       ret = do_trivia_source (0);
       if (ret < 0)
         {
@@ -468,10 +469,24 @@ wrap_nettle_rnd (void *_ctx, int level, void *data, size_t datasize)
   return 0;
 }
 
+static void
+wrap_nettle_rnd_refresh (void *_ctx)
+{
+  RND_LOCK;
+  gettime(&current_time);
+
+  do_trivia_source (0);
+  do_device_source (0);
+
+  RND_UNLOCK;
+  return;
+}
+
 int crypto_rnd_prio = INT_MAX;
 
 gnutls_crypto_rnd_st _gnutls_rnd_ops = {
   .init = wrap_nettle_rnd_init,
   .deinit = wrap_nettle_rnd_deinit,
   .rnd = wrap_nettle_rnd,
+  .rnd_refresh = wrap_nettle_rnd_refresh,
 };
index 06b08dba60004d66cee3bfe270cb863ce6236875..3af03befeb99cd0b4ce35386a2c0e3b705f71e3a 100644 (file)
@@ -73,3 +73,20 @@ gnutls_rnd (gnutls_rnd_level_t level, void *data, size_t len)
 {
   return _gnutls_rnd(level, data, len);
 }
+
+/**
+ * gnutls_rnd_refresh:
+ *
+ * This function refreshes the random generator state.
+ * That is the current precise time, CPU usage, and
+ * other values are input into its state.
+ *
+ * On a slower rate input from /dev/urandom is mixed too.
+ *
+ * Since: 3.1.7
+ **/
+void
+gnutls_rnd_refresh ()
+{
+  _gnutls_rnd_refresh();
+}
index 3d24363f2ce238d0309e88bbce15ea3a17cd0605..3a514f13f4b17fc658856a61d152bda88896724f 100644 (file)
@@ -40,6 +40,12 @@ _gnutls_rnd (gnutls_rnd_level_t level, void *data, size_t len)
   return 0;
 }
 
+inline static void
+_gnutls_rnd_refresh (void)
+{
+  _gnutls_rnd_ops.rnd_refresh (gnutls_rnd_ctx);
+}
+
 void _gnutls_rnd_deinit (void);
 int _gnutls_rnd_init (void);