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.js | 24 |
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,54 +1,52 @@ | |||
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)) { |
@@ -339,45 +337,43 @@ Clipperz.Crypto.ECC.BinaryField.Value._bitSize = function(aWordArray) { | |||
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 | }; |