[java] change Bn256 to Mcl

update-fork
MITSUNARI Shigeo 5 years ago
parent 17d2b0c18d
commit 24be4c8de1
  1. 2
      ffi/java/ElgamalTest.java
  2. 26
      ffi/java/Makefile
  3. 76
      ffi/java/MclTest.java
  4. 31
      ffi/java/bn256.i
  5. 249
      ffi/java/bn256_impl.hpp
  6. 1542
      ffi/java/bn256_wrap.cxx
  7. 88
      ffi/java/com/herumi/mcl/Bn256.java
  8. 68
      ffi/java/com/herumi/mcl/Bn256JNI.java
  9. 94
      ffi/java/com/herumi/mcl/Fp.java
  10. 40
      ffi/java/com/herumi/mcl/Fr.java
  11. 36
      ffi/java/com/herumi/mcl/G1.java
  12. 34
      ffi/java/com/herumi/mcl/G2.java
  13. 22
      ffi/java/com/herumi/mcl/GT.java
  14. 128
      ffi/java/com/herumi/mcl/Mcl.java
  15. 14
      ffi/java/com/herumi/mcl/MclConstants.java
  16. 104
      ffi/java/com/herumi/mcl/MclJNI.java
  17. 4
      ffi/java/java.md
  18. 28
      ffi/java/mcl.i
  19. 353
      ffi/java/mcl_impl.hpp
  20. 2432
      ffi/java/mcl_wrap.cxx
  21. 0
      ffi/java/run-mcl.bat

@ -8,7 +8,7 @@ import com.herumi.mcl.*;
*/
public class ElgamalTest {
static {
String lib = "mcl_elgamal";
String lib = "mclelgamaljava";
String libName = System.mapLibraryName(lib);
System.out.println("libName : " + libName);
System.loadLibrary(lib);

@ -15,33 +15,33 @@ MCL_LIB=$(TOP_DIR)/lib/libmcl.a
PACKAGE_NAME=com.herumi.mcl
PACKAGE_DIR=$(subst .,/,$(PACKAGE_NAME))
ELGAMAL_LIB=$(TOP_DIR)/bin/libmcl_elgamal.$(LIB_SUF)
BN256_LIB=$(TOP_DIR)/bin/libmcl_bn256.$(LIB_SUF)
JAVA_EXE=cd $(TOP_DIR)/bin && LD_LIBRARY_PATH=./:$(LD_LIBRARY_PATH) java -classpath ../ffi/java
ELGAMAL_LIB=$(TOP_DIR)/lib/libmclelgamaljava.$(LIB_SUF)
MCLJAVA_LIB=$(TOP_DIR)/lib/libmcljava.$(LIB_SUF)
JAVA_EXE=cd $(TOP_DIR)/lib && LD_LIBRARY_PATH=../lib:$(LD_LIBRARY_PATH) java -classpath ../ffi/java
all: $(ELGAMAL_LIB)
elgamal_wrap.cxx: elgamal.i elgamal_impl.hpp
$(MKDIR) $(PACKAGE_DIR)
swig -java -package $(PACKAGE_NAME) -outdir $(PACKAGE_DIR) -c++ -Wall elgamal.i
bn256_wrap.cxx: bn256.i bn256_impl.hpp
mcl_wrap.cxx: mcl.i mcl_impl.hpp
$(MKDIR) $(PACKAGE_DIR)
swig -java -package $(PACKAGE_NAME) -outdir $(PACKAGE_DIR) -c++ -Wall bn256.i
swig -java -package $(PACKAGE_NAME) -outdir $(PACKAGE_DIR) -c++ -Wall mcl.i
$(MCL_LIB):
make -C $(TOP_DIR)
$(ELGAMAL_LIB): elgamal_wrap.cxx $(MCL_LIB)
$(PRE)$(CXX) $< -o $@ $(CFLAGS) $(LDFLAGS) $(MCL_LIB) -shared
$(PRE)$(CXX) $< -o $@ $(CFLAGS) $(MCL_LIB) $(LDFLAGS) -shared
$(BN256_LIB): bn256_wrap.cxx $(MCL_LIB)
$(PRE)$(CXX) $< -o $@ $(CFLAGS) $(LDFLAGS) $(MCL_LIB) -shared
$(MCLJAVA_LIB): mcl_wrap.cxx $(MCL_LIB)
$(PRE)$(CXX) $< -o $@ $(CFLAGS) $(MCL_LIB) $(LDFLAGS) -shared
%.class: %.java
javac $<
ElgamalTest.class: ElgamalTest.java $(ELGAMAL_LIB)
Bn256Test.class: Bn256Test.java $(BN256_LIB)
MclTest.class: MclTest.java $(MCLJAVA_LIB)
jar:
jar cvf mcl.jar com
@ -53,13 +53,13 @@ test_elgamal: ElgamalTest.class $(ELGAMAL_LIB)
$(JAVA_EXE) ElgamalTest -e NIST_P384 -h sha384
$(JAVA_EXE) ElgamalTest -e NIST_P521 -h sha512
test_bn256: Bn256Test.class $(BN256_LIB)
$(JAVA_EXE) Bn256Test
test_mcl: MclTest.class $(MCLJAVA_LIB)
$(JAVA_EXE) MclTest
test:
$(MAKE) test_elgamal
$(MAKE) test_bn256
$(MAKE) test_mcl
clean:
rm -rf *.class $(ELGAMAL_LIB) $(PACKAGE_DIR)/*.class *_wrap.cxx
rm -rf *.class $(ELGAMAL_LIB) $(MCLJAVA_LIB) $(PACKAGE_DIR)/*.class *_wrap.cxx

@ -2,11 +2,11 @@ import java.io.*;
import com.herumi.mcl.*;
/*
Bn256Test
MclTest
*/
public class Bn256Test {
public class MclTest {
static {
String lib = "mcl_bn256";
String lib = "mcljava";
String libName = System.mapLibraryName(lib);
System.out.println("libName : " + libName);
System.loadLibrary(lib);
@ -25,34 +25,47 @@ public class Bn256Test {
System.out.println("NG : " + msg);
}
}
public static void main(String argv[]) {
public static void testCurve(int curveType, String name) {
try {
Bn256.SystemInit();
System.out.println("curve=" + name);
Mcl.SystemInit(curveType);
Fr x = new Fr(5);
Fr y = new Fr(-2);
Fr z = new Fr(5);
assertBool("x != y", !x.equals(y));
assertBool("x == z", x.equals(z));
assertEquals("x == 5", x.toString(), "5");
Bn256.add(x, x, y);
Mcl.add(x, x, y);
assertEquals("x == 3", x.toString(), "3");
Bn256.mul(x, x, x);
Mcl.mul(x, x, x);
assertEquals("x == 9", x.toString(), "9");
assertEquals("x == 12", (new Fr("12")).toString(), "12");
assertEquals("x == 18", (new Fr("12", 16)).toString(), "18");
assertEquals("x == ff", (new Fr("255")).toString(16), "ff");
/*
{
byte[] b = x.serialize();
Fr t = new Fr();
t.deserialize(b);
assertEquals("serialize", x, t);
}
*/
G1 P = new G1();
System.out.println("P=" + P);
P.set("-1", "1");
Mcl.hashAndMapToG1(P, "test".getBytes());
System.out.println("P=" + P);
Bn256.neg(P, P);
byte[] buf = { 1, 2, 3, 4 };
Mcl.hashAndMapToG1(P, buf);
System.out.println("P=" + P);
Mcl.neg(P, P);
System.out.println("P=" + P);
String xa = "12723517038133731887338407189719511622662176727675373276651903807414909099441";
String xb = "4168783608814932154536427934509895782246573715297911553964171371032945126671";
String ya = "13891744915211034074451795021214165905772212241412891944830863846330766296736";
String yb = "7937318970632701341203597196594272556916396164729705624521405069090520231616";
G2 Q = new G2(xa, xb, ya, yb);
G2 Q = new G2();
Mcl.hashAndMapToG2(Q, "abc".getBytes());
System.out.println("Q=" + Q);
P.hashAndMapToG1("This is a pen");
Mcl.hashAndMapToG1(P, "This is a pen".getBytes());
{
String s = P.toString();
G1 P1 = new G1();
@ -61,19 +74,20 @@ public class Bn256Test {
}
GT e = new GT();
Bn256.pairing(e, P, Q);
Mcl.pairing(e, P, Q);
GT e1 = new GT();
GT e2 = new GT();
Fr c = new Fr("1234567890123234928348230428394234");
System.out.println("c=" + c);
G2 cQ = new G2(Q);
Bn256.mul(cQ, Q, c); // cQ = Q * c
Bn256.pairing(e1, P, cQ);
Bn256.pow(e2, e, c); // e2 = e^c
Mcl.mul(cQ, Q, c); // cQ = Q * c
Mcl.pairing(e1, P, cQ);
Mcl.pow(e2, e, c); // e2 = e^c
assertBool("e1 == e2", e1.equals(e2));
G1 cP = new G1(P);
Bn256.mul(cP, P, c); // cP = P * c
Bn256.pairing(e1, cP, Q);
Mcl.mul(cP, P, c); // cP = P * c
Mcl.pairing(e1, cP, Q);
assertBool("e1 == e2", e1.equals(e2));
BLSsignature(Q);
@ -84,21 +98,25 @@ public class Bn256Test {
public static void BLSsignature(G2 Q)
{
Fr s = new Fr();
s.setRand(); // secret key
s.setByCSPRNG(); // secret key
System.out.println("secret key " + s);
G2 pub = new G2();
Bn256.mul(pub, Q, s); // public key = sQ
Mcl.mul(pub, Q, s); // public key = sQ
String m = "signature test";
byte[] m = "signature test".getBytes();
G1 H = new G1();
H.hashAndMapToG1(m); // H = Hash(m)
Mcl.hashAndMapToG1(H, m); // H = Hash(m)
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 e2 = new GT();
Bn256.pairing(e1, H, pub); // e1 = e(H, s Q)
Bn256.pairing(e2, sign, Q); // e2 = e(s H, Q);
Mcl.pairing(e1, H, pub); // e1 = e(H, s Q)
Mcl.pairing(e2, sign, Q); // e2 = e(s H, Q);
assertBool("verify signature", e1.equals(e2));
}
public static void main(String argv[]) {
testCurve(Mcl.BN254, "BN254");
testCurve(Mcl.BLS12_381, "BLS12_381");
}
}

@ -1,31 +0,0 @@
%module Bn256
%include "std_string.i"
%include "std_except.i"
%{
#include <cybozu/random_generator.hpp>
#include <cybozu/crypto.hpp>
#include <mcl/bn256.hpp>
struct Param {
cybozu::RandomGenerator rg;
static inline Param& getParam()
{
static Param p;
return p;
}
};
static void HashAndMapToG1(mcl::bn256::G1& P, const std::string& m)
{
std::string digest = cybozu::crypto::Hash::digest(cybozu::crypto::Hash::N_SHA256, m);
mcl::bn256::Fp t;
t.setArrayMask(digest.c_str(), digest.size());
mcl::bn256::BN::param.mapTo.calcG1(P, t);
}
#include "bn256_impl.hpp"
%}
%include "bn256_impl.hpp"

@ -1,249 +0,0 @@
#include <mcl/bn256.hpp>
#include <stdint.h>
#include <sstream>
void SystemInit() throw(std::exception)
{
mcl::bn256::initPairing();
}
class G1;
class G2;
class GT;
/*
Fr = Z / rZ
*/
class Fr {
mcl::bn256::Fr self_;
friend class G1;
friend class G2;
friend class GT;
friend void neg(Fr& y, const Fr& x);
friend void add(Fr& z, const Fr& x, const Fr& y);
friend void sub(Fr& z, const Fr& x, const Fr& y);
friend void mul(Fr& z, const Fr& x, const Fr& y);
friend void mul(G1& z, const G1& x, const Fr& y);
friend void mul(G2& z, const G2& x, const Fr& y);
friend void div(Fr& z, const Fr& x, const Fr& y);
friend void pow(GT& z, const GT& x, const Fr& y);
public:
Fr() {}
Fr(const Fr& rhs) : self_(rhs.self_) {}
Fr(int x) : self_(x) {}
Fr(const std::string& str) throw(std::exception)
: self_(str) {}
bool equals(const Fr& rhs) const { return self_ == rhs.self_; }
void setStr(const std::string& str) throw(std::exception)
{
self_.setStr(str);
}
void setInt(int x)
{
self_ = x;
}
void clear()
{
self_.clear();
}
void setRand()
{
self_.setRand(Param::getParam().rg);
}
std::string toString() const throw(std::exception)
{
return self_.getStr();
}
};
void neg(Fr& y, const Fr& x)
{
mcl::bn256::Fr::neg(y.self_, x.self_);
}
void add(Fr& z, const Fr& x, const Fr& y)
{
mcl::bn256::Fr::add(z.self_, x.self_, y.self_);
}
void sub(Fr& z, const Fr& x, const Fr& y)
{
mcl::bn256::Fr::sub(z.self_, x.self_, y.self_);
}
void mul(Fr& z, const Fr& x, const Fr& y)
{
mcl::bn256::Fr::mul(z.self_, x.self_, y.self_);
}
void div(Fr& z, const Fr& x, const Fr& y)
{
mcl::bn256::Fr::div(z.self_, x.self_, y.self_);
}
/*
#G1 = r
*/
class G1 {
mcl::bn256::G1 self_;
friend void neg(G1& y, const G1& x);
friend void dbl(G1& y, const G1& x);
friend void add(G1& z, const G1& x, const G1& y);
friend void sub(G1& z, const G1& x, const G1& y);
friend void mul(G1& z, const G1& x, const Fr& y);
friend void pairing(GT& e, const G1& P, const G2& Q);
public:
G1() {}
G1(const G1& rhs) : self_(rhs.self_) {}
G1(const std::string& x, const std::string& y) throw(std::exception)
: self_(mcl::bn256::Fp(x), mcl::bn256::Fp(y))
{
}
bool equals(const G1& rhs) const { return self_ == rhs.self_; }
void set(const std::string& x, const std::string& y)
{
self_.set(mcl::bn256::Fp(x), mcl::bn256::Fp(y));
}
void hashAndMapToG1(const std::string& m) throw(std::exception)
{
HashAndMapToG1(self_, m);
}
void clear()
{
self_.clear();
}
/*
compressed format
*/
void setStr(const std::string& str) throw(std::exception)
{
self_.setStr(str);
}
std::string toString() const throw(std::exception)
{
return self_.getStr();
}
};
void neg(G1& y, const G1& x)
{
mcl::bn256::G1::neg(y.self_, x.self_);
}
void dbl(G1& y, const G1& x)
{
mcl::bn256::G1::dbl(y.self_, x.self_);
}
void add(G1& z, const G1& x, const G1& y)
{
mcl::bn256::G1::add(z.self_, x.self_, y.self_);
}
void sub(G1& z, const G1& x, const G1& y)
{
mcl::bn256::G1::sub(z.self_, x.self_, y.self_);
}
void mul(G1& z, const G1& x, const Fr& y)
{
mcl::bn256::G1::mul(z.self_, x.self_, y.self_);
}
/*
#G2 = r
*/
class G2 {
mcl::bn256::G2 self_;
friend void neg(G2& y, const G2& x);
friend void dbl(G2& y, const G2& x);
friend void add(G2& z, const G2& x, const G2& y);
friend void sub(G2& z, const G2& x, const G2& y);
friend void mul(G2& z, const G2& x, const Fr& y);
friend void pairing(GT& e, const G1& P, const G2& Q);
public:
G2() {}
G2(const G2& rhs) : self_(rhs.self_) {}
G2(const std::string& xa, const std::string& xb, const std::string& ya, const std::string& yb) throw(std::exception)
: self_(mcl::bn256::Fp2(xa, xb), mcl::bn256::Fp2(ya, yb))
{
}
bool equals(const G2& rhs) const { return self_ == rhs.self_; }
void set(const std::string& xa, const std::string& xb, const std::string& ya, const std::string& yb)
{
self_.set(mcl::bn256::Fp2(xa, xb), mcl::bn256::Fp2(ya, yb));
}
void clear()
{
self_.clear();
}
/*
compressed format
*/
void setStr(const std::string& str) throw(std::exception)
{
self_.setStr(str);
}
std::string toString() const throw(std::exception)
{
return self_.getStr();
}
};
void neg(G2& y, const G2& x)
{
mcl::bn256::G2::neg(y.self_, x.self_);
}
void dbl(G2& y, const G2& x)
{
mcl::bn256::G2::dbl(y.self_, x.self_);
}
void add(G2& z, const G2& x, const G2& y)
{
mcl::bn256::G2::add(z.self_, x.self_, y.self_);
}
void sub(G2& z, const G2& x, const G2& y)
{
mcl::bn256::G2::sub(z.self_, x.self_, y.self_);
}
void mul(G2& z, const G2& x, const Fr& y)
{
mcl::bn256::G2::mul(z.self_, x.self_, y.self_);
}
/*
#GT = r
*/
class GT {
mcl::bn256::Fp12 self_;
friend void mul(GT& z, const GT& x, const GT& y);
friend void pow(GT& z, const GT& x, const Fr& y);
friend void pairing(GT& e, const G1& P, const G2& Q);
public:
GT() {}
GT(const GT& rhs) : self_(rhs.self_) {}
bool equals(const GT& rhs) const { return self_ == rhs.self_; }
void clear()
{
self_.clear();
}
void setStr(const std::string& str) throw(std::exception)
{
std::istringstream iss(str);
iss >> self_;
}
std::string toString() const throw(std::exception)
{
std::ostringstream oss;
oss << self_;
return oss.str();
}
};
void mul(GT& z, const GT& x, const GT& y)
{
mcl::bn256::Fp12::mul(z.self_, x.self_, y.self_);
}
void pow(GT& z, const GT& x, const Fr& y)
{
mcl::bn256::Fp12::pow(z.self_, x.self_, y.self_);
}
void pairing(GT& e, const G1& P, const G2& Q)
{
mcl::bn256::pairing(e.self_, P.self_, Q.self_);
}

File diff suppressed because it is too large Load Diff

@ -1,88 +0,0 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package com.herumi.mcl;
public class Bn256 {
public static void SystemInit() {
Bn256JNI.SystemInit();
}
public static void neg(Fr y, Fr x) {
Bn256JNI.neg__SWIG_0(Fr.getCPtr(y), y, Fr.getCPtr(x), x);
}
public static void add(Fr z, Fr x, Fr y) {
Bn256JNI.add__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void sub(Fr z, Fr x, Fr y) {
Bn256JNI.sub__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void mul(Fr z, Fr x, Fr y) {
Bn256JNI.mul__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void mul(G1 z, G1 x, Fr y) {
Bn256JNI.mul__SWIG_1(G1.getCPtr(z), z, G1.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void mul(G2 z, G2 x, Fr y) {
Bn256JNI.mul__SWIG_2(G2.getCPtr(z), z, G2.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void div(Fr z, Fr x, Fr y) {
Bn256JNI.div(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void pow(GT z, GT x, Fr y) {
Bn256JNI.pow(GT.getCPtr(z), z, GT.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void neg(G1 y, G1 x) {
Bn256JNI.neg__SWIG_1(G1.getCPtr(y), y, G1.getCPtr(x), x);
}
public static void dbl(G1 y, G1 x) {
Bn256JNI.dbl__SWIG_0(G1.getCPtr(y), y, G1.getCPtr(x), x);
}
public static void add(G1 z, G1 x, G1 y) {
Bn256JNI.add__SWIG_1(G1.getCPtr(z), z, G1.getCPtr(x), x, G1.getCPtr(y), y);
}
public static void sub(G1 z, G1 x, G1 y) {
Bn256JNI.sub__SWIG_1(G1.getCPtr(z), z, G1.getCPtr(x), x, G1.getCPtr(y), y);
}
public static void pairing(GT e, G1 P, G2 Q) {
Bn256JNI.pairing(GT.getCPtr(e), e, G1.getCPtr(P), P, G2.getCPtr(Q), Q);
}
public static void neg(G2 y, G2 x) {
Bn256JNI.neg__SWIG_2(G2.getCPtr(y), y, G2.getCPtr(x), x);
}
public static void dbl(G2 y, G2 x) {
Bn256JNI.dbl__SWIG_1(G2.getCPtr(y), y, G2.getCPtr(x), x);
}
public static void add(G2 z, G2 x, G2 y) {
Bn256JNI.add__SWIG_2(G2.getCPtr(z), z, G2.getCPtr(x), x, G2.getCPtr(y), y);
}
public static void sub(G2 z, G2 x, G2 y) {
Bn256JNI.sub__SWIG_2(G2.getCPtr(z), z, G2.getCPtr(x), x, G2.getCPtr(y), y);
}
public static void mul(GT z, GT x, GT y) {
Bn256JNI.mul__SWIG_3(GT.getCPtr(z), z, GT.getCPtr(x), x, GT.getCPtr(y), y);
}
}

@ -1,68 +0,0 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package com.herumi.mcl;
public class Bn256JNI {
public final static native void SystemInit();
public final static native void neg__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_);
public final static native void add__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
public final static native void sub__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
public final static native void mul__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
public final static native void mul__SWIG_1(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_, long jarg3, Fr jarg3_);
public final static native void mul__SWIG_2(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_, long jarg3, Fr jarg3_);
public final static native void div(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
public final static native void pow(long jarg1, GT jarg1_, long jarg2, GT jarg2_, long jarg3, Fr jarg3_);
public final static native long new_Fr__SWIG_0();
public final static native long new_Fr__SWIG_1(long jarg1, Fr jarg1_);
public final static native long new_Fr__SWIG_2(int jarg1);
public final static native long new_Fr__SWIG_3(String jarg1);
public final static native boolean Fr_equals(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_);
public final static native void Fr_setStr(long jarg1, Fr jarg1_, String jarg2);
public final static native void Fr_setInt(long jarg1, Fr jarg1_, int jarg2);
public final static native void Fr_clear(long jarg1, Fr jarg1_);
public final static native void Fr_setRand(long jarg1, Fr jarg1_);
public final static native String Fr_toString(long jarg1, Fr jarg1_);
public final static native void delete_Fr(long jarg1);
public final static native void neg__SWIG_1(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_);
public final static native void dbl__SWIG_0(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_);
public final static native void add__SWIG_1(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_, long jarg3, G1 jarg3_);
public final static native void sub__SWIG_1(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_, long jarg3, G1 jarg3_);
public final static native void pairing(long jarg1, GT jarg1_, long jarg2, G1 jarg2_, long jarg3, G2 jarg3_);
public final static native long new_G1__SWIG_0();
public final static native long new_G1__SWIG_1(long jarg1, G1 jarg1_);
public final static native long new_G1__SWIG_2(String jarg1, String jarg2);
public final static native boolean G1_equals(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_);
public final static native void G1_set(long jarg1, G1 jarg1_, String jarg2, String jarg3);
public final static native void G1_hashAndMapToG1(long jarg1, G1 jarg1_, String jarg2);
public final static native void G1_clear(long jarg1, G1 jarg1_);
public final static native void G1_setStr(long jarg1, G1 jarg1_, String jarg2);
public final static native String G1_toString(long jarg1, G1 jarg1_);
public final static native void delete_G1(long jarg1);
public final static native void neg__SWIG_2(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_);
public final static native void dbl__SWIG_1(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_);
public final static native void add__SWIG_2(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_, long jarg3, G2 jarg3_);
public final static native void sub__SWIG_2(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_, long jarg3, G2 jarg3_);
public final static native long new_G2__SWIG_0();
public final static native long new_G2__SWIG_1(long jarg1, G2 jarg1_);
public final static native long new_G2__SWIG_2(String jarg1, String jarg2, String jarg3, String jarg4);
public final static native boolean G2_equals(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_);
public final static native void G2_set(long jarg1, G2 jarg1_, String jarg2, String jarg3, String jarg4, String jarg5);
public final static native void G2_clear(long jarg1, G2 jarg1_);
public final static native void G2_setStr(long jarg1, G2 jarg1_, String jarg2);
public final static native String G2_toString(long jarg1, G2 jarg1_);
public final static native void delete_G2(long jarg1);
public final static native void mul__SWIG_3(long jarg1, GT jarg1_, long jarg2, GT jarg2_, long jarg3, GT jarg3_);
public final static native long new_GT__SWIG_0();
public final static native long new_GT__SWIG_1(long jarg1, GT jarg1_);
public final static native boolean GT_equals(long jarg1, GT jarg1_, long jarg2, GT jarg2_);
public final static native void GT_clear(long jarg1, GT jarg1_);
public final static native void GT_setStr(long jarg1, GT jarg1_, String jarg2);
public final static native String GT_toString(long jarg1, GT jarg1_);
public final static native void delete_GT(long jarg1);
}

@ -0,0 +1,94 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package com.herumi.mcl;
public class Fp {
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected Fp(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr(Fp obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
MclJNI.delete_Fp(swigCPtr);
}
swigCPtr = 0;
}
}
public Fp() {
this(MclJNI.new_Fp__SWIG_0(), true);
}
public Fp(Fp rhs) {
this(MclJNI.new_Fp__SWIG_1(Fp.getCPtr(rhs), rhs), true);
}
public Fp(int x) {
this(MclJNI.new_Fp__SWIG_2(x), true);
}
public Fp(String str, int base) {
this(MclJNI.new_Fp__SWIG_3(str, base), true);
}
public Fp(String str) {
this(MclJNI.new_Fp__SWIG_4(str), true);
}
public boolean equals(Fp rhs) {
return MclJNI.Fp_equals(swigCPtr, this, Fp.getCPtr(rhs), rhs);
}
public void setStr(String str, int base) {
MclJNI.Fp_setStr__SWIG_0(swigCPtr, this, str, base);
}
public void setStr(String str) {
MclJNI.Fp_setStr__SWIG_1(swigCPtr, this, str);
}
public void setInt(int x) {
MclJNI.Fp_setInt(swigCPtr, this, x);
}
public void clear() {
MclJNI.Fp_clear(swigCPtr, this);
}
public void setByCSPRNG() {
MclJNI.Fp_setByCSPRNG(swigCPtr, this);
}
public String toString(int base) {
return MclJNI.Fp_toString__SWIG_0(swigCPtr, this, base);
}
public String toString() {
return MclJNI.Fp_toString__SWIG_1(swigCPtr, this);
}
public void deserialize(byte[] cbuf) {
MclJNI.Fp_deserialize(swigCPtr, this, cbuf);
}
}

@ -29,50 +29,66 @@ public class Fr {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
Bn256JNI.delete_Fr(swigCPtr);
MclJNI.delete_Fr(swigCPtr);
}
swigCPtr = 0;
}
}
public Fr() {
this(Bn256JNI.new_Fr__SWIG_0(), true);
this(MclJNI.new_Fr__SWIG_0(), true);
}
public Fr(Fr rhs) {
this(Bn256JNI.new_Fr__SWIG_1(Fr.getCPtr(rhs), rhs), true);
this(MclJNI.new_Fr__SWIG_1(Fr.getCPtr(rhs), rhs), true);
}
public Fr(int x) {
this(Bn256JNI.new_Fr__SWIG_2(x), true);
this(MclJNI.new_Fr__SWIG_2(x), true);
}
public Fr(String str, int base) {
this(MclJNI.new_Fr__SWIG_3(str, base), true);
}
public Fr(String str) {
this(Bn256JNI.new_Fr__SWIG_3(str), true);
this(MclJNI.new_Fr__SWIG_4(str), true);
}
public boolean equals(Fr rhs) {
return Bn256JNI.Fr_equals(swigCPtr, this, Fr.getCPtr(rhs), rhs);
return MclJNI.Fr_equals(swigCPtr, this, Fr.getCPtr(rhs), rhs);
}
public void setStr(String str, int base) {
MclJNI.Fr_setStr__SWIG_0(swigCPtr, this, str, base);
}
public void setStr(String str) {
Bn256JNI.Fr_setStr(swigCPtr, this, str);
MclJNI.Fr_setStr__SWIG_1(swigCPtr, this, str);
}
public void setInt(int x) {
Bn256JNI.Fr_setInt(swigCPtr, this, x);
MclJNI.Fr_setInt(swigCPtr, this, x);
}
public void clear() {
Bn256JNI.Fr_clear(swigCPtr, this);
MclJNI.Fr_clear(swigCPtr, this);
}
public void setRand() {
Bn256JNI.Fr_setRand(swigCPtr, this);
public void setByCSPRNG() {
MclJNI.Fr_setByCSPRNG(swigCPtr, this);
}
public String toString(int base) {
return MclJNI.Fr_toString__SWIG_0(swigCPtr, this, base);
}
public String toString() {
return Bn256JNI.Fr_toString(swigCPtr, this);
return MclJNI.Fr_toString__SWIG_1(swigCPtr, this);
}
public void deserialize(byte[] cbuf) {
MclJNI.Fr_deserialize(swigCPtr, this, cbuf);
}
}

@ -29,46 +29,54 @@ public class G1 {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
Bn256JNI.delete_G1(swigCPtr);
MclJNI.delete_G1(swigCPtr);
}
swigCPtr = 0;
}
}
public G1() {
this(Bn256JNI.new_G1__SWIG_0(), true);
this(MclJNI.new_G1__SWIG_0(), true);
}
public G1(G1 rhs) {
this(Bn256JNI.new_G1__SWIG_1(G1.getCPtr(rhs), rhs), true);
this(MclJNI.new_G1__SWIG_1(G1.getCPtr(rhs), rhs), true);
}
public G1(String x, String y) {
this(Bn256JNI.new_G1__SWIG_2(x, y), true);
public G1(Fp x, Fp y) {
this(MclJNI.new_G1__SWIG_2(Fp.getCPtr(x), x, Fp.getCPtr(y), y), true);
}
public boolean equals(G1 rhs) {
return Bn256JNI.G1_equals(swigCPtr, this, G1.getCPtr(rhs), rhs);
return MclJNI.G1_equals(swigCPtr, this, G1.getCPtr(rhs), rhs);
}
public void set(String x, String y) {
Bn256JNI.G1_set(swigCPtr, this, x, y);
public void set(Fp x, Fp y) {
MclJNI.G1_set(swigCPtr, this, Fp.getCPtr(x), x, Fp.getCPtr(y), y);
}
public void hashAndMapToG1(String m) {
Bn256JNI.G1_hashAndMapToG1(swigCPtr, this, m);
public void clear() {
MclJNI.G1_clear(swigCPtr, this);
}
public void clear() {
Bn256JNI.G1_clear(swigCPtr, this);
public void setStr(String str, int base) {
MclJNI.G1_setStr__SWIG_0(swigCPtr, this, str, base);
}
public void setStr(String str) {
Bn256JNI.G1_setStr(swigCPtr, this, str);
MclJNI.G1_setStr__SWIG_1(swigCPtr, this, str);
}
public String toString(int base) {
return MclJNI.G1_toString__SWIG_0(swigCPtr, this, base);
}
public String toString() {
return Bn256JNI.G1_toString(swigCPtr, this);
return MclJNI.G1_toString__SWIG_1(swigCPtr, this);
}
public void deserialize(byte[] cbuf) {
MclJNI.G1_deserialize(swigCPtr, this, cbuf);
}
}

@ -29,42 +29,54 @@ public class G2 {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
Bn256JNI.delete_G2(swigCPtr);
MclJNI.delete_G2(swigCPtr);
}
swigCPtr = 0;
}
}
public G2() {
this(Bn256JNI.new_G2__SWIG_0(), true);
this(MclJNI.new_G2__SWIG_0(), true);
}
public G2(G2 rhs) {
this(Bn256JNI.new_G2__SWIG_1(G2.getCPtr(rhs), rhs), true);
this(MclJNI.new_G2__SWIG_1(G2.getCPtr(rhs), rhs), true);
}
public G2(String xa, String xb, String ya, String yb) {
this(Bn256JNI.new_G2__SWIG_2(xa, xb, ya, yb), true);
public G2(Fp ax, Fp ay, Fp bx, Fp by) {
this(MclJNI.new_G2__SWIG_2(Fp.getCPtr(ax), ax, Fp.getCPtr(ay), ay, Fp.getCPtr(bx), bx, Fp.getCPtr(by), by), true);
}
public boolean equals(G2 rhs) {
return Bn256JNI.G2_equals(swigCPtr, this, G2.getCPtr(rhs), rhs);
return MclJNI.G2_equals(swigCPtr, this, G2.getCPtr(rhs), rhs);
}
public void set(String xa, String xb, String ya, String yb) {
Bn256JNI.G2_set(swigCPtr, this, xa, xb, ya, yb);
public void set(Fp ax, Fp ay, Fp bx, Fp by) {
MclJNI.G2_set(swigCPtr, this, Fp.getCPtr(ax), ax, Fp.getCPtr(ay), ay, Fp.getCPtr(bx), bx, Fp.getCPtr(by), by);
}
public void clear() {
Bn256JNI.G2_clear(swigCPtr, this);
MclJNI.G2_clear(swigCPtr, this);
}
public void setStr(String str, int base) {
MclJNI.G2_setStr__SWIG_0(swigCPtr, this, str, base);
}
public void setStr(String str) {
Bn256JNI.G2_setStr(swigCPtr, this, str);
MclJNI.G2_setStr__SWIG_1(swigCPtr, this, str);
}
public String toString(int base) {
return MclJNI.G2_toString__SWIG_0(swigCPtr, this, base);
}
public String toString() {
return Bn256JNI.G2_toString(swigCPtr, this);
return MclJNI.G2_toString__SWIG_1(swigCPtr, this);
}
public void deserialize(byte[] cbuf) {
MclJNI.G2_deserialize(swigCPtr, this, cbuf);
}
}

@ -29,34 +29,42 @@ public class GT {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
Bn256JNI.delete_GT(swigCPtr);
MclJNI.delete_GT(swigCPtr);
}
swigCPtr = 0;
}
}
public GT() {
this(Bn256JNI.new_GT__SWIG_0(), true);
this(MclJNI.new_GT__SWIG_0(), true);
}
public GT(GT rhs) {
this(Bn256JNI.new_GT__SWIG_1(GT.getCPtr(rhs), rhs), true);
this(MclJNI.new_GT__SWIG_1(GT.getCPtr(rhs), rhs), true);
}
public boolean equals(GT rhs) {
return Bn256JNI.GT_equals(swigCPtr, this, GT.getCPtr(rhs), rhs);
return MclJNI.GT_equals(swigCPtr, this, GT.getCPtr(rhs), rhs);
}
public void clear() {
Bn256JNI.GT_clear(swigCPtr, this);
MclJNI.GT_clear(swigCPtr, this);
}
public void setStr(String str, int base) {
MclJNI.GT_setStr__SWIG_0(swigCPtr, this, str, base);
}
public void setStr(String str) {
Bn256JNI.GT_setStr(swigCPtr, this, str);
MclJNI.GT_setStr__SWIG_1(swigCPtr, this, str);
}
public String toString(int base) {
return MclJNI.GT_toString__SWIG_0(swigCPtr, this, base);
}
public String toString() {
return Bn256JNI.GT_toString(swigCPtr, this);
return MclJNI.GT_toString__SWIG_1(swigCPtr, this);
}
}

@ -0,0 +1,128 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package com.herumi.mcl;
public class Mcl implements MclConstants {
public static void SystemInit(int curveType) {
MclJNI.SystemInit(curveType);
}
public static void neg(Fr y, Fr x) {
MclJNI.neg__SWIG_0(Fr.getCPtr(y), y, Fr.getCPtr(x), x);
}
public static void add(Fr z, Fr x, Fr y) {
MclJNI.add__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void sub(Fr z, Fr x, Fr y) {
MclJNI.sub__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void mul(Fr z, Fr x, Fr y) {
MclJNI.mul__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void mul(G1 z, G1 x, Fr y) {
MclJNI.mul__SWIG_1(G1.getCPtr(z), z, G1.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void mul(G2 z, G2 x, Fr y) {
MclJNI.mul__SWIG_2(G2.getCPtr(z), z, G2.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void div(Fr z, Fr x, Fr y) {
MclJNI.div__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void pow(GT z, GT x, Fr y) {
MclJNI.pow__SWIG_0(GT.getCPtr(z), z, GT.getCPtr(x), x, Fr.getCPtr(y), y);
}
public static void neg(Fp y, Fp x) {
MclJNI.neg__SWIG_1(Fp.getCPtr(y), y, Fp.getCPtr(x), x);
}
public static void add(Fp z, Fp x, Fp y) {
MclJNI.add__SWIG_1(Fp.getCPtr(z), z, Fp.getCPtr(x), x, Fp.getCPtr(y), y);
}
public static void sub(Fp z, Fp x, Fp y) {
MclJNI.sub__SWIG_1(Fp.getCPtr(z), z, Fp.getCPtr(x), x, Fp.getCPtr(y), y);
}
public static void mul(Fp z, Fp x, Fp y) {
MclJNI.mul__SWIG_3(Fp.getCPtr(z), z, Fp.getCPtr(x), x, Fp.getCPtr(y), y);
}
public static void mul(G1 z, G1 x, Fp y) {
MclJNI.mul__SWIG_4(G1.getCPtr(z), z, G1.getCPtr(x), x, Fp.getCPtr(y), y);
}
public static void mul(G2 z, G2 x, Fp y) {
MclJNI.mul__SWIG_5(G2.getCPtr(z), z, G2.getCPtr(x), x, Fp.getCPtr(y), y);
}
public static void div(Fp z, Fp x, Fp y) {
MclJNI.div__SWIG_1(Fp.getCPtr(z), z, Fp.getCPtr(x), x, Fp.getCPtr(y), y);
}
public static void pow(GT z, GT x, Fp y) {
MclJNI.pow__SWIG_1(GT.getCPtr(z), z, GT.getCPtr(x), x, Fp.getCPtr(y), y);
}
public static void neg(G1 y, G1 x) {
MclJNI.neg__SWIG_2(G1.getCPtr(y), y, G1.getCPtr(x), x);
}
public static void dbl(G1 y, G1 x) {
MclJNI.dbl__SWIG_0(G1.getCPtr(y), y, G1.getCPtr(x), x);
}
public static void add(G1 z, G1 x, G1 y) {
MclJNI.add__SWIG_2(G1.getCPtr(z), z, G1.getCPtr(x), x, G1.getCPtr(y), y);
}
public static void sub(G1 z, G1 x, G1 y) {
MclJNI.sub__SWIG_2(G1.getCPtr(z), z, G1.getCPtr(x), x, G1.getCPtr(y), y);
}
public static void pairing(GT e, G1 P, G2 Q) {
MclJNI.pairing(GT.getCPtr(e), e, G1.getCPtr(P), P, G2.getCPtr(Q), Q);
}
public static void hashAndMapToG1(G1 P, byte[] cbuf) {
MclJNI.hashAndMapToG1(G1.getCPtr(P), P, cbuf);
}
public static void neg(G2 y, G2 x) {
MclJNI.neg__SWIG_3(G2.getCPtr(y), y, G2.getCPtr(x), x);
}
public static void dbl(G2 y, G2 x) {
MclJNI.dbl__SWIG_1(G2.getCPtr(y), y, G2.getCPtr(x), x);
}
public static void add(G2 z, G2 x, G2 y) {
MclJNI.add__SWIG_3(G2.getCPtr(z), z, G2.getCPtr(x), x, G2.getCPtr(y), y);
}
public static void sub(G2 z, G2 x, G2 y) {
MclJNI.sub__SWIG_3(G2.getCPtr(z), z, G2.getCPtr(x), x, G2.getCPtr(y), y);
}
public static void hashAndMapToG2(G2 P, byte[] cbuf) {
MclJNI.hashAndMapToG2(G2.getCPtr(P), P, cbuf);
}
public static void mul(GT z, GT x, GT y) {
MclJNI.mul__SWIG_6(GT.getCPtr(z), z, GT.getCPtr(x), x, GT.getCPtr(y), y);
}
}

@ -0,0 +1,14 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package com.herumi.mcl;
public interface MclConstants {
public final static int BN254 = 0;
public final static int BLS12_381 = 5;
}

@ -0,0 +1,104 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package com.herumi.mcl;
public class MclJNI {
public final static native void SystemInit(int jarg1);
public final static native void neg__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_);
public final static native void add__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
public final static native void sub__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
public final static native void mul__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
public final static native void mul__SWIG_1(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_, long jarg3, Fr jarg3_);
public final static native void mul__SWIG_2(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_, long jarg3, Fr jarg3_);
public final static native void div__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
public final static native void pow__SWIG_0(long jarg1, GT jarg1_, long jarg2, GT jarg2_, long jarg3, Fr jarg3_);
public final static native long new_Fr__SWIG_0();
public final static native long new_Fr__SWIG_1(long jarg1, Fr jarg1_);
public final static native long new_Fr__SWIG_2(int jarg1);
public final static native long new_Fr__SWIG_3(String jarg1, int jarg2);
public final static native long new_Fr__SWIG_4(String jarg1);
public final static native boolean Fr_equals(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_);
public final static native void Fr_setStr__SWIG_0(long jarg1, Fr jarg1_, String jarg2, int jarg3);
public final static native void Fr_setStr__SWIG_1(long jarg1, Fr jarg1_, String jarg2);
public final static native void Fr_setInt(long jarg1, Fr jarg1_, int jarg2);
public final static native void Fr_clear(long jarg1, Fr jarg1_);
public final static native void Fr_setByCSPRNG(long jarg1, Fr jarg1_);
public final static native String Fr_toString__SWIG_0(long jarg1, Fr jarg1_, int jarg2);
public final static native String Fr_toString__SWIG_1(long jarg1, Fr jarg1_);
public final static native void Fr_deserialize(long jarg1, Fr jarg1_, byte[] jarg2);
public final static native void delete_Fr(long jarg1);
public final static native void neg__SWIG_1(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_);
public final static native void add__SWIG_1(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_, long jarg3, Fp jarg3_);
public final static native void sub__SWIG_1(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_, long jarg3, Fp jarg3_);
public final static native void mul__SWIG_3(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_, long jarg3, Fp jarg3_);
public final static native void mul__SWIG_4(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_, long jarg3, Fp jarg3_);
public final static native void mul__SWIG_5(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_, long jarg3, Fp jarg3_);
public final static native void div__SWIG_1(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_, long jarg3, Fp jarg3_);
public final static native void pow__SWIG_1(long jarg1, GT jarg1_, long jarg2, GT jarg2_, long jarg3, Fp jarg3_);
public final static native long new_Fp__SWIG_0();
public final static native long new_Fp__SWIG_1(long jarg1, Fp jarg1_);
public final static native long new_Fp__SWIG_2(int jarg1);
public final static native long new_Fp__SWIG_3(String jarg1, int jarg2);
public final static native long new_Fp__SWIG_4(String jarg1);
public final static native boolean Fp_equals(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_);
public final static native void Fp_setStr__SWIG_0(long jarg1, Fp jarg1_, String jarg2, int jarg3);
public final static native void Fp_setStr__SWIG_1(long jarg1, Fp jarg1_, String jarg2);
public final static native void Fp_setInt(long jarg1, Fp jarg1_, int jarg2);
public final static native void Fp_clear(long jarg1, Fp jarg1_);
public final static native void Fp_setByCSPRNG(long jarg1, Fp jarg1_);
public final static native String Fp_toString__SWIG_0(long jarg1, Fp jarg1_, int jarg2);
public final static native String Fp_toString__SWIG_1(long jarg1, Fp jarg1_);
public final static native void Fp_deserialize(long jarg1, Fp jarg1_, byte[] jarg2);
public final static native void delete_Fp(long jarg1);
public final static native void neg__SWIG_2(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_);
public final static native void dbl__SWIG_0(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_);
public final static native void add__SWIG_2(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_, long jarg3, G1 jarg3_);
public final static native void sub__SWIG_2(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_, long jarg3, G1 jarg3_);
public final static native void pairing(long jarg1, GT jarg1_, long jarg2, G1 jarg2_, long jarg3, G2 jarg3_);
public final static native void hashAndMapToG1(long jarg1, G1 jarg1_, byte[] jarg2);
public final static native long new_G1__SWIG_0();
public final static native long new_G1__SWIG_1(long jarg1, G1 jarg1_);
public final static native long new_G1__SWIG_2(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_);
public final static native boolean G1_equals(long jarg1, G1 jarg1_, long jarg2, G1 jarg2_);
public final static native void G1_set(long jarg1, G1 jarg1_, long jarg2, Fp jarg2_, long jarg3, Fp jarg3_);
public final static native void G1_clear(long jarg1, G1 jarg1_);
public final static native void G1_setStr__SWIG_0(long jarg1, G1 jarg1_, String jarg2, int jarg3);
public final static native void G1_setStr__SWIG_1(long jarg1, G1 jarg1_, String jarg2);
public final static native String G1_toString__SWIG_0(long jarg1, G1 jarg1_, int jarg2);
public final static native String G1_toString__SWIG_1(long jarg1, G1 jarg1_);
public final static native void G1_deserialize(long jarg1, G1 jarg1_, byte[] jarg2);
public final static native void delete_G1(long jarg1);
public final static native void neg__SWIG_3(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_);
public final static native void dbl__SWIG_1(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_);
public final static native void add__SWIG_3(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_, long jarg3, G2 jarg3_);
public final static native void sub__SWIG_3(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_, long jarg3, G2 jarg3_);
public final static native void hashAndMapToG2(long jarg1, G2 jarg1_, byte[] jarg2);
public final static native long new_G2__SWIG_0();
public final static native long new_G2__SWIG_1(long jarg1, G2 jarg1_);
public final static native long new_G2__SWIG_2(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_, long jarg3, Fp jarg3_, long jarg4, Fp jarg4_);
public final static native boolean G2_equals(long jarg1, G2 jarg1_, long jarg2, G2 jarg2_);
public final static native void G2_set(long jarg1, G2 jarg1_, long jarg2, Fp jarg2_, long jarg3, Fp jarg3_, long jarg4, Fp jarg4_, long jarg5, Fp jarg5_);
public final static native void G2_clear(long jarg1, G2 jarg1_);
public final static native void G2_setStr__SWIG_0(long jarg1, G2 jarg1_, String jarg2, int jarg3);
public final static native void G2_setStr__SWIG_1(long jarg1, G2 jarg1_, String jarg2);
public final static native String G2_toString__SWIG_0(long jarg1, G2 jarg1_, int jarg2);
public final static native String G2_toString__SWIG_1(long jarg1, G2 jarg1_);
public final static native void G2_deserialize(long jarg1, G2 jarg1_, byte[] jarg2);
public final static native void delete_G2(long jarg1);
public final static native void mul__SWIG_6(long jarg1, GT jarg1_, long jarg2, GT jarg2_, long jarg3, GT jarg3_);
public final static native long new_GT__SWIG_0();
public final static native long new_GT__SWIG_1(long jarg1, GT jarg1_);
public final static native boolean GT_equals(long jarg1, GT jarg1_, long jarg2, GT jarg2_);
public final static native void GT_clear(long jarg1, GT jarg1_);
public final static native void GT_setStr__SWIG_0(long jarg1, GT jarg1_, String jarg2, int jarg3);
public final static native void GT_setStr__SWIG_1(long jarg1, GT jarg1_, String jarg2);
public final static native String GT_toString__SWIG_0(long jarg1, GT jarg1_, int jarg2);
public final static native String GT_toString__SWIG_1(long jarg1, GT jarg1_);
public final static native void delete_GT(long jarg1);
}

@ -21,7 +21,7 @@ System.loadLibrary("mcl_bn256");
## Fr
* `Fr::setInt(int x)` ; set by x
* `Fr::setStr(String str)` ; set by str such as "123", "0xfff", etc.
* `Fr::setRand()` ; randomly set
* `Fr::setByCSPRNG()` ; randomly set
* `Bn256.neg(Fr y, Fr x)` ; `y = -x`
* `Bn256.add(Fr z, Fr x, Fr y)` ; `z = x + y`
* `Bn256.sub(Fr z, Fr x, Fr y)` ; `z = x - y`
@ -68,7 +68,7 @@ String yb = "7937318970632701341203597196594272556916396164729705624521405069090
G2 Q = new G2(xa, xb, ya, yb); // fixed point of G2
Fr s = new Fr();
s.setRand(); // secret key
s.setByCSPRNG(); // secret key
G2 pub = new G2();
Bn256.mul(pub, Q, s); // public key = sQ

@ -0,0 +1,28 @@
%module Mcl
%include "std_string.i"
%include "std_except.i"
%apply(char *STRING, size_t LENGTH) { (const char *cbuf, size_t bufSize) };
%{
#include <mcl/bls12_381.hpp>
#include "mcl_impl.hpp"
%}
%include "mcl_impl.hpp"
%javaconst(1);
#define BN254 0
#define BLS12_381 5
%typemap(jtype) void serialize "byte[]"
%typemap(jstype) void serialize "byte[]"
%typemap(jni) void serialize "jbyteArray"
%typemap(javaout) void serialize { return $jnicall; }
%typemap(in, numinputs=0) std::string& out (std::string temp) "$1=&temp;"
%typemap(argout) std::string& out {
$result = JCALL1(NewByteArray, jenv, $1->size());
JCALL4(SetByteArrayRegion, jenv, $result, 0, $1->size(), (const jbyte*)$1->c_str());
}

@ -0,0 +1,353 @@
#include <mcl/bls12_381.hpp>
#include <stdint.h>
#include <sstream>
void SystemInit(int curveType) throw(std::exception)
{
mcl::CurveParam cp;
switch (curveType) {
case MCL_BN254: cp = mcl::BN254; break;
case MCL_BN_SNARK1: cp = mcl::BN_SNARK1; break;
case MCL_BLS12_381: cp = mcl::BLS12_381; break;
default:
throw std::runtime_error("bad curveType");
}
mcl::bn::initPairing(cp);
}
class G1;
class G2;
class GT;
/*
Fr = Z / rZ
*/
class Fr {
mcl::bn::Fr self_;
friend class G1;
friend class G2;
friend class GT;
friend void neg(Fr& y, const Fr& x);
friend void add(Fr& z, const Fr& x, const Fr& y);
friend void sub(Fr& z, const Fr& x, const Fr& y);
friend void mul(Fr& z, const Fr& x, const Fr& y);
friend void mul(G1& z, const G1& x, const Fr& y);
friend void mul(G2& z, const G2& x, const Fr& y);
friend void div(Fr& z, const Fr& x, const Fr& y);
friend void pow(GT& z, const GT& x, const Fr& y);
public:
Fr() {}
Fr(const Fr& rhs) : self_(rhs.self_) {}
Fr(int x) : self_(x) {}
Fr(const std::string& str, int base = 0) throw(std::exception)
: self_(str, base) {}
bool equals(const Fr& rhs) const { return self_ == rhs.self_; }
void setStr(const std::string& str, int base = 0) throw(std::exception)
{
self_.setStr(str, base);
}
void setInt(int x)
{
self_ = x;
}
void clear()
{
self_.clear();
}
void setByCSPRNG()
{
self_.setByCSPRNG();
}
std::string toString(int base = 0) const throw(std::exception)
{
return self_.getStr(base);
}
void deserialize(const char *cbuf, size_t bufSize) throw(std::exception)
{
if (self_.deserialize(cbuf, bufSize) == 0) {
throw std::runtime_error("deserialize");
}
}
};
void neg(Fr& y, const Fr& x)
{
mcl::bn::Fr::neg(y.self_, x.self_);
}
void add(Fr& z, const Fr& x, const Fr& y)
{
mcl::bn::Fr::add(z.self_, x.self_, y.self_);
}
void sub(Fr& z, const Fr& x, const Fr& y)
{
mcl::bn::Fr::sub(z.self_, x.self_, y.self_);
}
void mul(Fr& z, const Fr& x, const Fr& y)
{
mcl::bn::Fr::mul(z.self_, x.self_, y.self_);
}
void div(Fr& z, const Fr& x, const Fr& y)
{
mcl::bn::Fr::div(z.self_, x.self_, y.self_);
}
class Fp {
mcl::bn::Fp self_;
friend class G1;
friend class G2;
friend class GT;
friend void neg(Fp& y, const Fp& x);
friend void add(Fp& z, const Fp& x, const Fp& y);
friend void sub(Fp& z, const Fp& x, const Fp& y);
friend void mul(Fp& z, const Fp& x, const Fp& y);
friend void mul(G1& z, const G1& x, const Fp& y);
friend void mul(G2& z, const G2& x, const Fp& y);
friend void div(Fp& z, const Fp& x, const Fp& y);
friend void pow(GT& z, const GT& x, const Fp& y);
public:
Fp() {}
Fp(const Fp& rhs) : self_(rhs.self_) {}
Fp(int x) : self_(x) {}
Fp(const std::string& str, int base = 0) throw(std::exception)
: self_(str, base) {}
bool equals(const Fp& rhs) const { return self_ == rhs.self_; }
void setStr(const std::string& str, int base = 0) throw(std::exception)
{
self_.setStr(str, base);
}
void setInt(int x)
{
self_ = x;
}
void clear()
{
self_.clear();
}
void setByCSPRNG()
{
self_.setByCSPRNG();
}
std::string toString(int base = 0) const throw(std::exception)
{
return self_.getStr(base);
}
void deserialize(const char *cbuf, size_t bufSize) throw(std::exception)
{
if (self_.deserialize(cbuf, bufSize) == 0) {
throw std::runtime_error("deserialize");
}
}
};
void neg(Fp& y, const Fp& x)
{
mcl::bn::Fp::neg(y.self_, x.self_);
}
void add(Fp& z, const Fp& x, const Fp& y)
{
mcl::bn::Fp::add(z.self_, x.self_, y.self_);
}
void sub(Fp& z, const Fp& x, const Fp& y)
{
mcl::bn::Fp::sub(z.self_, x.self_, y.self_);
}
void mul(Fp& z, const Fp& x, const Fp& y)
{
mcl::bn::Fp::mul(z.self_, x.self_, y.self_);
}
void div(Fp& z, const Fp& x, const Fp& y)
{
mcl::bn::Fp::div(z.self_, x.self_, y.self_);
}
/*
#G1 = r
*/
class G1 {
mcl::bn::G1 self_;
friend void neg(G1& y, const G1& x);
friend void dbl(G1& y, const G1& x);
friend void add(G1& z, const G1& x, const G1& y);
friend void sub(G1& z, const G1& x, const G1& y);
friend void mul(G1& z, const G1& x, const Fr& y);
friend void pairing(GT& e, const G1& P, const G2& Q);
friend void hashAndMapToG1(G1& P, const char *cbuf, size_t bufSize) throw(std::exception);
public:
G1() {}
G1(const G1& rhs) : self_(rhs.self_) {}
G1(const Fp& x, const Fp& y) throw(std::exception)
: self_(x.self_, y.self_) { }
bool equals(const G1& rhs) const { return self_ == rhs.self_; }
void set(const Fp& x, const Fp& y) throw(std::exception)
{
self_.set(x.self_, y.self_);
}
void clear()
{
self_.clear();
}
/*
compressed format
*/
void setStr(const std::string& str, int base = 0) throw(std::exception)
{
self_.setStr(str, base);
}
std::string toString(int base = 0) const throw(std::exception)
{
return self_.getStr(base);
}
void deserialize(const char *cbuf, size_t bufSize) throw(std::exception)
{
if (self_.deserialize(cbuf, bufSize) == 0) {
throw std::runtime_error("deserialize");
}
}
};
void neg(G1& y, const G1& x)
{
mcl::bn::G1::neg(y.self_, x.self_);
}
void dbl(G1& y, const G1& x)
{
mcl::bn::G1::dbl(y.self_, x.self_);
}
void add(G1& z, const G1& x, const G1& y)
{
mcl::bn::G1::add(z.self_, x.self_, y.self_);
}
void sub(G1& z, const G1& x, const G1& y)
{
mcl::bn::G1::sub(z.self_, x.self_, y.self_);
}
void mul(G1& z, const G1& x, const Fr& y)
{
mcl::bn::G1::mul(z.self_, x.self_, y.self_);
}
/*
#G2 = r
*/
class G2 {
mcl::bn::G2 self_;
friend void neg(G2& y, const G2& x);
friend void dbl(G2& y, const G2& x);
friend void add(G2& z, const G2& x, const G2& y);
friend void sub(G2& z, const G2& x, const G2& y);
friend void mul(G2& z, const G2& x, const Fr& y);
friend void pairing(GT& e, const G1& P, const G2& Q);
friend void hashAndMapToG2(G2& P, const char *cbuf, size_t bufSize) throw(std::exception);
public:
G2() {}
G2(const G2& rhs) : self_(rhs.self_) {}
G2(const Fp& ax, const Fp& ay, const Fp& bx, const Fp& by) throw(std::exception)
: self_(mcl::bn::Fp2(ax.self_, ay.self_), mcl::bn::Fp2(bx.self_, by.self_))
{
}
bool equals(const G2& rhs) const { return self_ == rhs.self_; }
void set(const Fp& ax, const Fp& ay, const Fp& bx, const Fp& by) throw(std::exception)
{
self_.set(mcl::bn::Fp2(ax.self_, ay.self_), mcl::bn::Fp2(bx.self_, by.self_));
}
void clear()
{
self_.clear();
}
/*
compressed format
*/
void setStr(const std::string& str, int base = 0) throw(std::exception)
{
self_.setStr(str, base);
}
std::string toString(int base = 0) const throw(std::exception)
{
return self_.getStr(base);
}
void deserialize(const char *cbuf, size_t bufSize) throw(std::exception)
{
if (self_.deserialize(cbuf, bufSize) == 0) {
throw std::runtime_error("deserialize");
}
}
};
void neg(G2& y, const G2& x)
{
mcl::bn::G2::neg(y.self_, x.self_);
}
void dbl(G2& y, const G2& x)
{
mcl::bn::G2::dbl(y.self_, x.self_);
}
void add(G2& z, const G2& x, const G2& y)
{
mcl::bn::G2::add(z.self_, x.self_, y.self_);
}
void sub(G2& z, const G2& x, const G2& y)
{
mcl::bn::G2::sub(z.self_, x.self_, y.self_);
}
void mul(G2& z, const G2& x, const Fr& y)
{
mcl::bn::G2::mul(z.self_, x.self_, y.self_);
}
/*
#GT = r
*/
class GT {
mcl::bn::Fp12 self_;
friend void mul(GT& z, const GT& x, const GT& y);
friend void pow(GT& z, const GT& x, const Fr& y);
friend void pairing(GT& e, const G1& P, const G2& Q);
public:
GT() {}
GT(const GT& rhs) : self_(rhs.self_) {}
bool equals(const GT& rhs) const { return self_ == rhs.self_; }
void clear()
{
self_.clear();
}
void setStr(const std::string& str, int base = 0) throw(std::exception)
{
self_.setStr(str, base);
}
std::string toString(int base = 0) const throw(std::exception)
{
return self_.getStr(base);
}
};
void mul(GT& z, const GT& x, const GT& y)
{
mcl::bn::Fp12::mul(z.self_, x.self_, y.self_);
}
void pow(GT& z, const GT& x, const Fr& y)
{
mcl::bn::Fp12::pow(z.self_, x.self_, y.self_);
}
void pairing(GT& e, const G1& P, const G2& Q)
{
mcl::bn::pairing(e.self_, P.self_, Q.self_);
}
void hashAndMapToG1(G1& P, const char *cbuf, size_t bufSize) throw(std::exception)
{
mcl::bn::hashAndMapToG1(P.self_, cbuf, bufSize);
}
void hashAndMapToG2(G2& P, const char *cbuf, size_t bufSize) throw(std::exception)
{
mcl::bn::hashAndMapToG2(P.self_, cbuf, bufSize);
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save