summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/Crypto/BigInt.js
Side-by-side diff
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.js23
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,70 +1,68 @@
/*
-Copyright 2008-2011 Clipperz Srl
+Copyright 2008-2013 Clipperz Srl
-This file is part of Clipperz Community Edition.
-Clipperz Community Edition is an online password manager.
+This file is part of Clipperz, the online password manager.
For further information about its features and functionalities please
refer to http://www.clipperz.com.
-* Clipperz Community Edition is free software: you can redistribute
- it and/or modify it under the terms of the GNU Affero General Public
- License as published by the Free Software Foundation, either version
- 3 of the License, or (at your option) any later version.
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
-* Clipperz Community Edition is distributed in the hope that it will
- be useful, but WITHOUT ANY WARRANTY; without even the implied
- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
- License along with Clipperz Community Edition. If not, see
- <http://www.gnu.org/licenses/>.
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
*/
if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; }
//#############################################################################
// Downloaded on March 05, 2007 from http://www.leemon.com/crypto/BigInt.js
//#############################################################################
////////////////////////////////////////////////////////////////////////////////////////
// Big Integer Library v. 5.0
// Created 2000, last modified 2006
// Leemon Baird
// www.leemon.com
//
// This file is public domain. You can use it for any purpose without restriction.
// I do not guarantee that it is correct, so use it at your own risk. If you use
// it for something interesting, I'd appreciate hearing about it. If you find
// any bugs or make any improvements, I'd appreciate hearing about those too.
// It would also be nice if my name and address were left in the comments.
// But none of that is required.
//
// This code defines a bigInt library for arbitrary-precision integers.
// A bigInt is an array of integers storing the value in chunks of bpe bits,
// little endian (buff[0] is the least significant word).
// Negative bigInts are stored two's complement.
// Some functions assume their parameters have at least one leading zero element.
// Functions with an underscore at the end of the name have unpredictable behavior in case of overflow,
// so the caller must make sure overflow won't happen.
// For each function where a parameter is modified, that same
// variable must not be used as another argument too.
// So, you cannot square x by doing multMod_(x,x,n).
// You must use squareMod_(x,n) instead, or do y=dup(x); multMod_(x,y,n).
//
// These functions are designed to avoid frequent dynamic memory allocation in the inner loop.
// For most functions, if it needs a BigInt as a local variable it will actually use
// a global, and will only allocate to it when it's not the right size. This ensures
// that when a function is called repeatedly with same-sized parameters, it only allocates
// memory on the first call.
//
// Note that for cryptographic purposes, the calls to Math.random() must
// be replaced with calls to a better pseudorandom number generator.
//
// In the following, "bigInt" means a bigInt with at least one leading zero element,
// and "integer" means a nonnegative integer less than radix. In some cases, integer
// can be negative. Negative bigInts are 2s complement.
@@ -1432,97 +1430,96 @@ Clipperz.Crypto.BigInt = function (aValue, aBase) {
}
this._internalValue = str2bigInt(value, base, 1, 1);
}
return this;
}
//=============================================================================
MochiKit.Base.update(Clipperz.Crypto.BigInt.prototype, {
'clone': function() {
return new Clipperz.Crypto.BigInt(this.internalValue());
},
//-------------------------------------------------------------------------
'internalValue': function () {
return this._internalValue;
},
//-------------------------------------------------------------------------
'isBigInt': true,
//-------------------------------------------------------------------------
'toString': function(aBase) {
return this.asString(aBase);
},
//-------------------------------------------------------------------------
'asString': function (aBase, minimumLength) {
var result;
var base;
if (typeof(aBase) == 'undefined') {
base = 10;
} else {
base = aBase;
}
result = bigInt2str(this.internalValue(), base).toLowerCase();
if ((typeof(minimumLength) != 'undefined') && (result.length < minimumLength)) {
var i, c;
-//MochiKit.Logging.logDebug(">>> FIXING BigInt.asString length issue")
c = (minimumLength - result.length);
for (i=0; i<c; i++) {
result = '0' + result;
}
}
return result;
},
//-------------------------------------------------------------------------
'asByteArray': function() {
return new Clipperz.ByteArray("0x" + this.asString(16), 16);
},
//-------------------------------------------------------------------------
'equals': function (aValue) {
var result;
if (aValue.isBigInt) {
result = equals(this.internalValue(), aValue.internalValue());
} else if (typeof(aValue) == "number") {
result = equalsInt(this.internalValue(), aValue);
} else {
throw Clipperz.Crypt.BigInt.exception.UnknownType;
}
return result;
},
//-------------------------------------------------------------------------
'compare': function(aValue) {
/*
var result;
var thisAsString;
var aValueAsString;
thisAsString = this.asString(10);
aValueAsString = aValue.asString(10);
result = MochiKit.Base.compare(thisAsString.length, aValueAsString.length);
if (result == 0) {
result = MochiKit.Base.compare(thisAsString, aValueAsString);
}
return result;