[skip ci][java] add Fr::inv and Fp::inv

update-fork
MITSUNARI Shigeo 4 years ago
parent e9399112b7
commit de148824a4
  1. 3
      ffi/java/MclTest.java
  2. 4
      ffi/java/com/herumi/mcl/Fp.java
  3. 4
      ffi/java/com/herumi/mcl/Fr.java
  4. 10
      ffi/java/com/herumi/mcl/Mcl.java
  5. 6
      ffi/java/com/herumi/mcl/MclJNI.java
  6. 14
      ffi/java/mcl_impl.hpp
  7. 76
      ffi/java/mcl_wrap.cxx

@ -45,6 +45,9 @@ public class MclTest {
assertEquals("x == 12", (new Fr("12")).toString(), "12"); assertEquals("x == 12", (new Fr("12")).toString(), "12");
assertEquals("x == 18", (new Fr("12", 16)).toString(), "18"); assertEquals("x == 18", (new Fr("12", 16)).toString(), "18");
assertEquals("x == ff", (new Fr("255")).toString(16), "ff"); assertEquals("x == ff", (new Fr("255")).toString(16), "ff");
Mcl.inv(y, x);
Mcl.mul(x, y, x);
assertBool("x == 1", x.isOne());
{ {
byte[] b = x.serialize(); byte[] b = x.serialize();

@ -64,6 +64,10 @@ public class Fp {
return MclJNI.Fp_isZero(swigCPtr, this); return MclJNI.Fp_isZero(swigCPtr, this);
} }
public boolean isOne() {
return MclJNI.Fp_isOne(swigCPtr, this);
}
public void setStr(String str, int base) { public void setStr(String str, int base) {
MclJNI.Fp_setStr__SWIG_0(swigCPtr, this, str, base); MclJNI.Fp_setStr__SWIG_0(swigCPtr, this, str, base);
} }

@ -64,6 +64,10 @@ public class Fr {
return MclJNI.Fr_isZero(swigCPtr, this); return MclJNI.Fr_isZero(swigCPtr, this);
} }
public boolean isOne() {
return MclJNI.Fr_isOne(swigCPtr, this);
}
public void setStr(String str, int base) { public void setStr(String str, int base) {
MclJNI.Fr_setStr__SWIG_0(swigCPtr, this, str, base); MclJNI.Fr_setStr__SWIG_0(swigCPtr, this, str, base);
} }

@ -17,6 +17,10 @@ public class Mcl implements MclConstants {
MclJNI.neg__SWIG_0(Fr.getCPtr(y), y, Fr.getCPtr(x), x); MclJNI.neg__SWIG_0(Fr.getCPtr(y), y, Fr.getCPtr(x), x);
} }
public static void inv(Fr y, Fr x) {
MclJNI.inv__SWIG_0(Fr.getCPtr(y), y, Fr.getCPtr(x), x);
}
public static void add(Fr z, Fr x, Fr y) { 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); MclJNI.add__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y);
} }
@ -49,6 +53,10 @@ public class Mcl implements MclConstants {
MclJNI.neg__SWIG_1(Fp.getCPtr(y), y, Fp.getCPtr(x), x); MclJNI.neg__SWIG_1(Fp.getCPtr(y), y, Fp.getCPtr(x), x);
} }
public static void inv(Fp y, Fp x) {
MclJNI.inv__SWIG_1(Fp.getCPtr(y), y, Fp.getCPtr(x), x);
}
public static void add(Fp z, Fp x, Fp y) { 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); MclJNI.add__SWIG_1(Fp.getCPtr(z), z, Fp.getCPtr(x), x, Fp.getCPtr(y), y);
} }
@ -114,7 +122,7 @@ public class Mcl implements MclConstants {
} }
public static void inv(GT y, GT x) { public static void inv(GT y, GT x) {
MclJNI.inv(GT.getCPtr(y), y, GT.getCPtr(x), x); MclJNI.inv__SWIG_2(GT.getCPtr(y), y, GT.getCPtr(x), x);
} }
} }

@ -11,6 +11,7 @@ package com.herumi.mcl;
public class MclJNI { public class MclJNI {
public final static native void SystemInit(int jarg1); 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 neg__SWIG_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_);
public final static native void inv__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 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 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_0(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_, long jarg3, Fr jarg3_);
@ -25,6 +26,7 @@ public class MclJNI {
public final static native long new_Fr__SWIG_4(String jarg1); 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 boolean Fr_equals(long jarg1, Fr jarg1_, long jarg2, Fr jarg2_);
public final static native boolean Fr_isZero(long jarg1, Fr jarg1_); public final static native boolean Fr_isZero(long jarg1, Fr jarg1_);
public final static native boolean Fr_isOne(long jarg1, Fr jarg1_);
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_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_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_setInt(long jarg1, Fr jarg1_, int jarg2);
@ -38,6 +40,7 @@ public class MclJNI {
public final static native byte[] Fr_serialize(long jarg1, Fr jarg1_); public final static native byte[] Fr_serialize(long jarg1, Fr jarg1_);
public final static native void delete_Fr(long jarg1); 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 neg__SWIG_1(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_);
public final static native void inv__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 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 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_3(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_, long jarg3, Fp jarg3_);
@ -49,6 +52,7 @@ public class MclJNI {
public final static native long new_Fp__SWIG_4(String jarg1); 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 boolean Fp_equals(long jarg1, Fp jarg1_, long jarg2, Fp jarg2_);
public final static native boolean Fp_isZero(long jarg1, Fp jarg1_); public final static native boolean Fp_isZero(long jarg1, Fp jarg1_);
public final static native boolean Fp_isOne(long jarg1, Fp jarg1_);
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_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_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_setInt(long jarg1, Fp jarg1_, int jarg2);
@ -100,7 +104,7 @@ public class MclJNI {
public final static native byte[] G2_serialize(long jarg1, G2 jarg1_); public final static native byte[] G2_serialize(long jarg1, G2 jarg1_);
public final static native void delete_G2(long jarg1); public final static native void delete_G2(long jarg1);
public final static native void mul__SWIG_4(long jarg1, GT jarg1_, long jarg2, GT jarg2_, long jarg3, GT jarg3_); public final static native void mul__SWIG_4(long jarg1, GT jarg1_, long jarg2, GT jarg2_, long jarg3, GT jarg3_);
public final static native void inv(long jarg1, GT jarg1_, long jarg2, GT jarg2_); public final static native void inv__SWIG_2(long jarg1, GT jarg1_, long jarg2, GT jarg2_);
public final static native long new_GT__SWIG_0(); 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 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 boolean GT_equals(long jarg1, GT jarg1_, long jarg2, GT jarg2_);

@ -61,6 +61,7 @@ class Fr {
friend class G2; friend class G2;
friend class GT; friend class GT;
friend void neg(Fr& y, const Fr& x); friend void neg(Fr& y, const Fr& x);
friend void inv(Fr& y, const Fr& x);
friend void add(Fr& z, const Fr& x, const Fr& y); friend void add(Fr& z, const Fr& x, const Fr& y);
friend void sub(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(Fr& z, const Fr& x, const Fr& y);
@ -76,6 +77,7 @@ public:
: self_(str, base) {} : self_(str, base) {}
bool equals(const Fr& rhs) const { return self_ == rhs.self_; } bool equals(const Fr& rhs) const { return self_ == rhs.self_; }
bool isZero() const { return self_.isZero(); } bool isZero() const { return self_.isZero(); }
bool isOne() const { return self_.isOne(); }
void setStr(const std::string& str, int base = 0) throw(std::exception) void setStr(const std::string& str, int base = 0) throw(std::exception)
{ {
self_.setStr(str, base); self_.setStr(str, base);
@ -119,6 +121,11 @@ void neg(Fr& y, const Fr& x)
mcl::bn::Fr::neg(y.self_, x.self_); mcl::bn::Fr::neg(y.self_, x.self_);
} }
void inv(Fr& y, const Fr& x)
{
mcl::bn::Fr::inv(y.self_, x.self_);
}
void add(Fr& z, const Fr& x, const Fr& y) void add(Fr& z, const Fr& x, const Fr& y)
{ {
mcl::bn::Fr::add(z.self_, x.self_, y.self_); mcl::bn::Fr::add(z.self_, x.self_, y.self_);
@ -145,6 +152,7 @@ class Fp {
friend class G2; friend class G2;
friend class GT; friend class GT;
friend void neg(Fp& y, const Fp& x); friend void neg(Fp& y, const Fp& x);
friend void inv(Fp& y, const Fp& x);
friend void add(Fp& z, const Fp& x, const Fp& y); friend void add(Fp& z, const Fp& x, const Fp& y);
friend void sub(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(Fp& z, const Fp& x, const Fp& y);
@ -157,6 +165,7 @@ public:
: self_(str, base) {} : self_(str, base) {}
bool equals(const Fp& rhs) const { return self_ == rhs.self_; } bool equals(const Fp& rhs) const { return self_ == rhs.self_; }
bool isZero() const { return self_.isZero(); } bool isZero() const { return self_.isZero(); }
bool isOne() const { return self_.isOne(); }
void setStr(const std::string& str, int base = 0) throw(std::exception) void setStr(const std::string& str, int base = 0) throw(std::exception)
{ {
self_.setStr(str, base); self_.setStr(str, base);
@ -192,6 +201,11 @@ void neg(Fp& y, const Fp& x)
mcl::bn::Fp::neg(y.self_, x.self_); mcl::bn::Fp::neg(y.self_, x.self_);
} }
void inv(Fp& y, const Fp& x)
{
mcl::bn::Fp::inv(y.self_, x.self_);
}
void add(Fp& z, const Fp& x, const Fp& y) void add(Fp& z, const Fp& x, const Fp& y)
{ {
mcl::bn::Fp::add(z.self_, x.self_, y.self_); mcl::bn::Fp::add(z.self_, x.self_, y.self_);

@ -286,6 +286,28 @@ SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_neg_1_1SWIG_10(JNIEnv *jenv,
} }
SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_inv_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
Fr *arg1 = 0 ;
Fr *arg2 = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
(void)jarg2_;
arg1 = *(Fr **)&jarg1;
if (!arg1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Fr & reference is null");
return ;
}
arg2 = *(Fr **)&jarg2;
if (!arg2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Fr const & reference is null");
return ;
}
inv(*arg1,(Fr const &)*arg2);
}
SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_add_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jlong jarg3, jobject jarg3_) { SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_add_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jlong jarg3, jobject jarg3_) {
Fr *arg1 = 0 ; Fr *arg1 = 0 ;
Fr *arg2 = 0 ; Fr *arg2 = 0 ;
@ -627,6 +649,21 @@ SWIGEXPORT jboolean JNICALL Java_com_herumi_mcl_MclJNI_Fr_1isZero(JNIEnv *jenv,
} }
SWIGEXPORT jboolean JNICALL Java_com_herumi_mcl_MclJNI_Fr_1isOne(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jboolean jresult = 0 ;
Fr *arg1 = (Fr *) 0 ;
bool result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(Fr **)&jarg1;
result = (bool)((Fr const *)arg1)->isOne();
jresult = (jboolean)result;
return jresult;
}
SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_Fr_1setStr_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jint jarg3) { SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_Fr_1setStr_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jint jarg3) {
Fr *arg1 = (Fr *) 0 ; Fr *arg1 = (Fr *) 0 ;
std::string *arg2 = 0 ; std::string *arg2 = 0 ;
@ -908,6 +945,28 @@ SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_neg_1_1SWIG_11(JNIEnv *jenv,
} }
SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_inv_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
Fp *arg1 = 0 ;
Fp *arg2 = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
(void)jarg2_;
arg1 = *(Fp **)&jarg1;
if (!arg1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Fp & reference is null");
return ;
}
arg2 = *(Fp **)&jarg2;
if (!arg2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Fp const & reference is null");
return ;
}
inv(*arg1,(Fp const &)*arg2);
}
SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_add_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jlong jarg3, jobject jarg3_) { SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_add_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jlong jarg3, jobject jarg3_) {
Fp *arg1 = 0 ; Fp *arg1 = 0 ;
Fp *arg2 = 0 ; Fp *arg2 = 0 ;
@ -1162,6 +1221,21 @@ SWIGEXPORT jboolean JNICALL Java_com_herumi_mcl_MclJNI_Fp_1isZero(JNIEnv *jenv,
} }
SWIGEXPORT jboolean JNICALL Java_com_herumi_mcl_MclJNI_Fp_1isOne(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jboolean jresult = 0 ;
Fp *arg1 = (Fp *) 0 ;
bool result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(Fp **)&jarg1;
result = (bool)((Fp const *)arg1)->isOne();
jresult = (jboolean)result;
return jresult;
}
SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_Fp_1setStr_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jint jarg3) { SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_Fp_1setStr_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jint jarg3) {
Fp *arg1 = (Fp *) 0 ; Fp *arg1 = (Fp *) 0 ;
std::string *arg2 = 0 ; std::string *arg2 = 0 ;
@ -2338,7 +2412,7 @@ SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_mul_1_1SWIG_14(JNIEnv *jenv,
} }
SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_inv(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) { SWIGEXPORT void JNICALL Java_com_herumi_mcl_MclJNI_inv_1_1SWIG_12(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
GT *arg1 = 0 ; GT *arg1 = 0 ;
GT *arg2 = 0 ; GT *arg2 = 0 ;

Loading…
Cancel
Save