Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wasmcurves

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wasmcurves - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

.eslintignore

6

benchmarks/multiexp.js

@@ -7,5 +7,2 @@ const bn128 = require("ffjavascript").bn128;

async function run() {

@@ -41,4 +38,3 @@ const n8 = 32;

// for (let k=0; k<3; k++)
pb.g1m_multiexpAffine(pBases, pScalars, n8, N, pRes);
pb.g1m_multiexpAffine(pBases, pScalars, n8, N, pRes);

@@ -45,0 +41,0 @@ const t2 = performance.now();

{
"name": "wasmcurves",
"version": "0.1.1",
"version": "0.1.2",
"description": "elliptic curves implementations in wasm",
"main": "index.js",
"scripts": {
"test": "mocha --experimental-worker",
"lint": "eslint .",
"pretest": "npm run lint",
"test": "mocha",
"build_bn128": "node tools/buildwasm_bn128.js",

@@ -9,0 +11,0 @@ "build_mnt6753": "node tools/buildwasm_mnt6753.js",

@@ -29,3 +29,2 @@ const bigInt = require("big-integer");

const f2size = f1size * 2;
const f6size = f1size * 6;
const ftsize = f1size * 12;

@@ -192,7 +191,2 @@

const pTwoInv = module.alloc([
...utils.bigInt2BytesLE( toMontgomery( bigInt(2).modInv(q)), f1size ),
...utils.bigInt2BytesLE( bigInt(0), f1size )
]);
const pBls12381Twist = module.alloc([

@@ -203,7 +197,2 @@ ...utils.bigInt2BytesLE( toMontgomery(1), f1size ),

const pTwistCoefB = module.alloc([
...utils.bigInt2BytesLE( toMontgomery("4"), f1size ),
...utils.bigInt2BytesLE( toMontgomery("4"), f1size ),
]);
function build_mulNR2() {

@@ -866,3 +855,2 @@ const f = module.addFunction(f2mPrefix + "_mulNR");

const preP = c.getLocal("ppreP");
const preQ = c.getLocal("ppreQ");

@@ -1056,5 +1044,2 @@ const coefs = c.getLocal("pCoef");

f.addCode(
// c.call(ftmPrefix + "_square", x0, r0),
// // t0 + t1*y = (z0 + z1*y)^2 = a^2

@@ -1158,4 +1143,2 @@ // tmp = z0 * z1;

f.addCode(
// c.call(ftmPrefix + "_exp", x, c.i32_const(pExponent), c.i32_const(32), res),
c.call(ftmPrefix + "_conjugate", x, inverse),

@@ -1178,3 +1161,2 @@ c.call(ftmPrefix + "_one", res),

c.block(c.loop(
// c.call(ftmPrefix + "_square", res, res),
c.call(prefix + "__cyclotomicSquare", res, res),

@@ -1543,3 +1525,2 @@ c.if(

const spy = c.i32_const(psp+f1size);
const spz = c.i32_const(psp+2*f1size);

@@ -1546,0 +1527,0 @@ const ps2p = module.alloc(f1size*2);

@@ -29,3 +29,2 @@ const bigInt = require("big-integer");

const f2size = f1size * 2;
const f6size = f1size * 6;
const ftsize = f1size * 12;

@@ -561,4 +560,2 @@

const QX = c.getLocal("pQ");
const QY = c.i32_add( c.getLocal("pQ"), c.i32_const(f2size));
const QZ = c.i32_add( c.getLocal("pQ"), c.i32_const(f2size*2));

@@ -573,3 +570,2 @@ const pR = module.alloc(f2size*3);

const cQY = c.i32_add( c.getLocal("ppreQ"), c.i32_const(f2size));
const cQZ = c.i32_add( c.getLocal("ppreQ"), c.i32_const(f2size*2));

@@ -581,5 +577,3 @@ const pQ1 = module.alloc(f2size*3);

const Q2 = c.i32_const(pQ2);
const Q2X = c.i32_const(pQ2);
const Q2Y = c.i32_const(pQ2 + f2size);
const Q2Z = c.i32_const(pQ2 + f2size*2);

@@ -1071,5 +1065,2 @@ f.addCode(

f.addCode(
// c.call(ftmPrefix + "_square", x0, r0),
// // t0 + t1*y = (z0 + z1*y)^2 = a^2

@@ -1155,3 +1146,2 @@ // tmp = z0 * z1;

const pExponentNafBytes = module.alloc(exponentNafBytes);
const pExponent = module.alloc(utils.bigInt2BytesLE(exponent, 32));

@@ -1174,4 +1164,2 @@ const f = module.addFunction(prefix+ "__cyclotomicExp_"+fnName);

f.addCode(
// c.call(ftmPrefix + "_exp", x, c.i32_const(pExponent), c.i32_const(32), res),
c.call(ftmPrefix + "_conjugate", x, inverse),

@@ -1194,3 +1182,2 @@ c.call(ftmPrefix + "_one", res),

c.block(c.loop(
// c.call(ftmPrefix + "_square", res, res),
c.call(prefix + "__cyclotomicSquare", res, res),

@@ -1197,0 +1184,0 @@ c.if(

@@ -1326,3 +1326,2 @@ /*

function buildInCurveAffine() {

@@ -1336,27 +1335,2 @@ const f = module.addFunction(prefix + "_inCurveAffine");

const x = c.getLocal("pIn");
const y = c.i32_add(c.getLocal("pIn"), n8);
const y2 = module.alloc(n8*2);
const x3b = module.alloc(n8*2);
f.addCode(
c.call(prefixField + "_square", y, y2),
c.call(prefixField + "_square", x, x3b),
c.call(prefixField + "_mul", x, x3b, x3b),
c.call(prefixField + "_add", x3b, c.i32_const(pB), x3b),
c.ret(
c.call(prefixField + "_eq", y2, x3b)
)
);
}
function buildInCurveAffine() {
const f = module.addFunction(prefix + "_inCurveAffine");
f.addParam("pIn", "i32");
f.setReturnType("i32");
const c = f.getCodeBuilder();
const x = c.getLocal("pIn");
const y = c.i32_add(c.getLocal("pIn"), c.i32_const(n8));

@@ -1363,0 +1337,0 @@

@@ -40,3 +40,2 @@ /*

const pR = module.alloc(utils.bigInt2BytesLE(bigInt.one.shiftLeft(n64*64).mod(q), n8));
const pR2 = module.alloc(utils.bigInt2BytesLE(bigInt.one.shiftLeft(n64*64).square().mod(q), n8));

@@ -135,23 +134,2 @@ const pOne = module.alloc(utils.bigInt2BytesLE(bigInt.one.shiftLeft(n64*64).mod(q), n8));

/*
function buildIsNegative() {
const f = module.addFunction(prefix+"_isNegative");
f.addParam("x", "i32");
f.setReturnType("i32");
const c = f.getCodeBuilder();
const AUX = c.i32_const(module.alloc(n8));
f.addCode(
c.call(prefix + "_fromMontgomery", c.getLocal("x"), AUX),
c.i32_and(
c.i32_load(AUX),
c.i32_const(1)
)
);
}
*/
function buildSign() {

@@ -820,4 +798,2 @@ const f = module.addFunction(prefix+"_sign");

const pnqr = module.alloc(utils.bigInt2BytesLE(_nqr.shiftLeft(n64*64).mod(q), n8));
let s2 = 0;

@@ -824,0 +800,0 @@ let _t = _minusOne;

@@ -20,4 +20,2 @@ /*

const utils = require("./utils.js");
module.exports = function buildInt(module, n64, _prefix) {

@@ -32,4 +30,2 @@

const one = module.alloc(n8, utils.bigInt2BytesLE(1, n8));
function buildCopy() {

@@ -36,0 +32,0 @@ const f = module.addFunction(prefix+"_copy");

@@ -20,3 +20,3 @@ /*

module.exports = function buildMem(module, prefix, prefixField) {
module.exports = function buildMem(module, prefix) {

@@ -23,0 +23,0 @@ function buildCopy() {

@@ -20,15 +20,8 @@ /*

const bigInt = require("big-integer");
const utils = require("./utils.js");
module.exports = function buildTestF1(module) {
const q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583");
const pR2 = module.modules.f1m.pR2;
const n8 = module.modules.f1m.n64*8;
const pR3 = module.alloc(utils.bigInt2BytesLE(bigInt.one.shiftLeft(256).square().mod(q).shiftRight(128), n8));
function buildTestF1() {

@@ -45,5 +38,3 @@ const f = module.addFunction("testF1");

f.addCode(c.block(c.loop(
// c.call("f1m_add", c.i32_const(pR2), c.i32_const(pR2), c.i32_const(pAux1)),
c.call("f1m_mul", c.i32_const(pR2), c.i32_const(pR2), c.i32_const(pAux1)),
// c.call("int_div", c.i32_const(pR2), c.i32_const(pR3), c.i32_const(pAux1), c.i32_const(0)),
c.setLocal("i", c.i32_sub(c.getLocal("i"), c.i32_const(1))),

@@ -50,0 +41,0 @@ c.br_if(1, c.i32_eqz ( c.getLocal("i") )),

@@ -20,4 +20,2 @@ /*

const bigInt = require("big-integer");
module.exports = function buildTestAddG1(module) {

@@ -24,0 +22,0 @@

const assert = require("assert");
const bigInt = require("big-integer");

@@ -12,3 +11,2 @@ module.exports = function buildTomCook(module, _prefix) {

const CHUNK_BASE_MAX = "9223372036317904896";
const CHUNK_MASK = CHUNK_BASE -1;

@@ -160,26 +158,2 @@ function load(size, c, localVar, pos) {

function buildNeg(n, sizes) {
const fnName = prefix+"_neg"+n+sizes;
if (definedFunctions[fnName]) return;
definedFunctions[fnName] = true;
const f = module.addFunction(fnName);
f.addParam("x", "i32");
f.addParam("r", "i32");
const c = f.getCodeBuilder();
for (let i=0; i<n; i++) {
f.addCode(
store(sizes[1], c, "r", i,
c.i32_sub(
c.i32_const(0),
load(sizes[0], c, "x", i)
)
)
);
}
}
function buildAdd(n, sizes) {

@@ -410,40 +384,2 @@

function buildFix(n, sizes) {
const fnName = prefix+"_fix"+n+sizes;
if (definedFunctions[fnName]) return;
definedFunctions[fnName] = true;
const f = module.addFunction(fnName);
f.addParam("x", "i32");
f.addParam("r", "i32");
f.addLocal("c", "i64");
f.addLocal("aux", "i64");
const c = f.getCodeBuilder();
f.addCode(
c.setLocal(
"c",
load(sizes[0], c, "x", 0)
),
storeAdjusting(sizes[1], c, "c", "r", "aux", 0)
);
for (let i=1; i<n; i++) {
f.addCode(
c.setLocal(
"c",
c.i64_add(
c.i64_div_s(c.getLocal("c"), c.i64_const(CHUNK_BASE)),
load(sizes[0], c, "x", i)
)
),
storeAdjusting(sizes[1], c, "c", "r", "aux", i)
);
}
}
function buildMul(n, sizes) {

@@ -593,7 +529,2 @@

buildMul(9, "sss");
/* module.exportFunction(prefix+"_divshort6");
module.exportFunction(prefix+"_mulshort6");
module.exportFunction(prefix+"_mul3");
module.exportFunction(prefix+"_mulu9");
*/
module.exportFunction(prefix+"_mul9sss", prefix+"_mul9");

@@ -600,0 +531,0 @@

@@ -20,3 +20,2 @@ /*

/* globals WebAssembly */
const bigInt = require("big-integer");

@@ -23,0 +22,0 @@ const ModuleBuilder = require("wasmbuilder").ModuleBuilder;

@@ -49,4 +49,4 @@ /*

return true;
}
};

@@ -101,6 +101,8 @@ const assert = require("assert");

//eslint-disable-next-line no-unused-vars
function printF1(s, p) {
console.log(s, " " + ns(p))
console.log(s, " " + ns(p));
}
//eslint-disable-next-line no-unused-vars
function printF2(s, p) {

@@ -110,2 +112,3 @@ console.log(s + " Fq2(" + ns(p) + " + " + ns(p+n8q) +"*u " );

//eslint-disable-next-line no-unused-vars
function printF6(s, p) {

@@ -117,2 +120,3 @@ console.log(s + " [Fq2(\n" + ns(p) + " +\n " + ns(p+n8q) +"*u],[" );

//eslint-disable-next-line no-unused-vars
function printF12(s, p) {

@@ -127,2 +131,3 @@ console.log(s + " [ [Fq2(\n" + ns(p) + " +\n " + ns(p+n8q) +"*u],[" );

//eslint-disable-next-line no-unused-vars
function printG1(s, p) {

@@ -132,2 +137,3 @@ console.log(s + " G1(" + ns(p) + " , " + ns(p+n8q) + " , " + ns(p+n8q*2) + ")" );

//eslint-disable-next-line no-unused-vars
function printG2(s, p) {

@@ -605,5 +611,2 @@ console.log(s + " (G2):");

const pA = pb.alloc(n8q*12);
const pAf = pb.alloc(n8q*12);
const pAInverse = pb.alloc(n8q*12);
const pUnitary = pb.alloc(n8q*12);
const pBeta = pb.alloc(n8q*12);

@@ -610,0 +613,0 @@ const pCycSquare = pb.alloc(n8q*12);

@@ -53,2 +53,3 @@ const assert = require("assert");

//eslint-disable-next-line no-unused-vars
function printF1(s, p) {

@@ -58,2 +59,3 @@ console.log(s, " " + ns(p));

//eslint-disable-next-line no-unused-vars
function printF2(s, p) {

@@ -63,2 +65,3 @@ console.log(s + " Fq2(" + ns(p) + " + " + ns(p+32) +"*u " );

//eslint-disable-next-line no-unused-vars
function printF6(s, p) {

@@ -70,2 +73,3 @@ console.log(s + " [Fq2(\n" + ns(p) + " +\n " + ns(p+32) +"*u],[" );

//eslint-disable-next-line no-unused-vars
function printF12(s, p) {

@@ -80,2 +84,3 @@ console.log(s + " [ [Fq2(\n" + ns(p) + " +\n " + ns(p+32) +"*u],[" );

//eslint-disable-next-line no-unused-vars
function printG1(s, p) {

@@ -85,2 +90,3 @@ console.log(s + " G1(" + ns(p) + " , " + ns(p+n8) + " , " + ns(p+n8*2) + ")" );

//eslint-disable-next-line no-unused-vars
function printG2(s, p) {

@@ -370,5 +376,2 @@ console.log(s + " (G2):");

const pA = pb.alloc(32*12);
const pAf = pb.alloc(32*12);
const pAInverse = pb.alloc(32*12);
const pUnitary = pb.alloc(32*12);
const pBeta = pb.alloc(32*12);

@@ -375,0 +378,0 @@ const pCycSquare = pb.alloc(32*12);

@@ -259,6 +259,4 @@ const assert = require("assert");

f1.int_mul(pA, pB, pC);
const c = f1.getInt2(pC);
f1.f1m_mReduct(pC, pD);
const d = f1.getInt(pD);

@@ -751,3 +749,2 @@ const r = bigInt.one.shiftLeft(256).mod(q);

buildTest2(module, "f1m_mul");
// buildTest(module, "f1m_mulOld");
}, 32);

@@ -754,0 +751,0 @@

@@ -18,3 +18,2 @@ const assert = require("assert");

buildTest2(module, "int_mul");
// buildTest(module, "int_mulOld");
}, 32);

@@ -21,0 +20,0 @@ });

@@ -9,5 +9,2 @@ const assert = require("assert");

const helpers = require("./helpers/helpers.js");
describe("Basic tests for MNT6753", function () {

@@ -90,6 +87,8 @@ let pb;

//eslint-disable-next-line no-unused-vars
function printF1(s, p) {
console.log(s, " " + ns(p))
console.log(s, " " + ns(p));
}
//eslint-disable-next-line no-unused-vars
function printF3(s, p) {

@@ -99,2 +98,3 @@ console.log(s + " Fq3(" + ns(p) + " + " + ns(p+96) +"*u + "+ ns(p+96*2)+ "*u^2 )" );

//eslint-disable-next-line no-unused-vars
function printF6(s, p) {

@@ -379,4 +379,3 @@ console.log(s + " [Fq3(\n" + ns(p) + " +\n " + ns(p+96) +"*u +\n"+ ns(p+96*2)+ "*u^2)\n],[" );

let o;
// let o;
// o = pPreQ + 96*3*5;

@@ -459,3 +458,2 @@ // for (let i=0; i<376; i++) {

const ps = pb.alloc(96);
const pOne = pb.alloc(96*6);
pb.set(ps, bigInt("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16));

@@ -462,0 +460,0 @@ const pRes1 = pb.alloc(96*6);

@@ -104,5 +104,2 @@ const assert = require("assert");

// const A=bigInt(0).add(bigInt(0).shiftLeft(29*3).add(bigInt(bigInt("7FFFFFFFFFFFFFFFFFFFFF", 16)).shiftLeft(29*6)));
// const B=bigInt(0).add(bigInt(0).shiftLeft(29*3).add(bigInt(bigInt("7FFFFFFFFFFFFFFFFFFFFF", 16)).shiftLeft(29*6)));
const A = bigInt("3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16);

@@ -141,8 +138,8 @@ const B = bigInt("3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16);

// console.log(values[i].toString(16));
// console.log(values[j].toString(16));
// console.log(values[i].toString(16));
// console.log(values[j].toString(16));
pbTC.tomcook_mul9(pA, pB, pC);
c = pbTC.get(pC, 1, 72);
// console.log("Result: " + c.toString(16));
// console.log("Refere: " + values[i].times(values[j]).toString(16));
// console.log("Result: " + c.toString(16));
// console.log("Refere: " + values[i].times(values[j]).toString(16));
assert(c.equals(values[i].times(values[j])));

@@ -175,3 +172,2 @@ }

let start, end, time;
// const A = bigInt.one.shiftLeft(29*3).minus(1);
const A = bigInt.one.shiftLeft(254).minus(1);

@@ -181,3 +177,2 @@ const B = bigInt.one.shiftLeft(254).minus(1);

console.log(A.toString(16));
// const B = bigInt.zero.minus(bigInt.one.shiftLeft(29*3).minus(1));

@@ -184,0 +179,0 @@ const pA = pbTC.set(pbTC.alloc(9*4), A, 9*4);

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc