1.0.3 • Published 12 months ago

crypto-toys v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

crypto-toys

Library for computing Discrete Logarithm, Elliptic Curve and Pairings toy examples.

Crypto-Toys may be either installed as a library, or else one may clone the project, build it and run its command line tool.


Requirements

Node.js v14 or later


Crypto-Toys Library

To add crypto-toys to a node.js project:

npm i crypto-toys

Next import the library using one of these methods:

const toys = require("crypto-toys")
import * as toys from "crypto-toys"

The most important configuration structure to be aware of is ECurve, defined as follows:

interface ECurve {
    fieldN: number;
    coeffA?: number;
    coeffB?: number;
    rorder?: number;
    iSQR?: number;
}

These are the parameters defining the field, EC and sub-group order over which computations are to be computed.


Toy Examples from Literature

Example 1 - Weil Pairing Computation

Source: On The Implementation Of Pairing-Based Cryptosystems - Ben Lynn (page 53 to 55)

Computing e(P, Q) given additional points R and S.

const toys = require("crypto-toys")

// Prepare curve parameters
let ec = {
        fieldN: 59,
        coeffA: 1,
        coeffB: 0,
        rorder: 5
    }

//Points for which the example is to be worked
let P = [[25,0], [30,0]]
let Q = [[(59-25),0], [0,30]]
let R = [[40,0], [54,0]]
let S = [[48,55], [28,51]]

//Pairing computation
toys.weilPairing(ec, P, Q, R, S, true)

//Expected Result: e(P, Q) = 46 + 56i

Example 2 - Weil Pairing Computation

Source: Pairings for beginners - Craig Costello (page 69 to 70)

Computing e(P, Q) given additional points R and S.

const toys = require("crypto-toys")

// Prepare curve parameters
let ec = {
        fieldN: 23,
        coeffA: -1,
        coeffB: 0,
        rorder: 3
    }

//Points for which the example is to be worked
let P = [[2,0], [11,0]]
let Q = [[21,0], [0,12]]
let R = [[0,17], [21,2]]
let S = [[18,10], [13,13]]

//Pairing computation
toys.weilPairing(ec, P, Q, R, S, true)

//Expected Result: e(P, Q) = 11 + 15i

Example 3 - Tate Pairing Computation

Source: Pairings for beginners - Craig Costello (page 74)

Computing e(P, Q) given additional point R.

const toys = require("crypto-toys")

// Prepare curve parameters
let ec = {
        fieldN: 19, 
        coeffA: 14, 
        coeffB: 3, 
        rorder: 5
    }


//Points for which the example is to be worked
let P = [[17,0], [9, 0]]
let Q = [[16,0], [0,16]]
let R = [[18,2], [14,5]]

//Pairing computation
toys.tatePairing(ec, P, Q, R, true)

//Expected Result: e(P, Q) = 2 + 15i

Clone and Build

git clone https://github.com/kaxxa123/crypto-toys.git
cd crypto-toys
npm install
npm run build

Crypto-Toys Command-Line Tool

After building crypto-toys, check all possible command line operations by running:

# List of all commands from npm
npm run help

# List of all commands from node
node ./build/src/toyscli --help

# Help for individual commands
node ./build/src/toyscli ecipoints --help

For each command, an npm script is available that allows to quickly see the command in action without entering any parameters. For example, to quickly see ecipoints in action:

npm run ecipoints

From here one can copy the command line used to generate the output and customize it to the required EC. For example (at the time of writing) the command generated for ecipoints is:

node ./build/src/toyscli.js ecipoints --fieldN 11 --coeffA 4 --coeffB 3

In this case fieldN is the integer field over which the EC operation is being computed. Whereas coeffA and coeffB are the A and B coefficients in the EC formula: y2 = x3 + Ax + B

For complete details on the parameters check the help for each command.


PLONK by Crypto-Toys

See details on how to run PLONK setup using Crypto-Toys.


References

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago