summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js24
1 files changed, 10 insertions, 14 deletions
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,383 +1,379 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26//try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { 24//try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
27 //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; 25 //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!";
28//} 26//}
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 27if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } 28if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; }
31if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } 29if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; }
32if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } 30if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; }
33 31
34Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase, aBitSize) { 32Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase, aBitSize) {
35 if (aValue.constructor == String) { 33 if (aValue.constructor == String) {
36 varvalue; 34 varvalue;
37 varstringLength; 35 varstringLength;
38 var numberOfWords; 36 var numberOfWords;
39 vari,c; 37 vari,c;
40 38
41 if (aBase != 16) { 39 if (aBase != 16) {
42 throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; 40 throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase;
43 } 41 }
44 42
45 value = aValue.replace(/ /g, ''); 43 value = aValue.replace(/ /g, '');
46 stringLength = value.length; 44 stringLength = value.length;
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
82Clipperz.Crypto.ECC.BinaryField.Value.prototype = MochiKit.Base.update(null, { 80Clipperz.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++) {
119 varwordAsString; 117 varwordAsString;
120 118
121 // wordAsString = ("00000000" + this.value()[i].toString(16)); 119 // wordAsString = ("00000000" + this.value()[i].toString(16));
122 wordAsString = ("00000000" + this._value[i].toString(16)); 120 wordAsString = ("00000000" + this._value[i].toString(16));
123 wordAsString = wordAsString.substring(wordAsString.length - 8); 121 wordAsString = wordAsString.substring(wordAsString.length - 8);
124 result = wordAsString + result; 122 result = wordAsString + result;
125 } 123 }
126 124
127 result = result.replace(/^(00)*/, ""); 125 result = result.replace(/^(00)*/, "");
128 126
129 if (result == "") { 127 if (result == "") {
130 result = "0"; 128 result = "0";
131 } 129 }
132 130
133 return result; 131 return result;
134 }, 132 },
135 133
136 //----------------------------------------------------------------------------- 134 //-----------------------------------------------------------------------------
137 135
138 'shiftLeft': function(aNumberOfBitsToShift) { 136 'shiftLeft': function(aNumberOfBitsToShift) {
139 //this method seems like it is never called. :-( 137 //this method seems like it is never called. :-(
140 return new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this._value, aNumberOfBitsToShift)); 138 return new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this._value, aNumberOfBitsToShift));
141 }, 139 },
142 140
143 //----------------------------------------------------------------------------- 141 //-----------------------------------------------------------------------------
144 142
145 'bitSize': function() { 143 'bitSize': function() {
146 if (this._bitSize == null) { 144 if (this._bitSize == null) {
147 this._bitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(this._value); 145 this._bitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(this._value);
148 } 146 }
149 147
150 return this._bitSize; 148 return this._bitSize;
151 }, 149 },
152 150
153 //----------------------------------------------------------------------------- 151 //-----------------------------------------------------------------------------
154 152
155 'isBitSet': function(aBitPosition) { 153 'isBitSet': function(aBitPosition) {
156 return Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(this._value, aBitPosition); 154 return Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(this._value, aBitPosition);
157 }, 155 },
158 156
159 //----------------------------------------------------------------------------- 157 //-----------------------------------------------------------------------------
160 158
161 'xor': function(aValue) { 159 'xor': function(aValue) {
162 return new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(this._value, aValue._value)); 160 return new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(this._value, aValue._value));
163 }, 161 },
164 162
165 //----------------------------------------------------------------------------- 163 //-----------------------------------------------------------------------------
166 164
167 'compare': function(aValue) { 165 'compare': function(aValue) {
168 return Clipperz.Crypto.ECC.BinaryField.Value._compare(this._value, aValue._value); 166 return Clipperz.Crypto.ECC.BinaryField.Value._compare(this._value, aValue._value);
169 }, 167 },
170 168
171 //----------------------------------------------------------------------------- 169 //-----------------------------------------------------------------------------
172 __syntaxFix__: "syntax fix" 170 __syntaxFix__: "syntax fix"
173}); 171});
174 172
175Clipperz.Crypto.ECC.BinaryField.Value.O = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16); 173Clipperz.Crypto.ECC.BinaryField.Value.O = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16);
176Clipperz.Crypto.ECC.BinaryField.Value.I = new Clipperz.Crypto.ECC.BinaryField.Value('1', 16); 174Clipperz.Crypto.ECC.BinaryField.Value.I = new Clipperz.Crypto.ECC.BinaryField.Value('1', 16);
177 175
178Clipperz.Crypto.ECC.BinaryField.Value._xor = function(a, b, aFirstItemOffset) { 176Clipperz.Crypto.ECC.BinaryField.Value._xor = function(a, b, aFirstItemOffset) {
179 var result; 177 var result;
180 var resultSize; 178 var resultSize;
181 var i,c; 179 var i,c;
182 var firstItemOffset; 180 var firstItemOffset;
183 181
184 firstItemOffset = aFirstItemOffset || 0; 182 firstItemOffset = aFirstItemOffset || 0;
185 resultSize = Math.max((a.length - firstItemOffset), b.length) + firstItemOffset; 183 resultSize = Math.max((a.length - firstItemOffset), b.length) + firstItemOffset;
186 184
187 result = new Array(resultSize); 185 result = new Array(resultSize);
188 186
189 c = firstItemOffset; 187 c = firstItemOffset;
190 for (i=0; i<c; i++) { 188 for (i=0; i<c; i++) {
191 result[i] = a[i]; 189 result[i] = a[i];
192 } 190 }
193 191
194 c = resultSize; 192 c = resultSize;
195 for (i=firstItemOffset; i<c; i++) { 193 for (i=firstItemOffset; i<c; i++) {
196 result[i] = (((a[i] || 0) ^ (b[i - firstItemOffset] || 0)) >>> 0); 194 result[i] = (((a[i] || 0) ^ (b[i - firstItemOffset] || 0)) >>> 0);
197 } 195 }
198 196
199 return result; 197 return result;
200}; 198};
201 199
202Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor = function(a, b, aFirstItemOffset) { 200Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor = function(a, b, aFirstItemOffset) {
203 var i,c; 201 var i,c;
204 var firstItemOffset; 202 var firstItemOffset;
205 203
206 firstItemOffset = aFirstItemOffset || 0; 204 firstItemOffset = aFirstItemOffset || 0;
207 205
208 c = Math.max((a.length - firstItemOffset), b.length) + firstItemOffset; 206 c = Math.max((a.length - firstItemOffset), b.length) + firstItemOffset;
209 for (i=firstItemOffset; i<c; i++) { 207 for (i=firstItemOffset; i<c; i++) {
210 a[i] = (((a[i] || 0) ^ (b[i - firstItemOffset] || 0)) >>> 0); 208 a[i] = (((a[i] || 0) ^ (b[i - firstItemOffset] || 0)) >>> 0);
211 } 209 }
212}; 210};
213 211
214Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft = function(aWordArray, aNumberOfBitsToShift) { 212Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft = function(aWordArray, aNumberOfBitsToShift) {
215 var numberOfWordsToShift; 213 var numberOfWordsToShift;
216 varnumberOfBitsToShift; 214 varnumberOfBitsToShift;
217 var result; 215 var result;
218 varoverflowValue; 216 varoverflowValue;
219 var nextOverflowValue; 217 var nextOverflowValue;
220 vari,c; 218 vari,c;
221 219
222 numberOfWordsToShift = Math.floor(aNumberOfBitsToShift / 32); 220 numberOfWordsToShift = Math.floor(aNumberOfBitsToShift / 32);
223 numberOfBitsToShift = aNumberOfBitsToShift % 32; 221 numberOfBitsToShift = aNumberOfBitsToShift % 32;
224 222
225 result = new Array(aWordArray.length + numberOfWordsToShift); 223 result = new Array(aWordArray.length + numberOfWordsToShift);
226 224
227 c = numberOfWordsToShift; 225 c = numberOfWordsToShift;
228 for (i=0; i<c; i++) { 226 for (i=0; i<c; i++) {
229 result[i] = 0; 227 result[i] = 0;
230 } 228 }
231 229
232 overflowValue = 0; 230 overflowValue = 0;
233 nextOverflowValue = 0; 231 nextOverflowValue = 0;
234 232
235 c = aWordArray.length; 233 c = aWordArray.length;
236 for (i=0; i<c; i++) { 234 for (i=0; i<c; i++) {
237 varvalue; 235 varvalue;
238 varresultWord; 236 varresultWord;
239 237
240 // value = this.value()[i]; 238 // value = this.value()[i];
241 value = aWordArray[i]; 239 value = aWordArray[i];
242 240
243 if (numberOfBitsToShift > 0) { 241 if (numberOfBitsToShift > 0) {
244 nextOverflowValue = (value >>> (32 - numberOfBitsToShift)); 242 nextOverflowValue = (value >>> (32 - numberOfBitsToShift));
245 value = value & (0xffffffff >>> numberOfBitsToShift); 243 value = value & (0xffffffff >>> numberOfBitsToShift);
246 resultWord = (((value << numberOfBitsToShift) | overflowValue) >>> 0); 244 resultWord = (((value << numberOfBitsToShift) | overflowValue) >>> 0);
247 } else { 245 } else {
248 resultWord = value; 246 resultWord = value;
249 } 247 }
250 248
251 result[i+numberOfWordsToShift] = resultWord; 249 result[i+numberOfWordsToShift] = resultWord;
252 overflowValue = nextOverflowValue; 250 overflowValue = nextOverflowValue;
253 } 251 }
254 252
255 if (overflowValue != 0) { 253 if (overflowValue != 0) {
256 result[aWordArray.length + numberOfWordsToShift] = overflowValue; 254 result[aWordArray.length + numberOfWordsToShift] = overflowValue;
257 } 255 }
258 256
259 return result; 257 return result;
260}; 258};
261 259
262Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft = function(aWordArray, aNumberOfBitsToShift) { 260Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft = function(aWordArray, aNumberOfBitsToShift) {
263 var numberOfWordsToShift; 261 var numberOfWordsToShift;
264 varnumberOfBitsToShift; 262 varnumberOfBitsToShift;
265 var result; 263 var result;
266 varoverflowValue; 264 varoverflowValue;
267 vari,c; 265 vari,c;
268 266
269 numberOfWordsToShift = Math.floor(aNumberOfBitsToShift / 32); 267 numberOfWordsToShift = Math.floor(aNumberOfBitsToShift / 32);
270 numberOfBitsToShift = aNumberOfBitsToShift % 32; 268 numberOfBitsToShift = aNumberOfBitsToShift % 32;
271 269
272 result = new Array(aWordArray.length + numberOfWordsToShift); 270 result = new Array(aWordArray.length + numberOfWordsToShift);
273 271
274 c = numberOfWordsToShift; 272 c = numberOfWordsToShift;
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
311Clipperz.Crypto.ECC.BinaryField.Value._bitSize = function(aWordArray) { 309Clipperz.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
346Clipperz.Crypto.ECC.BinaryField.Value._isBitSet = function(aWordArray, aBitPosition) { 344Clipperz.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
363Clipperz.Crypto.ECC.BinaryField.Value._compare = function(a,b) { 361Clipperz.Crypto.ECC.BinaryField.Value._compare = function(a,b) {
364 varresult; 362 varresult;
365 var i,c; 363 var i,c;
366 364
367 result = MochiKit.Base.compare(a.length, b.length); 365 result = MochiKit.Base.compare(a.length, b.length);
368 366
369 c = a.length; 367 c = a.length;
370 for (i=0; (i<c) && (result==0); i++) { 368 for (i=0; (i<c) && (result==0); i++) {
371//console.log("compare[" + c + " - " + i + " - 1] " + this.value()[c-i-1] + ", " + aValue.value()[c-i-1]);
372 // result = MochiKit.Base.compare(this.value()[c-i-1], aValue.value()[c-i-1]);
373 result = MochiKit.Base.compare(a[c-i-1], b[c-i-1]); 369 result = MochiKit.Base.compare(a[c-i-1], b[c-i-1]);
374 } 370 }
375 371
376 return result; 372 return result;
377}; 373};
378 374
379 375
380Clipperz.Crypto.ECC.BinaryField.Value['exception']= { 376Clipperz.Crypto.ECC.BinaryField.Value['exception']= {
381 'UnsupportedBase': new MochiKit.Base.NamedError("Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase"), 377 'UnsupportedBase': new MochiKit.Base.NamedError("Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase"),
382 'UnsupportedConstructorValueType':new MochiKit.Base.NamedError("Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType") 378 'UnsupportedConstructorValueType':new MochiKit.Base.NamedError("Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType")
383}; 379};