Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
47 | holmgren | 1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
2 | ## 02_smartlink_rpath.dpatch |
||
3 | ## |
||
4 | ## DP: Patch from CVS to make the Nettle module compile with Nettle 2.0 |
||
5 | |||
6 | @DPATCH@ |
||
7 | |||
8 | diff -urad Pike-v7.8.316/src/post_modules/Nettle/acconfig.h pike-cvs/7.8/src/post_modules/Nettle/acconfig.h |
||
9 | --- Pike-v7.8.316/src/post_modules/Nettle/acconfig.h 2004-02-21 06:07:35.000000000 +0100 |
||
10 | +++ pike-cvs/7.8/src/post_modules/Nettle/acconfig.h 2009-07-02 18:35:38.000000000 +0200 |
||
11 | @@ -1 +1,5 @@ |
||
12 | +/* Define this if your struct yarrow256_ctx has the field seed_file. */ |
||
13 | +#undef HAVE_STRUCT_YARROW256_CTX_SEED_FILE |
||
14 | |||
15 | +/* Define this if the nettle_crypt_func typedef is a pointer type. */ |
||
16 | +#undef HAVE_NETTLE_CRYPT_FUNC_IS_POINTER |
||
17 | diff -urad Pike-v7.8.316/src/post_modules/Nettle/cipher.cmod pike-cvs/7.8/src/post_modules/Nettle/cipher.cmod |
||
18 | --- Pike-v7.8.316/src/post_modules/Nettle/cipher.cmod 2008-07-31 16:52:27.000000000 +0200 |
||
19 | +++ pike-cvs/7.8/src/post_modules/Nettle/cipher.cmod 2009-07-02 18:35:38.000000000 +0200 |
||
20 | @@ -65,6 +65,13 @@ |
||
21 | /* Force means to use key even if it is weak */ |
||
22 | int force); |
||
23 | |||
24 | +#ifdef HAVE_NETTLE_CRYPT_FUNC_IS_POINTER |
||
25 | +typedef nettle_crypt_func crypt_func; |
||
26 | +#else |
||
27 | +/* Nettle 2.0 */ |
||
28 | +typedef nettle_crypt_func *crypt_func; |
||
29 | +#endif |
||
30 | + |
||
31 | struct pike_cipher |
||
32 | { |
||
33 | const char *name; |
||
34 | @@ -79,8 +86,8 @@ |
||
35 | pike_nettle_set_key_func set_encrypt_key; |
||
36 | pike_nettle_set_key_func set_decrypt_key; |
||
37 | |||
38 | - nettle_crypt_func encrypt; |
||
39 | - nettle_crypt_func decrypt; |
||
40 | + crypt_func encrypt; |
||
41 | + crypt_func decrypt; |
||
42 | }; |
||
43 | |||
44 | #define _PIKE_CIPHER(name, NAME) { \ |
||
45 | @@ -90,8 +97,8 @@ |
||
46 | NAME##_KEY_SIZE, \ |
||
47 | pike_##name##_set_encrypt_key, \ |
||
48 | pike_##name##_set_decrypt_key, \ |
||
49 | - (nettle_crypt_func) name##_encrypt, \ |
||
50 | - (nettle_crypt_func) name##_decrypt, \ |
||
51 | + (crypt_func) name##_encrypt, \ |
||
52 | + (crypt_func) name##_decrypt, \ |
||
53 | } |
||
54 | |||
55 | /*! @class CipherInfo |
||
56 | @@ -175,7 +182,7 @@ |
||
57 | PIKECLASS CipherState |
||
58 | { |
||
59 | INHERIT CipherInfo; |
||
60 | - CVAR nettle_crypt_func crypt; |
||
61 | + CVAR crypt_func crypt; |
||
62 | CVAR void *ctx; |
||
63 | CVAR int key_size; |
||
64 | |||
65 | diff -urad Pike-v7.8.316/src/post_modules/Nettle/configure.in pike-cvs/7.8/src/post_modules/Nettle/configure.in |
||
66 | --- Pike-v7.8.316/src/post_modules/Nettle/configure.in 2008-07-17 12:53:20.000000000 +0200 |
||
67 | +++ pike-cvs/7.8/src/post_modules/Nettle/configure.in 2009-07-02 23:27:56.000000000 +0200 |
||
68 | @@ -54,6 +54,52 @@ |
||
69 | AC_MSG_RESULT([no]) |
||
70 | IDEA_OBJ="" |
||
71 | fi |
||
72 | + |
||
73 | + # These might have been purged from the Nettle lib to avoid GPL |
||
74 | + # contamination. |
||
75 | + AC_CHECK_FUNCS(nettle_blowfish_decrypt nettle_serpent_decrypt) |
||
76 | + |
||
77 | + # This is the recomended interface in Nettle 2.0. |
||
78 | + AC_CHECK_FUNCS(nettle_yarrow256_slow_reseed) |
||
79 | + |
||
80 | + AC_MSG_CHECKING([for struct yarrow256_ctx.seed_file]) |
||
81 | + AC_CACHE_VAL(pike_cv_nettle_struct_yarrow256_ctx_seed_file, [ |
||
82 | + pike_cv_nettle_struct_yarrow256_ctx_seed_file=no |
||
83 | + AC_TRY_COMPILE([ |
||
84 | +#include <nettle/yarrow.h> |
||
85 | + ], [ |
||
86 | + struct yarrow256_ctx ctx; |
||
87 | + return !sizeof(ctx.seed_file); |
||
88 | + ], [ |
||
89 | + pike_cv_nettle_struct_yarrow256_ctx_seed_file=yes |
||
90 | + ]) |
||
91 | + ]) |
||
92 | + AC_MSG_RESULT($pike_cv_nettle_struct_yarrow256_ctx_seed_file); |
||
93 | + if test "x$pike_cv_nettle_struct_yarrow256_ctx_seed_file" = "xyes"; then |
||
94 | + AC_DEFINE(HAVE_STRUCT_YARROW256_CTX_SEED_FILE) |
||
95 | + fi |
||
96 | + |
||
97 | + AC_MSG_CHECKING([whether nettle_crypt_func is a pointer type]) |
||
98 | + AC_CACHE_VAL(pike_cv_nettle_crypt_func_is_pointer, [ |
||
99 | + pike_cv_nettle_crypt_func_is_pointer=no |
||
100 | + AC_TRY_COMPILE([ |
||
101 | +/* Note: Old Nettles had the nettle_crypt_func typedef directly |
||
102 | + * in <nettle/nettle-meta.h> while more modern have it in |
||
103 | + * <nettle/nettle-types.h>. Since <nettle/nettle-meta.h> |
||
104 | + * pulls in <nettle/nettle-types.h> it should be sufficient. |
||
105 | + */ |
||
106 | +#include <nettle/nettle-meta.h> |
||
107 | + ], [ |
||
108 | + nettle_crypt_func foo = (nettle_crypt_func)(void *)0; |
||
109 | + return (int)foo; |
||
110 | + ], [ |
||
111 | + pike_cv_nettle_crypt_func_is_pointer=yes |
||
112 | + ]) |
||
113 | + ]) |
||
114 | + AC_MSG_RESULT($pike_cv_nettle_crypt_func_is_pointer); |
||
115 | + if test "x$pike_cv_nettle_crypt_func_is_pointer" = "xyes"; then |
||
116 | + AC_DEFINE(HAVE_NETTLE_CRYPT_FUNC_IS_POINTER) |
||
117 | + fi |
||
118 | else |
||
119 | if test "$ac_cv_lib_gmp_mpz_init:$ac_cv_lib_gmp___mpz_init:$ac_cv_lib_gmp___gmpz_init" = "no:no:no"; then |
||
120 | # No gmp found; enable it if possible. |
||
121 | @@ -76,10 +122,6 @@ |
||
122 | ]) |
||
123 | PIKE_FEATURE_NODEP(Nettle) |
||
124 | fi |
||
125 | - |
||
126 | - # These might have been purged from the Nettle lib to avoid GPL |
||
127 | - # contamination. |
||
128 | - AC_CHECK_FUNCS(nettle_blowfish_decrypt nettle_serpent_decrypt) |
||
129 | fi |
||
130 | |||
131 | AC_OUTPUT(Makefile,echo FOO >stamp-h ) |
||
132 | diff -urad Pike-v7.8.316/src/post_modules/Nettle/nettle.cmod pike-cvs/7.8/src/post_modules/Nettle/nettle.cmod |
||
133 | --- Pike-v7.8.316/src/post_modules/Nettle/nettle.cmod 2008-06-29 00:57:14.000000000 +0200 |
||
134 | +++ pike-cvs/7.8/src/post_modules/Nettle/nettle.cmod 2009-07-05 21:41:58.000000000 +0200 |
||
135 | @@ -46,6 +46,36 @@ |
||
136 | CVAR struct yarrow256_ctx ctx; |
||
137 | CVAR struct yarrow_source *sources; |
||
138 | |||
139 | +#ifndef HAVE_STRUCT_YARROW256_CTX_SEED_FILE |
||
140 | + /* NOTE: Nettle 2.0 does not have the automatic seed_file maintenance |
||
141 | + * that Nettle 1.x had. This stuff is needed since it affected |
||
142 | + * the state emitted by random_string(). When Nettle 2.0 is the |
||
143 | + * default, consider implementing this via overloading of the |
||
144 | + * various seeding functions instead, since it does have a bit |
||
145 | + * of overhead. |
||
146 | + * |
||
147 | + * /grubba 2009-07-05 |
||
148 | + */ |
||
149 | + PIKEVAR string seed_file flags ID_PRIVATE|ID_STATIC; |
||
150 | +#endif |
||
151 | + |
||
152 | + DECLARE_STORAGE; |
||
153 | + |
||
154 | +#ifndef HAVE_STRUCT_YARROW256_CTX_SEED_FILE |
||
155 | + static void pike_generate_seed_file(void) |
||
156 | + { |
||
157 | + struct pike_string *seed_file = |
||
158 | + begin_shared_string(YARROW256_SEED_FILE_SIZE); |
||
159 | + yarrow256_random(&THIS->ctx, YARROW256_SEED_FILE_SIZE, STR0(seed_file)); |
||
160 | + if (THIS->seed_file) { |
||
161 | + free_string(THIS->seed_file); |
||
162 | + } |
||
163 | + THIS->seed_file = end_shared_string(seed_file); |
||
164 | + } |
||
165 | +#else |
||
166 | +#define pike_generate_seed_file() |
||
167 | +#endif |
||
168 | + |
||
169 | /*! @decl void create(void|int sources) |
||
170 | *! The number of entropy sources that will feed entropy to the |
||
171 | *! random number generator is given as an argument to Yarrow |
||
172 | @@ -90,10 +120,12 @@ |
||
173 | optflags OPT_SIDE_EFFECT; |
||
174 | { |
||
175 | if(data->len < YARROW256_SEED_FILE_SIZE) |
||
176 | - Pike_error( "Seed must be at least 32 characters.\n" ); |
||
177 | + Pike_error("Seed must be at least %d characters.\n", |
||
178 | + YARROW256_SEED_FILE_SIZE); |
||
179 | |||
180 | NO_WIDE_STRING(data); |
||
181 | - yarrow256_seed(&THIS->ctx, data->len, (const uint8_t *)data->str); |
||
182 | + yarrow256_seed(&THIS->ctx, data->len, STR0(data)); |
||
183 | + pike_generate_seed_file(); |
||
184 | RETURN this_object(); |
||
185 | } |
||
186 | |||
187 | @@ -109,19 +141,31 @@ |
||
188 | RETURN YARROW256_SEED_FILE_SIZE; |
||
189 | } |
||
190 | |||
191 | - /*! @decl string get_seed() |
||
192 | - *! Returns part of the internal state so that it can |
||
193 | - *! be saved for later seeding. |
||
194 | + /*! @decl string(0..255) get_seed() |
||
195 | + *! Returns part of the internal state so that it can |
||
196 | + *! be saved for later seeding. |
||
197 | + *! |
||
198 | *! @seealso |
||
199 | - *! @[seed] |
||
200 | + *! @[seed()], @[random_string()] |
||
201 | */ |
||
202 | PIKEFUN string get_seed() |
||
203 | optflags OPT_EXTERNAL_DEPEND; |
||
204 | + rawtype tDeprecated(tFunc(tNone, tStr8)); |
||
205 | { |
||
206 | if( !yarrow256_is_seeded(&THIS->ctx) ) |
||
207 | Pike_error("Random generator not seeded.\n"); |
||
208 | - RETURN make_shared_binary_string((const char *)THIS->ctx.seed_file, |
||
209 | - YARROW256_SEED_FILE_SIZE); |
||
210 | + |
||
211 | +#ifdef HAVE_STRUCT_YARROW256_CTX_SEED_FILE |
||
212 | + RETURN make_shared_binary_string(THIS->ctx.seed_file, |
||
213 | + YARROW256_SEED_FILE_SIZE); |
||
214 | +#else |
||
215 | + if (THIS->seed_file) { |
||
216 | + REF_RETURN THIS->seed_file; |
||
217 | + } else { |
||
218 | + struct pike_string *s = begin_shared_string(YARROW256_SEED_FILE_SIZE); |
||
219 | + RETURN end_shared_string(s); |
||
220 | + } |
||
221 | +#endif /* HAVE_STRUCT_YARROW256_CTX_SEED_FILE */ |
||
222 | } |
||
223 | |||
224 | /*! @decl int(0..1) is_seeded() |
||
225 | @@ -144,7 +188,19 @@ |
||
226 | PIKEFUN void force_reseed() |
||
227 | optflags OPT_SIDE_EFFECT; |
||
228 | { |
||
229 | +#ifdef HAVE_NETTLE_YARROW256_SLOW_RESEED |
||
230 | + /* From change notes for Nettle 2.0: |
||
231 | + * |
||
232 | + * * Changes to the yarrow256 interface. The function |
||
233 | + * yarrow256_force_reseed has been replaced by the two |
||
234 | + * functions yarrow256_fast_reseed and yarrow256_slow_reseed, |
||
235 | + * which were previously static. |
||
236 | + */ |
||
237 | + yarrow256_slow_reseed(&THIS->ctx); |
||
238 | +#else |
||
239 | yarrow256_force_reseed(&THIS->ctx); |
||
240 | +#endif |
||
241 | + pike_generate_seed_file(); |
||
242 | } |
||
243 | |||
244 | /*! @decl int(0..1) update(string data, int source, int entropy) |
||
245 | @@ -156,6 +212,7 @@ |
||
246 | PIKEFUN int(0..1) update(string data, int source, int entropy) |
||
247 | optflags OPT_SIDE_EFFECT; |
||
248 | { |
||
249 | + int ret; |
||
250 | /* FIXME: Wide strings could actually be supported here */ |
||
251 | NO_WIDE_STRING(data); |
||
252 | if( !THIS->sources ) |
||
253 | @@ -166,8 +223,11 @@ |
||
254 | Pike_error("Entropy must be positive.\n"); |
||
255 | if( entropy>(data->len*8) ) |
||
256 | Pike_error("Impossibly large entropy value.\n"); |
||
257 | - RETURN yarrow256_update(&THIS->ctx, source, entropy, data->len, |
||
258 | - (const uint8_t *)data->str); |
||
259 | + ret = yarrow256_update(&THIS->ctx, source, entropy, data->len, |
||
260 | + (const uint8_t *)data->str); |
||
261 | + if (ret) |
||
262 | + pike_generate_seed_file(); |
||
263 | + RETURN ret; |
||
264 | } |
||
265 | |||
266 | /*! @decl int(0..) needed_sources() |
||
267 | diff -urad Pike-v7.8.316/src/post_modules/Nettle/testsuite.in pike-cvs/7.8/src/post_modules/Nettle/testsuite.in |
||
268 | --- Pike-v7.8.316/src/post_modules/Nettle/testsuite.in 2007-06-18 02:43:51.000000000 +0200 |
||
269 | +++ pike-cvs/7.8/src/post_modules/Nettle/testsuite.in 2009-08-05 12:01:45.000000000 +0200 |
||
270 | @@ -193,4 +193,14 @@ |
||
271 | } |
||
272 | ) |
||
273 | ]]) |
||
274 | + |
||
275 | +cond_resolv( Nettle.Yarrow, [[ |
||
276 | + test_any_equal([[ |
||
277 | + object y = Nettle.Yarrow()->seed("What happen? Somebody set up us the bomb."); |
||
278 | + return ({ y->get_seed(), y->random_string(20), y->get_seed(), y->random_string(20) }); |
||
279 | + ]], [[({String.hex2string("73a35b2f896a8061be0ad434a592a43a82b81b9ed6c018f1c5a51300bbc8d53d"), |
||
280 | + String.hex2string("7847458e32fb789ff6b6cd6e1c8cc3712ba532a8"), |
||
281 | + String.hex2string("73a35b2f896a8061be0ad434a592a43a82b81b9ed6c018f1c5a51300bbc8d53d"), |
||
282 | + String.hex2string("49a090656a6d93782e169994f41005a3616d3cd7")})]]) |
||
283 | +]]) |
||
284 | END_MARKER |