Skip to content

Commit a6a6ecd

Browse files
authored
Merge pull request #90 from phxql/develop
Version 2.11
2 parents 1b8bc8a + 6d8e693 commit a6a6ecd

File tree

17 files changed

+579
-46
lines changed

17 files changed

+579
-46
lines changed

.github/workflows/build-and-test.yml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@ on:
1111

1212

1313
jobs:
14-
buildon-linux:
14+
build-on-linux:
1515
strategy:
1616
matrix:
1717
os: [ ubuntu-latest ]
18-
# New gradle doesn't run on <= 8
19-
# Java >= 12 doesn't support source/target level 6 anymore
20-
java: [ 8, 9, 10, 11 ]
21-
architecture: [ x86, x64 ]
18+
# See CONTRIBUTING.md on JDK 11 build requirement
19+
java: [ '11' ]
20+
architecture: [ 'x64' ] # ubuntu-latest has no support for x86
21+
distribution: [ 'zulu', 'adopt' ]
2222
runs-on: ${{ matrix.os }}
2323
steps:
2424
- uses: actions/checkout@v2
2525
- name: Set up JDK ${{ matrix.java }}
26-
uses: actions/setup-java@v1
26+
uses: actions/setup-java@v2
2727
with:
2828
java-version: ${{ matrix.java }}
2929
architecture: ${{ matrix.architecture }}
30+
distribution: ${{ matrix.distribution }}
3031
- name: Cache Gradle packages
3132
uses: actions/cache@v2
3233
with:
@@ -41,19 +42,20 @@ jobs:
4142
strategy:
4243
matrix:
4344
os: [ macos-latest ]
44-
# New gradle doesn't run on <= 8
45-
# Java >= 12 doesn't support source/target level 6 anymore
46-
java: [ 8, 9, 10, 11 ]
45+
# See CONTRIBUTING.md on JDK 11 build requirement
46+
java: [ '11' ]
4747
# MacOS has no support for x86 ("Error: No valid download found for version 11.x and package jdk.")
48-
architecture: [ x64 ]
48+
architecture: [ 'x64' ]
49+
distribution: [ 'zulu', 'adopt' ]
4950
runs-on: ${{ matrix.os }}
5051
steps:
5152
- uses: actions/checkout@v2
5253
- name: Set up JDK ${{ matrix.java }}
53-
uses: actions/setup-java@v1
54+
uses: actions/setup-java@v2
5455
with:
5556
java-version: ${{ matrix.java }}
5657
architecture: ${{ matrix.architecture }}
58+
distribution: ${{ matrix.distribution }}
5759
- name: Cache Gradle packages
5860
uses: actions/cache@v2
5961
with:
@@ -68,10 +70,10 @@ jobs:
6870
strategy:
6971
matrix:
7072
os: [ windows-latest ]
71-
# New gradle doesn't run on <= 8
72-
# Java >= 12 doesn't support source/target level 6 anymore
73-
java: [ 8, 9, 10, 11 ]
74-
architecture: [ x86, x64 ]
73+
# See CONTRIBUTING.md on JDK 11 build requirement
74+
java: [ '11' ]
75+
architecture: [ 'x86', 'x64' ]
76+
distribution: [ 'zulu', 'adopt' ]
7577
runs-on: ${{ matrix.os }}
7678
steps:
7779
- uses: actions/checkout@v2
@@ -80,6 +82,7 @@ jobs:
8082
with:
8183
java-version: ${{ matrix.java }}
8284
architecture: ${{ matrix.architecture }}
85+
distribution: ${{ matrix.distribution }}
8386
- name: Cache Gradle packages
8487
uses: actions/cache@v2
8588
with:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [2.11] - 2021-10-02
6+
7+
### Added
8+
9+
* `argon2-jvm-nolibs` is now a multi-release JAR with a `module-info` file for Java >= 11. ([PR](https://github.com/phxql/argon2-jvm/pull/85))
10+
* Added support for context secrets and associated data ([PR](https://github.com/phxql/argon2-jvm/pull/86))
11+
512
## [2.10.1] - 2021-04-06
613

714
### Changed

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Contributing
22

33
Feel free to fork the project and create pull requests. Please use the `develop` branch for new features,
4-
I like to keep the `master` branch stable.
4+
I like to keep the `master` branch stable.
5+
6+
Note that JDK 11 is required to build. Older versions do not allow creating a Multi-Release JAR and
7+
newer versions do not support `--release 6`.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Without pre-compiled Argon2 libraries (recommended, install argon2 via your pack
1919
<dependency>
2020
<groupId>de.mkammerer</groupId>
2121
<artifactId>argon2-jvm-nolibs</artifactId>
22-
<version>2.10.1</version>
22+
<version>2.11</version>
2323
</dependency>
2424
```
2525

@@ -29,7 +29,7 @@ With pre-compiled Argon2 libraries:
2929
<dependency>
3030
<groupId>de.mkammerer</groupId>
3131
<artifactId>argon2-jvm</artifactId>
32-
<version>2.10.1</version>
32+
<version>2.11</version>
3333
</dependency>
3434
```
3535

@@ -38,13 +38,13 @@ With pre-compiled Argon2 libraries:
3838
Without pre-compiled Argon2 libraries (recommended, install argon2 via your package manager):
3939

4040
```groovy
41-
implementation 'de.mkammerer:argon2-jvm-nolibs:2.10.1'
41+
implementation 'de.mkammerer:argon2-jvm-nolibs:2.11'
4242
```
4343

4444
With pre-compiled Argon2 libraries:
4545

4646
```groovy
47-
implementation 'de.mkammerer:argon2-jvm:2.10.1'
47+
implementation 'de.mkammerer:argon2-jvm:2.11'
4848
```
4949

5050
## Usage

argon2-jvm-nolibs/build.gradle

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,42 @@ plugins {
22
id 'org.sonarqube' version '3.0'
33
}
44

5+
sourceSets {
6+
java11 {
7+
java {
8+
srcDirs = ['src/main/java', 'src/main/java11']
9+
}
10+
}
11+
}
12+
513
jar {
614
manifest {
715
attributes(
8-
'Automatic-Module-Name': 'de.mkammerer.argon2.nolibs'
16+
'Automatic-Module-Name': 'de.mkammerer.argon2.nolibs',
17+
'Multi-Release': 'true'
918
)
1019
}
20+
into('META-INF/versions/11') {
21+
from sourceSets.java11.output
22+
include('module-info.class')
23+
}
1124
}
1225

1326
dependencies {
1427
implementation 'net.java.dev.jna:jna:5.8.0'
1528
}
1629

30+
compileJava11Java {
31+
sourceCompatibility = 11
32+
targetCompatibility = 11
33+
options.compilerArgs.addAll([
34+
'--release', '11',
35+
'--module-path', sourceSets.main.compileClasspath.asPath,
36+
'--module-version', project.version]);
37+
}
38+
1739
sonarqube {
1840
properties {
1941
property 'sonar.exclusions', 'src/main/java/de/mkammerer/argon2/jna/*.java'
2042
}
21-
}
43+
}

argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2Advanced.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,71 @@ public interface Argon2Advanced extends Argon2 {
134134
*/
135135
HashResult hashAdvanced(int iterations, int memory, int parallelism, byte[] password, byte[] salt, int hashLength, Argon2Version version);
136136

137+
/**
138+
* Hashes a password, using the given salt, secret and associated data.
139+
*
140+
* @param iterations Number of iterations
141+
* @param memory Sets memory usage to x kibibytes
142+
* @param parallelism Number of threads and compute lanes
143+
* @param password Password to hash
144+
* @param charset Charset of the password
145+
* @param salt Salt
146+
* @param secret Secret (sometimes referred as Pepper)
147+
* @param associatedData Associated Data
148+
* @return Hashed password in raw bytes.
149+
*/
150+
byte[] rawHashAdvanced(int iterations, int memory, int parallelism, char[] password, Charset charset, byte[] salt, byte[] secret, byte[] associatedData);
151+
152+
/**
153+
* Advanced version of hash, let the caller specify addition parameters such as hash length, salt, secret and associated data.
154+
* Return both the encoded and the raw hash.
155+
*
156+
* @param iterations Number of iterations
157+
* @param memory Sets memory usage to x kibibytes
158+
* @param parallelism Number of threads and compute lanes
159+
* @param password Password to hash
160+
* @param salt Salt
161+
* @param secret Secret (sometimes referred as Pepper)
162+
* @param associatedData Associated Data
163+
* @param hashLength Length of the returned hash in bytes.
164+
* @param version Argon2 version
165+
* @return Hashed password in raw bytes.
166+
*/
167+
byte[] rawHashAdvanced(int iterations, int memory, int parallelism, byte[] password, byte[] salt, byte[] secret, byte[] associatedData, int hashLength, Argon2Version version);
168+
169+
/**
170+
* Verifies a password against a hash.
171+
*
172+
* @param iterations Number of iterations
173+
* @param memory Sets memory usage to x kibibytes
174+
* @param parallelism Number of threads and compute lanes
175+
* @param password Password to hash
176+
* @param charset Charset of the password
177+
* @param salt Salt
178+
* @param secret Secret (sometimes referred as Pepper)
179+
* @param associatedData Associated Data
180+
* @param rawHash Raw Hash bytes.
181+
* @return True if the password matches the hash, false otherwise.
182+
*/
183+
boolean verifyAdvanced(int iterations, int memory, int parallelism, char[] password, Charset charset, byte[] salt, byte[] secret, byte[] associatedData, byte[] rawHash);
184+
185+
/**
186+
* Verifies a password against a hash.
187+
*
188+
* @param iterations Number of iterations
189+
* @param memory Sets memory usage to x kibibytes
190+
* @param parallelism Number of threads and compute lanes
191+
* @param password Password to hash
192+
* @param salt Salt
193+
* @param secret Secret (sometimes referred as Pepper)
194+
* @param associatedData Associated Data
195+
* @param hashLength Length of the returned hash in bytes.
196+
* @param version Argon2 version
197+
* @param rawHash Raw Hash bytes.
198+
* @return True if the password matches the hash, false otherwise.
199+
*/
200+
boolean verifyAdvanced(int iterations, int memory, int parallelism, byte[] password, byte[] salt, byte[] secret, byte[] associatedData, int hashLength, Argon2Version version, byte[] rawHash);
201+
137202
/**
138203
* Generates salt with the default length.
139204
*
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
package de.mkammerer.argon2;
22

3+
import de.mkammerer.argon2.jna.Argon2_version;
4+
35
/**
46
* Version of the Argon2 algorithm.
57
*/
68
public enum Argon2Version {
79
V10(0x10),
8-
V13(0x13);
10+
V13(0x13),
11+
DEFAULT_VERSION(V13.version);
12+
13+
private final int version;
14+
private final Argon2_version jnaType;
915

10-
private final int jnaVersion;
16+
Argon2Version(int version) {
17+
this.version = version;
18+
this.jnaType = new Argon2_version(version);
19+
}
1120

12-
Argon2Version(int jnaVersion) {
13-
this.jnaVersion = jnaVersion;
21+
public Argon2_version getJnaType() {
22+
return jnaType;
1423
}
1524

16-
public int getJnaVersion() {
17-
return jnaVersion;
25+
public int getVersion() {
26+
return version;
1827
}
1928
}

argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2d.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.mkammerer.argon2;
22

33
import de.mkammerer.argon2.jna.Argon2Library;
4+
import de.mkammerer.argon2.jna.Argon2_context;
45
import de.mkammerer.argon2.jna.JnaUint32;
56
import de.mkammerer.argon2.jna.Size_t;
67

@@ -45,4 +46,14 @@ salt, new Size_t(salt.length), hash, new Size_t(hash.length)
4546
protected int callLibraryVerify(byte[] encoded, byte[] pwd) {
4647
return Argon2Library.INSTANCE.argon2d_verify(encoded, pwd, new Size_t(pwd.length));
4748
}
49+
50+
@Override
51+
protected int callLibraryContext(Argon2_context.ByReference context) {
52+
return Argon2Library.INSTANCE.argon2d_ctx(context);
53+
}
54+
55+
@Override
56+
protected int callLibraryVerifyContext(Argon2_context.ByReference context, byte[] rawHash) {
57+
return Argon2Library.INSTANCE.argon2d_verify_ctx(context, rawHash);
58+
}
4859
}

argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2i.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.mkammerer.argon2;
22

33
import de.mkammerer.argon2.jna.Argon2Library;
4+
import de.mkammerer.argon2.jna.Argon2_context;
45
import de.mkammerer.argon2.jna.JnaUint32;
56
import de.mkammerer.argon2.jna.Size_t;
67

@@ -45,4 +46,14 @@ salt, new Size_t(salt.length), hash, new Size_t(hash.length)
4546
protected int callLibraryVerify(byte[] encoded, byte[] pwd) {
4647
return Argon2Library.INSTANCE.argon2i_verify(encoded, pwd, new Size_t(pwd.length));
4748
}
49+
50+
@Override
51+
protected int callLibraryContext(Argon2_context.ByReference context) {
52+
return Argon2Library.INSTANCE.argon2i_ctx(context);
53+
}
54+
55+
@Override
56+
protected int callLibraryVerifyContext(Argon2_context.ByReference context, byte[] rawHash) {
57+
return Argon2Library.INSTANCE.argon2i_verify_ctx(context, rawHash);
58+
}
4859
}

argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2id.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.mkammerer.argon2;
22

33
import de.mkammerer.argon2.jna.Argon2Library;
4+
import de.mkammerer.argon2.jna.Argon2_context;
45
import de.mkammerer.argon2.jna.JnaUint32;
56
import de.mkammerer.argon2.jna.Size_t;
67

@@ -45,4 +46,14 @@ salt, new Size_t(salt.length), hash, new Size_t(hash.length)
4546
protected int callLibraryVerify(byte[] encoded, byte[] pwd) {
4647
return Argon2Library.INSTANCE.argon2id_verify(encoded, pwd, new Size_t(pwd.length));
4748
}
49+
50+
@Override
51+
protected int callLibraryContext(Argon2_context.ByReference context) {
52+
return Argon2Library.INSTANCE.argon2id_ctx(context);
53+
}
54+
55+
@Override
56+
protected int callLibraryVerifyContext(Argon2_context.ByReference context, byte[] rawHash) {
57+
return Argon2Library.INSTANCE.argon2id_verify_ctx(context, rawHash);
58+
}
4859
}

0 commit comments

Comments
 (0)