Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js index a649c9f..56f257a 100644 --- a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js +++ b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js | |||
@@ -1,120 +1,117 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz's Javascript Crypto Library. | 5 | This file is part of Clipperz Community Edition. |
6 | Javascript Crypto Library provides web developers with an extensive | 6 | Clipperz Community Edition is an online password manager. |
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
11 | refer to http://www.clipperz.com | 8 | refer to http://www.clipperz.com. |
12 | 9 | ||
13 | * Javascript Crypto Library is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
14 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
15 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
16 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
17 | 14 | ||
18 | * Javascript Crypto Library is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
21 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
22 | 19 | ||
23 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
24 | License along with Javascript Crypto Library. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
25 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
26 | 23 | ||
27 | */ | 24 | */ |
28 | 25 | ||
29 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | 26 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { |
30 | //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; | 27 | //throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; |
31 | //} | 28 | //} |
32 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | 29 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } |
33 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | 30 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } |
34 | 31 | ||
35 | Clipperz.Crypto.ECC.BinaryField.FiniteField = function(args) { | 32 | Clipperz.Crypto.ECC.BinaryField.FiniteField = function(args) { |
36 | args = args || {}; | 33 | args = args || {}; |
37 | this._modulus = args.modulus; | 34 | this._modulus = args.modulus; |
38 | 35 | ||
39 | return this; | 36 | return this; |
40 | } | 37 | } |
41 | 38 | ||
42 | Clipperz.Crypto.ECC.BinaryField.FiniteField.prototype = MochiKit.Base.update(null, { | 39 | Clipperz.Crypto.ECC.BinaryField.FiniteField.prototype = MochiKit.Base.update(null, { |
43 | 40 | ||
44 | 'asString': function() { | 41 | 'asString': function() { |
45 | return "Clipperz.Crypto.ECC.BinaryField.FiniteField (" + this.modulus().asString() + ")"; | 42 | return "Clipperz.Crypto.ECC.BinaryField.FiniteField (" + this.modulus().asString() + ")"; |
46 | }, | 43 | }, |
47 | 44 | ||
48 | //----------------------------------------------------------------------------- | 45 | //----------------------------------------------------------------------------- |
49 | 46 | ||
50 | 'modulus': function() { | 47 | 'modulus': function() { |
51 | return this._modulus; | 48 | return this._modulus; |
52 | }, | 49 | }, |
53 | 50 | ||
54 | //----------------------------------------------------------------------------- | 51 | //----------------------------------------------------------------------------- |
55 | 52 | ||
56 | '_module': function(aValue) { | 53 | '_module': function(aValue) { |
57 | varresult; | 54 | varresult; |
58 | var modulusComparison; | 55 | var modulusComparison; |
59 | //console.log(">>> binaryField.finiteField.(standard)module"); | 56 | //console.log(">>> binaryField.finiteField.(standard)module"); |
60 | 57 | ||
61 | modulusComparison = Clipperz.Crypto.ECC.BinaryField.Value._compare(aValue, this.modulus()._value); | 58 | modulusComparison = Clipperz.Crypto.ECC.BinaryField.Value._compare(aValue, this.modulus()._value); |
62 | 59 | ||
63 | if (modulusComparison < 0) { | 60 | if (modulusComparison < 0) { |
64 | result = aValue; | 61 | result = aValue; |
65 | } else if (modulusComparison == 0) { | 62 | } else if (modulusComparison == 0) { |
66 | result = [0]; | 63 | result = [0]; |
67 | } else { | 64 | } else { |
68 | var modulusBitSize; | 65 | var modulusBitSize; |
69 | var resultBitSize; | 66 | var resultBitSize; |
70 | 67 | ||
71 | result = aValue; | 68 | result = aValue; |
72 | 69 | ||
73 | modulusBitSize = this.modulus().bitSize(); | 70 | modulusBitSize = this.modulus().bitSize(); |
74 | resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); | 71 | resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); |
75 | while (resultBitSize >= modulusBitSize) { | 72 | while (resultBitSize >= modulusBitSize) { |
76 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this.modulus()._value, resultBitSize - modulusBitSize)); | 73 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(result, Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft(this.modulus()._value, resultBitSize - modulusBitSize)); |
77 | resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); | 74 | resultBitSize = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(result); |
78 | } | 75 | } |
79 | } | 76 | } |
80 | //console.log("<<< binaryField.finiteField.(standard)module"); | 77 | //console.log("<<< binaryField.finiteField.(standard)module"); |
81 | 78 | ||
82 | return result; | 79 | return result; |
83 | }, | 80 | }, |
84 | 81 | ||
85 | 'module': function(aValue) { | 82 | 'module': function(aValue) { |
86 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._module(aValue._value.slice(0))); | 83 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._module(aValue._value.slice(0))); |
87 | }, | 84 | }, |
88 | 85 | ||
89 | //----------------------------------------------------------------------------- | 86 | //----------------------------------------------------------------------------- |
90 | 87 | ||
91 | '_add': function(a, b) { | 88 | '_add': function(a, b) { |
92 | return Clipperz.Crypto.ECC.BinaryField.Value._xor(a, b); | 89 | return Clipperz.Crypto.ECC.BinaryField.Value._xor(a, b); |
93 | }, | 90 | }, |
94 | 91 | ||
95 | '_overwriteAdd': function(a, b) { | 92 | '_overwriteAdd': function(a, b) { |
96 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(a, b); | 93 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor(a, b); |
97 | }, | 94 | }, |
98 | 95 | ||
99 | 'add': function(a, b) { | 96 | 'add': function(a, b) { |
100 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._add(a._value, b._value)); | 97 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._add(a._value, b._value)); |
101 | }, | 98 | }, |
102 | 99 | ||
103 | //----------------------------------------------------------------------------- | 100 | //----------------------------------------------------------------------------- |
104 | 101 | ||
105 | 'negate': function(aValue) { | 102 | 'negate': function(aValue) { |
106 | return aValue.clone(); | 103 | return aValue.clone(); |
107 | }, | 104 | }, |
108 | 105 | ||
109 | //----------------------------------------------------------------------------- | 106 | //----------------------------------------------------------------------------- |
110 | 107 | ||
111 | '_multiply': function(a, b) { | 108 | '_multiply': function(a, b) { |
112 | var result; | 109 | var result; |
113 | var valueToXor; | 110 | var valueToXor; |
114 | var i,c; | 111 | var i,c; |
115 | 112 | ||
116 | result = [0]; | 113 | result = [0]; |
117 | valueToXor = b; | 114 | valueToXor = b; |
118 | c = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(a); | 115 | c = Clipperz.Crypto.ECC.BinaryField.Value._bitSize(a); |
119 | for (i=0; i<c; i++) { | 116 | for (i=0; i<c; i++) { |
120 | if (Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(a, i) === true) { | 117 | if (Clipperz.Crypto.ECC.BinaryField.Value._isBitSet(a, i) === true) { |