Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a license (MIT)

* Added a the MIT license
* Minor changes
  • Loading branch information...
commit 7577cc78019daa2091d18bb87ace57ccc4f078a6 1 parent f263414
@siddMahen authored
Showing with 77 additions and 10 deletions.
  1. +23 −1 README.md
  2. +54 −8 lib/elliptic-curve.js
  3. +0 −1  lib/elliptic-elgamel.js
View
24 README.md
@@ -13,4 +13,26 @@ To install `ecc.js`:
For usage details see the in code documentation
and the examples folder.
-TODO
+## License
+
+(The MIT License)
+
+Copyright (C) 2012 by Siddharth Mahendraker
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
62 lib/elliptic-curve.js
@@ -39,6 +39,21 @@ function curve(A, B, Fp){
}
/*
+ * Computes wether a given point in on the
+ * curve
+ *
+ * @param {Point} p
+ *
+ * @returns {Boolean} if p is or isn't on the curve
+ *
+ * @api public
+ */
+
+curve.prototype.contains = function(p){
+ return this.mod((p.y*p.y), this.Fp) == this.mod(((p.x*p.x*p.x) + this.A*p.x + this.B), this.Fp);
+}
+
+/*
* Computes modulo for both positive and
* negative numbers.
*
@@ -55,9 +70,31 @@ curve.prototype.mod = function(a, b){
}
/*
+ * Computes the GCD of two numbers
+ *
+ * gcd(a, b)
+ *
+ * @param {Integer} a
+ * @param {Integer} b
+ *
+ * @returns {Integer} gcd(a, b)
+ *
+ * @api public
+ */
+
+curve.prototype.gcd = function(a, b){
+ while(b != 0){
+ var t = b;
+ b = this.mod(a, b);
+ a = t;
+ }
+ return a;
+}
+
+/*
* Computes the solutions to the equation
*
- * ax + by = gcd(a, b)
+ * ax - by = gcd(a, b) = 1
*
* where a and b are given.
*
@@ -70,17 +107,26 @@ curve.prototype.mod = function(a, b){
*/
curve.prototype.ext_gcd = function(a, b){
- if(b == 0){
- return [1, 0];
- } else {
+ var lx = 0, ly = 1,
+ x = 1, y = 0;
+
+ while(b !== 0){
var r = this.mod(a, b),
q = (a - r) / b,
- res = this.ext_gcd(b, r),
- t = res[1],
- s = ((res[0]) - (q * t));
+ tmpx = x,
+ tmpy = y;
- return [t, s];
+ x = lx - (q*x);
+ lx = tmpx;
+
+ y = ly - (q*y);
+ ly = tmpy;
+
+ a = b;
+ b = r;
}
+
+ return [ly, lx];
}
/*
View
1  lib/elliptic-elgamel.js
@@ -57,7 +57,6 @@ elgamel.prototype.encrypt = function(plaintext, pub_key, callback){
var self = this,
curve = self.ec;
- // FIXME: too many randBytes?
crypto.randomBytes(1024, function(err, buff){
var str = buff.toString("utf8"),
k = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.