Skip to content

Commit

Permalink
Merge pull request #30 from cryptimeleon/develop
Browse files Browse the repository at this point in the history
Release of new version
  • Loading branch information
feidens authored Sep 21, 2021
2 parents 32ba556 + 7c2b7f6 commit d7d006e
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 23 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -90,15 +91,15 @@ To add the newest Mclwrap version as a dependency, add this to your project's PO
<dependency>
<groupId>org.cryptimeleon</groupId>
<artifactId>mclwrap</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>
</dependency>
```

### Adding Mclwrap Dependency With Gradle

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:

Expand All @@ -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'
}
```

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,10 +20,9 @@ tasks.withType(JavaCompile) {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}

def mathVersionNoSuffix = '2.0.0'
def mathVersionNoSuffix = '3.0.0'

dependencies {

Expand Down
13 changes: 8 additions & 5 deletions install_mcl.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
mcl_version="v1.26"
mcl_version="5faedff92a72a685d4e6c94e1974ec2033b9d352"
# exit immediately on error
set -e

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/herumi/mcl/Fp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/herumi/mcl/Fr.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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); }

}
24 changes: 24 additions & 0 deletions src/main/java/com/herumi/mcl/G1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

}
4 changes: 4 additions & 0 deletions src/main/java/com/herumi/mcl/G2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
10 changes: 9 additions & 1 deletion src/main/java/com/herumi/mcl/Mcl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

}
1 change: 1 addition & 0 deletions src/main/java/com/herumi/mcl/MclConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 14 additions & 1 deletion src/main/java/com/herumi/mcl/MclJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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);
Expand All @@ -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_);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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_);
Expand All @@ -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_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d7d006e

Please sign in to comment.