keybase-ecurve
Advanced tools
Comparing version 0.9.0 to 1.0.0
@@ -0,1 +1,12 @@ | ||
1.0.0 / 2014-06-25 | ||
------------------ | ||
* removed curve `secp224r1` because we're using curve specific optimizations for other curves see [#21](https://github.com/cryptocoinjs/ecurve/issues/21) | ||
0.10.0 / 2014-06-25 | ||
------------------- | ||
* moved curves to json [Daniel Cousens](https://github.com/cryptocoinjs/ecurve/pull/18) | ||
* added jshint [Daniel Cousens](https://github.com/cryptocoinjs/ecurve/pull/20) | ||
* added NIST test vectors [Daniel Cousens](https://github.com/cryptocoinjs/ecurve/commit/a35b1e210e6da46f8823e4044c8862fa58c078d0) | ||
* added pointFromX() on `Curve` instance [Daniel Cousens](https://github.com/cryptocoinjs/ecurve/commit/91296c13bb1283480335264677458281f8d2a7df) | ||
0.9.0 / 2014-06-12 | ||
@@ -2,0 +13,0 @@ ------------------ |
@@ -6,4 +6,2 @@ var assert = require('assert') | ||
module.exports = Curve | ||
function Curve(p, a, b, Gx, Gy, n, h) { | ||
@@ -13,3 +11,3 @@ this.p = p | ||
this.b = b | ||
this.G = Point.fromAffine(this, Gx, Gy), | ||
this.G = Point.fromAffine(this, Gx, Gy) | ||
this.n = n | ||
@@ -19,6 +17,21 @@ this.h = h | ||
this.infinity = new Point(this, null, null, BigInteger.ZERO) | ||
// result caching | ||
this.pOverFour = p.add(BigInteger.ONE).shiftRight(2) | ||
} | ||
Curve.prototype.pointFromX = function(isOdd, x) { | ||
var alpha = x.pow(3).add(this.a.multiply(x)).add(this.b).mod(this.p) | ||
var beta = alpha.modPow(this.pOverFour, this.p) | ||
var y = beta | ||
if (beta.isEven() ^ !isOdd) { | ||
y = this.p.subtract(y) // -y % p | ||
} | ||
return Point.fromAffine(this, x, y) | ||
} | ||
Curve.prototype.isInfinity = function(Q) { | ||
if (Q == this.infinity) return true | ||
if (Q === this.infinity) return true | ||
@@ -63,1 +76,3 @@ return Q.z.signum() === 0 && Q.y.signum() !== 0 | ||
} | ||
module.exports = Curve |
130
lib/names.js
var BigInteger = require('bn').BigInteger | ||
var curves = require('./curves') | ||
var Curve = require('./curve') | ||
var Point = require('./point') | ||
var fromHex = BigInteger.fromHex | ||
var namedCurves = { | ||
secp128r1: function() { | ||
// p = 2^128 - 2^97 - 1 | ||
var p = fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF") | ||
var a = fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC") | ||
var b = fromHex("E87579C11079F43DD824993C2CEE5ED3") | ||
var n = fromHex("FFFFFFFE0000000075A30D1B9038A115") | ||
var h = BigInteger.ONE | ||
function getCurveByName(name) { | ||
var curve = curves[name] | ||
if (!curve) return null | ||
var Gx = fromHex("161FF7528B899B2D0C28607CA52C5B86") | ||
var Gy = fromHex("CF5AC8395BAFEB13C02DA292DDED7A83") | ||
var p = new BigInteger(curve.p, 16) | ||
var a = new BigInteger(curve.a, 16) | ||
var b = new BigInteger(curve.b, 16) | ||
var n = new BigInteger(curve.n, 16) | ||
var h = new BigInteger(curve.h, 16) | ||
var Gx = new BigInteger(curve.Gx, 16) | ||
var Gy = new BigInteger(curve.Gy, 16) | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
}, | ||
secp160k1: function() { | ||
// p = 2^160 - 2^32 - 2^14 - 2^12 - 2^9 - 2^8 - 2^7 - 2^3 - 2^2 - 1 | ||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73") | ||
var a = BigInteger.ZERO | ||
var b = fromHex("07") | ||
var n = fromHex("0100000000000000000001B8FA16DFAB9ACA16B6B3") | ||
var h = BigInteger.ONE | ||
var Gx = fromHex("3B4C382CE37AA192A4019E763036F4F5DD4D7EBB") | ||
var Gy = fromHex("938CF935318FDCED6BC28286531733C3F03C4FEE") | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
}, | ||
secp160r1: function() { | ||
// p = 2^160 - 2^31 - 1 | ||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF") | ||
var a = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC") | ||
var b = fromHex("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45") | ||
var n = fromHex("0100000000000000000001F4C8F927AED3CA752257") | ||
var h = BigInteger.ONE | ||
var Gx = fromHex("4A96B5688EF573284664698968C38BB913CBFC82") | ||
var Gy = fromHex("23A628553168947D59DCC912042351377AC5FB32") | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
}, | ||
secp192k1: function() { | ||
// p = 2^192 - 2^32 - 2^12 - 2^8 - 2^7 - 2^6 - 2^3 - 1 | ||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37") | ||
var a = BigInteger.ZERO | ||
var b = fromHex("03") | ||
var n = fromHex("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D") | ||
var h = BigInteger.ONE | ||
var Gx = fromHex("DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D") | ||
var Gy = fromHex("9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D") | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
}, | ||
secp192r1: function() { | ||
// p = 2^192 - 2^64 - 1 | ||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF") | ||
var a = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC") | ||
var b = fromHex("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1") | ||
var n = fromHex("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831") | ||
var h = BigInteger.ONE | ||
var Gx = fromHex("188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012") | ||
var Gy = fromHex("07192B95FFC8DA78631011ED6B24CDD573F977A11E794811") | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
}, | ||
secp224r1: function() { | ||
// p = 2^224 - 2^96 + 1 | ||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001") | ||
var a = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE") | ||
var b = fromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4") | ||
var n = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D") | ||
var h = BigInteger.ONE | ||
var Gx = fromHex("B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21") | ||
var Gy = fromHex("BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34") | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
}, | ||
secp256k1: function() { | ||
// p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1 | ||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F") | ||
var a = BigInteger.ZERO | ||
var b = fromHex("07") | ||
var n = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141") | ||
var h = BigInteger.ONE | ||
var Gx = fromHex("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798") | ||
var Gy = fromHex("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8") | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
}, | ||
secp256r1: function() { | ||
// p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1 | ||
var p = fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF") | ||
var a = fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC") | ||
var b = fromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B") | ||
var n = fromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551") | ||
var h = BigInteger.ONE | ||
var Gx = fromHex("6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296") | ||
var Gy = fromHex("4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5") | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
} | ||
return new Curve(p, a, b, Gx, Gy, n, h) | ||
} | ||
function getCurveByName(name) { | ||
return (typeof namedCurves[name] == 'function') ? namedCurves[name]() : null | ||
} | ||
module.exports = getCurveByName | ||
@@ -61,3 +61,3 @@ var assert = require('assert') | ||
Point.prototype.negate = function() { | ||
var y = this.y.negate().mod(this.curve.p) | ||
var y = this.curve.p.subtract(this.y) | ||
@@ -82,7 +82,7 @@ return new Point(this.curve, this.x, y, this.z) | ||
if (v.signum() === 0) { | ||
if (u.signum() === 0) { | ||
return this.twice() // this == b, so double | ||
} | ||
if (u.signum() === 0) { | ||
return this.twice() // this == b, so double | ||
} | ||
return this.curve.infinity // this = -b, so infinity | ||
return this.curve.infinity // this = -b, so infinity | ||
} | ||
@@ -153,3 +153,3 @@ | ||
if (hBit != eBit) { | ||
R = R.add(hBit ? this : neg) | ||
R = R.add(hBit ? this : neg) | ||
} | ||
@@ -172,14 +172,19 @@ } | ||
var both = this.add(x) | ||
while (i >= 0) { | ||
R = R.twice() | ||
if (j.testBit(i)) { | ||
if (k.testBit(i)) { | ||
var jBit = j.testBit(i) | ||
var kBit = k.testBit(i) | ||
if (jBit) { | ||
if (kBit) { | ||
R = R.add(both) | ||
} | ||
else { | ||
} else { | ||
R = R.add(this) | ||
} | ||
} | ||
else { | ||
if (k.testBit(i)) { | ||
} else { | ||
if (kBit) { | ||
R = R.add(x) | ||
@@ -225,9 +230,9 @@ } | ||
Point.decodeFrom = function(curve, buffer) { | ||
var type = buffer.readUInt8(0); | ||
var type = buffer.readUInt8(0) | ||
var compressed = (type !== 4) | ||
var x = BigInteger.fromBuffer(buffer.slice(1, 33)) | ||
var y | ||
var byteLength = Math.floor((curve.p.bitLength() + 7) / 8) | ||
var Q | ||
if (compressed) { | ||
@@ -237,29 +242,14 @@ assert.equal(buffer.length, byteLength + 1, 'Invalid sequence length') | ||
var isYEven = (type === 0x02) | ||
var a = curve.a | ||
var b = curve.b | ||
var p = curve.p | ||
var isOdd = (type === 0x03) | ||
Q = curve.pointFromX(isOdd, x) | ||
// We precalculate (p + 1) / 4 where p is the field order | ||
if (!curve.P_OVER_FOUR) { | ||
curve.P_OVER_FOUR = p.add(BigInteger.ONE).shiftRight(2) | ||
} | ||
// Convert x to point | ||
var alpha = x.pow(3).add(a.multiply(x)).add(b).mod(p) | ||
var beta = alpha.modPow(curve.P_OVER_FOUR, p) | ||
// If beta is even, but y isn't, or vice versa, then convert it, | ||
// otherwise we're done and y == beta. | ||
y = (beta.isEven() ^ isYEven) ? p.subtract(beta) : beta | ||
} else { | ||
assert.equal(buffer.length, 1 + byteLength + byteLength, 'Invalid sequence length') | ||
y = BigInteger.fromBuffer(buffer.slice(1 + byteLength)) | ||
var y = BigInteger.fromBuffer(buffer.slice(1 + byteLength)) | ||
Q = Point.fromAffine(curve, x, y) | ||
} | ||
var pt = Point.fromAffine(curve, x, y) | ||
pt.compressed = compressed | ||
return pt | ||
Q.compressed = compressed | ||
return Q | ||
} | ||
@@ -266,0 +256,0 @@ |
{ | ||
"name": "keybase-ecurve", | ||
"version": "0.9.0", | ||
"version": "1.0.0", | ||
"description": "Elliptic curve cryptography, which uses keybase/bn for bignums", | ||
@@ -10,11 +10,12 @@ "keywords": [ | ||
"litecoin", | ||
"eliptical", | ||
"elliptic", | ||
"curve" | ||
], | ||
"devDependencies": { | ||
"coveralls": "^2.10.0", | ||
"istanbul": "^0.2.10", | ||
"jshint": "2.5.1", | ||
"mocha": "^1.20.0", | ||
"mochify": "^0.4.2", | ||
"coveralls": "^2.10.0", | ||
"mocha-lcov-reporter": "0.0.1", | ||
"istanbul": "^0.2.10" | ||
"mochify": "^0.4.2" | ||
}, | ||
@@ -27,9 +28,10 @@ "repository": { | ||
"scripts": { | ||
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js", | ||
"coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info", | ||
"jshint": "./node_modules/.bin/jshint --config jshint.json lib/*.js ; true", | ||
"test": "mocha --ui bdd", | ||
"unit": "./node_modules/.bin/mocha", | ||
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js", | ||
"coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info" | ||
"unit": "./node_modules/.bin/mocha" | ||
}, | ||
"dependencies": { | ||
"bn": ">=0.0.6" | ||
"bn": "^1.0.0" | ||
}, | ||
@@ -36,0 +38,0 @@ "testling": { |
##### Signed by https://keybase.io/max | ||
``` | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: GnuPG/MacGPG2 v2.0.22 (Darwin) | ||
Comment: GPGTools - https://gpgtools.org | ||
Version: GnuPG v2 | ||
iQEcBAABCgAGBQJTm1tgAAoJEJgKPw0B/gTfZpUH/ROLrtxkpvu92BvzZg2qER7z | ||
0Q9wCCU7SOUmVLOOpgoPUTJotSo0cTGLdl9SuCGExa46V4JwQJo2sKCCILl8pbSY | ||
TLMGuZ839SIYhoknDxajCgf0pKMJc/KyyQLvkILfx9RUUWY/hl7s4GAyQAvI4y72 | ||
SackerlShJixGIsJt5zuKYkSjd8+lS+RcHrSHWzVz3lKkwr2B+eJrQ92DDXYmh2c | ||
GzUUV+ycr9LnnPVY8UwGA0/2uURcqgilPpKChm90YEyhCIG+KPONz3OvB1SX0UMf | ||
ucZ8pAWf274HKQSxAhqDWECKhhVhHNvPOakWCB3byarRDHvc1nAAI745gJz9NVg= | ||
=boGM | ||
iQEcBAABAgAGBQJT2NgNAAoJEJgKPw0B/gTfVcsH+wdCi96U7ZEuL71BQ3FoBRPB | ||
mvN39q34wIlgRhm8d9pp6yRktHdt3tNjGtlnoR2j6b7a9iPjIkFSQwGhoQMwrB0H | ||
zETZgPuCaHY/RHeMUBvufMydnO/WchvX0fKqsn343nGU3FV1QDyRqSdKWKmZx9I0 | ||
yh/E9+pQfhiCpSJsY3W6YRjW6tWEqaR1r0TipEtNrO4jfhliL5y8DeumEJFx5Ey9 | ||
+YJOTg1cjgq2V3940tBSuflgJWQCw/1QYYfzmFfmn98hCMijrQeb4D6dSyNMhcBI | ||
ci2Ibxli2rIXGonR++GJFlWP6twAPkQ+moYoGr8vQlusulTjS9mH3n1XL9iptbs= | ||
=RxXF | ||
-----END PGP SIGNATURE----- | ||
@@ -25,26 +24,30 @@ | ||
``` | ||
size exec file contents | ||
./ | ||
33 .gitignore 044a875c16eed65b7485565a6eef29167ffab92b5ee4247a5e9f3b8203faf405 | ||
103 .min-wd 5b779cd77bc3f45bce80c1f7d4aeea4b11ff874e6eafebd2ebac6657c378e219 | ||
72 .npmignore 013421fd6eee4c2812a4342b3c944349b1f64ee94f3eeaa152825003731a4181 | ||
172 .travis.yml 51a676eeaf009d3eea6773b6efc828f4807185cd950895a85b865fdf51758c45 | ||
4623 CHANGELOG.md 3e4dcf1938585dd3ac2ba0bca5a1f9db83feec4f9d8833a9f4a477cd4bcae397 | ||
159 Makefile 26c6343df0ac899866055d5ebf76251b81bf93581a81a31cb9a0dc2ae6c9ba59 | ||
599 README.md bb8247bf8afff378db42dea36408955b4c7b9b07407689ecc212be21f3363d01 | ||
lib/ | ||
1462 curve.js d45bfb32033dc71ac7d39f6f2d5de9e5332520ce3540ca540c919c86f77175c6 | ||
190 index.js c5bd5761f0fdbd7a11d0755e33bc36cd15ed78b3089f9c92ac3d929ec2828cba | ||
4734 names.js a041265ec0f3dddd212bb9285edea3bac72eaebede3c5354213bf38e040ed7c9 | ||
6901 point.js 906616ecbb91315c47ae561262d8a02b897760f469a4d5a4671625e4e38e90ff | ||
1140 package.json 6eb33f01db5d15e5650103a240d9f8efe6444d4702b27f5dc4dca2d6e5865a96 | ||
276 patch.sh 378e7b47c88c843a39ad22d0017f7bb98f783d5891553f1054cd6cab6ba4fc1f | ||
test/ | ||
8817 curve.test.js 32420fd56b6d7906fb6a8fa8fca6ede5f3b09fa49f1ea40054217b24fc3dd8ce | ||
fixtures/ | ||
932 curve.json 5ec54a330cfca970f7953616bd3d3426e1792b1345a8cb030b0b99ca5e79c853 | ||
3674 point.json 83f68fcf38b49766031e7ffc4b458a4c3d50fd4600e705be875e01b1c01a19af | ||
39 mocha.opts 74ff3e60361757523c9cacc452540490fb2deec1bace92f82b12c06702a4e1ba | ||
1513 names.test.js d4c9826f92e467658a4ffe0de6c5718e378713a0c82386a0b672ab00dfef27f5 | ||
8230 point.test.js 9d679f4441a4cdf3fb48068b522de6f768b140ed836644d16c9fdb858b49a6c3 | ||
size exec file contents | ||
./ | ||
33 .gitignore 044a875c16eed65b7485565a6eef29167ffab92b5ee4247a5e9f3b8203faf405 | ||
103 .min-wd 5b779cd77bc3f45bce80c1f7d4aeea4b11ff874e6eafebd2ebac6657c378e219 | ||
72 .npmignore 013421fd6eee4c2812a4342b3c944349b1f64ee94f3eeaa152825003731a4181 | ||
172 .travis.yml 51a676eeaf009d3eea6773b6efc828f4807185cd950895a85b865fdf51758c45 | ||
5302 CHANGELOG.md 657cf5f94b23c928320c52c7fa8833d93e86edcf7b23786450583846eaf13b8b | ||
159 Makefile 26c6343df0ac899866055d5ebf76251b81bf93581a81a31cb9a0dc2ae6c9ba59 | ||
599 README.md bb8247bf8afff378db42dea36408955b4c7b9b07407689ecc212be21f3363d01 | ||
309 jshint.json f61b0cc0a09a7b7adefe7a1cc8d30f7799aeeea8bedddf3ab3b265b8e680baf5 | ||
lib/ | ||
1840 curve.js e4399114d747a0aacc4ac4ec9b79d2a08c1761b1f590b18eed50fbb7d463e39e | ||
2543 curves.json d46c62c9a52e0a0f258522935de19272f2b79be804a6c13d4852a267970682f1 | ||
190 index.js c5bd5761f0fdbd7a11d0755e33bc36cd15ed78b3089f9c92ac3d929ec2828cba | ||
542 names.js 7f7d401cf0b22ffaf934aa6be8e36799bb631c771545b57e4069faf79df30c08 | ||
6414 point.js a06693e6bd50c8673166302e4b2a18047f334a5a29a086e531cd894a53d10508 | ||
1242 package.json 939d7a181399763a605fd8f2fdbe88e5aab0f014f52a321dd8a821dc97917f5c | ||
276 patch.sh 378e7b47c88c843a39ad22d0017f7bb98f783d5891553f1054cd6cab6ba4fc1f | ||
test/ | ||
10371 curve.js ed82b768513b532187b630aeeb9028f3a984b879e034aef8caaef521fbdd2cb4 | ||
fixtures/ | ||
932 curve.json 82dcb87156c194f85072d1a54a3201c792f93d3f47b9ef1e48890d98b37727a3 | ||
93532 nist.json b09a197421b6ee144530a5e4e0cd30cd6caa44cecf7504b88c2dea569ba1af05 | ||
3951 point.json 1dd500fd162becb8c0391acc0a56177becdfa2d1117f2ce7bfacc26a1d7a48ca | ||
39 mocha.opts 74ff3e60361757523c9cacc452540490fb2deec1bace92f82b12c06702a4e1ba | ||
1026 names.js 8d9f576495831570148feb1428fcbfd7d678597f903fe052842973149d282e2b | ||
852 nist.vectors.js dde7e20c03a97c59462ce52edae544cc23ff1f0f6b8a70a70f0078118dac5b74 | ||
3044 point.js 3b4793d5f393a98918611aea4692193362973610c7f7e07b390492b0454289f3 | ||
``` | ||
@@ -51,0 +54,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
14
356
1
23764
6
Updatedbn@^1.0.0