aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-01-10 12:02:24 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-01-10 12:02:24 +0800
commit4d21e1df91076eb0559fceceb2f677e0c9f05404 (patch)
tree8925e6a9fbe624d83e7c4d03bf13cc3f98b83a2b
parent404e58445c8b9d4918afe80a916edd4d07e77d07 (diff)
downloaddexon-mcl-4d21e1df91076eb0559fceceb2f677e0c9f05404.tar.gz
dexon-mcl-4d21e1df91076eb0559fceceb2f677e0c9f05404.tar.zst
dexon-mcl-4d21e1df91076eb0559fceceb2f677e0c9f05404.zip
add Bn256 JNI
-rw-r--r--java/Bn256Test.java84
-rw-r--r--java/Makefile25
-rw-r--r--java/bn256.i37
-rw-r--r--java/bn256_impl.hpp249
-rw-r--r--java/com/herumi/mcl/CipherText.java66
-rw-r--r--java/com/herumi/mcl/Elgamal.java38
-rw-r--r--java/com/herumi/mcl/ElgamalJNI.java51
-rw-r--r--java/com/herumi/mcl/PrivateKey.java86
-rw-r--r--java/com/herumi/mcl/PublicKey.java82
-rw-r--r--java/com/herumi/mcl/SWIGTYPE_p_bool.java26
-rwxr-xr-xjava/make_wrap.bat13
-rwxr-xr-xjava/run-bn256.bat8
12 files changed, 405 insertions, 360 deletions
diff --git a/java/Bn256Test.java b/java/Bn256Test.java
new file mode 100644
index 0000000..4dcddf2
--- /dev/null
+++ b/java/Bn256Test.java
@@ -0,0 +1,84 @@
+import java.io.*;
+import com.herumi.mcl.*;
+
+/*
+ Bn256Test [ecParam]
+ ecParam = secp192k1, NIST_P224, ...
+ hashParam = hash224, hash384, ...
+*/
+public class Bn256Test {
+ static {
+ String lib = "mcl_bn256";
+ String libName = System.mapLibraryName(lib);
+ System.out.println("libName : " + libName);
+ System.loadLibrary(lib);
+ }
+ public static void assertEquals(String msg, String x, String y) {
+ if (x.equals(y)) {
+ System.out.println("OK : " + msg);
+ } else {
+ System.out.println("NG : " + msg + ", x = " + x + ", y = " + y);
+ }
+ }
+ public static void assertBool(String msg, boolean b) {
+ if (b) {
+ System.out.println("OK : " + msg);
+ } else {
+ System.out.println("NG : " + msg);
+ }
+ }
+ public static void main(String argv[]) {
+ try {
+ Bn256.SystemInit();
+ 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);
+ assertEquals("x == 3", x.toString(), "3");
+ Bn256.mul(x, x, x);
+ assertEquals("x == 9", x.toString(), "9");
+ G1 P = new G1();
+ System.out.println("P=" + P);
+ P.set("-1", "1");
+ System.out.println("P=" + P);
+ Bn256.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);
+
+ P.hashAndMap("This is a pen");
+ {
+ String s = P.toString();
+ G1 P1 = new G1();
+ P1.setStr(s);
+ assertBool("P == P1", P1.equals(P));
+ }
+
+ GT e = new GT();
+ Bn256.pairing(e, Q, P);
+ GT e1 = new GT();
+ GT e2 = new GT();
+ Fr c = new Fr("1234567890123234928348230428394234");
+ G2 cQ = new G2(Q);
+ Bn256.mul(cQ, Q, c); // cQ = Q * c
+ Bn256.pairing(e1, cQ, P);
+ Bn256.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, Q, cP);
+ assertBool("e1 == e2", e1.equals(e2));
+ } catch (RuntimeException e) {
+ System.out.println("unknown exception :" + e);
+ }
+ }
+}
diff --git a/java/Makefile b/java/Makefile
index fb10814..33d49fa 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -15,36 +15,47 @@ MCL_LIB=../lib/libmcl.a
PACKAGE_NAME=com.herumi.mcl
PACKAGE_DIR=$(subst .,/,$(PACKAGE_NAME))
-TARGET=../bin/libmcl_elgamal.$(LIB_SUF)
+ELGAMAL_LIB=../bin/libmcl_elgamal.$(LIB_SUF)
+BN256_LIB=../bin/libmcl_bn256.$(LIB_SUF)
JAVA_EXE=cd ../bin && LD_LIBRARY_PATH=./:$(LD_LIBRARY_PATH) java -classpath ../java
-all: $(TARGET)
+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
+ $(MKDIR) $(PACKAGE_DIR)
+ swig -java -package $(PACKAGE_NAME) -outdir $(PACKAGE_DIR) -c++ -Wall bn256.i
+
$(MCL_LIB):
make -C ..
-$(TARGET): elgamal_wrap.cxx $(MCL_LIB)
+$(ELGAMAL_LIB): elgamal_wrap.cxx $(MCL_LIB)
$(PRE)$(CXX) $< -o $@ $(CFLAGS) $(LDFLAGS) $(MCL_LIB) -shared
+$(BN256_LIB): bn256_wrap.cxx $(MCL_LIB)
+ $(PRE)$(CXX) $< -o $@ $(CFLAGS) $(LDFLAGS) $(MCL_LIB) -shared
%.class: %.java
javac $<
-ElgamalTest.class: ElgamalTest.java $(TARGET)
+ElgamalTest.class: ElgamalTest.java $(ELGAMAL_LIB)
+Bn256Test.class: Bn256Test.java $(BN256_LIB)
jar:
- jar cvf mcl_elgamal.jar com
+ jar cvf mcl.jar com
-test_elgamal: ElgamalTest.class $(TARGET)
+test_elgamal: ElgamalTest.class $(ELGAMAL_LIB)
$(JAVA_EXE) ElgamalTest
$(JAVA_EXE) ElgamalTest -e NIST_P192
$(JAVA_EXE) ElgamalTest -e NIST_P256 -h sha256
$(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
+
clean:
- rm -rf *.class $(TARGET) $(PACKAGE_DIR)/*.class
+ rm -rf *.class $(ELGAMAL_LIB) $(PACKAGE_DIR)/*.class *_wrap.cxx
diff --git a/java/bn256.i b/java/bn256.i
new file mode 100644
index 0000000..848d116
--- /dev/null
+++ b/java/bn256.i
@@ -0,0 +1,37 @@
+%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;
+ mcl::bn::MapTo<mcl::bn256::Fp> mapTo;
+ static inline Param& getParam()
+ {
+ static Param p;
+ return p;
+ }
+};
+static void mapToG1(mcl::bn256::G1& P, const mcl::bn256::Fp& t)
+{
+ static mcl::bn::MapTo<mcl::bn256::Fp> mapTo;
+ mapTo.calcG1(P, t);
+}
+
+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());
+ mapToG1(P, t);
+}
+
+#include "bn256_impl.hpp"
+%}
+
+%include "bn256_impl.hpp"
diff --git a/java/bn256_impl.hpp b/java/bn256_impl.hpp
new file mode 100644
index 0000000..ca04a38
--- /dev/null
+++ b/java/bn256_impl.hpp
@@ -0,0 +1,249 @@
+#include <mcl/bn256.hpp>
+#include <stdint.h>
+#include <sstream>
+
+void SystemInit() throw(std::exception)
+{
+ mcl::bn256::bn256init();
+}
+
+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 G2& Q, const G1& P);
+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 hashAndMap(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 G2& Q, const G1& P);
+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 G2& Q, const G1& P);
+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 G2& Q, const G1& P)
+{
+ mcl::bn256::BN::pairing(e.self_, Q.self_, P.self_);
+}
diff --git a/java/com/herumi/mcl/CipherText.java b/java/com/herumi/mcl/CipherText.java
deleted file mode 100644
index 4584755..0000000
--- a/java/com/herumi/mcl/CipherText.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.8
- *
- * 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 CipherText {
- private transient long swigCPtr;
- protected transient boolean swigCMemOwn;
-
- protected CipherText(long cPtr, boolean cMemoryOwn) {
- swigCMemOwn = cMemoryOwn;
- swigCPtr = cPtr;
- }
-
- protected static long getCPtr(CipherText obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-
- protected void finalize() {
- delete();
- }
-
- public synchronized void delete() {
- if (swigCPtr != 0) {
- if (swigCMemOwn) {
- swigCMemOwn = false;
- ElgamalJNI.delete_CipherText(swigCPtr);
- }
- swigCPtr = 0;
- }
- }
-
- public String toStr() {
- return ElgamalJNI.CipherText_toStr(swigCPtr, this);
- }
-
- public String toString() {
- return ElgamalJNI.CipherText_toString(swigCPtr, this);
- }
-
- public void fromStr(String str) {
- ElgamalJNI.CipherText_fromStr(swigCPtr, this, str);
- }
-
- public void add(CipherText c) {
- ElgamalJNI.CipherText_add(swigCPtr, this, CipherText.getCPtr(c), c);
- }
-
- public void mul(int m) {
- ElgamalJNI.CipherText_mul__SWIG_0(swigCPtr, this, m);
- }
-
- public void mul(String str) {
- ElgamalJNI.CipherText_mul__SWIG_1(swigCPtr, this, str);
- }
-
- public CipherText() {
- this(ElgamalJNI.new_CipherText(), true);
- }
-
-}
diff --git a/java/com/herumi/mcl/Elgamal.java b/java/com/herumi/mcl/Elgamal.java
deleted file mode 100644
index 95beb30..0000000
--- a/java/com/herumi/mcl/Elgamal.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.8
- *
- * 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 Elgamal {
- public static SWIGTYPE_p_bool new_p_bool() {
- long cPtr = ElgamalJNI.new_p_bool();
- return (cPtr == 0) ? null : new SWIGTYPE_p_bool(cPtr, false);
- }
-
- public static SWIGTYPE_p_bool copy_p_bool(boolean value) {
- long cPtr = ElgamalJNI.copy_p_bool(value);
- return (cPtr == 0) ? null : new SWIGTYPE_p_bool(cPtr, false);
- }
-
- public static void delete_p_bool(SWIGTYPE_p_bool obj) {
- ElgamalJNI.delete_p_bool(SWIGTYPE_p_bool.getCPtr(obj));
- }
-
- public static void p_bool_assign(SWIGTYPE_p_bool obj, boolean value) {
- ElgamalJNI.p_bool_assign(SWIGTYPE_p_bool.getCPtr(obj), value);
- }
-
- public static boolean p_bool_value(SWIGTYPE_p_bool obj) {
- return ElgamalJNI.p_bool_value(SWIGTYPE_p_bool.getCPtr(obj));
- }
-
- public static void SystemInit(String param) {
- ElgamalJNI.SystemInit(param);
- }
-
-}
diff --git a/java/com/herumi/mcl/ElgamalJNI.java b/java/com/herumi/mcl/ElgamalJNI.java
deleted file mode 100644
index f2f09a9..0000000
--- a/java/com/herumi/mcl/ElgamalJNI.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.8
- *
- * 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 ElgamalJNI {
- public final static native long new_p_bool();
- public final static native long copy_p_bool(boolean jarg1);
- public final static native void delete_p_bool(long jarg1);
- public final static native void p_bool_assign(long jarg1, boolean jarg2);
- public final static native boolean p_bool_value(long jarg1);
- public final static native void SystemInit(String jarg1);
- public final static native String CipherText_toStr(long jarg1, CipherText jarg1_);
- public final static native String CipherText_toString(long jarg1, CipherText jarg1_);
- public final static native void CipherText_fromStr(long jarg1, CipherText jarg1_, String jarg2);
- public final static native void CipherText_add(long jarg1, CipherText jarg1_, long jarg2, CipherText jarg2_);
- public final static native void CipherText_mul__SWIG_0(long jarg1, CipherText jarg1_, int jarg2);
- public final static native void CipherText_mul__SWIG_1(long jarg1, CipherText jarg1_, String jarg2);
- public final static native long new_CipherText();
- public final static native void delete_CipherText(long jarg1);
- public final static native String PublicKey_toStr(long jarg1, PublicKey jarg1_);
- public final static native String PublicKey_toString(long jarg1, PublicKey jarg1_);
- public final static native void PublicKey_fromStr(long jarg1, PublicKey jarg1_, String jarg2);
- public final static native void PublicKey_save(long jarg1, PublicKey jarg1_, String jarg2);
- public final static native void PublicKey_load(long jarg1, PublicKey jarg1_, String jarg2);
- public final static native void PublicKey_enc__SWIG_0(long jarg1, PublicKey jarg1_, long jarg2, CipherText jarg2_, int jarg3);
- public final static native void PublicKey_enc__SWIG_1(long jarg1, PublicKey jarg1_, long jarg2, CipherText jarg2_, String jarg3);
- public final static native void PublicKey_rerandomize(long jarg1, PublicKey jarg1_, long jarg2, CipherText jarg2_);
- public final static native void PublicKey_add__SWIG_0(long jarg1, PublicKey jarg1_, long jarg2, CipherText jarg2_, int jarg3);
- public final static native void PublicKey_add__SWIG_1(long jarg1, PublicKey jarg1_, long jarg2, CipherText jarg2_, String jarg3);
- public final static native long new_PublicKey();
- public final static native void delete_PublicKey(long jarg1);
- public final static native String PrivateKey_toStr(long jarg1, PrivateKey jarg1_);
- public final static native String PrivateKey_toString(long jarg1, PrivateKey jarg1_);
- public final static native void PrivateKey_fromStr(long jarg1, PrivateKey jarg1_, String jarg2);
- public final static native void PrivateKey_save(long jarg1, PrivateKey jarg1_, String jarg2);
- public final static native void PrivateKey_load(long jarg1, PrivateKey jarg1_, String jarg2);
- public final static native void PrivateKey_init(long jarg1, PrivateKey jarg1_);
- public final static native long PrivateKey_getPublicKey(long jarg1, PrivateKey jarg1_);
- public final static native int PrivateKey_dec__SWIG_0(long jarg1, PrivateKey jarg1_, long jarg2, CipherText jarg2_, long jarg3);
- public final static native int PrivateKey_dec__SWIG_1(long jarg1, PrivateKey jarg1_, long jarg2, CipherText jarg2_);
- public final static native void PrivateKey_setCache(long jarg1, PrivateKey jarg1_, int jarg2, int jarg3);
- public final static native void PrivateKey_clearCache(long jarg1, PrivateKey jarg1_);
- public final static native long new_PrivateKey();
- public final static native void delete_PrivateKey(long jarg1);
-}
diff --git a/java/com/herumi/mcl/PrivateKey.java b/java/com/herumi/mcl/PrivateKey.java
deleted file mode 100644
index 10c01bd..0000000
--- a/java/com/herumi/mcl/PrivateKey.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.8
- *
- * 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 PrivateKey {
- private transient long swigCPtr;
- protected transient boolean swigCMemOwn;
-
- protected PrivateKey(long cPtr, boolean cMemoryOwn) {
- swigCMemOwn = cMemoryOwn;
- swigCPtr = cPtr;
- }
-
- protected static long getCPtr(PrivateKey obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-
- protected void finalize() {
- delete();
- }
-
- public synchronized void delete() {
- if (swigCPtr != 0) {
- if (swigCMemOwn) {
- swigCMemOwn = false;
- ElgamalJNI.delete_PrivateKey(swigCPtr);
- }
- swigCPtr = 0;
- }
- }
-
- public String toStr() {
- return ElgamalJNI.PrivateKey_toStr(swigCPtr, this);
- }
-
- public String toString() {
- return ElgamalJNI.PrivateKey_toString(swigCPtr, this);
- }
-
- public void fromStr(String str) {
- ElgamalJNI.PrivateKey_fromStr(swigCPtr, this, str);
- }
-
- public void save(String fileName) {
- ElgamalJNI.PrivateKey_save(swigCPtr, this, fileName);
- }
-
- public void load(String fileName) {
- ElgamalJNI.PrivateKey_load(swigCPtr, this, fileName);
- }
-
- public void init() {
- ElgamalJNI.PrivateKey_init(swigCPtr, this);
- }
-
- public PublicKey getPublicKey() {
- return new PublicKey(ElgamalJNI.PrivateKey_getPublicKey(swigCPtr, this), true);
- }
-
- public int dec(CipherText c, SWIGTYPE_p_bool b) {
- return ElgamalJNI.PrivateKey_dec__SWIG_0(swigCPtr, this, CipherText.getCPtr(c), c, SWIGTYPE_p_bool.getCPtr(b));
- }
-
- public int dec(CipherText c) {
- return ElgamalJNI.PrivateKey_dec__SWIG_1(swigCPtr, this, CipherText.getCPtr(c), c);
- }
-
- public void setCache(int rangeMin, int rangeMax) {
- ElgamalJNI.PrivateKey_setCache(swigCPtr, this, rangeMin, rangeMax);
- }
-
- public void clearCache() {
- ElgamalJNI.PrivateKey_clearCache(swigCPtr, this);
- }
-
- public PrivateKey() {
- this(ElgamalJNI.new_PrivateKey(), true);
- }
-
-}
diff --git a/java/com/herumi/mcl/PublicKey.java b/java/com/herumi/mcl/PublicKey.java
deleted file mode 100644
index 1e6c63f..0000000
--- a/java/com/herumi/mcl/PublicKey.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.8
- *
- * 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 PublicKey {
- private transient long swigCPtr;
- protected transient boolean swigCMemOwn;
-
- protected PublicKey(long cPtr, boolean cMemoryOwn) {
- swigCMemOwn = cMemoryOwn;
- swigCPtr = cPtr;
- }
-
- protected static long getCPtr(PublicKey obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-
- protected void finalize() {
- delete();
- }
-
- public synchronized void delete() {
- if (swigCPtr != 0) {
- if (swigCMemOwn) {
- swigCMemOwn = false;
- ElgamalJNI.delete_PublicKey(swigCPtr);
- }
- swigCPtr = 0;
- }
- }
-
- public String toStr() {
- return ElgamalJNI.PublicKey_toStr(swigCPtr, this);
- }
-
- public String toString() {
- return ElgamalJNI.PublicKey_toString(swigCPtr, this);
- }
-
- public void fromStr(String str) {
- ElgamalJNI.PublicKey_fromStr(swigCPtr, this, str);
- }
-
- public void save(String fileName) {
- ElgamalJNI.PublicKey_save(swigCPtr, this, fileName);
- }
-
- public void load(String fileName) {
- ElgamalJNI.PublicKey_load(swigCPtr, this, fileName);
- }
-
- public void enc(CipherText c, int m) {
- ElgamalJNI.PublicKey_enc__SWIG_0(swigCPtr, this, CipherText.getCPtr(c), c, m);
- }
-
- public void enc(CipherText c, String str) {
- ElgamalJNI.PublicKey_enc__SWIG_1(swigCPtr, this, CipherText.getCPtr(c), c, str);
- }
-
- public void rerandomize(CipherText c) {
- ElgamalJNI.PublicKey_rerandomize(swigCPtr, this, CipherText.getCPtr(c), c);
- }
-
- public void add(CipherText c, int m) {
- ElgamalJNI.PublicKey_add__SWIG_0(swigCPtr, this, CipherText.getCPtr(c), c, m);
- }
-
- public void add(CipherText c, String str) {
- ElgamalJNI.PublicKey_add__SWIG_1(swigCPtr, this, CipherText.getCPtr(c), c, str);
- }
-
- public PublicKey() {
- this(ElgamalJNI.new_PublicKey(), true);
- }
-
-}
diff --git a/java/com/herumi/mcl/SWIGTYPE_p_bool.java b/java/com/herumi/mcl/SWIGTYPE_p_bool.java
deleted file mode 100644
index e998dde..0000000
--- a/java/com/herumi/mcl/SWIGTYPE_p_bool.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.8
- *
- * 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 SWIGTYPE_p_bool {
- private transient long swigCPtr;
-
- protected SWIGTYPE_p_bool(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
- swigCPtr = cPtr;
- }
-
- protected SWIGTYPE_p_bool() {
- swigCPtr = 0;
- }
-
- protected static long getCPtr(SWIGTYPE_p_bool obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-}
-
diff --git a/java/make_wrap.bat b/java/make_wrap.bat
index e658c33..8198b8a 100755
--- a/java/make_wrap.bat
+++ b/java/make_wrap.bat
@@ -4,14 +4,19 @@ set JAVA_INCLUDE=%JAVA_DIR%\include
set SWIG=..\..\..\p\swig\swig.exe
set PACKAGE_NAME=com.herumi.mcl
set PACKAGE_DIR=%PACKAGE_NAME:.=\%
+if /i "%1"=="" (
+ set NAME=elgamal
+) else (
+ set NAME=%1
+)
echo [[run swig]]
mkdir %PACKAGE_DIR%
-%SWIG% -java -package %PACKAGE_NAME% -outdir %PACKAGE_DIR% -c++ -Wall elgamal.i
+%SWIG% -java -package %PACKAGE_NAME% -outdir %PACKAGE_DIR% -c++ -Wall %NAME%.i
echo [[make dll]]
-cl /MT /DNOMINMAX /LD /Ox /DNDEBUG /EHsc elgamal_wrap.cxx ../src/fp.cpp -DMCL_NO_AUTOLINK -I%JAVA_INCLUDE% -I%JAVA_INCLUDE%\win32 -I../include -I../../cybozulib/include -I../../cybozulib_ext/include -I../../xbyak /link /LIBPATH:../../cybozulib_ext/lib /OUT:../bin/mcl_elgamal.dll
+cl /MT /DNOMINMAX /LD /Ox /DNDEBUG /EHsc %NAME%_wrap.cxx ../src/fp.cpp -DMCL_NO_AUTOLINK -I%JAVA_INCLUDE% -I%JAVA_INCLUDE%\win32 -I../include -I../../cybozulib/include -I../../cybozulib_ext/include -I../../xbyak /link /LIBPATH:../../cybozulib_ext/lib /OUT:../bin/mcl_%NAME%.dll
-call run-elgamal.bat
+call run-%NAME%.bat
echo [[make jar]]
-%JAVA_DIR%\bin\jar cvf mcl_elgamal.jar com \ No newline at end of file
+%JAVA_DIR%\bin\jar cvf mcl.jar com
diff --git a/java/run-bn256.bat b/java/run-bn256.bat
new file mode 100755
index 0000000..19018c1
--- /dev/null
+++ b/java/run-bn256.bat
@@ -0,0 +1,8 @@
+@echo off
+echo [[compile Bn256Test.java]]
+%JAVA_DIR%\bin\javac Bn256Test.java
+
+echo [[run Bn256Test]]
+pushd ..\bin
+%JAVA_DIR%\bin\java -classpath ..\java Bn256Test %1 %2 %3 %4 %5 %6
+popd