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