diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d34a03..acf9972 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.0.0] + +### Changed +- Replace getInteger with asInteger [#30](https://github.com/cryptimeleon/mclwrap/pull/30/commits/5bcc7a64b1550c33d889f02b14d44f5bdcf014cb) +- Increment Math dependency version to 3.0.0 + +## [2.0.0] - 2021-06-29 + ### Fixed - Fixed serialization of `MclBilinearGroup` returning "bn256" instead of the correct "bn254" which lead to deserialization not working - ### Changed - Made most of the mcl wrapper classes package-private @@ -20,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial release -[Unreleased]: https://github.com/cryptimeleon/mclwrap/compare/v1.0.0...HEAD +[Unreleased]: https://github.com/cryptimeleon/mclwrap/compare/v3.0.0...HEAD +[3.0.0]: https://github.com/cryptimeleon/mclwrap/compare/v2.0.0...v3.0.0 +[2.0.0]: https://github.com/cryptimeleon/mclwrap/compare/v1.0.0...v2.0.0 [1.0.0]: https://github.com/cryptimeleon/mclwrap/releases/tag/v1.0.0 diff --git a/README.md b/README.md index 5673d77..6d022f7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Build Status](https://github.com/cryptimeleon/mclwrap/workflows/Development%20Java%20CI/badge.svg) -![Build Status](https://github.com/cryptimeleon/mclwrap/workflows/Release%20Java%20CI/badge.svg) -![Build Status](https://github.com/cryptimeleon/mclwrap/workflows/Scheduled%20Release%20Java%20CI/badge.svg) +![Build Status](https://github.com/cryptimeleon/mclwrap/workflows/Main%20Java%20CI/badge.svg) +![Build Status](https://github.com/cryptimeleon/mclwrap/workflows/Scheduled%20Main%20Java%20CI/badge.svg) # Mclwrap Mclwrap provides a wrapper around the BN-254 bilinear group implemented in the [MCL library](https://github.com/herumi/mcl). As the bilinear groups implemented in the Cryptimeleon Math library are not particulary efficient, use of this wrapper is recommended for proper benchmarks. @@ -30,8 +30,9 @@ We give a more detailed tutorial below. #### Linux/Mac OS You can peform most of the installation automatically by using the `install_mcl.sh` script contained in this directory. -It will compile the mcl library (version v1.26) as well as the Java bindings, and move the shared library to the correct library folder. +It will compile the mcl library (version v1.28) as well as the Java bindings, and move the shared library to the correct library folder. As a prerequisite, you need to have the `libgmp-dev` package installed. +You will also need `make` and `g++` (or `clang++` if using FreeBSD or OpenBSD). Additionally, you may have to make the script executable by executing `chmod +x install_mcl.sh` before execution. The `install_mcl.sh` script takes the `include` path of your Java JVM as its only argument. @@ -51,12 +52,12 @@ The below commands are executed in the Developer Command Prompt for VS 2019 sinc Before you start with the actual installation, you need to make sure that x64 is selected as target architecure in the Command Prompt. For VS 2017 or later, this is done by executing `vcvarsall.bat x64` in the `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\` folder (replace with your Visual Studio location). For VS 2015, the batch file will be in `C:\Program Files (x86)\Microsoft Visual Studio 15.0\VC\` instead. -Now, we need to clone [Mcl](https://github.com/herumi/mcl) and [Cybozu_ext](https://github.com/herumi/cybozulib_ext). The repositories need to be in the same folder. Furthermore, we need to ensure that the correct version of Mcl is checked out. We currently use version v1.26. +Now, we need to clone [Mcl](https://github.com/herumi/mcl) and [Cybozu_ext](https://github.com/herumi/cybozulib_ext). The repositories need to be in the same folder. Furthermore, we need to ensure that the correct version of Mcl is checked out. We currently use version v1.28. ``` git clone https://github.com/herumi/mcl.git git clone https://github.com/herumi/cybozulib_ext.git cd mcl -git checkout v1.26 +git checkout v1.28 ``` Next, we build Mcl: @@ -90,7 +91,7 @@ To add the newest Mclwrap version as a dependency, add this to your project's PO org.cryptimeleon mclwrap - 2.0.0 + 3.0.0 ``` @@ -98,7 +99,7 @@ To add the newest Mclwrap version as a dependency, add this to your project's PO Mclwrap is published via Maven Central. Therefore, you need to add `mavenCentral()` to the `repositories` section of your project's `build.gradle` file. -Then, add `implementation group: 'org.cryptimeleon', name: 'mclwrap', version: '2.0.0'` to the `dependencies` section of your `build.gradle` file. +Then, add `implementation group: 'org.cryptimeleon', name: 'mclwrap', version: '3.0.0'` to the `dependencies` section of your `build.gradle` file. For example: @@ -108,7 +109,7 @@ repositories { } dependencies { - implementation group: 'org.cryptimeleon', name: 'mclwrap', version: '2.0.0' + implementation group: 'org.cryptimeleon', name: 'mclwrap', version: '3.0.0' } ``` diff --git a/build.gradle b/build.gradle index aa49c06..51a549b 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,8 @@ plugins { group 'org.cryptimeleon' archivesBaseName = project.name boolean isRelease = project.hasProperty("release") -version = '2.0.0' + (isRelease ? "" : "-SNAPSHOT") +version = '3.0.0' + (isRelease ? "" : "-SNAPSHOT") + sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -19,10 +20,9 @@ tasks.withType(JavaCompile) { repositories { mavenLocal() mavenCentral() - jcenter() } -def mathVersionNoSuffix = '2.0.0' +def mathVersionNoSuffix = '3.0.0' dependencies { diff --git a/install_mcl.sh b/install_mcl.sh index 40a59e7..3c59324 100755 --- a/install_mcl.sh +++ b/install_mcl.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -mcl_version="v1.26" +mcl_version="5faedff92a72a685d4e6c94e1974ec2033b9d352" # exit immediately on error set -e @@ -10,18 +10,21 @@ if [ "$(uname)" == "Darwin" ]; then elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then os="linux" else - echo "Unsupported operating system. This script only works on Linux and Mac OS." + echo "Unsupported operating system. This script only works on Linux and macOS." exit 2 fi # check that JAVA_INC is given if [ $# -eq 0 ]; then echo "Missing Java include argument" - echo "Please give path of Java include folder as first argument" + echo "Please specify path of your JDK 'include' directory as first argument" if [ $os == "linux" ]; then - echo "For example: /usr/lib/jvm/java-8-openjdk-amd64/include" + echo "For example: ./install_mcl.sh /usr/lib/jvm/java-8-openjdk-amd64/include" else # mac os - echo "For example: /Library/Java/JavaVirtualMachines/openjdk-13.0.1.jdk/Contents/Home/include" + echo "For example: ./install_mcl.sh /Library/Java/JavaVirtualMachines/openjdk-13.0.1.jdk/Contents/Home/include" + echo "For your system, it's probably: " + javahome=$(/usr/libexec/java_home) + echo ./install_mcl.sh $javahome/include fi exit 1 fi diff --git a/src/main/java/com/herumi/mcl/Fp.java b/src/main/java/com/herumi/mcl/Fp.java index 5d50e98..2b39ffd 100644 --- a/src/main/java/com/herumi/mcl/Fp.java +++ b/src/main/java/com/herumi/mcl/Fp.java @@ -64,6 +64,10 @@ public boolean isZero() { return MclJNI.Fp_isZero(swigCPtr, this); } + public boolean isOne() { + return MclJNI.Fp_isOne(swigCPtr, this); + } + public void setStr(String str, int base) { MclJNI.Fp_setStr__SWIG_0(swigCPtr, this, str, base); } diff --git a/src/main/java/com/herumi/mcl/Fr.java b/src/main/java/com/herumi/mcl/Fr.java index 8ed95df..b26d001 100644 --- a/src/main/java/com/herumi/mcl/Fr.java +++ b/src/main/java/com/herumi/mcl/Fr.java @@ -64,6 +64,10 @@ public boolean isZero() { return MclJNI.Fr_isZero(swigCPtr, this); } + public boolean isOne() { + return MclJNI.Fr_isOne(swigCPtr, this); + } + public void setStr(String str, int base) { MclJNI.Fr_setStr__SWIG_0(swigCPtr, this, str, base); } @@ -96,6 +100,14 @@ public void deserialize(byte[] cbuf) { MclJNI.Fr_deserialize(swigCPtr, this, cbuf); } + public void setLittleEndianMod(byte[] cbuf) { + MclJNI.Fr_setLittleEndianMod(swigCPtr, this, cbuf); + } + + public void setHashOf(byte[] cbuf) { + MclJNI.Fr_setHashOf(swigCPtr, this, cbuf); + } + public byte[] serialize() { return MclJNI.Fr_serialize(swigCPtr, this); } } diff --git a/src/main/java/com/herumi/mcl/G1.java b/src/main/java/com/herumi/mcl/G1.java index d46e3f1..0d34b80 100644 --- a/src/main/java/com/herumi/mcl/G1.java +++ b/src/main/java/com/herumi/mcl/G1.java @@ -56,6 +56,10 @@ public boolean isZero() { return MclJNI.G1_isZero(swigCPtr, this); } + public boolean isValidOrder() { + return MclJNI.G1_isValidOrder(swigCPtr, this); + } + public void set(Fp x, Fp y) { MclJNI.G1_set(swigCPtr, this, Fp.getCPtr(x), x, Fp.getCPtr(y), y); } @@ -86,4 +90,24 @@ public void deserialize(byte[] cbuf) { public byte[] serialize() { return MclJNI.G1_serialize(swigCPtr, this); } + public void normalize() { + MclJNI.G1_normalize(swigCPtr, this); + } + + public void tryAndIncMapTo(Fp x) { + MclJNI.G1_tryAndIncMapTo(swigCPtr, this, Fp.getCPtr(x), x); + } + + public Fp getX() { + return new Fp(MclJNI.G1_getX(swigCPtr, this), true); + } + + public Fp getY() { + return new Fp(MclJNI.G1_getY(swigCPtr, this), true); + } + + public Fp getZ() { + return new Fp(MclJNI.G1_getZ(swigCPtr, this), true); + } + } diff --git a/src/main/java/com/herumi/mcl/G2.java b/src/main/java/com/herumi/mcl/G2.java index aed241e..a626bdc 100644 --- a/src/main/java/com/herumi/mcl/G2.java +++ b/src/main/java/com/herumi/mcl/G2.java @@ -86,4 +86,8 @@ public void deserialize(byte[] cbuf) { public byte[] serialize() { return MclJNI.G2_serialize(swigCPtr, this); } + public void normalize() { + MclJNI.G2_normalize(swigCPtr, this); + } + } diff --git a/src/main/java/com/herumi/mcl/Mcl.java b/src/main/java/com/herumi/mcl/Mcl.java index 8074e39..502a661 100644 --- a/src/main/java/com/herumi/mcl/Mcl.java +++ b/src/main/java/com/herumi/mcl/Mcl.java @@ -17,6 +17,10 @@ public static void neg(Fr y, Fr 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) { MclJNI.add__SWIG_0(Fr.getCPtr(z), z, Fr.getCPtr(x), x, Fr.getCPtr(y), y); } @@ -49,6 +53,10 @@ public static void neg(Fp y, Fp 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) { MclJNI.add__SWIG_1(Fp.getCPtr(z), z, Fp.getCPtr(x), x, Fp.getCPtr(y), y); } @@ -114,7 +122,7 @@ public static void mul(GT z, GT x, GT y) { } 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); } } diff --git a/src/main/java/com/herumi/mcl/MclConstants.java b/src/main/java/com/herumi/mcl/MclConstants.java index 8068eca..2f3d238 100644 --- a/src/main/java/com/herumi/mcl/MclConstants.java +++ b/src/main/java/com/herumi/mcl/MclConstants.java @@ -11,4 +11,5 @@ public interface MclConstants { public final static int BN254 = 0; public final static int BLS12_381 = 5; + public final static int SECP256K1 = 102; } diff --git a/src/main/java/com/herumi/mcl/MclJNI.java b/src/main/java/com/herumi/mcl/MclJNI.java index 24e34cf..025d29d 100644 --- a/src/main/java/com/herumi/mcl/MclJNI.java +++ b/src/main/java/com/herumi/mcl/MclJNI.java @@ -11,6 +11,7 @@ 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 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 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_); @@ -25,6 +26,7 @@ public class MclJNI { 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_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_1(long jarg1, Fr jarg1_, String jarg2); public final static native void Fr_setInt(long jarg1, Fr jarg1_, int jarg2); @@ -33,9 +35,12 @@ public class MclJNI { 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 Fr_setLittleEndianMod(long jarg1, Fr jarg1_, byte[] jarg2); + public final static native void Fr_setHashOf(long jarg1, Fr jarg1_, byte[] jarg2); 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 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 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_); @@ -47,6 +52,7 @@ public class MclJNI { 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_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_1(long jarg1, Fp jarg1_, String jarg2); public final static native void Fp_setInt(long jarg1, Fp jarg1_, int jarg2); @@ -68,6 +74,7 @@ public class MclJNI { 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 boolean G1_isZero(long jarg1, G1 jarg1_); + public final static native boolean G1_isValidOrder(long jarg1, G1 jarg1_); 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); @@ -76,6 +83,11 @@ public class MclJNI { 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 byte[] G1_serialize(long jarg1, G1 jarg1_); + public final static native void G1_normalize(long jarg1, G1 jarg1_); + public final static native void G1_tryAndIncMapTo(long jarg1, G1 jarg1_, long jarg2, Fp jarg2_); + public final static native long G1_getX(long jarg1, G1 jarg1_); + public final static native long G1_getY(long jarg1, G1 jarg1_); + public final static native long G1_getZ(long jarg1, G1 jarg1_); 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_); @@ -95,9 +107,10 @@ public class MclJNI { 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 byte[] G2_serialize(long jarg1, G2 jarg1_); + public final static native void G2_normalize(long jarg1, G2 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 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_1(long jarg1, GT jarg1_); public final static native boolean GT_equals(long jarg1, GT jarg1_, long jarg2, GT jarg2_); diff --git a/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroup1ElementImpl.java b/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroup1ElementImpl.java index 8dcf1a8..2c30eef 100644 --- a/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroup1ElementImpl.java +++ b/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroup1ElementImpl.java @@ -54,7 +54,7 @@ public MclGroup1ElementImpl pow(BigInteger k) { public MclGroup1ElementImpl pow(Zn.ZnElement k) { G1 res = new G1(); - Fr exponent = new Fr(k.getInteger().toString()); + Fr exponent = new Fr(k.asInteger().toString()); Mcl.mul(res, getElement(), exponent); return getStructure().createElement(res); } diff --git a/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroup2ElementImpl.java b/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroup2ElementImpl.java index 6a00a9a..6e15a06 100644 --- a/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroup2ElementImpl.java +++ b/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroup2ElementImpl.java @@ -54,7 +54,7 @@ public MclGroup2ElementImpl pow(BigInteger k) { public MclGroup2ElementImpl pow(Zn.ZnElement k) { G2 res = new G2(); - Fr exponent = new Fr(k.getInteger().toString()); + Fr exponent = new Fr(k.asInteger().toString()); Mcl.mul(res, getElement(), exponent); return getStructure().createElement(res); } diff --git a/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroupTElementImpl.java b/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroupTElementImpl.java index 164db27..1fd0e4c 100644 --- a/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroupTElementImpl.java +++ b/src/main/java/org/cryptimeleon/mclwrap/bn254/MclGroupTElementImpl.java @@ -51,7 +51,7 @@ public MclGroupTElementImpl pow(BigInteger k) { public MclGroupTElementImpl pow(Zn.ZnElement k) { GT res = new GT(); - Fr exponent = new Fr(k.getInteger().toString()); + Fr exponent = new Fr(k.asInteger().toString()); Mcl.pow(res, getElement(), exponent); return getStructure().createElement(res); }