elliptic
Advanced tools
Comparing version 6.3.2 to 6.3.3
@@ -140,3 +140,3 @@ 'use strict'; | ||
a: '76d06', | ||
b: '0', | ||
b: '1', | ||
n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed', | ||
@@ -143,0 +143,0 @@ hash: hash.sha256, |
'use strict'; | ||
var BN = require('bn.js'); | ||
var elliptic = require('../../elliptic'); | ||
var utils = elliptic.utils; | ||
var assert = utils.assert; | ||
@@ -84,2 +87,11 @@ function KeyPair(ec, options) { | ||
if (key.x || key.y) { | ||
// Montgomery points only have an `x` coordinate. | ||
// Weierstrass/Edwards points on the other hand have both `x` and | ||
// `y` coordinates. | ||
if (this.ec.curve.type === 'mont') { | ||
assert(key.x, 'Need x coordinate'); | ||
} else if (this.ec.curve.type === 'short' || | ||
this.ec.curve.type === 'edwards') { | ||
assert(key.x && key.y, 'Need both x and y coordinate'); | ||
} | ||
this.pub = this.ec.curve.point(key.x, key.y); | ||
@@ -86,0 +98,0 @@ return; |
{ | ||
"name": "elliptic", | ||
"version": "6.3.2", | ||
"version": "6.3.3", | ||
"description": "EC cryptography", | ||
@@ -38,2 +38,3 @@ "main": "lib/elliptic.js", | ||
"grunt-browserify": "^5.0.0", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-contrib-connect": "^1.0.0", | ||
@@ -40,0 +41,0 @@ "grunt-contrib-copy": "^1.0.0", |
@@ -122,4 +122,4 @@ # Elliptic [![Build Status](https://secure.travis-ci.org/indutny/elliptic.png)](http://travis-ci.org/indutny/elliptic) [![Coverage Status](https://coveralls.io/repos/indutny/elliptic/badge.svg?branch=master&service=github)](https://coveralls.io/github/indutny/elliptic?branch=master) [![Code Climate](https://codeclimate.com/github/indutny/elliptic/badges/gpa.svg)](https://codeclimate.com/github/indutny/elliptic) | ||
```javascript | ||
var ECDH = require('elliptic').ec; | ||
var ec = new ECDH('curve25519'); | ||
var EC = require('elliptic').ec; | ||
var ec = new EC('curve25519'); | ||
@@ -138,2 +138,24 @@ // Generate keys | ||
three and more members: | ||
```javascript | ||
var EC = require('elliptic').ec; | ||
var ec = new EC('curve25519'); | ||
var A = ec.genKeyPair(); | ||
var B = ec.genKeyPair(); | ||
var C = ec.genKeyPair(); | ||
var AB = A.getPublic().mul(B.getPrivate()) | ||
var BC = B.getPublic().mul(C.getPrivate()) | ||
var CA = C.getPublic().mul(A.getPrivate()) | ||
var ABC = AB.mul(C.getPrivate()) | ||
var BCA = BC.mul(A.getPrivate()) | ||
var CAB = CA.mul(B.getPrivate()) | ||
console.log(ABC.getX().toString(16)) | ||
console.log(BCA.getX().toString(16)) | ||
console.log(CAB.getX().toString(16)) | ||
``` | ||
NOTE: `.derive()` returns a [BN][1] instance. | ||
@@ -140,0 +162,0 @@ |
121465
3513
228
14