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