Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/BigInt.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/BigInt.js | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/BigInt.js b/frontend/gamma/js/Clipperz/Crypto/BigInt.js index 41483a3..031ed30 100644 --- a/frontend/gamma/js/Clipperz/Crypto/BigInt.js +++ b/frontend/gamma/js/Clipperz/Crypto/BigInt.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 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } | 25 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } |
28 | 26 | ||
29 | //############################################################################# | 27 | //############################################################################# |
30 | //Downloaded on March 05, 2007 from http://www.leemon.com/crypto/BigInt.js | 28 | //Downloaded on March 05, 2007 from http://www.leemon.com/crypto/BigInt.js |
31 | //############################################################################# | 29 | //############################################################################# |
32 | 30 | ||
33 | 31 | ||
34 | //////////////////////////////////////////////////////////////////////////////////////// | 32 | //////////////////////////////////////////////////////////////////////////////////////// |
35 | // Big Integer Library v. 5.0 | 33 | // Big Integer Library v. 5.0 |
36 | // Created 2000, last modified 2006 | 34 | // Created 2000, last modified 2006 |
37 | // Leemon Baird | 35 | // Leemon Baird |
38 | // www.leemon.com | 36 | // www.leemon.com |
39 | // | 37 | // |
40 | // This file is public domain. You can use it for any purpose without restriction. | 38 | // This file is public domain. You can use it for any purpose without restriction. |
41 | // I do not guarantee that it is correct, so use it at your own risk. If you use | 39 | // I do not guarantee that it is correct, so use it at your own risk. If you use |
42 | // it for something interesting, I'd appreciate hearing about it. If you find | 40 | // it for something interesting, I'd appreciate hearing about it. If you find |
43 | // any bugs or make any improvements, I'd appreciate hearing about those too. | 41 | // any bugs or make any improvements, I'd appreciate hearing about those too. |
44 | // It would also be nice if my name and address were left in the comments. | 42 | // It would also be nice if my name and address were left in the comments. |
45 | // But none of that is required. | 43 | // But none of that is required. |
46 | // | 44 | // |
47 | // This code defines a bigInt library for arbitrary-precision integers. | 45 | // This code defines a bigInt library for arbitrary-precision integers. |
48 | // A bigInt is an array of integers storing the value in chunks of bpe bits, | 46 | // A bigInt is an array of integers storing the value in chunks of bpe bits, |
49 | // little endian (buff[0] is the least significant word). | 47 | // little endian (buff[0] is the least significant word). |
50 | // Negative bigInts are stored two's complement. | 48 | // Negative bigInts are stored two's complement. |
51 | // Some functions assume their parameters have at least one leading zero element. | 49 | // Some functions assume their parameters have at least one leading zero element. |
52 | // Functions with an underscore at the end of the name have unpredictable behavior in case of overflow, | 50 | // Functions with an underscore at the end of the name have unpredictable behavior in case of overflow, |
53 | // so the caller must make sure overflow won't happen. | 51 | // so the caller must make sure overflow won't happen. |
54 | // For each function where a parameter is modified, that same | 52 | // For each function where a parameter is modified, that same |
@@ -1448,65 +1446,64 @@ MochiKit.Base.update(Clipperz.Crypto.BigInt.prototype, { | |||
1448 | //------------------------------------------------------------------------- | 1446 | //------------------------------------------------------------------------- |
1449 | 1447 | ||
1450 | 'internalValue': function () { | 1448 | 'internalValue': function () { |
1451 | return this._internalValue; | 1449 | return this._internalValue; |
1452 | }, | 1450 | }, |
1453 | 1451 | ||
1454 | //------------------------------------------------------------------------- | 1452 | //------------------------------------------------------------------------- |
1455 | 1453 | ||
1456 | 'isBigInt': true, | 1454 | 'isBigInt': true, |
1457 | 1455 | ||
1458 | //------------------------------------------------------------------------- | 1456 | //------------------------------------------------------------------------- |
1459 | 1457 | ||
1460 | 'toString': function(aBase) { | 1458 | 'toString': function(aBase) { |
1461 | return this.asString(aBase); | 1459 | return this.asString(aBase); |
1462 | }, | 1460 | }, |
1463 | 1461 | ||
1464 | //------------------------------------------------------------------------- | 1462 | //------------------------------------------------------------------------- |
1465 | 1463 | ||
1466 | 'asString': function (aBase, minimumLength) { | 1464 | 'asString': function (aBase, minimumLength) { |
1467 | varresult; | 1465 | varresult; |
1468 | varbase; | 1466 | varbase; |
1469 | 1467 | ||
1470 | if (typeof(aBase) == 'undefined') { | 1468 | if (typeof(aBase) == 'undefined') { |
1471 | base = 10; | 1469 | base = 10; |
1472 | } else { | 1470 | } else { |
1473 | base = aBase; | 1471 | base = aBase; |
1474 | } | 1472 | } |
1475 | 1473 | ||
1476 | result = bigInt2str(this.internalValue(), base).toLowerCase(); | 1474 | result = bigInt2str(this.internalValue(), base).toLowerCase(); |
1477 | 1475 | ||
1478 | if ((typeof(minimumLength) != 'undefined') && (result.length < minimumLength)) { | 1476 | if ((typeof(minimumLength) != 'undefined') && (result.length < minimumLength)) { |
1479 | var i, c; | 1477 | var i, c; |
1480 | //MochiKit.Logging.logDebug(">>> FIXING BigInt.asString length issue") | ||
1481 | c = (minimumLength - result.length); | 1478 | c = (minimumLength - result.length); |
1482 | for (i=0; i<c; i++) { | 1479 | for (i=0; i<c; i++) { |
1483 | result = '0' + result; | 1480 | result = '0' + result; |
1484 | } | 1481 | } |
1485 | } | 1482 | } |
1486 | 1483 | ||
1487 | return result; | 1484 | return result; |
1488 | }, | 1485 | }, |
1489 | 1486 | ||
1490 | //------------------------------------------------------------------------- | 1487 | //------------------------------------------------------------------------- |
1491 | 1488 | ||
1492 | 'asByteArray': function() { | 1489 | 'asByteArray': function() { |
1493 | return new Clipperz.ByteArray("0x" + this.asString(16), 16); | 1490 | return new Clipperz.ByteArray("0x" + this.asString(16), 16); |
1494 | }, | 1491 | }, |
1495 | 1492 | ||
1496 | //------------------------------------------------------------------------- | 1493 | //------------------------------------------------------------------------- |
1497 | 1494 | ||
1498 | 'equals': function (aValue) { | 1495 | 'equals': function (aValue) { |
1499 | var result; | 1496 | var result; |
1500 | 1497 | ||
1501 | if (aValue.isBigInt) { | 1498 | if (aValue.isBigInt) { |
1502 | result = equals(this.internalValue(), aValue.internalValue()); | 1499 | result = equals(this.internalValue(), aValue.internalValue()); |
1503 | } else if (typeof(aValue) == "number") { | 1500 | } else if (typeof(aValue) == "number") { |
1504 | result = equalsInt(this.internalValue(), aValue); | 1501 | result = equalsInt(this.internalValue(), aValue); |
1505 | } else { | 1502 | } else { |
1506 | throw Clipperz.Crypt.BigInt.exception.UnknownType; | 1503 | throw Clipperz.Crypt.BigInt.exception.UnknownType; |
1507 | } | 1504 | } |
1508 | 1505 | ||
1509 | return result; | 1506 | return result; |
1510 | }, | 1507 | }, |
1511 | 1508 | ||
1512 | //------------------------------------------------------------------------- | 1509 | //------------------------------------------------------------------------- |