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/BinaryField/Value.js | |
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/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,70 +1,68 @@ | |||
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); |
@@ -323,61 +321,59 @@ Clipperz.Crypto.ECC.BinaryField.Value._bitSize = function(aWordArray) { | |||
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 | }; |