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