key: error when only either x or y are provided

PR-URL: https://github.com/indutny/elliptic/pull/112
Reviewed-By: Fedor Indutny <[email protected]>
This commit is contained in:
oberien
2017-02-06 18:12:11 -05:00
committed by Fedor Indutny
parent 198a9fea76
commit 26a0e25df9
+12
View File
@@ -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;
@@ -81,6 +84,15 @@ 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/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);
return;
}