[java] update documents

update-fork
MITSUNARI Shigeo 5 years ago
parent 4797680018
commit 4a5202567c
  1. 72
      ffi/java/java.md
  2. 2
      readme.md

@ -1,13 +1,14 @@
# JNI for mcl (experimental) # JNI for mcl (experimental)
This library provides functionality to compute the optimal ate pairing This library provides functionality to compute the optimal ate pairing
over Barreto-Naehrig (BN) curves. over Barreto-Naehrig (BN) or BLS12-381 curves.
# Initialization # Initialization
Load the library `mcl_bn256`. Load the library `mcljava`.
``` ```
import com.herumi.mcl.*; import com.herumi.mcl.*;
System.loadLibrary("mcl_bn256"); System.loadLibrary(System.mapLibraryName("mcljava"));
Mcl.SystemInit(curveType); // curveType = Mcl.BN254 or Mcl.BLS12_381
``` ```
# Classes # Classes
@ -22,74 +23,65 @@ System.loadLibrary("mcl_bn256");
* `Fr::setInt(int x)` ; set by x * `Fr::setInt(int x)` ; set by x
* `Fr::setStr(String str)` ; set by str such as "123", "0xfff", etc. * `Fr::setStr(String str)` ; set by str such as "123", "0xfff", etc.
* `Fr::setByCSPRNG()` ; randomly set * `Fr::setByCSPRNG()` ; randomly set
* `Bn256.neg(Fr y, Fr x)` ; `y = -x` * `Mcl.neg(Fr y, Fr x)` ; `y = -x`
* `Bn256.add(Fr z, Fr x, Fr y)` ; `z = x + y` * `Mcl.add(Fr z, Fr x, Fr y)` ; `z = x + y`
* `Bn256.sub(Fr z, Fr x, Fr y)` ; `z = x - y` * `Mcl.sub(Fr z, Fr x, Fr y)` ; `z = x - y`
* `Bn256.mul(Fr z, Fr x, Fr y)` ; `z = x * y` * `Mcl.mul(Fr z, Fr x, Fr y)` ; `z = x * y`
* `Bn256.div(Fr z, Fr x, Fr y)` ; `z = x / y` * `Mcl.div(Fr z, Fr x, Fr y)` ; `z = x / y`
## G1 ## G1
* `G1::set(String x, String y)` ; set by (x, y) * `Mcl.neg(G1 y, G1 x)` ; `y = -x`
* `G1::hashAndMapToG1(String m)` ; take SHA-256 of m and map it to an element of G1 * `Mcl.dbl(G1 y, G1 x)` ; `y = 2x`
* `G1::setStr(String str)` ; set by the result of `toString()` method * `Mcl.add(G1 z, G1 x, G1 y)` ; `z = x + y`
* `Bn256.neg(G1 y, G1 x)` ; `y = -x` * `Mcl.sub(G1 z, G1 x, G1 y)` ; `z = x - y`
* `Bn256.dbl(G1 y, G1 x)` ; `y = 2x` * `Mcl.mul(G1 z, G1 x, Fr y)` ; `z = x * y`
* `Bn256.add(G1 z, G1 x, G1 y)` ; `z = x + y`
* `Bn256.sub(G1 z, G1 x, G1 y)` ; `z = x - y`
* `Bn256.mul(G1 z, G1 x, Fr y)` ; `z = x * y`
## G2 ## G2
* `G2::set(String xa, String xb, String ya, String yb)` ; set by ((xa, xb), (ya, yb)) * `Mcl.neg(G2 y, G2 x)` ; `y = -x`
* `G2::setStr(String str)` ; set by the result of `toString()` method * `Mcl.dbl(G2 y, G2 x)` ; `y = 2x`
* `Bn256.neg(G2 y, G2 x)` ; `y = -x` * `Mcl.add(G2 z, G2 x, G2 y)` ; `z = x + y`
* `Bn256.dbl(G2 y, G2 x)` ; `y = 2x` * `Mcl.sub(G2 z, G2 x, G2 y)` ; `z = x - y`
* `Bn256.add(G2 z, G2 x, G2 y)` ; `z = x + y` * `Mcl.mul(G2 z, G2 x, Fr y)` ; `z = x * y`
* `Bn256.sub(G2 z, G2 x, G2 y)` ; `z = x - y`
* `Bn256.mul(G2 z, G2 x, Fr y)` ; `z = x * y`
## GT ## GT
* `GT::setStr(String str)` ; set by the result of `toString()` method * `GT::setStr(String str)` ; set by the result of `toString()` method
* `Bn256.mul(GT z, GT x, GT y)` ; `z = x * y` * `Mcl.mul(GT z, GT x, GT y)` ; `z = x * y`
* `Bn256.pow(GT z, GT x, Fr y)` ; `z = x ^ y` * `Mcl.pow(GT z, GT x, Fr y)` ; `z = x ^ y`
## pairing ## pairing
* `Bn256.pairing(GT e, G1 P, G2 Q)` ; e = e(P, Q) * `Mcl.pairing(GT e, G1 P, G2 Q)` ; e = e(P, Q)
# BLS signature sample # BLS signature sample
``` ```
String xa = "12723517038133731887338407189719511622662176727675373276651903807414909099441"; G2 Q = new G2();
String xb = "4168783608814932154536427934509895782246573715297911553964171371032945126671"; Mcl.hashAndMapToG2(Q, "abc".getBytes());
String ya = "13891744915211034074451795021214165905772212241412891944830863846330766296736";
String yb = "7937318970632701341203597196594272556916396164729705624521405069090520231616";
G2 Q = new G2(xa, xb, ya, yb); // fixed point of G2
Fr s = new Fr(); Fr s = new Fr();
s.setByCSPRNG(); // secret key s.setByCSPRNG(); // secret key
G2 pub = new G2(); G2 pub = new G2();
Bn256.mul(pub, Q, s); // public key = sQ Mcl.mul(pub, Q, s); // public key = sQ
String m = "signature test"; String m = "signature test";
G1 H = new G1(); G1 H = new G1();
H.hashAndMapToG1(m); // H = Hash(m) Mcl.hashAndMapToG1(H, m.getBytes()); // H = Hash(m)
G1 sign = new G1(); G1 sign = new G1();
Bn256.mul(sign, H, s); // signature of m = s H Mcl.mul(sign, H, s); // signature of m = s H
GT e1 = new GT(); GT e1 = new GT();
GT e2 = new GT(); GT e2 = new GT();
Bn256.pairing(e1, H, pub); // e1 = e(H, s Q) Mcl.pairing(e1, H, pub); // e1 = e(H, s Q)
Bn256.pairing(e2, sign, Q); // e2 = e(s H, Q); Mcl.pairing(e2, sign, Q); // e2 = e(s H, Q);
assertBool("verify signature", e1.equals(e2)); assertBool("verify signature", e1.equals(e2));
``` ```
# Make test # Make test
``` ```
cd java cd ffi/java
make test_bn256 make test
``` ```
# Sample code # Sample code
[Bn256Test.java](https://github.com/herumi/mcl/blob/master/java/Bn256Test.java) [MclTest.java](https://github.com/herumi/mcl/blob/master/ffi/java/MclTest.java)

@ -430,7 +430,7 @@ K. Shimizu, and T. Teruya. ASIACCS 2018
* [she-api(Japanese)](https://github.com/herumi/mcl/blob/master/misc/she/she-api-ja.md) * [she-api(Japanese)](https://github.com/herumi/mcl/blob/master/misc/she/she-api-ja.md)
# Java API # Java API
See [java.md](https://github.com/herumi/mcl/blob/master/java/java.md) See [java.md](https://github.com/herumi/mcl/blob/master/ffi/java/java.md)
# License # License

Loading…
Cancel
Save