Skip to content

Commit

Permalink
Merge f6d27c0 into 79e2f37
Browse files Browse the repository at this point in the history
  • Loading branch information
oberien committed Jan 4, 2017
2 parents 79e2f37 + f6d27c0 commit 612b8e8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/elliptic/ec/key.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

var BN = require('bn.js');
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var assert = utils.assert;

function KeyPair(ec, options) {
this.ec = ec;
Expand Down Expand Up @@ -81,6 +84,17 @@ KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {

KeyPair.prototype._importPublic = function _importPublic(key, enc) {
if (key.x || key.y) {
// Montgomery points only have an x coordinate.
// Weierstrass points on the other hand have both an x and a y corrdinate.
// Therefore if the curve is of type 'short' we have the folling:
// • If x is missing, there are 1 or 2 y points.
// • If y is missing, there are 1 or 3 x points.
// We don't know, which point is wanted.
if (this.ec.curve.type == 'mont') {
assert(key.x, 'Need x coordinate');
} else if (this.ec.curve.type == 'short') {
assert(key.x && key.y, 'Need both x and y coordinate');
}
this.pub = this.ec.curve.point(key.x, key.y);
return;
}
Expand Down

0 comments on commit 612b8e8

Please sign in to comment.