summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js b/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js
index 650b479..de1e6a8 100644
--- a/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js
+++ b/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js
@@ -1,118 +1,116 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer 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
26try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { 24try { 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}
29if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } 27if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; }
30if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } 28if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; }
31 29
32Clipperz.Crypto.ECC.BinaryField.FiniteField = function(args) { 30Clipperz.Crypto.ECC.BinaryField.FiniteField = function(args) {
33 args = args || {}; 31 args = args || {};
34 this._modulus = args.modulus; 32 this._modulus = args.modulus;
35 33
36 return this; 34 return this;
37} 35}
38 36
39Clipperz.Crypto.ECC.BinaryField.FiniteField.prototype = MochiKit.Base.update(null, { 37Clipperz.Crypto.ECC.BinaryField.FiniteField.prototype = MochiKit.Base.update(null, {
40 38
41 'asString': function() { 39 'asString': function() {
42 return "Clipperz.Crypto.ECC.BinaryField.FiniteField (" + this.modulus().asString() + ")"; 40 return "Clipperz.Crypto.ECC.BinaryField.FiniteField (" + this.modulus().asString() + ")";
43 }, 41 },
44 42
45 //----------------------------------------------------------------------------- 43 //-----------------------------------------------------------------------------
46 44
47 'modulus': function() { 45 'modulus': function() {
48 return this._modulus; 46 return this._modulus;
49 }, 47 },
50 48
51 //----------------------------------------------------------------------------- 49 //-----------------------------------------------------------------------------
52 50
53 '_module': function(aValue) { 51 '_module': function(aValue) {
54 varresult; 52 varresult;
55 var modulusComparison; 53 var modulusComparison;
56//console.log(">>> binaryField.finiteField.(standard)module"); 54//console.log(">>> binaryField.finiteField.(standard)module");
57 55
58 modulusComparison = Clipperz.Crypto.ECC.BinaryField.Value._compare(aValue, this.modulus()._value); 56 modulusComparison = Clipperz.Crypto.ECC.BinaryField.Value._compare(aValue, this.modulus()._value);
59 57
60 if (modulusComparison < 0) { 58 if (modulusComparison < 0) {
61 result = aValue; 59 result = aValue;
62 } else if (modulusComparison == 0) { 60 } else if (modulusComparison == 0) {
63 result = [0]; 61 result = [0];
64 } else { 62 } else {
65 var modulusBitSize; 63 var modulusBitSize;
66 var resultBitSize; 64 var resultBitSize;
67 65
68 result = aValue; 66 result = aValue;
69 67
70 modulusBitSize = this.modulus().bitSize(); 68 modulusBitSize = this.modulus().bitSize();
71 resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); 69 resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result);
72 while (resultBitSize >= modulusBitSize) { 70 while (resultBitSize >= modulusBitSize) {
73 Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this.modulus()._value, resultBitSize - modulusBitSize)); 71 Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this.modulus()._value, resultBitSize - modulusBitSize));
74 resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); 72 resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result);
75 } 73 }
76 } 74 }
77//console.log("<<< binaryField.finiteField.(standard)module"); 75//console.log("<<< binaryField.finiteField.(standard)module");
78 76
79 return result; 77 return result;
80 }, 78 },
81 79
82 'module': function(aValue) { 80 'module': function(aValue) {
83 return new Clipperz.Crypto.ECC.BinaryField.Value(this._module(aValue._value.slice(0))); 81 return new Clipperz.Crypto.ECC.BinaryField.Value(this._module(aValue._value.slice(0)));
84 }, 82 },
85 83
86 //----------------------------------------------------------------------------- 84 //-----------------------------------------------------------------------------
87 85
88 '_add': function(a, b) { 86 '_add': function(a, b) {
89 return Clipperz.Crypto.ECC.BinaryField.Value._xor(a, b); 87 return Clipperz.Crypto.ECC.BinaryField.Value._xor(a, b);
90 }, 88 },
91 89
92 '_overwriteAdd': function(a, b) { 90 '_overwriteAdd': function(a, b) {
93 Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(a, b); 91 Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(a, b);
94 }, 92 },
95 93
96 'add': function(a, b) { 94 'add': function(a, b) {
97 return new Clipperz.Crypto.ECC.BinaryField.Value(this._add(a._value, b._value)); 95 return new Clipperz.Crypto.ECC.BinaryField.Value(this._add(a._value, b._value));
98 }, 96 },
99 97
100 //----------------------------------------------------------------------------- 98 //-----------------------------------------------------------------------------
101 99
102 'negate': function(aValue) { 100 'negate': function(aValue) {
103 return aValue.clone(); 101 return aValue.clone();
104 }, 102 },
105 103
106 //----------------------------------------------------------------------------- 104 //-----------------------------------------------------------------------------
107 105
108 '_multiply': function(a, b) { 106 '_multiply': function(a, b) {
109 var result; 107 var result;
110 var valueToXor; 108 var valueToXor;
111 var i,c; 109 var i,c;
112 110
113 result = [0]; 111 result = [0];
114 valueToXor = b; 112 valueToXor = b;
115 c = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(a); 113 c = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(a);
116 for (i=0; i<c; i++) { 114 for (i=0; i<c; i++) {
117 if (Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(a, i) === true) { 115 if (Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(a, i) === true) {
118 Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, valueToXor); 116 Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, valueToXor);