Rev 47 | Go to most recent revision | Details | Compare with Previous | 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 | ## |
||
50 | holmgren | 4 | ## DP: Changes from CVS to make the Nettle module compile with Nettle 2.0 |
47 | holmgren | 5 | |
6 | @DPATCH@ |
||
7 | |||
8 | diff -urad Pike-v7.8.316/src/post_modules/Nettle/cipher.cmod pike-cvs/7.8/src/post_modules/Nettle/cipher.cmod |
||
9 | --- Pike-v7.8.316/src/post_modules/Nettle/cipher.cmod 2008-07-31 16:52:27.000000000 +0200 |
||
10 | +++ pike-cvs/7.8/src/post_modules/Nettle/cipher.cmod 2009-07-02 18:35:38.000000000 +0200 |
||
11 | @@ -79,8 +86,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; |
||
50 | holmgren | 17 | + nettle_crypt_func *encrypt; |
18 | + nettle_crypt_func *decrypt; |
||
47 | holmgren | 19 | }; |
20 | |||
21 | #define _PIKE_CIPHER(name, NAME) { \ |
||
22 | @@ -90,8 +97,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, \ |
||
50 | holmgren | 28 | + (nettle_crypt_func*) name##_encrypt, \ |
29 | + (nettle_crypt_func*) name##_decrypt, \ |
||
47 | holmgren | 30 | } |
31 | |||
32 | /*! @class CipherInfo |
||
33 | @@ -175,7 +182,7 @@ |
||
34 | PIKECLASS CipherState |
||
35 | { |
||
36 | INHERIT CipherInfo; |
||
37 | - CVAR nettle_crypt_func crypt; |
||
50 | holmgren | 38 | + CVAR nettle_crypt_func *crypt; |
47 | holmgren | 39 | CVAR void *ctx; |
40 | CVAR int key_size; |
||
41 | |||
42 | diff -urad Pike-v7.8.316/src/post_modules/Nettle/nettle.cmod pike-cvs/7.8/src/post_modules/Nettle/nettle.cmod |
||
43 | --- Pike-v7.8.316/src/post_modules/Nettle/nettle.cmod 2008-06-29 00:57:14.000000000 +0200 |
||
44 | +++ pike-cvs/7.8/src/post_modules/Nettle/nettle.cmod 2009-07-05 21:41:58.000000000 +0200 |
||
50 | holmgren | 45 | @@ -46,6 +46,21 @@ |
47 | holmgren | 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 | + DECLARE_STORAGE; |
||
52 | + |
||
53 | + static void pike_generate_seed_file(void) |
||
54 | + { |
||
55 | + struct pike_string *seed_file = |
||
56 | + begin_shared_string(YARROW256_SEED_FILE_SIZE); |
||
57 | + yarrow256_random(&THIS->ctx, YARROW256_SEED_FILE_SIZE, STR0(seed_file)); |
||
58 | + if (THIS->seed_file) { |
||
59 | + free_string(THIS->seed_file); |
||
60 | + } |
||
61 | + THIS->seed_file = end_shared_string(seed_file); |
||
62 | + } |
||
63 | + |
||
64 | /*! @decl void create(void|int sources) |
||
65 | *! The number of entropy sources that will feed entropy to the |
||
66 | *! random number generator is given as an argument to Yarrow |
||
67 | @@ -90,10 +120,12 @@ |
||
68 | optflags OPT_SIDE_EFFECT; |
||
69 | { |
||
70 | if(data->len < YARROW256_SEED_FILE_SIZE) |
||
71 | - Pike_error( "Seed must be at least 32 characters.\n" ); |
||
72 | + Pike_error("Seed must be at least %d characters.\n", |
||
73 | + YARROW256_SEED_FILE_SIZE); |
||
74 | |||
75 | NO_WIDE_STRING(data); |
||
76 | - yarrow256_seed(&THIS->ctx, data->len, (const uint8_t *)data->str); |
||
77 | + yarrow256_seed(&THIS->ctx, data->len, STR0(data)); |
||
78 | + pike_generate_seed_file(); |
||
79 | RETURN this_object(); |
||
80 | } |
||
81 | |||
50 | holmgren | 82 | @@ -109,19 +141,26 @@ |
47 | holmgren | 83 | RETURN YARROW256_SEED_FILE_SIZE; |
84 | } |
||
85 | |||
86 | - /*! @decl string get_seed() |
||
87 | - *! Returns part of the internal state so that it can |
||
88 | - *! be saved for later seeding. |
||
89 | + /*! @decl string(0..255) get_seed() |
||
90 | + *! Returns part of the internal state so that it can |
||
91 | + *! be saved for later seeding. |
||
92 | + *! |
||
93 | *! @seealso |
||
94 | - *! @[seed] |
||
95 | + *! @[seed()], @[random_string()] |
||
96 | */ |
||
97 | PIKEFUN string get_seed() |
||
98 | optflags OPT_EXTERNAL_DEPEND; |
||
99 | + rawtype tDeprecated(tFunc(tNone, tStr8)); |
||
100 | { |
||
101 | if( !yarrow256_is_seeded(&THIS->ctx) ) |
||
102 | Pike_error("Random generator not seeded.\n"); |
||
103 | - RETURN make_shared_binary_string((const char *)THIS->ctx.seed_file, |
||
104 | - YARROW256_SEED_FILE_SIZE); |
||
105 | + |
||
106 | + if (THIS->seed_file) { |
||
107 | + REF_RETURN THIS->seed_file; |
||
108 | + } else { |
||
109 | + struct pike_string *s = begin_shared_string(YARROW256_SEED_FILE_SIZE); |
||
110 | + RETURN end_shared_string(s); |
||
111 | + } |
||
112 | } |
||
113 | |||
114 | /*! @decl int(0..1) is_seeded() |
||
50 | holmgren | 115 | @@ -144,7 +188,8 @@ |
47 | holmgren | 116 | PIKEFUN void force_reseed() |
117 | optflags OPT_SIDE_EFFECT; |
||
118 | { |
||
50 | holmgren | 119 | - yarrow256_force_reseed(&THIS->ctx); |
47 | holmgren | 120 | + yarrow256_slow_reseed(&THIS->ctx); |
121 | + pike_generate_seed_file(); |
||
122 | } |
||
123 | |||
124 | /*! @decl int(0..1) update(string data, int source, int entropy) |
||
125 | @@ -156,6 +212,7 @@ |
||
126 | PIKEFUN int(0..1) update(string data, int source, int entropy) |
||
127 | optflags OPT_SIDE_EFFECT; |
||
128 | { |
||
129 | + int ret; |
||
130 | /* FIXME: Wide strings could actually be supported here */ |
||
131 | NO_WIDE_STRING(data); |
||
132 | if( !THIS->sources ) |
||
133 | @@ -166,8 +223,11 @@ |
||
134 | Pike_error("Entropy must be positive.\n"); |
||
135 | if( entropy>(data->len*8) ) |
||
136 | Pike_error("Impossibly large entropy value.\n"); |
||
137 | - RETURN yarrow256_update(&THIS->ctx, source, entropy, data->len, |
||
138 | - (const uint8_t *)data->str); |
||
139 | + ret = yarrow256_update(&THIS->ctx, source, entropy, data->len, |
||
140 | + (const uint8_t *)data->str); |
||
141 | + if (ret) |
||
142 | + pike_generate_seed_file(); |
||
143 | + RETURN ret; |
||
144 | } |
||
145 | |||
146 | /*! @decl int(0..) needed_sources() |
||
147 | diff -urad Pike-v7.8.316/src/post_modules/Nettle/testsuite.in pike-cvs/7.8/src/post_modules/Nettle/testsuite.in |
||
148 | --- Pike-v7.8.316/src/post_modules/Nettle/testsuite.in 2007-06-18 02:43:51.000000000 +0200 |
||
149 | +++ pike-cvs/7.8/src/post_modules/Nettle/testsuite.in 2009-08-05 12:01:45.000000000 +0200 |
||
150 | @@ -193,4 +193,14 @@ |
||
151 | } |
||
152 | ) |
||
153 | ]]) |
||
154 | + |
||
155 | +cond_resolv( Nettle.Yarrow, [[ |
||
156 | + test_any_equal([[ |
||
157 | + object y = Nettle.Yarrow()->seed("What happen? Somebody set up us the bomb."); |
||
158 | + return ({ y->get_seed(), y->random_string(20), y->get_seed(), y->random_string(20) }); |
||
159 | + ]], [[({String.hex2string("73a35b2f896a8061be0ad434a592a43a82b81b9ed6c018f1c5a51300bbc8d53d"), |
||
160 | + String.hex2string("7847458e32fb789ff6b6cd6e1c8cc3712ba532a8"), |
||
161 | + String.hex2string("73a35b2f896a8061be0ad434a592a43a82b81b9ed6c018f1c5a51300bbc8d53d"), |
||
162 | + String.hex2string("49a090656a6d93782e169994f41005a3616d3cd7")})]]) |
||
163 | +]]) |
||
164 | END_MARKER |