Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js index 2033eb4..19f19c2 100644 --- a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js +++ b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.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.Curve = function(args) { | 32 | Clipperz.Crypto.ECC.BinaryField.Curve = function(args) { |
36 | args = args || {}; | 33 | args = args || {}; |
37 | 34 | ||
38 | this._modulus = args.modulus; | 35 | this._modulus = args.modulus; |
39 | 36 | ||
40 | this._a = args.a; | 37 | this._a = args.a; |
41 | this._b = args.b; | 38 | this._b = args.b; |
42 | this._G = args.G; | 39 | this._G = args.G; |
43 | this._r = args.r; | 40 | this._r = args.r; |
44 | this._h = args.h; | 41 | this._h = args.h; |
45 | 42 | ||
46 | this._finiteField = null; | 43 | this._finiteField = null; |
47 | 44 | ||
48 | return this; | 45 | return this; |
49 | } | 46 | } |
50 | 47 | ||
51 | Clipperz.Crypto.ECC.BinaryField.Curve.prototype = MochiKit.Base.update(null, { | 48 | Clipperz.Crypto.ECC.BinaryField.Curve.prototype = MochiKit.Base.update(null, { |
52 | 49 | ||
53 | 'asString': function() { | 50 | 'asString': function() { |
54 | return "Clipperz.Crypto.ECC.BinaryField.Curve"; | 51 | return "Clipperz.Crypto.ECC.BinaryField.Curve"; |
55 | }, | 52 | }, |
56 | 53 | ||
57 | //----------------------------------------------------------------------------- | 54 | //----------------------------------------------------------------------------- |
58 | 55 | ||
59 | 'modulus': function() { | 56 | 'modulus': function() { |
60 | return this._modulus; | 57 | return this._modulus; |
61 | }, | 58 | }, |
62 | 59 | ||
63 | 'a': function() { | 60 | 'a': function() { |
64 | return this._a; | 61 | return this._a; |
65 | }, | 62 | }, |
66 | 63 | ||
67 | 'b': function() { | 64 | 'b': function() { |
68 | return this._b; | 65 | return this._b; |
69 | }, | 66 | }, |
70 | 67 | ||
71 | 'G': function() { | 68 | 'G': function() { |
72 | return this._G; | 69 | return this._G; |
73 | }, | 70 | }, |
74 | 71 | ||
75 | 'r': function() { | 72 | 'r': function() { |
76 | return this._r; | 73 | return this._r; |
77 | }, | 74 | }, |
78 | 75 | ||
79 | 'h': function() { | 76 | 'h': function() { |
80 | return this._h; | 77 | return this._h; |
81 | }, | 78 | }, |
82 | 79 | ||
83 | //----------------------------------------------------------------------------- | 80 | //----------------------------------------------------------------------------- |
84 | 81 | ||
85 | 'finiteField': function() { | 82 | 'finiteField': function() { |
86 | if (this._finiteField == null) { | 83 | if (this._finiteField == null) { |
87 | this._finiteField = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:this.modulus()}) | 84 | this._finiteField = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:this.modulus()}) |
88 | } | 85 | } |
89 | 86 | ||
90 | return this._finiteField; | 87 | return this._finiteField; |
91 | }, | 88 | }, |
92 | 89 | ||
93 | //----------------------------------------------------------------------------- | 90 | //----------------------------------------------------------------------------- |
94 | 91 | ||
95 | 'negate': function(aPointA) { | 92 | 'negate': function(aPointA) { |
96 | var result; | 93 | var result; |
97 | 94 | ||
98 | result = new Clipperz.Crypto.ECC.Point({x:aPointA.x(), y:this.finiteField().add(aPointA.y(), aPointA.x())}) | 95 | result = new Clipperz.Crypto.ECC.Point({x:aPointA.x(), y:this.finiteField().add(aPointA.y(), aPointA.x())}) |
99 | 96 | ||
100 | return result; | 97 | return result; |
101 | }, | 98 | }, |
102 | 99 | ||
103 | //----------------------------------------------------------------------------- | 100 | //----------------------------------------------------------------------------- |
104 | 101 | ||
105 | 'add': function(aPointA, aPointB) { | 102 | 'add': function(aPointA, aPointB) { |
106 | var result; | 103 | var result; |
107 | 104 | ||
108 | //console.log(">>> ECC.BinaryField.Curve.add"); | 105 | //console.log(">>> ECC.BinaryField.Curve.add"); |
109 | if (aPointA.isZero()) { | 106 | if (aPointA.isZero()) { |
110 | //console.log("--- pointA == zero"); | 107 | //console.log("--- pointA == zero"); |
111 | result = aPointB; | 108 | result = aPointB; |
112 | } else if (aPointB.isZero()) { | 109 | } else if (aPointB.isZero()) { |
113 | //console.log("--- pointB == zero"); | 110 | //console.log("--- pointB == zero"); |
114 | result = aPointA; | 111 | result = aPointA; |
115 | } else if ((aPointA.x().compare(aPointB.x()) == 0) && ((aPointA.y().compare(aPointB.y()) != 0) || aPointB.x().isZero())) { | 112 | } else if ((aPointA.x().compare(aPointB.x()) == 0) && ((aPointA.y().compare(aPointB.y()) != 0) || aPointB.x().isZero())) { |
116 | //console.log("compare A.x - B.x: ", aPointA.x().compare(aPointB.x())); | 113 | //console.log("compare A.x - B.x: ", aPointA.x().compare(aPointB.x())); |
117 | //console.log("compare A.y - B.y: ", (aPointA.y().compare(aPointB.y()) != 0)); | 114 | //console.log("compare A.y - B.y: ", (aPointA.y().compare(aPointB.y()) != 0)); |
118 | //console.log("compare B.x.isZero(): ", aPointB.x().isZero()); | 115 | //console.log("compare B.x.isZero(): ", aPointB.x().isZero()); |
119 | 116 | ||
120 | //console.log("--- result = zero"); | 117 | //console.log("--- result = zero"); |