author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/gamma/js/Clipperz/Crypto/ECC | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/ECC') (more/less context) (ignore whitespace changes)
5 files changed, 1768 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js new file mode 100644 index 0000000..2033eb4 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js | |||
@@ -0,0 +1,550 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | ||
30 | //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; | ||
31 | //} | ||
32 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | ||
33 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | ||
34 | |||
35 | Clipperz.Crypto.ECC.BinaryField.Curve = function(args) { | ||
36 | args = args || {}; | ||
37 | |||
38 | this._modulus = args.modulus; | ||
39 | |||
40 | this._a = args.a; | ||
41 | this._b = args.b; | ||
42 | this._G = args.G; | ||
43 | this._r = args.r; | ||
44 | this._h = args.h; | ||
45 | |||
46 | this._finiteField = null; | ||
47 | |||
48 | return this; | ||
49 | } | ||
50 | |||
51 | Clipperz.Crypto.ECC.BinaryField.Curve.prototype = MochiKit.Base.update(null, { | ||
52 | |||
53 | 'asString': function() { | ||
54 | return "Clipperz.Crypto.ECC.BinaryField.Curve"; | ||
55 | }, | ||
56 | |||
57 | //----------------------------------------------------------------------------- | ||
58 | |||
59 | 'modulus': function() { | ||
60 | return this._modulus; | ||
61 | }, | ||
62 | |||
63 | 'a': function() { | ||
64 | return this._a; | ||
65 | }, | ||
66 | |||
67 | 'b': function() { | ||
68 | return this._b; | ||
69 | }, | ||
70 | |||
71 | 'G': function() { | ||
72 | return this._G; | ||
73 | }, | ||
74 | |||
75 | 'r': function() { | ||
76 | return this._r; | ||
77 | }, | ||
78 | |||
79 | 'h': function() { | ||
80 | return this._h; | ||
81 | }, | ||
82 | |||
83 | //----------------------------------------------------------------------------- | ||
84 | |||
85 | 'finiteField': function() { | ||
86 | if (this._finiteField == null) { | ||
87 | this._finiteField = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:this.modulus()}) | ||
88 | } | ||
89 | |||
90 | return this._finiteField; | ||
91 | }, | ||
92 | |||
93 | //----------------------------------------------------------------------------- | ||
94 | |||
95 | 'negate': function(aPointA) { | ||
96 | var result; | ||
97 | |||
98 | result = new Clipperz.Crypto.ECC.Point({x:aPointA.x(), y:this.finiteField().add(aPointA.y(), aPointA.x())}) | ||
99 | |||
100 | return result; | ||
101 | }, | ||
102 | |||
103 | //----------------------------------------------------------------------------- | ||
104 | |||
105 | 'add': function(aPointA, aPointB) { | ||
106 | var result; | ||
107 | |||
108 | //console.log(">>> ECC.BinaryField.Curve.add"); | ||
109 | if (aPointA.isZero()) { | ||
110 | //console.log("--- pointA == zero"); | ||
111 | result = aPointB; | ||
112 | } else if (aPointB.isZero()) { | ||
113 | //console.log("--- pointB == zero"); | ||
114 | result = aPointA; | ||
115 | } else if ((aPointA.x().compare(aPointB.x()) == 0) && ((aPointA.y().compare(aPointB.y()) != 0) || aPointB.x().isZero())) { | ||
116 | //console.log("compare A.x - B.x: ", aPointA.x().compare(aPointB.x())); | ||
117 | //console.log("compare A.y - B.y: ", (aPointA.y().compare(aPointB.y()) != 0)); | ||
118 | //console.log("compare B.x.isZero(): ", aPointB.x().isZero()); | ||
119 | |||
120 | //console.log("--- result = zero"); | ||
121 | result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); | ||
122 | } else { | ||
123 | //console.log("--- result = ELSE"); | ||
124 | varf2m; | ||
125 | var x, y; | ||
126 | var lambda; | ||
127 | var aX, aY, bX, bY; | ||
128 | |||
129 | aX = aPointA.x()._value; | ||
130 | aY = aPointA.y()._value; | ||
131 | bX = aPointB.x()._value; | ||
132 | bY = aPointB.y()._value; | ||
133 | |||
134 | f2m = this.finiteField(); | ||
135 | |||
136 | if (aPointA.x().compare(aPointB.x()) != 0) { | ||
137 | //console.log(" a.x != b.x"); | ||
138 | lambda =f2m._fastMultiply( | ||
139 | f2m._add(aY, bY), | ||
140 | f2m._inverse(f2m._add(aX, bX)) | ||
141 | ); | ||
142 | x = f2m._add(this.a()._value, f2m._square(lambda)); | ||
143 | f2m._overwriteAdd(x, lambda); | ||
144 | f2m._overwriteAdd(x, aX); | ||
145 | f2m._overwriteAdd(x, bX); | ||
146 | } else { | ||
147 | //console.log(" a.x == b.x"); | ||
148 | lambda = f2m._add(bX, f2m._fastMultiply(bY, f2m._inverse(bX))); | ||
149 | //console.log(" lambda: " + lambda.asString(16)); | ||
150 | x = f2m._add(this.a()._value, f2m._square(lambda)); | ||
151 | //console.log(" x (step 1): " + x.asString(16)); | ||
152 | f2m._overwriteAdd(x, lambda); | ||
153 | //console.log(" x (step 2): " + x.asString(16)); | ||
154 | } | ||
155 | |||
156 | y = f2m._fastMultiply(f2m._add(bX, x), lambda); | ||
157 | //console.log(" y (step 1): " + y.asString(16)); | ||
158 | f2m._overwriteAdd(y, x); | ||
159 | //console.log(" y (step 2): " + y.asString(16)); | ||
160 | f2m._overwriteAdd(y, bY); | ||
161 | //console.log(" y (step 3): " + y.asString(16)); | ||
162 | |||
163 | result = new Clipperz.Crypto.ECC.BinaryField.Point({x:new Clipperz.Crypto.ECC.BinaryField.Value(x), y:new Clipperz.Crypto.ECC.BinaryField.Value(y)}) | ||
164 | } | ||
165 | //console.log("<<< ECC.BinaryField.Curve.add"); | ||
166 | |||
167 | return result; | ||
168 | }, | ||
169 | |||
170 | //----------------------------------------------------------------------------- | ||
171 | |||
172 | 'addTwice': function(aPointA) { | ||
173 | return this.add(aPointA, aPointA); | ||
174 | }, | ||
175 | |||
176 | //----------------------------------------------------------------------------- | ||
177 | |||
178 | 'overwriteAdd': function(aPointA, aPointB) { | ||
179 | if (aPointA.isZero()) { | ||
180 | // result = aPointB; | ||
181 | aPointA._x._value = aPointB._x._value; | ||
182 | aPointA._y._value = aPointB._y._value; | ||
183 | } else if (aPointB.isZero()) { | ||
184 | // result = aPointA; | ||
185 | } else if ((aPointA.x().compare(aPointB.x()) == 0) && ((aPointA.y().compare(aPointB.y()) != 0) || aPointB.x().isZero())) { | ||
186 | // result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); | ||
187 | aPointA._x = Clipperz.Crypto.ECC.BinaryField.Value.O; | ||
188 | aPointA._y = Clipperz.Crypto.ECC.BinaryField.Value.O; | ||
189 | } else { | ||
190 | varf2m; | ||
191 | var x, y; | ||
192 | var lambda; | ||
193 | var aX, aY, bX, bY; | ||
194 | |||
195 | aX = aPointA.x()._value; | ||
196 | aY = aPointA.y()._value; | ||
197 | bX = aPointB.x()._value; | ||
198 | bY = aPointB.y()._value; | ||
199 | |||
200 | f2m = this.finiteField(); | ||
201 | |||
202 | if (aPointA.x().compare(aPointB.x()) != 0) { | ||
203 | //console.log(" a.x != b.x"); | ||
204 | lambda =f2m._fastMultiply( | ||
205 | f2m._add(aY, bY), | ||
206 | f2m._inverse(f2m._add(aX, bX)) | ||
207 | ); | ||
208 | x = f2m._add(this.a()._value, f2m._square(lambda)); | ||
209 | f2m._overwriteAdd(x, lambda); | ||
210 | f2m._overwriteAdd(x, aX); | ||
211 | f2m._overwriteAdd(x, bX); | ||
212 | } else { | ||
213 | //console.log(" a.x == b.x"); | ||
214 | lambda = f2m._add(bX, f2m._fastMultiply(bY, f2m._inverse(bX))); | ||
215 | //console.log(" lambda: " + lambda.asString(16)); | ||
216 | x = f2m._add(this.a()._value, f2m._square(lambda)); | ||
217 | //console.log(" x (step 1): " + x.asString(16)); | ||
218 | f2m._overwriteAdd(x, lambda); | ||
219 | //console.log(" x (step 2): " + x.asString(16)); | ||
220 | } | ||
221 | |||
222 | y = f2m._fastMultiply(f2m._add(bX, x), lambda); | ||
223 | //console.log(" y (step 1): " + y.asString(16)); | ||
224 | f2m._overwriteAdd(y, x); | ||
225 | //console.log(" y (step 2): " + y.asString(16)); | ||
226 | f2m._overwriteAdd(y, bY); | ||
227 | //console.log(" y (step 3): " + y.asString(16)); | ||
228 | |||
229 | // result = new Clipperz.Crypto.ECC.BinaryField.Point({x:new Clipperz.Crypto.ECC.BinaryField.Value(x), y:new Clipperz.Crypto.ECC.BinaryField.Value(y)}) | ||
230 | aPointA._x._value = x; | ||
231 | aPointA._y._value = y; | ||
232 | |||
233 | } | ||
234 | //console.log("<<< ECC.BinaryField.Curve.add"); | ||
235 | |||
236 | return result; | ||
237 | }, | ||
238 | |||
239 | //----------------------------------------------------------------------------- | ||
240 | |||
241 | 'multiply': function(aValue, aPoint) { | ||
242 | var result; | ||
243 | |||
244 | //console.profile(); | ||
245 | result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); | ||
246 | |||
247 | if (aValue.isZero() == false) { | ||
248 | var k, Q; | ||
249 | var i; | ||
250 | var countIndex; countIndex = 0; | ||
251 | |||
252 | if (aValue.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) > 0) { | ||
253 | k = aValue; | ||
254 | Q = aPoint; | ||
255 | } else { | ||
256 | MochiKit.Logging.logError("The Clipperz.Crypto.ECC.BinaryFields.Value does not work with negative values!!!!"); | ||
257 | k = aValue.negate(); | ||
258 | Q = this.negate(aPoint); | ||
259 | } | ||
260 | |||
261 | //console.log("k: " + k.toString(16)); | ||
262 | //console.log("k.bitSize: " + k.bitSize()); | ||
263 | for (i=k.bitSize()-1; i>=0; i--) { | ||
264 | result = this.add(result, result); | ||
265 | // this.overwriteAdd(result, result); | ||
266 | if (k.isBitSet(i)) { | ||
267 | result = this.add(result, Q); | ||
268 | // this.overwriteAdd(result, Q); | ||
269 | } | ||
270 | |||
271 | // if (countIndex==100) {console.log("multiply.break"); break;} else countIndex++; | ||
272 | } | ||
273 | } | ||
274 | //console.profileEnd(); | ||
275 | |||
276 | return result; | ||
277 | }, | ||
278 | |||
279 | //----------------------------------------------------------------------------- | ||
280 | |||
281 | 'deferredMultiply': function(aValue, aPoint) { | ||
282 | var deferredResult; | ||
283 | var result; | ||
284 | |||
285 | MochiKit.Logging.logDebug(">>> deferredMultiply - value: " + aValue + ", point: " + aPoint); | ||
286 | //console.profile("ECC.Curve.multiply"); | ||
287 | deferredResult = new MochiKit.Async.Deferred(); | ||
288 | //deferredResult.addCallback(function(res) {console.profile("ECC.Curve.deferredMultiply"); return res;} ); | ||
289 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 1: " + res); return res;}); | ||
290 | |||
291 | result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); | ||
292 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 2: " + res); return res;}); | ||
293 | |||
294 | if (aValue.isZero() == false) { | ||
295 | var k, Q; | ||
296 | var i; | ||
297 | var countIndex; countIndex = 0; | ||
298 | |||
299 | if (aValue.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) > 0) { | ||
300 | k = aValue; | ||
301 | Q = aPoint; | ||
302 | } else { | ||
303 | MochiKit.Logging.logError("The Clipperz.Crypto.ECC.BinaryFields.Value does not work with negative values!!!!"); | ||
304 | k = aValue.negate(); | ||
305 | Q = this.negate(aPoint); | ||
306 | } | ||
307 | |||
308 | //console.log("k: " + k.toString(16)); | ||
309 | //console.log("k.bitSize: " + k.bitSize()); | ||
310 | |||
311 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 3: " + res); return res;}); | ||
312 | for (i=k.bitSize()-1; i>=0; i--) { | ||
313 | //MochiKit.Logging.logDebug("====> " + i); | ||
314 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 4 > i = " + i + ": " + res); return res;}); | ||
315 | deferredResult.addMethod(this, "addTwice"); | ||
316 | //# result = this.add(result, result); | ||
317 | // this.overwriteAdd(result, result); | ||
318 | if (k.isBitSet(i)) { | ||
319 | deferredResult.addMethod(this, "add", Q); | ||
320 | //# result = this.add(result, Q); | ||
321 | // this.overwriteAdd(result, Q); | ||
322 | } | ||
323 | if (i%20 == 0) {deferredResult.addCallback(MochiKit.Async.wait, 0.1);} | ||
324 | |||
325 | // if (countIndex==100) {console.log("multiply.break"); break;} else countIndex++; | ||
326 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 4 < i = " + i + ": " + res); return res;}); | ||
327 | } | ||
328 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 4: " + res); return res;}); | ||
329 | } | ||
330 | //#console.profileEnd(); | ||
331 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 5: " + res); return res;}); | ||
332 | //deferredResult.addBoth(function(res) {console.profileEnd(); return res;}); | ||
333 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("# 6: " + res); return res;}); | ||
334 | deferredResult.callback(result); | ||
335 | |||
336 | //# return result; | ||
337 | return deferredResult; | ||
338 | }, | ||
339 | |||
340 | //----------------------------------------------------------------------------- | ||
341 | __syntaxFix__: "syntax fix" | ||
342 | }); | ||
343 | |||
344 | |||
345 | //############################################################################# | ||
346 | |||
347 | Clipperz.Crypto.ECC.StandardCurves = {}; | ||
348 | |||
349 | MochiKit.Base.update(Clipperz.Crypto.ECC.StandardCurves, { | ||
350 | /* | ||
351 | '_K571': null, | ||
352 | 'K571': function() { | ||
353 | if (Clipperz.Crypto.ECC.StandardCurves._K571 == null) { | ||
354 | Clipperz.Crypto.ECC.StandardCurves._K571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
355 | 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), | ||
356 | a: new Clipperz.Crypto.ECC.BinaryField.Value('0', 16), | ||
357 | b: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
358 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
359 | 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), | ||
360 | 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) | ||
361 | }), | ||
362 | 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), | ||
363 | h: new Clipperz.Crypto.ECC.BinaryField.Value('4', 16) | ||
364 | }); | ||
365 | } | ||
366 | |||
367 | return Clipperz.Crypto.ECC.StandardCurves._K571; | ||
368 | }, | ||
369 | |||
370 | |||
371 | |||
372 | '_K283': null, | ||
373 | 'K283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 | ||
374 | if (Clipperz.Crypto.ECC.StandardCurves._K283 == null) { | ||
375 | Clipperz.Crypto.ECC.StandardCurves._K283 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
376 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | ||
377 | a: new Clipperz.Crypto.ECC.BinaryField.Value('0', 16), | ||
378 | b: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
379 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
380 | x: new Clipperz.Crypto.ECC.BinaryField.Value('0503213f 78ca4488 3f1a3b81 62f188e5 53cd265f 23c1567a 16876913 b0c2ac24 58492836', 16), | ||
381 | y: new Clipperz.Crypto.ECC.BinaryField.Value('01ccda38 0f1c9e31 8d90f95d 07e5426f e87e45c0 e8184698 e4596236 4e341161 77dd2259', 16) | ||
382 | }), | ||
383 | r: new Clipperz.Crypto.ECC.BinaryField.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16), | ||
384 | h: new Clipperz.Crypto.ECC.BinaryField.Value('4', 16) | ||
385 | }); | ||
386 | } | ||
387 | |||
388 | return Clipperz.Crypto.ECC.StandardCurves._K283; | ||
389 | }, | ||
390 | */ | ||
391 | //----------------------------------------------------------------------------- | ||
392 | |||
393 | '_B571': null, | ||
394 | 'B571': function() { //f(z) = z^571 + z^10 + z^5 + z^2 + 1 | ||
395 | if (Clipperz.Crypto.ECC.StandardCurves._B571 == null) { | ||
396 | Clipperz.Crypto.ECC.StandardCurves._B571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
397 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425', 16), | ||
398 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
399 | b: new Clipperz.Crypto.ECC.BinaryField.Value('02f40e7e2221f295de297117b7f3d62f5c6a97ffcb8ceff1cd6ba8ce4a9a18ad84ffabbd8efa59332be7ad6756a66e294afd185a78ff12aa520e4de739baca0c7ffeff7f2955727a', 16), | ||
400 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
401 | 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), | ||
402 | 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) | ||
403 | }), | ||
404 | 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), | ||
405 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) | ||
406 | |||
407 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), | ||
408 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) | ||
409 | }); | ||
410 | |||
411 | //----------------------------------------------------------------------------- | ||
412 | // | ||
413 | //Guide to Elliptic Curve Cryptography | ||
414 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | ||
415 | //- Pag: 56, Alorithm 2.45 (with a typo!!!) | ||
416 | // | ||
417 | //----------------------------------------------------------------------------- | ||
418 | // | ||
419 | // http://www.milw0rm.com/papers/136 | ||
420 | // | ||
421 | // ------------------------------------------------------------------------- | ||
422 | // Polynomial Reduction Algorithm Modulo f571 | ||
423 | // ------------------------------------------------------------------------- | ||
424 | // | ||
425 | // Input: Polynomial p(x) of degree 1140 or less, stored as | ||
426 | // an array of 2T machinewords. | ||
427 | // Output: p(x) mod f571(x) | ||
428 | // | ||
429 | // FOR i = T-1, ..., 0 DO | ||
430 | // SET X := P[i+T] | ||
431 | // P[i] := P[i] ^ (X<<5) ^ (X<<7) ^ (X<<10) ^ (X<<15) | ||
432 | // P[i+1] := P[i+1] ^ (X>>17) ^ (X>>22) ^ (X>>25) ^ (X>>27) | ||
433 | // | ||
434 | // SET X := P[T-1] >> 27 | ||
435 | // P[0] := P[0] ^ X ^ (X<<2) ^ (X<<5) ^ (X<<10) | ||
436 | // P[T-1] := P[T-1] & 0x07ffffff | ||
437 | // | ||
438 | // RETURN P[T-1],...,P[0] | ||
439 | // | ||
440 | // ------------------------------------------------------------------------- | ||
441 | // | ||
442 | Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().slowModule = Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().module; | ||
443 | Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().module = function(aValue) { | ||
444 | varresult; | ||
445 | |||
446 | if (aValue.bitSize() > 1140) { | ||
447 | MochiKit.Logging.logWarning("ECC.StandarCurves.B571.finiteField().module: falling back to default implementation"); | ||
448 | result = Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().slowModule(aValue); | ||
449 | } else { | ||
450 | varC, T; | ||
451 | var i; | ||
452 | |||
453 | //console.log(">>> binaryField.finiteField.(improved)module"); | ||
454 | // C = aValue.value().slice(0); | ||
455 | C = aValue._value.slice(0); | ||
456 | for (i=35; i>=18; i--) { | ||
457 | T = C[i]; | ||
458 | C[i-18] = (((C[i-18] ^ (T<<5) ^ (T<<7) ^ (T<<10) ^ (T<<15)) & 0xffffffff) >>> 0); | ||
459 | C[i-17] = ((C[i-17] ^ (T>>>27) ^ (T>>>25) ^ (T>>>22) ^ (T>>>17)) >>> 0); | ||
460 | } | ||
461 | T = (C[17] >>> 27); | ||
462 | C[0] = ((C[0] ^ T ^ ((T<<2) ^ (T<<5) ^ (T<<10)) & 0xffffffff) >>> 0); | ||
463 | C[17] = (C[17] & 0x07ffffff); | ||
464 | |||
465 | for(i=18; i<=35; i++) { | ||
466 | C[i] = 0; | ||
467 | } | ||
468 | |||
469 | result = new Clipperz.Crypto.ECC.BinaryField.Value(C); | ||
470 | //console.log("<<< binaryField.finiteField.(improved)module"); | ||
471 | } | ||
472 | |||
473 | return result; | ||
474 | }; | ||
475 | } | ||
476 | |||
477 | return Clipperz.Crypto.ECC.StandardCurves._B571; | ||
478 | }, | ||
479 | |||
480 | //----------------------------------------------------------------------------- | ||
481 | |||
482 | '_B283': null, | ||
483 | 'B283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 | ||
484 | if (Clipperz.Crypto.ECC.StandardCurves._B283 == null) { | ||
485 | Clipperz.Crypto.ECC.StandardCurves._B283 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
486 | // modulus: new Clipperz.Crypto.ECC.BinaryField.Value('10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | ||
487 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | ||
488 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
489 | b: new Clipperz.Crypto.ECC.BinaryField.Value('027b680a c8b8596d a5a4af8a 19a0303f ca97fd76 45309fa2 a581485a f6263e31 3b79a2f5', 16), | ||
490 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
491 | x: new Clipperz.Crypto.ECC.BinaryField.Value('05f93925 8db7dd90 e1934f8c 70b0dfec 2eed25b8 557eac9c 80e2e198 f8cdbecd 86b12053', 16), | ||
492 | y: new Clipperz.Crypto.ECC.BinaryField.Value('03676854 fe24141c b98fe6d4 b20d02b4 516ff702 350eddb0 826779c8 13f0df45 be8112f4', 16) | ||
493 | }), | ||
494 | r: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffff ffffffff ffffffff ffffffff ffffef90 399660fc 938a9016 5b042a7c efadb307', 16), | ||
495 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) | ||
496 | |||
497 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), | ||
498 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) | ||
499 | }); | ||
500 | |||
501 | //----------------------------------------------------------------------------- | ||
502 | // | ||
503 | //Guide to Elliptic Curve Cryptography | ||
504 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | ||
505 | //- Pag: 56, Alorithm 2.43 | ||
506 | // | ||
507 | //----------------------------------------------------------------------------- | ||
508 | Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().slowModule = Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().module; | ||
509 | Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().module = function(aValue) { | ||
510 | varresult; | ||
511 | |||
512 | if (aValue.bitSize() > 564) { | ||
513 | MochiKit.Logging.logWarning("ECC.StandarCurves.B283.finiteField().module: falling back to default implementation"); | ||
514 | result = Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().slowModule(aValue); | ||
515 | } else { | ||
516 | varC, T; | ||
517 | var i; | ||
518 | |||
519 | //console.log(">>> binaryField.finiteField.(improved)module"); | ||
520 | C = aValue._value.slice(0); | ||
521 | for (i=17; i>=9; i--) { | ||
522 | T = C[i]; | ||
523 | C[i-9] = (((C[i-9] ^ (T<<5) ^ (T<<10) ^ (T<<12) ^ (T<<17)) & 0xffffffff) >>> 0); | ||
524 | C[i-8] = ((C[i-8] ^ (T>>>27) ^ (T>>>22) ^ (T>>>20) ^ (T>>>15)) >>> 0); | ||
525 | } | ||
526 | T = (C[8] >>> 27); | ||
527 | C[0] = ((C[0] ^ T ^ ((T<<5) ^ (T<<7) ^ (T<<12)) & 0xffffffff) >>> 0); | ||
528 | C[8] = (C[8] & 0x07ffffff); | ||
529 | |||
530 | for(i=9; i<=17; i++) { | ||
531 | C[i] = 0; | ||
532 | } | ||
533 | |||
534 | result = new Clipperz.Crypto.ECC.BinaryField.Value(C); | ||
535 | //console.log("<<< binaryField.finiteField.(improved)module"); | ||
536 | } | ||
537 | |||
538 | return result; | ||
539 | }; | ||
540 | } | ||
541 | |||
542 | return Clipperz.Crypto.ECC.StandardCurves._B283; | ||
543 | }, | ||
544 | |||
545 | //----------------------------------------------------------------------------- | ||
546 | __syntaxFix__: "syntax fix" | ||
547 | }); | ||
548 | |||
549 | //############################################################################# | ||
550 | |||
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js new file mode 100644 index 0000000..a649c9f --- a/dev/null +++ b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js | |||
@@ -0,0 +1,526 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | ||
30 | //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; | ||
31 | //} | ||
32 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | ||
33 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | ||
34 | |||
35 | Clipperz.Crypto.ECC.BinaryField.FiniteField = function(args) { | ||
36 | args = args || {}; | ||
37 | this._modulus = args.modulus; | ||
38 | |||
39 | return this; | ||
40 | } | ||
41 | |||
42 | Clipperz.Crypto.ECC.BinaryField.FiniteField.prototype = MochiKit.Base.update(null, { | ||
43 | |||
44 | 'asString': function() { | ||
45 | return "Clipperz.Crypto.ECC.BinaryField.FiniteField (" + this.modulus().asString() + ")"; | ||
46 | }, | ||
47 | |||
48 | //----------------------------------------------------------------------------- | ||
49 | |||
50 | 'modulus': function() { | ||
51 | return this._modulus; | ||
52 | }, | ||
53 | |||
54 | //----------------------------------------------------------------------------- | ||
55 | |||
56 | '_module': function(aValue) { | ||
57 | varresult; | ||
58 | var modulusComparison; | ||
59 | //console.log(">>> binaryField.finiteField.(standard)module"); | ||
60 | |||
61 | modulusComparison = Clipperz.Crypto.ECC.BinaryField.Value._compare(aValue, this.modulus()._value); | ||
62 | |||
63 | if (modulusComparison < 0) { | ||
64 | result = aValue; | ||
65 | } else if (modulusComparison == 0) { | ||
66 | result = [0]; | ||
67 | } else { | ||
68 | var modulusBitSize; | ||
69 | var resultBitSize; | ||
70 | |||
71 | result = aValue; | ||
72 | |||
73 | modulusBitSize = this.modulus().bitSize(); | ||
74 | resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); | ||
75 | while (resultBitSize >= modulusBitSize) { | ||
76 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this.modulus()._value, resultBitSize - modulusBitSize)); | ||
77 | resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); | ||
78 | } | ||
79 | } | ||
80 | //console.log("<<< binaryField.finiteField.(standard)module"); | ||
81 | |||
82 | return result; | ||
83 | }, | ||
84 | |||
85 | 'module': function(aValue) { | ||
86 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._module(aValue._value.slice(0))); | ||
87 | }, | ||
88 | |||
89 | //----------------------------------------------------------------------------- | ||
90 | |||
91 | '_add': function(a, b) { | ||
92 | return Clipperz.Crypto.ECC.BinaryField.Value._xor(a, b); | ||
93 | }, | ||
94 | |||
95 | '_overwriteAdd': function(a, b) { | ||
96 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(a, b); | ||
97 | }, | ||
98 | |||
99 | 'add': function(a, b) { | ||
100 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._add(a._value, b._value)); | ||
101 | }, | ||
102 | |||
103 | //----------------------------------------------------------------------------- | ||
104 | |||
105 | 'negate': function(aValue) { | ||
106 | return aValue.clone(); | ||
107 | }, | ||
108 | |||
109 | //----------------------------------------------------------------------------- | ||
110 | |||
111 | '_multiply': function(a, b) { | ||
112 | var result; | ||
113 | var valueToXor; | ||
114 | var i,c; | ||
115 | |||
116 | result = [0]; | ||
117 | valueToXor = b; | ||
118 | c = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(a); | ||
119 | for (i=0; i<c; i++) { | ||
120 | if (Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(a, i) === true) { | ||
121 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, valueToXor); | ||
122 | } | ||
123 | valueToXor = Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft(valueToXor, 1); | ||
124 | } | ||
125 | result = this._module(result); | ||
126 | |||
127 | return result; | ||
128 | }, | ||
129 | |||
130 | 'multiply': function(a, b) { | ||
131 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._multiply(a._value, b._value)); | ||
132 | }, | ||
133 | |||
134 | //----------------------------------------------------------------------------- | ||
135 | |||
136 | '_fastMultiply': function(a, b) { | ||
137 | var result; | ||
138 | var B; | ||
139 | var i,c; | ||
140 | |||
141 | result = [0]; | ||
142 | B = b.slice(0); //Is this array copy avoidable? | ||
143 | c = 32; | ||
144 | for (i=0; i<c; i++) { | ||
145 | var ii, cc; | ||
146 | |||
147 | cc = a.length; | ||
148 | for (ii=0; ii<cc; ii++) { | ||
149 | if (((a[ii] >>> i) & 0x01) == 1) { | ||
150 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, B, ii); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | if (i < (c-1)) { | ||
155 | B = Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft(B, 1); | ||
156 | } | ||
157 | } | ||
158 | result = this._module(result); | ||
159 | |||
160 | return result; | ||
161 | }, | ||
162 | |||
163 | 'fastMultiply': function(a, b) { | ||
164 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._fastMultiply(a._value, b._value)); | ||
165 | }, | ||
166 | |||
167 | //----------------------------------------------------------------------------- | ||
168 | // | ||
169 | //Guide to Elliptic Curve Cryptography | ||
170 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | ||
171 | //- Pag: 49, Alorithm 2.34 | ||
172 | // | ||
173 | //----------------------------------------------------------------------------- | ||
174 | |||
175 | '_square': function(aValue) { | ||
176 | var result; | ||
177 | var value; | ||
178 | var c,i; | ||
179 | var precomputedValues; | ||
180 | |||
181 | value = aValue; | ||
182 | result = new Array(value.length * 2); | ||
183 | precomputedValues = Clipperz.Crypto.ECC.BinaryField.FiniteField.squarePrecomputedBytes; | ||
184 | |||
185 | c = value.length; | ||
186 | for (i=0; i<c; i++) { | ||
187 | result[i*2] = precomputedValues[(value[i] & 0x000000ff)]; | ||
188 | result[i*2] |= ((precomputedValues[(value[i] & 0x0000ff00) >>> 8]) << 16); | ||
189 | |||
190 | result[i*2 + 1] = precomputedValues[(value[i] & 0x00ff0000) >>> 16]; | ||
191 | result[i*2 + 1] |= ((precomputedValues[(value[i] & 0xff000000) >>> 24]) << 16); | ||
192 | } | ||
193 | |||
194 | return this._module(result); | ||
195 | }, | ||
196 | |||
197 | 'square': function(aValue) { | ||
198 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._square(aValue._value)); | ||
199 | }, | ||
200 | |||
201 | //----------------------------------------------------------------------------- | ||
202 | |||
203 | '_inverse': function(aValue) { | ||
204 | varresult; | ||
205 | var b, c; | ||
206 | var u, v; | ||
207 | |||
208 | // b = Clipperz.Crypto.ECC.BinaryField.Value.I._value; | ||
209 | b = [1]; | ||
210 | // c = Clipperz.Crypto.ECC.BinaryField.Value.O._value; | ||
211 | c = [0]; | ||
212 | u = this._module(aValue); | ||
213 | v = this.modulus()._value.slice(0); | ||
214 | |||
215 | while (Clipperz.Crypto.ECC.BinaryField.Value._bitSize(u) > 1) { | ||
216 | varbitDifferenceSize; | ||
217 | |||
218 | bitDifferenceSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(u) - Clipperz.Crypto.ECC.BinaryField.Value._bitSize(v); | ||
219 | if (bitDifferenceSize < 0) { | ||
220 | var swap; | ||
221 | |||
222 | swap = u; | ||
223 | u = v; | ||
224 | v = swap; | ||
225 | |||
226 | swap = c; | ||
227 | c = b; | ||
228 | b = swap; | ||
229 | |||
230 | bitDifferenceSize = -bitDifferenceSize; | ||
231 | } | ||
232 | |||
233 | u = this._add(u, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(v, bitDifferenceSize)); | ||
234 | b = this._add(b, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(c, bitDifferenceSize)); | ||
235 | // this._overwriteAdd(u, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(v, bitDifferenceSize)); | ||
236 | // this._overwriteAdd(b, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(c, bitDifferenceSize)); | ||
237 | } | ||
238 | |||
239 | result = this._module(b); | ||
240 | |||
241 | return result; | ||
242 | }, | ||
243 | |||
244 | 'inverse': function(aValue) { | ||
245 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._inverse(aValue._value)); | ||
246 | }, | ||
247 | |||
248 | //----------------------------------------------------------------------------- | ||
249 | __syntaxFix__: "syntax fix" | ||
250 | }); | ||
251 | |||
252 | |||
253 | Clipperz.Crypto.ECC.BinaryField.FiniteField.squarePrecomputedBytes = [ | ||
254 | 0x0000, // 0 = 0000 0000 -> 0000 0000 0000 0000 | ||
255 | 0x0001, // 1 = 0000 0001 -> 0000 0000 0000 0001 | ||
256 | 0x0004, // 2 = 0000 0010 -> 0000 0000 0000 0100 | ||
257 | 0x0005, // 3 = 0000 0011 -> 0000 0000 0000 0101 | ||
258 | 0x0010, // 4 = 0000 0100 -> 0000 0000 0001 0000 | ||
259 | 0x0011, // 5 = 0000 0101 -> 0000 0000 0001 0001 | ||
260 | 0x0014, // 6 = 0000 0110 -> 0000 0000 0001 0100 | ||
261 | 0x0015, // 7 = 0000 0111 -> 0000 0000 0001 0101 | ||
262 | 0x0040, // 8 = 0000 1000 -> 0000 0000 0100 0000 | ||
263 | 0x0041, // 9 = 0000 1001 -> 0000 0000 0100 0001 | ||
264 | 0x0044, // 10 = 0000 1010 -> 0000 0000 0100 0100 | ||
265 | 0x0045, // 11 = 0000 1011 -> 0000 0000 0100 0101 | ||
266 | 0x0050, // 12 = 0000 1100 -> 0000 0000 0101 0000 | ||
267 | 0x0051, // 13 = 0000 1101 -> 0000 0000 0101 0001 | ||
268 | 0x0054, // 14 = 0000 1110 -> 0000 0000 0101 0100 | ||
269 | 0x0055, // 15 = 0000 1111 -> 0000 0000 0101 0101 | ||
270 | |||
271 | 0x0100, // 16 = 0001 0000 -> 0000 0001 0000 0000 | ||
272 | 0x0101, // 17 = 0001 0001 -> 0000 0001 0000 0001 | ||
273 | 0x0104, // 18 = 0001 0010 -> 0000 0001 0000 0100 | ||
274 | 0x0105, // 19 = 0001 0011 -> 0000 0001 0000 0101 | ||
275 | 0x0110, // 20 = 0001 0100 -> 0000 0001 0001 0000 | ||
276 | 0x0111, // 21 = 0001 0101 -> 0000 0001 0001 0001 | ||
277 | 0x0114, // 22 = 0001 0110 -> 0000 0001 0001 0100 | ||
278 | 0x0115, // 23 = 0001 0111 -> 0000 0001 0001 0101 | ||
279 | 0x0140, // 24 = 0001 1000 -> 0000 0001 0100 0000 | ||
280 | 0x0141, // 25 = 0001 1001 -> 0000 0001 0100 0001 | ||
281 | 0x0144, // 26 = 0001 1010 -> 0000 0001 0100 0100 | ||
282 | 0x0145, // 27 = 0001 1011 -> 0000 0001 0100 0101 | ||
283 | 0x0150, // 28 = 0001 1100 -> 0000 0001 0101 0000 | ||
284 | 0x0151, // 28 = 0001 1101 -> 0000 0001 0101 0001 | ||
285 | 0x0154, // 30 = 0001 1110 -> 0000 0001 0101 0100 | ||
286 | 0x0155, // 31 = 0001 1111 -> 0000 0001 0101 0101 | ||
287 | |||
288 | 0x0400, // 32 = 0010 0000 -> 0000 0100 0000 0000 | ||
289 | 0x0401, // 33 = 0010 0001 -> 0000 0100 0000 0001 | ||
290 | 0x0404, // 34 = 0010 0010 -> 0000 0100 0000 0100 | ||
291 | 0x0405, // 35 = 0010 0011 -> 0000 0100 0000 0101 | ||
292 | 0x0410, // 36 = 0010 0100 -> 0000 0100 0001 0000 | ||
293 | 0x0411, // 37 = 0010 0101 -> 0000 0100 0001 0001 | ||
294 | 0x0414, // 38 = 0010 0110 -> 0000 0100 0001 0100 | ||
295 | 0x0415, // 39 = 0010 0111 -> 0000 0100 0001 0101 | ||
296 | 0x0440, // 40 = 0010 1000 -> 0000 0100 0100 0000 | ||
297 | 0x0441, // 41 = 0010 1001 -> 0000 0100 0100 0001 | ||
298 | 0x0444, // 42 = 0010 1010 -> 0000 0100 0100 0100 | ||
299 | 0x0445, // 43 = 0010 1011 -> 0000 0100 0100 0101 | ||
300 | 0x0450, // 44 = 0010 1100 -> 0000 0100 0101 0000 | ||
301 | 0x0451, // 45 = 0010 1101 -> 0000 0100 0101 0001 | ||
302 | 0x0454, // 46 = 0010 1110 -> 0000 0100 0101 0100 | ||
303 | 0x0455, // 47 = 0010 1111 -> 0000 0100 0101 0101 | ||
304 | |||
305 | 0x0500, // 48 = 0011 0000 -> 0000 0101 0000 0000 | ||
306 | 0x0501, // 49 = 0011 0001 -> 0000 0101 0000 0001 | ||
307 | 0x0504, // 50 = 0011 0010 -> 0000 0101 0000 0100 | ||
308 | 0x0505, // 51 = 0011 0011 -> 0000 0101 0000 0101 | ||
309 | 0x0510, // 52 = 0011 0100 -> 0000 0101 0001 0000 | ||
310 | 0x0511, // 53 = 0011 0101 -> 0000 0101 0001 0001 | ||
311 | 0x0514, // 54 = 0011 0110 -> 0000 0101 0001 0100 | ||
312 | 0x0515, // 55 = 0011 0111 -> 0000 0101 0001 0101 | ||
313 | 0x0540, // 56 = 0011 1000 -> 0000 0101 0100 0000 | ||
314 | 0x0541, // 57 = 0011 1001 -> 0000 0101 0100 0001 | ||
315 | 0x0544, // 58 = 0011 1010 -> 0000 0101 0100 0100 | ||
316 | 0x0545, // 59 = 0011 1011 -> 0000 0101 0100 0101 | ||
317 | 0x0550, // 60 = 0011 1100 -> 0000 0101 0101 0000 | ||
318 | 0x0551, // 61 = 0011 1101 -> 0000 0101 0101 0001 | ||
319 | 0x0554, // 62 = 0011 1110 -> 0000 0101 0101 0100 | ||
320 | 0x0555, // 63 = 0011 1111 -> 0000 0101 0101 0101 | ||
321 | |||
322 | 0x1000, // 64 = 0100 0000 -> 0001 0000 0000 0000 | ||
323 | 0x1001, // 65 = 0100 0001 -> 0001 0000 0000 0001 | ||
324 | 0x1004, // 66 = 0100 0010 -> 0001 0000 0000 0100 | ||
325 | 0x1005, // 67 = 0100 0011 -> 0001 0000 0000 0101 | ||
326 | 0x1010, // 68 = 0100 0100 -> 0001 0000 0001 0000 | ||
327 | 0x1011, // 69 = 0100 0101 -> 0001 0000 0001 0001 | ||
328 | 0x1014, // 70 = 0100 0110 -> 0001 0000 0001 0100 | ||
329 | 0x1015, // 71 = 0100 0111 -> 0001 0000 0001 0101 | ||
330 | 0x1040, // 72 = 0100 1000 -> 0001 0000 0100 0000 | ||
331 | 0x1041, // 73 = 0100 1001 -> 0001 0000 0100 0001 | ||
332 | 0x1044, // 74 = 0100 1010 -> 0001 0000 0100 0100 | ||
333 | 0x1045, // 75 = 0100 1011 -> 0001 0000 0100 0101 | ||
334 | 0x1050, // 76 = 0100 1100 -> 0001 0000 0101 0000 | ||
335 | 0x1051, // 77 = 0100 1101 -> 0001 0000 0101 0001 | ||
336 | 0x1054, // 78 = 0100 1110 -> 0001 0000 0101 0100 | ||
337 | 0x1055, // 79 = 0100 1111 -> 0001 0000 0101 0101 | ||
338 | |||
339 | 0x1100, // 80 = 0101 0000 -> 0001 0001 0000 0000 | ||
340 | 0x1101, // 81 = 0101 0001 -> 0001 0001 0000 0001 | ||
341 | 0x1104, // 82 = 0101 0010 -> 0001 0001 0000 0100 | ||
342 | 0x1105, // 83 = 0101 0011 -> 0001 0001 0000 0101 | ||
343 | 0x1110, // 84 = 0101 0100 -> 0001 0001 0001 0000 | ||
344 | 0x1111, // 85 = 0101 0101 -> 0001 0001 0001 0001 | ||
345 | 0x1114, // 86 = 0101 0110 -> 0001 0001 0001 0100 | ||
346 | 0x1115, // 87 = 0101 0111 -> 0001 0001 0001 0101 | ||
347 | 0x1140, // 88 = 0101 1000 -> 0001 0001 0100 0000 | ||
348 | 0x1141, // 89 = 0101 1001 -> 0001 0001 0100 0001 | ||
349 | 0x1144, // 90 = 0101 1010 -> 0001 0001 0100 0100 | ||
350 | 0x1145, // 91 = 0101 1011 -> 0001 0001 0100 0101 | ||
351 | 0x1150, // 92 = 0101 1100 -> 0001 0001 0101 0000 | ||
352 | 0x1151, // 93 = 0101 1101 -> 0001 0001 0101 0001 | ||
353 | 0x1154, // 94 = 0101 1110 -> 0001 0001 0101 0100 | ||
354 | 0x1155, // 95 = 0101 1111 -> 0001 0001 0101 0101 | ||
355 | |||
356 | 0x1400, // 96 = 0110 0000 -> 0001 0100 0000 0000 | ||
357 | 0x1401, // 97 = 0110 0001 -> 0001 0100 0000 0001 | ||
358 | 0x1404, // 98 = 0110 0010 -> 0001 0100 0000 0100 | ||
359 | 0x1405, // 99 = 0110 0011 -> 0001 0100 0000 0101 | ||
360 | 0x1410, //100 = 0110 0100 -> 0001 0100 0001 0000 | ||
361 | 0x1411, //101 = 0110 0101 -> 0001 0100 0001 0001 | ||
362 | 0x1414, //102 = 0110 0110 -> 0001 0100 0001 0100 | ||
363 | 0x1415, //103 = 0110 0111 -> 0001 0100 0001 0101 | ||
364 | 0x1440, //104 = 0110 1000 -> 0001 0100 0100 0000 | ||
365 | 0x1441, //105 = 0110 1001 -> 0001 0100 0100 0001 | ||
366 | 0x1444, //106 = 0110 1010 -> 0001 0100 0100 0100 | ||
367 | 0x1445, //107 = 0110 1011 -> 0001 0100 0100 0101 | ||
368 | 0x1450, //108 = 0110 1100 -> 0001 0100 0101 0000 | ||
369 | 0x1451, //109 = 0110 1101 -> 0001 0100 0101 0001 | ||
370 | 0x1454, //110 = 0110 1110 -> 0001 0100 0101 0100 | ||
371 | 0x1455, //111 = 0110 1111 -> 0001 0100 0101 0101 | ||
372 | |||
373 | 0x1500, //112 = 0111 0000 -> 0001 0101 0000 0000 | ||
374 | 0x1501, //113 = 0111 0001 -> 0001 0101 0000 0001 | ||
375 | 0x1504, //114 = 0111 0010 -> 0001 0101 0000 0100 | ||
376 | 0x1505, //115 = 0111 0011 -> 0001 0101 0000 0101 | ||
377 | 0x1510, //116 = 0111 0100 -> 0001 0101 0001 0000 | ||
378 | 0x1511, //117 = 0111 0101 -> 0001 0101 0001 0001 | ||
379 | 0x1514, //118 = 0111 0110 -> 0001 0101 0001 0100 | ||
380 | 0x1515, //119 = 0111 0111 -> 0001 0101 0001 0101 | ||
381 | 0x1540, //120 = 0111 1000 -> 0001 0101 0100 0000 | ||
382 | 0x1541, //121 = 0111 1001 -> 0001 0101 0100 0001 | ||
383 | 0x1544, //122 = 0111 1010 -> 0001 0101 0100 0100 | ||
384 | 0x1545, //123 = 0111 1011 -> 0001 0101 0100 0101 | ||
385 | 0x1550, //124 = 0111 1100 -> 0001 0101 0101 0000 | ||
386 | 0x1551, //125 = 0111 1101 -> 0001 0101 0101 0001 | ||
387 | 0x1554, //126 = 0111 1110 -> 0001 0101 0101 0100 | ||
388 | 0x1555, //127 = 0111 1111 -> 0001 0101 0101 0101 | ||
389 | |||
390 | 0x4000, //128 = 1000 0000 -> 0100 0000 0000 0000 | ||
391 | 0x4001, //129 = 1000 0001 -> 0100 0000 0000 0001 | ||
392 | 0x4004, //130 = 1000 0010 -> 0100 0000 0000 0100 | ||
393 | 0x4005, //131 = 1000 0011 -> 0100 0000 0000 0101 | ||
394 | 0x4010, //132 = 1000 0100 -> 0100 0000 0001 0000 | ||
395 | 0x4011, //133 = 1000 0101 -> 0100 0000 0001 0001 | ||
396 | 0x4014, //134 = 1000 0110 -> 0100 0000 0001 0100 | ||
397 | 0x4015, //135 = 1000 0111 -> 0100 0000 0001 0101 | ||
398 | 0x4040, //136 = 1000 1000 -> 0100 0000 0100 0000 | ||
399 | 0x4041, //137 = 1000 1001 -> 0100 0000 0100 0001 | ||
400 | 0x4044, //138 = 1000 1010 -> 0100 0000 0100 0100 | ||
401 | 0x4045, //139 = 1000 1011 -> 0100 0000 0100 0101 | ||
402 | 0x4050, //140 = 1000 1100 -> 0100 0000 0101 0000 | ||
403 | 0x4051, //141 = 1000 1101 -> 0100 0000 0101 0001 | ||
404 | 0x4054, //142 = 1000 1110 -> 0100 0000 0101 0100 | ||
405 | 0x4055, //143 = 1000 1111 -> 0100 0000 0101 0101 | ||
406 | |||
407 | 0x4100, //144 = 1001 0000 -> 0100 0001 0000 0000 | ||
408 | 0x4101, //145 = 1001 0001 -> 0100 0001 0000 0001 | ||
409 | 0x4104, //146 = 1001 0010 -> 0100 0001 0000 0100 | ||
410 | 0x4105, //147 = 1001 0011 -> 0100 0001 0000 0101 | ||
411 | 0x4110, //148 = 1001 0100 -> 0100 0001 0001 0000 | ||
412 | 0x4111, //149 = 1001 0101 -> 0100 0001 0001 0001 | ||
413 | 0x4114, //150 = 1001 0110 -> 0100 0001 0001 0100 | ||
414 | 0x4115, //151 = 1001 0111 -> 0100 0001 0001 0101 | ||
415 | 0x4140, //152 = 1001 1000 -> 0100 0001 0100 0000 | ||
416 | 0x4141, //153 = 1001 1001 -> 0100 0001 0100 0001 | ||
417 | 0x4144, //154 = 1001 1010 -> 0100 0001 0100 0100 | ||
418 | 0x4145, //155 = 1001 1011 -> 0100 0001 0100 0101 | ||
419 | 0x4150, //156 = 1001 1100 -> 0100 0001 0101 0000 | ||
420 | 0x4151, //157 = 1001 1101 -> 0100 0001 0101 0001 | ||
421 | 0x4154, //158 = 1001 1110 -> 0100 0001 0101 0100 | ||
422 | 0x4155, //159 = 1001 1111 -> 0100 0001 0101 0101 | ||
423 | |||
424 | 0x4400, //160 = 1010 0000 -> 0100 0100 0000 0000 | ||
425 | 0x4401, //161 = 1010 0001 -> 0100 0100 0000 0001 | ||
426 | 0x4404, //162 = 1010 0010 -> 0100 0100 0000 0100 | ||
427 | 0x4405, //163 = 1010 0011 -> 0100 0100 0000 0101 | ||
428 | 0x4410, //164 = 1010 0100 -> 0100 0100 0001 0000 | ||
429 | 0x4411, //165 = 1010 0101 -> 0100 0100 0001 0001 | ||
430 | 0x4414, //166 = 1010 0110 -> 0100 0100 0001 0100 | ||
431 | 0x4415, //167 = 1010 0111 -> 0100 0100 0001 0101 | ||
432 | 0x4440, //168 = 1010 1000 -> 0100 0100 0100 0000 | ||
433 | 0x4441, //169 = 1010 1001 -> 0100 0100 0100 0001 | ||
434 | 0x4444, //170 = 1010 1010 -> 0100 0100 0100 0100 | ||
435 | 0x4445, //171 = 1010 1011 -> 0100 0100 0100 0101 | ||
436 | 0x4450, //172 = 1010 1100 -> 0100 0100 0101 0000 | ||
437 | 0x4451, //173 = 1010 1101 -> 0100 0100 0101 0001 | ||
438 | 0x4454, //174 = 1010 1110 -> 0100 0100 0101 0100 | ||
439 | 0x4455, //175 = 1010 1111 -> 0100 0100 0101 0101 | ||
440 | |||
441 | 0x4500, //176 = 1011 0000 -> 0100 0101 0000 0000 | ||
442 | 0x4501, //177 = 1011 0001 -> 0100 0101 0000 0001 | ||
443 | 0x4504, //178 = 1011 0010 -> 0100 0101 0000 0100 | ||
444 | 0x4505, //179 = 1011 0011 -> 0100 0101 0000 0101 | ||
445 | 0x4510, //180 = 1011 0100 -> 0100 0101 0001 0000 | ||
446 | 0x4511, //181 = 1011 0101 -> 0100 0101 0001 0001 | ||
447 | 0x4514, //182 = 1011 0110 -> 0100 0101 0001 0100 | ||
448 | 0x4515, //183 = 1011 0111 -> 0100 0101 0001 0101 | ||
449 | 0x4540, //184 = 1011 1000 -> 0100 0101 0100 0000 | ||
450 | 0x4541, //185 = 1011 1001 -> 0100 0101 0100 0001 | ||
451 | 0x4544, //186 = 1011 1010 -> 0100 0101 0100 0100 | ||
452 | 0x4545, //187 = 1011 1011 -> 0100 0101 0100 0101 | ||
453 | 0x4550, //188 = 1011 1100 -> 0100 0101 0101 0000 | ||
454 | 0x4551, //189 = 1011 1101 -> 0100 0101 0101 0001 | ||
455 | 0x4554, //190 = 1011 1110 -> 0100 0101 0101 0100 | ||
456 | 0x4555, //191 = 1011 1111 -> 0100 0101 0101 0101 | ||
457 | |||
458 | 0x5000, //192 = 1100 0000 -> 0101 0000 0000 0000 | ||
459 | 0x5001, //193 = 1100 0001 -> 0101 0000 0000 0001 | ||
460 | 0x5004, //194 = 1100 0010 -> 0101 0000 0000 0100 | ||
461 | 0x5005, //195 = 1100 0011 -> 0101 0000 0000 0101 | ||
462 | 0x5010, //196 = 1100 0100 -> 0101 0000 0001 0000 | ||
463 | 0x5011, //197 = 1100 0101 -> 0101 0000 0001 0001 | ||
464 | 0x5014, //198 = 1100 0110 -> 0101 0000 0001 0100 | ||
465 | 0x5015, //199 = 1100 0111 -> 0101 0000 0001 0101 | ||
466 | 0x5040, //200 = 1100 1000 -> 0101 0000 0100 0000 | ||
467 | 0x5041, //201 = 1100 1001 -> 0101 0000 0100 0001 | ||
468 | 0x5044, //202 = 1100 1010 -> 0101 0000 0100 0100 | ||
469 | 0x5045, //203 = 1100 1011 -> 0101 0000 0100 0101 | ||
470 | 0x5050, //204 = 1100 1100 -> 0101 0000 0101 0000 | ||
471 | 0x5051, //205 = 1100 1101 -> 0101 0000 0101 0001 | ||
472 | 0x5054, //206 = 1100 1110 -> 0101 0000 0101 0100 | ||
473 | 0x5055, //207 = 1100 1111 -> 0101 0000 0101 0101 | ||
474 | |||
475 | 0x5100, //208 = 1101 0000 -> 0101 0001 0000 0000 | ||
476 | 0x5101, //209 = 1101 0001 -> 0101 0001 0000 0001 | ||
477 | 0x5104, //210 = 1101 0010 -> 0101 0001 0000 0100 | ||
478 | 0x5105, //211 = 1101 0011 -> 0101 0001 0000 0101 | ||
479 | 0x5110, //212 = 1101 0100 -> 0101 0001 0001 0000 | ||
480 | 0x5111, //213 = 1101 0101 -> 0101 0001 0001 0001 | ||
481 | 0x5114, //214 = 1101 0110 -> 0101 0001 0001 0100 | ||
482 | 0x5115, //215 = 1101 0111 -> 0101 0001 0001 0101 | ||
483 | 0x5140, //216 = 1101 1000 -> 0101 0001 0100 0000 | ||
484 | 0x5141, //217 = 1101 1001 -> 0101 0001 0100 0001 | ||
485 | 0x5144, //218 = 1101 1010 -> 0101 0001 0100 0100 | ||
486 | 0x5145, //219 = 1101 1011 -> 0101 0001 0100 0101 | ||
487 | 0x5150, //220 = 1101 1100 -> 0101 0001 0101 0000 | ||
488 | 0x5151, //221 = 1101 1101 -> 0101 0001 0101 0001 | ||
489 | 0x5154, //222 = 1101 1110 -> 0101 0001 0101 0100 | ||
490 | 0x5155, //223 = 1101 1111 -> 0101 0001 0101 0101 | ||
491 | |||
492 | 0x5400, //224 = 1110 0000 -> 0101 0100 0000 0000 | ||
493 | 0x5401, //225 = 1110 0001 -> 0101 0100 0000 0001 | ||
494 | 0x5404, //226 = 1110 0010 -> 0101 0100 0000 0100 | ||
495 | 0x5405, //227 = 1110 0011 -> 0101 0100 0000 0101 | ||
496 | 0x5410, //228 = 1110 0100 -> 0101 0100 0001 0000 | ||
497 | 0x5411, //229 = 1110 0101 -> 0101 0100 0001 0001 | ||
498 | 0x5414, //230 = 1110 0110 -> 0101 0100 0001 0100 | ||
499 | 0x5415, //231 = 1110 0111 -> 0101 0100 0001 0101 | ||
500 | 0x5440, //232 = 1110 1000 -> 0101 0100 0100 0000 | ||
501 | 0x5441, //233 = 1110 1001 -> 0101 0100 0100 0001 | ||
502 | 0x5444, //234 = 1110 1010 -> 0101 0100 0100 0100 | ||
503 | 0x5445, //235 = 1110 1011 -> 0101 0100 0100 0101 | ||
504 | 0x5450, //236 = 1110 1100 -> 0101 0100 0101 0000 | ||
505 | 0x5451, //237 = 1110 1101 -> 0101 0100 0101 0001 | ||
506 | 0x5454, //238 = 1110 1110 -> 0101 0100 0101 0100 | ||
507 | 0x5455, //239 = 1110 1111 -> 0101 0100 0101 0101 | ||
508 | |||
509 | 0x5500, //240 = 1111 0000 -> 0101 0101 0000 0000 | ||
510 | 0x5501, //241 = 1111 0001 -> 0101 0101 0000 0001 | ||
511 | 0x5504, //242 = 1111 0010 -> 0101 0101 0000 0100 | ||
512 | 0x5505, //243 = 1111 0011 -> 0101 0101 0000 0101 | ||
513 | 0x5510, //244 = 1111 0100 -> 0101 0101 0001 0000 | ||
514 | 0x5511, //245 = 1111 0101 -> 0101 0101 0001 0001 | ||
515 | 0x5514, //246 = 1111 0110 -> 0101 0101 0001 0100 | ||
516 | 0x5515, //247 = 1111 0111 -> 0101 0101 0001 0101 | ||
517 | 0x5540, //248 = 1111 1000 -> 0101 0101 0100 0000 | ||
518 | 0x5541, //249 = 1111 1001 -> 0101 0101 0100 0001 | ||
519 | 0x5544, //250 = 1111 1010 -> 0101 0101 0100 0100 | ||
520 | 0x5545, //251 = 1111 1011 -> 0101 0101 0100 0101 | ||
521 | 0x5550, //252 = 1111 1100 -> 0101 0101 0101 0000 | ||
522 | 0x5551, //253 = 1111 1101 -> 0101 0101 0101 0001 | ||
523 | 0x5554, //254 = 1111 1110 -> 0101 0101 0101 0100 | ||
524 | 0x5555 //255 = 1111 1111 -> 0101 0101 0101 0101 | ||
525 | |||
526 | ] | ||
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Point.js b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Point.js new file mode 100644 index 0000000..b7a5537 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Point.js | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | ||
30 | //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; | ||
31 | //} | ||
32 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | ||
33 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | ||
34 | |||
35 | Clipperz.Crypto.ECC.BinaryField.Point = function(args) { | ||
36 | args = args || {}; | ||
37 | this._x = args.x; | ||
38 | this._y = args.y; | ||
39 | |||
40 | return this; | ||
41 | } | ||
42 | |||
43 | Clipperz.Crypto.ECC.BinaryField.Point.prototype = MochiKit.Base.update(null, { | ||
44 | |||
45 | 'asString': function() { | ||
46 | return "Clipperz.Crypto.ECC.BinaryField.Point (" + this.x() + ", " + this.y() + ")"; | ||
47 | }, | ||
48 | |||
49 | //----------------------------------------------------------------------------- | ||
50 | |||
51 | 'x': function() { | ||
52 | return this._x; | ||
53 | }, | ||
54 | |||
55 | 'y': function() { | ||
56 | return this._y; | ||
57 | }, | ||
58 | |||
59 | //----------------------------------------------------------------------------- | ||
60 | |||
61 | 'isZero': function() { | ||
62 | return (this.x().isZero() && this.y().isZero()) | ||
63 | }, | ||
64 | |||
65 | //----------------------------------------------------------------------------- | ||
66 | __syntaxFix__: "syntax fix" | ||
67 | }); | ||
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js new file mode 100644 index 0000000..5a430d1 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js | |||
@@ -0,0 +1,386 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | ||
30 | //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; | ||
31 | //} | ||
32 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
33 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } | ||
34 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | ||
35 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | ||
36 | |||
37 | Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase, aBitSize) { | ||
38 | if (aValue.constructor == String) { | ||
39 | varvalue; | ||
40 | varstringLength; | ||
41 | var numberOfWords; | ||
42 | vari,c; | ||
43 | |||
44 | if (aBase != 16) { | ||
45 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; | ||
46 | } | ||
47 | |||
48 | value = aValue.replace(/ /g, ''); | ||
49 | stringLength = value.length; | ||
50 | numberOfWords = Math.ceil(stringLength / 8); | ||
51 | this._value = new Array(numberOfWords); | ||
52 | |||
53 | c = numberOfWords; | ||
54 | for (i=0; i<c; i++) { | ||
55 | varword; | ||
56 | |||
57 | if (i < (c-1)) { | ||
58 | word = parseInt(value.substr(stringLength-((i+1)*8), 8), 16); | ||
59 | } else { | ||
60 | word = parseInt(value.substr(0, stringLength-(i*8)), 16); | ||
61 | } | ||
62 | |||
63 | this._value[i] = word; | ||
64 | } | ||
65 | } else if (aValue.constructor == Array) { | ||
66 | var itemsToCopy; | ||
67 | |||
68 | itemsToCopy = aValue.length; | ||
69 | while (aValue[itemsToCopy - 1] == 0) { | ||
70 | itemsToCopy --; | ||
71 | } | ||
72 | |||
73 | this._value = aValue.slice(0, itemsToCopy); | ||
74 | } else if (aValue.constructor == Number) { | ||
75 | this._value = [aValue]; | ||
76 | } else { | ||
77 | // throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType; | ||
78 | } | ||
79 | |||
80 | this._bitSize == aBitSize || null; | ||
81 | |||
82 | return this; | ||
83 | } | ||
84 | |||
85 | Clipperz.Crypto.ECC.BinaryField.Value.prototype = MochiKit.Base.update(null, { | ||
86 | |||
87 | 'value': function() { | ||
88 | return this._value; | ||
89 | }, | ||
90 | |||
91 | //----------------------------------------------------------------------------- | ||
92 | |||
93 | 'wordSize': function() { | ||
94 | return this._value.length | ||
95 | }, | ||
96 | |||
97 | //----------------------------------------------------------------------------- | ||
98 | |||
99 | 'clone': function() { | ||
100 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._value.slice(0), null, this._bitSize); | ||
101 | }, | ||
102 | |||
103 | //----------------------------------------------------------------------------- | ||
104 | |||
105 | 'isZero': function() { | ||
106 | return (this.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) == 0); | ||
107 | }, | ||
108 | |||
109 | //----------------------------------------------------------------------------- | ||
110 | |||
111 | 'asString': function(aBase) { | ||
112 | varresult; | ||
113 | var i,c; | ||
114 | |||
115 | if (aBase != 16) { | ||
116 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; | ||
117 | } | ||
118 | |||
119 | result = ""; | ||
120 | c = this.wordSize(); | ||
121 | for (i=0; i<c; i++) { | ||
122 | varwordAsString; | ||
123 | |||
124 | // wordAsString = ("00000000" + this.value()[i].toString(16)); | ||
125 | wordAsString = ("00000000" + this._value[i].toString(16)); | ||
126 | wordAsString = wordAsString.substring(wordAsString.length - 8); | ||
127 | result = wordAsString + result; | ||
128 | } | ||
129 | |||
130 | result = result.replace(/^(00)*/, ""); | ||
131 | |||
132 | if (result == "") { | ||
133 | result = "0"; | ||
134 | } | ||
135 | |||
136 | return result; | ||
137 | }, | ||
138 | |||
139 | //----------------------------------------------------------------------------- | ||
140 | |||
141 | 'shiftLeft': function(aNumberOfBitsToShift) { | ||
142 | //this method seems like it is never called. :-( | ||
143 | return new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this._value, aNumberOfBitsToShift)); | ||
144 | }, | ||
145 | |||
146 | //----------------------------------------------------------------------------- | ||
147 | |||
148 | 'bitSize': function() { | ||
149 | if (this._bitSize == null) { | ||
150 | this._bitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(this._value); | ||
151 | } | ||
152 | |||
153 | return this._bitSize; | ||
154 | }, | ||
155 | |||
156 | //----------------------------------------------------------------------------- | ||
157 | |||
158 | 'isBitSet': function(aBitPosition) { | ||
159 | return Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(this._value, aBitPosition); | ||
160 | }, | ||
161 | |||
162 | //----------------------------------------------------------------------------- | ||
163 | |||
164 | 'xor': function(aValue) { | ||
165 | return new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(this._value, aValue._value)); | ||
166 | }, | ||
167 | |||
168 | //----------------------------------------------------------------------------- | ||
169 | |||
170 | 'compare': function(aValue) { | ||
171 | return Clipperz.Crypto.ECC.BinaryField.Value._compare(this._value, aValue._value); | ||
172 | }, | ||
173 | |||
174 | //----------------------------------------------------------------------------- | ||
175 | __syntaxFix__: "syntax fix" | ||
176 | }); | ||
177 | |||
178 | Clipperz.Crypto.ECC.BinaryField.Value.O = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16); | ||
179 | Clipperz.Crypto.ECC.BinaryField.Value.I = new Clipperz.Crypto.ECC.BinaryField.Value('1', 16); | ||
180 | |||
181 | Clipperz.Crypto.ECC.BinaryField.Value._xor = function(a, b, aFirstItemOffset) { | ||
182 | var result; | ||
183 | var resultSize; | ||
184 | var i,c; | ||
185 | var firstItemOffset; | ||
186 | |||
187 | firstItemOffset = aFirstItemOffset || 0; | ||
188 | resultSize = Math.max((a.length - firstItemOffset), b.length) + firstItemOffset; | ||
189 | |||
190 | result = new Array(resultSize); | ||
191 | |||
192 | c = firstItemOffset; | ||
193 | for (i=0; i<c; i++) { | ||
194 | result[i] = a[i]; | ||
195 | } | ||
196 | |||
197 | c = resultSize; | ||
198 | for (i=firstItemOffset; i<c; i++) { | ||
199 | result[i] = (((a[i] || 0) ^ (b[i - firstItemOffset] || 0)) >>> 0); | ||
200 | } | ||
201 | |||
202 | return result; | ||
203 | }; | ||
204 | |||
205 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor = function(a, b, aFirstItemOffset) { | ||
206 | var i,c; | ||
207 | var firstItemOffset; | ||
208 | |||
209 | firstItemOffset = aFirstItemOffset || 0; | ||
210 | |||
211 | c = Math.max((a.length - firstItemOffset), b.length) + firstItemOffset; | ||
212 | for (i=firstItemOffset; i<c; i++) { | ||
213 | a[i] = (((a[i] || 0) ^ (b[i - firstItemOffset] || 0)) >>> 0); | ||
214 | } | ||
215 | }; | ||
216 | |||
217 | Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft = function(aWordArray, aNumberOfBitsToShift) { | ||
218 | var numberOfWordsToShift; | ||
219 | varnumberOfBitsToShift; | ||
220 | var result; | ||
221 | varoverflowValue; | ||
222 | var nextOverflowValue; | ||
223 | vari,c; | ||
224 | |||
225 | numberOfWordsToShift = Math.floor(aNumberOfBitsToShift / 32); | ||
226 | numberOfBitsToShift = aNumberOfBitsToShift % 32; | ||
227 | |||
228 | result = new Array(aWordArray.length + numberOfWordsToShift); | ||
229 | |||
230 | c = numberOfWordsToShift; | ||
231 | for (i=0; i<c; i++) { | ||
232 | result[i] = 0; | ||
233 | } | ||
234 | |||
235 | overflowValue = 0; | ||
236 | nextOverflowValue = 0; | ||
237 | |||
238 | c = aWordArray.length; | ||
239 | for (i=0; i<c; i++) { | ||
240 | varvalue; | ||
241 | varresultWord; | ||
242 | |||
243 | // value = this.value()[i]; | ||
244 | value = aWordArray[i]; | ||
245 | |||
246 | if (numberOfBitsToShift > 0) { | ||
247 | nextOverflowValue = (value >>> (32 - numberOfBitsToShift)); | ||
248 | value = value & (0xffffffff >>> numberOfBitsToShift); | ||
249 | resultWord = (((value << numberOfBitsToShift) | overflowValue) >>> 0); | ||
250 | } else { | ||
251 | resultWord = value; | ||
252 | } | ||
253 | |||
254 | result[i+numberOfWordsToShift] = resultWord; | ||
255 | overflowValue = nextOverflowValue; | ||
256 | } | ||
257 | |||
258 | if (overflowValue != 0) { | ||
259 | result[aWordArray.length + numberOfWordsToShift] = overflowValue; | ||
260 | } | ||
261 | |||
262 | return result; | ||
263 | }; | ||
264 | |||
265 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft = function(aWordArray, aNumberOfBitsToShift) { | ||
266 | var numberOfWordsToShift; | ||
267 | varnumberOfBitsToShift; | ||
268 | var result; | ||
269 | varoverflowValue; | ||
270 | vari,c; | ||
271 | |||
272 | numberOfWordsToShift = Math.floor(aNumberOfBitsToShift / 32); | ||
273 | numberOfBitsToShift = aNumberOfBitsToShift % 32; | ||
274 | |||
275 | result = new Array(aWordArray.length + numberOfWordsToShift); | ||
276 | |||
277 | c = numberOfWordsToShift; | ||
278 | for (i=0; i<c; i++) { | ||
279 | result[i] = 0; | ||
280 | } | ||
281 | |||
282 | overflowValue = 0; | ||
283 | nextOverflowValue = 0; | ||
284 | |||
285 | c = aWordArray.length; | ||
286 | for (i=0; i<c; i++) { | ||
287 | varvalue; | ||
288 | varresultWord; | ||
289 | |||
290 | // value = this.value()[i]; | ||
291 | value = aWordArray[i]; | ||
292 | |||
293 | if (numberOfBitsToShift > 0) { | ||
294 | var nextOverflowValue; | ||
295 | |||
296 | nextOverflowValue = (value >>> (32 - numberOfBitsToShift)); | ||
297 | value = value & (0xffffffff >>> numberOfBitsToShift); | ||
298 | resultWord = (((value << numberOfBitsToShift) | overflowValue) >>> 0); | ||
299 | } else { | ||
300 | resultWord = value; | ||
301 | } | ||
302 | |||
303 | result[i+numberOfWordsToShift] = resultWord; | ||
304 | overflowValue = nextOverflowValue; | ||
305 | } | ||
306 | |||
307 | if (overflowValue != 0) { | ||
308 | result[aWordArray.length + numberOfWordsToShift] = overflowValue; | ||
309 | } | ||
310 | |||
311 | return result; | ||
312 | }; | ||
313 | |||
314 | Clipperz.Crypto.ECC.BinaryField.Value._bitSize = function(aWordArray) { | ||
315 | varresult; | ||
316 | varnotNullElements; | ||
317 | var mostValuableWord; | ||
318 | var matchingBitsInMostImportantWord; | ||
319 | var mask; | ||
320 | var i,c; | ||
321 | |||
322 | notNullElements = aWordArray.length; | ||
323 | |||
324 | if ((aWordArray.length == 1) && (aWordArray[0] == 0)) { | ||
325 | result = 0; | ||
326 | } else { | ||
327 | notNullElements --; | ||
328 | while((notNullElements > 0) && (aWordArray[notNullElements] == 0)) { | ||
329 | notNullElements --; | ||
330 | } | ||
331 | |||
332 | result = notNullElements * 32; | ||
333 | mostValuableWord = aWordArray[notNullElements]; | ||
334 | |||
335 | matchingBits = 32; | ||
336 | mask = 0x80000000; | ||
337 | |||
338 | while ((matchingBits > 0) && ((mostValuableWord & mask) == 0)) { | ||
339 | matchingBits --; | ||
340 | mask >>>= 1; | ||
341 | } | ||
342 | |||
343 | result += matchingBits; | ||
344 | } | ||
345 | |||
346 | return result; | ||
347 | }; | ||
348 | |||
349 | Clipperz.Crypto.ECC.BinaryField.Value._isBitSet = function(aWordArray, aBitPosition) { | ||
350 | var result; | ||
351 | varbyteIndex; | ||
352 | var bitIndexInSelectedByte; | ||
353 | |||
354 | byteIndex = Math.floor(aBitPosition / 32); | ||
355 | bitIndexInSelectedByte = aBitPosition % 32; | ||
356 | |||
357 | if (byteIndex <= aWordArray.length) { | ||
358 | result = ((aWordArray[byteIndex] & (1 << bitIndexInSelectedByte)) != 0); | ||
359 | } else { | ||
360 | result = false; | ||
361 | } | ||
362 | |||
363 | return result; | ||
364 | }; | ||
365 | |||
366 | Clipperz.Crypto.ECC.BinaryField.Value._compare = function(a,b) { | ||
367 | varresult; | ||
368 | var i,c; | ||
369 | |||
370 | result = MochiKit.Base.compare(a.length, b.length); | ||
371 | |||
372 | c = a.length; | ||
373 | for (i=0; (i<c) && (result==0); i++) { | ||
374 | //console.log("compare[" + c + " - " + i + " - 1] " + this.value()[c-i-1] + ", " + aValue.value()[c-i-1]); | ||
375 | // result = MochiKit.Base.compare(this.value()[c-i-1], aValue.value()[c-i-1]); | ||
376 | result = MochiKit.Base.compare(a[c-i-1], b[c-i-1]); | ||
377 | } | ||
378 | |||
379 | return result; | ||
380 | }; | ||
381 | |||
382 | |||
383 | Clipperz.Crypto.ECC.BinaryField.Value['exception']= { | ||
384 | 'UnsupportedBase': new MochiKit.Base.NamedError("Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase"), | ||
385 | 'UnsupportedConstructorValueType':new MochiKit.Base.NamedError("Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType") | ||
386 | }; | ||
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/StandardCurves.js b/frontend/gamma/js/Clipperz/Crypto/ECC/StandardCurves.js new file mode 100644 index 0000000..ae2b8fb --- a/dev/null +++ b/frontend/gamma/js/Clipperz/Crypto/ECC/StandardCurves.js | |||
@@ -0,0 +1,239 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | //try { if (typeof(Clipperz.Crypto.ECC.BinaryField.Curve) == 'undefined') { throw ""; }} catch (e) { | ||
30 | //throw "Clipperz.Crypto.ECC depends on Clipperz.Crypto.ECC.BinaryField.Curve!"; | ||
31 | //} | ||
32 | //try { if (typeof(Clipperz.Crypto.ECC.Koblitz.Curve) == 'undefined') { throw ""; }} catch (e) { | ||
33 | //throw "Clipperz.Crypto.ECC depends on Clipperz.Crypto.ECC.Koblitz.Curve!"; | ||
34 | //} | ||
35 | |||
36 | Clipperz.Crypto.ECC.StandardCurves = {}; | ||
37 | |||
38 | MochiKit.Base.update(Clipperz.Crypto.ECC.StandardCurves, { | ||
39 | |||
40 | //============================================================================== | ||
41 | |||
42 | '_K571': null, | ||
43 | 'K571': function() { //f(z) = z^571 + z^10 + z^5 + z^2 + 1 | ||
44 | if ((Clipperz.Crypto.ECC.StandardCurves._K571 == null) && (typeof(Clipperz.Crypto.ECC.Koblitz.Curve) != 'undefined')) { | ||
45 | Clipperz.Crypto.ECC.StandardCurves._K571 = new Clipperz.Crypto.ECC.Koblitz.Curve({ | ||
46 | modulus: new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000425', 16), | ||
47 | a: new Clipperz.Crypto.ECC.Koblitz.Value('0', 16), | ||
48 | b: new Clipperz.Crypto.ECC.Koblitz.Value('1', 16), | ||
49 | G: new Clipperz.Crypto.ECC.Koblitz.Point({ | ||
50 | x: new Clipperz.Crypto.ECC.Koblitz.Value('026eb7a8 59923fbc 82189631 f8103fe4 ac9ca297 0012d5d4 60248048 01841ca4 43709584 93b205e6 47da304d b4ceb08c bbd1ba39 494776fb 988b4717 4dca88c7 e2945283 a01c8972', 16), | ||
51 | y: new Clipperz.Crypto.ECC.Koblitz.Value('0349dc80 7f4fbf37 4f4aeade 3bca9531 4dd58cec 9f307a54 ffc61efc 006d8a2c 9d4979c0 ac44aea7 4fbebbb9 f772aedc b620b01a 7ba7af1b 320430c8 591984f6 01cd4c14 3ef1c7a3', 16) | ||
52 | }), | ||
53 | r: new Clipperz.Crypto.ECC.Koblitz.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16), | ||
54 | h: new Clipperz.Crypto.ECC.Koblitz.Value('4', 16), | ||
55 | primeFactor: new Clipperz.Crypto.ECC.Koblitz.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16) | ||
56 | }); | ||
57 | } | ||
58 | |||
59 | return Clipperz.Crypto.ECC.StandardCurves._K571; | ||
60 | }, | ||
61 | |||
62 | //----------------------------------------------------------------------------- | ||
63 | |||
64 | '_K283': null, | ||
65 | 'K283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 | ||
66 | if ((Clipperz.Crypto.ECC.StandardCurves._K283 == null) && (typeof(Clipperz.Crypto.ECC.Koblitz.Curve) != 'undefined')) { | ||
67 | Clipperz.Crypto.ECC.StandardCurves._K283 = new Clipperz.Crypto.ECC.Koblitz.Curve({ | ||
68 | modulus: new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | ||
69 | a: new Clipperz.Crypto.ECC.Koblitz.Value('0', 16), | ||
70 | b: new Clipperz.Crypto.ECC.Koblitz.Value('1', 16), | ||
71 | G: new Clipperz.Crypto.ECC.Koblitz.Point({ | ||
72 | x: new Clipperz.Crypto.ECC.Koblitz.Value('0503213f 78ca4488 3f1a3b81 62f188e5 53cd265f 23c1567a 16876913 b0c2ac24 58492836', 16), | ||
73 | y: new Clipperz.Crypto.ECC.Koblitz.Value('01ccda38 0f1c9e31 8d90f95d 07e5426f e87e45c0 e8184698 e4596236 4e341161 77dd2259', 16) | ||
74 | }), | ||
75 | r: new Clipperz.Crypto.ECC.Koblitz.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16), | ||
76 | h: new Clipperz.Crypto.ECC.Koblitz.Value('4', 16), | ||
77 | primeFactor: new Clipperz.Crypto.ECC.Koblitz.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16) | ||
78 | }); | ||
79 | } | ||
80 | |||
81 | return Clipperz.Crypto.ECC.StandardCurves._K283; | ||
82 | }, | ||
83 | |||
84 | //============================================================================== | ||
85 | |||
86 | '_B571': null, | ||
87 | 'B571': function() { //f(z) = z^571 + z^10 + z^5 + z^2 + 1 | ||
88 | if ((Clipperz.Crypto.ECC.StandardCurves._B571 == null) && (typeof(Clipperz.Crypto.ECC.BinaryField.Curve) != 'undefined')) { | ||
89 | Clipperz.Crypto.ECC.StandardCurves._B571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
90 | 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), | ||
91 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
92 | b: new Clipperz.Crypto.ECC.BinaryField.Value('02f40e7e 2221f295 de297117 b7f3d62f 5c6a97ff cb8ceff1 cd6ba8ce 4a9a18ad 84ffabbd 8efa5933 2be7ad67 56a66e29 4afd185a 78ff12aa 520e4de7 39baca0c 7ffeff7f 2955727a', 16), | ||
93 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
94 | 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), | ||
95 | 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) | ||
96 | }), | ||
97 | 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), | ||
98 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) | ||
99 | |||
100 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), | ||
101 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) | ||
102 | }); | ||
103 | |||
104 | //----------------------------------------------------------------------------- | ||
105 | // | ||
106 | //Guide to Elliptic Curve Cryptography | ||
107 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | ||
108 | //- Pag: 56, Alorithm 2.45 (with a typo!!!) | ||
109 | // | ||
110 | //----------------------------------------------------------------------------- | ||
111 | // | ||
112 | // http://www.milw0rm.com/papers/136 | ||
113 | // | ||
114 | // ------------------------------------------------------------------------- | ||
115 | // Polynomial Reduction Algorithm Modulo f571 | ||
116 | // ------------------------------------------------------------------------- | ||
117 | // | ||
118 | // Input: Polynomial p(x) of degree 1140 or less, stored as | ||
119 | // an array of 2T machinewords. | ||
120 | // Output: p(x) mod f571(x) | ||
121 | // | ||
122 | // FOR i = T-1, ..., 0 DO | ||
123 | // SET X := P[i+T] | ||
124 | // P[i] := P[i] ^ (X<<5) ^ (X<<7) ^ (X<<10) ^ (X<<15) | ||
125 | // P[i+1] := P[i+1] ^ (X>>17) ^ (X>>22) ^ (X>>25) ^ (X>>27) | ||
126 | // | ||
127 | // SET X := P[T-1] >> 27 | ||
128 | // P[0] := P[0] ^ X ^ (X<<2) ^ (X<<5) ^ (X<<10) | ||
129 | // P[T-1] := P[T-1] & 0x07ffffff | ||
130 | // | ||
131 | // RETURN P[T-1],...,P[0] | ||
132 | // | ||
133 | // ------------------------------------------------------------------------- | ||
134 | // | ||
135 | Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().slowModule = Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().module; | ||
136 | Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().module = function(aValue) { | ||
137 | varresult; | ||
138 | |||
139 | if (aValue.bitSize() > 1140) { | ||
140 | MochiKit.Logging.logWarning("ECC.StandarCurves.B571.finiteField().module: falling back to default implementation"); | ||
141 | result = Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().slowModule(aValue); | ||
142 | } else { | ||
143 | varC, T; | ||
144 | var i; | ||
145 | |||
146 | //console.log(">>> binaryField.finiteField.(improved)module"); | ||
147 | // C = aValue.value().slice(0); | ||
148 | C = aValue._value.slice(0); | ||
149 | for (i=35; i>=18; i--) { | ||
150 | T = C[i]; | ||
151 | C[i-18] = (((C[i-18] ^ (T<<5) ^ (T<<7) ^ (T<<10) ^ (T<<15)) & 0xffffffff) >>> 0); | ||
152 | C[i-17] = ((C[i-17] ^ (T>>>27) ^ (T>>>25) ^ (T>>>22) ^ (T>>>17)) >>> 0); | ||
153 | } | ||
154 | T = (C[17] >>> 27); | ||
155 | C[0] = ((C[0] ^ T ^ ((T<<2) ^ (T<<5) ^ (T<<10)) & 0xffffffff) >>> 0); | ||
156 | C[17] = (C[17] & 0x07ffffff); | ||
157 | |||
158 | for(i=18; i<=35; i++) { | ||
159 | C[i] = 0; | ||
160 | } | ||
161 | |||
162 | result = new Clipperz.Crypto.ECC.BinaryField.Value(C); | ||
163 | //console.log("<<< binaryField.finiteField.(improved)module"); | ||
164 | } | ||
165 | |||
166 | return result; | ||
167 | }; | ||
168 | } | ||
169 | |||
170 | return Clipperz.Crypto.ECC.StandardCurves._B571; | ||
171 | }, | ||
172 | |||
173 | //----------------------------------------------------------------------------- | ||
174 | |||
175 | '_B283': null, | ||
176 | 'B283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 | ||
177 | if ((Clipperz.Crypto.ECC.StandardCurves._B283 == null) && (typeof(Clipperz.Crypto.ECC.BinaryField.Curve) != 'undefined')) { | ||
178 | Clipperz.Crypto.ECC.StandardCurves._B283 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | ||
179 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | ||
180 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | ||
181 | b: new Clipperz.Crypto.ECC.BinaryField.Value('027b680a c8b8596d a5a4af8a 19a0303f ca97fd76 45309fa2 a581485a f6263e31 3b79a2f5', 16), | ||
182 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | ||
183 | x: new Clipperz.Crypto.ECC.BinaryField.Value('05f93925 8db7dd90 e1934f8c 70b0dfec 2eed25b8 557eac9c 80e2e198 f8cdbecd 86b12053', 16), | ||
184 | y: new Clipperz.Crypto.ECC.BinaryField.Value('03676854 fe24141c b98fe6d4 b20d02b4 516ff702 350eddb0 826779c8 13f0df45 be8112f4', 16) | ||
185 | }), | ||
186 | r: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffff ffffffff ffffffff ffffffff ffffef90 399660fc 938a9016 5b042a7c efadb307', 16), | ||
187 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) | ||
188 | }); | ||
189 | |||
190 | //----------------------------------------------------------------------------- | ||
191 | // | ||
192 | //Guide to Elliptic Curve Cryptography | ||
193 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | ||
194 | //- Pag: 56, Alorithm 2.43 | ||
195 | // | ||
196 | //----------------------------------------------------------------------------- | ||
197 | Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().slowModule = Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().module; | ||
198 | Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().module = function(aValue) { | ||
199 | varresult; | ||
200 | |||
201 | if (aValue.bitSize() > 564) { | ||
202 | MochiKit.Logging.logWarning("ECC.StandarCurves.B283.finiteField().module: falling back to default implementation"); | ||
203 | result = Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().slowModule(aValue); | ||
204 | } else { | ||
205 | varC, T; | ||
206 | var i; | ||
207 | |||
208 | //console.log(">>> binaryField.finiteField.(improved)module"); | ||
209 | C = aValue._value.slice(0); | ||
210 | for (i=17; i>=9; i--) { | ||
211 | T = C[i]; | ||
212 | C[i-9] = (((C[i-9] ^ (T<<5) ^ (T<<10) ^ (T<<12) ^ (T<<17)) & 0xffffffff) >>> 0); | ||
213 | C[i-8] = ((C[i-8] ^ (T>>>27) ^ (T>>>22) ^ (T>>>20) ^ (T>>>15)) >>> 0); | ||
214 | } | ||
215 | T = (C[8] >>> 27); | ||
216 | C[0] = ((C[0] ^ T ^ ((T<<5) ^ (T<<7) ^ (T<<12)) & 0xffffffff) >>> 0); | ||
217 | C[8] = (C[8] & 0x07ffffff); | ||
218 | |||
219 | for(i=9; i<=17; i++) { | ||
220 | C[i] = 0; | ||
221 | } | ||
222 | |||
223 | result = new Clipperz.Crypto.ECC.BinaryField.Value(C); | ||
224 | //console.log("<<< binaryField.finiteField.(improved)module"); | ||
225 | } | ||
226 | |||
227 | return result; | ||
228 | }; | ||
229 | } | ||
230 | |||
231 | return Clipperz.Crypto.ECC.StandardCurves._B283; | ||
232 | }, | ||
233 | |||
234 | //============================================================================== | ||
235 | __syntaxFix__: "syntax fix" | ||
236 | }); | ||
237 | |||
238 | |||
239 | |||