Diffstat (limited to 'frontend/gamma/js/ClipperzCryptoLibrary/ECC/BinaryField/Curve.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/ClipperzCryptoLibrary/ECC/BinaryField/Curve.js | 545 |
1 files changed, 0 insertions, 545 deletions
diff --git a/frontend/gamma/js/ClipperzCryptoLibrary/ECC/BinaryField/Curve.js b/frontend/gamma/js/ClipperzCryptoLibrary/ECC/BinaryField/Curve.js deleted file mode 100644 index 9c61bab..0000000 --- a/frontend/gamma/js/ClipperzCryptoLibrary/ECC/BinaryField/Curve.js +++ b/dev/null | |||
@@ -1,545 +0,0 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | ||
25 | //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; | ||
26 | //} | ||
27 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | ||
28 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | ||
29 | |||
30 | Clipperz.Crypto.ECC.BinaryField.Curve = function(args) { | ||
31 | args = args || {}; | ||
32 | |||
33 | this._modulus = args.modulus; | ||
34 | |||
35 | this._a = args.a; | ||
36 | this._b = args.b; | ||
37 | this._G = args.G; | ||
38 | this._r = args.r; | ||
39 | this._h = args.h; | ||
40 | |||
41 | this._finiteField = null; | ||
42 | |||
43 | return this; | ||
44 | } | ||
45 | |||
46 | Clipperz.Crypto.ECC.BinaryField.Curve.prototype = MochiKit.Base.update(null, { | ||
47 | |||
48 | 'asString': function() { | ||
49 | return "Clipperz.Crypto.ECC.BinaryField.Curve"; | ||
50 | }, | ||
51 | |||
52 | //----------------------------------------------------------------------------- | ||
53 | |||
54 | 'modulus': function() { | ||
55 | return this._modulus; | ||
56 | }, | ||
57 | |||
58 | 'a': function() { | ||
59 | return this._a; | ||
60 | }, | ||
61 | |||
62 | 'b': function() { | ||
63 | return this._b; | ||
64 | }, | ||
65 | |||
66 | 'G': function() { | ||
67 | return this._G; | ||
68 | }, | ||
69 | |||
70 | 'r': function() { | ||
71 | return this._r; | ||
72 | }, | ||
73 | |||
74 | 'h': function() { | ||
75 | return this._h; | ||
76 | }, | ||
77 | |||
78 | //----------------------------------------------------------------------------- | ||
79 | |||
80 | 'finiteField': function() { | ||
81 | if (this._finiteField == null) { | ||
82 | this._finiteField = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:this.modulus()}) | ||
83 | } | ||
84 | |||
85 | return this._finiteField; | ||
86 | }, | ||
87 | |||
88 | //----------------------------------------------------------------------------- | ||
89 | |||
90 | 'negate': function(aPointA) { | ||
91 | var result; | ||
92 | |||
93 | result = new Clipperz.Crypto.ECC.Point({x:aPointA.x(), y:this.finiteField().add(aPointA.y(), aPointA.x())}) | ||
94 | |||
95 | return result; | ||
96 | }, | ||
97 | |||
98 | //----------------------------------------------------------------------------- | ||
99 | |||
100 | 'add': function(aPointA, aPointB) { | ||
101 | var result; | ||
102 | |||
103 | //console.log(">>> ECC.BinaryField.Curve.add"); | ||
104 | if (aPointA.isZero()) { | ||
105 | //console.log("--- pointA == zero"); | ||
106 | result = aPointB; | ||
107 | } else if (aPointB.isZero()) { | ||
108 | //console.log("--- pointB == zero"); | ||
109 | result = aPointA; | ||
110 | } else if ((aPointA.x().compare(aPointB.x()) == 0) && ((aPointA.y().compare(aPointB.y()) != 0) || aPointB.x().isZero())) { | ||
111 | //console.log("compare A.x - B.x: ", aPointA.x().compare(aPointB.x())); | ||
112 | //console.log("compare A.y - B.y: ", (aPointA.y().compare(aPointB.y()) != 0)); | ||
113 | //console.log("compare B.x.isZero(): ", aPointB.x().isZero()); | ||
114 | |||
115 | //console.log("--- result = zero"); | ||
116 | result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); | ||
117 | } else { | ||
118 | //console.log("--- result = ELSE"); | ||
119 | varf2m; | ||
120 | var x, y; | ||
121 | var lambda; | ||
122 | var aX, aY, bX, bY; | ||
123 | |||
124 | aX = aPointA.x()._value; | ||
125 | aY = aPointA.y()._value; | ||
126 | bX = aPointB.x()._value; | ||
127 | bY = aPointB.y()._value; | ||
128 | |||
129 | f2m = this.finiteField(); | ||
130 | |||
131 | if (aPointA.x().compare(aPointB.x()) != 0) { | ||
132 | //console.log(" a.x != b.x"); | ||
133 | lambda =f2m._fastMultiply( | ||
134 | f2m._add(aY, bY), | ||
135 | f2m._inverse(f2m._add(aX, bX)) | ||
136 | ); | ||
137 | x = f2m._add(this.a()._value, f2m._square(lambda)); | ||
138 | f2m._overwriteAdd(x, lambda); | ||
139 | f2m._overwriteAdd(x, aX); | ||
140 | f2m._overwriteAdd(x, bX); | ||
141 | } else { | ||
142 | //console.log(" a.x == b.x"); | ||
143 | lambda = f2m._add(bX, f2m._fastMultiply(bY, f2m._inverse(bX))); | ||
144 | //console.log(" lambda: " + lambda.asString(16)); | ||
145 | x = f2m._add(this.a()._value, f2m._square(lambda)); | ||
146 | //console.log(" x (step 1): " + x.asString(16)); | ||
147 | f2m._overwriteAdd(x, lambda); | ||
148 | //console.log(" x (step 2): " + x.asString(16)); | ||
149 | } | ||
150 | |||
151 | y = f2m._fastMultiply(f2m._add(bX, x), lambda); | ||
152 | //console.log(" y (step 1): " + y.asString(16)); | ||
153 | f2m._overwriteAdd(y, x); | ||
154 | //console.log(" y (step 2): " + y.asString(16)); | ||
155 | f2m._overwriteAdd(y, bY); | ||
156 | //console.log(" y (step 3): " + y.asString(16)); | ||
157 | |||
158 | result = new Clipperz.Crypto.ECC.BinaryField.Point({x:new Clipperz.Crypto.ECC.BinaryField.Value(x), y:new Clipperz.Crypto.ECC.BinaryField.Value(y)}) | ||
159 | } | ||
160 | //console.log("<<< ECC.BinaryField.Curve.add"); | ||
161 | |||
162 | return result; | ||
163 | }, | ||
164 | |||
165 | //----------------------------------------------------------------------------- | ||
166 | |||
167 | 'addTwice': function(aPointA) { | ||
168 | return this.add(aPointA, aPointA); | ||
169 | }, | ||
170 | |||
171 | //----------------------------------------------------------------------------- | ||
172 | |||
173 | 'overwriteAdd': function(aPointA, aPointB) { | ||
174 | if (aPointA.isZero()) { | ||
175 | // result = aPointB; | ||
176 | aPointA._x._value = aPointB._x._value; | ||
177 | aPointA._y._value = aPointB._y._value; | ||
178 | } else if (aPointB.isZero()) { | ||
179 | // result = aPointA; | ||
180 | } else if ((aPointA.x().compare(aPointB.x()) == 0) && ((aPointA.y().compare(aPointB.y()) != 0) || aPointB.x().isZero())) { | ||
181 | // result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); | ||
182 | aPointA._x = Clipperz.Crypto.ECC.BinaryField.Value.O; | ||
183 | aPointA._y = Clipperz.Crypto.ECC.BinaryField.Value.O; | ||
184 | } else { | ||
185 | varf2m; | ||
186 | var x, y; | ||
187 | var lambda; | ||
188 | var aX, aY, bX, bY; | ||
189 | |||
190 | aX = aPointA.x()._value; | ||
191 | aY = aPointA.y()._value; | ||
192 | bX = aPointB.x()._value; | ||
193 | bY = aPointB.y()._value; | ||
194 | |||
195 | f2m = this.finiteField(); | ||
196 | |||
197 | if (aPointA.x().compare(aPointB.x()) != 0) { | ||
198 | //console.log(" a.x != b.x"); | ||
199 | lambda =f2m._fastMultiply( | ||
200 | f2m._add(aY, bY), | ||
201 | f2m._inverse(f2m._add(aX, bX)) | ||
202 | ); | ||
203 | x = f2m._add(this.a()._value, f2m._square(lambda)); | ||
204 | f2m._overwriteAdd(x, lambda); | ||
205 | f2m._overwriteAdd(x, aX); | ||
206 | f2m._overwriteAdd(x, bX); | ||
207 | } else { | ||
208 | //console.log(" a.x == b.x"); | ||
209 | lambda = f2m._add(bX, f2m._fastMultiply(bY, f2m._inverse(bX))); | ||
210 | //console.log(" lambda: " + lambda.asString(16)); | ||
211 | x = f2m._add(this.a()._value, f2m._square(lambda)); | ||
212 | //console.log(" x (step 1): " + x.asString(16)); | ||
213 | f2m._overwriteAdd(x, lambda); | ||
214 | //console.log(" x (step 2): " + x.asString(16)); | ||
215 | } | ||
216 | |||
217 | y = f2m._fastMultiply(f2m._add(bX, x), lambda); | ||
218 | //console.log(" y (step 1): " + y.asString(16)); | ||
219 | f2m._overwriteAdd(y, x); | ||
220 | //console.log(" y (step 2): " + y.asString(16)); | ||
221 | f2m._overwriteAdd(y, bY); | ||
222 | //console.log(" y (step 3): " + y.asString(16)); | ||
223 | |||
224 | // result = new Clipperz.Crypto.ECC.BinaryField.Point({x:new Clipperz.Crypto.ECC.BinaryField.Value(x), y:new Clipperz.Crypto.ECC.BinaryField.Value(y)}) | ||
225 | aPointA._x._value = x; | ||
226 | aPointA._y._value = y; | ||
227 | |||
228 | } | ||
229 | //console.log("<<< ECC.BinaryField.Curve.add"); | ||
230 | |||
231 | return result; | ||
232 | }, | ||
233 | |||
234 | //----------------------------------------------------------------------------- | ||
235 | |||
236 | 'multiply': function(aValue, aPoint) { | ||
237 | var result; | ||
238 | |||
239 | //console.profile(); | ||
240 | result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); | ||
241 | |||
242 | if (aValue.isZero() == false) { | ||
243 | var k, Q; | ||
244 | var i; | ||
245 | var countIndex; countIndex = 0; | ||
246 | |||
247 | if (aValue.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) > 0) { | ||
248 | k = aValue; | ||
249 | Q = aPoint; | ||
250 | } else { | ||
251 | MochiKit.Logging.logError("The Clipperz.Crypto.ECC.BinaryFields.Value does not work with negative values!!!!"); | ||
252 | k = aValue.negate(); | ||
253 | Q = this.negate(aPoint); | ||
254 | } | ||
255 | |||
256 | //console.log("k: " + k.toString(16)); | ||
257 | //console.log("k.bitSize: " + k.bitSize()); | ||
258 | for (i=k.bitSize()-1; i>=0; i--) { | ||
259 | result = this.add(result, result); | ||
260 | // this.overwriteAdd(result, result); | ||
261 | if (k.isBitSet(i)) { | ||
262 | result = this.add(result, Q); | ||
263 | // this.overwriteAdd(result, Q); | ||
264 | } | ||
265 | |||
266 | // if (countIndex==100) {console.log("multiply.break"); break;} else countIndex++; | ||
267 | } | ||
268 | } | ||
269 | //console.profileEnd(); | ||
270 | |||
271 | return result; | ||
272 | }, | ||
273 | |||
274 | //----------------------------------------------------------------------------- | ||
275 | |||
276 | 'deferredMultiply': function(aValue, aPoint) { | ||
277 | var deferredResult; | ||
278 | var result; | ||
279 | |||
280 | MochiKit.Logging.logDebug(">>> deferredMultiply - value: " + aValue + ", point: " + aPoint); | ||
281 | //console.profile("ECC.Curve.multiply"); | ||
282 | deferredResult = new MochiKit.Async.Deferred(); | ||
283 | //deferredResult.addCallback(function(res) {console.profile("ECC.Curve.deferredMultiply"); return res;} ); | ||
284 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 1: " + res); return res;}); | ||
285 | |||
286 | result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); | ||
287 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 2: " + res); return res;}); | ||
288 | |||
289 | if (aValue.isZero() == false) { | ||
290 | var k, Q; | ||
291 | var i; | ||
292 | var countIndex; countIndex = 0; | ||
293 | |||
294 | if (aValue.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) > 0) { | ||
295 | k = aValue; | ||
296 | Q = aPoint; | ||
297 | } else { | ||
298 | MochiKit.Logging.logError("The Clipperz.Crypto.ECC.BinaryFields.Value does not work with negative values!!!!"); | ||
299 | k = aValue.negate(); | ||
300 | Q = this.negate(aPoint); | ||
301 | } | ||
302 | |||
303 | //console.log("k: " + k.toString(16)); | ||
304 | //console.log("k.bitSize: " + k.bitSize()); | ||
305 | |||
306 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 3: " + res); return res;}); | ||
307 | for (i=k.bitSize()-1; i>=0; i--) { | ||
308 | //MochiKit.Logging.logDebug("====> " + i); | ||
309 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 4 > i = " + i + ": " + res); return res;}); | ||
310 | deferredResult.addMethod(this, "addTwice"); | ||
311 | //# result = this.add(result, result); | ||
312 | // this.overwriteAdd(result, result); | ||
313 | if (k.isBitSet(i)) { | ||
314 | deferredResult.addMethod(this, "add", Q); | ||
315 | //# result = this.add(result, Q); | ||
316 | // this.overwriteAdd(result, Q); | ||
317 | } | ||
318 | if (i%20 == 0) {deferredResult.addCallback(MochiKit.Async.wait, 0.1);} | ||
319 | |||
320 | // if (countIndex==100) {console.log("multiply.break"); break;} else countIndex++; | ||
321 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 4 < i = " + i + ": " + res); return res;}); | ||
322 | } | ||
323 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 4: " + res); return res;}); | ||
324 | } | ||
325 | //#console.profileEnd(); | ||
326 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 5: " + res); return res;}); | ||
327 | //deferredResult.addBoth(function(res) {console.profileEnd(); return res;}); | ||
328 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 6: " + res); return res;}); | ||
329 | deferredResult.callback(result); | ||
330 | |||
331 | //# return result; | ||
332 | return deferredResult; | ||
333 | }, | ||
334 | |||
335 | //----------------------------------------------------------------------------- | ||
336 | __syntaxFix__: "syntax fix" | ||
337 | }); | ||
338 | |||
339 | |||
340 | //############################################################################# | ||
341 | |||
342 | Clipperz.Crypto.ECC.StandardCurves = {}; | ||
343 | |||
344 | MochiKit.Base.update(Clipperz.Crypto.ECC.StandardCurves, { | ||
345 | /* | ||
346 | '_K571': null, | ||
347 | 'K571': function() { | ||
348 | if (Clipperz.Crypto.ECC.StandardCurves._K571 == null) { | ||
349 | Clipperz.Crypto.ECC.StandardCurves._K571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
350 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000425', 16), | ||
351 | a: new Clipperz.Crypto.ECC.BinaryField.Value('0', 16), | ||
352 | b: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
353 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
354 | x: new Clipperz.Crypto.ECC.BinaryField.Value('026eb7a8 59923fbc 82189631 f8103fe4 ac9ca297 0012d5d4 60248048 01841ca4 43709584 93b205e6 47da304d b4ceb08c bbd1ba39 494776fb 988b4717 4dca88c7 e2945283 a01c8972', 16), | ||
355 | y: new Clipperz.Crypto.ECC.BinaryField.Value('0349dc80 7f4fbf37 4f4aeade 3bca9531 4dd58cec 9f307a54 ffc61efc 006d8a2c 9d4979c0 ac44aea7 4fbebbb9 f772aedc b620b01a 7ba7af1b 320430c8 591984f6 01cd4c14 3ef1c7a3', 16) | ||
356 | }), | ||
357 | r: new Clipperz.Crypto.ECC.BinaryField.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16), | ||
358 | h: new Clipperz.Crypto.ECC.BinaryField.Value('4', 16) | ||
359 | }); | ||
360 | } | ||
361 | |||
362 | return Clipperz.Crypto.ECC.StandardCurves._K571; | ||
363 | }, | ||
364 | |||
365 | |||
366 | |||
367 | '_K283': null, | ||
368 | 'K283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 | ||
369 | if (Clipperz.Crypto.ECC.StandardCurves._K283 == null) { | ||
370 | Clipperz.Crypto.ECC.StandardCurves._K283 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
371 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | ||
372 | a: new Clipperz.Crypto.ECC.BinaryField.Value('0', 16), | ||
373 | b: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
374 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
375 | x: new Clipperz.Crypto.ECC.BinaryField.Value('0503213f 78ca4488 3f1a3b81 62f188e5 53cd265f 23c1567a 16876913 b0c2ac24 58492836', 16), | ||
376 | y: new Clipperz.Crypto.ECC.BinaryField.Value('01ccda38 0f1c9e31 8d90f95d 07e5426f e87e45c0 e8184698 e4596236 4e341161 77dd2259', 16) | ||
377 | }), | ||
378 | r: new Clipperz.Crypto.ECC.BinaryField.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16), | ||
379 | h: new Clipperz.Crypto.ECC.BinaryField.Value('4', 16) | ||
380 | }); | ||
381 | } | ||
382 | |||
383 | return Clipperz.Crypto.ECC.StandardCurves._K283; | ||
384 | }, | ||
385 | */ | ||
386 | //----------------------------------------------------------------------------- | ||
387 | |||
388 | '_B571': null, | ||
389 | 'B571': function() { //f(z) = z^571 + z^10 + z^5 + z^2 + 1 | ||
390 | if (Clipperz.Crypto.ECC.StandardCurves._B571 == null) { | ||
391 | Clipperz.Crypto.ECC.StandardCurves._B571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
392 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425', 16), | ||
393 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
394 | b: new Clipperz.Crypto.ECC.BinaryField.Value('02f40e7e2221f295de297117b7f3d62f5c6a97ffcb8ceff1cd6ba8ce4a9a18ad84ffabbd8efa59332be7ad6756a66e294afd185a78ff12aa520e4de739baca0c7ffeff7f2955727a', 16), | ||
395 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
396 | x: new Clipperz.Crypto.ECC.BinaryField.Value('0303001d 34b85629 6c16c0d4 0d3cd775 0a93d1d2 955fa80a a5f40fc8 db7b2abd bde53950 f4c0d293 cdd711a3 5b67fb14 99ae6003 8614f139 4abfa3b4 c850d927 e1e7769c 8eec2d19', 16), | ||
397 | y: new Clipperz.Crypto.ECC.BinaryField.Value('037bf273 42da639b 6dccfffe b73d69d7 8c6c27a6 009cbbca 1980f853 3921e8a6 84423e43 bab08a57 6291af8f 461bb2a8 b3531d2f 0485c19b 16e2f151 6e23dd3c 1a4827af 1b8ac15b', 16) | ||
398 | }), | ||
399 | r: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff e661ce18 ff559873 08059b18 6823851e c7dd9ca1 161de93d 5174d66e 8382e9bb 2fe84e47', 16), | ||
400 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) | ||
401 | |||
402 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), | ||
403 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) | ||
404 | }); | ||
405 | |||
406 | //----------------------------------------------------------------------------- | ||
407 | // | ||
408 | //Guide to Elliptic Curve Cryptography | ||
409 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | ||
410 | //- Pag: 56, Alorithm 2.45 (with a typo!!!) | ||
411 | // | ||
412 | //----------------------------------------------------------------------------- | ||
413 | // | ||
414 | // http://www.milw0rm.com/papers/136 | ||
415 | // | ||
416 | // ------------------------------------------------------------------------- | ||
417 | // Polynomial Reduction Algorithm Modulo f571 | ||
418 | // ------------------------------------------------------------------------- | ||
419 | // | ||
420 | // Input: Polynomial p(x) of degree 1140 or less, stored as | ||
421 | // an array of 2T machinewords. | ||
422 | // Output: p(x) mod f571(x) | ||
423 | // | ||
424 | // FOR i = T-1, ..., 0 DO | ||
425 | // SET X := P[i+T] | ||
426 | // P[i] := P[i] ^ (X<<5) ^ (X<<7) ^ (X<<10) ^ (X<<15) | ||
427 | // P[i+1] := P[i+1] ^ (X>>17) ^ (X>>22) ^ (X>>25) ^ (X>>27) | ||
428 | // | ||
429 | // SET X := P[T-1] >> 27 | ||
430 | // P[0] := P[0] ^ X ^ (X<<2) ^ (X<<5) ^ (X<<10) | ||
431 | // P[T-1] := P[T-1] & 0x07ffffff | ||
432 | // | ||
433 | // RETURN P[T-1],...,P[0] | ||
434 | // | ||
435 | // ------------------------------------------------------------------------- | ||
436 | // | ||
437 | Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().slowModule = Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().module; | ||
438 | Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().module = function(aValue) { | ||
439 | varresult; | ||
440 | |||
441 | if (aValue.bitSize() > 1140) { | ||
442 | MochiKit.Logging.logWarning("ECC.StandarCurves.B571.finiteField().module: falling back to default implementation"); | ||
443 | result = Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().slowModule(aValue); | ||
444 | } else { | ||
445 | varC, T; | ||
446 | var i; | ||
447 | |||
448 | //console.log(">>> binaryField.finiteField.(improved)module"); | ||
449 | // C = aValue.value().slice(0); | ||
450 | C = aValue._value.slice(0); | ||
451 | for (i=35; i>=18; i--) { | ||
452 | T = C[i]; | ||
453 | C[i-18] = (((C[i-18] ^ (T<<5) ^ (T<<7) ^ (T<<10) ^ (T<<15)) & 0xffffffff) >>> 0); | ||
454 | C[i-17] = ((C[i-17] ^ (T>>>27) ^ (T>>>25) ^ (T>>>22) ^ (T>>>17)) >>> 0); | ||
455 | } | ||
456 | T = (C[17] >>> 27); | ||
457 | C[0] = ((C[0] ^ T ^ ((T<<2) ^ (T<<5) ^ (T<<10)) & 0xffffffff) >>> 0); | ||
458 | C[17] = (C[17] & 0x07ffffff); | ||
459 | |||
460 | for(i=18; i<=35; i++) { | ||
461 | C[i] = 0; | ||
462 | } | ||
463 | |||
464 | result = new Clipperz.Crypto.ECC.BinaryField.Value(C); | ||
465 | //console.log("<<< binaryField.finiteField.(improved)module"); | ||
466 | } | ||
467 | |||
468 | return result; | ||
469 | }; | ||
470 | } | ||
471 | |||
472 | return Clipperz.Crypto.ECC.StandardCurves._B571; | ||
473 | }, | ||
474 | |||
475 | //----------------------------------------------------------------------------- | ||
476 | |||
477 | '_B283': null, | ||
478 | 'B283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 | ||
479 | if (Clipperz.Crypto.ECC.StandardCurves._B283 == null) { | ||
480 | Clipperz.Crypto.ECC.StandardCurves._B283 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
481 | // modulus: new Clipperz.Crypto.ECC.BinaryField.Value('10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | ||
482 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | ||
483 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
484 | b: new Clipperz.Crypto.ECC.BinaryField.Value('027b680a c8b8596d a5a4af8a 19a0303f ca97fd76 45309fa2 a581485a f6263e31 3b79a2f5', 16), | ||
485 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
486 | x: new Clipperz.Crypto.ECC.BinaryField.Value('05f93925 8db7dd90 e1934f8c 70b0dfec 2eed25b8 557eac9c 80e2e198 f8cdbecd 86b12053', 16), | ||
487 | y: new Clipperz.Crypto.ECC.BinaryField.Value('03676854 fe24141c b98fe6d4 b20d02b4 516ff702 350eddb0 826779c8 13f0df45 be8112f4', 16) | ||
488 | }), | ||
489 | r: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffff ffffffff ffffffff ffffffff ffffef90 399660fc 938a9016 5b042a7c efadb307', 16), | ||
490 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) | ||
491 | |||
492 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), | ||
493 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) | ||
494 | }); | ||
495 | |||
496 | //----------------------------------------------------------------------------- | ||
497 | // | ||
498 | //Guide to Elliptic Curve Cryptography | ||
499 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | ||
500 | //- Pag: 56, Alorithm 2.43 | ||
501 | // | ||
502 | //----------------------------------------------------------------------------- | ||
503 | Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().slowModule = Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().module; | ||
504 | Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().module = function(aValue) { | ||
505 | varresult; | ||
506 | |||
507 | if (aValue.bitSize() > 564) { | ||
508 | MochiKit.Logging.logWarning("ECC.StandarCurves.B283.finiteField().module: falling back to default implementation"); | ||
509 | result = Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().slowModule(aValue); | ||
510 | } else { | ||
511 | varC, T; | ||
512 | var i; | ||
513 | |||
514 | //console.log(">>> binaryField.finiteField.(improved)module"); | ||
515 | C = aValue._value.slice(0); | ||
516 | for (i=17; i>=9; i--) { | ||
517 | T = C[i]; | ||
518 | C[i-9] = (((C[i-9] ^ (T<<5) ^ (T<<10) ^ (T<<12) ^ (T<<17)) & 0xffffffff) >>> 0); | ||
519 | C[i-8] = ((C[i-8] ^ (T>>>27) ^ (T>>>22) ^ (T>>>20) ^ (T>>>15)) >>> 0); | ||
520 | } | ||
521 | T = (C[8] >>> 27); | ||
522 | C[0] = ((C[0] ^ T ^ ((T<<5) ^ (T<<7) ^ (T<<12)) & 0xffffffff) >>> 0); | ||
523 | C[8] = (C[8] & 0x07ffffff); | ||
524 | |||
525 | for(i=9; i<=17; i++) { | ||
526 | C[i] = 0; | ||
527 | } | ||
528 | |||
529 | result = new Clipperz.Crypto.ECC.BinaryField.Value(C); | ||
530 | //console.log("<<< binaryField.finiteField.(improved)module"); | ||
531 | } | ||
532 | |||
533 | return result; | ||
534 | }; | ||
535 | } | ||
536 | |||
537 | return Clipperz.Crypto.ECC.StandardCurves._B283; | ||
538 | }, | ||
539 | |||
540 | //----------------------------------------------------------------------------- | ||
541 | __syntaxFix__: "syntax fix" | ||
542 | }); | ||
543 | |||
544 | //############################################################################# | ||
545 | |||