Skip to content

Commit

Permalink
add script to compute precomputed curves, elliptic.usePrecomputed, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Sep 9, 2019
1 parent 71e4e8e commit dae93e6
Show file tree
Hide file tree
Showing 22 changed files with 6,976 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/elliptic.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ elliptic.curves = require('./elliptic/curves');
// Protocols
elliptic.ec = require('./elliptic/ec');
elliptic.eddsa = require('./elliptic/eddsa');

// Performance
elliptic.usePrecomputed = require('./elliptic/use-precomputed');
4 changes: 2 additions & 2 deletions lib/elliptic/curve/short.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ Point.prototype._getBeta = function _getBeta() {

Point.prototype.toJSON = function toJSON() {
if (!this.precomputed)
return [ this.x, this.y ];
return [ this.x.fromRed(), this.y.fromRed() ];

return [ this.x, this.y, this.precomputed && {
return [ this.x.fromRed(), this.y.fromRed(), this.precomputed && {
doubles: this.precomputed.doubles && {
step: this.precomputed.doubles.step,
points: this.precomputed.doubles.points.slice(1)
Expand Down
9 changes: 9 additions & 0 deletions lib/elliptic/curves.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,25 @@ function PresetCurve(options) {
this.n = this.curve.n;
this.hash = options.hash;

if (!options.skipValidation) {
this.validate();
}
}

PresetCurve.prototype.validate = function () {
assert(this.g.validate(), 'Invalid curve');
assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
}

curves.PresetCurve = PresetCurve;

function defineCurve(name, options) {
Object.defineProperty(curves, name, {
configurable: true,
enumerable: true,
get: function() {
// ok to mutate, this getter is only used internally
options.skipValidation = true;
var curve = new PresetCurve(options);
Object.defineProperty(curves, name, {
configurable: true,
Expand Down
Loading

0 comments on commit dae93e6

Please sign in to comment.