Subversion Repositories

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

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
48 holmgren 1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## nettle_2.0.dpatch by  <holmgren@debian.org>
3
##
4
## DP: Changes from CVS to make the Nettle module compile with Nettle 2.0
5
 
6
@DPATCH@
7
diff -urNad 7.6-stable~/src/post_modules/Nettle/cipher.cmod 7.6-stable/src/post_modules/Nettle/cipher.cmod
8
--- 7.6-stable~/src/post_modules/Nettle/cipher.cmod	2004-02-21 19:36:35.000000000 +0100
9
+++ 7.6-stable/src/post_modules/Nettle/cipher.cmod	2009-08-18 21:51:38.000000000 +0200
10
@@ -69,8 +69,8 @@
11
   pike_nettle_set_key_func set_encrypt_key;
12
   pike_nettle_set_key_func set_decrypt_key;
13
 
14
-  nettle_crypt_func encrypt;
15
-  nettle_crypt_func decrypt;
16
+  nettle_crypt_func *encrypt;
17
+  nettle_crypt_func *decrypt;
18
 };
19
 
20
 #define _PIKE_CIPHER(name, NAME) {		\
21
@@ -80,8 +80,8 @@
22
   NAME##_KEY_SIZE,				\
23
   pike_##name##_set_encrypt_key,		\
24
   pike_##name##_set_decrypt_key,		\
25
-  (nettle_crypt_func) name##_encrypt,		\
26
-  (nettle_crypt_func) name##_decrypt,		\
27
+  (nettle_crypt_func*) name##_encrypt,		\
28
+  (nettle_crypt_func*) name##_decrypt,		\
29
 }
30
 
31
 /*! @class CipherInfo
32
@@ -165,7 +165,7 @@
33
 PIKECLASS CipherState
34
 {
35
   INHERIT CipherInfo;
36
-  CVAR nettle_crypt_func crypt;
37
+  CVAR nettle_crypt_func *crypt;
38
   CVAR void *ctx;
39
   CVAR int key_size;
40
 
41
diff -urNad 7.6-stable~/src/post_modules/Nettle/nettle.cmod 7.6-stable/src/post_modules/Nettle/nettle.cmod
42
--- 7.6-stable~/src/post_modules/Nettle/nettle.cmod	2005-12-11 19:01:46.000000000 +0100
43
+++ 7.6-stable/src/post_modules/Nettle/nettle.cmod	2009-08-18 21:51:38.000000000 +0200
44
@@ -46,6 +46,19 @@
45
   CVAR struct yarrow256_ctx ctx;
46
   CVAR struct yarrow_source *sources;
47
 
48
+  PIKEVAR string seed_file flags ID_PRIVATE|ID_STATIC;
49
+
50
+  static void pike_generate_seed_file(void)
51
+  {
52
+    struct pike_string *seed_file =
53
+      begin_shared_string(YARROW256_SEED_FILE_SIZE);
54
+    yarrow256_random(&THIS->ctx, YARROW256_SEED_FILE_SIZE, STR0(seed_file));
55
+    if (THIS->seed_file) {
56
+      free_string(THIS->seed_file);
57
+    }
58
+    THIS->seed_file = end_shared_string(seed_file);
59
+  }
60
+
61
   /*! @decl void create(void|int sources)
62
    *! The number of entropy sources that will feed entropy to the
63
    *! random number generator is given as an argument to Yarrow
64
@@ -93,6 +106,7 @@
65
 
66
     NO_WIDE_STRING(data);
67
     yarrow256_seed(&THIS->ctx, data->len, data->str);
68
+    pike_generate_seed_file();
69
     RETURN this_object();
70
   }
71
 
72
@@ -119,8 +133,12 @@
73
   {
74
     if( !yarrow256_is_seeded(&THIS->ctx) )
75
       Pike_error("Random generator not seeded.\n");
76
-    RETURN make_shared_binary_string(THIS->ctx.seed_file,
77
-				     YARROW256_SEED_FILE_SIZE);
78
+    if (THIS->seed_file) {
79
+      REF_RETURN THIS->seed_file;
80
+    } else {
81
+      struct pike_string *s = begin_shared_string(YARROW256_SEED_FILE_SIZE);
82
+      RETURN end_shared_string(s);
83
+    }
84
   }
85
 
86
   /*! @decl int(0..1) is_seeded()
87
@@ -143,7 +161,8 @@
88
   PIKEFUN void force_reseed()
89
     optflags OPT_SIDE_EFFECT;
90
   {
91
-    yarrow256_force_reseed(&THIS->ctx);
92
+    yarrow256_slow_reseed(&THIS->ctx);
93
+    pike_generate_seed_file();
94
   }
95
 
96
   /*! @decl int(0..1) update(string data, int source, int entropy)
97
@@ -156,6 +212,7 @@
98
   PIKEFUN int(0..1) update(string data, int source, int entropy)
99
     optflags OPT_SIDE_EFFECT;
100
   {
101
+    int ret;
102
     /* FIXME: Wide strings could actually be supported here */
103
     NO_WIDE_STRING(data);
104
     if( !THIS->sources )
105
@@ -165,7 +184,10 @@
106
       Pike_error("Entropy must be positive.\n");
107
     if( entropy>(data->len*8) )
108
       Pike_error("Impossibly large entropy value.\n");
109
-    RETURN yarrow256_update(&THIS->ctx, source, entropy, data->len, data->str);
110
+    ret = yarrow256_update(&THIS->ctx, source, entropy, data->len, data->str);
111
+    if (ret)
112
+      pike_generate_seed_file();
113
+    RETURN ret;
114
   }
115
 
116
   /*! @decl int(0..) needed_sources()
117
diff -urad 7.6-stable~/src/post_modules/Nettle/testsuite.in 7.6-stable/7.8/src/post_modules/Nettle/testsuite.in
118
--- 7.6-stable~/src/post_modules/Nettle/testsuite.in	2007-06-18 02:43:51.000000000 +0200
119
+++ 7.6-stable/src/post_modules/Nettle/testsuite.in	2009-08-05 12:01:45.000000000 +0200
120
@@ -193,4 +193,14 @@
121
   }
122
 )
123
 ]])
124
+
125
+cond_resolv( Nettle.Yarrow, [[
126
+  test_any_equal([[
127
+    object y = Nettle.Yarrow()->seed("What happen? Somebody set up us the bomb.");
128
+    return ({ y->get_seed(), y->random_string(20), y->get_seed(), y->random_string(20) });
129
+  ]], [[({String.hex2string("73a35b2f896a8061be0ad434a592a43a82b81b9ed6c018f1c5a51300bbc8d53d"),
130
+	  String.hex2string("7847458e32fb789ff6b6cd6e1c8cc3712ba532a8"),
131
+	  String.hex2string("73a35b2f896a8061be0ad434a592a43a82b81b9ed6c018f1c5a51300bbc8d53d"),
132
+	  String.hex2string("49a090656a6d93782e169994f41005a3616d3cd7")})]])
133
+]])