Skip to content

Commit

Permalink
Merge pull request #90 from phxql/develop
Browse files Browse the repository at this point in the history
Version 2.11
  • Loading branch information
phxql authored Oct 2, 2021
2 parents 1b8bc8a + 6d8e693 commit a6a6ecd
Show file tree
Hide file tree
Showing 17 changed files with 579 additions and 46 deletions.
33 changes: 18 additions & 15 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ on:


jobs:
buildon-linux:
build-on-linux:
strategy:
matrix:
os: [ ubuntu-latest ]
# New gradle doesn't run on <= 8
# Java >= 12 doesn't support source/target level 6 anymore
java: [ 8, 9, 10, 11 ]
architecture: [ x86, x64 ]
# See CONTRIBUTING.md on JDK 11 build requirement
java: [ '11' ]
architecture: [ 'x64' ] # ubuntu-latest has no support for x86
distribution: [ 'zulu', 'adopt' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
architecture: ${{ matrix.architecture }}
distribution: ${{ matrix.distribution }}
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand All @@ -41,19 +42,20 @@ jobs:
strategy:
matrix:
os: [ macos-latest ]
# New gradle doesn't run on <= 8
# Java >= 12 doesn't support source/target level 6 anymore
java: [ 8, 9, 10, 11 ]
# See CONTRIBUTING.md on JDK 11 build requirement
java: [ '11' ]
# MacOS has no support for x86 ("Error: No valid download found for version 11.x and package jdk.")
architecture: [ x64 ]
architecture: [ 'x64' ]
distribution: [ 'zulu', 'adopt' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
architecture: ${{ matrix.architecture }}
distribution: ${{ matrix.distribution }}
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand All @@ -68,10 +70,10 @@ jobs:
strategy:
matrix:
os: [ windows-latest ]
# New gradle doesn't run on <= 8
# Java >= 12 doesn't support source/target level 6 anymore
java: [ 8, 9, 10, 11 ]
architecture: [ x86, x64 ]
# See CONTRIBUTING.md on JDK 11 build requirement
java: [ '11' ]
architecture: [ 'x86', 'x64' ]
distribution: [ 'zulu', 'adopt' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand All @@ -80,6 +82,7 @@ jobs:
with:
java-version: ${{ matrix.java }}
architecture: ${{ matrix.architecture }}
distribution: ${{ matrix.distribution }}
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

## [2.11] - 2021-10-02

### Added

* `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))
* Added support for context secrets and associated data ([PR](https://github.com/phxql/argon2-jvm/pull/86))

## [2.10.1] - 2021-04-06

### Changed
Expand Down
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Contributing

Feel free to fork the project and create pull requests. Please use the `develop` branch for new features,
I like to keep the `master` branch stable.
I like to keep the `master` branch stable.

Note that JDK 11 is required to build. Older versions do not allow creating a Multi-Release JAR and
newer versions do not support `--release 6`.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Without pre-compiled Argon2 libraries (recommended, install argon2 via your pack
<dependency>
<groupId>de.mkammerer</groupId>
<artifactId>argon2-jvm-nolibs</artifactId>
<version>2.10.1</version>
<version>2.11</version>
</dependency>
```

Expand All @@ -29,7 +29,7 @@ With pre-compiled Argon2 libraries:
<dependency>
<groupId>de.mkammerer</groupId>
<artifactId>argon2-jvm</artifactId>
<version>2.10.1</version>
<version>2.11</version>
</dependency>
```

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

```groovy
implementation 'de.mkammerer:argon2-jvm-nolibs:2.10.1'
implementation 'de.mkammerer:argon2-jvm-nolibs:2.11'
```

With pre-compiled Argon2 libraries:

```groovy
implementation 'de.mkammerer:argon2-jvm:2.10.1'
implementation 'de.mkammerer:argon2-jvm:2.11'
```

## Usage
Expand Down
26 changes: 24 additions & 2 deletions argon2-jvm-nolibs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,42 @@ plugins {
id 'org.sonarqube' version '3.0'
}

sourceSets {
java11 {
java {
srcDirs = ['src/main/java', 'src/main/java11']
}
}
}

jar {
manifest {
attributes(
'Automatic-Module-Name': 'de.mkammerer.argon2.nolibs'
'Automatic-Module-Name': 'de.mkammerer.argon2.nolibs',
'Multi-Release': 'true'
)
}
into('META-INF/versions/11') {
from sourceSets.java11.output
include('module-info.class')
}
}

dependencies {
implementation 'net.java.dev.jna:jna:5.8.0'
}

compileJava11Java {
sourceCompatibility = 11
targetCompatibility = 11
options.compilerArgs.addAll([
'--release', '11',
'--module-path', sourceSets.main.compileClasspath.asPath,
'--module-version', project.version]);
}

sonarqube {
properties {
property 'sonar.exclusions', 'src/main/java/de/mkammerer/argon2/jna/*.java'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,71 @@ public interface Argon2Advanced extends Argon2 {
*/
HashResult hashAdvanced(int iterations, int memory, int parallelism, byte[] password, byte[] salt, int hashLength, Argon2Version version);

/**
* Hashes a password, using the given salt, secret and associated data.
*
* @param iterations Number of iterations
* @param memory Sets memory usage to x kibibytes
* @param parallelism Number of threads and compute lanes
* @param password Password to hash
* @param charset Charset of the password
* @param salt Salt
* @param secret Secret (sometimes referred as Pepper)
* @param associatedData Associated Data
* @return Hashed password in raw bytes.
*/
byte[] rawHashAdvanced(int iterations, int memory, int parallelism, char[] password, Charset charset, byte[] salt, byte[] secret, byte[] associatedData);

/**
* Advanced version of hash, let the caller specify addition parameters such as hash length, salt, secret and associated data.
* Return both the encoded and the raw hash.
*
* @param iterations Number of iterations
* @param memory Sets memory usage to x kibibytes
* @param parallelism Number of threads and compute lanes
* @param password Password to hash
* @param salt Salt
* @param secret Secret (sometimes referred as Pepper)
* @param associatedData Associated Data
* @param hashLength Length of the returned hash in bytes.
* @param version Argon2 version
* @return Hashed password in raw bytes.
*/
byte[] rawHashAdvanced(int iterations, int memory, int parallelism, byte[] password, byte[] salt, byte[] secret, byte[] associatedData, int hashLength, Argon2Version version);

/**
* Verifies a password against a hash.
*
* @param iterations Number of iterations
* @param memory Sets memory usage to x kibibytes
* @param parallelism Number of threads and compute lanes
* @param password Password to hash
* @param charset Charset of the password
* @param salt Salt
* @param secret Secret (sometimes referred as Pepper)
* @param associatedData Associated Data
* @param rawHash Raw Hash bytes.
* @return True if the password matches the hash, false otherwise.
*/
boolean verifyAdvanced(int iterations, int memory, int parallelism, char[] password, Charset charset, byte[] salt, byte[] secret, byte[] associatedData, byte[] rawHash);

/**
* Verifies a password against a hash.
*
* @param iterations Number of iterations
* @param memory Sets memory usage to x kibibytes
* @param parallelism Number of threads and compute lanes
* @param password Password to hash
* @param salt Salt
* @param secret Secret (sometimes referred as Pepper)
* @param associatedData Associated Data
* @param hashLength Length of the returned hash in bytes.
* @param version Argon2 version
* @param rawHash Raw Hash bytes.
* @return True if the password matches the hash, false otherwise.
*/
boolean verifyAdvanced(int iterations, int memory, int parallelism, byte[] password, byte[] salt, byte[] secret, byte[] associatedData, int hashLength, Argon2Version version, byte[] rawHash);

/**
* Generates salt with the default length.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package de.mkammerer.argon2;

import de.mkammerer.argon2.jna.Argon2_version;

/**
* Version of the Argon2 algorithm.
*/
public enum Argon2Version {
V10(0x10),
V13(0x13);
V13(0x13),
DEFAULT_VERSION(V13.version);

private final int version;
private final Argon2_version jnaType;

private final int jnaVersion;
Argon2Version(int version) {
this.version = version;
this.jnaType = new Argon2_version(version);
}

Argon2Version(int jnaVersion) {
this.jnaVersion = jnaVersion;
public Argon2_version getJnaType() {
return jnaType;
}

public int getJnaVersion() {
return jnaVersion;
public int getVersion() {
return version;
}
}
11 changes: 11 additions & 0 deletions argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2d.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.mkammerer.argon2;

import de.mkammerer.argon2.jna.Argon2Library;
import de.mkammerer.argon2.jna.Argon2_context;
import de.mkammerer.argon2.jna.JnaUint32;
import de.mkammerer.argon2.jna.Size_t;

Expand Down Expand Up @@ -45,4 +46,14 @@ salt, new Size_t(salt.length), hash, new Size_t(hash.length)
protected int callLibraryVerify(byte[] encoded, byte[] pwd) {
return Argon2Library.INSTANCE.argon2d_verify(encoded, pwd, new Size_t(pwd.length));
}

@Override
protected int callLibraryContext(Argon2_context.ByReference context) {
return Argon2Library.INSTANCE.argon2d_ctx(context);
}

@Override
protected int callLibraryVerifyContext(Argon2_context.ByReference context, byte[] rawHash) {
return Argon2Library.INSTANCE.argon2d_verify_ctx(context, rawHash);
}
}
11 changes: 11 additions & 0 deletions argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2i.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.mkammerer.argon2;

import de.mkammerer.argon2.jna.Argon2Library;
import de.mkammerer.argon2.jna.Argon2_context;
import de.mkammerer.argon2.jna.JnaUint32;
import de.mkammerer.argon2.jna.Size_t;

Expand Down Expand Up @@ -45,4 +46,14 @@ salt, new Size_t(salt.length), hash, new Size_t(hash.length)
protected int callLibraryVerify(byte[] encoded, byte[] pwd) {
return Argon2Library.INSTANCE.argon2i_verify(encoded, pwd, new Size_t(pwd.length));
}

@Override
protected int callLibraryContext(Argon2_context.ByReference context) {
return Argon2Library.INSTANCE.argon2i_ctx(context);
}

@Override
protected int callLibraryVerifyContext(Argon2_context.ByReference context, byte[] rawHash) {
return Argon2Library.INSTANCE.argon2i_verify_ctx(context, rawHash);
}
}
11 changes: 11 additions & 0 deletions argon2-jvm-nolibs/src/main/java/de/mkammerer/argon2/Argon2id.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.mkammerer.argon2;

import de.mkammerer.argon2.jna.Argon2Library;
import de.mkammerer.argon2.jna.Argon2_context;
import de.mkammerer.argon2.jna.JnaUint32;
import de.mkammerer.argon2.jna.Size_t;

Expand Down Expand Up @@ -45,4 +46,14 @@ salt, new Size_t(salt.length), hash, new Size_t(hash.length)
protected int callLibraryVerify(byte[] encoded, byte[] pwd) {
return Argon2Library.INSTANCE.argon2id_verify(encoded, pwd, new Size_t(pwd.length));
}

@Override
protected int callLibraryContext(Argon2_context.ByReference context) {
return Argon2Library.INSTANCE.argon2id_ctx(context);
}

@Override
protected int callLibraryVerifyContext(Argon2_context.ByReference context, byte[] rawHash) {
return Argon2Library.INSTANCE.argon2id_verify_ctx(context, rawHash);
}
}
Loading

0 comments on commit a6a6ecd

Please sign in to comment.