Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#! /bin/sh /usr/share/dpatch/dpatch-run
## nettle_2.0.dpatch by  <holmgren@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
diff -urNad 7.6-stable~/src/post_modules/Nettle/cipher.cmod 7.6-stable/src/post_modules/Nettle/cipher.cmod
--- 7.6-stable~/src/post_modules/Nettle/cipher.cmod     2004-02-21 19:36:35.000000000 +0100
+++ 7.6-stable/src/post_modules/Nettle/cipher.cmod      2009-08-18 21:51:38.000000000 +0200
@@ -69,8 +69,8 @@
   pike_nettle_set_key_func set_encrypt_key;
   pike_nettle_set_key_func set_decrypt_key;
 
-  nettle_crypt_func encrypt;
-  nettle_crypt_func decrypt;
+  nettle_crypt_func *encrypt;
+  nettle_crypt_func *decrypt;
 };
 
 #define _PIKE_CIPHER(name, NAME) {             \
@@ -80,8 +80,8 @@
   NAME##_KEY_SIZE,                             \
   pike_##name##_set_encrypt_key,               \
   pike_##name##_set_decrypt_key,               \
-  (nettle_crypt_func) name##_encrypt,          \
-  (nettle_crypt_func) name##_decrypt,          \
+  (nettle_crypt_func*) name##_encrypt,         \
+  (nettle_crypt_func*) name##_decrypt,         \
 }
 
 /*! @class CipherInfo
@@ -165,7 +165,7 @@
 PIKECLASS CipherState
 {
   INHERIT CipherInfo;
-  CVAR nettle_crypt_func crypt;
+  CVAR nettle_crypt_func *crypt;
   CVAR void *ctx;
   CVAR int key_size;
 
diff -urNad 7.6-stable~/src/post_modules/Nettle/nettle.cmod 7.6-stable/src/post_modules/Nettle/nettle.cmod
--- 7.6-stable~/src/post_modules/Nettle/nettle.cmod     2005-12-11 19:01:46.000000000 +0100
+++ 7.6-stable/src/post_modules/Nettle/nettle.cmod      2009-08-18 21:51:38.000000000 +0200
@@ -46,6 +46,19 @@
   CVAR struct yarrow256_ctx ctx;
   CVAR struct yarrow_source *sources;
 
+  PIKEVAR string seed_file flags ID_PRIVATE|ID_STATIC;
+
+  static void pike_generate_seed_file(void)
+  {
+    struct pike_string *seed_file =
+      begin_shared_string(YARROW256_SEED_FILE_SIZE);
+    yarrow256_random(&THIS->ctx, YARROW256_SEED_FILE_SIZE, STR0(seed_file));
+    if (THIS->seed_file) {
+      free_string(THIS->seed_file);
+    }
+    THIS->seed_file = end_shared_string(seed_file);
+  }
+
   /*! @decl void create(void|int sources)
    *! The number of entropy sources that will feed entropy to the
    *! random number generator is given as an argument to Yarrow
@@ -93,6 +106,7 @@
 
     NO_WIDE_STRING(data);
     yarrow256_seed(&THIS->ctx, data->len, data->str);
+    pike_generate_seed_file();
     RETURN this_object();
   }
 
@@ -119,8 +133,12 @@
   {
     if( !yarrow256_is_seeded(&THIS->ctx) )
       Pike_error("Random generator not seeded.\n");
-    RETURN make_shared_binary_string(THIS->ctx.seed_file,
-                                    YARROW256_SEED_FILE_SIZE);
+    if (THIS->seed_file) {
+      REF_RETURN THIS->seed_file;
+    } else {
+      struct pike_string *s = begin_shared_string(YARROW256_SEED_FILE_SIZE);
+      RETURN end_shared_string(s);
+    }
   }
 
   /*! @decl int(0..1) is_seeded()
@@ -143,7 +161,8 @@
   PIKEFUN void force_reseed()
     optflags OPT_SIDE_EFFECT;
   {
-    yarrow256_force_reseed(&THIS->ctx);
+    yarrow256_slow_reseed(&THIS->ctx);
+    pike_generate_seed_file();
   }
 
   /*! @decl int(0..1) update(string data, int source, int entropy)
@@ -156,6 +212,7 @@
   PIKEFUN int(0..1) update(string data, int source, int entropy)
     optflags OPT_SIDE_EFFECT;
   {
+    int ret;
     /* FIXME: Wide strings could actually be supported here */
     NO_WIDE_STRING(data);
     if( !THIS->sources )
@@ -165,7 +184,11 @@
       Pike_error("Entropy must be positive.\n");
     if( entropy>(data->len*8) )
       Pike_error("Impossibly large entropy value.\n");
-    RETURN yarrow256_update(&THIS->ctx, source, entropy, data->len, data->str);
+    ret = yarrow256_update(&THIS->ctx, source, entropy, data->len,
+                          (const uint8_t *)data->str);
+    if (ret)
+      pike_generate_seed_file();
+    RETURN ret;
   }
 
   /*! @decl int(0..) needed_sources()