author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/Crypto/ECC | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/ECC') (more/less context) (ignore whitespace changes)
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,547 +1,500 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | //} |
29 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | 27 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } |
30 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | 28 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } |
31 | 29 | ||
32 | Clipperz.Crypto.ECC.BinaryField.Curve = function(args) { | 30 | Clipperz.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 | } |
47 | 45 | ||
48 | Clipperz.Crypto.ECC.BinaryField.Curve.prototype = MochiKit.Base.update(null, { | 46 | Clipperz.Crypto.ECC.BinaryField.Curve.prototype = MochiKit.Base.update(null, { |
49 | 47 | ||
50 | 'asString': function() { | 48 | 'asString': function() { |
51 | return "Clipperz.Crypto.ECC.BinaryField.Curve"; | 49 | return "Clipperz.Crypto.ECC.BinaryField.Curve"; |
52 | }, | 50 | }, |
53 | 51 | ||
54 | //----------------------------------------------------------------------------- | 52 | //----------------------------------------------------------------------------- |
55 | 53 | ||
56 | 'modulus': function() { | 54 | 'modulus': function() { |
57 | return this._modulus; | 55 | return this._modulus; |
58 | }, | 56 | }, |
59 | 57 | ||
60 | 'a': function() { | 58 | 'a': function() { |
61 | return this._a; | 59 | return this._a; |
62 | }, | 60 | }, |
63 | 61 | ||
64 | 'b': function() { | 62 | 'b': function() { |
65 | return this._b; | 63 | return this._b; |
66 | }, | 64 | }, |
67 | 65 | ||
68 | 'G': function() { | 66 | 'G': function() { |
69 | return this._G; | 67 | return this._G; |
70 | }, | 68 | }, |
71 | 69 | ||
72 | 'r': function() { | 70 | 'r': function() { |
73 | return this._r; | 71 | return this._r; |
74 | }, | 72 | }, |
75 | 73 | ||
76 | 'h': function() { | 74 | 'h': function() { |
77 | return this._h; | 75 | return this._h; |
78 | }, | 76 | }, |
79 | 77 | ||
80 | //----------------------------------------------------------------------------- | 78 | //----------------------------------------------------------------------------- |
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 { |
253 | MochiKit.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 | ||
282 | MochiKit.Logging.logDebug(">>> deferredMultiply - value: " + aValue + ", point: " + aPoint); | 251 | Clipperz.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 { |
300 | MochiKit.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 | ||
344 | Clipperz.Crypto.ECC.StandardCurves = {}; | 302 | Clipperz.Crypto.ECC.StandardCurves = {}; |
345 | 303 | ||
346 | MochiKit.Base.update(Clipperz.Crypto.ECC.StandardCurves, { | 304 | MochiKit.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), |
355 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | 313 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ |
356 | 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), | 314 | x: new Clipperz.Crypto.ECC.BinaryField.Value('026eb7a8 59923fbc 82189631 f8103fe4 ac9ca297 0012d5d4 60248048 01841ca4 43709584 93b205e6 47da304d b4ceb08c bbd1ba39 494776fb 988b4717 4dca88c7 e2945283 a01c8972', 16), |
357 | 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) | 315 | y: new Clipperz.Crypto.ECC.BinaryField.Value('0349dc80 7f4fbf37 4f4aeade 3bca9531 4dd58cec 9f307a54 ffc61efc 006d8a2c 9d4979c0 ac44aea7 4fbebbb9 f772aedc b620b01a 7ba7af1b 320430c8 591984f6 01cd4c14 3ef1c7a3', 16) |
358 | }), | 316 | }), |
359 | 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), | 317 | r: new Clipperz.Crypto.ECC.BinaryField.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16), |
360 | h: new Clipperz.Crypto.ECC.BinaryField.Value('4', 16) | 318 | h: new Clipperz.Crypto.ECC.BinaryField.Value('4', 16) |
361 | }); | 319 | }); |
362 | } | 320 | } |
363 | 321 | ||
364 | return Clipperz.Crypto.ECC.StandardCurves._K571; | 322 | return Clipperz.Crypto.ECC.StandardCurves._K571; |
365 | }, | 323 | }, |
366 | 324 | ||
367 | 325 | ||
368 | 326 | ||
369 | '_K283': null, | 327 | '_K283': null, |
370 | 'K283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 | 328 | 'K283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 |
371 | if (Clipperz.Crypto.ECC.StandardCurves._K283 == null) { | 329 | if (Clipperz.Crypto.ECC.StandardCurves._K283 == null) { |
372 | Clipperz.Crypto.ECC.StandardCurves._K283 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | 330 | Clipperz.Crypto.ECC.StandardCurves._K283 = new Clipperz.Crypto.ECC.BinaryField.Curve({ |
373 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | 331 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), |
374 | a: new Clipperz.Crypto.ECC.BinaryField.Value('0', 16), | 332 | a: new Clipperz.Crypto.ECC.BinaryField.Value('0', 16), |
375 | b: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | 333 | b: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), |
376 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | 334 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ |
377 | x: new Clipperz.Crypto.ECC.BinaryField.Value('0503213f 78ca4488 3f1a3b81 62f188e5 53cd265f 23c1567a 16876913 b0c2ac24 58492836', 16), | 335 | x: new Clipperz.Crypto.ECC.BinaryField.Value('0503213f 78ca4488 3f1a3b81 62f188e5 53cd265f 23c1567a 16876913 b0c2ac24 58492836', 16), |
378 | y: new Clipperz.Crypto.ECC.BinaryField.Value('01ccda38 0f1c9e31 8d90f95d 07e5426f e87e45c0 e8184698 e4596236 4e341161 77dd2259', 16) | 336 | y: new Clipperz.Crypto.ECC.BinaryField.Value('01ccda38 0f1c9e31 8d90f95d 07e5426f e87e45c0 e8184698 e4596236 4e341161 77dd2259', 16) |
379 | }), | 337 | }), |
380 | r: new Clipperz.Crypto.ECC.BinaryField.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16), | 338 | r: new Clipperz.Crypto.ECC.BinaryField.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16), |
381 | h: new Clipperz.Crypto.ECC.BinaryField.Value('4', 16) | 339 | h: new Clipperz.Crypto.ECC.BinaryField.Value('4', 16) |
382 | }); | 340 | }); |
383 | } | 341 | } |
384 | 342 | ||
385 | return Clipperz.Crypto.ECC.StandardCurves._K283; | 343 | return Clipperz.Crypto.ECC.StandardCurves._K283; |
386 | }, | 344 | }, |
387 | */ | 345 | */ |
388 | //----------------------------------------------------------------------------- | 346 | //----------------------------------------------------------------------------- |
389 | 347 | ||
390 | '_B571': null, | 348 | '_B571': null, |
391 | 'B571': function() { //f(z) = z^571 + z^10 + z^5 + z^2 + 1 | 349 | 'B571': function() { //f(z) = z^571 + z^10 + z^5 + z^2 + 1 |
392 | if (Clipperz.Crypto.ECC.StandardCurves._B571 == null) { | 350 | if (Clipperz.Crypto.ECC.StandardCurves._B571 == null) { |
393 | Clipperz.Crypto.ECC.StandardCurves._B571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | 351 | Clipperz.Crypto.ECC.StandardCurves._B571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ |
394 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425', 16), | 352 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425', 16), |
395 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | 353 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), |
396 | b: new Clipperz.Crypto.ECC.BinaryField.Value('02f40e7e2221f295de297117b7f3d62f5c6a97ffcb8ceff1cd6ba8ce4a9a18ad84ffabbd8efa59332be7ad6756a66e294afd185a78ff12aa520e4de739baca0c7ffeff7f2955727a', 16), | 354 | b: new Clipperz.Crypto.ECC.BinaryField.Value('02f40e7e2221f295de297117b7f3d62f5c6a97ffcb8ceff1cd6ba8ce4a9a18ad84ffabbd8efa59332be7ad6756a66e294afd185a78ff12aa520e4de739baca0c7ffeff7f2955727a', 16), |
397 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | 355 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ |
398 | 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), | 356 | x: new Clipperz.Crypto.ECC.BinaryField.Value('0303001d 34b85629 6c16c0d4 0d3cd775 0a93d1d2 955fa80a a5f40fc8 db7b2abd bde53950 f4c0d293 cdd711a3 5b67fb14 99ae6003 8614f139 4abfa3b4 c850d927 e1e7769c 8eec2d19', 16), |
399 | 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) | 357 | y: new Clipperz.Crypto.ECC.BinaryField.Value('037bf273 42da639b 6dccfffe b73d69d7 8c6c27a6 009cbbca 1980f853 3921e8a6 84423e43 bab08a57 6291af8f 461bb2a8 b3531d2f 0485c19b 16e2f151 6e23dd3c 1a4827af 1b8ac15b', 16) |
400 | }), | 358 | }), |
401 | 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), | 359 | r: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff e661ce18 ff559873 08059b18 6823851e c7dd9ca1 161de93d 5174d66e 8382e9bb 2fe84e47', 16), |
402 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) | 360 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) |
403 | 361 | ||
404 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), | 362 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), |
405 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) | 363 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) |
406 | }); | 364 | }); |
407 | 365 | ||
408 | //----------------------------------------------------------------------------- | 366 | //----------------------------------------------------------------------------- |
409 | // | 367 | // |
410 | //Guide to Elliptic Curve Cryptography | 368 | //Guide to Elliptic Curve Cryptography |
411 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | 369 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone |
412 | //- Pag: 56, Alorithm 2.45 (with a typo!!!) | 370 | //- Pag: 56, Alorithm 2.45 (with a typo!!!) |
413 | // | 371 | // |
414 | //----------------------------------------------------------------------------- | 372 | //----------------------------------------------------------------------------- |
415 | // | 373 | // |
416 | // http://www.milw0rm.com/papers/136 | 374 | // http://www.milw0rm.com/papers/136 |
417 | // | 375 | // |
418 | // ------------------------------------------------------------------------- | 376 | // ------------------------------------------------------------------------- |
419 | // Polynomial Reduction Algorithm Modulo f571 | 377 | // Polynomial Reduction Algorithm Modulo f571 |
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,174 +1,170 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | //} |
29 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | 27 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } |
30 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | 28 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } |
31 | 29 | ||
32 | Clipperz.Crypto.ECC.BinaryField.FiniteField = function(args) { | 30 | Clipperz.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 | ||
39 | Clipperz.Crypto.ECC.BinaryField.FiniteField.prototype = MochiKit.Base.update(null, { | 37 | Clipperz.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) { |
103 | return aValue.clone(); | 99 | return aValue.clone(); |
104 | }, | 100 | }, |
105 | 101 | ||
106 | //----------------------------------------------------------------------------- | 102 | //----------------------------------------------------------------------------- |
107 | 103 | ||
108 | '_multiply': function(a, b) { | 104 | '_multiply': function(a, b) { |
109 | var result; | 105 | var result; |
110 | var valueToXor; | 106 | var valueToXor; |
111 | var i,c; | 107 | var i,c; |
112 | 108 | ||
113 | result = [0]; | 109 | result = [0]; |
114 | valueToXor = b; | 110 | valueToXor = b; |
115 | c = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(a); | 111 | c = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(a); |
116 | for (i=0; i<c; i++) { | 112 | for (i=0; i<c; i++) { |
117 | if (Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(a, i) === true) { | 113 | if (Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(a, i) === true) { |
118 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, valueToXor); | 114 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, valueToXor); |
119 | } | 115 | } |
120 | valueToXor = Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft(valueToXor, 1); | 116 | valueToXor = Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft(valueToXor, 1); |
121 | } | 117 | } |
122 | result = this._module(result); | 118 | result = this._module(result); |
123 | 119 | ||
124 | return result; | 120 | return result; |
125 | }, | 121 | }, |
126 | 122 | ||
127 | 'multiply': function(a, b) { | 123 | 'multiply': function(a, b) { |
128 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._multiply(a._value, b._value)); | 124 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._multiply(a._value, b._value)); |
129 | }, | 125 | }, |
130 | 126 | ||
131 | //----------------------------------------------------------------------------- | 127 | //----------------------------------------------------------------------------- |
132 | 128 | ||
133 | '_fastMultiply': function(a, b) { | 129 | '_fastMultiply': function(a, b) { |
134 | var result; | 130 | var result; |
135 | var B; | 131 | var B; |
136 | var i,c; | 132 | var i,c; |
137 | 133 | ||
138 | result = [0]; | 134 | result = [0]; |
139 | B = b.slice(0); //Is this array copy avoidable? | 135 | B = b.slice(0); //Is this array copy avoidable? |
140 | c = 32; | 136 | c = 32; |
141 | for (i=0; i<c; i++) { | 137 | for (i=0; i<c; i++) { |
142 | var ii, cc; | 138 | var ii, cc; |
143 | 139 | ||
144 | cc = a.length; | 140 | cc = a.length; |
145 | for (ii=0; ii<cc; ii++) { | 141 | for (ii=0; ii<cc; ii++) { |
146 | if (((a[ii] >>> i) & 0x01) == 1) { | 142 | if (((a[ii] >>> i) & 0x01) == 1) { |
147 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, B, ii); | 143 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, B, ii); |
148 | } | 144 | } |
149 | } | 145 | } |
150 | 146 | ||
151 | if (i < (c-1)) { | 147 | if (i < (c-1)) { |
152 | B = Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft(B, 1); | 148 | B = Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft(B, 1); |
153 | } | 149 | } |
154 | } | 150 | } |
155 | result = this._module(result); | 151 | result = this._module(result); |
156 | 152 | ||
157 | return result; | 153 | return result; |
158 | }, | 154 | }, |
159 | 155 | ||
160 | 'fastMultiply': function(a, b) { | 156 | 'fastMultiply': function(a, b) { |
161 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._fastMultiply(a._value, b._value)); | 157 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._fastMultiply(a._value, b._value)); |
162 | }, | 158 | }, |
163 | 159 | ||
164 | //----------------------------------------------------------------------------- | 160 | //----------------------------------------------------------------------------- |
165 | // | 161 | // |
166 | //Guide to Elliptic Curve Cryptography | 162 | //Guide to Elliptic Curve Cryptography |
167 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | 163 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone |
168 | //- Pag: 49, Alorithm 2.34 | 164 | //- Pag: 49, Alorithm 2.34 |
169 | // | 165 | // |
170 | //----------------------------------------------------------------------------- | 166 | //----------------------------------------------------------------------------- |
171 | 167 | ||
172 | '_square': function(aValue) { | 168 | '_square': function(aValue) { |
173 | var result; | 169 | var result; |
174 | var value; | 170 | var value; |
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,64 +1,62 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | //} |
29 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | 27 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } |
30 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | 28 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } |
31 | 29 | ||
32 | Clipperz.Crypto.ECC.BinaryField.Point = function(args) { | 30 | Clipperz.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 | ||
40 | Clipperz.Crypto.ECC.BinaryField.Point.prototype = MochiKit.Base.update(null, { | 38 | Clipperz.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 | //----------------------------------------------------------------------------- |
47 | 45 | ||
48 | 'x': function() { | 46 | 'x': function() { |
49 | return this._x; | 47 | return this._x; |
50 | }, | 48 | }, |
51 | 49 | ||
52 | 'y': function() { | 50 | 'y': function() { |
53 | return this._y; | 51 | return this._y; |
54 | }, | 52 | }, |
55 | 53 | ||
56 | //----------------------------------------------------------------------------- | 54 | //----------------------------------------------------------------------------- |
57 | 55 | ||
58 | 'isZero': function() { | 56 | 'isZero': function() { |
59 | return (this.x().isZero() && this.y().isZero()) | 57 | return (this.x().isZero() && this.y().isZero()) |
60 | }, | 58 | }, |
61 | 59 | ||
62 | //----------------------------------------------------------------------------- | 60 | //----------------------------------------------------------------------------- |
63 | __syntaxFix__: "syntax fix" | 61 | __syntaxFix__: "syntax fix" |
64 | }); | 62 | }); |
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,118 +1,116 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | //} |
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 27 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
30 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } | 28 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } |
31 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | 29 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } |
32 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | 30 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } |
33 | 31 | ||
34 | Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase, aBitSize) { | 32 | Clipperz.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; |
47 | numberOfWords = Math.ceil(stringLength / 8); | 45 | numberOfWords = Math.ceil(stringLength / 8); |
48 | this._value = new Array(numberOfWords); | 46 | this._value = new Array(numberOfWords); |
49 | 47 | ||
50 | c = numberOfWords; | 48 | c = numberOfWords; |
51 | for (i=0; i<c; i++) { | 49 | for (i=0; i<c; i++) { |
52 | varword; | 50 | varword; |
53 | 51 | ||
54 | if (i < (c-1)) { | 52 | if (i < (c-1)) { |
55 | word = parseInt(value.substr(stringLength-((i+1)*8), 8), 16); | 53 | word = parseInt(value.substr(stringLength-((i+1)*8), 8), 16); |
56 | } else { | 54 | } else { |
57 | word = parseInt(value.substr(0, stringLength-(i*8)), 16); | 55 | word = parseInt(value.substr(0, stringLength-(i*8)), 16); |
58 | } | 56 | } |
59 | 57 | ||
60 | this._value[i] = word; | 58 | this._value[i] = word; |
61 | } | 59 | } |
62 | } else if (aValue.constructor == Array) { | 60 | } else if (aValue.constructor == Array) { |
63 | var itemsToCopy; | 61 | var itemsToCopy; |
64 | 62 | ||
65 | itemsToCopy = aValue.length; | 63 | itemsToCopy = aValue.length; |
66 | while (aValue[itemsToCopy - 1] == 0) { | 64 | while (aValue[itemsToCopy - 1] == 0) { |
67 | itemsToCopy --; | 65 | itemsToCopy --; |
68 | } | 66 | } |
69 | 67 | ||
70 | this._value = aValue.slice(0, itemsToCopy); | 68 | this._value = aValue.slice(0, itemsToCopy); |
71 | } else if (aValue.constructor == Number) { | 69 | } else if (aValue.constructor == Number) { |
72 | this._value = [aValue]; | 70 | this._value = [aValue]; |
73 | } else { | 71 | } else { |
74 | // throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType; | 72 | // throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType; |
75 | } | 73 | } |
76 | 74 | ||
77 | this._bitSize == aBitSize || null; | 75 | this._bitSize == aBitSize || null; |
78 | 76 | ||
79 | return this; | 77 | return this; |
80 | } | 78 | } |
81 | 79 | ||
82 | Clipperz.Crypto.ECC.BinaryField.Value.prototype = MochiKit.Base.update(null, { | 80 | Clipperz.Crypto.ECC.BinaryField.Value.prototype = MochiKit.Base.update(null, { |
83 | 81 | ||
84 | 'value': function() { | 82 | 'value': function() { |
85 | return this._value; | 83 | return this._value; |
86 | }, | 84 | }, |
87 | 85 | ||
88 | //----------------------------------------------------------------------------- | 86 | //----------------------------------------------------------------------------- |
89 | 87 | ||
90 | 'wordSize': function() { | 88 | 'wordSize': function() { |
91 | return this._value.length | 89 | return this._value.length |
92 | }, | 90 | }, |
93 | 91 | ||
94 | //----------------------------------------------------------------------------- | 92 | //----------------------------------------------------------------------------- |
95 | 93 | ||
96 | 'clone': function() { | 94 | 'clone': function() { |
97 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._value.slice(0), null, this._bitSize); | 95 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._value.slice(0), null, this._bitSize); |
98 | }, | 96 | }, |
99 | 97 | ||
100 | //----------------------------------------------------------------------------- | 98 | //----------------------------------------------------------------------------- |
101 | 99 | ||
102 | 'isZero': function() { | 100 | 'isZero': function() { |
103 | return (this.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) == 0); | 101 | return (this.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) == 0); |
104 | }, | 102 | }, |
105 | 103 | ||
106 | //----------------------------------------------------------------------------- | 104 | //----------------------------------------------------------------------------- |
107 | 105 | ||
108 | 'asString': function(aBase) { | 106 | 'asString': function(aBase) { |
109 | varresult; | 107 | varresult; |
110 | var i,c; | 108 | var i,c; |
111 | 109 | ||
112 | if (aBase != 16) { | 110 | if (aBase != 16) { |
113 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; | 111 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; |
114 | } | 112 | } |
115 | 113 | ||
116 | result = ""; | 114 | result = ""; |
117 | c = this.wordSize(); | 115 | c = this.wordSize(); |
118 | for (i=0; i<c; i++) { | 116 | for (i=0; i<c; i++) { |
@@ -275,109 +273,107 @@ Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft = function(aWordArray, | |||
275 | for (i=0; i<c; i++) { | 273 | for (i=0; i<c; i++) { |
276 | result[i] = 0; | 274 | result[i] = 0; |
277 | } | 275 | } |
278 | 276 | ||
279 | overflowValue = 0; | 277 | overflowValue = 0; |
280 | nextOverflowValue = 0; | 278 | nextOverflowValue = 0; |
281 | 279 | ||
282 | c = aWordArray.length; | 280 | c = aWordArray.length; |
283 | for (i=0; i<c; i++) { | 281 | for (i=0; i<c; i++) { |
284 | varvalue; | 282 | varvalue; |
285 | varresultWord; | 283 | varresultWord; |
286 | 284 | ||
287 | // value = this.value()[i]; | 285 | // value = this.value()[i]; |
288 | value = aWordArray[i]; | 286 | value = aWordArray[i]; |
289 | 287 | ||
290 | if (numberOfBitsToShift > 0) { | 288 | if (numberOfBitsToShift > 0) { |
291 | var nextOverflowValue; | 289 | var nextOverflowValue; |
292 | 290 | ||
293 | nextOverflowValue = (value >>> (32 - numberOfBitsToShift)); | 291 | nextOverflowValue = (value >>> (32 - numberOfBitsToShift)); |
294 | value = value & (0xffffffff >>> numberOfBitsToShift); | 292 | value = value & (0xffffffff >>> numberOfBitsToShift); |
295 | resultWord = (((value << numberOfBitsToShift) | overflowValue) >>> 0); | 293 | resultWord = (((value << numberOfBitsToShift) | overflowValue) >>> 0); |
296 | } else { | 294 | } else { |
297 | resultWord = value; | 295 | resultWord = value; |
298 | } | 296 | } |
299 | 297 | ||
300 | result[i+numberOfWordsToShift] = resultWord; | 298 | result[i+numberOfWordsToShift] = resultWord; |
301 | overflowValue = nextOverflowValue; | 299 | overflowValue = nextOverflowValue; |
302 | } | 300 | } |
303 | 301 | ||
304 | if (overflowValue != 0) { | 302 | if (overflowValue != 0) { |
305 | result[aWordArray.length + numberOfWordsToShift] = overflowValue; | 303 | result[aWordArray.length + numberOfWordsToShift] = overflowValue; |
306 | } | 304 | } |
307 | 305 | ||
308 | return result; | 306 | return result; |
309 | }; | 307 | }; |
310 | 308 | ||
311 | Clipperz.Crypto.ECC.BinaryField.Value._bitSize = function(aWordArray) { | 309 | Clipperz.Crypto.ECC.BinaryField.Value._bitSize = function(aWordArray) { |
312 | varresult; | 310 | varresult; |
313 | varnotNullElements; | 311 | varnotNullElements; |
314 | var mostValuableWord; | 312 | var mostValuableWord; |
315 | var matchingBitsInMostImportantWord; | 313 | var matchingBitsInMostImportantWord; |
316 | var mask; | 314 | var mask; |
317 | var i,c; | 315 | var i,c; |
318 | 316 | ||
319 | notNullElements = aWordArray.length; | 317 | notNullElements = aWordArray.length; |
320 | 318 | ||
321 | if ((aWordArray.length == 1) && (aWordArray[0] == 0)) { | 319 | if ((aWordArray.length == 1) && (aWordArray[0] == 0)) { |
322 | result = 0; | 320 | result = 0; |
323 | } else { | 321 | } else { |
324 | notNullElements --; | 322 | notNullElements --; |
325 | while((notNullElements > 0) && (aWordArray[notNullElements] == 0)) { | 323 | while((notNullElements > 0) && (aWordArray[notNullElements] == 0)) { |
326 | notNullElements --; | 324 | notNullElements --; |
327 | } | 325 | } |
328 | 326 | ||
329 | result = notNullElements * 32; | 327 | result = notNullElements * 32; |
330 | mostValuableWord = aWordArray[notNullElements]; | 328 | mostValuableWord = aWordArray[notNullElements]; |
331 | 329 | ||
332 | matchingBits = 32; | 330 | matchingBits = 32; |
333 | mask = 0x80000000; | 331 | mask = 0x80000000; |
334 | 332 | ||
335 | while ((matchingBits > 0) && ((mostValuableWord & mask) == 0)) { | 333 | while ((matchingBits > 0) && ((mostValuableWord & mask) == 0)) { |
336 | matchingBits --; | 334 | matchingBits --; |
337 | mask >>>= 1; | 335 | mask >>>= 1; |
338 | } | 336 | } |
339 | 337 | ||
340 | result += matchingBits; | 338 | result += matchingBits; |
341 | } | 339 | } |
342 | 340 | ||
343 | return result; | 341 | return result; |
344 | }; | 342 | }; |
345 | 343 | ||
346 | Clipperz.Crypto.ECC.BinaryField.Value._isBitSet = function(aWordArray, aBitPosition) { | 344 | Clipperz.Crypto.ECC.BinaryField.Value._isBitSet = function(aWordArray, aBitPosition) { |
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 | ||
363 | Clipperz.Crypto.ECC.BinaryField.Value._compare = function(a,b) { | 361 | Clipperz.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 | ||
380 | Clipperz.Crypto.ECC.BinaryField.Value['exception']= { | 376 | Clipperz.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,236 +1,229 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | ||
33 | Clipperz.Crypto.ECC.StandardCurves = {}; | 31 | Clipperz.Crypto.ECC.StandardCurves = {}; |
34 | 32 | ||
35 | MochiKit.Base.update(Clipperz.Crypto.ECC.StandardCurves, { | 33 | MochiKit.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({ |
47 | x: new Clipperz.Crypto.ECC.Koblitz.Value('026eb7a8 59923fbc 82189631 f8103fe4 ac9ca297 0012d5d4 60248048 01841ca4 43709584 93b205e6 47da304d b4ceb08c bbd1ba39 494776fb 988b4717 4dca88c7 e2945283 a01c8972', 16), | 45 | x: new Clipperz.Crypto.ECC.Koblitz.Value('026eb7a8 59923fbc 82189631 f8103fe4 ac9ca297 0012d5d4 60248048 01841ca4 43709584 93b205e6 47da304d b4ceb08c bbd1ba39 494776fb 988b4717 4dca88c7 e2945283 a01c8972', 16), |
48 | y: new Clipperz.Crypto.ECC.Koblitz.Value('0349dc80 7f4fbf37 4f4aeade 3bca9531 4dd58cec 9f307a54 ffc61efc 006d8a2c 9d4979c0 ac44aea7 4fbebbb9 f772aedc b620b01a 7ba7af1b 320430c8 591984f6 01cd4c14 3ef1c7a3', 16) | 46 | y: new Clipperz.Crypto.ECC.Koblitz.Value('0349dc80 7f4fbf37 4f4aeade 3bca9531 4dd58cec 9f307a54 ffc61efc 006d8a2c 9d4979c0 ac44aea7 4fbebbb9 f772aedc b620b01a 7ba7af1b 320430c8 591984f6 01cd4c14 3ef1c7a3', 16) |
49 | }), | 47 | }), |
50 | r: new Clipperz.Crypto.ECC.Koblitz.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16), | 48 | r: new Clipperz.Crypto.ECC.Koblitz.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16), |
51 | h: new Clipperz.Crypto.ECC.Koblitz.Value('4', 16), | 49 | h: new Clipperz.Crypto.ECC.Koblitz.Value('4', 16), |
52 | primeFactor: new Clipperz.Crypto.ECC.Koblitz.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16) | 50 | primeFactor: new Clipperz.Crypto.ECC.Koblitz.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16) |
53 | }); | 51 | }); |
54 | } | 52 | } |
55 | 53 | ||
56 | return Clipperz.Crypto.ECC.StandardCurves._K571; | 54 | return Clipperz.Crypto.ECC.StandardCurves._K571; |
57 | }, | 55 | }, |
58 | 56 | ||
59 | //----------------------------------------------------------------------------- | 57 | //----------------------------------------------------------------------------- |
60 | 58 | ||
61 | '_K283': null, | 59 | '_K283': null, |
62 | 'K283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 | 60 | 'K283': function() { //f(z) = z^283 + z^12 + z^7 + z^5 + 1 |
63 | if ((Clipperz.Crypto.ECC.StandardCurves._K283 == null) && (typeof(Clipperz.Crypto.ECC.Koblitz.Curve) != 'undefined')) { | 61 | if ((Clipperz.Crypto.ECC.StandardCurves._K283 == null) && (typeof(Clipperz.Crypto.ECC.Koblitz.Curve) != 'undefined')) { |
64 | Clipperz.Crypto.ECC.StandardCurves._K283 = new Clipperz.Crypto.ECC.Koblitz.Curve({ | 62 | Clipperz.Crypto.ECC.StandardCurves._K283 = new Clipperz.Crypto.ECC.Koblitz.Curve({ |
65 | modulus: new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), | 63 | modulus: new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), |
66 | a: new Clipperz.Crypto.ECC.Koblitz.Value('0', 16), | 64 | a: new Clipperz.Crypto.ECC.Koblitz.Value('0', 16), |
67 | b: new Clipperz.Crypto.ECC.Koblitz.Value('1', 16), | 65 | b: new Clipperz.Crypto.ECC.Koblitz.Value('1', 16), |
68 | G: new Clipperz.Crypto.ECC.Koblitz.Point({ | 66 | G: new Clipperz.Crypto.ECC.Koblitz.Point({ |
69 | x: new Clipperz.Crypto.ECC.Koblitz.Value('0503213f 78ca4488 3f1a3b81 62f188e5 53cd265f 23c1567a 16876913 b0c2ac24 58492836', 16), | 67 | x: new Clipperz.Crypto.ECC.Koblitz.Value('0503213f 78ca4488 3f1a3b81 62f188e5 53cd265f 23c1567a 16876913 b0c2ac24 58492836', 16), |
70 | y: new Clipperz.Crypto.ECC.Koblitz.Value('01ccda38 0f1c9e31 8d90f95d 07e5426f e87e45c0 e8184698 e4596236 4e341161 77dd2259', 16) | 68 | y: new Clipperz.Crypto.ECC.Koblitz.Value('01ccda38 0f1c9e31 8d90f95d 07e5426f e87e45c0 e8184698 e4596236 4e341161 77dd2259', 16) |
71 | }), | 69 | }), |
72 | r: new Clipperz.Crypto.ECC.Koblitz.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16), | 70 | r: new Clipperz.Crypto.ECC.Koblitz.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16), |
73 | h: new Clipperz.Crypto.ECC.Koblitz.Value('4', 16), | 71 | h: new Clipperz.Crypto.ECC.Koblitz.Value('4', 16), |
74 | primeFactor: new Clipperz.Crypto.ECC.Koblitz.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16) | 72 | primeFactor: new Clipperz.Crypto.ECC.Koblitz.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16) |
75 | }); | 73 | }); |
76 | } | 74 | } |
77 | 75 | ||
78 | return Clipperz.Crypto.ECC.StandardCurves._K283; | 76 | return Clipperz.Crypto.ECC.StandardCurves._K283; |
79 | }, | 77 | }, |
80 | 78 | ||
81 | //============================================================================== | 79 | //============================================================================== |
82 | 80 | ||
83 | '_B571': null, | 81 | '_B571': null, |
84 | 'B571': function() { //f(z) = z^571 + z^10 + z^5 + z^2 + 1 | 82 | 'B571': function() { //f(z) = z^571 + z^10 + z^5 + z^2 + 1 |
85 | if ((Clipperz.Crypto.ECC.StandardCurves._B571 == null) && (typeof(Clipperz.Crypto.ECC.BinaryField.Curve) != 'undefined')) { | 83 | if ((Clipperz.Crypto.ECC.StandardCurves._B571 == null) && (typeof(Clipperz.Crypto.ECC.BinaryField.Curve) != 'undefined')) { |
86 | Clipperz.Crypto.ECC.StandardCurves._B571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ | 84 | Clipperz.Crypto.ECC.StandardCurves._B571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ |
87 | 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), | 85 | 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), |
88 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), | 86 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), |
89 | b: new Clipperz.Crypto.ECC.BinaryField.Value('02f40e7e 2221f295 de297117 b7f3d62f 5c6a97ff cb8ceff1 cd6ba8ce 4a9a18ad 84ffabbd 8efa5933 2be7ad67 56a66e29 4afd185a 78ff12aa 520e4de7 39baca0c 7ffeff7f 2955727a', 16), | 87 | b: new Clipperz.Crypto.ECC.BinaryField.Value('02f40e7e 2221f295 de297117 b7f3d62f 5c6a97ff cb8ceff1 cd6ba8ce 4a9a18ad 84ffabbd 8efa5933 2be7ad67 56a66e29 4afd185a 78ff12aa 520e4de7 39baca0c 7ffeff7f 2955727a', 16), |
90 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ | 88 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ |
91 | 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), | 89 | 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), |
92 | 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) | 90 | 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) |
93 | }), | 91 | }), |
94 | 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), | 92 | 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), |
95 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) | 93 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) |
96 | 94 | ||
97 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), | 95 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), |
98 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) | 96 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) |
99 | }); | 97 | }); |
100 | 98 | ||
101 | //----------------------------------------------------------------------------- | 99 | //----------------------------------------------------------------------------- |
102 | // | 100 | // |
103 | //Guide to Elliptic Curve Cryptography | 101 | //Guide to Elliptic Curve Cryptography |
104 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone | 102 | //Darrel Hankerson, Alfred Menezes, Scott Vanstone |
105 | //- Pag: 56, Alorithm 2.45 (with a typo!!!) | 103 | //- Pag: 56, Alorithm 2.45 (with a typo!!!) |
106 | // | 104 | // |
107 | //----------------------------------------------------------------------------- | 105 | //----------------------------------------------------------------------------- |
108 | // | 106 | // |
109 | // http://www.milw0rm.com/papers/136 | 107 | // http://www.milw0rm.com/papers/136 |
110 | // | 108 | // |
111 | // ------------------------------------------------------------------------- | 109 | // ------------------------------------------------------------------------- |
112 | // Polynomial Reduction Algorithm Modulo f571 | 110 | // Polynomial Reduction Algorithm Modulo f571 |
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 | ||