summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-06 00:36:10 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-06 00:36:10 (UTC)
commit6ba274c79e60e417132b260bd0117c5a68121387 (patch) (unidiff)
tree57c1f95d0fbf9b80312c5c6b6f4a4f951e31c770 /frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js
parent13ebf1b1987a1566d081ff1ba89b4dca197b7d2e (diff)
downloadclipperz-6ba274c79e60e417132b260bd0117c5a68121387.zip
clipperz-6ba274c79e60e417132b260bd0117c5a68121387.tar.gz
clipperz-6ba274c79e60e417132b260bd0117c5a68121387.tar.bz2
Fixed the copyright headers
Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Curve.js15
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,152 +1,149 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2011 Clipperz Srl
4 4
5This file is part of Clipperz's Javascript Crypto Library. 5This file is part of Clipperz Community Edition.
6Javascript Crypto Library provides web developers with an extensive 6Clipperz Community Edition is an online password manager.
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please 7For further information about its features and functionalities please
11refer to http://www.clipperz.com 8refer 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//}
32if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } 29if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; }
33if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } 30if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; }
34 31
35Clipperz.Crypto.ECC.BinaryField.Curve = function(args) { 32Clipperz.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
51Clipperz.Crypto.ECC.BinaryField.Curve.prototype = MochiKit.Base.update(null, { 48Clipperz.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");
121 result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O}); 118 result = new Clipperz.Crypto.ECC.BinaryField.Point({x:Clipperz.Crypto.ECC.BinaryField.Value.O, y:Clipperz.Crypto.ECC.BinaryField.Value.O});
122 } else { 119 } else {
123//console.log("--- result = ELSE"); 120//console.log("--- result = ELSE");
124 varf2m; 121 varf2m;
125 var x, y; 122 var x, y;
126 var lambda; 123 var lambda;
127 var aX, aY, bX, bY; 124 var aX, aY, bX, bY;
128 125
129 aX = aPointA.x()._value; 126 aX = aPointA.x()._value;
130 aY = aPointA.y()._value; 127 aY = aPointA.y()._value;
131 bX = aPointB.x()._value; 128 bX = aPointB.x()._value;
132 bY = aPointB.y()._value; 129 bY = aPointB.y()._value;
133 130
134 f2m = this.finiteField(); 131 f2m = this.finiteField();
135 132
136 if (aPointA.x().compare(aPointB.x()) != 0) { 133 if (aPointA.x().compare(aPointB.x()) != 0) {
137//console.log(" a.x != b.x"); 134//console.log(" a.x != b.x");
138 lambda =f2m._fastMultiply( 135 lambda =f2m._fastMultiply(
139 f2m._add(aY, bY), 136 f2m._add(aY, bY),
140 f2m._inverse(f2m._add(aX, bX)) 137 f2m._inverse(f2m._add(aX, bX))
141 ); 138 );
142 x = f2m._add(this.a()._value, f2m._square(lambda)); 139 x = f2m._add(this.a()._value, f2m._square(lambda));
143 f2m._overwriteAdd(x, lambda); 140 f2m._overwriteAdd(x, lambda);
144 f2m._overwriteAdd(x, aX); 141 f2m._overwriteAdd(x, aX);
145 f2m._overwriteAdd(x, bX); 142 f2m._overwriteAdd(x, bX);
146 } else { 143 } else {
147//console.log(" a.x == b.x"); 144//console.log(" a.x == b.x");
148 lambda = f2m._add(bX, f2m._fastMultiply(bY, f2m._inverse(bX))); 145 lambda = f2m._add(bX, f2m._fastMultiply(bY, f2m._inverse(bX)));
149//console.log(" lambda: " + lambda.asString(16)); 146//console.log(" lambda: " + lambda.asString(16));
150 x = f2m._add(this.a()._value, f2m._square(lambda)); 147 x = f2m._add(this.a()._value, f2m._square(lambda));
151//console.log(" x (step 1): " + x.asString(16)); 148//console.log(" x (step 1): " + x.asString(16));
152 f2m._overwriteAdd(x, lambda); 149 f2m._overwriteAdd(x, lambda);