Skip to content

Commit

Permalink
Merge pull request #3 from Zylquinal/java-21
Browse files Browse the repository at this point in the history
java 21
  • Loading branch information
Zylquinal authored Sep 30, 2023
2 parents 312ac5f + 3c11836 commit f39421f
Show file tree
Hide file tree
Showing 25 changed files with 1,893 additions and 2,452 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: 'Set up JDK 20'
- name: 'Set up JDK 21'
uses: oracle-actions/setup-java@v1
with:
website: jdk.java.net
release: 20
release: 21
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ plugins {
}

group 'com.zylquinal.argon2'
version '2.1-SNAPSHOT'
version '2.1.1-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.jetbrains:annotations:23.0.0'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'de.mkammerer:argon2-jvm:2.11'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-rc-3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jdk:
- openjdk20
- openjdk21
15 changes: 7 additions & 8 deletions src/main/java/com/zylquinal/argon2/api/ArgonDirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
public class ArgonDirect {

public static byte[] rawHash(byte @NotNull [] password, byte @NotNull [] salt, @NotNull ArgonConfig argonConfig) {
try (Arena arena = Arena.openConfined()) {
MemorySegment hashPtr = MemorySegment.allocateNative(argonConfig.hashLength(), arena.scope());
MemorySegment passwordPtr = MemorySegment.allocateNative(password.length, arena.scope());
try (Arena arena = Arena.ofConfined()) {
MemorySegment hashPtr = arena.allocate(argonConfig.hashLength());
MemorySegment passwordPtr = arena.allocate(password.length);
for (int i = 0; i < password.length; i++) {
passwordPtr.set(ValueLayout.JAVA_BYTE, i, password[i]);
}

MemorySegment saltPtr = MemorySegment.allocateNative(salt.length, arena.scope());
MemorySegment saltPtr = arena.allocate(salt.length);
for (int i = 0; i < salt.length; i++) {
saltPtr.set(ValueLayout.JAVA_BYTE, i, salt[i]);
}
Expand Down Expand Up @@ -72,13 +72,12 @@ public static byte[] rawHash(byte @NotNull [] password, byte @NotNull [] salt, b
*/
public static byte[] rawHash(byte @NotNull [] password, byte @NotNull [] salt, byte[] secret, byte[] associatedData, int hashLength,
int memoryCost, int parallelism, int iterations, @NotNull ArgonVersion version, @NotNull ArgonFlag flag, @NotNull ArgonVariant variant) {
try (Arena arena = Arena.openConfined()) {
MemorySegment struct = Argon2_Context.layout(password, salt, secret, associatedData, hashLength, memoryCost, parallelism, iterations, version, flag, arena.scope());
try (Arena arena = Arena.ofConfined()) {
MemorySegment struct = Argon2_Context.layout(password, salt, secret, associatedData, hashLength, memoryCost, parallelism, iterations, version, flag, arena);
MemorySegment outAddress = Argon2_Context.out$get(struct);
MemorySegment out = MemorySegment.ofAddress(outAddress.address(), hashLength, arena.scope());
int result = argon2_h.argon2_ctx(struct, variant.variant());
if (result != 0) throw new ArgonException(ArgonStatus.of(result));
return out.toArray(ValueLayout.OfByte.JAVA_BYTE);
return outAddress.asSlice(0, hashLength).toArray(ValueLayout.OfByte.JAVA_BYTE);
}
}

Expand Down
Loading

0 comments on commit f39421f

Please sign in to comment.