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) (side-by-side diff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.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/FiniteField.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js index 56f257a..7b7c2c6 100644 --- a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js +++ b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js @@ -1,270 +1,266 @@ /* -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/. */ //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { // throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; //} if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } Clipperz.Crypto.ECC.BinaryField.FiniteField = function(args) { args = args || {}; this._modulus = args.modulus; return this; } Clipperz.Crypto.ECC.BinaryField.FiniteField.prototype = MochiKit.Base.update(null, { 'asString': function() { return "Clipperz.Crypto.ECC.BinaryField.FiniteField (" + this.modulus().asString() + ")"; }, //----------------------------------------------------------------------------- 'modulus': function() { return this._modulus; }, //----------------------------------------------------------------------------- '_module': function(aValue) { var result; var modulusComparison; -//console.log(">>> binaryField.finiteField.(standard)module"); modulusComparison = Clipperz.Crypto.ECC.BinaryField.Value._compare(aValue, this.modulus()._value); if (modulusComparison < 0) { result = aValue; } else if (modulusComparison == 0) { result = [0]; } else { var modulusBitSize; var resultBitSize; result = aValue; modulusBitSize = this.modulus().bitSize(); resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); while (resultBitSize >= modulusBitSize) { Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this.modulus()._value, resultBitSize - modulusBitSize)); resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); } } -//console.log("<<< binaryField.finiteField.(standard)module"); - + return result; }, 'module': function(aValue) { return new Clipperz.Crypto.ECC.BinaryField.Value(this._module(aValue._value.slice(0))); }, //----------------------------------------------------------------------------- '_add': function(a, b) { return Clipperz.Crypto.ECC.BinaryField.Value._xor(a, b); }, '_overwriteAdd': function(a, b) { Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(a, b); }, 'add': function(a, b) { return new Clipperz.Crypto.ECC.BinaryField.Value(this._add(a._value, b._value)); }, //----------------------------------------------------------------------------- 'negate': function(aValue) { return aValue.clone(); }, //----------------------------------------------------------------------------- '_multiply': function(a, b) { var result; var valueToXor; var i,c; result = [0]; valueToXor = b; c = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(a); for (i=0; i<c; i++) { if (Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(a, i) === true) { Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, valueToXor); } valueToXor = Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft(valueToXor, 1); } result = this._module(result); return result; }, 'multiply': function(a, b) { return new Clipperz.Crypto.ECC.BinaryField.Value(this._multiply(a._value, b._value)); }, //----------------------------------------------------------------------------- '_fastMultiply': function(a, b) { var result; var B; var i,c; result = [0]; B = b.slice(0); // Is this array copy avoidable? c = 32; for (i=0; i<c; i++) { var ii, cc; cc = a.length; for (ii=0; ii<cc; ii++) { if (((a[ii] >>> i) & 0x01) == 1) { Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, B, ii); } } if (i < (c-1)) { B = Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft(B, 1); } } result = this._module(result); return result; }, 'fastMultiply': function(a, b) { return new Clipperz.Crypto.ECC.BinaryField.Value(this._fastMultiply(a._value, b._value)); }, //----------------------------------------------------------------------------- // // Guide to Elliptic Curve Cryptography // Darrel Hankerson, Alfred Menezes, Scott Vanstone // - Pag: 49, Alorithm 2.34 // //----------------------------------------------------------------------------- '_square': function(aValue) { var result; var value; var c,i; var precomputedValues; value = aValue; result = new Array(value.length * 2); precomputedValues = Clipperz.Crypto.ECC.BinaryField.FiniteField.squarePrecomputedBytes; c = value.length; for (i=0; i<c; i++) { result[i*2] = precomputedValues[(value[i] & 0x000000ff)]; result[i*2] |= ((precomputedValues[(value[i] & 0x0000ff00) >>> 8]) << 16); result[i*2 + 1] = precomputedValues[(value[i] & 0x00ff0000) >>> 16]; result[i*2 + 1] |= ((precomputedValues[(value[i] & 0xff000000) >>> 24]) << 16); } return this._module(result); }, 'square': function(aValue) { return new Clipperz.Crypto.ECC.BinaryField.Value(this._square(aValue._value)); }, //----------------------------------------------------------------------------- '_inverse': function(aValue) { var result; var b, c; var u, v; // b = Clipperz.Crypto.ECC.BinaryField.Value.I._value; b = [1]; // c = Clipperz.Crypto.ECC.BinaryField.Value.O._value; c = [0]; u = this._module(aValue); v = this.modulus()._value.slice(0); while (Clipperz.Crypto.ECC.BinaryField.Value._bitSize(u) > 1) { var bitDifferenceSize; bitDifferenceSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(u) - Clipperz.Crypto.ECC.BinaryField.Value._bitSize(v); if (bitDifferenceSize < 0) { var swap; swap = u; u = v; v = swap; swap = c; c = b; b = swap; bitDifferenceSize = -bitDifferenceSize; } u = this._add(u, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(v, bitDifferenceSize)); b = this._add(b, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(c, bitDifferenceSize)); // this._overwriteAdd(u, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(v, bitDifferenceSize)); // this._overwriteAdd(b, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(c, bitDifferenceSize)); } result = this._module(b); return result; }, 'inverse': function(aValue) { return new Clipperz.Crypto.ECC.BinaryField.Value(this._inverse(aValue._value)); }, //----------------------------------------------------------------------------- __syntaxFix__: "syntax fix" }); Clipperz.Crypto.ECC.BinaryField.FiniteField.squarePrecomputedBytes = [ 0x0000, // 0 = 0000 0000 -> 0000 0000 0000 0000 0x0001, // 1 = 0000 0001 -> 0000 0000 0000 0001 0x0004, // 2 = 0000 0010 -> 0000 0000 0000 0100 0x0005, // 3 = 0000 0011 -> 0000 0000 0000 0101 0x0010, // 4 = 0000 0100 -> 0000 0000 0001 0000 0x0011, // 5 = 0000 0101 -> 0000 0000 0001 0001 0x0014, // 6 = 0000 0110 -> 0000 0000 0001 0100 0x0015, // 7 = 0000 0111 -> 0000 0000 0001 0101 0x0040, // 8 = 0000 1000 -> 0000 0000 0100 0000 0x0041, // 9 = 0000 1001 -> 0000 0000 0100 0001 0x0044, // 10 = 0000 1010 -> 0000 0000 0100 0100 0x0045, // 11 = 0000 1011 -> 0000 0000 0100 0101 0x0050, // 12 = 0000 1100 -> 0000 0000 0101 0000 0x0051, // 13 = 0000 1101 -> 0000 0000 0101 0001 0x0054, // 14 = 0000 1110 -> 0000 0000 0101 0100 0x0055, // 15 = 0000 1111 -> 0000 0000 0101 0101 0x0100, // 16 = 0001 0000 -> 0000 0001 0000 0000 0x0101, // 17 = 0001 0001 -> 0000 0001 0000 0001 0x0104, // 18 = 0001 0010 -> 0000 0001 0000 0100 |