diff --git a/.eslintrc.js b/.eslintrc.js index 2f45ad9..ce75c5c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,4 @@ module.exports = { - "plugins": [ - "mocha" - ], "env": { "es6": true, "node": true, @@ -27,7 +24,6 @@ module.exports = { "semi": [ "error", "always" - ], - "mocha/no-exclusive-tests": "error" + ] } }; diff --git a/COPYING b/COPYING index 9cecc1d..9dc9bca 100644 --- a/COPYING +++ b/COPYING @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2020 0Kims Association Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. diff --git a/TUTORIAL.md b/TUTORIAL.md index 72fe63a..ab20464 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -6,7 +6,7 @@ This tutorial will guide you in creating your first Zero Knowledge zkSnark circu ### 1.1 Pre-requisites -If you don't have it installed yet, you need to install `Node.js`. +If you don't have it installed yet, you need to install `Node.js`. The last stable version of `Node.js` (or 8.12.0) works just fine, but if you install the latest current version `Node.js` (10.12.0) you will see a significant increase in performance. This is because last versions of node includes Big Integer Libraries nativelly. The `snarkjs` library makes use of this feature if available, and this improves the performance x10 (!). @@ -16,6 +16,7 @@ Run: ```sh npm install -g circom +npm install -g circom_runtime npm install -g snarkjs ``` @@ -42,7 +43,7 @@ template Multiplier() { signal private input a; signal private input b; signal output c; - + c <== a*b; } @@ -62,10 +63,12 @@ Note: When compiling a circuit, a component named `main` must always exist. We are now ready to compile the circuit. Run the following command: ```sh -circom circuit.circom -o circuit.json +circom circuit.circom --r1cs --wasm --sym ``` -to compile the circuit to a file named `circuit.json` +The -r optin will generate `circuit.r1cs` ( The r1cs constraint system of the circuit in binary format) +The -w will generate `circuit.wasm` (The wasm code to generate the witness) +The -s will generate `circuit.sym` (This is the symbols file, required for debugging or if you want to print the constraint system in an annotated mode) ## 3. Taking the compiled circuit to *snarkjs* @@ -74,7 +77,7 @@ Now that the circuit is compiled, we will continue with `snarkjs`. Please note that you can always access the help of `snarkjs` by typing: ```sh -snarkjs --help +snarkjs --help ``` ### 3.1 View information and stats regarding a circuit @@ -82,13 +85,13 @@ snarkjs --help To show general statistics of this circuit, you can run: ```sh -snarkjs info -c circuit.json +snarkjs info -r circuit.r1cs ``` You can also print the constraints of the circuit by running: ```sh -snarkjs printconstraints -c circuit.json +snarkjs printconstraints -r circuit.r1cs -s circuit.sym ``` @@ -98,10 +101,10 @@ snarkjs printconstraints -c circuit.json Ok, let's run a setup for our circuit: ```sh -snarkjs setup +snarkjs setup ``` -> By default `snarkjs` will look for and use `circuit.json`. You can always specify a different circuit file by adding `-c ` +> By default `snarkjs` will look for and use `circuit.r1cs`. You can always specify a different circuit file by adding `-r ` The output of the setup will in the form of 2 files: `proving_key.json` and `verification_key.json` @@ -109,13 +112,13 @@ The output of the setup will in the form of 2 files: `proving_key.json` and `ver Before creating any proof, we need to calculate all the signals of the circuit that match (all) the constrains of the circuit. -`snarkjs` calculates those for you. You need to provide a file with the inputs and it will execute the circuit and calculate all the intermediate signals and the output. This set of signals is the *witness*. +`circom` generates a wasm module that calculates those for you. You need to provide a file with the inputs and it will execute the circuit and calculate all the intermediate signals and the output. This set of signals is the *witness*. The zero knowledge proofs prove that you know a set of signals (witness) that match all the constraints, without revealing any of the signals except the public inputs plus the outputs. -For example, imagine you want to prove you are able to factor 33. It means that you know two numbers `a` and `b` and when you multiply them, it results in 33. +For example, imagine you want to prove you are able to factor 33. It means that you know two numbers `a` and `b` and when you multiply them, it results in 33. -> Of course you can always use one and the same number as `a` and `b`. We will deal with this problem later. +> Of course you can always use one and the same number as `a` or `b`. We will deal with this problem later. So you want to prove that you know 3 and 11. @@ -128,9 +131,13 @@ Let's create a file named `input.json` Now let's calculate the witness: ```sh -snarkjs calculatewitness +snarkjs --wasm circuit.wasm --input input.json --witness witness.json ``` +`calcwit` is part of the circom_runtime package and it's just a wrapper in JS to call the wasm module. + +You can use `circom_runtime` from your own project to calulate the witness. + You may want to take a look at `witness.json` file with all the signals. ### Create the proof @@ -214,20 +221,20 @@ template Multiplier() { signal output c; signal inva; signal invb; - + inva <-- 1/(a-1); (a-1)*inva === 1; - + invb <-- 1/(b-1); - (b-1)*invb === 1; - + (b-1)*invb === 1; + c <== a*b; } component main = Multiplier(); ``` -A nice thing of the circom language is that you can split a <== into two independent actions: <-- and === +A nice thing of the circom language is that you can split a <== into two independent actions: <-- and === The <-- and --> operators assign a value to a signal without creating any constraints. diff --git a/cli.js b/cli.js index 17651fe..11be768 100755 --- a/cli.js +++ b/cli.js @@ -23,6 +23,7 @@ const fs = require("fs"); const path = require("path"); +const bigInt = require("big-integer"); const compiler = require("./src/compiler"); @@ -37,6 +38,7 @@ const argv = require("yargs") .alias("t", "wat") .alias("s", "sym") .alias("r", "r1cs") + .alias("p", "prime") .alias("n", "newThreadTemplates") .help("h") .alias("h", "help") @@ -50,10 +52,6 @@ const argv = require("yargs") type: "boolean", description: "Do not optimize constraints" }) - .option("sanityCheck", { - type: "boolean", - description: "Add sanity check code" - }) .epilogue(`Copyright (C) 2018 0kims association This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it @@ -84,6 +82,8 @@ const options = {}; options.reduceConstraints = !argv.fast; options.verbose = argv.verbose || false; options.sanityCheck = argv.sanitycheck; +options.prime = argv.prime || bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); + if (argv.csource) { options.cSourceWriteStream = fs.createWriteStream(cSourceName); } diff --git a/doc/r1cs_bin_format.md b/doc/r1cs_bin_format.md index fbe3ab0..813af4b 100644 --- a/doc/r1cs_bin_format.md +++ b/doc/r1cs_bin_format.md @@ -152,114 +152,93 @@ Size in bytes of the section Section Type: 0x01 ```` - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ - ┃ 4 │ FieldDefSize ┃ FieldDef ┃ field Id - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━━━━┳━━━━━━━━━━━━━━━━━┓ - ┃ 4 │ 00 00 00 00 ┃ bigInt Format + ┃ 4 │ 20 00 00 00 ┃ Field Size in bytes (fs) ┗━━━━┻━━━━━━━━━━━━━━━━━┛ + ┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ fs │ 010000f0 93f5e143 9170b979 48e83328 5d588181 b64550b8 29a031e1 724e6430 ┃ Prime size + ┗━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━━━━┳━━━━━━━━━━━━━━━━━┓ - ┃ 4 │ is ┃ Id size ( Normally 4 (32bits)) + ┃ 32 │ 01 00 00 00 ┃ nWires ┗━━━━┻━━━━━━━━━━━━━━━━━┛ ┏━━━━┳━━━━━━━━━━━━━━━━━┓ - ┃ is │ 01 00 00 00 ┃ nWires + ┃ 32 │ 01 00 00 00 ┃ nPubOut ┗━━━━┻━━━━━━━━━━━━━━━━━┛ ┏━━━━┳━━━━━━━━━━━━━━━━━┓ - ┃ is │ 01 00 00 00 ┃ nPubOut + ┃ 32 │ 01 00 00 00 ┃ nPubIn ┗━━━━┻━━━━━━━━━━━━━━━━━┛ ┏━━━━┳━━━━━━━━━━━━━━━━━┓ - ┃ is │ 01 00 00 00 ┃ nPubIn + ┃ 32 │ 01 00 00 00 ┃ nPrvIn ┗━━━━┻━━━━━━━━━━━━━━━━━┛ + ┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 64 │ 01 00 00 00 00 00 00 00 ┃ nLabels + ┗━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━━━━┳━━━━━━━━━━━━━━━━━┓ - ┃ is │ 01 00 00 00 ┃ nPrvIn - ┗━━━━┻━━━━━━━━━━━━━━━━━┛ - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ - ┃ is │ 01 00 00 00 ┃ nLabels - ┗━━━━┻━━━━━━━━━━━━━━━━━┛ - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ - ┃ is │ 01 00 00 00 ┃ mConstraints + ┃ 32 │ 01 00 00 00 ┃ mConstraints ┗━━━━┻━━━━━━━━━━━━━━━━━┛ ```` -#### fieldDefSize +#### field Size (fs) Size: 4 bytes Format: Little-Endian -Size of the field Definition +Size in bytes of a field element. Mast be a multiple of 8. Example: ``` 0x00 0x0 0x00 0x00 ``` -#### fieldDef - -Field dfinition the first 4 bytes are the type in LE. 0x0000001 Ar prime fields. - -For the prime fields, the next bytes are the prime in variable length LE base 256 format. - -NOTE: This number is independent of the bigInt Format defined next - -#### bigInt Format +#### Prime -Size: 4 bytes -Format: Little-Endian - -0 Means that the Big Int are variable size LE. -That is the First byte indicates the size and the remaining bytes are the number in little enfian (LSB first) base 256. - -Numbers from 1 to 16383 are fixed size Litle endian format base 256. +Prime Number of the field Example: ``` -0x00 0x00 0x00 0x00 +0x010000f0_93f5e143_9170b979_48e83328_5d588181_b64550b8_29a031e1_724e6430 ``` -#### Id Size (is) - -Size: 4 bytes -Format: Little-Endian - -Size of the identifiers for wires, labels and constraints. In small circuits this is going to be 4 (32 bits) -but can be increaset to 8 for bigger circiuits. - -The only possible numbers are 4 or 8 - - #### Number of wires -Size: `is` bytes +Size: 4 bytes Format: Little-Endian Total Number of wires including ONE signal (Index 0). #### Number of public outputs -Size: `is` bytes +Size: 4 bytes Format: Little-Endian Total Number of wires public output wires. They should be starting at idx 1 #### Number of public inputs -Size: `is` bytes +Size: 4 bytes Format: Little-Endian Total Number of wires public input wires. They should be starting just after the public output #### Number of private inputs -Size: `is` bytes +Size: 4 bytes +Format: Little-Endian + +Total Number of wires private input wires. They should be starting just after the public inputs + +#### Number of Labels + +Size: 8 bytes Format: Little-Endian Total Number of wires private input wires. They should be starting just after the public inputs #### Number of constraints (m) -Size: `ìs` bytes +Size: 4 bytes Format: Little-Endian Total Number of constraints @@ -269,115 +248,115 @@ Total Number of constraints Section Type: 0x02 ```` - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ ╲ - ┃ is │ nA ┃ ╲ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ╲ - ┃ is │ wireId_1 ┃ V │ a_{0,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ - ┃ is │ wireId_2 ┃ V │ a_{0,wireId_2} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ... ... │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nA ┃ V │ a_{0,wireId_nA} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ nB ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_1 ┃ V │ b_{0,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ ╲ - ┃ is │ wireId_2 ┃ V │ b_{0,wireId_2} ┃ ╲ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ Constraint_0 - ... ... ╱ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nB ┃ V │ b_{0,wireId_nB} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ nC ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_1 ┃ V │ c_{0,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ - ┃ is │ wireId_2 ┃ V │ c_{0,wireId_2} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ... ... │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nC ┃ V │ c_{0,wireId_nC} ┃ ╱ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ - ╱ - - - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ ╲ - ┃ is │ nA ┃ ╲ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ╲ - ┃ is │ wireId_1 ┃ V │ a_{1,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ - ┃ is │ wireId_2 ┃ V │ a_{1,wireId_2} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ... ... │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nA ┃ V │ a_{1,wireId_nA} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ nB ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_1 ┃ V │ b_{1,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ ╲ - ┃ is │ wireId_2 ┃ V │ b_{1,wireId_2} ┃ ╲ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ Constraint_1 - ... ... ╱ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nB ┃ V │ b_{1,wireId_nB} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ nC ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_1 ┃ V │ c_{1,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ - ┃ is │ wireId_2 ┃ V │ c_{1,wireId_2} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ... ... │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nC ┃ V │ c_{1,wireId_nC} ┃ ╱ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ - ╱ + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ ╲ + ┃ 32 │ nA ┃ ╲ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ╲ + ┃ 32 │ wireId_1 ┃ fs │ a_{0,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ + ┃ 32 │ wireId_2 ┃ fs │ a_{0,wireId_2} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ... ... │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nA ┃ fs │ a_{0,wireId_nA} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ nB ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_1 ┃ fs │ b_{0,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ ╲ + ┃ 32 │ wireId_2 ┃ fs │ b_{0,wireId_2} ┃ ╲ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ Constraint_0 + ... ... ╱ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nB ┃ fs │ b_{0,wireId_nB} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ nC ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_1 ┃ fs │ c_{0,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ + ┃ 32 │ wireId_2 ┃ fs │ c_{0,wireId_2} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ... ... │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nC ┃ fs │ c_{0,wireId_nC} ┃ ╱ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ + ╱ + + + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ ╲ + ┃ 32 │ nA ┃ ╲ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ╲ + ┃ 32 │ wireId_1 ┃ fs │ a_{1,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ + ┃ 32 │ wireId_2 ┃ fs │ a_{1,wireId_2} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ... ... │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nA ┃ fs │ a_{1,wireId_nA} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ nB ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_1 ┃ fs │ b_{1,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ ╲ + ┃ 32 │ wireId_2 ┃ fs │ b_{1,wireId_2} ┃ ╲ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ Constraint_1 + ... ... ╱ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nB ┃ fs │ b_{1,wireId_nB} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ nC ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_1 ┃ fs │ c_{1,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ + ┃ 32 │ wireId_2 ┃ fs │ c_{1,wireId_2} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ... ... │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nC ┃ fs │ c_{1,wireId_nC} ┃ ╱ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ + ╱ ... ... ... - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ ╲ - ┃ is │ nA ┃ ╲ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ╲ - ┃ is │ wireId_1 ┃ V │ a_{m-1,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ - ┃ is │ wireId_2 ┃ V │ a_{m-1,wireId_2} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ... ... │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nA ┃ V │ a_{m-1,wireId_nA} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ nB ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_1 ┃ V │ b_{m-1,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ ╲ - ┃ is │ wireId_2 ┃ V │ b_{m-1,wireId_2} ┃ ╲ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ Constraint_{m-1} - ... ... ╱ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nB ┃ V │ b_{m-1,wireId_nB} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ nC ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_1 ┃ V │ c_{m-1,wireId_1} ┃ │ - ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ - ┃ is │ wireId_2 ┃ V │ c_{m-1,wireId_2} ┃ │ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ - ... ... │ - ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ - ┃ is │ wireId_nC ┃ V │ c_{m-1,wireId_nC} ┃ ╱ - ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ - ╱ ╱ + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ ╲ + ┃ 32 │ nA ┃ ╲ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ╲ + ┃ 32 │ wireId_1 ┃ fs │ a_{m-1,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ + ┃ 32 │ wireId_2 ┃ fs │ a_{m-1,wireId_2} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ... ... │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nA ┃ fs │ a_{m-1,wireId_nA} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ nB ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_1 ┃ fs │ b_{m-1,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ ╲ + ┃ 32 │ wireId_2 ┃ fs │ b_{m-1,wireId_2} ┃ ╲ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ Constraint_{m-1} + ... ... ╱ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nB ┃ fs │ b_{m-1,wireId_nB} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ nC ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_1 ┃ fs │ c_{m-1,wireId_1} ┃ │ + ┣━━━━╋━━━━━━━━━━━━━━━━━╋━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ │ + ┃ 32 │ wireId_2 ┃ fs │ c_{m-1,wireId_2} ┃ │ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ │ + ... ... │ + ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ │ + ┃ 32 │ wireId_nC ┃ fs │ c_{m-1,wireId_nC} ┃ ╱ + ┗━━━━┻━━━━━━━━━━━━━━━━━┻━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ ╱ + ╱ ```` @@ -401,7 +380,7 @@ $$ #### Number of nonZero Factors -Size: `ìs` bytes +Size: 4 bytes Format: Little-Endian Total number of non Zero factors in the linear compination. @@ -414,16 +393,14 @@ For each factor we have the index of the factor and the value of the factor. #### WireId of the factor -Size: `is` bytes +Size: 4 bytes Format: Little-Endian WireId of the nonZero Factor #### Value of the factor -The first byte indicate the length N in bytes of the number in the upcoming bytes. - -The next N bytes represent the value in Little Endian format. +This is the factor that multiplies the associated wire in the linear convination. For example, to represent the linear combination: @@ -436,13 +413,13 @@ The linear combination would be represented as: ```` ┏━━━━━━━━━━━━━━━━━┓ ┃ 03 00 00 00 ┃ - ┣━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━┓ - ┃ 04 00 00 00 ┃ 01 05 ┃ - ┣━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━┫ - ┃ 05 00 00 00 ┃ 01 08 ┃ - ┣━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━┫ - ┃ 76 03 00 00 ┃ 02 04 01 ┃ - ┗━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━┛ + ┣━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 04 00 00 00 ┃ 05000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 05 00 00 00 ┃ 08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 76 03 00 00 ┃ 04010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ```` @@ -452,7 +429,7 @@ Section Type: 0x03 ```` ┏━━┳━━━━━━━━━━━━━━━━━━━┳━━┳━━━━━━━━━━━━━━━━━━━┓ ┏━━┳━━━━━━━━━━━━━━━━━━━┓ -┃is│ labelId of Wire_0 ┃is│ labelId of Wire_1 ┃ ... ┃is│ labelId of Wire_n ┃ +┃64│ labelId of Wire_0 ┃64│ labelId of Wire_1 ┃ ... ┃64│ labelId of Wire_n ┃ ┗━━┻━━━━━━━━━━━━━━━━━━━┻━━┻━━━━━━━━━━━━━━━━━━━┛ ┗━━┻━━━━━━━━━━━━━━━━━━━┛ ```` @@ -500,176 +477,170 @@ $$ The format will be: ```` - ┏━━━━━━━━━━━━━━┓ - ┃ 72 31 63 77 ┃ Magic - ┣━━━━━━━━━━━━━━┫ - ┃ 01 00 00 00 ┃ Version - ┣━━━━━━━━━━━━━━┫ - ┃ 03 00 00 00 ┃ nSections - ┗━━━━━━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓ - ┃ 01 00 00 00 ┃ 49 00 00 00 ┃ SectionType: Header - ┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓ - ┃ 25 00 00 00 ┃ 10 00 00 00 ┃ FieldDefSize FieldDef - ┣━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ - ┃ 20 010000f0 93f5e143 9170b979 48e83328 5d588181 b64550b8 29a031e1 724e6430┃ - ┣━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ - ┃ 00 00 00 00 ┃ Big Int format - ┣━━━━━━━━━━━━━━┫ - ┃ 04 00 00 00 ┃ Id Size - ┣━━━━━━━━━━━━━━┫ - ┃ 07 00 00 00 ┃ # of wires - ┣━━━━━━━━━━━━━━┫ - ┃ 01 00 00 00 ┃ # Public Outs - ┣━━━━━━━━━━━━━━┫ - ┃ 02 00 00 00 ┃ # Public Ins - ┣━━━━━━━━━━━━━━┫ - ┃ 03 00 00 00 ┃ # Private Ins - ┣━━━━━━━━━━━━━━┫ - ┃ e8 03 00 00 ┃ # Labels - ┣━━━━━━━━━━━━━━┫ - ┃ 03 00 00 00 ┃ # Constraints - ┗━━━━━━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓ - ┃ 02 00 00 00 ┃ 8b 00 00 00 ┃ SectionType: Constraints - ┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┓ Constraint 0: (3w_5 + 8w_6) * (2w_0 + 20w_2 + 12w_3) - (5w_0 + 7w_2) = 0 - ┃ 02 00 00 00 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━┓ - ┃ 05 00 00 00 ┃ 01 03 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━┫ - ┃ 06 00 00 00 ┃ 01 08 ┃ - ┗━━━━━━━━━━━━━━┻━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┓ - ┃ 03 00 00 00 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━┓ - ┃ 00 00 00 00 ┃ 01 02 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━┫ - ┃ 02 00 00 00 ┃ 01 14 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━┫ - ┃ 03 00 00 00 ┃ 01 0C ┃ - ┗━━━━━━━━━━━━━━┻━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┓ - ┃ 02 00 00 00 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━┓ - ┃ 00 00 00 00 ┃ 01 05 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━┫ - ┃ 02 00 00 00 ┃ 01 07 ┃ - ┗━━━━━━━━━━━━━━┻━━━━━━━━┛ - - ┏━━━━━━━━━━━━━━┓ Constraint 1: (4w_1 + 8w_4 + 3w_5) * (6w_6 + 44w_3) = 0 - ┃ 03 00 00 00 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┓ - ┃ 01 00 00 00 ┃ 01 04 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┫ - ┃ 04 00 00 00 ┃ 01 08 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┫ - ┃ 05 00 00 00 ┃ 01 03 ┃ - ┗━━━━━━━━━━━━━━┻━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┓ - ┃ 02 00 00 00 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┓ - ┃ 03 00 00 00 ┃ 01 2C ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┫ - ┃ 06 00 00 00 ┃ 01 06 ┃ - ┗━━━━━━━━━━━━━━┻━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┓ - ┃ 00 00 00 00 ┃ - ┗━━━━━━━━━━━━━━┛ - - ┏━━━━━━━━━━━━━━┓ Constraint 2: (4w_6) * (6w_0 + 5w_3 + 11w_2) - (600w_6) = 0 - ┃ 01 00 00 00 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┓ - ┃ 06 00 00 00 ┃ 01 04 ┃ - ┗━━━━━━━━━━━━━━┻━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┓ - ┃ 03 00 00 00 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┓ - ┃ 00 00 00 00 ┃ 01 06 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┫ - ┃ 02 00 00 00 ┃ 01 0B ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━┫ - ┃ 03 00 00 00 ┃ 01 05 ┃ - ┗━━━━━━━━━━━━━━┻━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┓ - ┃ 01 00 00 00 ┃ - ┣━━━━━━━━━━━━━━╋━━━━━━━━━━━━━┓ - ┃ 06 00 00 00 ┃ 02 58 02 ┃ - ┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛ - - ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓ - ┃ 03 00 00 00 ┃ 1c 00 00 00 ┃ Wire to Label Map - ┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛ - ┏━━━━━━━━━━━━━━┓ - ┃ 00 00 00 00 ┃ - ┣━━━━━━━━━━━━━━┫ - ┃ 03 00 00 00 ┃ - ┣━━━━━━━━━━━━━━┫ - ┃ 0a 00 00 00 ┃ - ┣━━━━━━━━━━━━━━┫ - ┃ 0b 00 00 00 ┃ - ┣━━━━━━━━━━━━━━┫ - ┃ 0c 00 00 00 ┃ - ┣━━━━━━━━━━━━━━┫ - ┃ 0f 00 00 00 ┃ - ┣━━━━━━━━━━━━━━┫ - ┃ 44 01 00 00 ┃ - ┗━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ + ┃ 72316377 ┃ Magic + ┣━━━━━━━━━━┫ + ┃ 01000000 ┃ Version + ┣━━━━━━━━━━┫ + ┃ 03000000 ┃ nSections + ┗━━━━━━━━━━┛ + ┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓ + ┃ 01000000 ┃ 40000000 00000000 ┃ SectionType: Header + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ + ┃ 20000000 ┃ Field Size + ┣━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 010000f0 93f5e143 9170b979 48e83328 5d588181 b64550b8 29a031e1 724e6430 ┃ + ┣━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + ┃ 07000000 ┃ # of wires + ┣━━━━━━━━━━┫ + ┃ 01000000 ┃ # Public Outs + ┣━━━━━━━━━━┫ + ┃ 02000000 ┃ # Public Ins + ┣━━━━━━━━━━┫ + ┃ 03000000 ┃ # Private Ins + ┣━━━━━━━━━━┻━━━━━━━━┓ + ┃ e8030000 00000000 ┃ # Labels + ┣━━━━━━━━━━┳━━━━━━━━┛ + ┃ 03000000 ┃ # Constraints + ┗━━━━━━━━━━┛ + ┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓ + ┃ 02000000 ┃ 88200000 00000000 ┃ SectionType: Constraints + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ Constraint 0: (3w_5 + 8w_6) * (2w_0 + 20w_2 + 12w_3) - (5w_0 + 7w_2) = 0 + ┃ 02000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 05000000 ┃ 03000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 06000000 ┃ 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ + ┃ 03000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 00000000 ┃ 02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 02000000 ┃ 01140000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 03000000 ┃ 0C000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ + ┃ 02000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 00000000 ┃ 05000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 02000000 ┃ 07000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + + ┏━━━━━━━━━━┓ Constraint 1: (4w_1 + 8w_4 + 3w_5) * (6w_6 + 44w_3) = 0 + ┃ 03000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 01000000 ┃ 04000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 04000000 ┃ 08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 05000000 ┃ 03000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ + ┃ 02000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 03000000 ┃ 2C000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 06000000 ┃ 06000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ + ┃ 00000000 ┃ + ┗━━━━━━━━━━┛ + + ┏━━━━━━━━━━┓ Constraint 2: (4w_6) * (6w_0 + 5w_3 + 11w_2) - (600w_6) = 0 + ┃ 01000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 06000000 ┃ 04000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ + ┃ 03000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 00000000 ┃ 06000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 02000000 ┃ 0B000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + ┃ 03000000 ┃ 05000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━┓ + ┃ 01000000 ┃ + ┣━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ 06000000 ┃ 58020000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ┃ + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + + ┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓ + ┃ 03000000 ┃ 38000000 00000000 ┃ Wire to Label Map + ┗━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┛ + ┏━━━━━━━━━━━━━━━━━━━┓ + ┃ 00000000 00000000 ┃ + ┣━━━━━━━━━━━━━━━━━━━┫ + ┃ 03000000 00000000 ┃ + ┣━━━━━━━━━━━━━━━━━━━┫ + ┃ 0a000000 00000000 ┃ + ┣━━━━━━━━━━━━━━━━━━━┫ + ┃ 0b000000 00000000 ┃ + ┣━━━━━━━━━━━━━━━━━━━┫ + ┃ 0c000000 00000000 ┃ + ┣━━━━━━━━━━━━━━━━━━━┫ + ┃ 0f000000 00000000 ┃ + ┣━━━━━━━━━━━━━━━━━━━┫ + ┃ 44010000 00000000 ┃ + ┗━━━━━━━━━━━━━━━━━━━┛ ```` And the binary representation in Hex: ```` -72 31 63 77 -01 00 00 00 -03 00 00 00 -01 00 00 00 49 00 00 00 -25 00 00 00 10 00 00 00 -20 010000f0 93f5e143 9170b979 48e83328 5d588181 b64550b8 29a031e1 724e6430 -00 00 00 00 -04 00 00 00 -07 00 00 00 -01 00 00 00 -02 00 00 00 -03 00 00 00 -e8 03 00 00 -03 00 00 00 -02 00 00 00 8b 00 00 00 -02 00 00 00 -05 00 00 00 01 03 -06 00 00 00 01 08 -03 00 00 00 -00 00 00 00 01 02 -02 00 00 00 01 14 -03 00 00 00 01 0C -02 00 00 00 -00 00 00 00 01 05 -02 00 00 00 01 07 -03 00 00 00 -01 00 00 00 01 04 -04 00 00 00 01 08 -05 00 00 00 01 03 -02 00 00 00 -03 00 00 00 01 2C -06 00 00 00 01 06 -00 00 00 00 -01 00 00 00 -06 00 00 00 01 04 -03 00 00 00 -00 00 00 00 01 06 -02 00 00 00 01 0B -03 00 00 00 01 05 -01 00 00 00 -06 00 00 00 02 58 02 -03 00 00 00 1c 00 00 00 -00 00 00 00 -03 00 00 00 -0a 00 00 00 -0b 00 00 00 -0c 00 00 00 -0f 00 00 00 -44 01 00 00 +72316377 +01000000 +03000000 +01000000 40000000 00000000 +20000000 +010000f0 93f5e143 9170b979 48e83328 5d588181 b64550b8 29a031e1 724e6430 +07000000 +01000000 +02000000 +03000000 +e8030000 00000000 +03000000 +02000000 88200000 00000000 +02000000 +05000000 03000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +06000000 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +03000000 +00000000 02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +02000000 01140000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +03000000 0C000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +02000000 +00000000 05000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +02000000 07000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +03000000 +01000000 04000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +04000000 08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +05000000 03000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +02000000 +03000000 2C000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +06000000 06000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +00000000 +01000000 +06000000 04000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +03000000 +00000000 06000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +02000000 0B000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +03000000 05000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +01000000 +06000000 58020000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 +03000000 38000000 00000000 +00000000 00000000 +03000000 00000000 +0a000000 00000000 +0b000000 00000000 +0c000000 00000000 +0f000000 00000000 +44010000 00000000 ```` diff --git a/doc/r1cs_bin_format.monopic b/doc/r1cs_bin_format.monopic deleted file mode 100644 index b49bf3a..0000000 Binary files a/doc/r1cs_bin_format.monopic and /dev/null differ diff --git a/doc/r1cs_example.monopic b/doc/r1cs_example.monopic deleted file mode 100644 index e4aa83b..0000000 Binary files a/doc/r1cs_example.monopic and /dev/null differ diff --git a/package-lock.json b/package-lock.json index 87e037c..d504a3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,25 +5,36 @@ "requires": true, "dependencies": { "@babel/code-frame": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", - "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz", + "integrity": "sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g==", "dev": true, "requires": { - "@babel/highlight": "^7.0.0" + "@babel/highlight": "^7.8.3" } }, + "@babel/helper-validator-identifier": { + "version": "7.9.0", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.0.tgz", + "integrity": "sha512-6G8bQKjOh+of4PV/ThDm/rRqlU7+IGoJuofpagU5GlEl29Vv0RGqqt86ZGRV8ZuSOY3o+8yXl5y782SMcG7SHw==", + "dev": true + }, "@babel/highlight": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", - "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", + "version": "7.9.0", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.9.0.tgz", + "integrity": "sha512-lJZPilxX7Op3Nv/2cvFdnlepPXDxi29wxteT57Q965oc5R9v86ztx0jfxVrTcBk8C2kcPkkDa2Z4T3ZsPPVWsQ==", "dev": true, "requires": { + "@babel/helper-validator-identifier": "^7.9.0", "chalk": "^2.0.0", - "esutils": "^2.0.2", "js-tokens": "^4.0.0" } }, + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" + }, "JSONSelect": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/JSONSelect/-/JSONSelect-0.4.0.tgz", @@ -37,24 +48,24 @@ "dev": true }, "acorn": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", - "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", + "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", "dev": true }, "acorn-jsx": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.1.tgz", - "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.2.0.tgz", + "integrity": "sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ==", "dev": true }, "ajv": { - "version": "6.10.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", - "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", + "version": "6.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.0.tgz", + "integrity": "sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==", "dev": true, "requires": { - "fast-deep-equal": "^2.0.1", + "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" @@ -68,23 +79,34 @@ "optional": true }, "ansi-escapes": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", - "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", - "dev": true + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.1.tgz", + "integrity": "sha512-JWF7ocqNrp8u9oqpgV+wH5ftbt+cfvv+PTjOvKLT3AdYly/LmORARfEVT1iyjwN+4MqE5UmVKoAdIBqeoCHgLA==", + "dev": true, + "requires": { + "type-fest": "^0.11.0" + }, + "dependencies": { + "type-fest": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.11.0.tgz", + "integrity": "sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ==", + "dev": true + } + } }, "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==" }, "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "requires": { - "color-convert": "^1.9.0" + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" } }, "argparse": { @@ -99,8 +121,7 @@ "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "dev": true + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==" }, "astral-regex": { "version": "1.0.0", @@ -114,18 +135,9 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "big-integer": { - "version": "1.6.43", - "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.43.tgz", - "integrity": "sha512-9dULc9jsKmXl0Aeunug8wbF+58n+hQoFjqClN7WeZwGLh0XJUWyJJ9Ee+Ep+Ql/J9fRsTVaeThp8MhiCCrY0Jg==" - }, - "bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "dev": true, - "requires": { - "file-uri-to-path": "1.0.0" - } + "version": "1.6.48", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz", + "integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==" }, "brace-expansion": { "version": "1.1.11", @@ -151,7 +163,6 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", - "dev": true, "requires": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", @@ -170,6 +181,32 @@ "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + } } }, "chardet": { @@ -181,8 +218,16 @@ "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", - "dev": true + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=" + }, + "circom_runtime": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/circom_runtime/-/circom_runtime-0.0.2.tgz", + "integrity": "sha512-aJcQucUxrZ31O7JbY14l1oiP6ZlNAtPW+i8/CY4b9GAjgWPjts+D9pxtz/x2yC2Ei+ieaJY7LFjfCKFTOoHGDQ==", + "requires": { + "big-integer": "^1.6.48", + "fnv-plus": "^1.3.1" + } }, "cjson": { "version": "0.3.0", @@ -194,12 +239,12 @@ } }, "cli-cursor": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", - "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", + "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", "dev": true, "requires": { - "restore-cursor": "^2.0.0" + "restore-cursor": "^3.1.0" } }, "cli-width": { @@ -209,34 +254,27 @@ "dev": true }, "cliui": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", - "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", "requires": { - "string-width": "^2.1.1", - "strip-ansi": "^4.0.0", - "wrap-ansi": "^2.0.0" + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" } }, - "code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" - }, "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "requires": { - "color-name": "1.1.3" + "color-name": "~1.1.4" } }, "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "colors": { "version": "0.5.1", @@ -253,12 +291,21 @@ "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "dev": true, "requires": { "nice-try": "^1.0.4", "path-key": "^2.0.1", "semver": "^5.5.0", "shebang-command": "^1.2.0", "which": "^1.2.9" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } } }, "debug": { @@ -279,7 +326,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", - "dev": true, "requires": { "type-detect": "^4.0.0" } @@ -311,18 +357,9 @@ "integrity": "sha512-cuIMtJwxvzumSAkqaaoGY/L6Fc/t6YvoP9/VIaK0V/CyqKLEQ8sqODmYfy/cjXEdZ9+OOL8TecbJu+1RsofGDw==" }, "emoji-regex": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", - "dev": true - }, - "end-of-stream": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", - "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", - "requires": { - "once": "^1.4.0" - } + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "escape-string-regexp": { "version": "1.0.5", @@ -363,70 +400,71 @@ } }, "eslint": { - "version": "5.16.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.16.0.tgz", - "integrity": "sha512-S3Rz11i7c8AA5JPv7xAH+dOyq/Cu/VXHiHXBPOU1k/JAM5dXqQPt3qcrhpHSorXmrpu2g0gkIBVXAqCpzfoZIg==", + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.8.0.tgz", + "integrity": "sha512-K+Iayyo2LtyYhDSYwz5D5QdWw0hCacNzyq1Y821Xna2xSJj7cijoLLYmLxTQgcgZ9mC61nryMy9S7GRbYpI5Ig==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "ajv": "^6.9.1", + "ajv": "^6.10.0", "chalk": "^2.1.0", "cross-spawn": "^6.0.5", "debug": "^4.0.1", "doctrine": "^3.0.0", - "eslint-scope": "^4.0.3", - "eslint-utils": "^1.3.1", - "eslint-visitor-keys": "^1.0.0", - "espree": "^5.0.1", + "eslint-scope": "^5.0.0", + "eslint-utils": "^1.4.3", + "eslint-visitor-keys": "^1.1.0", + "espree": "^6.1.2", "esquery": "^1.0.1", "esutils": "^2.0.2", "file-entry-cache": "^5.0.1", "functional-red-black-tree": "^1.0.1", - "glob": "^7.1.2", - "globals": "^11.7.0", + "glob-parent": "^5.0.0", + "globals": "^12.1.0", "ignore": "^4.0.6", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", - "inquirer": "^6.2.2", - "js-yaml": "^3.13.0", + "inquirer": "^7.0.0", + "is-glob": "^4.0.0", + "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.3.0", - "lodash": "^4.17.11", + "lodash": "^4.17.14", "minimatch": "^3.0.4", "mkdirp": "^0.5.1", "natural-compare": "^1.4.0", - "optionator": "^0.8.2", - "path-is-inside": "^1.0.2", + "optionator": "^0.8.3", "progress": "^2.0.0", "regexpp": "^2.0.1", - "semver": "^5.5.1", - "strip-ansi": "^4.0.0", - "strip-json-comments": "^2.0.1", + "semver": "^6.1.2", + "strip-ansi": "^5.2.0", + "strip-json-comments": "^3.0.1", "table": "^5.2.3", - "text-table": "^0.2.0" + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" }, "dependencies": { - "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } } } }, - "eslint-plugin-mocha": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-5.3.0.tgz", - "integrity": "sha512-3uwlJVLijjEmBeNyH60nzqgA1gacUWLUmcKV8PIGNvj1kwP/CTgAWQHn2ayyJVwziX+KETkr9opNwT1qD/RZ5A==", - "dev": true, - "requires": { - "ramda": "^0.26.1" - } - }, "eslint-scope": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", - "integrity": "sha512-p7VutNr1O/QrxysMo3E45FjYDTeXBy0iTltPFNSqKAIfjDSXC+4dj+qfyuD8bfAXrW/y6lW3O76VaYNPKfpKrg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", + "integrity": "sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw==", "dev": true, "requires": { "esrecurse": "^4.1.0", @@ -434,29 +472,29 @@ } }, "eslint-utils": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.2.tgz", - "integrity": "sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==", + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.3.tgz", + "integrity": "sha512-fbBN5W2xdY45KulGXmLHZ3c3FHfVYmKg0IrAKGOkT/464PQsx2UeIzfz1RmEci+KLm1bBaAzZAh8+/E+XAeZ8Q==", "dev": true, "requires": { - "eslint-visitor-keys": "^1.0.0" + "eslint-visitor-keys": "^1.1.0" } }, "eslint-visitor-keys": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", - "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz", + "integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==", "dev": true }, "espree": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-5.0.1.tgz", - "integrity": "sha512-qWAZcWh4XE/RwzLJejfcofscgMc9CamR6Tn1+XRXNzrvUSSbiAjGOI/fggztjIi7y9VLPqnICMIPiGyr8JaZ0A==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-6.2.1.tgz", + "integrity": "sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw==", "dev": true, "requires": { - "acorn": "^6.0.7", - "acorn-jsx": "^5.0.0", - "eslint-visitor-keys": "^1.0.0" + "acorn": "^7.1.1", + "acorn-jsx": "^5.2.0", + "eslint-visitor-keys": "^1.1.0" } }, "esprima": { @@ -466,12 +504,20 @@ "dev": true }, "esquery": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", - "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.2.0.tgz", + "integrity": "sha512-weltsSqdeWIX9G2qQZz7KlTRJdkkOCTPgLYJUz1Hacf48R4YOwGPHO3+ORfWedqJKbq5WQmsgK90n+pFLIKt/Q==", "dev": true, "requires": { - "estraverse": "^4.0.0" + "estraverse": "^5.0.0" + }, + "dependencies": { + "estraverse": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.0.0.tgz", + "integrity": "sha512-j3acdrMzqrxmJTNj5dbr1YbjacrYgAxVMeF0gK16E3j494mOe7xygM/ZLIguEQ0ETwAg2hlJCtHRGav+y0Ny5A==", + "dev": true + } } }, "esrecurse": { @@ -484,52 +530,49 @@ } }, "estraverse": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", - "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, "esutils": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, - "execa": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", - "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", - "requires": { - "cross-spawn": "^6.0.0", - "get-stream": "^4.0.0", - "is-stream": "^1.1.0", - "npm-run-path": "^2.0.0", - "p-finally": "^1.0.0", - "signal-exit": "^3.0.0", - "strip-eof": "^1.0.0" - } - }, "external-editor": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", - "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", + "integrity": "sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==", "dev": true, "requires": { "chardet": "^0.7.0", "iconv-lite": "^0.4.24", "tmp": "^0.0.33" + }, + "dependencies": { + "tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dev": true, + "requires": { + "os-tmpdir": "~1.0.2" + } + } } }, "fast-deep-equal": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", - "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", + "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==", "dev": true }, "fast-json-stable-stringify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true }, "fast-levenshtein": { @@ -538,25 +581,47 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, - "fflib": { + "ffiasm": { "version": "0.0.2", - "resolved": "https://registry.npmjs.org/fflib/-/fflib-0.0.2.tgz", - "integrity": "sha512-TvQ3nQjJwdyrFBZAz+GTWz1mv9hHwRiQmZX3T2G0P+cBAlyw42lm4W62i+Ofj1ZOW1XNrEEhFhxHPnutTsJBwA==", + "resolved": "https://registry.npmjs.org/ffiasm/-/ffiasm-0.0.2.tgz", + "integrity": "sha512-o/CL7F4IodB7eRHCOQL1SrqN2DIPHrQbEwjPY7NIyeBRdnB3G0xo6b6Mj44SKiWFnvpQMb3n4N7acjD3vv4NVQ==", + "requires": { + "big-integer": "^1.6.48", + "ejs": "^3.0.1", + "yargs": "^15.3.1" + } + }, + "ffjavascript": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.0.3.tgz", + "integrity": "sha512-uXbiC7cNbFzNJCdkGlbQf2d7GciY1ICMcBeAA7+D8RHPr9Y5zYiDRWtU5etjAV8TplE7eZQ9Iqd9ieFi0ARJLA==", "requires": { "big-integer": "^1.6.48" + } + }, + "ffwasm": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/ffwasm/-/ffwasm-0.0.5.tgz", + "integrity": "sha512-biz1jK3TjxpwigoBLWzvBNtuQAC6WBVzlI1sw2BQp3RqTei66OhJ6E2G+zSk2SubUVWlrgTN+WfE+Fmn3qdtgg==", + "requires": { + "big-integer": "^1.6.48", + "wasmbuilder": "0.0.8" }, "dependencies": { - "big-integer": { - "version": "1.6.48", - "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz", - "integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==" + "wasmbuilder": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.8.tgz", + "integrity": "sha512-d63cIsDmHnybA5hTlRRLadgys5r3Tl4W8SbcBRh13FauEPOo48dqjgzdL1xefpZkpKKybDRlFqgm+9cX04B3+w==", + "requires": { + "big-integer": "^1.6.43" + } } } }, "figures": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", - "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", + "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", "dev": true, "requires": { "escape-string-regexp": "^1.0.5" @@ -571,18 +636,13 @@ "flat-cache": "^2.0.1" } }, - "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "dev": true - }, "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", "requires": { - "locate-path": "^3.0.0" + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" } }, "flat-cache": { @@ -594,12 +654,23 @@ "flatted": "^2.0.0", "rimraf": "2.6.3", "write": "1.0.3" + }, + "dependencies": { + "rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } } }, "flatted": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.0.tgz", - "integrity": "sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.1.tgz", + "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", "dev": true }, "fnv-plus": { @@ -619,28 +690,19 @@ "dev": true }, "get-caller-file": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", - "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==" + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" }, "get-func-name": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", - "dev": true - }, - "get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "requires": { - "pump": "^3.0.0" - } + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=" }, "glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -650,11 +712,23 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, "globals": { - "version": "11.11.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.11.0.tgz", - "integrity": "sha512-WHq43gS+6ufNOEqlrDBxVEbb8ntfXrfAUU2ZOpCxrBdGKW3gyv8mCxAfIBD0DroPKGrJ2eSsXsLtY9MPntsyTw==", - "dev": true + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } }, "has-flag": { "version": "3.0.0", @@ -678,9 +752,9 @@ "dev": true }, "import-fresh": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz", - "integrity": "sha512-pOnA9tfM3Uwics+SaBLCNyZZZbK+4PTu0OPZtLlMIrv17EdBoC15S9Kn8ckJ9TZTyKb3ywNE5y1yeDxxGA7nTQ==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz", + "integrity": "sha512-6e1q1cnWP2RXD9/keSkxHScg508CdXqXWgWBaETNhyuBFz+kUZlKboh+ISK+bU++DmbHimVBrOz/zzPe0sZ3sQ==", "dev": true, "requires": { "parent-module": "^1.0.0", @@ -703,57 +777,77 @@ } }, "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "inquirer": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.2.2.tgz", - "integrity": "sha512-Z2rREiXA6cHRR9KBOarR3WuLlFzlIfAEIiB45ll5SSadMg7WqOh1MKEjjndfuH5ewXdixWCxqnVfGOQzPeiztA==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.1.0.tgz", + "integrity": "sha512-5fJMWEmikSYu0nv/flMc475MhGbB7TSPd/2IpFV4I4rMklboCH2rQjYY5kKiYGHqUF9gvaambupcJFFG9dvReg==", "dev": true, "requires": { - "ansi-escapes": "^3.2.0", - "chalk": "^2.4.2", - "cli-cursor": "^2.1.0", + "ansi-escapes": "^4.2.1", + "chalk": "^3.0.0", + "cli-cursor": "^3.1.0", "cli-width": "^2.0.0", "external-editor": "^3.0.3", - "figures": "^2.0.0", - "lodash": "^4.17.11", - "mute-stream": "0.0.7", - "run-async": "^2.2.0", - "rxjs": "^6.4.0", - "string-width": "^2.1.0", - "strip-ansi": "^5.0.0", + "figures": "^3.0.0", + "lodash": "^4.17.15", + "mute-stream": "0.0.8", + "run-async": "^2.4.0", + "rxjs": "^6.5.3", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0", "through": "^2.3.6" }, "dependencies": { - "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, - "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", "dev": true, "requires": { - "ansi-regex": "^4.1.0" + "has-flag": "^4.0.0" } } } }, - "invert-kv": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", - "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==" + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true }, "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } }, "is-promise": { "version": "2.1.0", @@ -761,15 +855,11 @@ "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", "dev": true }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" - }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true }, "jison": { "version": "0.4.18", @@ -843,26 +933,6 @@ "nomnom": ">= 1.5.x" } }, - "keccak": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/keccak/-/keccak-2.0.0.tgz", - "integrity": "sha512-rKe/lRr0KGhjoz97cwg+oeT1Rj/Y4cjae6glArioUC8JBF9ROGZctwIaaruM7d7naovME4Q8WcQSO908A8qcyQ==", - "dev": true, - "requires": { - "bindings": "^1.2.1", - "inherits": "^2.0.3", - "nan": "^2.2.1", - "safe-buffer": "^5.1.0" - } - }, - "lcid": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", - "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", - "requires": { - "invert-kv": "^2.0.0" - } - }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", @@ -880,12 +950,11 @@ "dev": true }, "locate-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", "requires": { - "p-locate": "^3.0.0", - "path-exists": "^3.0.0" + "p-locate": "^4.1.0" } }, "lodash": { @@ -894,35 +963,10 @@ "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, - "map-age-cleaner": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", - "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", - "requires": { - "p-defer": "^1.0.0" - } - }, - "mem": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", - "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", - "requires": { - "map-age-cleaner": "^0.1.1", - "mimic-fn": "^2.0.0", - "p-is-promise": "^2.0.0" - }, - "dependencies": { - "mimic-fn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" - } - } - }, "mimic-fn": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true }, "minimatch": { @@ -934,43 +978,30 @@ } }, "minimist": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", - "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=" + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.4.tgz", + "integrity": "sha512-iG9AK/dJLtJ0XNgTuDbSyNS3zECqDlAhnQW4CsNxBG3LQJBbHmRX1egw39DmtOdCAqY+dKXV+sgPgilNWUKMVw==", "dev": true, "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - } + "minimist": "^1.2.5" } }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, "mute-stream": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", - "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", - "dev": true - }, - "nan": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", - "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, "natural-compare": { @@ -980,9 +1011,10 @@ "dev": true }, "nice-try": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.4.tgz", - "integrity": "sha512-2NpiFHqC87y/zFke0fC0spBXL3bBsoh/p5H1EFhshxjCR5+0g2d6BiXbUFz9v1sAcxsk2htp2eQnNIci2dIYcA==" + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", + "dev": true }, "nomnom": { "version": "1.5.2", @@ -994,19 +1026,6 @@ "underscore": "1.1.x" } }, - "npm-run-path": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", - "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", - "requires": { - "path-key": "^2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" - }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -1016,53 +1035,26 @@ } }, "onetime": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", - "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz", + "integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==", "dev": true, "requires": { - "mimic-fn": "^1.0.0" - } - }, - "optimist": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", - "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", - "requires": { - "minimist": "~0.0.1", - "wordwrap": "~0.0.2" + "mimic-fn": "^2.1.0" } }, "optionator": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", - "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", + "integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==", "dev": true, "requires": { "deep-is": "~0.1.3", - "fast-levenshtein": "~2.0.4", + "fast-levenshtein": "~2.0.6", "levn": "~0.3.0", "prelude-ls": "~1.1.2", "type-check": "~0.3.2", - "wordwrap": "~1.0.0" - }, - "dependencies": { - "wordwrap": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", - "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", - "dev": true - } - } - }, - "os-locale": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", - "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", - "requires": { - "execa": "^1.0.0", - "lcid": "^2.0.0", - "mem": "^4.0.0" + "word-wrap": "~1.2.3" } }, "os-tmpdir": { @@ -1071,35 +1063,20 @@ "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true }, - "p-defer": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", - "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=" - }, - "p-finally": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" - }, - "p-is-promise": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", - "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==" - }, "p-limit": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", - "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.2.tgz", + "integrity": "sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ==", "requires": { "p-try": "^2.0.0" } }, "p-locate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", "requires": { - "p-limit": "^2.0.0" + "p-limit": "^2.2.0" } }, "p-try": { @@ -1117,31 +1094,25 @@ } }, "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, - "path-is-inside": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", - "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", - "dev": true - }, "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", + "dev": true }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", - "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", - "dev": true + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=" }, "prelude-ls": { "version": "1.1.2", @@ -1155,26 +1126,19 @@ "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true }, - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, - "ramda": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.26.1.tgz", - "integrity": "sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ==", - "dev": true + "r1csfile": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/r1csfile/-/r1csfile-0.0.2.tgz", + "integrity": "sha512-H1aR5NYRJ/RUrHWR/PNEivFEDkLV4R0+4SlKo2eq/fyiWxwgZNapOkjnJXsy5TZn40uFVrud0uOxGyVWgm9rDg==", + "requires": { + "big-integer": "^1.6.48" + } }, "regexpp": { "version": "2.0.1", @@ -1188,9 +1152,9 @@ "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" }, "require-main-filename": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", - "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" }, "resolve-from": { "version": "4.0.0", @@ -1199,55 +1163,41 @@ "dev": true }, "restore-cursor": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", - "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", + "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", "dev": true, "requires": { - "onetime": "^2.0.0", + "onetime": "^5.1.0", "signal-exit": "^3.0.2" } }, "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", "requires": { "glob": "^7.1.3" } }, - "rimraf-promise": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/rimraf-promise/-/rimraf-promise-2.0.0.tgz", - "integrity": "sha1-PdvkN4wa3slmvDZt37yYUUPHaVI=", - "requires": { - "rimraf": "^2.4.3" - } - }, "run-async": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", - "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.0.tgz", + "integrity": "sha512-xJTbh/d7Lm7SBhc1tNvTpeCHaEzoyxPrqNlvSdMfBTYwaY++UJFyXUOxAtsRUXjlqOfj8luNaR9vjCh4KeV+pg==", "dev": true, "requires": { "is-promise": "^2.1.0" } }, "rxjs": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.4.0.tgz", - "integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", + "integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==", "dev": true, "requires": { "tslib": "^1.9.0" } }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true - }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -1255,9 +1205,10 @@ "dev": true }, "semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true }, "set-blocking": { "version": "2.0.0", @@ -1268,6 +1219,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "dev": true, "requires": { "shebang-regex": "^1.0.0" } @@ -1275,12 +1227,14 @@ "shebang-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", + "dev": true }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "dev": true }, "slice-ansi": { "version": "2.1.0", @@ -1291,20 +1245,38 @@ "ansi-styles": "^3.2.0", "astral-regex": "^1.0.0", "is-fullwidth-code-point": "^2.0.0" - } - }, - "snarkjs": { - "version": "0.1.14", - "resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.14.tgz", - "integrity": "sha512-mNsWx5K0ojz73689ZARwqyY62ENvW43movC+WMEHVYsFdcX9lpG+ZjiJGvnQh7LkYg2WY2lFzsXTUZI35TxqeA==", - "dev": true, - "requires": { - "big-integer": "^1.6.43", - "chai": "^4.2.0", - "escape-string-regexp": "^1.0.5", - "eslint": "^5.16.0", - "keccak": "^2.0.0", - "yargs": "^12.0.5" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + } } }, "source-map": { @@ -1324,38 +1296,27 @@ "dev": true }, "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" } }, "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", "requires": { - "ansi-regex": "^3.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" - } + "ansi-regex": "^5.0.0" } }, - "strip-eof": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", - "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" - }, "strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", + "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", "dev": true }, "supports-color": { @@ -1368,13 +1329,13 @@ } }, "table": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/table/-/table-5.2.3.tgz", - "integrity": "sha512-N2RsDAMvDLvYwFcwbPyF3VmVSSkuF+G1e+8inhBLtHpvwXGw4QRPEZhihQNeEN0i1up6/f6ObCJXNdlRG3YVyQ==", + "version": "5.4.6", + "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", + "integrity": "sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==", "dev": true, "requires": { - "ajv": "^6.9.1", - "lodash": "^4.17.11", + "ajv": "^6.10.2", + "lodash": "^4.17.14", "slice-ansi": "^2.1.0", "string-width": "^3.0.0" }, @@ -1385,6 +1346,18 @@ "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, "string-width": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", @@ -1420,12 +1393,11 @@ "dev": true }, "tmp": { - "version": "0.0.33", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", - "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", - "dev": true, + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", + "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==", "requires": { - "os-tmpdir": "~1.0.2" + "rimraf": "^2.6.3" } }, "tmp-promise": { @@ -1434,22 +1406,12 @@ "integrity": "sha512-zl71nFWjPKW2KXs+73gEk8RmqvtAeXPxhWDkTUoa3MSMkjq3I+9OeknjF178MQoMYsdqL730hfzvNfEkePxq9Q==", "requires": { "tmp": "0.1.0" - }, - "dependencies": { - "tmp": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", - "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==", - "requires": { - "rimraf": "^2.6.3" - } - } } }, "tslib": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", - "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", + "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==", "dev": true }, "type-check": { @@ -1464,7 +1426,12 @@ "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" + }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", "dev": true }, "underscore": { @@ -1482,18 +1449,25 @@ "punycode": "^2.1.0" } }, + "v8-compile-cache": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz", + "integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", + "dev": true + }, "wasmbuilder": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.8.tgz", - "integrity": "sha512-d63cIsDmHnybA5hTlRRLadgys5r3Tl4W8SbcBRh13FauEPOo48dqjgzdL1xefpZkpKKybDRlFqgm+9cX04B3+w==", + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.9.tgz", + "integrity": "sha512-QJ550VwQvN6P4oW0d+/tCfo3i+1GBuuFX906r8QpDRryYXmXvdRZWJM0qkHgOfhg8G47SfgJVYNl3fyLfkxaPw==", "requires": { - "big-integer": "^1.6.43" + "big-integer": "^1.6.48" } }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, "requires": { "isexe": "^2.0.0" } @@ -1503,46 +1477,20 @@ "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, - "wordwrap": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", - "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=" + "word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true }, "wrap-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", - "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", "requires": { - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1" - }, - "dependencies": { - "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "requires": { - "number-is-nan": "^1.0.0" - } - }, - "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" - } - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "requires": { - "ansi-regex": "^2.0.0" - } - } + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" } }, "wrappy": { @@ -1565,28 +1513,27 @@ "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" }, "yargs": { - "version": "12.0.5", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz", - "integrity": "sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw==", + "version": "15.3.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.3.1.tgz", + "integrity": "sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA==", "requires": { - "cliui": "^4.0.0", + "cliui": "^6.0.0", "decamelize": "^1.2.0", - "find-up": "^3.0.0", - "get-caller-file": "^1.0.1", - "os-locale": "^3.0.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", "require-directory": "^2.1.1", - "require-main-filename": "^1.0.1", + "require-main-filename": "^2.0.0", "set-blocking": "^2.0.0", - "string-width": "^2.0.0", + "string-width": "^4.2.0", "which-module": "^2.0.0", - "y18n": "^3.2.1 || ^4.0.0", - "yargs-parser": "^11.1.1" + "y18n": "^4.0.0", + "yargs-parser": "^18.1.1" } }, "yargs-parser": { - "version": "11.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-11.1.1.tgz", - "integrity": "sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ==", + "version": "18.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.1.tgz", + "integrity": "sha512-KRHEsOM16IX7XuLnMOqImcPNbLVXMNHYAoFc3BKR8Ortl5gzDbtXvvEoGx9imk5E+X1VeNKNlcHr8B8vi+7ipA==", "requires": { "camelcase": "^5.0.0", "decamelize": "^1.2.0" diff --git a/package.json b/package.json index 65df8bf..32b8914 100644 --- a/package.json +++ b/package.json @@ -30,20 +30,19 @@ }, "dependencies": { "big-integer": "^1.6.32", - "ejs": "^3.0.1", - "fflib": "0.0.2", + "chai": "^4.2.0", + "circom_runtime": "0.0.2", + "ffiasm": "0.0.2", + "ffjavascript": "0.0.3", + "ffwasm": "0.0.5", "fnv-plus": "^1.3.1", - "optimist": "^0.6.1", - "rimraf-promise": "^2.0.0", + "r1csfile": "0.0.2", "tmp-promise": "^2.0.2", - "wasmbuilder": "0.0.8", - "yargs": "^12.0.2" + "wasmbuilder": "0.0.9" }, "devDependencies": { - "chai": "^4.2.0", - "eslint": "^5.16.0", - "eslint-plugin-mocha": "^5.3.0", + "eslint": "^6.8.0", "jison": "^0.4.18", - "snarkjs": "0.1.14" + "yargs": "^15.3.1" } } diff --git a/ports/c/buildasm/add.asm.ejs b/ports/c/buildasm/add.asm.ejs deleted file mode 100644 index 70cfd73..0000000 --- a/ports/c/buildasm/add.asm.ejs +++ /dev/null @@ -1,245 +0,0 @@ -<% function addS1S2() { %> - xor rdx, rdx - mov edx, eax - add edx, ecx - jo add_manageOverflow ; rsi already is the 64bits result - - mov [rdi], rdx ; not necessary to adjust so just save and return - ret - -add_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rsi, eax - movsx rdx, ecx - add rsi, rdx - call rawCopyS2L - pop rsi - ret -<% } %> - - - -<% function addL1S2() { %> - add rsi, 8 - movsx rdx, ecx - add rdi, 8 - cmp rdx, 0 - <% const rawAddLabel = global.tmpLabel() %> - jns <%= rawAddLabel %> - neg rdx - call rawSubLS - sub rdi, 8 - sub rsi, 8 - ret -<%= rawAddLabel %>: - call rawAddLS - sub rdi, 8 - sub rsi, 8 - ret - -<% } %> - -<% function addS1L2() { %> - lea rsi, [rdx + 8] - movsx rdx, eax - add rdi, 8 - cmp rdx, 0 - <% const rawAddLabel = global.tmpLabel() %> - jns <%= rawAddLabel %> - neg rdx - call rawSubLS - sub rdi, 8 - sub rsi, 8 - ret -<%= rawAddLabel %>: - call rawAddLS - sub rdi, 8 - sub rsi, 8 - ret -<% } %> - -<% function addL1L2() { %> - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret -<% } %> - -;;;;;;;;;;;;;;;;;;;;;; -; add -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_add: - mov rax, [rsi] - mov rcx, [rdx] - bt rax, 63 ; Check if is short first operand - jc add_l1 - bt rcx, 63 ; Check if is short second operand - jc add_s1l2 - -add_s1s2: ; Both operands are short -<%= addS1S2() %> -add_l1: - bt rcx, 63 ; Check if is short second operand - jc add_l1l2 - -;;;;;;;; -add_l1s2: - bt rax, 62 ; check if montgomery first - jc add_l1ms2 -add_l1ns2: -<%= global.setTypeDest("0x80"); %> -<%= addL1S2(); %> - -add_l1ms2: - bt rcx, 62 ; check if montgomery second - jc add_l1ms2m -add_l1ms2n: -<%= global.setTypeDest("0xC0"); %> -<%= global.toMont_b() %> -<%= addL1L2() %> - -add_l1ms2m: -<%= global.setTypeDest("0xC0"); %> -<%= addL1L2() %> - - -;;;;;;;; -add_s1l2: - bt rcx, 62 ; check if montgomery second - jc add_s1l2m -add_s1l2n: -<%= global.setTypeDest("0x80"); %> -<%= addS1L2(); %> - -add_s1l2m: - bt rax, 62 ; check if montgomery first - jc add_s1ml2m -add_s1nl2m: -<%= global.setTypeDest("0xC0"); %> -<%= global.toMont_a() %> -<%= addL1L2() %> - -add_s1ml2m: -<%= global.setTypeDest("0xC0"); %> -<%= addL1L2() %> - -;;;; -add_l1l2: - bt rax, 62 ; check if montgomery first - jc add_l1ml2 -add_l1nl2: - bt rcx, 62 ; check if montgomery second - jc add_l1nl2m -add_l1nl2n: -<%= global.setTypeDest("0x80"); %> -<%= addL1L2() %> - -add_l1nl2m: -<%= global.setTypeDest("0xC0"); %> -<%= global.toMont_a(); %> -<%= addL1L2() %> - -add_l1ml2: - bt rcx, 62 ; check if montgomery seconf - jc add_l1ml2m -add_l1ml2n: -<%= global.setTypeDest("0xC0"); %> -<%= global.toMont_b(); %> -<%= addL1L2() %> - -add_l1ml2m: -<%= global.setTypeDest("0xC0"); %> -<%= addL1L2() %> - - - -;;;;;;;;;;;;;;;;;;;;;; -; rawAddLL -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of type long -; Params: -; rsi <= Pointer to the long data of element 1 -; rdx <= Pointer to the long data of element 2 -; rdi <= Pointer to the long data of result -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawAddLL: - ; Add component by component with carry -<% for (let i=0; i - mov rax, [rsi + <%=i*8%>] - <%= i==0 ? "add" : "adc" %> rax, [rdx + <%=i*8%>] - mov [rdi + <%=i*8%>], rax -<% } %> - jc rawAddLL_sq ; if overflow, substract q - - ; Compare with q -<% for (let i=0; i -<% if (i>0) { %> - mov rax, [rdi + <%= (n64-i-1)*8 %>] -<% } %> - cmp rax, [q + <%= (n64-i-1)*8 %>] - jc rawAddLL_done ; q is bigget so done. - jnz rawAddLL_sq ; q is lower -<% } %> - ; If equal substract q -rawAddLL_sq: -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "sub" : "sbb" %> [rdi + <%=i*8%>], rax -<% } %> -rawAddLL_done: - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; rawAddLS -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of type long -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to the long data of element 1 -; rdx <= Value to be added -;;;;;;;;;;;;;;;;;;;;;; -rawAddLS: - ; Add component by component with carry - - add rdx, [rsi] - mov [rdi] ,rdx -<% for (let i=1; i - mov rdx, 0 - adc rdx, [rsi + <%=i*8%>] - mov [rdi + <%=i*8%>], rdx -<% } %> - jc rawAddLS_sq ; if overflow, substract q - - ; Compare with q -<% for (let i=0; i - mov rax, [rdi + <%= (n64-i-1)*8 %>] - cmp rax, [q + <%= (n64-i-1)*8 %>] - jc rawAddLS_done ; q is bigget so done. - jnz rawAddLS_sq ; q is lower -<% } %> - ; If equal substract q -rawAddLS_sq: -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "sub" : "sbb" %> [rdi + <%=i*8%>], rax -<% } %> -rawAddLS_done: - ret - - - - diff --git a/ports/c/buildasm/binops.asm.ejs b/ports/c/buildasm/binops.asm.ejs deleted file mode 100644 index 4001893..0000000 --- a/ports/c/buildasm/binops.asm.ejs +++ /dev/null @@ -1,240 +0,0 @@ -<% function binOpSubQIfBigger() { %> - <% const subQ = global.tmpLabel() %> - <% const done = global.tmpLabel() %> - - ; Compare with q -<% for (let i=0; i - mov rax, [rdi + <%= (n64-i)*8 %>] - cmp rax, [q + <%= (n64-i-1)*8 %>] - jc <%=done%> ; q is bigget so done. - jnz <%=subQ%> ; q is lower -<% } %> - ; If equal substract q -<%=subQ%>: -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "sub" : "sbb" %> [rdi + <%=i*8 + 8 %>], rax -<% } %> -<%=done%>: -<% } %> - - -<% function binOpS1S2(op) { %> - cmp r8d, 0 - <% const s1s2_solveNeg = global.tmpLabel() %> - js <%=s1s2_solveNeg%> - - cmp r9d, 0 - js <%=s1s2_solveNeg%> - xor rdx, rdx ; both ops are positive so do the op and return - mov edx, r8d - <%=op%> edx, r9d - mov [rdi], rdx ; not necessary to adjust so just save and return - ret - -<%=s1s2_solveNeg%>: -<%= global.setTypeDest("0x80"); %> -<%= global.toLong_b() %> -<%= global.toLong_a() %> -<%= binOpL1L2(op) %> - - -<% } %> - -<% function binOpS1L2(op) { %> - cmp r8d, 0 - <% const s1l2_solveNeg = global.tmpLabel() %> - js <%=s1l2_solveNeg%> - movsx rax, r8d - <%=op%> rax, [rdx +8] - mov [rdi+8], rax -<% for (let i=1; i - xor rax, rax - <%=op%> rax, [rdx + <%= (i*8)+8 %>] -<% if (i== n64-1) { %> - and rax, [lboMask] -<% } %> - mov [rdi + <%= (i*8)+8 %> ], rax -<% } %> -<% binOpSubQIfBigger() %> - ret - -<%=s1l2_solveNeg%>: -<%= global.toLong_a() %> -<%= global.setTypeDest("0x80"); %> -<%= binOpL1L2(op) %> - -<% } %> - -<% function binOpL1S2(op) { %> - cmp r9d, 0 - <% const l1s2_solveNeg = global.tmpLabel() %> - js <%=l1s2_solveNeg%> - movsx rax, r9d - <%=op%> rax, [rsi +8] - mov [rdi+8], rax -<% for (let i=1; i - xor rax, rax - <%=op%> rax, [rsi + <%= (i*8)+8 %>]; -<% if (i== n64-1) { %> - and rax, [lboMask] ; -<% } %> - mov [rdi + <%= (i*8)+8 %> ], rax; -<% } %> -<% binOpSubQIfBigger() %> - ret - -<%=l1s2_solveNeg%>: -<%= global.toLong_b() %> -<%= global.setTypeDest("0x80"); %> -<%= binOpL1L2(op) %> - -<% } %> - -<% function binOpL1L2(op) { %> -<% for (let i=0; i - mov rax, [rsi + <%= (i*8)+8 %>] - <%=op%> rax, [rdx + <%= (i*8)+8 %>] -<% if (i== n64-1) { %> - and rax, [lboMask] -<% } %> - mov [rdi + <%= (i*8)+8 %> ], rax -<% } %> -<% binOpSubQIfBigger() %> - ret -<% } %> - - -<% function binOp(op) { %> -;;;;;;;;;;;;;;;;;;;;;; -; b<%= op %> -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_b<%=op%>: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc <%=op%>_l1 - bt r9, 63 ; Check if is short second operand - jc <%=op%>_s1l2 - -<%=op%>_s1s2: -<%= binOpS1S2(op) %> - - -<%=op%>_l1: - bt r9, 63 ; Check if is short second operand - jc <%=op%>_l1l2 - - -<%=op%>_l1s2: - bt r8, 62 ; check if montgomery first - jc <%=op%>_l1ms2 -<%=op%>_l1ns2: -<%= global.setTypeDest("0x80"); %> -<%= binOpL1S2(op) %> - -<%=op%>_l1ms2: -<%= global.setTypeDest("0x80"); %> - push r9 ; r9 is used in montgomery so we need to save it -<%= global.fromMont_a() %> - pop r9 -<%= binOpL1S2(op) %> - - -<%=op%>_s1l2: - bt r9, 62 ; check if montgomery first - jc <%=op%>_s1l2m -<%=op%>_s1l2n: -<%= global.setTypeDest("0x80"); %> -<%= binOpS1L2(op) %> - -<%=op%>_s1l2m: -<%= global.setTypeDest("0x80"); %> - push r8 ; r8 is used in montgomery so we need to save it -<%= global.fromMont_b() %> - pop r8 -<%= binOpS1L2(op) %> - - -<%=op%>_l1l2: - bt r8, 62 ; check if montgomery first - jc <%=op%>_l1ml2 - bt r9, 62 ; check if montgomery first - jc <%=op%>_l1nl2m -<%=op%>_l1nl2n: -<%= global.setTypeDest("0x80"); %> -<%= binOpL1L2(op) %> - -<%=op%>_l1nl2m: -<%= global.setTypeDest("0x80"); %> -<%= global.fromMont_b() %> -<%= binOpL1L2(op) %> - -<%=op%>_l1ml2: - bt r9, 62 ; check if montgomery first - jc <%=op%>_l1ml2m -<%=op%>_l1ml2n: -<%= global.setTypeDest("0x80"); %> -<%= global.fromMont_a() %> -<%= binOpL1L2(op) %> - -<%=op%>_l1ml2m: -<%= global.setTypeDest("0x80"); %> -<%= global.fromMont_a() %> -<%= global.fromMont_b() %> -<%= binOpL1L2(op) %> -<% } %> - -<%= binOp("and") %> -<%= binOp("or") %> -<%= binOp("xor") %> - - -;;;;;;;;;;;;;;;;;;;;;; -; bnot -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_bnot: - <%= global.setTypeDest("0x80"); %> - - mov r8, [rsi] - bt r8, 63 ; Check if is long operand - jc bnot_l1 -bnot_s: - <%= global.toLong_a() %> - jmp bnot_l1n - -bnot_l1: - bt r8, 62 ; check if montgomery first - jnc bnot_l1n - -bnot_l1m: -<%= global.fromMont_a() %> - -bnot_l1n: -<% for (let i=0; i - mov rax, [rsi + <%= i*8 + 8 %>] - not rax -<% if (i== n64-1) { %> - and rax, [lboMask] -<% } %> - mov [rdi + <%= i*8 + 8 %>], rax -<% } %> -<% binOpSubQIfBigger() %> - ret - - diff --git a/ports/c/buildasm/buildzqfield.js b/ports/c/buildasm/buildzqfield.js deleted file mode 100644 index e223bac..0000000 --- a/ports/c/buildasm/buildzqfield.js +++ /dev/null @@ -1,72 +0,0 @@ -const bigInt=require("big-integer"); -const path = require("path"); -const util = require("util"); -const renderFile = util.promisify(require("ejs").renderFile); - -const runningAsScript = !module.parent; - - -class ZqBuilder { - constructor(q, name) { - const self = this; - this.q=bigInt(q); - this.n64 = Math.floor((this.q.bitLength() - 1) / 64)+1; - this.name = name; - this.bigInt = bigInt; - this.lastTmp=0; - this.global = {}; - this.global.tmpLabel = function(label) { - self.lastTmp++; - label = label || "tmp"; - return label+"_"+self.lastTmp; - }; - } - - constantElement(v) { - let S = ""; - const mask = bigInt("FFFFFFFFFFFFFFFF", 16); - for (let i=0; i0) S = S+","; - let shex = v.shiftRight(i*64).and(mask).toString(16); - while (shex.length <16) shex = "0" + shex; - S = S + "0x" + shex; - } - return S; - } - -} - -async function buildField(q, name) { - const builder = new ZqBuilder(q, name); - - const asm = await renderFile(path.join(__dirname, "fr.asm.ejs"), builder); - const c = await renderFile(path.join(__dirname, "fr.c.ejs"), builder); - const h = await renderFile(path.join(__dirname, "fr.h.ejs"), builder); - - return {asm: asm, h: h, c: c}; -} - -if (runningAsScript) { - const fs = require("fs"); - var argv = require("yargs") - .usage("Usage: $0 -q [primeNum] -n [name] -oc [out .c file] -oh [out .h file]") - .demandOption(["q","n"]) - .alias("q", "prime") - .alias("n", "name") - .argv; - - const q = bigInt(argv.q); - - const asmFileName = (argv.oc) ? argv.oc : argv.name.toLowerCase() + ".asm"; - const hFileName = (argv.oc) ? argv.oc : argv.name.toLowerCase() + ".h"; - const cFileName = (argv.oc) ? argv.oc : argv.name.toLowerCase() + ".c"; - - buildField(q, argv.name).then( (res) => { - fs.writeFileSync(asmFileName, res.asm, "utf8"); - fs.writeFileSync(hFileName, res.h, "utf8"); - fs.writeFileSync(cFileName, res.c, "utf8"); - }); - -} else { - module.exports = buildField; -} diff --git a/ports/c/buildasm/buildzqfieldtester.js b/ports/c/buildasm/buildzqfieldtester.js deleted file mode 100644 index eff7d2a..0000000 --- a/ports/c/buildasm/buildzqfieldtester.js +++ /dev/null @@ -1,75 +0,0 @@ -const chai = require("chai"); -const assert = chai.assert; - -const fs = require("fs"); -var tmp = require("tmp-promise"); -const path = require("path"); -const util = require("util"); -const exec = util.promisify(require("child_process").exec); - -const BuildZqField = require("./buildzqfield"); - -module.exports = testField; - -async function testField(prime, test) { - tmp.setGracefulCleanup(); - - const dir = await tmp.dir({prefix: "circom_", unsafeCleanup: true }); - - const source = await BuildZqField(prime, "Fr"); - - // console.log(dir.path); - - await fs.promises.writeFile(path.join(dir.path, "fr.asm"), source.asm, "utf8"); - await fs.promises.writeFile(path.join(dir.path, "fr.h"), source.h, "utf8"); - await fs.promises.writeFile(path.join(dir.path, "fr.c"), source.c, "utf8"); - - await exec(`cp ${path.join(__dirname, "tester.cpp")} ${dir.path}`); - - await exec("nasm -fmacho64 --prefix _ " + - ` ${path.join(dir.path, "fr.asm")}` - ); - - await exec("g++" + - ` ${path.join(dir.path, "tester.cpp")}` + - ` ${path.join(dir.path, "fr.o")}` + - ` ${path.join(dir.path, "fr.c")}` + - ` -o ${path.join(dir.path, "tester")}` + - " -lgmp -g" - ); - - const inLines = []; - for (let i=0; i${path.join(dir.path, "out.tst")}`); - - const res = await fs.promises.readFile(path.join(dir.path, "out.tst"), "utf8"); - const resLines = res.split("\n"); - - for (let i=0; i -<% for (let i=n64-1; i>=0; i--) { %> - mov rax, [<%=reg%> + <%= 8+(i*8) %>] - cmp [half + <%= (i*8) %>], rax ; comare with (q-1)/2 - jc <%=label_neg%> ; half e1-e2 is neg => e1 < e2 -<% if (i>0) { %> - jnz <%=label_pos%> ; half>rax => e1 -e2 is pos => e1 > e2 -<% } else { %> - jmp <%=label_pos%> -<% } %> -<% } %> -<% } %> - - -;;;;;;;;;;;;;;;;;;;;;; -; rgt - Raw Greater Than -;;;;;;;;;;;;;;;;;;;;;; -; returns in ax 1 id *rsi > *rdx -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rax <= Return 1 or 0 -; Modified Registers: -; r8, r9, rax -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_rgt: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc rgt_l1 - bt r9, 63 ; Check if is short second operand - jc rgt_s1l2 - -rgt_s1s2: ; Both operands are short - cmp r8d, r9d - jg rgt_ret1 - jmp rgt_ret0 - - -rgt_l1: - bt r9, 63 ; Check if is short second operand - jc rgt_l1l2 - -;;;;;;;; -rgt_l1s2: - bt r8, 62 ; check if montgomery first - jc rgt_l1ms2 -rgt_l1ns2: -<%= global.toLong_b() %> - jmp rgtL1L2 - -rgt_l1ms2: -<%= global.toLong_b() %> -<%= global.fromMont_a() %> - jmp rgtL1L2 - - -;;;;;;;; -rgt_s1l2: - bt r9, 62 ; check if montgomery second - jc rgt_s1l2m -rgt_s1l2n: -<%= global.toLong_a() %> - jmp rgtL1L2 - -rgt_s1l2m: -<%= global.toLong_a() %> -<%= global.fromMont_b() %> - jmp rgtL1L2 - -;;;; -rgt_l1l2: - bt r8, 62 ; check if montgomery first - jc rgt_l1ml2 -rgt_l1nl2: - bt r9, 62 ; check if montgomery second - jc rgt_l1nl2m -rgt_l1nl2n: - jmp rgtL1L2 - -rgt_l1nl2m: -<%= global.fromMont_b() %> - jmp rgtL1L2 - -rgt_l1ml2: - bt r9, 62 ; check if montgomery second - jc rgt_l1ml2m -rgt_l1ml2n: -<%= global.fromMont_a() %> - jmp rgtL1L2 - -rgt_l1ml2m: -<%= global.fromMont_a() %> -<%= global.fromMont_b() %> - jmp rgtL1L2 - - -;;;;;; -; rgtL1L2 -;;;;;; - -rgtL1L2: -<%= signL("rsi", "rgtl1l2_p1", "rgtl1l2_n1") %> -rgtl1l2_p1: -<%= signL("rdx", "rgtRawL1L2", "rgt_ret1") %> - -rgtl1l2_n1: -<%= signL("rdx", "rgt_ret0", "rgtRawL1L2") %> - - -rgtRawL1L2: -<% for (let i=n64-1; i>=0; i--) { %> - mov rax, [rsi + <%= 8+(i*8) %>] - cmp [rdx + <%= 8+(i*8) %>], rax ; comare with (q-1)/2 - jc rgt_ret1 ; rsi 1st > 2nd -<% if (i>0) { %> - jnz rgt_ret0 -<% } %> -<% } %> - -rgt_ret0: - xor rax, rax - ret -rgt_ret1: - mov rax, 1 - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; rlt - Raw Less Than -;;;;;;;;;;;;;;;;;;;;;; -; returns in ax 1 id *rsi > *rdx -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rax <= Return 1 or 0 -; Modified Registers: -; r8, r9, rax -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_rlt: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc rlt_l1 - bt r9, 63 ; Check if is short second operand - jc rlt_s1l2 - -rlt_s1s2: ; Both operands are short - cmp r8d, r9d - jl rlt_ret1 - jmp rlt_ret0 - - -rlt_l1: - bt r9, 63 ; Check if is short second operand - jc rlt_l1l2 - -;;;;;;;; -rlt_l1s2: - bt r8, 62 ; check if montgomery first - jc rlt_l1ms2 -rlt_l1ns2: -<%= global.toLong_b() %> - jmp rltL1L2 - -rlt_l1ms2: -<%= global.toLong_b() %> -<%= global.fromMont_a() %> - jmp rltL1L2 - - -;;;;;;;; -rlt_s1l2: - bt r9, 62 ; check if montgomery second - jc rlt_s1l2m -rlt_s1l2n: -<%= global.toLong_a() %> - jmp rltL1L2 - -rlt_s1l2m: -<%= global.toLong_a() %> -<%= global.fromMont_b() %> - jmp rltL1L2 - -;;;; -rlt_l1l2: - bt r8, 62 ; check if montgomery first - jc rlt_l1ml2 -rlt_l1nl2: - bt r9, 62 ; check if montgomery second - jc rlt_l1nl2m -rlt_l1nl2n: - jmp rltL1L2 - -rlt_l1nl2m: -<%= global.fromMont_b() %> - jmp rltL1L2 - -rlt_l1ml2: - bt r9, 62 ; check if montgomery second - jc rlt_l1ml2m -rlt_l1ml2n: -<%= global.fromMont_a() %> - jmp rltL1L2 - -rlt_l1ml2m: -<%= global.fromMont_a() %> -<%= global.fromMont_b() %> - jmp rltL1L2 - - -;;;;;; -; rltL1L2 -;;;;;; - -rltL1L2: -<%= signL("rsi", "rltl1l2_p1", "rltl1l2_n1") %> -rltl1l2_p1: -<%= signL("rdx", "rltRawL1L2", "rlt_ret0") %> - -rltl1l2_n1: -<%= signL("rdx", "rlt_ret1", "rltRawL1L2") %> - - -rltRawL1L2: -<% for (let i=n64-1; i>=0; i--) { %> - mov rax, [rsi + <%= 8+(i*8) %>] - cmp [rdx + <%= 8+(i*8) %>], rax ; comare with (q-1)/2 - jc rlt_ret0 ; rsi 1st > 2nd - jnz rlt_ret1 -<% } %> - -rlt_ret0: - xor rax, rax - ret -rlt_ret1: - mov rax, 1 - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; req - Raw Eq -;;;;;;;;;;;;;;;;;;;;;; -; returns in ax 1 id *rsi == *rdx -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rax <= Return 1 or 0 -; Modified Registers: -; r8, r9, rax -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_req: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc req_l1 - bt r9, 63 ; Check if is short second operand - jc req_s1l2 - -req_s1s2: ; Both operands are short - cmp r8d, r9d - je req_ret1 - jmp req_ret0 - - -req_l1: - bt r9, 63 ; Check if is short second operand - jc req_l1l2 - -;;;;;;;; -req_l1s2: - bt r8, 62 ; check if montgomery first - jc req_l1ms2 -req_l1ns2: -<%= global.toLong_b() %> - jmp reqL1L2 - -req_l1ms2: -<%= global.toMont_b() %> - jmp reqL1L2 - - -;;;;;;;; -req_s1l2: - bt r9, 62 ; check if montgomery second - jc req_s1l2m -req_s1l2n: -<%= global.toLong_a() %> - jmp reqL1L2 - -req_s1l2m: -<%= global.toMont_a() %> - jmp reqL1L2 - -;;;; -req_l1l2: - bt r8, 62 ; check if montgomery first - jc req_l1ml2 -req_l1nl2: - bt r9, 62 ; check if montgomery second - jc req_l1nl2m -req_l1nl2n: - jmp reqL1L2 - -req_l1nl2m: -<%= global.toMont_a() %> - jmp reqL1L2 - -req_l1ml2: - bt r9, 62 ; check if montgomery second - jc req_l1ml2m -req_l1ml2n: -<%= global.toMont_b() %> - jmp reqL1L2 - -req_l1ml2m: - jmp reqL1L2 - - -;;;;;; -; eqL1L2 -;;;;;; - -reqL1L2: -<% for (let i=0; i - mov rax, [rsi + <%= 8+(i*8) %>] - cmp [rdx + <%= 8+(i*8) %>], rax - jne req_ret0 ; rsi 1st > 2nd -<% } %> - -req_ret1: - mov rax, 1 - ret - -req_ret0: - xor rax, rax - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; gt -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_gt: - call <%=name%>_rgt - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; lt -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_lt: - call <%=name%>_rlt - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; eq -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_eq: - call <%=name%>_req - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; neq -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_neq: - call <%=name%>_req - xor rax, 1 - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; geq -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_geq: - call <%=name%>_rlt - xor rax, 1 - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; leq -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_leq: - call <%=name%>_rgt - xor rax, 1 - mov [rdi], rax - ret diff --git a/ports/c/buildasm/cmpops_old.asm.ejs b/ports/c/buildasm/cmpops_old.asm.ejs deleted file mode 100644 index 420bdce..0000000 --- a/ports/c/buildasm/cmpops_old.asm.ejs +++ /dev/null @@ -1,108 +0,0 @@ - -<% function retOne() { %> - mov qword [rdi], 1 - add rsp, <%= (n64+1)*8 %> - ret -<% } %> - -<% function retZero() { %> - mov qword [rdi], 0 - add rsp, <%= (n64+1)*8 %> - ret -<% } %> - -<% function cmpLong(op, eq) { %> - -<% - if (eq==true) { - if (["leq","geq"].indexOf(op) >= 0) retOne(); - if (["lt","gt"].indexOf(op) >= 0) retZero(); - } -%> - - -<% const label_gt = global.tmpLabel() %> -<% const label_lt = global.tmpLabel() %> -<% for (let i=n64-1; i>=0; i--) { %> - mov rax, [rsp + <%= 8+(i*8) %>] - cmp [half + <%= (i*8) %>], rax ; comare with (q-1)/2 - jc <%=label_lt%> ; half e1-e2 is neg => e1 < e2 - jnz <%=label_gt%> ; half>rax => e1 -e2 is pos => e1 > e2 -<% } %> - ; half == rax => e1-e2 is pos => e1 > e2 -<%=label_gt%>: -<% if (["geq","gt"].indexOf(op) >= 0) retOne(); else retZero(); %> -<%=label_lt%>: -<% if (["leq","lt"].indexOf(op) >= 0) retOne(); else retZero(); %> -<% } // cmpLong%> - -<% function cmpOp(op) { %> -;;;;;;;;;;;;;;;;;;;;;; -; <%= op %> -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_<%=op%>: - sub rsp, <%= (n64+1)*8 %> ; Save space for the result of the substraction - push rdi ; Save rdi - lea rdi, [rsp+8] ; We pushed rdi so we need to add 8 - call <%=name%>_sub ; Do a substraction - call <%=name%>_toNormal ; Convert it to normal - pop rdi - - mov rax, [rsp] ; We already poped do no need to add 8 - bt rax, 63 ; check is result is long - jc <%=op%>_longCmp - -<%=op%>_shortCmp: - cmp eax, 0 - je <%=op%>_s_eq - js <%=op%>_s_lt -<%=op%>_s_gt: -<% if (["geq","gt", "neq"].indexOf(op) >= 0) retOne(); else retZero(); %> -<%=op%>_s_lt: -<% if (["leq","lt", "neq"].indexOf(op) >= 0) retOne(); else retZero(); %> -<%=op%>_s_eq: -<% if (["eq","geq", "leq"].indexOf(op) >= 0) retOne(); else retZero(); %> - -<%=op%>_longCmp: - -<% for (let i=n64-1; i>=0; i--) { %> - cmp qword [rsp + <%= 8+(i*8) %>], 0 - jnz <%=op%>_neq -<% } %> -<%=op%>_eq: -<% if (op == "eq") { - retOne(); - } else if (op == "neq") { - retZero(); - } else { - cmpLong(op, true); - } -%> -<%=op%>_neq: -<% if (op == "neq") { - retOne(); - } else if (op == "eq") { - retZero(); - } else { - cmpLong(op, false); - } -%> - - -<% } %> - -<%= cmpOp("eq") %> -<%= cmpOp("neq") %> -<%= cmpOp("lt") %> -<%= cmpOp("gt") %> -<%= cmpOp("leq") %> -<%= cmpOp("geq") %> - diff --git a/ports/c/buildasm/copy.asm.ejs b/ports/c/buildasm/copy.asm.ejs deleted file mode 100644 index a9623ed..0000000 --- a/ports/c/buildasm/copy.asm.ejs +++ /dev/null @@ -1,139 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;; -; copy -;;;;;;;;;;;;;;;;;;;;;; -; Copies -; Params: -; rsi <= the src -; rdi <= the dest -; -; Nidified registers: -; rax -;;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_copy: -<% for (let i=0; i<=n64; i++) { %> - mov rax, [rsi + <%= i*8 %>] - mov [rdi + <%= i*8 %>], rax -<% } %> - ret - -;;;;;;;;;;;;;;;;;;;;;; -; copy an array of integers -;;;;;;;;;;;;;;;;;;;;;; -; Copies -; Params: -; rsi <= the src -; rdi <= the dest -; rdx <= number of integers to copy -; -; Nidified registers: -; rax -;;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_copyn: -<%=name%>_copyn_loop: - mov r8, rsi - mov r9, rdi - mov rax, <%= n64+1 %> - mul rdx - mov rcx, rax - cld - rep movsq - mov rsi, r8 - mov rdi, r9 - ret - -;;;;;;;;;;;;;;;;;;;;;; -; rawCopyS2L -;;;;;;;;;;;;;;;;;;;;;; -; Convert a 64 bit integer to a long format field element -; Params: -; rsi <= the integer -; rdi <= Pointer to the overwritted element -; -; Nidified registers: -; rax -;;;;;;;;;;;;;;;;;;;;;;; - -rawCopyS2L: - mov al, 0x80 - shl rax, 56 - mov [rdi], rax ; set the result to LONG normal - - cmp rsi, 0 - js u64toLong_adjust_neg - - mov [rdi + 8], rsi - xor rax, rax -<% for (let i=1; i - mov [rdi + <%= 8+i*8 %>], rax -<% } %> - ret - -u64toLong_adjust_neg: - add rsi, [q] ; Set the first digit - mov [rdi + 8], rsi ; - - mov rsi, -1 ; all ones -<% for (let i=1; i - mov rax, rsi ; Add to q - adc rax, [q + <%= i*8 %> ] - mov [rdi + <%= (i+1)*8 %>], rax -<% } %> - ret - -;;;;;;;;;;;;;;;;;;;;;; -; toInt -;;;;;;;;;;;;;;;;;;;;;; -; Convert a 64 bit integer to a long format field element -; Params: -; rsi <= Pointer to the element -; Returs: -; rax <= The value -;;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_toInt: - mov rax, [rdi] - bt rax, 63 - jc <%=name%>_long - movsx rax, eax - ret - -<%=name%>_long: - bt rax, 62 - jnc <%=name%>_longNormal -<%=name%>_longMontgomery: - call <%=name%>_toLongNormal - -<%=name%>_longNormal: - mov rax, [rdi + 8] - mov rcx, rax - shr rcx, 31 - jnz <%=name%>_longNeg -<% for (let i=1; i< n64; i++) { %> - mov rcx, [rdi + <%= i*8+8 %>] - test rcx, rcx - jnz <%=name%>_longNeg -<% } %> - ret - -<%=name%>_longNeg: - mov rax, [rdi + 8] - sub rax, [q] - jnc <%=name%>_longErr -<% for (let i=1; i - mov rcx, [rdi + <%= i*8+8 %>] - sbb rcx, [q + <%= i*8 %>] - jnc <%=name%>_longErr -<% } %> - mov rcx, rax - sar rcx, 31 - add rcx, 1 - jnz <%=name%>_longErr - ret - -<%=name%>_longErr: - push rdi - mov rdi, 0 - call <%=name%>_fail - pop rdi - - - diff --git a/ports/c/buildasm/fr.asm b/ports/c/buildasm/fr.asm deleted file mode 100644 index 180cd8d..0000000 --- a/ports/c/buildasm/fr.asm +++ /dev/null @@ -1,7607 +0,0 @@ - - - global Fr_copy - global Fr_copyn - global Fr_add - global Fr_sub - global Fr_neg - global Fr_mul - global Fr_square - global Fr_band - global Fr_bor - global Fr_bxor - global Fr_bnot - global Fr_eq - global Fr_neq - global Fr_lt - global Fr_gt - global Fr_leq - global Fr_geq - global Fr_land - global Fr_lor - global Fr_lnot - global Fr_toNormal - global Fr_toLongNormal - global Fr_toMontgomery - global Fr_toInt - global Fr_isTrue - global Fr_q - extern Fr_fail - DEFAULT REL - - section .text - - - - - - - - - - - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; copy -;;;;;;;;;;;;;;;;;;;;;; -; Copies -; Params: -; rsi <= the src -; rdi <= the dest -; -; Nidified registers: -; rax -;;;;;;;;;;;;;;;;;;;;;;; -Fr_copy: - - mov rax, [rsi + 0] - mov [rdi + 0], rax - - mov rax, [rsi + 8] - mov [rdi + 8], rax - - mov rax, [rsi + 16] - mov [rdi + 16], rax - - mov rax, [rsi + 24] - mov [rdi + 24], rax - - mov rax, [rsi + 32] - mov [rdi + 32], rax - - ret - -;;;;;;;;;;;;;;;;;;;;;; -; copy an array of integers -;;;;;;;;;;;;;;;;;;;;;; -; Copies -; Params: -; rsi <= the src -; rdi <= the dest -; rdx <= number of integers to copy -; -; Nidified registers: -; rax -;;;;;;;;;;;;;;;;;;;;;;; -Fr_copyn: -Fr_copyn_loop: - mov r8, rsi - mov r9, rdi - mov rax, 5 - mul rdx - mov rcx, rax - cld - rep movsq - mov rsi, r8 - mov rdi, r9 - ret - -;;;;;;;;;;;;;;;;;;;;;; -; rawCopyS2L -;;;;;;;;;;;;;;;;;;;;;; -; Convert a 64 bit integer to a long format field element -; Params: -; rsi <= the integer -; rdi <= Pointer to the overwritted element -; -; Nidified registers: -; rax -;;;;;;;;;;;;;;;;;;;;;;; - -rawCopyS2L: - mov al, 0x80 - shl rax, 56 - mov [rdi], rax ; set the result to LONG normal - - cmp rsi, 0 - js u64toLong_adjust_neg - - mov [rdi + 8], rsi - xor rax, rax - - mov [rdi + 16], rax - - mov [rdi + 24], rax - - mov [rdi + 32], rax - - ret - -u64toLong_adjust_neg: - add rsi, [q] ; Set the first digit - mov [rdi + 8], rsi ; - - mov rsi, -1 ; all ones - - mov rax, rsi ; Add to q - adc rax, [q + 8 ] - mov [rdi + 16], rax - - mov rax, rsi ; Add to q - adc rax, [q + 16 ] - mov [rdi + 24], rax - - mov rax, rsi ; Add to q - adc rax, [q + 24 ] - mov [rdi + 32], rax - - ret - -;;;;;;;;;;;;;;;;;;;;;; -; toInt -;;;;;;;;;;;;;;;;;;;;;; -; Convert a 64 bit integer to a long format field element -; Params: -; rsi <= Pointer to the element -; Returs: -; rax <= The value -;;;;;;;;;;;;;;;;;;;;;;; -Fr_toInt: - mov rax, [rdi] - bt rax, 63 - jc Fr_long - movsx rax, eax - ret - -Fr_long: - bt rax, 62 - jnc Fr_longNormal -Fr_longMontgomery: - call Fr_toLongNormal - -Fr_longNormal: - mov rax, [rdi + 8] - mov rcx, rax - shr rcx, 31 - jnz Fr_longNeg - - mov rcx, [rdi + 16] - test rcx, rcx - jnz Fr_longNeg - - mov rcx, [rdi + 24] - test rcx, rcx - jnz Fr_longNeg - - mov rcx, [rdi + 32] - test rcx, rcx - jnz Fr_longNeg - - ret - -Fr_longNeg: - mov rax, [rdi + 8] - sub rax, [q] - jnc Fr_longErr - - mov rcx, [rdi + 16] - sbb rcx, [q + 8] - jnc Fr_longErr - - mov rcx, [rdi + 24] - sbb rcx, [q + 16] - jnc Fr_longErr - - mov rcx, [rdi + 32] - sbb rcx, [q + 24] - jnc Fr_longErr - - mov rcx, rax - sar rcx, 31 - add rcx, 1 - jnz Fr_longErr - ret - -Fr_longErr: - push rdi - mov rdi, 0 - call Fr_fail - pop rdi - - - - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; rawMontgomeryMul -;;;;;;;;;;;;;;;;;;;;;; -; Multiply two elements in montgomery form -; Params: -; rsi <= Pointer to the long data of element 1 -; rdx <= Pointer to the long data of element 2 -; rdi <= Pointer to the long data of result -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; - -rawMontgomeryMul: - sub rsp, 32 ; Reserve space for ms - mov rcx, rdx ; rdx is needed for multiplications so keep it in cx - mov r11, 0xc2e1f593efffffff ; np - xor r8,r8 - xor r9,r9 - xor r10,r10 - - mov rax, [rsi + 0] - mul qword [rcx + 0] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - - - mov rax, r8 - mul r11 - mov [rsp + 0], rax - mul qword [q] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, [rsi + 0] - mul qword [rcx + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsi + 8] - mul qword [rcx + 0] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, [rsp + 0] - mul qword [q + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, r9 - mul r11 - mov [rsp + 8], rax - mul qword [q] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, [rsi + 0] - mul qword [rcx + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsi + 8] - mul qword [rcx + 8] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsi + 16] - mul qword [rcx + 0] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, [rsp + 8] - mul qword [q + 8] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsp + 0] - mul qword [q + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, r10 - mul r11 - mov [rsp + 16], rax - mul qword [q] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, [rsi + 0] - mul qword [rcx + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsi + 8] - mul qword [rcx + 16] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsi + 16] - mul qword [rcx + 8] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsi + 24] - mul qword [rcx + 0] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, [rsp + 16] - mul qword [q + 8] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsp + 8] - mul qword [q + 16] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsp + 0] - mul qword [q + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, r8 - mul r11 - mov [rsp + 24], rax - mul qword [q] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, [rsi + 8] - mul qword [rcx + 24] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsi + 16] - mul qword [rcx + 16] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsi + 24] - mul qword [rcx + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, [rsp + 24] - mul qword [q + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsp + 16] - mul qword [q + 16] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsp + 8] - mul qword [q + 24] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov [rdi + 0 ], r9 - xor r9,r9 - - - - mov rax, [rsi + 16] - mul qword [rcx + 24] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsi + 24] - mul qword [rcx + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, [rsp + 24] - mul qword [q + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsp + 16] - mul qword [q + 24] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov [rdi + 8 ], r10 - xor r10,r10 - - - - mov rax, [rsi + 24] - mul qword [rcx + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, [rsp + 24] - mul qword [q + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov [rdi + 16 ], r8 - xor r8,r8 - - - - - - - - mov [rdi + 24 ], r9 - xor r9,r9 - - - - test r10, r10 - jnz rawMontgomeryMul_mulM_sq - ; Compare with q - - mov rax, [rdi + 24] - cmp rax, [q + 24] - jc rawMontgomeryMul_mulM_done ; q is bigget so done. - jnz rawMontgomeryMul_mulM_sq ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 16] - jc rawMontgomeryMul_mulM_done ; q is bigget so done. - jnz rawMontgomeryMul_mulM_sq ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 8] - jc rawMontgomeryMul_mulM_done ; q is bigget so done. - jnz rawMontgomeryMul_mulM_sq ; q is lower - - mov rax, [rdi + 0] - cmp rax, [q + 0] - jc rawMontgomeryMul_mulM_done ; q is bigget so done. - jnz rawMontgomeryMul_mulM_sq ; q is lower - - ; If equal substract q - -rawMontgomeryMul_mulM_sq: - - mov rax, [q + 0] - sub [rdi + 0], rax - - mov rax, [q + 8] - sbb [rdi + 8], rax - - mov rax, [q + 16] - sbb [rdi + 16], rax - - mov rax, [q + 24] - sbb [rdi + 24], rax - - -rawMontgomeryMul_mulM_done: - mov rdx, rcx ; recover rdx to its original place. - add rsp, 32 ; recover rsp - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; rawMontgomerySquare -;;;;;;;;;;;;;;;;;;;;;; -; Square an element -; Params: -; rsi <= Pointer to the long data of element 1 -; rdi <= Pointer to the long data of result -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; - -rawMontgomerySquare: - sub rsp, 32 ; Reserve space for ms - mov rcx, rdx ; rdx is needed for multiplications so keep it in cx - mov r11, 0xc2e1f593efffffff ; np - xor r8,r8 - xor r9,r9 - xor r10,r10 - - - - mov rax, [rsi + 0] - mul rax - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - - - - - mov rax, r8 - mul r11 - mov [rsp + 0], rax - mul qword [q] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, [rsi + 0] - mul qword [rsi + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - - - - - mov rax, [rsp + 0] - mul qword [q + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, r9 - mul r11 - mov [rsp + 8], rax - mul qword [q] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, [rsi + 0] - mul qword [rsi + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, [rsi + 8] - mul rax - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - - - mov rax, [rsp + 8] - mul qword [q + 8] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsp + 0] - mul qword [q + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, r10 - mul r11 - mov [rsp + 16], rax - mul qword [q] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, [rsi + 0] - mul qword [rsi + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsi + 8] - mul qword [rsi + 16] - add r8, rax - adc r9, rdx - adc r10, 0x0 - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - - - - - mov rax, [rsp + 16] - mul qword [q + 8] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsp + 8] - mul qword [q + 16] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsp + 0] - mul qword [q + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, r8 - mul r11 - mov [rsp + 24], rax - mul qword [q] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, [rsi + 8] - mul qword [rsi + 24] - add r9, rax - adc r10, rdx - adc r8, 0x0 - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, [rsi + 16] - mul rax - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - - - mov rax, [rsp + 24] - mul qword [q + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsp + 16] - mul qword [q + 16] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsp + 8] - mul qword [q + 24] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov [rdi + 0 ], r9 - xor r9,r9 - - - - mov rax, [rsi + 16] - mul qword [rsi + 24] - add r10, rax - adc r8, rdx - adc r9, 0x0 - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - - - - - mov rax, [rsp + 24] - mul qword [q + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsp + 16] - mul qword [q + 24] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov [rdi + 8 ], r10 - xor r10,r10 - - - - - - mov rax, [rsi + 24] - mul rax - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - - - mov rax, [rsp + 24] - mul qword [q + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov [rdi + 16 ], r8 - xor r8,r8 - - - - - - - - - - - - mov [rdi + 24 ], r9 - xor r9,r9 - - - - test r10, r10 - jnz rawMontgomerySquare_mulM_sq - ; Compare with q - - mov rax, [rdi + 24] - cmp rax, [q + 24] - jc rawMontgomerySquare_mulM_done ; q is bigget so done. - jnz rawMontgomerySquare_mulM_sq ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 16] - jc rawMontgomerySquare_mulM_done ; q is bigget so done. - jnz rawMontgomerySquare_mulM_sq ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 8] - jc rawMontgomerySquare_mulM_done ; q is bigget so done. - jnz rawMontgomerySquare_mulM_sq ; q is lower - - mov rax, [rdi + 0] - cmp rax, [q + 0] - jc rawMontgomerySquare_mulM_done ; q is bigget so done. - jnz rawMontgomerySquare_mulM_sq ; q is lower - - ; If equal substract q - -rawMontgomerySquare_mulM_sq: - - mov rax, [q + 0] - sub [rdi + 0], rax - - mov rax, [q + 8] - sbb [rdi + 8], rax - - mov rax, [q + 16] - sbb [rdi + 16], rax - - mov rax, [q + 24] - sbb [rdi + 24], rax - - -rawMontgomerySquare_mulM_done: - mov rdx, rcx ; recover rdx to its original place. - add rsp, 32 ; recover rsp - ret - - - - -;;;;;;;;;;;;;;;;;;;;;; -; rawMontgomeryMul1 -;;;;;;;;;;;;;;;;;;;;;; -; Multiply two elements in montgomery form -; Params: -; rsi <= Pointer to the long data of element 1 -; rdx <= second operand -; rdi <= Pointer to the long data of result -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; - -rawMontgomeryMul1: - sub rsp, 32 ; Reserve space for ms - mov rcx, rdx ; rdx is needed for multiplications so keep it in cx - mov r11, 0xc2e1f593efffffff ; np - xor r8,r8 - xor r9,r9 - xor r10,r10 - - mov rax, [rsi + 0] - mul rcx - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - - - mov rax, r8 - mul r11 - mov [rsp + 0], rax - mul qword [q] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, [rsi + 8] - mul rcx - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, [rsp + 0] - mul qword [q + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, r9 - mul r11 - mov [rsp + 8], rax - mul qword [q] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, [rsi + 16] - mul rcx - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, [rsp + 8] - mul qword [q + 8] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsp + 0] - mul qword [q + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, r10 - mul r11 - mov [rsp + 16], rax - mul qword [q] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, [rsi + 24] - mul rcx - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, [rsp + 16] - mul qword [q + 8] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsp + 8] - mul qword [q + 16] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsp + 0] - mul qword [q + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, r8 - mul r11 - mov [rsp + 24], rax - mul qword [q] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - - - mov rax, [rsp + 24] - mul qword [q + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsp + 16] - mul qword [q + 16] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsp + 8] - mul qword [q + 24] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov [rdi + 0 ], r9 - xor r9,r9 - - - - - - mov rax, [rsp + 24] - mul qword [q + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsp + 16] - mul qword [q + 24] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov [rdi + 8 ], r10 - xor r10,r10 - - - - - - mov rax, [rsp + 24] - mul qword [q + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov [rdi + 16 ], r8 - xor r8,r8 - - - - - - - - mov [rdi + 24 ], r9 - xor r9,r9 - - - - test r10, r10 - jnz rawMontgomeryMul1_mulM_sq - ; Compare with q - - mov rax, [rdi + 24] - cmp rax, [q + 24] - jc rawMontgomeryMul1_mulM_done ; q is bigget so done. - jnz rawMontgomeryMul1_mulM_sq ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 16] - jc rawMontgomeryMul1_mulM_done ; q is bigget so done. - jnz rawMontgomeryMul1_mulM_sq ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 8] - jc rawMontgomeryMul1_mulM_done ; q is bigget so done. - jnz rawMontgomeryMul1_mulM_sq ; q is lower - - mov rax, [rdi + 0] - cmp rax, [q + 0] - jc rawMontgomeryMul1_mulM_done ; q is bigget so done. - jnz rawMontgomeryMul1_mulM_sq ; q is lower - - ; If equal substract q - -rawMontgomeryMul1_mulM_sq: - - mov rax, [q + 0] - sub [rdi + 0], rax - - mov rax, [q + 8] - sbb [rdi + 8], rax - - mov rax, [q + 16] - sbb [rdi + 16], rax - - mov rax, [q + 24] - sbb [rdi + 24], rax - - -rawMontgomeryMul1_mulM_done: - mov rdx, rcx ; recover rdx to its original place. - add rsp, 32 ; recover rsp - ret - - - - -;;;;;;;;;;;;;;;;;;;;;; -; rawFromMontgomery -;;;;;;;;;;;;;;;;;;;;;; -; Multiply two elements in montgomery form -; Params: -; rsi <= Pointer to the long data of element 1 -; rdi <= Pointer to the long data of result -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; - -rawFromMontgomery: - sub rsp, 32 ; Reserve space for ms - mov rcx, rdx ; rdx is needed for multiplications so keep it in cx - mov r11, 0xc2e1f593efffffff ; np - xor r8,r8 - xor r9,r9 - xor r10,r10 - - add r8, [rdi + 0] - adc r9, 0x0 - adc r10, 0x0 - - - - - - mov rax, r8 - mul r11 - mov [rsp + 0], rax - mul qword [q] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - add r9, [rdi + 8] - adc r10, 0x0 - adc r8, 0x0 - - - - mov rax, [rsp + 0] - mul qword [q + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov rax, r9 - mul r11 - mov [rsp + 8], rax - mul qword [q] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - add r10, [rdi + 16] - adc r8, 0x0 - adc r9, 0x0 - - - - mov rax, [rsp + 8] - mul qword [q + 8] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsp + 0] - mul qword [q + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov rax, r10 - mul r11 - mov [rsp + 16], rax - mul qword [q] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - add r8, [rdi + 24] - adc r9, 0x0 - adc r10, 0x0 - - - - mov rax, [rsp + 16] - mul qword [q + 8] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsp + 8] - mul qword [q + 16] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - mov rax, [rsp + 0] - mul qword [q + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov rax, r8 - mul r11 - mov [rsp + 24], rax - mul qword [q] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - - - mov rax, [rsp + 24] - mul qword [q + 8] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsp + 16] - mul qword [q + 16] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - mov rax, [rsp + 8] - mul qword [q + 24] - add r9, rax - adc r10, rdx - adc r8, 0x0 - - - - mov [rdi + 0 ], r9 - xor r9,r9 - - - - - - mov rax, [rsp + 24] - mul qword [q + 16] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - mov rax, [rsp + 16] - mul qword [q + 24] - add r10, rax - adc r8, rdx - adc r9, 0x0 - - - - mov [rdi + 8 ], r10 - xor r10,r10 - - - - - - mov rax, [rsp + 24] - mul qword [q + 24] - add r8, rax - adc r9, rdx - adc r10, 0x0 - - - - mov [rdi + 16 ], r8 - xor r8,r8 - - - - - - - - mov [rdi + 24 ], r9 - xor r9,r9 - - - - test r10, r10 - jnz rawFromMontgomery_mulM_sq - ; Compare with q - - mov rax, [rdi + 24] - cmp rax, [q + 24] - jc rawFromMontgomery_mulM_done ; q is bigget so done. - jnz rawFromMontgomery_mulM_sq ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 16] - jc rawFromMontgomery_mulM_done ; q is bigget so done. - jnz rawFromMontgomery_mulM_sq ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 8] - jc rawFromMontgomery_mulM_done ; q is bigget so done. - jnz rawFromMontgomery_mulM_sq ; q is lower - - mov rax, [rdi + 0] - cmp rax, [q + 0] - jc rawFromMontgomery_mulM_done ; q is bigget so done. - jnz rawFromMontgomery_mulM_sq ; q is lower - - ; If equal substract q - -rawFromMontgomery_mulM_sq: - - mov rax, [q + 0] - sub [rdi + 0], rax - - mov rax, [q + 8] - sbb [rdi + 8], rax - - mov rax, [q + 16] - sbb [rdi + 16], rax - - mov rax, [q + 24] - sbb [rdi + 24], rax - - -rawFromMontgomery_mulM_done: - mov rdx, rcx ; recover rdx to its original place. - add rsp, 32 ; recover rsp - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; toMontgomery -;;;;;;;;;;;;;;;;;;;;;; -; Convert a number to Montgomery -; rdi <= Pointer element to convert -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;; -Fr_toMontgomery: - mov rax, [rdi] - bt rax, 62 ; check if montgomery - jc toMontgomery_doNothing - bt rax, 63 - jc toMontgomeryLong - -toMontgomeryShort: - add rdi, 8 - push rsi - push rdx - lea rsi, [R2] - movsx rdx, eax - cmp rdx, 0 - js negMontgomeryShort -posMontgomeryShort: - call rawMontgomeryMul1 - pop rdx - pop rsi - sub rdi, 8 - mov r11b, 0x40 - shl r11d, 24 - mov [rdi+4], r11d - ret - -negMontgomeryShort: - neg rdx ; Do the multiplication positive and then negate the result. - call rawMontgomeryMul1 - mov rsi, rdi - call rawNegL - pop rdx - pop rsi - sub rdi, 8 - mov r11b, 0x40 - shl r11d, 24 - mov [rdi+4], r11d - ret - - -toMontgomeryLong: - mov [rdi], rax - add rdi, 8 - push rsi - mov rdx, rdi - lea rsi, [R2] - call rawMontgomeryMul - pop rsi - sub rdi, 8 - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - -toMontgomery_doNothing: - ret - -;;;;;;;;;;;;;;;;;;;;;; -; toNormal -;;;;;;;;;;;;;;;;;;;;;; -; Convert a number from Montgomery -; rdi <= Pointer element to convert -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;; -Fr_toNormal: - mov rax, [rdi] - bt rax, 62 ; check if montgomery - jnc toNormal_doNothing - bt rax, 63 ; if short, it means it's converted - jnc toNormal_doNothing - -toNormalLong: - add rdi, 8 - call rawFromMontgomery - sub rdi, 8 - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - -toNormal_doNothing: - ret - -;;;;;;;;;;;;;;;;;;;;;; -; toLongNormal -;;;;;;;;;;;;;;;;;;;;;; -; Convert a number to long normal -; rdi <= Pointer element to convert -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;; -Fr_toLongNormal: - mov rax, [rdi] - bt rax, 62 ; check if montgomery - jc toLongNormal_fromMontgomery - bt rax, 63 ; check if long - jnc toLongNormal_fromShort - ret ; It is already long - -toLongNormal_fromMontgomery: - add rdi, 8 - call rawFromMontgomery - sub rdi, 8 - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - ret - -toLongNormal_fromShort: - mov r8, rsi ; save rsi - movsx rsi, eax - call rawCopyS2L - mov rsi, r8 ; recover rsi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - ret - - - - - - - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; add -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_add: - mov rax, [rsi] - mov rcx, [rdx] - bt rax, 63 ; Check if is short first operand - jc add_l1 - bt rcx, 63 ; Check if is short second operand - jc add_s1l2 - -add_s1s2: ; Both operands are short - - xor rdx, rdx - mov edx, eax - add edx, ecx - jo add_manageOverflow ; rsi already is the 64bits result - - mov [rdi], rdx ; not necessary to adjust so just save and return - ret - -add_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rsi, eax - movsx rdx, ecx - add rsi, rdx - call rawCopyS2L - pop rsi - ret - -add_l1: - bt rcx, 63 ; Check if is short second operand - jc add_l1l2 - -;;;;;;;; -add_l1s2: - bt rax, 62 ; check if montgomery first - jc add_l1ms2 -add_l1ns2: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - add rsi, 8 - movsx rdx, ecx - add rdi, 8 - cmp rdx, 0 - - jns tmp_1 - neg rdx - call rawSubLS - sub rdi, 8 - sub rsi, 8 - ret -tmp_1: - call rawAddLS - sub rdi, 8 - sub rsi, 8 - ret - - - -add_l1ms2: - bt rcx, 62 ; check if montgomery second - jc add_l1ms2m -add_l1ms2n: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rdx - call Fr_toMontgomery - mov rdx, rdi - pop rdi - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret - - -add_l1ms2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret - - - -;;;;;;;; -add_s1l2: - bt rcx, 62 ; check if montgomery second - jc add_s1l2m -add_s1l2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - lea rsi, [rdx + 8] - movsx rdx, eax - add rdi, 8 - cmp rdx, 0 - - jns tmp_2 - neg rdx - call rawSubLS - sub rdi, 8 - sub rsi, 8 - ret -tmp_2: - call rawAddLS - sub rdi, 8 - sub rsi, 8 - ret - - -add_s1l2m: - bt rax, 62 ; check if montgomery first - jc add_s1ml2m -add_s1nl2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toMontgomery - mov rdx, rsi - mov rsi, rdi - pop rdi - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret - - -add_s1ml2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret - - -;;;; -add_l1l2: - bt rax, 62 ; check if montgomery first - jc add_l1ml2 -add_l1nl2: - bt rcx, 62 ; check if montgomery second - jc add_l1nl2m -add_l1nl2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret - - -add_l1nl2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toMontgomery - mov rdx, rsi - mov rsi, rdi - pop rdi - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret - - -add_l1ml2: - bt rcx, 62 ; check if montgomery seconf - jc add_l1ml2m -add_l1ml2n: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rdx - call Fr_toMontgomery - mov rdx, rdi - pop rdi - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret - - -add_l1ml2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawAddLL - sub rdi, 8 - sub rsi, 8 - ret - - - - -;;;;;;;;;;;;;;;;;;;;;; -; rawAddLL -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of type long -; Params: -; rsi <= Pointer to the long data of element 1 -; rdx <= Pointer to the long data of element 2 -; rdi <= Pointer to the long data of result -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawAddLL: - ; Add component by component with carry - - mov rax, [rsi + 0] - add rax, [rdx + 0] - mov [rdi + 0], rax - - mov rax, [rsi + 8] - adc rax, [rdx + 8] - mov [rdi + 8], rax - - mov rax, [rsi + 16] - adc rax, [rdx + 16] - mov [rdi + 16], rax - - mov rax, [rsi + 24] - adc rax, [rdx + 24] - mov [rdi + 24], rax - - jc rawAddLL_sq ; if overflow, substract q - - ; Compare with q - - - cmp rax, [q + 24] - jc rawAddLL_done ; q is bigget so done. - jnz rawAddLL_sq ; q is lower - - - mov rax, [rdi + 16] - - cmp rax, [q + 16] - jc rawAddLL_done ; q is bigget so done. - jnz rawAddLL_sq ; q is lower - - - mov rax, [rdi + 8] - - cmp rax, [q + 8] - jc rawAddLL_done ; q is bigget so done. - jnz rawAddLL_sq ; q is lower - - - mov rax, [rdi + 0] - - cmp rax, [q + 0] - jc rawAddLL_done ; q is bigget so done. - jnz rawAddLL_sq ; q is lower - - ; If equal substract q -rawAddLL_sq: - - mov rax, [q + 0] - sub [rdi + 0], rax - - mov rax, [q + 8] - sbb [rdi + 8], rax - - mov rax, [q + 16] - sbb [rdi + 16], rax - - mov rax, [q + 24] - sbb [rdi + 24], rax - -rawAddLL_done: - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; rawAddLS -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of type long -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to the long data of element 1 -; rdx <= Value to be added -;;;;;;;;;;;;;;;;;;;;;; -rawAddLS: - ; Add component by component with carry - - add rdx, [rsi] - mov [rdi] ,rdx - - mov rdx, 0 - adc rdx, [rsi + 8] - mov [rdi + 8], rdx - - mov rdx, 0 - adc rdx, [rsi + 16] - mov [rdi + 16], rdx - - mov rdx, 0 - adc rdx, [rsi + 24] - mov [rdi + 24], rdx - - jc rawAddLS_sq ; if overflow, substract q - - ; Compare with q - - mov rax, [rdi + 24] - cmp rax, [q + 24] - jc rawAddLS_done ; q is bigget so done. - jnz rawAddLS_sq ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 16] - jc rawAddLS_done ; q is bigget so done. - jnz rawAddLS_sq ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 8] - jc rawAddLS_done ; q is bigget so done. - jnz rawAddLS_sq ; q is lower - - mov rax, [rdi + 0] - cmp rax, [q + 0] - jc rawAddLS_done ; q is bigget so done. - jnz rawAddLS_sq ; q is lower - - ; If equal substract q -rawAddLS_sq: - - mov rax, [q + 0] - sub [rdi + 0], rax - - mov rax, [q + 8] - sbb [rdi + 8], rax - - mov rax, [q + 16] - sbb [rdi + 16], rax - - mov rax, [q + 24] - sbb [rdi + 24], rax - -rawAddLS_done: - ret - - - - - - - - - - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; sub -;;;;;;;;;;;;;;;;;;;;;; -; Substracts two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_sub: - mov rax, [rsi] - mov rcx, [rdx] - bt rax, 63 ; Check if is long first operand - jc sub_l1 - bt rcx, 63 ; Check if is long second operand - jc sub_s1l2 - -sub_s1s2: ; Both operands are short - - xor rdx, rdx - mov edx, eax - sub edx, ecx - jo sub_manageOverflow ; rsi already is the 64bits result - - mov [rdi], rdx ; not necessary to adjust so just save and return - ret - -sub_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rsi, eax - movsx rdx, ecx - sub rsi, rdx - call rawCopyS2L - pop rsi - ret - -sub_l1: - bt rcx, 63 ; Check if is short second operand - jc sub_l1l2 - -;;;;;;;; -sub_l1s2: - bt rax, 62 ; check if montgomery first - jc sub_l1ms2 -sub_l1ns2: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - add rsi, 8 - movsx rdx, ecx - add rdi, 8 - cmp rdx, 0 - - jns tmp_3 - neg rdx - call rawAddLS - sub rdi, 8 - sub rsi, 8 - ret -tmp_3: - call rawSubLS - sub rdi, 8 - sub rsi, 8 - ret - - -sub_l1ms2: - bt rcx, 62 ; check if montgomery second - jc sub_l1ms2m -sub_l1ms2n: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rdx - call Fr_toMontgomery - mov rdx, rdi - pop rdi - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret - - -sub_l1ms2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret - - - -;;;;;;;; -sub_s1l2: - bt rcx, 62 ; check if montgomery first - jc sub_s1l2m -sub_s1l2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - cmp eax, 0 - - js tmp_4 - - ; First Operand is positive - push rsi - add rdi, 8 - movsx rsi, eax - add rdx, 8 - call rawSubSL - sub rdi, 8 - pop rsi - ret - -tmp_4: ; First operand is negative - push rsi - lea rsi, [rdx + 8] - movsx rdx, eax - add rdi, 8 - neg rdx - call rawNegLS - sub rdi, 8 - pop rsi - ret - - -sub_s1l2m: - bt rax, 62 ; check if montgomery second - jc sub_s1ml2m -sub_s1nl2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toMontgomery - mov rdx, rsi - mov rsi, rdi - pop rdi - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret - - -sub_s1ml2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret - - -;;;; -sub_l1l2: - bt rax, 62 ; check if montgomery first - jc sub_l1ml2 -sub_l1nl2: - bt rcx, 62 ; check if montgomery second - jc sub_l1nl2m -sub_l1nl2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret - - -sub_l1nl2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toMontgomery - mov rdx, rsi - mov rsi, rdi - pop rdi - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret - - -sub_l1ml2: - bt rcx, 62 ; check if montgomery seconf - jc sub_l1ml2m -sub_l1ml2n: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rdx - call Fr_toMontgomery - mov rdx, rdi - pop rdi - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret - - -sub_l1ml2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; rawSubLS -;;;;;;;;;;;;;;;;;;;;;; -; Substracts a short element from the long element -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to the long data of element 1 where will be substracted -; rdx <= Value to be substracted -; [rdi] = [rsi] - rdx -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawSubLS: - ; Substract first digit - - mov rax, [rsi] - sub rax, rdx - mov [rdi] ,rax - mov rdx, 0 - - mov rax, [rsi + 8] - sbb rax, rdx - mov [rdi + 8], rax - - mov rax, [rsi + 16] - sbb rax, rdx - mov [rdi + 16], rax - - mov rax, [rsi + 24] - sbb rax, rdx - mov [rdi + 24], rax - - jnc rawSubLS_done ; if overflow, add q - - ; Add q -rawSubLS_aq: - - mov rax, [q + 0] - add [rdi + 0], rax - - mov rax, [q + 8] - adc [rdi + 8], rax - - mov rax, [q + 16] - adc [rdi + 16], rax - - mov rax, [q + 24] - adc [rdi + 24], rax - -rawSubLS_done: - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; rawSubSL -;;;;;;;;;;;;;;;;;;;;;; -; Substracts a long element from a short element -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Value from where will bo substracted -; rdx <= Pointer to long of the value to be substracted -; -; [rdi] = rsi - [rdx] -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawSubSL: - ; Substract first digit - sub rsi, [rdx] - mov [rdi] ,rsi - - - mov rax, 0 - sbb rax, [rdx + 8] - mov [rdi + 8], rax - - mov rax, 0 - sbb rax, [rdx + 16] - mov [rdi + 16], rax - - mov rax, 0 - sbb rax, [rdx + 24] - mov [rdi + 24], rax - - jnc rawSubSL_done ; if overflow, add q - - ; Add q -rawSubSL_aq: - - mov rax, [q + 0] - add [rdi + 0], rax - - mov rax, [q + 8] - adc [rdi + 8], rax - - mov rax, [q + 16] - adc [rdi + 16], rax - - mov rax, [q + 24] - adc [rdi + 24], rax - -rawSubSL_done: - ret - -;;;;;;;;;;;;;;;;;;;;;; -; rawSubLL -;;;;;;;;;;;;;;;;;;;;;; -; Substracts a long element from a short element -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to long from where substracted -; rdx <= Pointer to long of the value to be substracted -; -; [rdi] = [rsi] - [rdx] -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawSubLL: - ; Substract first digit - - mov rax, [rsi + 0] - sub rax, [rdx + 0] - mov [rdi + 0], rax - - mov rax, [rsi + 8] - sbb rax, [rdx + 8] - mov [rdi + 8], rax - - mov rax, [rsi + 16] - sbb rax, [rdx + 16] - mov [rdi + 16], rax - - mov rax, [rsi + 24] - sbb rax, [rdx + 24] - mov [rdi + 24], rax - - jnc rawSubLL_done ; if overflow, add q - - ; Add q -rawSubLL_aq: - - mov rax, [q + 0] - add [rdi + 0], rax - - mov rax, [q + 8] - adc [rdi + 8], rax - - mov rax, [q + 16] - adc [rdi + 16], rax - - mov rax, [q + 24] - adc [rdi + 24], rax - -rawSubLL_done: - ret - -;;;;;;;;;;;;;;;;;;;;;; -; rawNegLS -;;;;;;;;;;;;;;;;;;;;;; -; Substracts a long element and a short element form 0 -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to long from where substracted -; rdx <= short value to be substracted too -; -; [rdi] = -[rsi] - rdx -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawNegLS: - mov rax, [q] - sub rax, rdx - mov [rdi], rax - - mov rax, [q + 8 ] - sbb rax, 0 - mov [rdi + 8], rax - - mov rax, [q + 16 ] - sbb rax, 0 - mov [rdi + 16], rax - - mov rax, [q + 24 ] - sbb rax, 0 - mov [rdi + 24], rax - - setc dl - - - mov rax, [rdi + 0 ] - sub rax, [rsi + 0] - mov [rdi + 0], rax - - mov rax, [rdi + 8 ] - sbb rax, [rsi + 8] - mov [rdi + 8], rax - - mov rax, [rdi + 16 ] - sbb rax, [rsi + 16] - mov [rdi + 16], rax - - mov rax, [rdi + 24 ] - sbb rax, [rsi + 24] - mov [rdi + 24], rax - - - setc dh - or dl, dh - jz rawNegSL_done - - ; it is a negative value, so add q - - mov rax, [q + 0] - add [rdi + 0], rax - - mov rax, [q + 8] - adc [rdi + 8], rax - - mov rax, [q + 16] - adc [rdi + 16], rax - - mov rax, [q + 24] - adc [rdi + 24], rax - - -rawNegSL_done: - ret - - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; neg -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element to be negated -; rdi <= Pointer to result -; [rdi] = -[rsi] -;;;;;;;;;;;;;;;;;;;;;; -Fr_neg: - mov rax, [rsi] - bt rax, 63 ; Check if is short first operand - jc neg_l - -neg_s: ; Operand is short - - neg eax - jo neg_manageOverflow ; Check if overflow. (0x80000000 is the only case) - - mov [rdi], rax ; not necessary to adjust so just save and return - ret - -neg_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rsi, eax - neg rsi - call rawCopyS2L - pop rsi - ret - - - -neg_l: - mov [rdi], rax ; Copy the type - - add rdi, 8 - add rsi, 8 - call rawNegL - sub rdi, 8 - sub rsi, 8 - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; rawNeg -;;;;;;;;;;;;;;;;;;;;;; -; Negates a value -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to the long data of element 1 -; -; [rdi] = - [rsi] -;;;;;;;;;;;;;;;;;;;;;; -rawNegL: - ; Compare is zero - - xor rax, rax - - cmp [rsi + 0], rax - jnz doNegate - - cmp [rsi + 8], rax - jnz doNegate - - cmp [rsi + 16], rax - jnz doNegate - - cmp [rsi + 24], rax - jnz doNegate - - ; it's zero so just set to zero - - mov [rdi + 0], rax - - mov [rdi + 8], rax - - mov [rdi + 16], rax - - mov [rdi + 24], rax - - ret -doNegate: - - mov rax, [q + 0] - sub rax, [rsi + 0] - mov [rdi + 0], rax - - mov rax, [q + 8] - sbb rax, [rsi + 8] - mov [rdi + 8], rax - - mov rax, [q + 16] - sbb rax, [rsi + 16] - mov [rdi + 16], rax - - mov rax, [q + 24] - sbb rax, [rsi + 24] - mov [rdi + 24], rax - - ret - - - - - - - - - - - - - - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; square -;;;;;;;;;;;;;;;;;;;;;; -; Squares a field element -; Params: -; rsi <= Pointer to element 1 -; rdi <= Pointer to result -; [rdi] = [rsi] * [rsi] -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_square: - mov r8, [rsi] - bt r8, 63 ; Check if is short first operand - jc square_l1 - -square_s1: ; Both operands are short - - xor rax, rax - mov eax, r8d - imul eax - jo square_manageOverflow ; rsi already is the 64bits result - - mov [rdi], rax ; not necessary to adjust so just save and return - -square_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rax, r8d - imul rax - mov rsi, rax - call rawCopyS2L - pop rsi - - ret - -square_l1: - bt r8, 62 ; check if montgomery first - jc square_l1m -square_l1n: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - call rawMontgomerySquare - sub rdi, 8 - sub rsi, 8 - - - push rsi - add rdi, 8 - mov rsi, rdi - lea rdx, [R3] - call rawMontgomeryMul - sub rdi, 8 - pop rsi - - ret - -square_l1m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - call rawMontgomerySquare - sub rdi, 8 - sub rsi, 8 - - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; mul -;;;;;;;;;;;;;;;;;;;;;; -; Multiplies two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; [rdi] = [rsi] * [rdi] -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_mul: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc mul_l1 - bt r9, 63 ; Check if is short second operand - jc mul_s1l2 - -mul_s1s2: ; Both operands are short - - xor rax, rax - mov eax, r8d - imul r9d - jo mul_manageOverflow ; rsi already is the 64bits result - - mov [rdi], rax ; not necessary to adjust so just save and return - -mul_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rax, r8d - movsx rcx, r9d - imul rcx - mov rsi, rax - call rawCopyS2L - pop rsi - - ret - -mul_l1: - bt r9, 63 ; Check if is short second operand - jc mul_l1l2 - -;;;;;;;; -mul_l1s2: - bt r8, 62 ; check if montgomery first - jc mul_l1ms2 -mul_l1ns2: - bt r9, 62 ; check if montgomery first - jc mul_l1ns2m -mul_l1ns2n: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - push rsi - add rsi, 8 - movsx rdx, r9d - add rdi, 8 - cmp rdx, 0 - - jns tmp_5 - neg rdx - call rawMontgomeryMul1 - mov rsi, rdi - call rawNegL - sub rdi, 8 - pop rsi - - jmp tmp_6 -tmp_5: - call rawMontgomeryMul1 - sub rdi, 8 - pop rsi -tmp_6: - - - - push rsi - add rdi, 8 - mov rsi, rdi - lea rdx, [R3] - call rawMontgomeryMul - sub rdi, 8 - pop rsi - - ret - - -mul_l1ns2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 - - ret - - -mul_l1ms2: - bt r9, 62 ; check if montgomery second - jc mul_l1ms2m -mul_l1ms2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - push rsi - add rsi, 8 - movsx rdx, r9d - add rdi, 8 - cmp rdx, 0 - - jns tmp_7 - neg rdx - call rawMontgomeryMul1 - mov rsi, rdi - call rawNegL - sub rdi, 8 - pop rsi - - jmp tmp_8 -tmp_7: - call rawMontgomeryMul1 - sub rdi, 8 - pop rsi -tmp_8: - - - ret - -mul_l1ms2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 - - ret - - -;;;;;;;; -mul_s1l2: - bt r8, 62 ; check if montgomery first - jc mul_s1ml2 -mul_s1nl2: - bt r9, 62 ; check if montgomery first - jc mul_s1nl2m -mul_s1nl2n: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - push rsi - lea rsi, [rdx + 8] - movsx rdx, r8d - add rdi, 8 - cmp rdx, 0 - - jns tmp_9 - neg rdx - call rawMontgomeryMul1 - mov rsi, rdi - call rawNegL - sub rdi, 8 - pop rsi - - jmp tmp_10 -tmp_9: - call rawMontgomeryMul1 - sub rdi, 8 - pop rsi -tmp_10: - - - - push rsi - add rdi, 8 - mov rsi, rdi - lea rdx, [R3] - call rawMontgomeryMul - sub rdi, 8 - pop rsi - - ret - -mul_s1nl2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - push rsi - lea rsi, [rdx + 8] - movsx rdx, r8d - add rdi, 8 - cmp rdx, 0 - - jns tmp_11 - neg rdx - call rawMontgomeryMul1 - mov rsi, rdi - call rawNegL - sub rdi, 8 - pop rsi - - jmp tmp_12 -tmp_11: - call rawMontgomeryMul1 - sub rdi, 8 - pop rsi -tmp_12: - - - ret - -mul_s1ml2: - bt r9, 62 ; check if montgomery first - jc mul_s1ml2m -mul_s1ml2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 - - ret - -mul_s1ml2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 - - ret - -;;;; -mul_l1l2: - bt r8, 62 ; check if montgomery first - jc mul_l1ml2 -mul_l1nl2: - bt r9, 62 ; check if montgomery second - jc mul_l1nl2m -mul_l1nl2n: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 - - - push rsi - add rdi, 8 - mov rsi, rdi - lea rdx, [R3] - call rawMontgomeryMul - sub rdi, 8 - pop rsi - - ret - -mul_l1nl2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 - - ret - -mul_l1ml2: - bt r9, 62 ; check if montgomery seconf - jc mul_l1ml2m -mul_l1ml2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 - - ret - -mul_l1ml2m: - mov r11b, 0xC0 - shl r11d, 24 - mov [rdi+4], r11d - - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 - - ret - - - - - - - - - - - - - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; band -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_band: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc and_l1 - bt r9, 63 ; Check if is short second operand - jc and_s1l2 - -and_s1s2: - - cmp r8d, 0 - - js tmp_13 - - cmp r9d, 0 - js tmp_13 - xor rdx, rdx ; both ops are positive so do the op and return - mov edx, r8d - and edx, r9d - mov [rdi], rdx ; not necessary to adjust so just save and return - ret - -tmp_13: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_15 ; q is bigget so done. - jnz tmp_14 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_15 ; q is bigget so done. - jnz tmp_14 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_15 ; q is bigget so done. - jnz tmp_14 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_15 ; q is bigget so done. - jnz tmp_14 ; q is lower - - ; If equal substract q -tmp_14: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_15: - - ret - - - - - - -and_l1: - bt r9, 63 ; Check if is short second operand - jc and_l1l2 - - -and_l1s2: - bt r8, 62 ; check if montgomery first - jc and_l1ms2 -and_l1ns2: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - cmp r9d, 0 - - js tmp_16 - movsx rax, r9d - and rax, [rsi +8] - mov [rdi+8], rax - - xor rax, rax - and rax, [rsi + 16]; - - mov [rdi + 16 ], rax; - - xor rax, rax - and rax, [rsi + 24]; - - mov [rdi + 24 ], rax; - - xor rax, rax - and rax, [rsi + 32]; - - and rax, [lboMask] ; - - mov [rdi + 32 ], rax; - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_18 ; q is bigget so done. - jnz tmp_17 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_18 ; q is bigget so done. - jnz tmp_17 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_18 ; q is bigget so done. - jnz tmp_17 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_18 ; q is bigget so done. - jnz tmp_17 ; q is lower - - ; If equal substract q -tmp_17: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_18: - - ret - -tmp_16: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_20 ; q is bigget so done. - jnz tmp_19 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_20 ; q is bigget so done. - jnz tmp_19 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_20 ; q is bigget so done. - jnz tmp_19 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_20 ; q is bigget so done. - jnz tmp_19 ; q is lower - - ; If equal substract q -tmp_19: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_20: - - ret - - - - -and_l1ms2: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push r9 ; r9 is used in montgomery so we need to save it - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - pop r9 - - cmp r9d, 0 - - js tmp_21 - movsx rax, r9d - and rax, [rsi +8] - mov [rdi+8], rax - - xor rax, rax - and rax, [rsi + 16]; - - mov [rdi + 16 ], rax; - - xor rax, rax - and rax, [rsi + 24]; - - mov [rdi + 24 ], rax; - - xor rax, rax - and rax, [rsi + 32]; - - and rax, [lboMask] ; - - mov [rdi + 32 ], rax; - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_23 ; q is bigget so done. - jnz tmp_22 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_23 ; q is bigget so done. - jnz tmp_22 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_23 ; q is bigget so done. - jnz tmp_22 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_23 ; q is bigget so done. - jnz tmp_22 ; q is lower - - ; If equal substract q -tmp_22: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_23: - - ret - -tmp_21: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_25 ; q is bigget so done. - jnz tmp_24 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_25 ; q is bigget so done. - jnz tmp_24 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_25 ; q is bigget so done. - jnz tmp_24 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_25 ; q is bigget so done. - jnz tmp_24 ; q is lower - - ; If equal substract q -tmp_24: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_25: - - ret - - - - - -and_s1l2: - bt r9, 62 ; check if montgomery first - jc and_s1l2m -and_s1l2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - cmp r8d, 0 - - js tmp_26 - movsx rax, r8d - and rax, [rdx +8] - mov [rdi+8], rax - - xor rax, rax - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - xor rax, rax - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - xor rax, rax - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_28 ; q is bigget so done. - jnz tmp_27 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_28 ; q is bigget so done. - jnz tmp_27 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_28 ; q is bigget so done. - jnz tmp_27 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_28 ; q is bigget so done. - jnz tmp_27 ; q is lower - - ; If equal substract q -tmp_27: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_28: - - ret - -tmp_26: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_30 ; q is bigget so done. - jnz tmp_29 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_30 ; q is bigget so done. - jnz tmp_29 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_30 ; q is bigget so done. - jnz tmp_29 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_30 ; q is bigget so done. - jnz tmp_29 ; q is lower - - ; If equal substract q -tmp_29: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_30: - - ret - - - - -and_s1l2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push r8 ; r8 is used in montgomery so we need to save it - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - pop r8 - - cmp r8d, 0 - - js tmp_31 - movsx rax, r8d - and rax, [rdx +8] - mov [rdi+8], rax - - xor rax, rax - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - xor rax, rax - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - xor rax, rax - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_33 ; q is bigget so done. - jnz tmp_32 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_33 ; q is bigget so done. - jnz tmp_32 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_33 ; q is bigget so done. - jnz tmp_32 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_33 ; q is bigget so done. - jnz tmp_32 ; q is lower - - ; If equal substract q -tmp_32: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_33: - - ret - -tmp_31: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_35 ; q is bigget so done. - jnz tmp_34 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_35 ; q is bigget so done. - jnz tmp_34 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_35 ; q is bigget so done. - jnz tmp_34 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_35 ; q is bigget so done. - jnz tmp_34 ; q is lower - - ; If equal substract q -tmp_34: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_35: - - ret - - - - - -and_l1l2: - bt r8, 62 ; check if montgomery first - jc and_l1ml2 - bt r9, 62 ; check if montgomery first - jc and_l1nl2m -and_l1nl2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_37 ; q is bigget so done. - jnz tmp_36 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_37 ; q is bigget so done. - jnz tmp_36 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_37 ; q is bigget so done. - jnz tmp_36 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_37 ; q is bigget so done. - jnz tmp_36 ; q is lower - - ; If equal substract q -tmp_36: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_37: - - ret - - -and_l1nl2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_39 ; q is bigget so done. - jnz tmp_38 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_39 ; q is bigget so done. - jnz tmp_38 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_39 ; q is bigget so done. - jnz tmp_38 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_39 ; q is bigget so done. - jnz tmp_38 ; q is lower - - ; If equal substract q -tmp_38: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_39: - - ret - - -and_l1ml2: - bt r9, 62 ; check if montgomery first - jc and_l1ml2m -and_l1ml2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_41 ; q is bigget so done. - jnz tmp_40 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_41 ; q is bigget so done. - jnz tmp_40 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_41 ; q is bigget so done. - jnz tmp_40 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_41 ; q is bigget so done. - jnz tmp_40 ; q is lower - - ; If equal substract q -tmp_40: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_41: - - ret - - -and_l1ml2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - - - mov rax, [rsi + 8] - and rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - and rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - and rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - and rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_43 ; q is bigget so done. - jnz tmp_42 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_43 ; q is bigget so done. - jnz tmp_42 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_43 ; q is bigget so done. - jnz tmp_42 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_43 ; q is bigget so done. - jnz tmp_42 ; q is lower - - ; If equal substract q -tmp_42: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_43: - - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; bor -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_bor: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc or_l1 - bt r9, 63 ; Check if is short second operand - jc or_s1l2 - -or_s1s2: - - cmp r8d, 0 - - js tmp_44 - - cmp r9d, 0 - js tmp_44 - xor rdx, rdx ; both ops are positive so do the op and return - mov edx, r8d - or edx, r9d - mov [rdi], rdx ; not necessary to adjust so just save and return - ret - -tmp_44: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_46 ; q is bigget so done. - jnz tmp_45 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_46 ; q is bigget so done. - jnz tmp_45 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_46 ; q is bigget so done. - jnz tmp_45 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_46 ; q is bigget so done. - jnz tmp_45 ; q is lower - - ; If equal substract q -tmp_45: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_46: - - ret - - - - - - -or_l1: - bt r9, 63 ; Check if is short second operand - jc or_l1l2 - - -or_l1s2: - bt r8, 62 ; check if montgomery first - jc or_l1ms2 -or_l1ns2: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - cmp r9d, 0 - - js tmp_47 - movsx rax, r9d - or rax, [rsi +8] - mov [rdi+8], rax - - xor rax, rax - or rax, [rsi + 16]; - - mov [rdi + 16 ], rax; - - xor rax, rax - or rax, [rsi + 24]; - - mov [rdi + 24 ], rax; - - xor rax, rax - or rax, [rsi + 32]; - - and rax, [lboMask] ; - - mov [rdi + 32 ], rax; - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_49 ; q is bigget so done. - jnz tmp_48 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_49 ; q is bigget so done. - jnz tmp_48 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_49 ; q is bigget so done. - jnz tmp_48 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_49 ; q is bigget so done. - jnz tmp_48 ; q is lower - - ; If equal substract q -tmp_48: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_49: - - ret - -tmp_47: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_51 ; q is bigget so done. - jnz tmp_50 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_51 ; q is bigget so done. - jnz tmp_50 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_51 ; q is bigget so done. - jnz tmp_50 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_51 ; q is bigget so done. - jnz tmp_50 ; q is lower - - ; If equal substract q -tmp_50: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_51: - - ret - - - - -or_l1ms2: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push r9 ; r9 is used in montgomery so we need to save it - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - pop r9 - - cmp r9d, 0 - - js tmp_52 - movsx rax, r9d - or rax, [rsi +8] - mov [rdi+8], rax - - xor rax, rax - or rax, [rsi + 16]; - - mov [rdi + 16 ], rax; - - xor rax, rax - or rax, [rsi + 24]; - - mov [rdi + 24 ], rax; - - xor rax, rax - or rax, [rsi + 32]; - - and rax, [lboMask] ; - - mov [rdi + 32 ], rax; - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_54 ; q is bigget so done. - jnz tmp_53 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_54 ; q is bigget so done. - jnz tmp_53 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_54 ; q is bigget so done. - jnz tmp_53 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_54 ; q is bigget so done. - jnz tmp_53 ; q is lower - - ; If equal substract q -tmp_53: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_54: - - ret - -tmp_52: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_56 ; q is bigget so done. - jnz tmp_55 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_56 ; q is bigget so done. - jnz tmp_55 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_56 ; q is bigget so done. - jnz tmp_55 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_56 ; q is bigget so done. - jnz tmp_55 ; q is lower - - ; If equal substract q -tmp_55: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_56: - - ret - - - - - -or_s1l2: - bt r9, 62 ; check if montgomery first - jc or_s1l2m -or_s1l2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - cmp r8d, 0 - - js tmp_57 - movsx rax, r8d - or rax, [rdx +8] - mov [rdi+8], rax - - xor rax, rax - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - xor rax, rax - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - xor rax, rax - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_59 ; q is bigget so done. - jnz tmp_58 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_59 ; q is bigget so done. - jnz tmp_58 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_59 ; q is bigget so done. - jnz tmp_58 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_59 ; q is bigget so done. - jnz tmp_58 ; q is lower - - ; If equal substract q -tmp_58: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_59: - - ret - -tmp_57: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_61 ; q is bigget so done. - jnz tmp_60 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_61 ; q is bigget so done. - jnz tmp_60 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_61 ; q is bigget so done. - jnz tmp_60 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_61 ; q is bigget so done. - jnz tmp_60 ; q is lower - - ; If equal substract q -tmp_60: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_61: - - ret - - - - -or_s1l2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push r8 ; r8 is used in montgomery so we need to save it - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - pop r8 - - cmp r8d, 0 - - js tmp_62 - movsx rax, r8d - or rax, [rdx +8] - mov [rdi+8], rax - - xor rax, rax - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - xor rax, rax - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - xor rax, rax - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_64 ; q is bigget so done. - jnz tmp_63 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_64 ; q is bigget so done. - jnz tmp_63 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_64 ; q is bigget so done. - jnz tmp_63 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_64 ; q is bigget so done. - jnz tmp_63 ; q is lower - - ; If equal substract q -tmp_63: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_64: - - ret - -tmp_62: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_66 ; q is bigget so done. - jnz tmp_65 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_66 ; q is bigget so done. - jnz tmp_65 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_66 ; q is bigget so done. - jnz tmp_65 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_66 ; q is bigget so done. - jnz tmp_65 ; q is lower - - ; If equal substract q -tmp_65: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_66: - - ret - - - - - -or_l1l2: - bt r8, 62 ; check if montgomery first - jc or_l1ml2 - bt r9, 62 ; check if montgomery first - jc or_l1nl2m -or_l1nl2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_68 ; q is bigget so done. - jnz tmp_67 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_68 ; q is bigget so done. - jnz tmp_67 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_68 ; q is bigget so done. - jnz tmp_67 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_68 ; q is bigget so done. - jnz tmp_67 ; q is lower - - ; If equal substract q -tmp_67: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_68: - - ret - - -or_l1nl2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_70 ; q is bigget so done. - jnz tmp_69 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_70 ; q is bigget so done. - jnz tmp_69 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_70 ; q is bigget so done. - jnz tmp_69 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_70 ; q is bigget so done. - jnz tmp_69 ; q is lower - - ; If equal substract q -tmp_69: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_70: - - ret - - -or_l1ml2: - bt r9, 62 ; check if montgomery first - jc or_l1ml2m -or_l1ml2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_72 ; q is bigget so done. - jnz tmp_71 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_72 ; q is bigget so done. - jnz tmp_71 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_72 ; q is bigget so done. - jnz tmp_71 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_72 ; q is bigget so done. - jnz tmp_71 ; q is lower - - ; If equal substract q -tmp_71: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_72: - - ret - - -or_l1ml2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - - - mov rax, [rsi + 8] - or rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - or rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - or rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - or rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_74 ; q is bigget so done. - jnz tmp_73 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_74 ; q is bigget so done. - jnz tmp_73 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_74 ; q is bigget so done. - jnz tmp_73 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_74 ; q is bigget so done. - jnz tmp_73 ; q is lower - - ; If equal substract q -tmp_73: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_74: - - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; bxor -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_bxor: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc xor_l1 - bt r9, 63 ; Check if is short second operand - jc xor_s1l2 - -xor_s1s2: - - cmp r8d, 0 - - js tmp_75 - - cmp r9d, 0 - js tmp_75 - xor rdx, rdx ; both ops are positive so do the op and return - mov edx, r8d - xor edx, r9d - mov [rdi], rdx ; not necessary to adjust so just save and return - ret - -tmp_75: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_77 ; q is bigget so done. - jnz tmp_76 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_77 ; q is bigget so done. - jnz tmp_76 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_77 ; q is bigget so done. - jnz tmp_76 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_77 ; q is bigget so done. - jnz tmp_76 ; q is lower - - ; If equal substract q -tmp_76: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_77: - - ret - - - - - - -xor_l1: - bt r9, 63 ; Check if is short second operand - jc xor_l1l2 - - -xor_l1s2: - bt r8, 62 ; check if montgomery first - jc xor_l1ms2 -xor_l1ns2: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - cmp r9d, 0 - - js tmp_78 - movsx rax, r9d - xor rax, [rsi +8] - mov [rdi+8], rax - - xor rax, rax - xor rax, [rsi + 16]; - - mov [rdi + 16 ], rax; - - xor rax, rax - xor rax, [rsi + 24]; - - mov [rdi + 24 ], rax; - - xor rax, rax - xor rax, [rsi + 32]; - - and rax, [lboMask] ; - - mov [rdi + 32 ], rax; - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_80 ; q is bigget so done. - jnz tmp_79 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_80 ; q is bigget so done. - jnz tmp_79 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_80 ; q is bigget so done. - jnz tmp_79 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_80 ; q is bigget so done. - jnz tmp_79 ; q is lower - - ; If equal substract q -tmp_79: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_80: - - ret - -tmp_78: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_82 ; q is bigget so done. - jnz tmp_81 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_82 ; q is bigget so done. - jnz tmp_81 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_82 ; q is bigget so done. - jnz tmp_81 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_82 ; q is bigget so done. - jnz tmp_81 ; q is lower - - ; If equal substract q -tmp_81: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_82: - - ret - - - - -xor_l1ms2: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push r9 ; r9 is used in montgomery so we need to save it - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - pop r9 - - cmp r9d, 0 - - js tmp_83 - movsx rax, r9d - xor rax, [rsi +8] - mov [rdi+8], rax - - xor rax, rax - xor rax, [rsi + 16]; - - mov [rdi + 16 ], rax; - - xor rax, rax - xor rax, [rsi + 24]; - - mov [rdi + 24 ], rax; - - xor rax, rax - xor rax, [rsi + 32]; - - and rax, [lboMask] ; - - mov [rdi + 32 ], rax; - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_85 ; q is bigget so done. - jnz tmp_84 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_85 ; q is bigget so done. - jnz tmp_84 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_85 ; q is bigget so done. - jnz tmp_84 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_85 ; q is bigget so done. - jnz tmp_84 ; q is lower - - ; If equal substract q -tmp_84: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_85: - - ret - -tmp_83: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_87 ; q is bigget so done. - jnz tmp_86 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_87 ; q is bigget so done. - jnz tmp_86 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_87 ; q is bigget so done. - jnz tmp_86 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_87 ; q is bigget so done. - jnz tmp_86 ; q is lower - - ; If equal substract q -tmp_86: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_87: - - ret - - - - - -xor_s1l2: - bt r9, 62 ; check if montgomery first - jc xor_s1l2m -xor_s1l2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - cmp r8d, 0 - - js tmp_88 - movsx rax, r8d - xor rax, [rdx +8] - mov [rdi+8], rax - - xor rax, rax - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - xor rax, rax - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - xor rax, rax - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_90 ; q is bigget so done. - jnz tmp_89 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_90 ; q is bigget so done. - jnz tmp_89 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_90 ; q is bigget so done. - jnz tmp_89 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_90 ; q is bigget so done. - jnz tmp_89 ; q is lower - - ; If equal substract q -tmp_89: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_90: - - ret - -tmp_88: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_92 ; q is bigget so done. - jnz tmp_91 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_92 ; q is bigget so done. - jnz tmp_91 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_92 ; q is bigget so done. - jnz tmp_91 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_92 ; q is bigget so done. - jnz tmp_91 ; q is lower - - ; If equal substract q -tmp_91: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_92: - - ret - - - - -xor_s1l2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push r8 ; r8 is used in montgomery so we need to save it - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - pop r8 - - cmp r8d, 0 - - js tmp_93 - movsx rax, r8d - xor rax, [rdx +8] - mov [rdi+8], rax - - xor rax, rax - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - xor rax, rax - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - xor rax, rax - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_95 ; q is bigget so done. - jnz tmp_94 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_95 ; q is bigget so done. - jnz tmp_94 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_95 ; q is bigget so done. - jnz tmp_94 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_95 ; q is bigget so done. - jnz tmp_94 ; q is lower - - ; If equal substract q -tmp_94: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_95: - - ret - -tmp_93: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_97 ; q is bigget so done. - jnz tmp_96 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_97 ; q is bigget so done. - jnz tmp_96 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_97 ; q is bigget so done. - jnz tmp_96 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_97 ; q is bigget so done. - jnz tmp_96 ; q is lower - - ; If equal substract q -tmp_96: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_97: - - ret - - - - - -xor_l1l2: - bt r8, 62 ; check if montgomery first - jc xor_l1ml2 - bt r9, 62 ; check if montgomery first - jc xor_l1nl2m -xor_l1nl2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_99 ; q is bigget so done. - jnz tmp_98 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_99 ; q is bigget so done. - jnz tmp_98 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_99 ; q is bigget so done. - jnz tmp_98 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_99 ; q is bigget so done. - jnz tmp_98 ; q is lower - - ; If equal substract q -tmp_98: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_99: - - ret - - -xor_l1nl2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_101 ; q is bigget so done. - jnz tmp_100 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_101 ; q is bigget so done. - jnz tmp_100 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_101 ; q is bigget so done. - jnz tmp_100 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_101 ; q is bigget so done. - jnz tmp_100 ; q is lower - - ; If equal substract q -tmp_100: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_101: - - ret - - -xor_l1ml2: - bt r9, 62 ; check if montgomery first - jc xor_l1ml2m -xor_l1ml2n: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_103 ; q is bigget so done. - jnz tmp_102 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_103 ; q is bigget so done. - jnz tmp_102 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_103 ; q is bigget so done. - jnz tmp_102 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_103 ; q is bigget so done. - jnz tmp_102 ; q is lower - - ; If equal substract q -tmp_102: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_103: - - ret - - -xor_l1ml2m: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - - - mov rax, [rsi + 8] - xor rax, [rdx + 8] - - mov [rdi + 8 ], rax - - mov rax, [rsi + 16] - xor rax, [rdx + 16] - - mov [rdi + 16 ], rax - - mov rax, [rsi + 24] - xor rax, [rdx + 24] - - mov [rdi + 24 ], rax - - mov rax, [rsi + 32] - xor rax, [rdx + 32] - - and rax, [lboMask] - - mov [rdi + 32 ], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_105 ; q is bigget so done. - jnz tmp_104 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_105 ; q is bigget so done. - jnz tmp_104 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_105 ; q is bigget so done. - jnz tmp_104 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_105 ; q is bigget so done. - jnz tmp_104 ; q is lower - - ; If equal substract q -tmp_104: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_105: - - ret - - - - -;;;;;;;;;;;;;;;;;;;;;; -; bnot -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_bnot: - mov r11b, 0x80 - shl r11d, 24 - mov [rdi+4], r11d - - mov r8, [rsi] - bt r8, 63 ; Check if is long operand - jc bnot_l1 -bnot_s: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - jmp bnot_l1n - -bnot_l1: - bt r8, 62 ; check if montgomery first - jnc bnot_l1n - -bnot_l1m: - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - -bnot_l1n: - - mov rax, [rsi + 8] - not rax - - mov [rdi + 8], rax - - mov rax, [rsi + 16] - not rax - - mov [rdi + 16], rax - - mov rax, [rsi + 24] - not rax - - mov [rdi + 24], rax - - mov rax, [rsi + 32] - not rax - - and rax, [lboMask] - - mov [rdi + 32], rax - - - - - - ; Compare with q - - mov rax, [rdi + 32] - cmp rax, [q + 24] - jc tmp_107 ; q is bigget so done. - jnz tmp_106 ; q is lower - - mov rax, [rdi + 24] - cmp rax, [q + 16] - jc tmp_107 ; q is bigget so done. - jnz tmp_106 ; q is lower - - mov rax, [rdi + 16] - cmp rax, [q + 8] - jc tmp_107 ; q is bigget so done. - jnz tmp_106 ; q is lower - - mov rax, [rdi + 8] - cmp rax, [q + 0] - jc tmp_107 ; q is bigget so done. - jnz tmp_106 ; q is lower - - ; If equal substract q -tmp_106: - - mov rax, [q + 0] - sub [rdi + 8], rax - - mov rax, [q + 8] - sbb [rdi + 16], rax - - mov rax, [q + 16] - sbb [rdi + 24], rax - - mov rax, [q + 24] - sbb [rdi + 32], rax - -tmp_107: - - ret - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; rgt - Raw Greater Than -;;;;;;;;;;;;;;;;;;;;;; -; returns in ax 1 id *rsi > *rdx -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rax <= Return 1 or 0 -; Modified Registers: -; r8, r9, rax -;;;;;;;;;;;;;;;;;;;;;; -Fr_rgt: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc rgt_l1 - bt r9, 63 ; Check if is short second operand - jc rgt_s1l2 - -rgt_s1s2: ; Both operands are short - cmp r8d, r9d - jg rgt_ret1 - jmp rgt_ret0 - - -rgt_l1: - bt r9, 63 ; Check if is short second operand - jc rgt_l1l2 - -;;;;;;;; -rgt_l1s2: - bt r8, 62 ; check if montgomery first - jc rgt_l1ms2 -rgt_l1ns2: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - jmp rgtL1L2 - -rgt_l1ms2: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - jmp rgtL1L2 - - -;;;;;;;; -rgt_s1l2: - bt r9, 62 ; check if montgomery second - jc rgt_s1l2m -rgt_s1l2n: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - jmp rgtL1L2 - -rgt_s1l2m: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - jmp rgtL1L2 - -;;;; -rgt_l1l2: - bt r8, 62 ; check if montgomery first - jc rgt_l1ml2 -rgt_l1nl2: - bt r9, 62 ; check if montgomery second - jc rgt_l1nl2m -rgt_l1nl2n: - jmp rgtL1L2 - -rgt_l1nl2m: - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - jmp rgtL1L2 - -rgt_l1ml2: - bt r9, 62 ; check if montgomery second - jc rgt_l1ml2m -rgt_l1ml2n: - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - jmp rgtL1L2 - -rgt_l1ml2m: - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - jmp rgtL1L2 - - -;;;;;; -; rgtL1L2 -;;;;;; - -rgtL1L2: - - - mov rax, [rsi + 32] - cmp [half + 24], rax ; comare with (q-1)/2 - jc rgtl1l2_n1 ; half e1-e2 is neg => e1 < e2 - - jnz rgtl1l2_p1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rsi + 24] - cmp [half + 16], rax ; comare with (q-1)/2 - jc rgtl1l2_n1 ; half e1-e2 is neg => e1 < e2 - - jnz rgtl1l2_p1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rsi + 16] - cmp [half + 8], rax ; comare with (q-1)/2 - jc rgtl1l2_n1 ; half e1-e2 is neg => e1 < e2 - - jnz rgtl1l2_p1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rsi + 8] - cmp [half + 0], rax ; comare with (q-1)/2 - jc rgtl1l2_n1 ; half e1-e2 is neg => e1 < e2 - - jmp rgtl1l2_p1 - - - -rgtl1l2_p1: - - - mov rax, [rdx + 32] - cmp [half + 24], rax ; comare with (q-1)/2 - jc rgt_ret1 ; half e1-e2 is neg => e1 < e2 - - jnz rgtRawL1L2 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 24] - cmp [half + 16], rax ; comare with (q-1)/2 - jc rgt_ret1 ; half e1-e2 is neg => e1 < e2 - - jnz rgtRawL1L2 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 16] - cmp [half + 8], rax ; comare with (q-1)/2 - jc rgt_ret1 ; half e1-e2 is neg => e1 < e2 - - jnz rgtRawL1L2 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 8] - cmp [half + 0], rax ; comare with (q-1)/2 - jc rgt_ret1 ; half e1-e2 is neg => e1 < e2 - - jmp rgtRawL1L2 - - - - -rgtl1l2_n1: - - - mov rax, [rdx + 32] - cmp [half + 24], rax ; comare with (q-1)/2 - jc rgtRawL1L2 ; half e1-e2 is neg => e1 < e2 - - jnz rgt_ret0 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 24] - cmp [half + 16], rax ; comare with (q-1)/2 - jc rgtRawL1L2 ; half e1-e2 is neg => e1 < e2 - - jnz rgt_ret0 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 16] - cmp [half + 8], rax ; comare with (q-1)/2 - jc rgtRawL1L2 ; half e1-e2 is neg => e1 < e2 - - jnz rgt_ret0 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 8] - cmp [half + 0], rax ; comare with (q-1)/2 - jc rgtRawL1L2 ; half e1-e2 is neg => e1 < e2 - - jmp rgt_ret0 - - - - - -rgtRawL1L2: - - mov rax, [rsi + 32] - cmp [rdx + 32], rax ; comare with (q-1)/2 - jc rgt_ret1 ; rsi 1st > 2nd - - jnz rgt_ret0 - - - mov rax, [rsi + 24] - cmp [rdx + 24], rax ; comare with (q-1)/2 - jc rgt_ret1 ; rsi 1st > 2nd - - jnz rgt_ret0 - - - mov rax, [rsi + 16] - cmp [rdx + 16], rax ; comare with (q-1)/2 - jc rgt_ret1 ; rsi 1st > 2nd - - jnz rgt_ret0 - - - mov rax, [rsi + 8] - cmp [rdx + 8], rax ; comare with (q-1)/2 - jc rgt_ret1 ; rsi 1st > 2nd - - - -rgt_ret0: - xor rax, rax - ret -rgt_ret1: - mov rax, 1 - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; rlt - Raw Less Than -;;;;;;;;;;;;;;;;;;;;;; -; returns in ax 1 id *rsi > *rdx -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rax <= Return 1 or 0 -; Modified Registers: -; r8, r9, rax -;;;;;;;;;;;;;;;;;;;;;; -Fr_rlt: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc rlt_l1 - bt r9, 63 ; Check if is short second operand - jc rlt_s1l2 - -rlt_s1s2: ; Both operands are short - cmp r8d, r9d - jl rlt_ret1 - jmp rlt_ret0 - - -rlt_l1: - bt r9, 63 ; Check if is short second operand - jc rlt_l1l2 - -;;;;;;;; -rlt_l1s2: - bt r8, 62 ; check if montgomery first - jc rlt_l1ms2 -rlt_l1ns2: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - jmp rltL1L2 - -rlt_l1ms2: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - jmp rltL1L2 - - -;;;;;;;; -rlt_s1l2: - bt r9, 62 ; check if montgomery second - jc rlt_s1l2m -rlt_s1l2n: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - jmp rltL1L2 - -rlt_s1l2m: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - jmp rltL1L2 - -;;;; -rlt_l1l2: - bt r8, 62 ; check if montgomery first - jc rlt_l1ml2 -rlt_l1nl2: - bt r9, 62 ; check if montgomery second - jc rlt_l1nl2m -rlt_l1nl2n: - jmp rltL1L2 - -rlt_l1nl2m: - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - jmp rltL1L2 - -rlt_l1ml2: - bt r9, 62 ; check if montgomery second - jc rlt_l1ml2m -rlt_l1ml2n: - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - jmp rltL1L2 - -rlt_l1ml2m: - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi - push rdi - mov rdi, rdx - call Fr_toNormal - mov rdx, rdi - pop rdi - jmp rltL1L2 - - -;;;;;; -; rltL1L2 -;;;;;; - -rltL1L2: - - - mov rax, [rsi + 32] - cmp [half + 24], rax ; comare with (q-1)/2 - jc rltl1l2_n1 ; half e1-e2 is neg => e1 < e2 - - jnz rltl1l2_p1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rsi + 24] - cmp [half + 16], rax ; comare with (q-1)/2 - jc rltl1l2_n1 ; half e1-e2 is neg => e1 < e2 - - jnz rltl1l2_p1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rsi + 16] - cmp [half + 8], rax ; comare with (q-1)/2 - jc rltl1l2_n1 ; half e1-e2 is neg => e1 < e2 - - jnz rltl1l2_p1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rsi + 8] - cmp [half + 0], rax ; comare with (q-1)/2 - jc rltl1l2_n1 ; half e1-e2 is neg => e1 < e2 - - jmp rltl1l2_p1 - - - -rltl1l2_p1: - - - mov rax, [rdx + 32] - cmp [half + 24], rax ; comare with (q-1)/2 - jc rlt_ret0 ; half e1-e2 is neg => e1 < e2 - - jnz rltRawL1L2 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 24] - cmp [half + 16], rax ; comare with (q-1)/2 - jc rlt_ret0 ; half e1-e2 is neg => e1 < e2 - - jnz rltRawL1L2 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 16] - cmp [half + 8], rax ; comare with (q-1)/2 - jc rlt_ret0 ; half e1-e2 is neg => e1 < e2 - - jnz rltRawL1L2 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 8] - cmp [half + 0], rax ; comare with (q-1)/2 - jc rlt_ret0 ; half e1-e2 is neg => e1 < e2 - - jmp rltRawL1L2 - - - - -rltl1l2_n1: - - - mov rax, [rdx + 32] - cmp [half + 24], rax ; comare with (q-1)/2 - jc rltRawL1L2 ; half e1-e2 is neg => e1 < e2 - - jnz rlt_ret1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 24] - cmp [half + 16], rax ; comare with (q-1)/2 - jc rltRawL1L2 ; half e1-e2 is neg => e1 < e2 - - jnz rlt_ret1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 16] - cmp [half + 8], rax ; comare with (q-1)/2 - jc rltRawL1L2 ; half e1-e2 is neg => e1 < e2 - - jnz rlt_ret1 ; half>rax => e1 -e2 is pos => e1 > e2 - - - mov rax, [rdx + 8] - cmp [half + 0], rax ; comare with (q-1)/2 - jc rltRawL1L2 ; half e1-e2 is neg => e1 < e2 - - jmp rlt_ret1 - - - - - -rltRawL1L2: - - mov rax, [rsi + 32] - cmp [rdx + 32], rax ; comare with (q-1)/2 - jc rlt_ret0 ; rsi 1st > 2nd - jnz rlt_ret1 - - mov rax, [rsi + 24] - cmp [rdx + 24], rax ; comare with (q-1)/2 - jc rlt_ret0 ; rsi 1st > 2nd - jnz rlt_ret1 - - mov rax, [rsi + 16] - cmp [rdx + 16], rax ; comare with (q-1)/2 - jc rlt_ret0 ; rsi 1st > 2nd - jnz rlt_ret1 - - mov rax, [rsi + 8] - cmp [rdx + 8], rax ; comare with (q-1)/2 - jc rlt_ret0 ; rsi 1st > 2nd - jnz rlt_ret1 - - -rlt_ret0: - xor rax, rax - ret -rlt_ret1: - mov rax, 1 - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; req - Raw Eq -;;;;;;;;;;;;;;;;;;;;;; -; returns in ax 1 id *rsi == *rdx -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rax <= Return 1 or 0 -; Modified Registers: -; r8, r9, rax -;;;;;;;;;;;;;;;;;;;;;; -Fr_req: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc req_l1 - bt r9, 63 ; Check if is short second operand - jc req_s1l2 - -req_s1s2: ; Both operands are short - cmp r8d, r9d - je req_ret1 - jmp req_ret0 - - -req_l1: - bt r9, 63 ; Check if is short second operand - jc req_l1l2 - -;;;;;;;; -req_l1s2: - bt r8, 62 ; check if montgomery first - jc req_l1ms2 -req_l1ns2: - push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi - jmp reqL1L2 - -req_l1ms2: - push rdi - mov rdi, rdx - call Fr_toMontgomery - mov rdx, rdi - pop rdi - jmp reqL1L2 - - -;;;;;;;; -req_s1l2: - bt r9, 62 ; check if montgomery second - jc req_s1l2m -req_s1l2n: - push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi - jmp reqL1L2 - -req_s1l2m: - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toMontgomery - mov rdx, rsi - mov rsi, rdi - pop rdi - jmp reqL1L2 - -;;;; -req_l1l2: - bt r8, 62 ; check if montgomery first - jc req_l1ml2 -req_l1nl2: - bt r9, 62 ; check if montgomery second - jc req_l1nl2m -req_l1nl2n: - jmp reqL1L2 - -req_l1nl2m: - push rdi - mov rdi, rsi - mov rsi, rdx - call Fr_toMontgomery - mov rdx, rsi - mov rsi, rdi - pop rdi - jmp reqL1L2 - -req_l1ml2: - bt r9, 62 ; check if montgomery second - jc req_l1ml2m -req_l1ml2n: - push rdi - mov rdi, rdx - call Fr_toMontgomery - mov rdx, rdi - pop rdi - jmp reqL1L2 - -req_l1ml2m: - jmp reqL1L2 - - -;;;;;; -; eqL1L2 -;;;;;; - -reqL1L2: - - mov rax, [rsi + 8] - cmp [rdx + 8], rax - jne req_ret0 ; rsi 1st > 2nd - - mov rax, [rsi + 16] - cmp [rdx + 16], rax - jne req_ret0 ; rsi 1st > 2nd - - mov rax, [rsi + 24] - cmp [rdx + 24], rax - jne req_ret0 ; rsi 1st > 2nd - - mov rax, [rsi + 32] - cmp [rdx + 32], rax - jne req_ret0 ; rsi 1st > 2nd - - -req_ret1: - mov rax, 1 - ret - -req_ret0: - xor rax, rax - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; gt -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_gt: - call Fr_rgt - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; lt -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_lt: - call Fr_rlt - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; eq -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_eq: - call Fr_req - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; neq -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_neq: - call Fr_req - xor rax, 1 - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; geq -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_geq: - call Fr_rlt - xor rax, 1 - mov [rdi], rax - ret - -;;;;;;;;;;;;;;;;;;;;;; -; leq -;;;;;;;;;;;;;;;;;;;;;; -; Compares two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result can be zero or one. -; Modified Registers: -; rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -Fr_leq: - call Fr_rgt - xor rax, 1 - mov [rdi], rax - ret - - - - - - - - - - - -;;;;;;;;;;;;;;;;;;;;;; -; land -;;;;;;;;;;;;;;;;;;;;;; -; Logical and between two elements -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result zero or one -; Modified Registers: -; rax, rcx, r8 -;;;;;;;;;;;;;;;;;;;;;; -Fr_land: - - - - - - - mov rax, [rsi] - bt rax, 63 - jc tmp_108 - - test eax, eax - jz retZero_110 - jmp retOne_109 - -tmp_108: - - mov rax, [rsi + 8] - test rax, rax - jnz retOne_109 - - mov rax, [rsi + 16] - test rax, rax - jnz retOne_109 - - mov rax, [rsi + 24] - test rax, rax - jnz retOne_109 - - mov rax, [rsi + 32] - test rax, rax - jnz retOne_109 - - -retZero_110: - mov qword r8, 0 - jmp done_111 - -retOne_109: - mov qword r8, 1 - -done_111: - - - - - - - - mov rax, [rdx] - bt rax, 63 - jc tmp_112 - - test eax, eax - jz retZero_114 - jmp retOne_113 - -tmp_112: - - mov rax, [rdx + 8] - test rax, rax - jnz retOne_113 - - mov rax, [rdx + 16] - test rax, rax - jnz retOne_113 - - mov rax, [rdx + 24] - test rax, rax - jnz retOne_113 - - mov rax, [rdx + 32] - test rax, rax - jnz retOne_113 - - -retZero_114: - mov qword rcx, 0 - jmp done_115 - -retOne_113: - mov qword rcx, 1 - -done_115: - - and rcx, r8 - mov [rdi], rcx - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; lor -;;;;;;;;;;;;;;;;;;;;;; -; Logical or between two elements -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result zero or one -; Modified Registers: -; rax, rcx, r8 -;;;;;;;;;;;;;;;;;;;;;; -Fr_lor: - - - - - - - mov rax, [rsi] - bt rax, 63 - jc tmp_116 - - test eax, eax - jz retZero_118 - jmp retOne_117 - -tmp_116: - - mov rax, [rsi + 8] - test rax, rax - jnz retOne_117 - - mov rax, [rsi + 16] - test rax, rax - jnz retOne_117 - - mov rax, [rsi + 24] - test rax, rax - jnz retOne_117 - - mov rax, [rsi + 32] - test rax, rax - jnz retOne_117 - - -retZero_118: - mov qword r8, 0 - jmp done_119 - -retOne_117: - mov qword r8, 1 - -done_119: - - - - - - - - mov rax, [rdx] - bt rax, 63 - jc tmp_120 - - test eax, eax - jz retZero_122 - jmp retOne_121 - -tmp_120: - - mov rax, [rdx + 8] - test rax, rax - jnz retOne_121 - - mov rax, [rdx + 16] - test rax, rax - jnz retOne_121 - - mov rax, [rdx + 24] - test rax, rax - jnz retOne_121 - - mov rax, [rdx + 32] - test rax, rax - jnz retOne_121 - - -retZero_122: - mov qword rcx, 0 - jmp done_123 - -retOne_121: - mov qword rcx, 1 - -done_123: - - or rcx, r8 - mov [rdi], rcx - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; lnot -;;;;;;;;;;;;;;;;;;;;;; -; Do the logical not of an element -; Params: -; rsi <= Pointer to element to be tested -; rdi <= Pointer to result one if element1 is zero and zero otherwise -; Modified Registers: -; rax, rax, r8 -;;;;;;;;;;;;;;;;;;;;;; -Fr_lnot: - - - - - - - mov rax, [rsi] - bt rax, 63 - jc tmp_124 - - test eax, eax - jz retZero_126 - jmp retOne_125 - -tmp_124: - - mov rax, [rsi + 8] - test rax, rax - jnz retOne_125 - - mov rax, [rsi + 16] - test rax, rax - jnz retOne_125 - - mov rax, [rsi + 24] - test rax, rax - jnz retOne_125 - - mov rax, [rsi + 32] - test rax, rax - jnz retOne_125 - - -retZero_126: - mov qword rcx, 0 - jmp done_127 - -retOne_125: - mov qword rcx, 1 - -done_127: - - test rcx, rcx - - jz lnot_retOne -lnot_retZero: - mov qword [rdi], 0 - ret -lnot_retOne: - mov qword [rdi], 1 - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; isTrue -;;;;;;;;;;;;;;;;;;;;;; -; Convert a 64 bit integer to a long format field element -; Params: -; rsi <= Pointer to the element -; Returs: -; rax <= 1 if true 0 if false -;;;;;;;;;;;;;;;;;;;;;;; -Fr_isTrue: - - - - - - - mov rax, [rdi] - bt rax, 63 - jc tmp_128 - - test eax, eax - jz retZero_130 - jmp retOne_129 - -tmp_128: - - mov rax, [rdi + 8] - test rax, rax - jnz retOne_129 - - mov rax, [rdi + 16] - test rax, rax - jnz retOne_129 - - mov rax, [rdi + 24] - test rax, rax - jnz retOne_129 - - mov rax, [rdi + 32] - test rax, rax - jnz retOne_129 - - -retZero_130: - mov qword rax, 0 - jmp done_131 - -retOne_129: - mov qword rax, 1 - -done_131: - - ret - - - - - - section .data -Fr_q: - dd 0 - dd 0x80000000 -q dq 0x43e1f593f0000001,0x2833e84879b97091,0xb85045b68181585d,0x30644e72e131a029 -half dq 0xa1f0fac9f8000000,0x9419f4243cdcb848,0xdc2822db40c0ac2e,0x183227397098d014 -R2 dq 0x1bb8e645ae216da7,0x53fe3ab1e35c59e3,0x8c49833d53bb8085,0x0216d0b17f4e44a5 -R3 dq 0x5e94d8e1b4bf0040,0x2a489cbe1cfbb6b8,0x893cc664a19fcfed,0x0cf8594b7fcc657c -lboMask dq 0x3fffffffffffffff - diff --git a/ports/c/buildasm/fr.asm.ejs b/ports/c/buildasm/fr.asm.ejs deleted file mode 100644 index fa5f339..0000000 --- a/ports/c/buildasm/fr.asm.ejs +++ /dev/null @@ -1,53 +0,0 @@ - - - global <%=name%>_copy - global <%=name%>_copyn - global <%=name%>_add - global <%=name%>_sub - global <%=name%>_neg - global <%=name%>_mul - global <%=name%>_square - global <%=name%>_band - global <%=name%>_bor - global <%=name%>_bxor - global <%=name%>_bnot - global <%=name%>_eq - global <%=name%>_neq - global <%=name%>_lt - global <%=name%>_gt - global <%=name%>_leq - global <%=name%>_geq - global <%=name%>_land - global <%=name%>_lor - global <%=name%>_lnot - global <%=name%>_toNormal - global <%=name%>_toLongNormal - global <%=name%>_toMontgomery - global <%=name%>_toInt - global <%=name%>_isTrue - global <%=name%>_q - extern <%=name%>_fail - DEFAULT REL - - section .text -<%- include('utils.asm.ejs'); %> -<%- include('copy.asm.ejs'); %> -<%- include('montgomery.asm.ejs'); %> -<%- include('add.asm.ejs'); %> -<%- include('sub.asm.ejs'); %> -<%- include('neg.asm.ejs'); %> -<%- include('mul.asm.ejs'); %> -<%- include('binops.asm.ejs'); %> -<%- include('cmpops.asm.ejs'); %> -<%- include('logicalops.asm.ejs'); %> - - section .data -<%=name%>_q: - dd 0 - dd 0x80000000 -q dq <%= constantElement(q) %> -half dq <%= constantElement(q.shiftRight(1)) %> -R2 dq <%= constantElement(bigInt.one.shiftLeft(n64*64*2).mod(q)) %> -R3 dq <%= constantElement(bigInt.one.shiftLeft(n64*64*3).mod(q)) %> -lboMask dq 0x<%= bigInt("10000000000000000",16).shiftRight(n64*64 - q.bitLength()).minus(bigInt.one).toString(16) %> - diff --git a/ports/c/buildasm/fr.c b/ports/c/buildasm/fr.c deleted file mode 100644 index 8e4aec0..0000000 --- a/ports/c/buildasm/fr.c +++ /dev/null @@ -1,201 +0,0 @@ -#include "fr.h" -#include -#include -#include -#include - -mpz_t q; -mpz_t zero; -mpz_t one; -mpz_t mask; -size_t nBits; - - -void Fr_toMpz(mpz_t r, PFrElement pE) { - Fr_toNormal(pE); - if (!(pE->type & Fr_LONG)) { - mpz_set_si(r, pE->shortVal); - if (pE->shortVal<0) { - mpz_add(r, r, q); - } - } else { - Fr_toNormal(pE); - mpz_import(r, Fr_N64, -1, 8, -1, 0, (const void *)pE->longVal); - } -} - -void Fr_fromMpz(PFrElement pE, mpz_t v) { - if (mpz_fits_sint_p(v)) { - pE->type = Fr_SHORT; - pE->shortVal = mpz_get_si(v); - } else { - pE->type = Fr_LONG; - for (int i=0; ilongVal[i] = 0; - mpz_export((void *)(pE->longVal), NULL, -1, 8, -1, 0, v); - } -} - - -void Fr_init() { - mpz_init(q); - mpz_import(q, Fr_N64, -1, 8, -1, 0, (const void *)Fr_q.longVal); - mpz_init_set_ui(zero, 0); - mpz_init_set_ui(one, 1); - nBits = mpz_sizeinbase (q, 2); - mpz_init(mask); - mpz_mul_2exp(mask, one, nBits); - mpz_sub(mask, mask, one); - -} - -void Fr_str2element(PFrElement pE, char const *s) { - mpz_t mr; - mpz_init_set_str(mr, s, 10); - Fr_fromMpz(pE, mr); -} - -char *Fr_element2str(PFrElement pE) { - mpz_t r; - if (!(pE->type & Fr_LONG)) { - if (pE->shortVal>=0) { - char *r = new char[32]; - sprintf(r, "%d", pE->shortVal); - return r; - } else { - mpz_init_set_si(r, pE->shortVal); - mpz_add(r, r, q); - } - } else { - Fr_toNormal(pE); - mpz_init(r); - mpz_import(r, Fr_N64, -1, 8, -1, 0, (const void *)pE->longVal); - } - char *res = mpz_get_str (0, 10, r); - mpz_clear(r); - return res; -} - -void Fr_idiv(PFrElement r, PFrElement a, PFrElement b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - Fr_toMpz(ma, a); - // char *s1 = mpz_get_str (0, 10, ma); - // printf("s1 %s\n", s1); - Fr_toMpz(mb, b); - // char *s2 = mpz_get_str (0, 10, mb); - // printf("s2 %s\n", s2); - mpz_fdiv_q(mr, ma, mb); - // char *sr = mpz_get_str (0, 10, mr); - // printf("r %s\n", sr); - Fr_fromMpz(r, mr); -} - -void Fr_mod(PFrElement r, PFrElement a, PFrElement b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - Fr_toMpz(ma, a); - Fr_toMpz(mb, b); - mpz_fdiv_r(mr, ma, mb); - Fr_fromMpz(r, mr); -} - -void Fr_shl(PFrElement r, PFrElement a, PFrElement b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - Fr_toMpz(ma, a); - Fr_toMpz(mb, b); - if (mpz_cmp_ui(mb, nBits) < 0) { - mpz_mul_2exp(mr, ma, mpz_get_ui(mb)); - mpz_and(mr, mr, mask); - if (mpz_cmp(mr, q) >= 0) { - mpz_sub(mr, mr, q); - } - } else { - mpz_sub(mb, q, mb); - if (mpz_cmp_ui(mb, nBits) < 0) { - mpz_tdiv_q_2exp(mr, ma, mpz_get_ui(mb)); - } else { - mpz_set(mr, zero); - } - } - Fr_fromMpz(r, mr); -} - -void Fr_shr(PFrElement r, PFrElement a, PFrElement b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - Fr_toMpz(ma, a); - Fr_toMpz(mb, b); - if (mpz_cmp_ui(mb, nBits) < 0) { - mpz_tdiv_q_2exp(mr, ma, mpz_get_ui(mb)); - } else { - mpz_sub(mb, q, mb); - if (mpz_cmp_ui(mb, nBits) < 0) { - mpz_mul_2exp(mr, ma, mpz_get_ui(mb)); - mpz_and(mr, mr, mask); - if (mpz_cmp(mr, q) >= 0) { - mpz_sub(mr, mr, q); - } - } else { - mpz_set(mr, zero); - } - } - Fr_fromMpz(r, mr); -} - - -void Fr_pow(PFrElement r, PFrElement a, PFrElement b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - Fr_toMpz(ma, a); - Fr_toMpz(mb, b); - mpz_powm(mr, ma, mb, q); - Fr_fromMpz(r, mr); -} - -void Fr_inv(PFrElement r, PFrElement a) { - mpz_t ma; - mpz_t mr; - mpz_init(ma); - mpz_init(mr); - - Fr_toMpz(ma, a); - mpz_invert(mr, ma, q); - Fr_fromMpz(r, mr); -} - -void Fr_div(PFrElement r, PFrElement a, PFrElement b) { - FrElement tmp; - Fr_inv(&tmp, b); - Fr_mul(r, a, &tmp); -} - -void Fr_fail() { - assert(false); -} - diff --git a/ports/c/buildasm/fr.c.ejs b/ports/c/buildasm/fr.c.ejs deleted file mode 100644 index 962b6c1..0000000 --- a/ports/c/buildasm/fr.c.ejs +++ /dev/null @@ -1,201 +0,0 @@ -#include "<%=name.toLowerCase()+".h"%>" -#include -#include -#include -#include - -mpz_t q; -mpz_t zero; -mpz_t one; -mpz_t mask; -size_t nBits; - - -void <%=name%>_toMpz(mpz_t r, P<%=name%>Element pE) { - <%=name%>_toNormal(pE); - if (!(pE->type & <%=name%>_LONG)) { - mpz_set_si(r, pE->shortVal); - if (pE->shortVal<0) { - mpz_add(r, r, q); - } - } else { - <%=name%>_toNormal(pE); - mpz_import(r, <%=name%>_N64, -1, 8, -1, 0, (const void *)pE->longVal); - } -} - -void <%=name%>_fromMpz(P<%=name%>Element pE, mpz_t v) { - if (mpz_fits_sint_p(v)) { - pE->type = <%=name%>_SHORT; - pE->shortVal = mpz_get_si(v); - } else { - pE->type = <%=name%>_LONG; - for (int i=0; i<<%=name%>_N64; i++) pE->longVal[i] = 0; - mpz_export((void *)(pE->longVal), NULL, -1, 8, -1, 0, v); - } -} - - -void <%=name%>_init() { - mpz_init(q); - mpz_import(q, <%=name%>_N64, -1, 8, -1, 0, (const void *)Fr_q.longVal); - mpz_init_set_ui(zero, 0); - mpz_init_set_ui(one, 1); - nBits = mpz_sizeinbase (q, 2); - mpz_init(mask); - mpz_mul_2exp(mask, one, nBits); - mpz_sub(mask, mask, one); - -} - -void <%=name%>_str2element(P<%=name%>Element pE, char const *s) { - mpz_t mr; - mpz_init_set_str(mr, s, 10); - <%=name%>_fromMpz(pE, mr); -} - -char *<%=name%>_element2str(P<%=name%>Element pE) { - mpz_t r; - if (!(pE->type & <%=name%>_LONG)) { - if (pE->shortVal>=0) { - char *r = new char[32]; - sprintf(r, "%d", pE->shortVal); - return r; - } else { - mpz_init_set_si(r, pE->shortVal); - mpz_add(r, r, q); - } - } else { - <%=name%>_toNormal(pE); - mpz_init(r); - mpz_import(r, <%=name%>_N64, -1, 8, -1, 0, (const void *)pE->longVal); - } - char *res = mpz_get_str (0, 10, r); - mpz_clear(r); - return res; -} - -void <%=name%>_idiv(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - <%=name%>_toMpz(ma, a); - // char *s1 = mpz_get_str (0, 10, ma); - // printf("s1 %s\n", s1); - <%=name%>_toMpz(mb, b); - // char *s2 = mpz_get_str (0, 10, mb); - // printf("s2 %s\n", s2); - mpz_fdiv_q(mr, ma, mb); - // char *sr = mpz_get_str (0, 10, mr); - // printf("r %s\n", sr); - <%=name%>_fromMpz(r, mr); -} - -void <%=name%>_mod(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - <%=name%>_toMpz(ma, a); - <%=name%>_toMpz(mb, b); - mpz_fdiv_r(mr, ma, mb); - <%=name%>_fromMpz(r, mr); -} - -void <%=name%>_shl(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - <%=name%>_toMpz(ma, a); - <%=name%>_toMpz(mb, b); - if (mpz_cmp_ui(mb, nBits) < 0) { - mpz_mul_2exp(mr, ma, mpz_get_ui(mb)); - mpz_and(mr, mr, mask); - if (mpz_cmp(mr, q) >= 0) { - mpz_sub(mr, mr, q); - } - } else { - mpz_sub(mb, q, mb); - if (mpz_cmp_ui(mb, nBits) < 0) { - mpz_tdiv_q_2exp(mr, ma, mpz_get_ui(mb)); - } else { - mpz_set(mr, zero); - } - } - <%=name%>_fromMpz(r, mr); -} - -void <%=name%>_shr(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - <%=name%>_toMpz(ma, a); - <%=name%>_toMpz(mb, b); - if (mpz_cmp_ui(mb, nBits) < 0) { - mpz_tdiv_q_2exp(mr, ma, mpz_get_ui(mb)); - } else { - mpz_sub(mb, q, mb); - if (mpz_cmp_ui(mb, nBits) < 0) { - mpz_mul_2exp(mr, ma, mpz_get_ui(mb)); - mpz_and(mr, mr, mask); - if (mpz_cmp(mr, q) >= 0) { - mpz_sub(mr, mr, q); - } - } else { - mpz_set(mr, zero); - } - } - <%=name%>_fromMpz(r, mr); -} - - -void <%=name%>_pow(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b) { - mpz_t ma; - mpz_t mb; - mpz_t mr; - mpz_init(ma); - mpz_init(mb); - mpz_init(mr); - - <%=name%>_toMpz(ma, a); - <%=name%>_toMpz(mb, b); - mpz_powm(mr, ma, mb, q); - <%=name%>_fromMpz(r, mr); -} - -void <%=name%>_inv(P<%=name%>Element r, P<%=name%>Element a) { - mpz_t ma; - mpz_t mr; - mpz_init(ma); - mpz_init(mr); - - <%=name%>_toMpz(ma, a); - mpz_invert(mr, ma, q); - <%=name%>_fromMpz(r, mr); -} - -void <%=name%>_div(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b) { - <%=name%>Element tmp; - <%=name%>_inv(&tmp, b); - <%=name%>_mul(r, a, &tmp); -} - -void <%=name%>_fail() { - assert(false); -} - diff --git a/ports/c/buildasm/fr.h b/ports/c/buildasm/fr.h deleted file mode 100644 index 9cc2378..0000000 --- a/ports/c/buildasm/fr.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __FR_H -#define __FR_H - -#include -#define Fr_N64 4 -#define Fr_SHORT 0x00000000 -#define Fr_LONG 0x80000000 -#define Fr_LONGMONTGOMERY 0xC0000000 -typedef struct __attribute__((__packed__)) { - int32_t shortVal; - uint32_t type; - uint64_t longVal[Fr_N64]; -} FrElement; -typedef FrElement *PFrElement; -extern FrElement Fr_q; -extern "C" void Fr_copy(PFrElement r, PFrElement a); -extern "C" void Fr_copyn(PFrElement r, PFrElement a, int n); -extern "C" void Fr_add(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_sub(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_neg(PFrElement r, PFrElement a); -extern "C" void Fr_mul(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_square(PFrElement r, PFrElement a); -extern "C" void Fr_band(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_bor(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_bxor(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_bnot(PFrElement r, PFrElement a); -extern "C" void Fr_eq(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_neq(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_lt(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_gt(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_leq(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_geq(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_land(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_lor(PFrElement r, PFrElement a, PFrElement b); -extern "C" void Fr_lnot(PFrElement r, PFrElement a); -extern "C" void Fr_toNormal(PFrElement pE); -extern "C" void Fr_toLongNormal(PFrElement pE); -extern "C" void Fr_toMontgomery(PFrElement pE); - -extern "C" int Fr_isTrue(PFrElement pE); -extern "C" int Fr_toInt(PFrElement pE); - -extern "C" void Fr_fail(); - -extern FrElement Fr_q; - -// Pending functions to convert - -void Fr_str2element(PFrElement pE, char const*s); -char *Fr_element2str(PFrElement pE); -void Fr_idiv(PFrElement r, PFrElement a, PFrElement b); -void Fr_mod(PFrElement r, PFrElement a, PFrElement b); -void Fr_inv(PFrElement r, PFrElement a); -void Fr_div(PFrElement r, PFrElement a, PFrElement b); -void Fr_shl(PFrElement r, PFrElement a, PFrElement b); -void Fr_shr(PFrElement r, PFrElement a, PFrElement b); -void Fr_pow(PFrElement r, PFrElement a, PFrElement b); - - -void Fr_init(); - - - -#endif // __FR_H - - - diff --git a/ports/c/buildasm/fr.h.ejs b/ports/c/buildasm/fr.h.ejs deleted file mode 100644 index 3359223..0000000 --- a/ports/c/buildasm/fr.h.ejs +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __<%=name.toUpperCase()%>_H -#define __<%=name.toUpperCase()%>_H - -#include -#define <%=name%>_N64 <%= n64 %> -#define <%=name%>_SHORT 0x00000000 -#define <%=name%>_LONG 0x80000000 -#define <%=name%>_LONGMONTGOMERY 0xC0000000 -typedef struct __attribute__((__packed__)) { - int32_t shortVal; - uint32_t type; - uint64_t longVal[<%=name%>_N64]; -} <%=name%>Element; -typedef <%=name%>Element *P<%=name%>Element; -extern <%=name%>Element <%=name%>_q; -extern "C" void <%=name%>_copy(P<%=name%>Element r, P<%=name%>Element a); -extern "C" void <%=name%>_copyn(P<%=name%>Element r, P<%=name%>Element a, int n); -extern "C" void <%=name%>_add(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_sub(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_neg(P<%=name%>Element r, P<%=name%>Element a); -extern "C" void <%=name%>_mul(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_square(P<%=name%>Element r, P<%=name%>Element a); -extern "C" void <%=name%>_band(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_bor(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_bxor(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_bnot(P<%=name%>Element r, P<%=name%>Element a); -extern "C" void <%=name%>_eq(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_neq(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_lt(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_gt(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_leq(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_geq(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_land(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_lor(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -extern "C" void <%=name%>_lnot(P<%=name%>Element r, P<%=name%>Element a); -extern "C" void <%=name%>_toNormal(P<%=name%>Element pE); -extern "C" void <%=name%>_toLongNormal(P<%=name%>Element pE); -extern "C" void <%=name%>_toMontgomery(P<%=name%>Element pE); - -extern "C" int <%=name%>_isTrue(P<%=name%>Element pE); -extern "C" int <%=name%>_toInt(P<%=name%>Element pE); - -extern "C" void <%=name%>_fail(); - -extern <%=name%>Element <%=name%>_q; - -// Pending functions to convert - -void <%=name%>_str2element(P<%=name%>Element pE, char const*s); -char *<%=name%>_element2str(P<%=name%>Element pE); -void <%=name%>_idiv(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -void <%=name%>_mod(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -void <%=name%>_inv(P<%=name%>Element r, P<%=name%>Element a); -void <%=name%>_div(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -void <%=name%>_shl(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -void <%=name%>_shr(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); -void <%=name%>_pow(P<%=name%>Element r, P<%=name%>Element a, P<%=name%>Element b); - - -void <%=name%>_init(); - - - -#endif // __<%=name.toUpperCase()%>_H - - - diff --git a/ports/c/buildasm/fr.o b/ports/c/buildasm/fr.o deleted file mode 100644 index 7bf2b66..0000000 Binary files a/ports/c/buildasm/fr.o and /dev/null differ diff --git a/ports/c/buildasm/logicalops.asm.ejs b/ports/c/buildasm/logicalops.asm.ejs deleted file mode 100644 index 00d90e8..0000000 --- a/ports/c/buildasm/logicalops.asm.ejs +++ /dev/null @@ -1,97 +0,0 @@ - - -<% function isTrue(resReg, srcPtrReg) { %> -<% const longIsZero = global.tmpLabel() %> -<% const retOne = global.tmpLabel("retOne") %> -<% const retZero = global.tmpLabel("retZero") %> -<% const done = global.tmpLabel("done") %> - - mov rax, [<%=srcPtrReg%>] - bt rax, 63 - jc <%= longIsZero %> - - test eax, eax - jz <%= retZero %> - jmp <%= retOne %> - -<%= longIsZero %>: -<% for (let i=0; i - mov rax, [<%= srcPtrReg + " + " +(i*8+8) %>] - test rax, rax - jnz <%= retOne %> -<% } %> - -<%= retZero %>: - mov qword <%=resReg%>, 0 - jmp <%= done %> - -<%= retOne %>: - mov qword <%=resReg%>, 1 - -<%= done %>: -<% } %> - - - - -<% function logicalOp(op) { %> -;;;;;;;;;;;;;;;;;;;;;; -; l<%= op %> -;;;;;;;;;;;;;;;;;;;;;; -; Logical <%= op %> between two elements -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result zero or one -; Modified Registers: -; rax, rcx, r8 -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_l<%=op%>: -<%= isTrue("r8", "rsi") %> -<%= isTrue("rcx", "rdx") %> - <%=op%> rcx, r8 - mov [rdi], rcx - ret -<% } %> - -<% logicalOp("and"); %> -<% logicalOp("or"); %> - -;;;;;;;;;;;;;;;;;;;;;; -; lnot -;;;;;;;;;;;;;;;;;;;;;; -; Do the logical not of an element -; Params: -; rsi <= Pointer to element to be tested -; rdi <= Pointer to result one if element1 is zero and zero otherwise -; Modified Registers: -; rax, rax, r8 -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_lnot: -<%= isTrue("rcx", "rsi") %> - test rcx, rcx - - jz lnot_retOne -lnot_retZero: - mov qword [rdi], 0 - ret -lnot_retOne: - mov qword [rdi], 1 - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; isTrue -;;;;;;;;;;;;;;;;;;;;;; -; Convert a 64 bit integer to a long format field element -; Params: -; rsi <= Pointer to the element -; Returs: -; rax <= 1 if true 0 if false -;;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_isTrue: - <%= isTrue("rax", "rdi") %> - ret - - - diff --git a/ports/c/buildasm/main.c b/ports/c/buildasm/main.c deleted file mode 100644 index d33cefb..0000000 --- a/ports/c/buildasm/main.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include "fr.h" - -int main() { - Fr_init(); -/* - FrElement a = { 0, Fr_LONGMONTGOMERY, {1,1,1,1}}; - FrElement b = { 0, Fr_LONGMONTGOMERY, {2,2,2,2}}; - - - FrElement a={0x43e1f593f0000000ULL,0x2833e84879b97091ULL,0xb85045b68181585dULL,0x30644e72e131a029ULL}; - FrElement b = {3,0,0,0}; - - FrElement c; -*/ -// Fr_add(&(c[0]), a, a); -// Fr_add(&(c[0]), c, b); - -/* - for (int i=0; i<1000000000; i++) { - Fr_mul(&c, &a, &b); - } - - Fr_mul(&c,&a, &b); -*/ - -/* - FrElement a1[10]; - FrElement a2[10]; - for (int i=0; i<10; i++) { - a1[i].type = Fr_LONGMONTGOMERY; - a1[i].shortVal =0; - for (int j=0; j -<%=fnName%>: - sub rsp, <%= n64*8 %> ; Reserve space for ms - mov rcx, rdx ; rdx is needed for multiplications so keep it in cx - mov r11, 0x<%= np64.toString(16) %> ; np - xor r8,r8 - xor r9,r9 - xor r10,r10 -<% - // Main loop - for (let i=0; i - -<% - for (let j=i-1; j>=0; j--) { // All ms - if (((i-j) - mov rax, [rsp + <%= j*8 %>] - mul qword [q + <%= (i-j)*8 %>] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } - } // ms -%> - -<% - if (i - mov rax, <%= r0 %> - mul r11 - mov [rsp + <%= i*8 %>], rax - mul qword [q] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } else { -%> - mov [rdi + <%= (i-n64)*8 %> ], <%= r0 %> - xor <%= r0 %>,<%= r0 %> -<% - } -%> - -<% - } // Main Loop -%> - test <%= r1 %>, <%= r1 %> - jnz <%=fnName%>_mulM_sq - ; Compare with q -<% - for (let i=0; i - mov rax, [rdi + <%= (n64-i-1)*8 %>] - cmp rax, [q + <%= (n64-i-1)*8 %>] - jc <%=fnName%>_mulM_done ; q is bigget so done. - jnz <%=fnName%>_mulM_sq ; q is lower -<% - } -%> - ; If equal substract q - -<%=fnName%>_mulM_sq: -<% - for (let i=0; i - mov rax, [q + <%= i*8 %>] - <%= i==0 ? "sub" : "sbb" %> [rdi + <%= i*8 %>], rax -<% - } -%> - -<%=fnName%>_mulM_done: - mov rdx, rcx ; recover rdx to its original place. - add rsp, <%= n64*8 %> ; recover rsp - ret - -<% -} // Template -%> - -;;;;;;;;;;;;;;;;;;;;;; -; rawMontgomeryMul -;;;;;;;;;;;;;;;;;;;;;; -; Multiply two elements in montgomery form -; Params: -; rsi <= Pointer to the long data of element 1 -; rdx <= Pointer to the long data of element 2 -; rdi <= Pointer to the long data of result -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<% -montgomeryTemplate("rawMontgomeryMul", function(i, r0, r1, r2) { - // Same Digit - for (let o1=Math.max(0, i-n64+1); (o1<=i)&&(o1 - mov rax, [rsi + <%= 8*o1 %>] - mul qword [rcx + <%= 8*o2 %>] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } // Same digit -}) -%> - -;;;;;;;;;;;;;;;;;;;;;; -; rawMontgomerySquare -;;;;;;;;;;;;;;;;;;;;;; -; Square an element -; Params: -; rsi <= Pointer to the long data of element 1 -; rdi <= Pointer to the long data of result -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<% -montgomeryTemplate("rawMontgomerySquare", function(i, r0, r1, r2) { - // Same Digit - for (let o1=Math.max(0, i-n64+1); (o1<((i+1)>>1) )&&(o1 - mov rax, [rsi + <%= 8*o1 %>] - mul qword [rsi + <%= 8*o2 %>] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } // Same digit -%> - -<% if (i%2 == 0) { %> - mov rax, [rsi + <%= 8*(i/2) %>] - mul rax - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% } %> - -<% -}) -%> - - -;;;;;;;;;;;;;;;;;;;;;; -; rawMontgomeryMul1 -;;;;;;;;;;;;;;;;;;;;;; -; Multiply two elements in montgomery form -; Params: -; rsi <= Pointer to the long data of element 1 -; rdx <= second operand -; rdi <= Pointer to the long data of result -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<% -montgomeryTemplate("rawMontgomeryMul1", function(i, r0, r1, r2) { - // Same Digit - if (i - mov rax, [rsi + <%= 8*i %>] - mul rcx - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } // Same digit -}) -%> - - -;;;;;;;;;;;;;;;;;;;;;; -; rawFromMontgomery -;;;;;;;;;;;;;;;;;;;;;; -; Multiply two elements in montgomery form -; Params: -; rsi <= Pointer to the long data of element 1 -; rdi <= Pointer to the long data of result -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<% -montgomeryTemplate("rawFromMontgomery", function(i, r0, r1, r2) { - // Same Digit - if (i - add <%= r0 %>, [rdi + <%= 8*i %>] - adc <%= r1 %>, 0x0 - adc <%= r2 %>, 0x0 -<% - } // Same digit -}) -%> - -;;;;;;;;;;;;;;;;;;;;;; -; toMontgomery -;;;;;;;;;;;;;;;;;;;;;; -; Convert a number to Montgomery -; rdi <= Pointer element to convert -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;; -<%=name%>_toMontgomery: - mov rax, [rdi] - bt rax, 62 ; check if montgomery - jc toMontgomery_doNothing - bt rax, 63 - jc toMontgomeryLong - -toMontgomeryShort: - add rdi, 8 - push rsi - push rdx - lea rsi, [R2] - movsx rdx, eax - cmp rdx, 0 - js negMontgomeryShort -posMontgomeryShort: - call rawMontgomeryMul1 - pop rdx - pop rsi - sub rdi, 8 - <%= global.setTypeDest("0x40"); %> - ret - -negMontgomeryShort: - neg rdx ; Do the multiplication positive and then negate the result. - call rawMontgomeryMul1 - mov rsi, rdi - call rawNegL - pop rdx - pop rsi - sub rdi, 8 - <%= global.setTypeDest("0x40"); %> - ret - - -toMontgomeryLong: - mov [rdi], rax - add rdi, 8 - push rsi - mov rdx, rdi - lea rsi, [R2] - call rawMontgomeryMul - pop rsi - sub rdi, 8 - <%= global.setTypeDest("0xC0"); %> - - -toMontgomery_doNothing: - ret - -;;;;;;;;;;;;;;;;;;;;;; -; toNormal -;;;;;;;;;;;;;;;;;;;;;; -; Convert a number from Montgomery -; rdi <= Pointer element to convert -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;; -<%=name%>_toNormal: - mov rax, [rdi] - bt rax, 62 ; check if montgomery - jnc toNormal_doNothing - bt rax, 63 ; if short, it means it's converted - jnc toNormal_doNothing - -toNormalLong: - add rdi, 8 - call rawFromMontgomery - sub rdi, 8 - <%= global.setTypeDest("0x80"); %> - -toNormal_doNothing: - ret - -;;;;;;;;;;;;;;;;;;;;;; -; toLongNormal -;;;;;;;;;;;;;;;;;;;;;; -; Convert a number to long normal -; rdi <= Pointer element to convert -; Modified registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;; -<%=name%>_toLongNormal: - mov rax, [rdi] - bt rax, 62 ; check if montgomery - jc toLongNormal_fromMontgomery - bt rax, 63 ; check if long - jnc toLongNormal_fromShort - ret ; It is already long - -toLongNormal_fromMontgomery: - add rdi, 8 - call rawFromMontgomery - sub rdi, 8 - <%= global.setTypeDest("0x80"); %> - ret - -toLongNormal_fromShort: - mov r8, rsi ; save rsi - movsx rsi, eax - call rawCopyS2L - mov rsi, r8 ; recover rsi - <%= global.setTypeDest("0x80"); %> - ret - diff --git a/ports/c/buildasm/mul.asm.ejs b/ports/c/buildasm/mul.asm.ejs deleted file mode 100644 index fca655d..0000000 --- a/ports/c/buildasm/mul.asm.ejs +++ /dev/null @@ -1,275 +0,0 @@ -<% function mulS1S2() { %> - xor rax, rax - mov eax, r8d - imul r9d - jo mul_manageOverflow ; rsi already is the 64bits result - - mov [rdi], rax ; not necessary to adjust so just save and return - -mul_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rax, r8d - movsx rcx, r9d - imul rcx - mov rsi, rax - call rawCopyS2L - pop rsi -<% } %> - -<% function squareS1() { %> - xor rax, rax - mov eax, r8d - imul eax - jo square_manageOverflow ; rsi already is the 64bits result - - mov [rdi], rax ; not necessary to adjust so just save and return - -square_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rax, r8d - imul rax - mov rsi, rax - call rawCopyS2L - pop rsi -<% } %> - - -<% function mulL1S2(t) { %> - push rsi - add rsi, 8 - movsx rdx, r9d - add rdi, 8 - cmp rdx, 0 - <% const rawPositiveLabel = global.tmpLabel() %> - jns <%= rawPositiveLabel %> - neg rdx - call rawMontgomeryMul1 - mov rsi, rdi - call rawNegL - sub rdi, 8 - pop rsi - <% const done = global.tmpLabel() %> - jmp <%= done %> -<%= rawPositiveLabel %>: - call rawMontgomeryMul1 - sub rdi, 8 - pop rsi -<%= done %>: - -<% } %> - -<% function mulS1L2() { %> - push rsi - lea rsi, [rdx + 8] - movsx rdx, r8d - add rdi, 8 - cmp rdx, 0 - <% const rawPositiveLabel = global.tmpLabel() %> - jns <%= rawPositiveLabel %> - neg rdx - call rawMontgomeryMul1 - mov rsi, rdi - call rawNegL - sub rdi, 8 - pop rsi - <% const done = global.tmpLabel() %> - jmp <%= done %> -<%= rawPositiveLabel %>: - call rawMontgomeryMul1 - sub rdi, 8 - pop rsi -<%= done %>: - -<% } %> - -<% function mulL1L2() { %> - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawMontgomeryMul - sub rdi, 8 - sub rsi, 8 -<% } %> - - -<% function squareL1() { %> - add rdi, 8 - add rsi, 8 - call rawMontgomerySquare - sub rdi, 8 - sub rsi, 8 -<% } %> - -<% function mulR3() { %> - push rsi - add rdi, 8 - mov rsi, rdi - lea rdx, [R3] - call rawMontgomeryMul - sub rdi, 8 - pop rsi -<% } %> - - - -;;;;;;;;;;;;;;;;;;;;;; -; square -;;;;;;;;;;;;;;;;;;;;;; -; Squares a field element -; Params: -; rsi <= Pointer to element 1 -; rdi <= Pointer to result -; [rdi] = [rsi] * [rsi] -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_square: - mov r8, [rsi] - bt r8, 63 ; Check if is short first operand - jc square_l1 - -square_s1: ; Both operands are short -<%= squareS1() %> - ret - -square_l1: - bt r8, 62 ; check if montgomery first - jc square_l1m -square_l1n: -<%= global.setTypeDest("0xC0"); %> -<%= squareL1() %> -<%= mulR3() %> - ret - -square_l1m: -<%= global.setTypeDest("0xC0"); %> -<%= squareL1() %> - ret - - - -;;;;;;;;;;;;;;;;;;;;;; -; mul -;;;;;;;;;;;;;;;;;;;;;; -; Multiplies two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; [rdi] = [rsi] * [rdi] -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_mul: - mov r8, [rsi] - mov r9, [rdx] - bt r8, 63 ; Check if is short first operand - jc mul_l1 - bt r9, 63 ; Check if is short second operand - jc mul_s1l2 - -mul_s1s2: ; Both operands are short -<%= mulS1S2() %> - ret - -mul_l1: - bt r9, 63 ; Check if is short second operand - jc mul_l1l2 - -;;;;;;;; -mul_l1s2: - bt r8, 62 ; check if montgomery first - jc mul_l1ms2 -mul_l1ns2: - bt r9, 62 ; check if montgomery first - jc mul_l1ns2m -mul_l1ns2n: -<%= global.setTypeDest("0xC0"); %> -<%= mulL1S2() %> -<%= mulR3() %> - ret - - -mul_l1ns2m: -<%= global.setTypeDest("0x80"); %> -<%= mulL1L2() %> - ret - - -mul_l1ms2: - bt r9, 62 ; check if montgomery second - jc mul_l1ms2m -mul_l1ms2n: -<%= global.setTypeDest("0x80"); %> -<%= mulL1S2() %> - ret - -mul_l1ms2m: -<%= global.setTypeDest("0xC0"); %> -<%= mulL1L2() %> - ret - - -;;;;;;;; -mul_s1l2: - bt r8, 62 ; check if montgomery first - jc mul_s1ml2 -mul_s1nl2: - bt r9, 62 ; check if montgomery first - jc mul_s1nl2m -mul_s1nl2n: -<%= global.setTypeDest("0xC0"); %> -<%= mulS1L2() %> -<%= mulR3() %> - ret - -mul_s1nl2m: -<%= global.setTypeDest("0x80"); %> -<%= mulS1L2(); %> - ret - -mul_s1ml2: - bt r9, 62 ; check if montgomery first - jc mul_s1ml2m -mul_s1ml2n: -<%= global.setTypeDest("0x80"); %> -<%= mulL1L2() %> - ret - -mul_s1ml2m: -<%= global.setTypeDest("0xC0"); %> -<%= mulL1L2() %> - ret - -;;;; -mul_l1l2: - bt r8, 62 ; check if montgomery first - jc mul_l1ml2 -mul_l1nl2: - bt r9, 62 ; check if montgomery second - jc mul_l1nl2m -mul_l1nl2n: -<%= global.setTypeDest("0xC0"); %> -<%= mulL1L2() %> -<%= mulR3() %> - ret - -mul_l1nl2m: -<%= global.setTypeDest("0x80"); %> -<%= mulL1L2() %> - ret - -mul_l1ml2: - bt r9, 62 ; check if montgomery seconf - jc mul_l1ml2m -mul_l1ml2n: -<%= global.setTypeDest("0x80"); %> -<%= mulL1L2() %> - ret - -mul_l1ml2m: -<%= global.setTypeDest("0xC0"); %> -<%= mulL1L2() %> - ret - - diff --git a/ports/c/buildasm/neg.asm.ejs b/ports/c/buildasm/neg.asm.ejs deleted file mode 100644 index d0796dc..0000000 --- a/ports/c/buildasm/neg.asm.ejs +++ /dev/null @@ -1,78 +0,0 @@ -<% function negS() { %> - neg eax - jo neg_manageOverflow ; Check if overflow. (0x80000000 is the only case) - - mov [rdi], rax ; not necessary to adjust so just save and return - ret - -neg_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rsi, eax - neg rsi - call rawCopyS2L - pop rsi - ret -<% } %> - -<% function negL() { %> - add rdi, 8 - add rsi, 8 - call rawNegL - sub rdi, 8 - sub rsi, 8 - ret -<% } %> - -;;;;;;;;;;;;;;;;;;;;;; -; neg -;;;;;;;;;;;;;;;;;;;;;; -; Adds two elements of any kind -; Params: -; rsi <= Pointer to element to be negated -; rdi <= Pointer to result -; [rdi] = -[rsi] -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_neg: - mov rax, [rsi] - bt rax, 63 ; Check if is short first operand - jc neg_l - -neg_s: ; Operand is short -<%= negS() %> - - -neg_l: - mov [rdi], rax ; Copy the type -<%= negL() %> - - -;;;;;;;;;;;;;;;;;;;;;; -; rawNeg -;;;;;;;;;;;;;;;;;;;;;; -; Negates a value -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to the long data of element 1 -; -; [rdi] = - [rsi] -;;;;;;;;;;;;;;;;;;;;;; -rawNegL: - ; Compare is zero - - xor rax, rax -<% for (let i=0; i - cmp [rsi + <%=i*8%>], rax - jnz doNegate -<% } %> - ; it's zero so just set to zero -<% for (let i=0; i - mov [rdi + <%=i*8%>], rax -<% } %> - ret -doNegate: -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "sub" : "sbb" %> rax, [rsi + <%=i*8%>] - mov [rdi + <%=i*8%>], rax -<% } %> - ret diff --git a/ports/c/buildasm/old/buildfieldasm.js b/ports/c/buildasm/old/buildfieldasm.js deleted file mode 100644 index fc48e4c..0000000 --- a/ports/c/buildasm/old/buildfieldasm.js +++ /dev/null @@ -1,33 +0,0 @@ -const tester = require("../c/buildasm/buildzqfieldtester2.js"); - -const bigInt = require("big-integer"); - -const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); - - -describe("basic cases", function () { - this.timeout(100000); - it("should do basic tests", async () => { - await tester(__P__, [ - ["add", 0, 0], - ["add", 0, 1], - ["add", 1, 0], - ["add", 1, 1], - ["add", 2, 1], - ["add", 2, 10], - ["add", -1, -1], - ["add", -20, -10], - ["add", "10604728079509999371218483608188593244163417117449316147628604036713980815027", "10604728079509999371218483608188593244163417117449316147628604036713980815027"], - - ["mul", 0, 0], - ["mul", 0, 1], - ["mul", 1, 0], - ["mul", 1, 1], - ["mul", 2, 1], - ["mul", 2, 10], - ["mul", -1, -1], - ["mul", -20, -10], - ["mul", "10604728079509999371218483608188593244163417117449316147628604036713980815027", "10604728079509999371218483608188593244163417117449316147628604036713980815027"], - ]); - }); -}); diff --git a/ports/c/buildasm/old/buildzqfield.js b/ports/c/buildasm/old/buildzqfield.js deleted file mode 100644 index 72e5284..0000000 --- a/ports/c/buildasm/old/buildzqfield.js +++ /dev/null @@ -1,209 +0,0 @@ -const bigInt=require("big-integer"); - - - - - -class ZqBuilder { - constructor(q, name) { - this.q=bigInt(q); - this.h = []; - this.c = []; - this.name = name; - } - - build() { - this._buildHeaders(); - this._buildAdd(); - this._buildMul(); - - this.c.push(""); this.h.push(""); - return [this.h.join("\n"), this.c.join("\n")]; - } - - _buildHeaders() { - this.n64 = Math.floor((this.q.bitLength() - 1) / 64)+1; - this.h.push("typedef unsigned long long u64;"); - this.h.push(`typedef u64 ${this.name}Element[${this.n64}];`); - this.h.push(`typedef u64 *P${this.name}Element;`); - this.h.push(`extern ${this.name}Element ${this.name}_q;`); - this.h.push(`#define ${this.name}_N64 ${this.n64}`); - this.c.push(`#include "${this.name.toLowerCase()}.h"`); - this._defineConstant(`${this.name}_q`, this.q); - this.c.push(""); this.h.push(""); - } - - _defineConstant(n, v) { - let S = `${this.name}Element ${n}={`; - const mask = bigInt("FFFFFFFFFFFFFFFF", 16); - for (let i=0; i0) S = S+","; - let shex = v.shiftRight(i*64).and(mask).toString(16); - while (shex <16) shex = "0" + shex; - S = S + "0x" + shex + "ULL"; - } - S += "};"; - this.c.push(S); - } - - _buildAdd() { - this.h.push(`void ${this.name}_add(P${this.name}Element r, P${this.name}Element a, P${this.name}Element b);`); - this.c.push(`void ${this.name}_add(P${this.name}Element r, P${this.name}Element a, P${this.name}Element b) {`); - this.c.push(" __asm__ __volatile__ ("); - for (let i=0; i0) { - this.c.push(` "movq ${(this.n64 - i-1)*8}(%0), %%rax;"`); - } - this.c.push(` "cmp ${(this.n64 - i-1)*8}(%3), %%rax;"`); - this.c.push(" \"jg SQ;\""); - this.c.push(" \"jl DONE;\""); - } - this.c.push(" \"SQ:\""); - for (let i=0; i=0; j--) { - if (((i-j)_add - global <%=name%>_mul - global <%=name%>_q - DEFAULT REL - - section .text - -;;;;;;;;;;;;;;;;;;;;;; -; add -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_add: - ; Add component by component with carry -<% for (let i=0; i - mov rax, [rsi + <%=i*8%>] - <%= i==0 ? "add" : "adc" %> rax, [rdx + <%=i*8%>] - mov [rdi + <%=i*8%>], rax -<% } %> - jc add_sq ; if overflow, substract q - - ; Compare with q -<% for (let i=0; i -<% if (i>0) { %> - mov rax, [rdi + <%= (n64-i-1)*8 %>] -<% } %> - cmp rax, [q + <%= (n64-i-1)*8 %>] - jg add_sq - jl add_done -<% } %> - ; If equal substract q -add_sq: -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "sub" : "sbb" %> [rdi + <%=i*8%>], rax - mov [rdx + <%=i*8%>], rax -<% } %> - -add_done: - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; mul Montgomery -;;;;;;;;;;;;;;;;;;;;;; -mulM: -<% -let r0, r1, r2; -function setR(step) { - if ((step % 3) == 0) { - r0 = "r8"; - r1 = "r9"; - r2 = "r10"; - } else if ((step % 3) == 1) { - r0 = "r9"; - r1 = "r10"; - r2 = "r8"; - } else { - r0 = "r10"; - r1 = "r8"; - r2 = "r9"; - } -} - -const base = bigInt.one.shiftLeft(64); -const np64 = base.minus(q.modInv(base)); -%> - sub rsp, <%= n64*8 %> ; Reserve space for ms - mov rcx, rdx ; rdx is needed for multiplications so keep it in cx - mov r11, 0x<%= np64.toString(16) %> ; np - xor r8,r8 - xor r9,r9 - xor r10,r10 -<% -// Main loop -for (let i=0; i -<% - // Same Digit - for (let o1=Math.max(0, i-n64+1); (o1<=i)&&(o1 - mov rax, [rsi + <%= 8*o1 %>] - mul qword [rcx + <%= 8*o2 %>] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } // Same digit -%> - - -<% - for (let j=i-1; j>=0; j--) { // All ms - if (((i-j) - mov rax, [rsp + <%= j*8 %>] - mul qword [q + <%= (i-j)*8 %>] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } - } // ms -%> - -<% - if (i - mov rax, <%= r0 %> - mul r11 - mov [rsp + <%= i*8 %>], rax - mul qword [q] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } else { -%> - mov [rdi + <%= (i-n64)*8 %> ], <%= r0 %> - xor <%= r0 %>,<%= r0 %> -<% - } -%> - -<% -} // Main Loop -%> - cmp <%= r1 %>, 0x0 - jne mulM_sq - ; Compare with q -<% -for (let i=0; i - mov rax, [rdi + <%= (n64-i-1)*8 %>] - cmp rax, [q + <%= (n64-i-1)*8 %>] - jg mulM_sq - jl mulM_done -<% -} -%> - ; If equal substract q - -mulM_sq: -<% -for (let i=0; i - mov rax, [q + <%= i*8 %>] - <%= i==0 ? "sub" : "sbb" %> [rdi + <%= i*8 %>], rax - mov [rdx + <%= i*8 %>], rax -<% -} -%> - -mulM_done: - add rsp, <%= n64*8 %> ; recover rsp - ret - -;;;;;;;;;;;;;;;;;;;;;; -; mul MontgomeryShort -;;;;;;;;;;;;;;;;;;;;;; -mulSM: - -;;;;;;;;;;;;;;;;;;;;;; -; mul -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_mul: - mov rax, [rsi] - bt rax, 63 - jc l1 - mov rcx, [rdx] - bt rcx, 63 - jc s1l2 -s1s2: ; short first and second - mul ecx - jc rs2l ; If if doesn't feed in 32 bits convert the result to long - - ; The shorts multiplication is done. copy the val to destination and return - mov [rdi], rax - ret - -rs2l: ; The result in the multiplication doen't feed - ; we have the result in edx:eax we need to convert it to long - shl rdx, 32 - mov edx, eax ; pack edx:eax to rdx - - xor rax, rax ; Set the format to long - bts rax, 63 - mov [rdi], rax ; move the first digit - - cmp rdx, 0 ; check if redx is negative. - jl rs2ln - - ; edx is positive. - mov [rdi + 8], rdx ; Set the firs digit - - xor rax, rax ; Set the remaining digits to 0 -<% for (let i=1; i - mov [rdi + <%= (i+1)*8 %>], rax -<% } %> - ret - - ; edx is negative. -rs2ln: - - add rdx, [q] ; Set the firs digit - mov [rdi + 8], rdx ; - - mov rdx, -1 ; all ones -<% for (let i=1; i - mov rax, rdx ; Add to q - adc rax, [q + <%= i*8 %> ] - mov [rdi + <%= (i+1)*8 %>], rax -<% } %> - ret - -l1: - mov rcx, [rdx] - bt rcx, 63 - jc ll - -l1s2: - xor rdx, rdx - mov edx, ecx - bt rax, 62 - jc lsM - jmp lsN - -s1l2: - mov rsi, rdx - xor rdx, rdx - mov edx, eax - bt rcx, 62 - jc lsM - jmp lsN - - -lsN: - mov byte [rdi + 3], 0xC0 ; set the result to montgomery - add rsi, 8 - add rdi, 8 - call mulSM - mov rdx, R3 - call mulM - ret - -lsM: - mov byte [rdi + 3], 0x80 ; set the result to long normal - add rsi, 8 - add rdi, 8 - call mulSM - ret - - -ll: - - bt rax, 62 - jc lml - bt rcx, 62 - jc lnlm - -lnln: - mov byte [rdi + 3], 0xC0 ; set the result to long montgomery - add rsi, 8 - add rdi, 8 - add rdx, 8 - call mulM - mov rdi, rsi - mov rdx, R3 - call mulM - ret - -lml: - bt rcx, 62 - jc lmlm - -lnlm: - mov byte [rdi + 3], 0x80 ; set the result to long normal - add rsi, 8 - add rdi, 8 - add rdx, 8 - call mulM - ret - -lmlm: - mov byte [rdi + 3], 0xC0 ; set the result to long montgomery - add rsi, 8 - add rdi, 8 - add rdx, 8 - call mulM - ret - - - section .data -<%=name%>_q: - dd 0 - dd 0x80000000 -q dq <%= constantElement(q) %> -R3 dq <%= constantElement(bigInt.one.shiftLeft(n64*64*3).mod(q)) %> - - diff --git a/ports/c/buildasm/old/mul.asm.ejs b/ports/c/buildasm/old/mul.asm.ejs deleted file mode 100644 index f6b537e..0000000 --- a/ports/c/buildasm/old/mul.asm.ejs +++ /dev/null @@ -1,251 +0,0 @@ - -;;;;;;;;;;;;;;;;;;;;;; -; mul Montgomery -;;;;;;;;;;;;;;;;;;;;;; -mulM: -<% -let r0, r1, r2; -function setR(step) { - if ((step % 3) == 0) { - r0 = "r8"; - r1 = "r9"; - r2 = "r10"; - } else if ((step % 3) == 1) { - r0 = "r9"; - r1 = "r10"; - r2 = "r8"; - } else { - r0 = "r10"; - r1 = "r8"; - r2 = "r9"; - } -} - -const base = bigInt.one.shiftLeft(64); -const np64 = base.minus(q.modInv(base)); -%> - sub rsp, <%= n64*8 %> ; Reserve space for ms - mov rcx, rdx ; rdx is needed for multiplications so keep it in cx - mov r11, 0x<%= np64.toString(16) %> ; np - xor r8,r8 - xor r9,r9 - xor r10,r10 -<% -// Main loop -for (let i=0; i -<% - // Same Digit - for (let o1=Math.max(0, i-n64+1); (o1<=i)&&(o1 - mov rax, [rsi + <%= 8*o1 %>] - mul qword [rcx + <%= 8*o2 %>] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } // Same digit -%> - - -<% - for (let j=i-1; j>=0; j--) { // All ms - if (((i-j) - mov rax, [rsp + <%= j*8 %>] - mul qword [q + <%= (i-j)*8 %>] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } - } // ms -%> - -<% - if (i - mov rax, <%= r0 %> - mul r11 - mov [rsp + <%= i*8 %>], rax - mul qword [q] - add <%= r0 %>, rax - adc <%= r1 %>, rdx - adc <%= r2 %>, 0x0 -<% - } else { -%> - mov [rdi + <%= (i-n64)*8 %> ], <%= r0 %> - xor <%= r0 %>,<%= r0 %> -<% - } -%> - -<% -} // Main Loop -%> - cmp <%= r1 %>, 0x0 - jne mulM_sq - ; Compare with q -<% -for (let i=0; i - mov rax, [rdi + <%= (n64-i-1)*8 %>] - cmp rax, [q + <%= (n64-i-1)*8 %>] - jg mulM_sq - jl mulM_done -<% -} -%> - ; If equal substract q - -mulM_sq: -<% -for (let i=0; i - mov rax, [q + <%= i*8 %>] - <%= i==0 ? "sub" : "sbb" %> [rdi + <%= i*8 %>], rax -<% -} -%> - -mulM_done: - add rsp, <%= n64*8 %> ; recover rsp - ret - -;;;;;;;;;;;;;;;;;;;;;; -; mul MontgomeryShort -;;;;;;;;;;;;;;;;;;;;;; -mulSM: - -;;;;;;;;;;;;;;;;;;;;;; -; mul -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_mul: - mov rax, [rsi] - bt rax, 63 - jc l1 - mov rcx, [rdx] - bt rcx, 63 - jc s1l2 -s1s2: ; short first and second - mul ecx - jc rs2l ; If if doesn't feed in 32 bits convert the result to long - - ; The shorts multiplication is done. copy the val to destination and return - mov [rdi], rax - ret - -rs2l: ; The result in the multiplication doen't feed - ; we have the result in edx:eax we need to convert it to long - shl rdx, 32 - mov edx, eax ; pack edx:eax to rdx - - xor rax, rax ; Set the format to long - bts rax, 63 - mov [rdi], rax ; move the first digit - - cmp rdx, 0 ; check if redx is negative. - jl rs2ln - - ; edx is positive. - mov [rdi + 8], rdx ; Set the firs digit - - xor rax, rax ; Set the remaining digits to 0 -<% for (let i=1; i - mov [rdi + <%= (i+1)*8 %>], rax -<% } %> - ret - - ; edx is negative. -rs2ln: - - add rdx, [q] ; Set the firs digit - mov [rdi + 8], rdx ; - - mov rdx, -1 ; all ones -<% for (let i=1; i - mov rax, rdx ; Add to q - adc rax, [q + <%= i*8 %> ] - mov [rdi + <%= (i+1)*8 %>], rax -<% } %> - ret - -l1: - mov rcx, [rdx] - bt rcx, 63 - jc ll - -l1s2: - xor rdx, rdx - mov edx, ecx - bt rax, 62 - jc lsM - jmp lsN - -s1l2: - mov rsi, rdx - xor rdx, rdx - mov edx, eax - bt rcx, 62 - jc lsM - jmp lsN - - -lsN: - mov byte [rdi + 7], 0xC0 ; set the result to montgomery - add rsi, 8 - add rdi, 8 - call mulSM - mov rsi, rdi - lea rdx, [R3] - call mulM - ret - -lsM: - mov byte [rdi + 7], 0x80 ; set the result to long normal - add rsi, 8 - add rdi, 8 - call mulSM - ret - - -ll: - - bt rax, 62 - jc lml - bt rcx, 62 - jc lnlm - -lnln: - mov byte [rdi + 7], 0xC0 ; set the result to long montgomery - add rsi, 8 - add rdi, 8 - add rdx, 8 - call mulM - mov rsi, rdi - lea rdx, [R3] - call mulM - ret - -lml: - bt rcx, 62 - jc lmlm - -lnlm: - mov byte [rdi + 7], 0x80 ; set the result to long normal - add rsi, 8 - add rdi, 8 - add rdx, 8 - call mulM - ret - -lmlm: - mov byte [rdi + 7], 0xC0 ; set the result to long montgomery - add rsi, 8 - add rdi, 8 - add rdx, 8 - call mulM - ret diff --git a/ports/c/buildasm/sub.asm.ejs b/ports/c/buildasm/sub.asm.ejs deleted file mode 100644 index 5a8d199..0000000 --- a/ports/c/buildasm/sub.asm.ejs +++ /dev/null @@ -1,317 +0,0 @@ -<% function subS1S2() { %> - xor rdx, rdx - mov edx, eax - sub edx, ecx - jo sub_manageOverflow ; rsi already is the 64bits result - - mov [rdi], rdx ; not necessary to adjust so just save and return - ret - -sub_manageOverflow: ; Do the operation in 64 bits - push rsi - movsx rsi, eax - movsx rdx, ecx - sub rsi, rdx - call rawCopyS2L - pop rsi - ret -<% } %> - -<% function subL1S2(t) { %> - add rsi, 8 - movsx rdx, ecx - add rdi, 8 - cmp rdx, 0 - <% const rawSubLabel = global.tmpLabel() %> - jns <%= rawSubLabel %> - neg rdx - call rawAddLS - sub rdi, 8 - sub rsi, 8 - ret -<%= rawSubLabel %>: - call rawSubLS - sub rdi, 8 - sub rsi, 8 - ret -<% } %> - - -<% function subS1L2(t) { %> - cmp eax, 0 - <% const s1NegLabel = global.tmpLabel() %> - js <%= s1NegLabel %> - - ; First Operand is positive - push rsi - add rdi, 8 - movsx rsi, eax - add rdx, 8 - call rawSubSL - sub rdi, 8 - pop rsi - ret - -<%= s1NegLabel %>: ; First operand is negative - push rsi - lea rsi, [rdx + 8] - movsx rdx, eax - add rdi, 8 - neg rdx - call rawNegLS - sub rdi, 8 - pop rsi - ret -<% } %> - - -<% function subL1L2(t) { %> - add rdi, 8 - add rsi, 8 - add rdx, 8 - call rawSubLL - sub rdi, 8 - sub rsi, 8 - ret -<% } %> - -;;;;;;;;;;;;;;;;;;;;;; -; sub -;;;;;;;;;;;;;;;;;;;;;; -; Substracts two elements of any kind -; Params: -; rsi <= Pointer to element 1 -; rdx <= Pointer to element 2 -; rdi <= Pointer to result -; Modified Registers: -; r8, r9, 10, r11, rax, rcx -;;;;;;;;;;;;;;;;;;;;;; -<%=name%>_sub: - mov rax, [rsi] - mov rcx, [rdx] - bt rax, 63 ; Check if is long first operand - jc sub_l1 - bt rcx, 63 ; Check if is long second operand - jc sub_s1l2 - -sub_s1s2: ; Both operands are short -<%= subS1S2() %> -sub_l1: - bt rcx, 63 ; Check if is short second operand - jc sub_l1l2 - -;;;;;;;; -sub_l1s2: - bt rax, 62 ; check if montgomery first - jc sub_l1ms2 -sub_l1ns2: -<%= global.setTypeDest("0x80"); %> -<%= subL1S2(); %> - -sub_l1ms2: - bt rcx, 62 ; check if montgomery second - jc sub_l1ms2m -sub_l1ms2n: -<%= global.setTypeDest("0xC0"); %> -<%= global.toMont_b() %> -<%= subL1L2() %> - -sub_l1ms2m: -<%= global.setTypeDest("0xC0"); %> -<%= subL1L2() %> - - -;;;;;;;; -sub_s1l2: - bt rcx, 62 ; check if montgomery first - jc sub_s1l2m -sub_s1l2n: -<%= global.setTypeDest("0x80"); %> -<%= subS1L2(); %> - -sub_s1l2m: - bt rax, 62 ; check if montgomery second - jc sub_s1ml2m -sub_s1nl2m: -<%= global.setTypeDest("0xC0"); %> -<%= global.toMont_a() %> -<%= subL1L2() %> - -sub_s1ml2m: -<%= global.setTypeDest("0xC0"); %> -<%= subL1L2() %> - -;;;; -sub_l1l2: - bt rax, 62 ; check if montgomery first - jc sub_l1ml2 -sub_l1nl2: - bt rcx, 62 ; check if montgomery second - jc sub_l1nl2m -sub_l1nl2n: -<%= global.setTypeDest("0x80"); %> -<%= subL1L2() %> - -sub_l1nl2m: -<%= global.setTypeDest("0xC0"); %> -<%= global.toMont_a(); %> -<%= subL1L2() %> - -sub_l1ml2: - bt rcx, 62 ; check if montgomery seconf - jc sub_l1ml2m -sub_l1ml2n: -<%= global.setTypeDest("0xC0"); %> -<%= global.toMont_b(); %> -<%= subL1L2() %> - -sub_l1ml2m: -<%= global.setTypeDest("0xC0"); %> -<%= subL1L2() %> - - -;;;;;;;;;;;;;;;;;;;;;; -; rawSubLS -;;;;;;;;;;;;;;;;;;;;;; -; Substracts a short element from the long element -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to the long data of element 1 where will be substracted -; rdx <= Value to be substracted -; [rdi] = [rsi] - rdx -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawSubLS: - ; Substract first digit - - mov rax, [rsi] - sub rax, rdx - mov [rdi] ,rax - mov rdx, 0 -<% for (let i=1; i - mov rax, [rsi + <%=i*8%>] - sbb rax, rdx - mov [rdi + <%=i*8%>], rax -<% } %> - jnc rawSubLS_done ; if overflow, add q - - ; Add q -rawSubLS_aq: -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "add" : "adc" %> [rdi + <%=i*8%>], rax -<% } %> -rawSubLS_done: - ret - - -;;;;;;;;;;;;;;;;;;;;;; -; rawSubSL -;;;;;;;;;;;;;;;;;;;;;; -; Substracts a long element from a short element -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Value from where will bo substracted -; rdx <= Pointer to long of the value to be substracted -; -; [rdi] = rsi - [rdx] -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawSubSL: - ; Substract first digit - sub rsi, [rdx] - mov [rdi] ,rsi - -<% for (let i=1; i - mov rax, 0 - sbb rax, [rdx + <%=i*8%>] - mov [rdi + <%=i*8%>], rax -<% } %> - jnc rawSubSL_done ; if overflow, add q - - ; Add q -rawSubSL_aq: -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "add" : "adc" %> [rdi + <%=i*8%>], rax -<% } %> -rawSubSL_done: - ret - -;;;;;;;;;;;;;;;;;;;;;; -; rawSubLL -;;;;;;;;;;;;;;;;;;;;;; -; Substracts a long element from a short element -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to long from where substracted -; rdx <= Pointer to long of the value to be substracted -; -; [rdi] = [rsi] - [rdx] -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawSubLL: - ; Substract first digit -<% for (let i=0; i - mov rax, [rsi + <%=i*8%>] - <%= i==0 ? "sub" : "sbb" %> rax, [rdx + <%=i*8%>] - mov [rdi + <%=i*8%>], rax -<% } %> - jnc rawSubLL_done ; if overflow, add q - - ; Add q -rawSubLL_aq: -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "add" : "adc" %> [rdi + <%=i*8%>], rax -<% } %> -rawSubLL_done: - ret - -;;;;;;;;;;;;;;;;;;;;;; -; rawNegLS -;;;;;;;;;;;;;;;;;;;;;; -; Substracts a long element and a short element form 0 -; Params: -; rdi <= Pointer to the long data of result -; rsi <= Pointer to long from where substracted -; rdx <= short value to be substracted too -; -; [rdi] = -[rsi] - rdx -; Modified Registers: -; rax -;;;;;;;;;;;;;;;;;;;;;; -rawNegLS: - mov rax, [q] - sub rax, rdx - mov [rdi], rax -<% for (let i=1; i - mov rax, [q + <%=i*8%> ] - sbb rax, 0 - mov [rdi + <%=i*8%>], rax -<% } %> - setc dl - -<% for (let i=0; i - mov rax, [rdi + <%=i*8%> ] - <%= i==0 ? "sub" : "sbb" %> rax, [rsi + <%=i*8%>] - mov [rdi + <%=i*8%>], rax -<% } %> - - setc dh - or dl, dh - jz rawNegSL_done - - ; it is a negative value, so add q -<% for (let i=0; i - mov rax, [q + <%=i*8%>] - <%= i==0 ? "add" : "adc" %> [rdi + <%=i*8%>], rax -<% } %> - -rawNegSL_done: - ret - - diff --git a/ports/c/buildasm/tester b/ports/c/buildasm/tester deleted file mode 100755 index 1a99905..0000000 Binary files a/ports/c/buildasm/tester and /dev/null differ diff --git a/ports/c/buildasm/tester.cpp b/ports/c/buildasm/tester.cpp deleted file mode 100644 index b74a983..0000000 --- a/ports/c/buildasm/tester.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include - -#include /* printf, NULL */ -#include -#include - - -#include "fr.h" - - -typedef void (*Func1)(PFrElement, PFrElement); -typedef void (*Func2)(PFrElement, PFrElement, PFrElement); -typedef void *FuncAny; - -typedef struct { - FuncAny fn; - int nOps; -} FunctionSpec; - -std::map functions; -std::vector stack; - -void addFunction(std::string name, FuncAny f, int nOps) { - FunctionSpec fs; - fs.fn = f; - fs.nOps = nOps; - functions[name] = fs; -} - -void fillMap() { - addFunction("add", (FuncAny)Fr_add, 2); - addFunction("sub", (FuncAny)Fr_sub, 2); - addFunction("neg", (FuncAny)Fr_neg, 1); - addFunction("mul", (FuncAny)Fr_mul, 2); - addFunction("square", (FuncAny)Fr_square, 1); - addFunction("idiv", (FuncAny)Fr_idiv, 2); - addFunction("inv", (FuncAny)Fr_inv, 1); - addFunction("div", (FuncAny)Fr_div, 2); - addFunction("band", (FuncAny)Fr_band, 2); - addFunction("bor", (FuncAny)Fr_bor, 2); - addFunction("bxor", (FuncAny)Fr_bxor, 2); - addFunction("bnot", (FuncAny)Fr_bnot, 1); - addFunction("eq", (FuncAny)Fr_eq, 2); - addFunction("neq", (FuncAny)Fr_neq, 2); - addFunction("lt", (FuncAny)Fr_lt, 2); - addFunction("gt", (FuncAny)Fr_gt, 2); - addFunction("leq", (FuncAny)Fr_leq, 2); - addFunction("geq", (FuncAny)Fr_geq, 2); - addFunction("land", (FuncAny)Fr_land, 2); - addFunction("lor", (FuncAny)Fr_lor, 2); - addFunction("lnot", (FuncAny)Fr_lnot, 1); - addFunction("shl", (FuncAny)Fr_shl, 2); - addFunction("shr", (FuncAny)Fr_shr, 2); -} - -u_int64_t readInt(std::string &s) { - if (s.rfind("0x", 0) == 0) { - return std::stoull(s.substr(2), 0, 16); - } else { - return std::stoull(s, 0, 10); - } -} - -void pushNumber(std::vector &v) { - u_int64_t a; - if ((v.size()<1) || (v.size() > (Fr_N64+1))) { - printf("Invalid Size: %d - %d \n", v.size(), Fr_N64); - throw std::runtime_error("Invalid number of parameters for number"); - } - FrElement e; - a = readInt(v[0]); - *(u_int64_t *)(&e) = a; - for (int i=0; i tokens; - - std::copy(begin, end, std::back_inserter(tokens)); - - // Remove initial empty tokens - while ((tokens.size() > 0)&&(tokens[0] == "")) { - tokens.erase(tokens.begin()); - } - - // Empty lines are valid but are not processed - if (tokens.size() == 0) return; - - auto search = functions.find(tokens[0]); - if (search == functions.end()) { - pushNumber(tokens); - } else { - if (tokens.size() != 1) { - throw std::runtime_error("Functions does not accept parameters"); - } - callFunction(search->second); - } -} - -int main(void) -{ - Fr_init(); - fillMap(); - std::string line; - int i=0; - while (std::getline(std::cin, line)) { - processLine(line); - // if (i%1000 == 0) printf("%d\n", i); - // printf("%d\n", i); - i++; - } - // Print the elements in the stack - // - for (int i=0; i -#include -#include "fr.h" - -typedef void (*Func2)(PFrElement, PFrElement, PFrElement); - -typedef struct { - const char *fnName; - Func2 fn; -} FN; - - -#define NFN 2 -FN fns[NFN] = { - {"add", Fr_add}, - {"mul", Fr_mul}, -}; - -int main(int argc, char **argv) { - - if (argc <= 1) { - fprintf( stderr, "invalid number of parameters"); - return 1; - } - - for (int i=0; i< NFN;i++) { - if (strcmp(argv[1], fns[i].fnName) == 0) { - if (argc != 4) { - fprintf( stderr, "invalid number of parameters"); - return 1; - } - FrElement a; - FrElement b; - - Fr_str2element(&a, argv[2]); - Fr_str2element(&b, argv[3]); - FrElement c; - fns[i].fn(&c, &a, &b); - - char *s; - s = Fr_element2str(&c); - printf("%s", s); - free(s); - return 0; - } - } - fprintf( stderr, "invalid operation %s", argv[1]); - return 1; -} - -*/ diff --git a/ports/c/buildasm/utils.asm.ejs b/ports/c/buildasm/utils.asm.ejs deleted file mode 100644 index a8852bf..0000000 --- a/ports/c/buildasm/utils.asm.ejs +++ /dev/null @@ -1,72 +0,0 @@ -<% global.setTypeDest = function (t) { -return ( -` mov r11b, ${t} - shl r11d, 24 - mov [rdi+4], r11d`); -} %> - - -<% global.toMont_a = function () { -return ( -` push rdi - mov rdi, rsi - mov rsi, rdx - call ${name}_toMontgomery - mov rdx, rsi - mov rsi, rdi - pop rdi`); -} %> - -<% global.toMont_b = function() { -return ( -` push rdi - mov rdi, rdx - call ${name}_toMontgomery - mov rdx, rdi - pop rdi`); -} %> - -<% global.fromMont_a = function () { -return ( -` push rdi - mov rdi, rsi - mov rsi, rdx - call ${name}_toNormal - mov rdx, rsi - mov rsi, rdi - pop rdi`); -} %> - -<% global.fromMont_b = function() { -return ( -` push rdi - mov rdi, rdx - call ${name}_toNormal - mov rdx, rdi - pop rdi`); -} %> - -<% global.toLong_a = function () { -return ( -` push rdi - push rdx - mov rdi, rsi - movsx rsi, r8d - call rawCopyS2L - mov rsi, rdi - pop rdx - pop rdi`); -} %> - -<% global.toLong_b = function() { -return ( -` push rdi - push rsi - mov rdi, rdx - movsx rsi, r9d - call rawCopyS2L - mov rdx, rdi - pop rsi - pop rdi`); -} %> - diff --git a/ports/c/calcwit.cpp b/ports/c/calcwit.cpp deleted file mode 100644 index fc3bcda..0000000 --- a/ports/c/calcwit.cpp +++ /dev/null @@ -1,234 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "calcwit.h" -#include "utils.h" - -Circom_CalcWit::Circom_CalcWit(Circom_Circuit *aCircuit) { - circuit = aCircuit; - -#ifdef SANITY_CHECK - signalAssigned = new bool[circuit->NSignals]; - signalAssigned[0] = true; -#endif - - mutexes = new std::mutex[NMUTEXES]; - cvs = new std::condition_variable[NMUTEXES]; - inputSignalsToTrigger = new int[circuit->NComponents]; - signalValues = new FrElement[circuit->NSignals]; - - // Set one signal - Fr_copy(&signalValues[0], circuit->constants + 1); - - reset(); -} - - -Circom_CalcWit::~Circom_CalcWit() { - -#ifdef SANITY_CHECK - delete signalAssigned; -#endif - - delete[] cvs; - delete[] mutexes; - - delete[] signalValues; - delete[] inputSignalsToTrigger; - -} - -void Circom_CalcWit::syncPrintf(const char *format, ...) { - va_list args; - va_start(args, format); - - printf_mutex.lock(); - vprintf(format, args); - printf_mutex.unlock(); - - va_end(args); -} - -void Circom_CalcWit::reset() { - -#ifdef SANITY_CHECK - for (int i=1; iNComponents; i++) signalAssigned[i] = false; -#endif - - for (int i=0; iNComponents; i++) { - inputSignalsToTrigger[i] = circuit->components[i].inputSignals; - } - for (int i=0; iNComponents; i++) { - if (inputSignalsToTrigger[i] == 0) triggerComponent(i); - } -} - - -int Circom_CalcWit::getSubComponentOffset(int cIdx, u64 hash) { - int hIdx; - for(hIdx = int(hash & 0xFF); hash!=circuit->components[cIdx].hashTable[hIdx].hash; hIdx++) { - if (!circuit->components[cIdx].hashTable[hIdx].hash) throw std::runtime_error("hash not found: " + int_to_hex(hash)); - } - int entryPos = circuit->components[cIdx].hashTable[hIdx].pos; - if (circuit->components[cIdx].entries[entryPos].type != _typeComponent) { - throw std::runtime_error("invalid type"); - } - return circuit->components[cIdx].entries[entryPos].offset; -} - - -Circom_Sizes Circom_CalcWit::getSubComponentSizes(int cIdx, u64 hash) { - int hIdx; - for(hIdx = int(hash & 0xFF); hash!=circuit->components[cIdx].hashTable[hIdx].hash; hIdx++) { - if (!circuit->components[cIdx].hashTable[hIdx].hash) throw std::runtime_error("hash not found: " + int_to_hex(hash)); - } - int entryPos = circuit->components[cIdx].hashTable[hIdx].pos; - if (circuit->components[cIdx].entries[entryPos].type != _typeComponent) { - throw std::runtime_error("invalid type"); - } - return circuit->components[cIdx].entries[entryPos].sizes; -} - -int Circom_CalcWit::getSignalOffset(int cIdx, u64 hash) { - int hIdx; - for(hIdx = int(hash & 0xFF); hash!=circuit->components[cIdx].hashTable[hIdx].hash; hIdx++) { - if (!circuit->components[cIdx].hashTable[hIdx].hash) throw std::runtime_error("hash not found: " + int_to_hex(hash)); - } - int entryPos = circuit->components[cIdx].hashTable[hIdx].pos; - if (circuit->components[cIdx].entries[entryPos].type != _typeSignal) { - throw std::runtime_error("invalid type"); - } - return circuit->components[cIdx].entries[entryPos].offset; -} - -Circom_Sizes Circom_CalcWit::getSignalSizes(int cIdx, u64 hash) { - int hIdx; - for(hIdx = int(hash & 0xFF); hash!=circuit->components[cIdx].hashTable[hIdx].hash; hIdx++) { - if (!circuit->components[cIdx].hashTable[hIdx].hash) throw std::runtime_error("hash not found: " + int_to_hex(hash)); - } - int entryPos = circuit->components[cIdx].hashTable[hIdx].pos; - if (circuit->components[cIdx].entries[entryPos].type != _typeSignal) { - throw std::runtime_error("invalid type"); - } - return circuit->components[cIdx].entries[entryPos].sizes; -} - -void Circom_CalcWit::getSignal(int currentComponentIdx, int cIdx, int sIdx, PFrElement value) { - // syncPrintf("getSignal: %d\n", sIdx); - if ((circuit->components[cIdx].newThread)&&(currentComponentIdx != cIdx)) { - std::unique_lock lk(mutexes[cIdx % NMUTEXES]); - while (inputSignalsToTrigger[cIdx] != -1) { - cvs[cIdx % NMUTEXES].wait(lk); - } - // cvs[cIdx % NMUTEXES].wait(lk, [&]{return inputSignalsToTrigger[cIdx] == -1;}); - lk.unlock(); - } -#ifdef SANITY_CHECK - if (signalAssigned[sIdx] == false) { - fprintf(stderr, "Accessing a not assigned signal: %d\n", sIdx); - assert(false); - } -#endif - Fr_copy(value, signalValues + sIdx); - /* - char *valueStr = mpz_get_str(0, 10, *value); - syncPrintf("%d, Get %d --> %s\n", currentComponentIdx, sIdx, valueStr); - free(valueStr); - */ -} - -void Circom_CalcWit::finished(int cIdx) { - { - std::lock_guard lk(mutexes[cIdx % NMUTEXES]); - inputSignalsToTrigger[cIdx] = -1; - } - // syncPrintf("Finished: %d\n", cIdx); - cvs[cIdx % NMUTEXES].notify_all(); -} - -void Circom_CalcWit::setSignal(int currentComponentIdx, int cIdx, int sIdx, PFrElement value) { - // syncPrintf("setSignal: %d\n", sIdx); - -#ifdef SANITY_CHECK - if (signalAssigned[sIdx] == true) { - fprintf(stderr, "Signal assigned twice: %d\n", sIdx); - assert(false); - } - signalAssigned[sIdx] = true; -#endif - // Log assignement - /* - char *valueStr = mpz_get_str(0, 10, *value); - syncPrintf("%d, Set %d --> %s\n", currentComponentIdx, sIdx, valueStr); - free(valueStr); - */ - Fr_copy(signalValues + sIdx, value); - if ( BITMAP_ISSET(circuit->mapIsInput, sIdx) ) { - if (inputSignalsToTrigger[cIdx]>0) { - inputSignalsToTrigger[cIdx]--; - if (inputSignalsToTrigger[cIdx] == 0) triggerComponent(cIdx); - } else { - fprintf(stderr, "Input signals does not match with map: %d\n", sIdx); - assert(false); - } - } - -} - -void Circom_CalcWit::checkConstraint(int currentComponentIdx, PFrElement value1, PFrElement value2, char const *err) { -#ifdef SANITY_CHECK - FrElement tmp; - Fr_eq(&tmp, value1, value2); - if (!Fr_isTrue(&tmp)) { - char *pcV1 = Fr_element2str(value1); - char *pcV2 = Fr_element2str(value2); - // throw std::runtime_error(std::to_string(currentComponentIdx) + std::string(", Constraint doesn't match, ") + err + ". " + sV1 + " != " + sV2 ); - fprintf(stderr, "Constraint doesn't match, %s: %s != %s", err, pcV1, pcV2); - free(pcV1); - free(pcV2); - assert(false); - } -#endif -} - - -void Circom_CalcWit::triggerComponent(int newCIdx) { - //int oldCIdx = cIdx; - // cIdx = newCIdx; - if (circuit->components[newCIdx].newThread) { - // syncPrintf("Triggered: %d\n", newCIdx); - std::thread t(circuit->components[newCIdx].fn, this, newCIdx); - // t.join(); - t.detach(); - } else { - (*(circuit->components[newCIdx].fn))(this, newCIdx); - } - // cIdx = oldCIdx; -} - -void Circom_CalcWit::log(PFrElement value) { - char *pcV = Fr_element2str(value); - syncPrintf("Log: %s\n", pcV); - free(pcV); -} - -void Circom_CalcWit::join() { - for (int i=0; iNComponents; i++) { - std::unique_lock lk(mutexes[i % NMUTEXES]); - while (inputSignalsToTrigger[i] != -1) { - cvs[i % NMUTEXES].wait(lk); - } - // cvs[i % NMUTEXES].wait(lk, [&]{return inputSignalsToTrigger[i] == -1;}); - lk.unlock(); - // syncPrintf("Joined: %d\n", i); - } - -} - - diff --git a/ports/c/calcwit.h b/ports/c/calcwit.h deleted file mode 100644 index 00f0445..0000000 --- a/ports/c/calcwit.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef CIRCOM_CALCWIT_H -#define CIRCOM_CALCWIT_H - -#include "circom.h" -#include "fr.h" -#include -#include - -#define NMUTEXES 128 - -class Circom_CalcWit { - -#ifdef SANITY_CHECK - bool *signalAssigned; -#endif - - // componentStatus -> For each component - // >0 Signals required to trigger - // == 0 Component triggered - // == -1 Component finished - int *inputSignalsToTrigger; - std::mutex *mutexes; - std::condition_variable *cvs; - - std::mutex printf_mutex; - - FrElement *signalValues; - - - void triggerComponent(int newCIdx); - void calculateWitness(void *input, void *output); - - void syncPrintf(const char *format, ...); - - -public: - Circom_Circuit *circuit; - -// Functions called by the circuit - Circom_CalcWit(Circom_Circuit *aCircuit); - ~Circom_CalcWit(); - - int getSubComponentOffset(int cIdx, u64 hash); - Circom_Sizes getSubComponentSizes(int cIdx, u64 hash); - int getSignalOffset(int cIdx, u64 hash); - Circom_Sizes getSignalSizes(int cIdx, u64 hash); - - void getSignal(int currentComponentIdx, int cIdx, int sIdx, PFrElement value); - void setSignal(int currentComponentIdx, int cIdx, int sIdx, PFrElement value); - - void checkConstraint(int currentComponentIdx, PFrElement value1, PFrElement value2, char const *err); - - void log(PFrElement value); - - void finished(int cIdx); - void join(); - - -// Public functions - inline void setInput(int idx, PFrElement val) { - setSignal(0, 0, circuit->wit2sig[idx], val); - } - inline void getWitness(int idx, PFrElement val) { - Fr_copy(val, &signalValues[circuit->wit2sig[idx]]); - } - - void reset(); - -}; - - - -#endif // CIRCOM_CALCWIT_H diff --git a/ports/c/circom.h b/ports/c/circom.h deleted file mode 100644 index 258c02e..0000000 --- a/ports/c/circom.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __CIRCOM_H -#define __CIRCOM_H - -#include -#include -#include "fr.h" - -class Circom_CalcWit; -typedef unsigned long long u64; -typedef uint32_t u32; -typedef uint8_t u8; - -typedef int Circom_Size; -typedef Circom_Size *Circom_Sizes; - -struct Circom_HashEntry { - u64 hash; - int pos; -}; -typedef Circom_HashEntry *Circom_HashTable; - -typedef enum { _typeSignal, _typeComponent} Circom_EntryType; - -struct Circom_ComponentEntry { - int offset; - Circom_Sizes sizes; - Circom_EntryType type; -}; -typedef Circom_ComponentEntry *Circom_ComponentEntries; - -typedef void (*Circom_ComponentFunction)(Circom_CalcWit *ctx, int __cIdx); - -struct Circom_Component { - Circom_HashTable hashTable; - Circom_ComponentEntries entries; - Circom_ComponentFunction fn; - int inputSignals; - bool newThread; -}; - -class Circom_Circuit { -public: - int NSignals; - int NComponents; - int NInputs; - int NOutputs; - int NVars; - int *wit2sig; - Circom_Component *components; - u32 *mapIsInput; - PFrElement constants; - const char *P; -}; - -#define BITMAP_ISSET(m, b) (m[b>>5] & (1 << (b&0x1F))) -extern struct Circom_Circuit _circuit; - -#endif diff --git a/ports/c/fr.c b/ports/c/fr.c deleted file mode 120000 index b3a3f61..0000000 --- a/ports/c/fr.c +++ /dev/null @@ -1 +0,0 @@ -buildasm/fr.c \ No newline at end of file diff --git a/ports/c/fr.h b/ports/c/fr.h deleted file mode 120000 index f682bb8..0000000 --- a/ports/c/fr.h +++ /dev/null @@ -1 +0,0 @@ -buildasm/fr.h \ No newline at end of file diff --git a/ports/c/fr.o b/ports/c/fr.o deleted file mode 120000 index 14a80cb..0000000 --- a/ports/c/fr.o +++ /dev/null @@ -1 +0,0 @@ -buildasm/fr.o \ No newline at end of file diff --git a/ports/c/main.cpp b/ports/c/main.cpp deleted file mode 100644 index 3a8b2ea..0000000 --- a/ports/c/main.cpp +++ /dev/null @@ -1,202 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using json = nlohmann::json; - -#include "calcwit.h" -#include "circom.h" -#include "utils.h" - -#define handle_error(msg) \ - do { perror(msg); exit(EXIT_FAILURE); } while (0) - -void loadBin(Circom_CalcWit *ctx, std::string filename) { - int fd; - struct stat sb; - - // map input - fd = open(filename.c_str(), O_RDONLY); - if (fd == -1) - handle_error("open"); - - if (fstat(fd, &sb) == -1) /* To obtain file size */ - handle_error("fstat"); - - - u8 *in; - - in = (u8 *)mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (in == MAP_FAILED) - handle_error("mmap"); - - close(fd); - - FrElement v; - u8 *p = in; - for (int i=0; i<_circuit.NInputs; i++) { - v.type = Fr_LONG; - for (int j=0; jsetSignal(0, 0, _circuit.wit2sig[1 + _circuit.NOutputs + i], &v); - } -} - - -typedef void (*ItFunc)(Circom_CalcWit *ctx, int idx, json val); - -void iterateArr(Circom_CalcWit *ctx, int o, Circom_Sizes sizes, json jarr, ItFunc f) { - if (!jarr.is_array()) { - assert((sizes[0] == 1)&&(sizes[1] == 0)); - f(ctx, o, jarr); - } else { - int n = sizes[0] / sizes[1]; - for (int i=0; i(); - } else if (val.is_number()) { - - double vd = val.get(); - std::stringstream stream; - stream << std::fixed << std::setprecision(0) << vd; - s = stream.str(); - } else { - handle_error("Invalid JSON type"); - } - - Fr_str2element (&v, s.c_str()); - - ctx->setSignal(0, 0, o, &v); -} - - -void loadJson(Circom_CalcWit *ctx, std::string filename) { - std::ifstream inStream(filename); - json j; - inStream >> j; - - for (json::iterator it = j.begin(); it != j.end(); ++it) { -// std::cout << it.key() << " => " << it.value() << '\n'; - u64 h = fnv1a(it.key()); - int o; - try { - o = ctx->getSignalOffset(0, h); - } catch (std::runtime_error e) { - std::ostringstream errStrStream; - errStrStream << "Error loadin variable: " << it.key() << "\n" << e.what(); - throw std::runtime_error(errStrStream.str() ); - } - Circom_Sizes sizes = ctx->getSignalSizes(0, h); - iterateArr(ctx, o, sizes, it.value(), itFunc); - } - -} - - -void writeOutBin(Circom_CalcWit *ctx, std::string filename) { - FILE *write_ptr; - - write_ptr = fopen(filename.c_str(),"wb"); - - FrElement v; - - u8 buffOut[256]; - for (int i=0;i<_circuit.NVars;i++) { - size_t size=256; - ctx->getWitness(i, &v); - Fr_toLongNormal(&v); - fwrite(v.longVal, Fr_N64*8, 1, write_ptr); - } - fclose(write_ptr); - -} - - -void writeOutJson(Circom_CalcWit *ctx, std::string filename) { - - std::ofstream outFile; - outFile.open (filename); - - outFile << "[\n"; - - FrElement v; - - for (int i=0;i<_circuit.NVars;i++) { - ctx->getWitness(i, &v); - char *pcV = Fr_element2str(&v); - std::string sV = std::string(pcV); - outFile << (i ? "," : " ") << "\"" << sV << "\"\n"; - free(pcV); - } - - outFile << "]\n"; - outFile.close(); -} - -bool hasEnding (std::string const &fullString, std::string const &ending) { - if (fullString.length() >= ending.length()) { - return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending)); - } else { - return false; - } -} - -int main(int argc, char *argv[]) { - Fr_init(); - if (argc!=3) { - std::string cl = argv[0]; - std::string base_filename = cl.substr(cl.find_last_of("/\\") + 1); - std::cout << "Usage: " << base_filename << " > >\n"; - } else { - - // open output - Circom_CalcWit *ctx = new Circom_CalcWit(&_circuit); - - std::string infilename = argv[1]; - - if (hasEnding(infilename, std::string(".bin"))) { - loadBin(ctx, infilename); - } else if (hasEnding(infilename, std::string(".json"))) { - loadJson(ctx, infilename); - } else { - handle_error("Invalid input extension (.bin / .json)"); - } - - ctx->join(); - - // printf("Finished!\n"); - - std::string outfilename = argv[2]; - - if (hasEnding(outfilename, std::string(".bin"))) { - writeOutBin(ctx, outfilename); - } else if (hasEnding(outfilename, std::string(".json"))) { - writeOutJson(ctx, outfilename); - } else { - handle_error("Invalid output extension (.bin / .json)"); - } - - delete ctx; - exit(EXIT_SUCCESS); - } -} diff --git a/ports/c/mainjson.cpp b/ports/c/mainjson.cpp deleted file mode 100644 index b711e1a..0000000 --- a/ports/c/mainjson.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -using json = nlohmann::json; - - -#include "utils.h" -#include "circom.h" -#include "calcwit.h" - -auto j = R"( - { - "in": "314" - } -)"_json; - -typedef void (*ItFunc)(int idx, json val); - -void iterateArr(int o, Circom_Sizes sizes, json jarr, ItFunc f) { - if (!jarr.is_array()) { - assert((sizes[0] == 1)&&(sizes[1] == 0)); - f(o, jarr); - } else { - int n = sizes[0] / sizes[1]; - for (int i=0; i " << it.value() << '\n'; - u64 h = fnv1a(it.key()); - int o = ctx->getSignalOffset(0, h); - Circom_Sizes sizes = ctx->getSignalSizes(0, h); - iterateArr(o, sizes, it.value(), itFunc); - } -} - diff --git a/ports/c/tester.js b/ports/c/tester.js index 84c1dc0..1edd55c 100644 --- a/ports/c/tester.js +++ b/ports/c/tester.js @@ -8,12 +8,11 @@ const compiler = require("../../src/compiler"); const util = require("util"); const exec = util.promisify(require("child_process").exec); -const stringifyBigInts = require("../../src/utils").stringifyBigInts; -const unstringifyBigInts = require("../../src/utils").unstringifyBigInts; const bigInt = require("big-integer"); const utils = require("../../src/utils"); -const loadR1cs = require("../../src/r1csfile").loadR1cs; -const ZqField = require("fflib").ZqField; +const loadR1cs = require("r1csfile").load; +const ZqField = require("ffjavascript").ZqField; +const buildZqField = require("ffiasm").buildZqField; module.exports = c_tester; @@ -31,22 +30,39 @@ async function c_tester(circomFile, _options) { options.cSourceWriteStream = fs.createWriteStream(path.join(dir.path, baseName + ".cpp")); options.symWriteStream = fs.createWriteStream(path.join(dir.path, baseName + ".sym")); options.r1csFileName = path.join(dir.path, baseName + ".r1cs"); + + options.p = options.p || bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); await compiler(circomFile, options); - const cdir = path.join(__dirname, "..", "c"); - await exec("cp" + - ` ${path.join(dir.path, baseName + ".cpp")}` + - " /tmp/circuit.cpp" - ); + const source = await buildZqField(options.p, "Fr"); + + // console.log(dir.path); + + await fs.promises.writeFile(path.join(dir.path, "fr.asm"), source.asm, "utf8"); + await fs.promises.writeFile(path.join(dir.path, "fr.h"), source.h, "utf8"); + await fs.promises.writeFile(path.join(dir.path, "fr.c"), source.c, "utf8"); + + if (process.platform === "darwin") { + await exec("nasm -fmacho64 --prefix _ " + + ` ${path.join(dir.path, "fr.asm")}` + ); + } else if (process.platform === "linux") { + await exec("nasm -felf64 " + + ` ${path.join(dir.path, "fr.asm")}` + ); + } else throw("Unsupported platform"); + + const cdir = path.join(__dirname, "..", "..", "node_modules", "circom_runtime", "c"); + await exec("g++" + ` ${path.join(cdir, "main.cpp")}` + ` ${path.join(cdir, "calcwit.cpp")}` + ` ${path.join(cdir, "utils.cpp")}` + - ` ${path.join(cdir, "fr.c")}` + - ` ${path.join(cdir, "fr.o")}` + + ` ${path.join(dir.path, "fr.c")}` + + ` ${path.join(dir.path, "fr.o")}` + ` ${path.join(dir.path, baseName + ".cpp")} ` + ` -o ${path.join(dir.path, baseName)}` + - ` -I ${cdir}` + + ` -I ${dir.path} -I${cdir}` + " -lgmp -std=c++11 -DSANITY_CHECK -g" ); @@ -68,7 +84,7 @@ class CTester { async calculateWitness(input) { await fs.promises.writeFile( path.join(this.dir.path, "in.json"), - JSON.stringify(stringifyBigInts(input), null, 1) + JSON.stringify(utils.stringifyBigInts(input), null, 1) ); const r = await exec(`${path.join(this.dir.path, this.baseName)}` + ` ${path.join(this.dir.path, "in.json")}` + @@ -81,7 +97,7 @@ class CTester { path.join(this.dir.path, "out.json") ); - const res = unstringifyBigInts(JSON.parse(resStr)); + const res = utils.unstringifyBigInts(JSON.parse(resStr)); return res; } @@ -95,10 +111,11 @@ class CTester { const lines = symsStr.split("\n"); for (let i=0; i -#include -#include -#include -#include - -#include "utils.h" - -std::string int_to_hex( u64 i ) -{ - std::stringstream stream; - stream << "0x" - << std::setfill ('0') << std::setw(16) - << std::hex << i; - return stream.str(); -} - -u64 fnv1a(std::string s) { - u64 hash = 0xCBF29CE484222325LL; - for(char& c : s) { - hash ^= u64(c); - hash *= 0x100000001B3LL; - } - return hash; -} diff --git a/ports/c/utils.h b/ports/c/utils.h deleted file mode 100644 index e2d72bf..0000000 --- a/ports/c/utils.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __UTILS_H -#define __UTILS_H - -#include "circom.h" - -std::string int_to_hex( u64 i ); -u64 fnv1a(std::string s); - - -#endif // __UTILS_H diff --git a/ports/c/zqfield.cpp b/ports/c/zqfield.cpp deleted file mode 100644 index 84605f6..0000000 --- a/ports/c/zqfield.cpp +++ /dev/null @@ -1,199 +0,0 @@ -#include "zqfield.h" - -ZqField::ZqField(PBigInt ap) { - mpz_init_set(p, *ap); - mpz_init_set_ui(zero, 0); - mpz_init_set_ui(one, 1); - nBits = mpz_sizeinbase (p, 2); - mpz_init(mask); - mpz_mul_2exp(mask, one, nBits-1); - mpz_sub(mask, mask, one); -} - -ZqField::~ZqField() { - mpz_clear(p); - mpz_clear(zero); - mpz_clear(one); -} - -void ZqField::add(PBigInt r, PBigInt a, PBigInt b) { - mpz_add(*r,*a,*b); - if (mpz_cmp(*r, p) >= 0) { - mpz_sub(*r, *r, p); - } -} - -void ZqField::sub(PBigInt r, PBigInt a, PBigInt b) { - if (mpz_cmp(*a, *b) >= 0) { - mpz_sub(*r, *a, *b); - } else { - mpz_sub(*r, *b, *a); - mpz_sub(*r, p, *r); - } -} - -void ZqField::neg(PBigInt r, PBigInt a) { - if (mpz_sgn(*a) > 0) { - mpz_sub(*r, p, *a); - } else { - mpz_set(*r, *a); - } -} - -void ZqField::mul(PBigInt r, PBigInt a, PBigInt b) { - mpz_t tmp; - mpz_init(tmp); - mpz_mul(tmp,*a,*b); - mpz_fdiv_r(*r, tmp, p); - mpz_clear(tmp); -} - -void ZqField::div(PBigInt r, PBigInt a, PBigInt b) { - mpz_t tmp; - mpz_init(tmp); - mpz_invert(tmp, *b, p); - mpz_mul(tmp,*a,tmp); - mpz_fdiv_r(*r, tmp, p); - mpz_clear(tmp); -} - -void ZqField::idiv(PBigInt r, PBigInt a, PBigInt b) { - mpz_fdiv_q(*r, *a, *b); -} - -void ZqField::mod(PBigInt r, PBigInt a, PBigInt b) { - mpz_fdiv_r(*r, *a, *b); -} - -void ZqField::pow(PBigInt r, PBigInt a, PBigInt b) { - mpz_powm(*r, *a, *b, p); -} - -void ZqField::lt(PBigInt r, PBigInt a, PBigInt b) { - int c = mpz_cmp(*a, *b); - if (c<0) { - mpz_set(*r, one); - } else { - mpz_set(*r, zero); - } -} - -void ZqField::eq(PBigInt r, PBigInt a, PBigInt b) { - int c = mpz_cmp(*a, *b); - if (c==0) { - mpz_set(*r, one); - } else { - mpz_set(*r, zero); - } -} - -void ZqField::gt(PBigInt r, PBigInt a, PBigInt b) { - int c = mpz_cmp(*a, *b); - if (c>0) { - mpz_set(*r, one); - } else { - mpz_set(*r, zero); - } -} - -void ZqField::leq(PBigInt r, PBigInt a, PBigInt b) { - int c = mpz_cmp(*a, *b); - if (c<=0) { - mpz_set(*r, one); - } else { - mpz_set(*r, zero); - } -} - -void ZqField::geq(PBigInt r, PBigInt a, PBigInt b) { - int c = mpz_cmp(*a, *b); - if (c>=0) { - mpz_set(*r, one); - } else { - mpz_set(*r, zero); - } -} - -void ZqField::neq(PBigInt r, PBigInt a, PBigInt b) { - int c = mpz_cmp(*a, *b); - if (c!=0) { - mpz_set(*r, one); - } else { - mpz_set(*r, zero); - } -} - -void ZqField::land(PBigInt r, PBigInt a, PBigInt b) { - if (mpz_sgn(*a) && mpz_sgn(*b)) { - mpz_set(*r, one); - } else { - mpz_set(*r, zero); - } -} - -void ZqField::lor(PBigInt r, PBigInt a, PBigInt b) { - if (mpz_sgn(*a) || mpz_sgn(*b)) { - mpz_set(*r, one); - } else { - mpz_set(*r, zero); - } -} - -void ZqField::lnot(PBigInt r, PBigInt a) { - if (mpz_sgn(*a)) { - mpz_set(*r, zero); - } else { - mpz_set(*r, one); - } -} - -int ZqField::isTrue(PBigInt a) { - return mpz_sgn(*a); -} - -void ZqField::copyn(PBigInt a, PBigInt b, int n) { - for (int i=0;i= 0) { - mpz_set(*r, zero); - } else { - mpz_mul_2exp(*r, *a, mpz_get_ui(*b)); - mpz_and(*r, *r, mask); - } -} - -void ZqField::shr(PBigInt r, PBigInt a, PBigInt b) { - if (mpz_cmp_ui(*b, nBits) >= 0) { - mpz_set(*r, zero); - } else { - mpz_tdiv_q_2exp(*r, *a, mpz_get_ui(*b)); - mpz_and(*r, *r, mask); - } -} - -int ZqField::toInt(PBigInt a) { - return mpz_get_si (*a); -} - diff --git a/ports/c/zqfield.h b/ports/c/zqfield.h deleted file mode 100644 index 1080387..0000000 --- a/ports/c/zqfield.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef ZQFIELD_H -#define ZQFIELD_H - -#include "circom.h" - -class ZqField { -public: - BigInt p; - BigInt one; - BigInt zero; - size_t nBits; - BigInt mask; - ZqField(PBigInt ap); - ~ZqField(); - - void copyn(PBigInt a, PBigInt b, int n); - - void add(PBigInt r,PBigInt a, PBigInt b); - void sub(PBigInt r,PBigInt a, PBigInt b); - void neg(PBigInt r,PBigInt a); - void mul(PBigInt r,PBigInt a, PBigInt b); - void div(PBigInt r,PBigInt a, PBigInt b); - void idiv(PBigInt r,PBigInt a, PBigInt b); - void mod(PBigInt r,PBigInt a, PBigInt b); - void pow(PBigInt r,PBigInt a, PBigInt b); - - void lt(PBigInt r, PBigInt a, PBigInt b); - void eq(PBigInt r, PBigInt a, PBigInt b); - void gt(PBigInt r, PBigInt a, PBigInt b); - void leq(PBigInt r, PBigInt a, PBigInt b); - void geq(PBigInt r, PBigInt a, PBigInt b); - void neq(PBigInt r, PBigInt a, PBigInt b); - - void land(PBigInt r, PBigInt a, PBigInt b); - void lor(PBigInt r, PBigInt a, PBigInt b); - void lnot(PBigInt r, PBigInt a); - - void band(PBigInt r, PBigInt a, PBigInt b); - void bor(PBigInt r, PBigInt a, PBigInt b); - void bxor(PBigInt r, PBigInt a, PBigInt b); - void bnot(PBigInt r, PBigInt a); - void shl(PBigInt r, PBigInt a, PBigInt b); - void shr(PBigInt r, PBigInt a, PBigInt b); - - int isTrue(PBigInt a); - int toInt(PBigInt a); -}; - -#endif // ZQFIELD_H diff --git a/ports/wasm/build_runtime.js b/ports/wasm/build_runtime.js index f568e7d..2c74cce 100644 --- a/ports/wasm/build_runtime.js +++ b/ports/wasm/build_runtime.js @@ -1,13 +1,16 @@ const errs = require("./errs"); -const buildWasmFf = require("fflib").buildWasmFf; +const buildWasmFf = require("ffwasm").buildWasmFf; module.exports = function buildRuntime(module, builder) { + const pSanityCheck = module.alloc(4); + function buildInit() { const f = module.addFunction("init"); + f.addParam("sanityCheck", "i32"); f.addLocal("i", "i32"); const c = f.getCodeBuilder(); @@ -26,6 +29,14 @@ module.exports = function buildRuntime(module, builder) { ) ); + // Save Sanity check flag + f.addCode( + c.i32_store( + c.i32_const(pSanityCheck), + c.getLocal("sanityCheck") + ) + ); + f.addCode( // i=0 c.setLocal("i", c.i32_const(0)), @@ -66,38 +77,36 @@ module.exports = function buildRuntime(module, builder) { )) ); - if (builder.sanityCheck) { - f.addCode( - // i=0 - c.setLocal("i", c.i32_const(0)), - c.block(c.loop( - // if (i==NSignals) break - c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(builder.header.NSignals))), - - // signalsAssigned[i] = false - c.i32_store( - c.i32_add( - c.i32_const(builder.pSignalsAssigned), - c.i32_mul( - c.getLocal("i"), - c.i32_const(4) - ) - ), - c.i32_const(0) - ), + f.addCode(ifSanityCheck(c, + // i=0 + c.setLocal("i", c.i32_const(0)), + c.block(c.loop( + // if (i==NSignals) break + c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(builder.header.NSignals))), - // i=i+1 - c.setLocal( - "i", - c.i32_add( + // signalsAssigned[i] = false + c.i32_store( + c.i32_add( + c.i32_const(builder.pSignalsAssigned), + c.i32_mul( c.getLocal("i"), - c.i32_const(1) + c.i32_const(4) ) ), - c.br(0) - )) - ); - } + c.i32_const(0) + ), + + // i=i+1 + c.setLocal( + "i", + c.i32_add( + c.getLocal("i"), + c.i32_const(1) + ) + ), + c.br(0) + )) + )); f.addCode( c.call( @@ -109,14 +118,12 @@ module.exports = function buildRuntime(module, builder) { ) ) ); - if (builder.sanityCheck) { - f.addCode( - c.i32_store( - c.i32_const(builder.pSignalsAssigned), - c.i32_const(1) - ) - ); - } + f.addCode(ifSanityCheck(c, + c.i32_store( + c.i32_const(builder.pSignalsAssigned), + c.i32_const(1) + ) + )); f.addCode( // i=0 @@ -158,6 +165,13 @@ module.exports = function buildRuntime(module, builder) { } + function ifSanityCheck(c, ...args) { + return c.if( + c.i32_load(c.i32_const(pSanityCheck)), + [].concat(...[...args]) + ); + } + function buildTriggerComponent() { const f = module.addFunction("triggerComponent"); @@ -227,9 +241,13 @@ module.exports = function buildRuntime(module, builder) { c.if( c.i64_eqz(c.getLocal("h")), c.call( - "err", + "error", c.i32_const(errs.HASH_NOT_FOUND.code), - c.i32_const(errs.HASH_NOT_FOUND.pointer) + c.i32_const(errs.HASH_NOT_FOUND.pointer), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0) ) ), c.setLocal( @@ -296,9 +314,13 @@ module.exports = function buildRuntime(module, builder) { c.i32_const(type) ), c.call( - "err", + "error", c.i32_const(errs.INVALID_TYPE.code), - c.i32_const(errs.INVALID_TYPE.pointer) + c.i32_const(errs.INVALID_TYPE.pointer), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0) ) ), c.i32_store( @@ -345,28 +367,30 @@ module.exports = function buildRuntime(module, builder) { const c = f.getCodeBuilder(); - if (builder.sanityCheck) { - f.addCode( - c.if( - c.i32_eqz( - c.i32_load( - c.i32_add( - c.i32_const(builder.pSignalsAssigned), - c.i32_mul( - c.getLocal("signal"), - c.i32_const(4) - ) - ), - ) - ), - c.call( - "err", - c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.code), - c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.pointer) + f.addCode(ifSanityCheck(c, + c.if( + c.i32_eqz( + c.i32_load( + c.i32_add( + c.i32_const(builder.pSignalsAssigned), + c.i32_mul( + c.getLocal("signal"), + c.i32_const(4) + ) + ), ) + ), + c.call( + "error", + c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.code), + c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.pointer), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0) ) - ); - } + ) + )); f.addCode( c.call( @@ -381,6 +405,11 @@ module.exports = function buildRuntime(module, builder) { ) ) ); + + f.addCode(ifSanityCheck(c, + c.call("logGetSignal", c.getLocal("signal"), c.getLocal("pR") ) + )); + } @@ -395,25 +424,10 @@ module.exports = function buildRuntime(module, builder) { const c = f.getCodeBuilder(); - if (builder.sanityCheck) { - f.addCode( - c.if( - c.i32_load( - c.i32_add( - c.i32_const(builder.pSignalsAssigned), - c.i32_mul( - c.getLocal("signal"), - c.i32_const(4) - ) - ), - ), - c.call( - "err", - c.i32_const(errs.SIGNAL_ASSIGNED_TWICE.code), - c.i32_const(errs.SIGNAL_ASSIGNED_TWICE.pointer) - ) - ), - c.i32_store( + f.addCode(ifSanityCheck(c, + c.call("logSetSignal", c.getLocal("signal"), c.getLocal("pVal") ), + c.if( + c.i32_load( c.i32_add( c.i32_const(builder.pSignalsAssigned), c.i32_mul( @@ -421,10 +435,28 @@ module.exports = function buildRuntime(module, builder) { c.i32_const(4) ) ), - c.i32_const(1) ), - ); - } + c.call( + "error", + c.i32_const(errs.SIGNAL_ASSIGNED_TWICE.code), + c.i32_const(errs.SIGNAL_ASSIGNED_TWICE.pointer), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0) + ) + ), + c.i32_store( + c.i32_add( + c.i32_const(builder.pSignalsAssigned), + c.i32_mul( + c.getLocal("signal"), + c.i32_const(4) + ) + ), + c.i32_const(1) + ), + )); f.addCode( c.call( @@ -510,11 +542,13 @@ module.exports = function buildRuntime(module, builder) { ) ], c.call( - "err2", + "error", c.i32_const(errs.MAPISINPUT_DONT_MATCH.code), c.i32_const(errs.MAPISINPUT_DONT_MATCH.pointer), c.getLocal("component"), - c.getLocal("signal") + c.getLocal("signal"), + c.i32_const(0), + c.i32_const(0) ) ) ] @@ -528,6 +562,23 @@ module.exports = function buildRuntime(module, builder) { const c = f.getCodeBuilder(); + f.addCode(ifSanityCheck(c, + c.call("logFinishComponent", c.getLocal("cIdx")) + )); + + f.addCode(c.ret([])); + } + + function buildComponentStarted() { + const f = module.addFunction("componentStarted"); + f.addParam("cIdx", "i32"); + + const c = f.getCodeBuilder(); + + f.addCode(ifSanityCheck(c, + c.call("logStartComponent", c.getLocal("cIdx")) + )); + f.addCode(c.ret([])); } @@ -541,33 +592,31 @@ module.exports = function buildRuntime(module, builder) { const c = f.getCodeBuilder(); - if (builder.sanityCheck) { - f.addCode( - c.call( - "Fr_eq", - c.i32_const(pTmp), - c.getLocal("pA"), - c.getLocal("pB") - ), - c.if ( - c.i32_eqz( - c.call( - "Fr_isTrue", - c.i32_const(pTmp), - ) - ), + f.addCode(ifSanityCheck(c, + c.call( + "Fr_eq", + c.i32_const(pTmp), + c.getLocal("pA"), + c.getLocal("pB") + ), + c.if ( + c.i32_eqz( c.call( - "err4", - c.i32_const(errs.CONSTRAIN_DOES_NOT_MATCH.code), - c.i32_const(errs.CONSTRAIN_DOES_NOT_MATCH.pointer), - c.getLocal("cIdx"), - c.getLocal("pA"), - c.getLocal("pB"), - c.getLocal("pStr"), + "Fr_isTrue", + c.i32_const(pTmp), ) + ), + c.call( + "error", + c.i32_const(errs.CONSTRAIN_DOES_NOT_MATCH.code), + c.i32_const(errs.CONSTRAIN_DOES_NOT_MATCH.pointer), + c.getLocal("cIdx"), + c.getLocal("pA"), + c.getLocal("pB"), + c.getLocal("pStr"), ) - ); - } + ) + )); } function buildGetNVars() { @@ -638,9 +687,13 @@ module.exports = function buildRuntime(module, builder) { ) ), c.call( - "err", + "error", c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.code), - c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.pointer) + c.i32_const(errs.ACCESSING_NOT_ASSIGNED_SIGNAL.pointer), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0) ) ) ); @@ -658,35 +711,92 @@ module.exports = function buildRuntime(module, builder) { ); } - const fErr = module.addIimportFunction("err", "runtime"); - fErr.addParam("code", "i32"); - fErr.addParam("pStr", "i32"); - - const fErr1 = module.addIimportFunction("err1", "runtime"); - fErr1.addParam("code", "i32"); - fErr1.addParam("pStr", "i32"); - fErr1.addParam("param1", "i32"); - - const fErr2 = module.addIimportFunction("err2", "runtime"); - fErr2.addParam("code", "i32"); - fErr2.addParam("pStr", "i32"); - fErr2.addParam("param1", "i32"); - fErr2.addParam("param2", "i32"); - - const fErr3 = module.addIimportFunction("err3", "runtime"); - fErr3.addParam("code", "i32"); - fErr3.addParam("pStr", "i32"); - fErr3.addParam("param1", "i32"); - fErr3.addParam("param2", "i32"); - fErr3.addParam("param3", "i32"); - - const fErr4 = module.addIimportFunction("err4", "runtime"); - fErr4.addParam("code", "i32"); - fErr4.addParam("pStr", "i32"); - fErr4.addParam("param1", "i32"); - fErr4.addParam("param2", "i32"); - fErr4.addParam("param3", "i32"); - fErr4.addParam("param4", "i32"); + function buildGetWitnessBuffer() { + const f = module.addFunction("getWitnessBuffer"); + f.setReturnType("i32"); + f.addLocal("i", "i32"); + f.addLocal("pSrc", "i32"); + f.addLocal("pDst", "i32"); + + const c = f.getCodeBuilder(); + + f.addCode( + c.setLocal("i", c.i32_const(0)), + c.block(c.loop( + // if (i==NComponents) break + c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(builder.header.NVars))), + + c.setLocal( + "pSrc", + c.i32_add( + c.i32_const(builder.pSignals), + c.i32_mul( + c.getLocal("i"), + c.i32_const(builder.sizeFr) + ) + ) + ), + + c.call( + "Fr_toLongNormal", + c.getLocal("pSrc") + ), + + c.setLocal( + "pDst", + c.i32_add( + c.i32_const(builder.pSignals), + c.i32_mul( + c.getLocal("i"), + c.i32_const(builder.sizeFr-8) + ) + ) + ), + + c.call( + "Fr_F1m_copy", + c.i32_add(c.getLocal("pSrc"), c.i32_const(8)), + c.getLocal("pDst") + ), + + // i=i+1 + c.setLocal( + "i", + c.i32_add( + c.getLocal("i"), + c.i32_const(1) + ) + ), + c.br(0) + )), + + c.i32_const(builder.pSignals) + ); + + } + + + const fError = module.addIimportFunction("error", "runtime"); + fError.addParam("code", "i32"); + fError.addParam("pStr", "i32"); + fError.addParam("param1", "i32"); + fError.addParam("param2", "i32"); + fError.addParam("param3", "i32"); + fError.addParam("param4", "i32"); + + const fLogSetSignal = module.addIimportFunction("logSetSignal", "runtime"); + fLogSetSignal.addParam("signal", "i32"); + fLogSetSignal.addParam("val", "i32"); + + const fLogGetSignal = module.addIimportFunction("logGetSignal", "runtime"); + fLogGetSignal.addParam("signal", "i32"); + fLogGetSignal.addParam("val", "i32"); + + const fLogFinishComponent = module.addIimportFunction("logFinishComponent", "runtime"); + fLogFinishComponent.addParam("cIdx", "i32"); + + const fLogStartComponent = module.addIimportFunction("logStartComponent", "runtime"); + fLogStartComponent.addParam("cIdx", "i32"); const fLog = module.addIimportFunction("log", "runtime"); fLog.addParam("code", "i32"); @@ -695,9 +805,7 @@ module.exports = function buildRuntime(module, builder) { builder.pSignals=module.alloc(builder.header.NSignals*builder.sizeFr); builder.pInputSignalsToTrigger=module.alloc(builder.header.NComponents*4); - if (builder.sanityCheck) { - builder.pSignalsAssigned=module.alloc(builder.header.NSignals*4); - } + builder.pSignalsAssigned=module.alloc(builder.header.NSignals*4); buildHash2ComponentEntry(); @@ -713,6 +821,7 @@ module.exports = function buildRuntime(module, builder) { buildGetSignal(); buildSetSignal(); + buildComponentStarted(); buildComponentFinished(); buildCheckConstraint(); @@ -721,6 +830,7 @@ module.exports = function buildRuntime(module, builder) { buildGetFrLen(); buildGetPWitness(); buildGetPRawPrime(); + buildGetWitnessBuffer(); // buildFrToInt(); @@ -732,5 +842,6 @@ module.exports = function buildRuntime(module, builder) { module.exportFunction("getPWitness"); module.exportFunction("Fr_toInt"); module.exportFunction("getPRawPrime"); + module.exportFunction("getWitnessBuffer"); }; diff --git a/ports/wasm/builder.js b/ports/wasm/builder.js index 6b5c429..f96bd10 100644 --- a/ports/wasm/builder.js +++ b/ports/wasm/builder.js @@ -528,9 +528,13 @@ class FunctionBuilderWasm { c.getLocal("sp") ), c.call( - "err", + "error", c.i32_const(errs.STACK_OUT_OF_MEM.code), - c.i32_const(errs.STACK_OUT_OF_MEM.pointer) + c.i32_const(errs.STACK_OUT_OF_MEM.pointer), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0) ) ), @@ -550,9 +554,13 @@ class FunctionBuilderWasm { c.getLocal("sp") ), c.call( - "err", + "error", c.i32_const(errs.STACK_TOO_SMALL.code), - c.i32_const(errs.STACK_TOO_SMALL.pointer) + c.i32_const(errs.STACK_TOO_SMALL.pointer), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0), + c.i32_const(0) ) ), @@ -650,7 +658,12 @@ class FunctionBuilderWasm { const c = f.getCodeBuilder(); + const code = []; + if (this.type=="COMPONENT") { + code.push(c.call("componentStarted", c.getLocal("cIdx"))); + } + code.push(this._buildHeader(c)); code.push(this.body.build(c)); if (this.type=="COMPONENT") { @@ -676,7 +689,7 @@ class FunctionBuilderWasm { } class BuilderWasm { - constructor(sanityCheck) { + constructor() { this.hashMaps={}; this.componentEntriesTables={}; this.sizes ={}; @@ -684,7 +697,6 @@ class BuilderWasm { this.usedConstants = {}; this.functions = []; this.components = []; - this.sanityCheck = sanityCheck; this.TYPE_SIGNAL = 1; this.TYPE_COMPONENT = 2; diff --git a/ports/wasm/tester.js b/ports/wasm/tester.js index 1a36bba..8da1644 100644 --- a/ports/wasm/tester.js +++ b/ports/wasm/tester.js @@ -5,21 +5,16 @@ const fs = require("fs"); var tmp = require("tmp-promise"); const path = require("path"); const compiler = require("../../src/compiler"); -const util = require("util"); -const exec = util.promisify(require("child_process").exec); -const stringifyBigInts = require("../../src/utils").stringifyBigInts; -const unstringifyBigInts = require("../../src/utils").unstringifyBigInts; const bigInt = require("big-integer"); const utils = require("../../src/utils"); -const loadR1cs = require("../../src/r1csfile").loadR1cs; -const ZqField = require("fflib").ZqField; +const loadR1cs = require("r1csfile").load; +const ZqField = require("ffjavascript").ZqField; -const WitnessCalculator = require("./witness_calculator"); +const WitnessCalculatorBuilder = require("circom_runtime").WitnessCalculatorBuilder; module.exports = wasm_tester; - async function wasm_tester(circomFile, _options) { tmp.setGracefulCleanup(); @@ -33,7 +28,6 @@ async function wasm_tester(circomFile, _options) { options.wasmWriteStream = fs.createWriteStream(path.join(dir.path, baseName + ".wasm")); options.symWriteStream = fs.createWriteStream(path.join(dir.path, baseName + ".sym")); options.r1csFileName = path.join(dir.path, baseName + ".r1cs"); - options.sanityCheck = true; const promisesArr = []; promisesArr.push(new Promise(fulfill => options.wasmWriteStream.on("finish", fulfill))); @@ -42,7 +36,9 @@ async function wasm_tester(circomFile, _options) { await Promise.all(promisesArr); - const wc = await WitnessCalculator.fromFile(path.join(dir.path, baseName + ".wasm")); + const wasm = await fs.promises.readFile(path.join(dir.path, baseName + ".wasm")); + + const wc = await WitnessCalculatorBuilder(wasm); return new WasmTester(dir, baseName, wc); } @@ -74,10 +70,11 @@ class WasmTester { const lines = symsStr.split("\n"); for (let i=0; i0; i++) bytes.push(i8[p+i]); - - return String.fromCharCode.apply(null, bytes); - } -}; - -class WitnessCalculator { - constructor(memory, instance) { - this.memory = memory; - this.i32 = new Uint32Array(memory.buffer); - this.instance = instance; - - this.n32 = (this.instance.exports.getFrLen() >> 2) - 2; - const pRawPrime = this.instance.exports.getPRawPrime(); - - this.prime = bigInt(0); - for (let i=this.n32-1; i>=0; i--) { - this.prime = this.prime.shiftLeft(32); - this.prime = this.prime.add(bigInt(this.i32[(pRawPrime >> 2) + i])); - } - - this.mask32 = bigInt("FFFFFFFF", 16); - this.NVars = this.instance.exports.getNVars(); - this.n64 = Math.floor((this.prime.bitLength() - 1) / 64)+1; - this.R = bigInt.one.shiftLeft(this.n64*64); - this.RInv = this.R.modInv(this.prime); - - } - - async calculateWitness(input) { - const w = []; - const old0 = this.i32[0]; - this.instance.exports.init(); - const pSigOffset = this.allocInt(); - const pFr = this.allocFr(); - for (let k in input) { - const h = utils.fnvHash(k); - const hMSB = parseInt(h.slice(0,8), 16); - const hLSB = parseInt(h.slice(8,16), 16); - this.instance.exports.getSignalOffset32(pSigOffset, 0, hMSB, hLSB); - const sigOffset = this.getInt(pSigOffset); - const fArr = utils.flatArray(input[k]); - for (let i=0; i>2]; - } - - setInt(p, v) { - this.i32[p>>2] = v; - } - - getFr(p) { - const self = this; - const idx = (p>>2); - - if (self.i32[idx + 1] & 0x80000000) { - let res= bigInt(0); - for (let i=self.n32-1; i>=0; i--) { - res = res.shiftLeft(32); - res = res.add(bigInt(self.i32[idx+2+i])); - } - if (self.i32[idx + 1] & 0x40000000) { - return fromMontgomery(res); - } else { - return res; - } - - } else { - if (self.i32[idx] & 0x80000000) { - return self.prime.add( bigInt(self.i32[idx]).minus(bigInt(0x100000000)) ); - } else { - return bigInt(self.i32[idx]); - } - } - - function fromMontgomery(n) { - return n.times(self.RInv).mod(self.prime); - } - - } - - - setFr(p, v) { - const self = this; - v = bigInt(v); - - if (v.lt(bigInt("80000000", 16)) ) { - return setShortPositive(v); - } - if (v.geq(self.prime.minus(bigInt("80000000", 16))) ) { - return setShortNegative(v); - } - return setLongNormal(v); - - function setShortPositive(a) { - self.i32[(p >> 2)] = parseInt(a); - self.i32[(p >> 2) + 1] = 0; - } - - function setShortNegative(a) { - const b = bigInt("80000000", 16 ).add(a.minus( self.prime.minus(bigInt("80000000", 16 )))); - self.i32[(p >> 2)] = parseInt(b); - self.i32[(p >> 2) + 1] = 0; - } - - function setLongNormal(a) { - self.i32[(p >> 2)] = 0; - self.i32[(p >> 2) + 1] = 0x80000000; - for (let i=0; i> 2) + 2 + i] = a.shiftRight(i*32).and(self.mask32); - } - } - } -} - - - diff --git a/src/buildsyms.js b/src/buildsyms.js index 688f1b2..f99bc70 100644 --- a/src/buildsyms.js +++ b/src/buildsyms.js @@ -19,7 +19,7 @@ module.exports = function buildSyms(ctx) { while (ctx.signals[s].e >= 0) s = ctx.signals[s].e; let wId = ctx.signals[s].id; if (typeof(wId) == "undefined") wId=-1; - rs.push(`${actual.offset},${wId},${actual.name}\n`); + rs.push(`${actual.offset},${wId},${actual.cIdx},${actual.name}\n`); it.next(); counter ++; @@ -32,11 +32,12 @@ module.exports = function buildSyms(ctx) { class SignalIt { - constructor (ctx, offset, prefix) { + constructor (ctx, offset, prefix, cIdx) { this.ctx = ctx; this.offset = offset; this.prefix = prefix; this.cur = 0; + this.cIdx = cIdx; } next() { @@ -47,16 +48,16 @@ class SignalIt { current() { if (this.cur == 0) { - return {offset: this.offset, name: this.prefix}; + return {offset: this.offset, name: this.prefix, cIdx: this.cIdx}; } } } class ArrayIt { - constructor (ctx, type, sizes, offset, prefix) { + constructor (ctx, type, sizes, offset, prefix, cIdx) { if (sizes.length == 0) { if (type == "S") { - return new SignalIt(ctx, offset, prefix); + return new SignalIt(ctx, offset, prefix, cIdx); } else { return new ComponentIt(ctx, offset, prefix); } @@ -67,6 +68,7 @@ class ArrayIt { this.sizes = sizes; this.offset = offset; this.prefix = prefix; + this.cIdx = cIdx; @@ -86,7 +88,7 @@ class ArrayIt { _loadSubIt() { if (this.cur < this.sizes[0]) { - this.subIt = new ArrayIt(this.ctx, this.type, this.sizes.slice(1), this.offset + this.cur*this.subArrSize, this.prefix + "[" + this.cur + "]"); + this.subIt = new ArrayIt(this.ctx, this.type, this.sizes.slice(1), this.offset + this.cur*this.subArrSize, this.prefix + "[" + this.cur + "]", this.cIdx); } } @@ -129,7 +131,7 @@ class ComponentIt { _loadSubIt() { if (this.cur < this.names.length) { const entrie = this.ctx.components[this.idxComponent].names.o[this.names[this.cur]]; - this.subIt = new ArrayIt(this.ctx, entrie.type, entrie.sizes, entrie.offset, this.prefix + "." + this.names[this.cur]); + this.subIt = new ArrayIt(this.ctx, entrie.type, entrie.sizes, entrie.offset, this.prefix + "." + this.names[this.cur], this.idxComponent); } } diff --git a/src/compiler.js b/src/compiler.js index 4016c3d..005fdd1 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -18,14 +18,14 @@ */ const bigInt = require("big-integer"); -const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); +const __P__ = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); const sONE = 0; const build = require("./build"); const BuilderC = require("../ports/c/builder.js"); const BuilderWasm = require("../ports/wasm/builder.js"); const constructionPhase = require("./construction_phase"); const Ctx = require("./ctx"); -const ZqField = require("fflib").ZqField; +const ZqField = require("ffjavascript").ZqField; const utils = require("./utils"); const buildR1cs = require("./r1csfile").buildR1cs; const BigArray = require("./bigarray"); @@ -49,7 +49,7 @@ async function compile(srcFile, options) { constructionPhase(ctx, srcFile); - console.log("NConstraints Before: "+ctx.constraints.length); + if (ctx.verbose) console.log("NConstraints Before: "+ctx.constraints.length); if (ctx.error) { throw(ctx.error); @@ -70,13 +70,13 @@ async function compile(srcFile, options) { // Repeat while reductions are performed let oldNConstrains = -1; while (ctx.constraints.length != oldNConstrains) { - console.log("Reducing constraints: "+ctx.constraints.length); + if (ctx.verbose) console.log("Reducing constraints: "+ctx.constraints.length); oldNConstrains = ctx.constraints.length; reduceConstrains(ctx); } } - console.log("NConstraints After: "+ctx.constraints.length); + if (ctx.verbose) console.log("NConstraints After: "+ctx.constraints.length); generateWitnessNames(ctx); @@ -94,7 +94,7 @@ async function compile(srcFile, options) { } if ((options.wasmWriteStream)||(options.watWriteStream)) { - ctx.builder = new BuilderWasm(options.sanityCheck); + ctx.builder = new BuilderWasm(); build(ctx); if (options.wasmWriteStream) { const rdStream = ctx.builder.build("wasm"); diff --git a/src/construction_phase.js b/src/construction_phase.js index 3f3262c..2736e86 100644 --- a/src/construction_phase.js +++ b/src/construction_phase.js @@ -924,7 +924,9 @@ function execConstrain(ctx, ast) { if (!ctx.lc.isZero(res)) { ctx.constraints.push(ctx.lc.toQEX(res)); - if ((ctx.constraints.length % 10000 == 0)&&(ctx.constraints.length>0)) console.log("Constraints: " + ctx.constraints.length); + if (ctx.verbose) { + if ((ctx.constraints.length % 10000 == 0)&&(ctx.constraints.length>0)) console.log("Constraints: " + ctx.constraints.length); + } } return a; diff --git a/src/r1csfile.js b/src/r1csfile.js index 8ea335d..f141f9a 100644 --- a/src/r1csfile.js +++ b/src/r1csfile.js @@ -4,157 +4,6 @@ const assert = require("assert"); const bigInt = require("big-integer"); module.exports.buildR1cs = buildR1cs; -module.exports.loadR1cs = loadR1cs; - -async function loadR1cs(fileName, loadConstraints, loadMap) { - const res = {}; - const fd = await fs.promises.open(fileName, "r"); - - const b = Buffer.allocUnsafe(4); - await fd.read(b, 0, 4, 0); - - if (b.toString() != "r1cs") assert(false, "Invalid File format"); - - let p=4; - - let v = await readU32(); - - if (v>1) assert(false, "Version not supported"); - - const nSections = await readU32(); - - let pHeader; - let pConstraints; - let headerSize; - let constraintsSize; - let pMap; - let mapSize; - for (let i=0; i { await doTest(wasm_tester, basicCases[i].circuit, basicCases[i].tv); }); } -*/ + }); diff --git a/test/basiccases.js.old b/test/basiccases.js.old deleted file mode 100644 index f7351ec..0000000 --- a/test/basiccases.js.old +++ /dev/null @@ -1,343 +0,0 @@ -const path = require("path"); - -const bigInt = require("big-integer"); -const c_tester = require("../index.js").c_tester; - -const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); - - -function normalize(o) { - if ((typeof(o) == "bigint") || o.isZero !== undefined) { - const res = bigInt(o); - return norm(res); - } else if (Array.isArray(o)) { - return o.map(normalize); - } else if (typeof o == "object") { - const res = {}; - for (let k in o) { - res[k] = normalize(o[k]); - } - return res; - } else { - const res = bigInt(o); - return norm(res); - } - - function norm(n) { - let res = n.mod(__P__); - if (res.isNegative()) res = __P__.add(res); - return res; - } -} - - -async function doTest(circuit, testVectors) { - const cir = await c_tester(path.join(__dirname, "circuits", circuit)); - - for (let i=0; i { - await doTest( - "inout.circom", - [ - [{in1: 1, in2: [2,3], in3:[[4,5], [6,7], [8,9]]}, {out1: 1, out2: [2,3], out3: [[4,5], [6,7],[8,9]]}], - ] - ); - }); - it("add", async () => { - await doTest( - "add.circom", - [ - [{in: [0,0]}, {out: 0}], - [{in: [0,1]}, {out: 1}], - [{in: [1,2]}, {out: 3}], - [{in: [__P__.minus(1),1]}, {out: 0}], - ] - ); - }); - it("add constant", async () => { - await doTest( - "addconst1.circom", - [ - [{in: 0}, {out: 15}], - [{in: 10}, {out: 25}], - [{in: __P__.minus(2)}, {out: 13}], - ] - ); - }); - it("for unrolled", async () => { - await doTest( - "forunrolled.circom", - [ - [{in: 0}, {out: [0,1,2]}], - [{in: 10}, {out: [10, 11, 12]}], - [{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}], - ] - ); - }); - it("for rolled", async () => { - await doTest( - "forrolled.circom", - [ - [{in: 0}, {out: 0}], - [{in: 10}, {out: 10}], - ] - ); - }); - it("while unrolled", async () => { - await doTest( - "whileunrolled.circom", - [ - [{in: 0}, {out: [0,1,2]}], - [{in: 10}, {out: [10, 11, 12]}], - [{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}], - ] - ); - }); - it("while rolled", async () => { - await doTest( - "whilerolled.circom", - [ - [{in: 0}, {out: 0}], - [{in: 10}, {out: 10}], - ] - ); - }); - it("function1", async () => { - await doTest( - "function1.circom", - [ - [{in: 0}, {out: 3}], - [{in: 10}, {out: 13}], - [{in: __P__.minus(2)}, {out: 1}], - ] - ); - }); - it("function2", async () => { - await doTest( - "function2.circom", - [ - [{in: 0}, {out: 3}], - [{in: 10}, {out: 13}], - [{in: __P__.minus(2)}, {out: 1}], - ] - ); - }); - it("constants1", async () => { - await doTest( - "constants1.circom", - [ - [{in: 0}, {out: 42}], - [{in: 10}, {out: 52}], - [{in: __P__.minus(2)}, {out: 40}], - ] - ); - }); - it("arrays", async () => { - await doTest( - "arrays.circom", - [ - [{in: 0}, {out: [1, 8, 51]}], - [{in: 10}, {out: [11, 28, 111]}], - [{in: __P__.minus(2)}, {out: [__P__.minus(1), 4, 39]}], - ] - ); - }); - it("if unrolled", async () => { - await doTest( - "ifunrolled.circom", - [ - [{in: 0}, {out: [1, 3, 6]}], - [{in: 10}, {out: [11, 13, 16]}], - [{in: __P__.minus(2)}, {out: [__P__.minus(1), 1, 4]}], - ] - ); - }); - it("if rolled", async () => { - await doTest( - "ifrolled.circom", - [ - [{in: 0}, {out: [1, 0, 0]}], - [{in: 1}, {out: [0, 1, 0]}], - [{in: 2}, {out: [0, 0, 1]}], - [{in: 3}, {out: [0, 0, 0]}], - [{in: __P__.minus(2)}, {out: [0,0,0]}], - ] - ); - }); - it("inc", async () => { - await doTest( - "inc.circom", - [ - [{in: 0}, {out: [5, 2]}], - [{in: 1}, {out: [6, 4]}], - [{in: 2}, {out: [7, 6]}], - [{in: 3}, {out: [8, 8]}], - [{in: __P__.minus(2)}, {out: [3,__P__.minus(2)]}], - ] - ); - }); - it("dec", async () => { - await doTest( - "dec.circom", - [ - [{in: 0}, {out: [1, __P__.minus(2)]}], - [{in: 1}, {out: [2, 0]}], - [{in: 2}, {out: [3, 2]}], - [{in: 3}, {out: [4, 4]}], - [{in: __P__.minus(2)}, {out: [__P__.minus(1),__P__.minus(6)]}], - ] - ); - }); - it("ops", async () => { - await doTest( - "ops.circom", - [ - [{in: [-2, 2]}, {add: 0, sub: -4, mul: -4}], - [{in: [-1, 1]}, {add: 0, sub: -2, mul: -1}], - [{in: [ 0, 0]}, {add: 0, sub: 0, mul: 0}], - [{in: [ 1,-1]}, {add: 0, sub: 2, mul: -1}], - [{in: [ 2,-2]}, {add: 0, sub: 4, mul: -4}], - [{in: [-2,-3]}, {add: -5, sub: 1, mul: 6}], - [{in: [ 2, 3]}, {add: 5, sub: -1, mul: 6}], - ] - ); - }); - it("ops2", async () => { - await doTest( - "ops2.circom", - [ - [{in: [-2, 2]}, {div: -1, idiv: bigInt("10944121435919637611123202872628637544274182200208017171849102093287904247807"), mod: 1}], - [{in: [-1, 1]}, {div: -1, idiv: -1, mod: 0}], - [{in: [ 1,-1]}, {div: -1, idiv: 0, mod: 1}], - ] - ); - }); - it("ops3", async () => { - await doTest( - "ops3.circom", - [ - [{in: [-2, 2]}, {neg1: 2,neg2: -2, pow: 4}], - [{in: [0, 1]}, {neg1: 0, neg2: -1, pow: 0}], - [{in: [ 1,-1]}, {neg1: -1, neg2: 1, pow: 1}], - ] - ); - }); - it("Comparation ops", async () => { - await doTest( - "opscmp.circom", - [ - [{in: [ 8, 9]}, {lt: 1, leq: 1, eq:0, neq:1, geq: 0, gt:0}], - [{in: [-2,-2]}, {lt: 0, leq: 1, eq:1, neq:0, geq: 1, gt:0}], - [{in: [-1,-2]}, {lt: 0, leq: 0, eq:0, neq:1, geq: 1, gt:1}], - [{in: [ 1,-1]}, {lt: 0, leq: 0, eq:0, neq:1, geq: 1, gt:1}], // In mod, negative values are higher than positive. - ] - ); - }); - it("Bit ops", async () => { - const mask = bigInt("14474011154664524427946373126085988481658748083205070504932198000989141204991"); - const m1m = bigInt("7414231717174750794300032619171286606889616317210963838766006185586667290624"); - await doTest( - "opsbit.circom", - [ - [{in: [ 5, 3]}, {and: 1, or: 7, xor:6, not1:mask.minus(5), shl: 40, shr:0}], - [{in: [ 0, 0]}, {and: 0, or: 0, xor:0, not1:mask, shl: 0, shr:0}], - [{in: [-1, 1]}, {and: 0, or: m1m.add(bigInt.one), xor:m1m.add(bigInt.one), not1:mask.minus(m1m), shl: m1m.shiftLeft(1).and(mask), shr:__P__.shiftRight(1).and(mask)}], - ] - ); - }); - it("Logical ops", async () => { - await doTest( - "opslog.circom", - [ - [{in: [ 5, 0]}, {and: 0, or: 1, not1:0}], - [{in: [ 0, 1]}, {and: 0, or: 1, not1:1}], - [{in: [-1, 9]}, {and: 1, or: 1, not1:0}], - [{in: [ 0, 0]}, {and: 0, or: 0, not1:1}], - ] - ); - }); - - it("Conditional Ternary operator", async () => { - await doTest( - "condternary.circom", - [ - [{in: 0}, {out: 21}], - [{in: 1}, {out: 1}], - [{in: 2}, {out: 23}], - [{in:-1}, {out: 20}], - ] - ); - }); - - it("Compute block", async () => { - await doTest( - "compute.circom", - [ - [{x: 1}, {y: 7}], - [{x: 2}, {y: 7}], - [{x: 3}, {y: 11}], - [{x:-1}, {y: -5}], - ] - ); - }); - it("Component array ", async () => { - await doTest( - "componentarray.circom", - [ - [{in: 1}, {out: 1}], - [{in: 2}, {out: 256}], - [{in: 3}, {out: 6561}], - [{in:-1}, {out: 1}], - ] - ); - }); - it("Component array 2d", async () => { - await doTest( - "componentarray2.circom", - [ - [{in: [1,2]}, {out: [1, 256]}], - [{in: [0,3]}, {out: [0, 6561]}], - ] - ); - }); - it("Constant circuit", async () => { - await doTest( - "constantcircuit.circom", - [ - // 0xbb67ae85 - [{}, {out: [1,0,1,0, 0,0,0,1, 0,1,1,1, 0,1,0,1, 1,1,1,0, 0,1,1,0, 1,1,0,1, 1,1,0,1]}], - ] - ); - }); - it("Constant internal circuit", async () => { - await doTest( - "constantinternalcircuit.circom", - [ - [{in: 1}, {out: 5}], - [{in: 0}, {out: 4}], - [{in: -2}, {out: 2}], - [{in: 10}, {out: 14}] - ] - ); - }); - it("include", async () => { - await doTest( - "include.circom", - [ - [{in: 3}, {out: 6}], - [{in: 6}, {out: 15}], - ] - ); - }); - -}); diff --git a/test/cases.js b/test/cases.js deleted file mode 100644 index 7b98d83..0000000 --- a/test/cases.js +++ /dev/null @@ -1,67 +0,0 @@ -const chai = require("chai"); -const path = require("path"); -const snarkjs = require("snarkjs"); - -const bigInt = snarkjs.bigInt; - -const compiler = require("../index.js"); - -const assert = chai.assert; - -async function assertThrowsAsync(fn, regExp) { - let f = () => {}; - try { - await fn(); - } catch(e) { - f = () => { throw e; }; - } finally { - assert.throws(f, regExp); - } -} - -describe("Sum test", () => { - it("Should compile a code with an undefined if", async () => { - await compiler(path.join(__dirname, "circuits", "undefinedif.circom")); - }); - it("Should compile a code with vars inside a for", async () => { - const cirDef = await compiler(path.join(__dirname, "circuits", "forvariables.circom")); - - const circuit = new snarkjs.Circuit(cirDef); - - const witness = circuit.calculateWitness({ "in": 111}); - assert(witness[0].equals(bigInt(1))); - assert(witness[1].equals(bigInt(114))); - assert(witness[2].equals(bigInt(111))); - - }); - it("Should compile a code with an undefined if", async () => { - const cirDef = await compiler(path.join(__dirname, "circuits", "mixvarsignal.circom")); - - const circuit = new snarkjs.Circuit(cirDef); - - const witness = circuit.calculateWitness({ "i": 111}); - assert(witness[0].equals(bigInt(1))); - assert(witness[1].equals(bigInt(111*111))); - assert(witness[2].equals(bigInt(111))); - }); -// it("Should assign signal ERROR", async () => { -// await assertThrowsAsync(async () => { -// await compiler(path.join(__dirname, "circuits", "assignsignal.circom")); -// }, /Cannot assign to a signal .*/); -// }); - it("Should compile a code with compute", async () => { - const cirDef = await compiler(path.join(__dirname, "circuits", "compute.circom")); - - const circuit = new snarkjs.Circuit(cirDef); - - const witness = circuit.calculateWitness({ "x": 6}); - assert(witness[0].equals(bigInt(1))); - assert(witness[1].equals(bigInt(37))); - assert(witness[2].equals(bigInt(6))); - }); - it("Should compile a code with compute", async () => { - const cirDef = await compiler(path.join(__dirname, "circuits", "inout.circom")); - - assert.equal(cirDef.constraints.length, 1); - }); -}); diff --git a/test/fieldasm.js b/test/fieldasm.js deleted file mode 100644 index 205fc8c..0000000 --- a/test/fieldasm.js +++ /dev/null @@ -1,453 +0,0 @@ -const tester = require("../ports/c/buildasm/buildzqfieldtester.js"); - -const ZqField = require("fflib").ZqField; - -const bigInt = require("big-integer"); - -const bn128q = new bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583"); -const bn128r = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); -const secp256k1q = new bigInt("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16); -const secp256k1r = new bigInt("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16); -const mnt6753q = new bigInt("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160001"); -const mnt6753r = new bigInt("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689601"); - -describe("field asm test", function () { - this.timeout(1000000000); - it("bn128r add", async () => { - const tv = buildTestVector2(bn128r, "add"); - await tester(bn128r, tv); - }); -/* - it("secp256k1q add", async () => { - const tv = buildTestVector2(secp256k1q, "add"); - await tester(secp256k1q, tv); - }); - it("mnt6753q add", async () => { - const tv = buildTestVector2(mnt6753q, "add"); - await tester(mnt6753q, tv); - }); - it("bn128r sub", async () => { - const tv = buildTestVector2(bn128r, "sub"); - await tester(bn128r, tv); - }); - it("secp256k1q sub", async () => { - const tv = buildTestVector2(secp256k1q, "sub"); - await tester(secp256k1q, tv); - }); - it("mnt6753q sub", async () => { - const tv = buildTestVector2(mnt6753q, "sub"); - await tester(mnt6753q, tv); - }); - it("bn128r neg", async () => { - const tv = buildTestVector1(bn128r, "neg"); - await tester(bn128r, tv); - }); - it("secp256k1q neg", async () => { - const tv = buildTestVector1(secp256k1q, "neg"); - await tester(secp256k1q, tv); - }); - it("mnt6753q neg", async () => { - const tv = buildTestVector1(mnt6753q, "neg"); - await tester(mnt6753q, tv); - }); - it("bn128r mul", async () => { - const tv = buildTestVector2(bn128r, "mul"); - await tester(bn128r, tv); - }); - it("secp256k1q mul", async () => { - const tv = buildTestVector2(secp256k1q, "mul"); - await tester(secp256k1q, tv); - }); - it("mnt6753q mul", async () => { - const tv = buildTestVector2(mnt6753q, "mul"); - await tester(mnt6753q, tv); - }); - it("bn128r binary and", async () => { - const tv = buildTestVector2(bn128r, "band"); - await tester(bn128r, tv); - }); - it("secp256k1q binary and", async () => { - const tv = buildTestVector2(secp256k1q, "band"); - await tester(secp256k1q, tv); - }); - it("mnt6753q binary and", async () => { - const tv = buildTestVector2(mnt6753q, "band"); - await tester(mnt6753q, tv); - }); - it("bn128r binary or", async () => { - const tv = buildTestVector2(bn128r, "bor"); - await tester(bn128r, tv); - }); - it("secp256k1q binary or", async () => { - const tv = buildTestVector2(secp256k1q, "bor"); - await tester(secp256k1q, tv); - }); - it("mnt6753q binary or", async () => { - const tv = buildTestVector2(mnt6753q, "bor"); - await tester(mnt6753q, tv); - }); - it("bn128r binary xor", async () => { - const tv = buildTestVector2(bn128r, "bxor"); - await tester(bn128r, tv); - }); - it("secp256k1q binary xor", async () => { - const tv = buildTestVector2(secp256k1q, "bxor"); - await tester(secp256k1q, tv); - }); - it("mnt6753q binary xor", async () => { - const tv = buildTestVector2(mnt6753q, "bxor"); - await tester(mnt6753q, tv); - }); - it("bn128r binary not", async () => { - const tv = buildTestVector1(bn128r, "bnot"); - await tester(bn128r, tv); - }); - it("secp256k1q binary not", async () => { - const tv = buildTestVector1(secp256k1q, "bnot"); - await tester(secp256k1q, tv); - }); - it("mnt6753q binary not", async () => { - const tv = buildTestVector1(mnt6753q, "bnot"); - await tester(mnt6753q, tv); - }); - it("bn128r eq", async () => { - const tv = buildTestVector2(bn128r, "eq"); - await tester(bn128r, tv); - }); - it("secp256k1q eq", async () => { - const tv = buildTestVector2(secp256k1q, "eq"); - await tester(secp256k1q, tv); - }); - it("mnt6753q eq", async () => { - const tv = buildTestVector2(mnt6753q, "eq"); - await tester(mnt6753q, tv); - }); - it("bn128r neq", async () => { - const tv = buildTestVector2(bn128r, "neq"); - await tester(bn128r, tv); - }); - it("secp256k1q neq", async () => { - const tv = buildTestVector2(secp256k1q, "neq"); - await tester(secp256k1q, tv); - }); - it("mnt6753q neq", async () => { - const tv = buildTestVector2(mnt6753q, "neq"); - await tester(mnt6753q, tv); - }); - it("bn128r lt", async () => { - const tv = buildTestVector2(bn128r, "lt"); - await tester(bn128r, tv); - }); - it("secp256k1q lt", async () => { - const tv = buildTestVector2(secp256k1q, "lt"); - await tester(secp256k1q, tv); - }); - it("mnt6753q lt", async () => { - const tv = buildTestVector2(mnt6753q, "lt"); - await tester(mnt6753q, tv); - }); - it("bn128r gt", async () => { - const tv = buildTestVector2(bn128r, "gt"); - await tester(bn128r, tv); - }); - it("secp256k1q gt", async () => { - const tv = buildTestVector2(secp256k1q, "gt"); - await tester(secp256k1q, tv); - }); - it("mnt6753q gt", async () => { - const tv = buildTestVector2(mnt6753q, "gt"); - await tester(mnt6753q, tv); - }); - it("bn128r leq", async () => { - const tv = buildTestVector2(bn128r, "leq"); - await tester(bn128r, tv); - }); - it("secp256k1q leq", async () => { - const tv = buildTestVector2(secp256k1q, "leq"); - await tester(secp256k1q, tv); - }); - it("mnt6753q leq", async () => { - const tv = buildTestVector2(mnt6753q, "leq"); - await tester(mnt6753q, tv); - }); - it("bn128r geq", async () => { - const tv = buildTestVector2(bn128r, "geq"); - await tester(bn128r, tv); - }); - it("secp256k1q geq", async () => { - const tv = buildTestVector2(secp256k1q, "geq"); - await tester(secp256k1q, tv); - }); - it("mnt6753q geq", async () => { - const tv = buildTestVector2(mnt6753q, "geq"); - await tester(mnt6753q, tv); - }); - it("bn128r logical and", async () => { - const tv = buildTestVector2(bn128r, "land"); - await tester(bn128r, tv); - }); - it("secp256k1q logical and", async () => { - const tv = buildTestVector2(secp256k1q, "land"); - await tester(secp256k1q, tv); - }); - it("mnt6753q logical and", async () => { - const tv = buildTestVector2(mnt6753q, "land"); - await tester(mnt6753q, tv); - }); - it("bn128r logical or", async () => { - const tv = buildTestVector2(bn128r, "lor"); - await tester(bn128r, tv); - }); - it("secp256k1q logical or", async () => { - const tv = buildTestVector2(secp256k1q, "lor"); - await tester(secp256k1q, tv); - }); - it("mnt6753q logical or", async () => { - const tv = buildTestVector2(mnt6753q, "lor"); - await tester(mnt6753q, tv); - }); - it("bn128r logical not", async () => { - const tv = buildTestVector1(bn128r, "lnot"); - await tester(bn128r, tv); - }); - it("secp256k1q logical not", async () => { - const tv = buildTestVector1(secp256k1q, "lnot"); - await tester(secp256k1q, tv); - }); - it("mnt6753q logical not", async () => { - const tv = buildTestVector1(mnt6753q, "lnot"); - await tester(mnt6753q, tv); - }); - it("bn128r idiv", async () => { - const tv = buildTestVector2(bn128r, "idiv"); - await tester(bn128r, tv); - }); - it("secp256k1q idiv", async () => { - const tv = buildTestVector2(secp256k1q, "idiv"); - await tester(secp256k1q, tv); - }); - it("mnt6753q idiv", async () => { - const tv = buildTestVector2(mnt6753q, "idiv"); - await tester(mnt6753q, tv); - }); - it("bn128r inv", async () => { - const tv = buildTestVector1(bn128r, "inv"); - await tester(bn128r, tv); - }); - it("secp256k1q inv", async () => { - const tv = buildTestVector1(secp256k1q, "inv"); - await tester(secp256k1q, tv); - }); - it("mnt6753q inv", async () => { - const tv = buildTestVector1(mnt6753q, "inv"); - await tester(mnt6753q, tv); - }); - it("bn128r div", async () => { - const tv = buildTestVector2(bn128r, "div"); - await tester(bn128r, tv); - }); - it("secp256k1q div", async () => { - const tv = buildTestVector2(secp256k1q, "div"); - await tester(secp256k1q, tv); - }); - it("mnt6753q div", async () => { - const tv = buildTestVector2(mnt6753q, "div"); - await tester(mnt6753q, tv); - }); - it("bn128r square", async () => { - const tv = buildTestVector1(bn128r, "square"); - await tester(bn128r, tv); - }); - it("secp256k1q square", async () => { - const tv = buildTestVector1(secp256k1q, "square"); - await tester(secp256k1q, tv); - }); - it("mnt6753q square", async () => { - const tv = buildTestVector1(mnt6753q, "square"); - await tester(mnt6753q, tv); - }); -*/ - it("bn128r shl", async () => { - const tv = buildTestVector2(bn128r, "shl"); - await tester(bn128r, tv); - }); -/* - it("secp256k1q shl", async () => { - const tv = buildTestVector2(secp256k1q, "shl"); - await tester(secp256k1q, tv); - }); - it("mnt6753q shl", async () => { - const tv = buildTestVector2(mnt6753q, "shl"); - await tester(mnt6753q, tv); - }); -*/ - it("bn128r shr", async () => { - const tv = buildTestVector2(bn128r, "shr"); - await tester(bn128r, tv); - }); -/* - it("secp256k1q shr", async () => { - const tv = buildTestVector2(secp256k1q, "shr"); - await tester(secp256k1q, tv); - }); - it("mnt6753q shr", async () => { - const tv = buildTestVector2(mnt6753q, "shr"); - await tester(mnt6753q, tv); - }); - it("mnt6753q band", async () => { - const tv = buildTestVector2(mnt6753q, "band"); - await tester(mnt6753q, tv); - }); - it("mnt6753q bor", async () => { - const tv = buildTestVector2(mnt6753q, "bor"); - await tester(mnt6753q, tv); - }); - it("mnt6753q bxor", async () => { - const tv = buildTestVector2(mnt6753q, "bxor"); - await tester(mnt6753q, tv); - }); - it("mnt6753q bnot", async () => { - const tv = buildTestVector1(mnt6753q, "bnot"); - await tester(mnt6753q, tv); - }); -*/ -}); - -function buildTestVector2(p, op) { - const F = new ZqField(p); - const tv = []; - const nums = getCriticalNumbers(p, 2); - - const excludeZero = ["div", "mod", "idiv"].indexOf(op) >= 0; - - for (let i=0; i= 0; - - for (let i=0; i