Skip to content

Commit

Permalink
(experimental) support secp384r1
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Feb 26, 2019
1 parent 9b25d9e commit 085a8c1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
20 changes: 20 additions & 0 deletions mcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,29 @@
exports.BN462 = 3
exports.BN_SNARK1 = 4
exports.BLS12_381 = 5

exports.SECP224K1 = 101
exports.SECP256K1 = 102
exports.SECP384R1 = 103
exports.NIST_P192 = 105
exports.NIST_P224 = 106
exports.NIST_P256 = 107
/* eslint-disable */
const getUnitSize = curveType => {
switch (curveType) {
case exports.BN254:
case exports.BN_SNARK1:
case exports.SECP224K1:
case exports.SECP256K1:
case exports.NIST_P192:
case exports.NIST_P224:
case exports.NIST_P256:
return 4; /* use mcl_c.js */
case exports.BN381_1:
case exports.BN381_2:
case exports.BLS12_381:
case exports.BN462:
case exports.SECP384R1:
return 8; /* use mcl_c512.js */
default:
throw new Error(`QQQ bad curveType=${curveType}`)
Expand Down Expand Up @@ -429,6 +442,13 @@
r.deserializeHexStr(s)
return r
}
exports.getBasePointG1 = () => {
const x = new exports.G1()
const xPos = x._alloc()
mod._mclBnG1_getBasePoint(xPos)
x._saveAndFree(xPos)
return x
}
exports.G2 = class extends Common {
constructor () {
super(MCLBN_G2_SIZE)
Expand Down
2 changes: 1 addition & 1 deletion mcl_c.js

Large diffs are not rendered by default.

Binary file modified mcl_c.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion mcl_c512.js

Large diffs are not rendered by default.

Binary file modified mcl_c512.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mcl-wasm",
"version": "0.3.0",
"version": "0.3.1",
"description": "mcl ; A portable and fast pairing-based cryptography library for Node.js by WebAssembly",
"main": "mcl.js",
"scripts": {
Expand Down
32 changes: 32 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,44 @@ const curveTest = (curveType, name) => {
})
}

const stdCurveTest = (curveType, name) => {
mcl.init(curveType)
.then(() => {
try {
console.log(`name=${name}`)
arithTest()
} catch (e) {
console.log(`TEST FAIL ${e}`)
assert(false)
}
})
}

function arithTest () {
const P = mcl.getBasePointG1()
console.log(`basePoint=${P.getStr(16)}`)
let Q = mcl.add(P, P) // x2
Q = mcl.add(Q, Q) // x4
Q = mcl.add(Q, Q) // x8
Q = mcl.add(Q, P) // x9
const r = new mcl.Fr()
r.setStr('9')
const R = mcl.mul(P, r)
assert(R.isEqual(Q))
}

async function curveTestAll () {
// can't parallel
await curveTest(mcl.BN254, 'BN254')
await curveTest(mcl.BN381_1, 'BN381_1')
await curveTest(mcl.BLS12_381, 'BLS12_381')
await curveTest(mcl.BN462, 'BN462')

await stdCurveTest(mcl.SECP224K1, 'secp224k1')
await stdCurveTest(mcl.SECP256K1, 'secp256k1')
await stdCurveTest(mcl.SECP384R1, 'secp384r1')
await stdCurveTest(mcl.NIST_P192, 'NIST_P192')
await stdCurveTest(mcl.NIST_P256, 'NIST_P256')
}

curveTestAll()
Expand Down

0 comments on commit 085a8c1

Please sign in to comment.