Subversion Repositories

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

Rev 47 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#! /bin/sh /usr/share/dpatch/dpatch-run
## 02_smartlink_rpath.dpatch
##
## DP: Changes from CVS to make the Nettle module compile with Nettle 2.0

@DPATCH@

diff -urad Pike-v7.8.316/src/post_modules/Nettle/cipher.cmod pike-cvs/7.8/src/post_modules/Nettle/cipher.cmod
--- Pike-v7.8.316/src/post_modules/Nettle/cipher.cmod   2008-07-31 16:52:27.000000000 +0200
+++ pike-cvs/7.8/src/post_modules/Nettle/cipher.cmod    2009-07-02 18:35:38.000000000 +0200
@@ -79,8 +86,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) {             \
@@ -90,8 +97,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
@@ -175,7 +182,7 @@
 PIKECLASS CipherState
 {
   INHERIT CipherInfo;
-  CVAR nettle_crypt_func crypt;
+  CVAR nettle_crypt_func *crypt;
   CVAR void *ctx;
   CVAR int key_size;
 
diff -urad Pike-v7.8.316/src/post_modules/Nettle/nettle.cmod pike-cvs/7.8/src/post_modules/Nettle/nettle.cmod
--- Pike-v7.8.316/src/post_modules/Nettle/nettle.cmod   2008-06-29 00:57:14.000000000 +0200
+++ pike-cvs/7.8/src/post_modules/Nettle/nettle.cmod    2009-07-05 21:41:58.000000000 +0200
@@ -46,6 +46,21 @@
   CVAR struct yarrow256_ctx ctx;
   CVAR struct yarrow_source *sources;
 
+  PIKEVAR string seed_file flags ID_PRIVATE|ID_STATIC;
+
+  DECLARE_STORAGE;
+
+  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
@@ -90,10 +120,12 @@
     optflags OPT_SIDE_EFFECT;
   {
     if(data->len < YARROW256_SEED_FILE_SIZE)
-      Pike_error( "Seed must be at least 32 characters.\n" );
+      Pike_error("Seed must be at least %d characters.\n",
+                YARROW256_SEED_FILE_SIZE);
 
     NO_WIDE_STRING(data);
-    yarrow256_seed(&THIS->ctx, data->len, (const uint8_t *)data->str);
+    yarrow256_seed(&THIS->ctx, data->len, STR0(data));
+    pike_generate_seed_file();
     RETURN this_object();
   }
 
@@ -109,19 +141,26 @@
     RETURN YARROW256_SEED_FILE_SIZE;
   }
 
-  /*! @decl string get_seed()
-   *! Returns part of the internal state so that it can
-   *! be saved for later seeding.
+  /*! @decl string(0..255) get_seed()
+   *!   Returns part of the internal state so that it can
+   *!   be saved for later seeding.
+   *!
    *! @seealso
-   *!   @[seed]
+   *!   @[seed()], @[random_string()]
    */
   PIKEFUN string get_seed()
     optflags OPT_EXTERNAL_DEPEND;
+    rawtype tDeprecated(tFunc(tNone, tStr8));
   {
     if( !yarrow256_is_seeded(&THIS->ctx) )
       Pike_error("Random generator not seeded.\n");
-    RETURN make_shared_binary_string((const char *)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()
@@ -144,7 +188,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 )
@@ -166,8 +223,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,
-                            (const uint8_t *)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()
diff -urad Pike-v7.8.316/src/post_modules/Nettle/testsuite.in pike-cvs/7.8/src/post_modules/Nettle/testsuite.in
--- Pike-v7.8.316/src/post_modules/Nettle/testsuite.in  2007-06-18 02:43:51.000000000 +0200
+++ pike-cvs/7.8/src/post_modules/Nettle/testsuite.in   2009-08-05 12:01:45.000000000 +0200
@@ -193,4 +193,14 @@
   }
 )
 ]])
+
+cond_resolv( Nettle.Yarrow, [[
+  test_any_equal([[
+    object y = Nettle.Yarrow()->seed("What happen? Somebody set up us the bomb.");
+    return ({ y->get_seed(), y->random_string(20), y->get_seed(), y->random_string(20) });
+  ]], [[({String.hex2string("73a35b2f896a8061be0ad434a592a43a82b81b9ed6c018f1c5a51300bbc8d53d"),
+         String.hex2string("7847458e32fb789ff6b6cd6e1c8cc3712ba532a8"),
+         String.hex2string("73a35b2f896a8061be0ad434a592a43a82b81b9ed6c018f1c5a51300bbc8d53d"),
+         String.hex2string("49a090656a6d93782e169994f41005a3616d3cd7")})]])
+]])
 END_MARKER