Subversion Repositories

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

Rev 45 | Details | Compare with Previous | Last modification | View Log | RSS feed

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