parent
17d2b0c18d
commit
24be4c8de1
@ -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); |
||||
} |
||||
|
||||
} |
@ -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); |
||||
} |
@ -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…
Reference in new issue