de.mkammerer.argon2.Argon2d Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of argon2-jvm Show documentation
Show all versions of argon2-jvm Show documentation
Argon2 Binding for the JVM
package de.mkammerer.argon2;
import de.mkammerer.argon2.jna.Argon2Library;
import de.mkammerer.argon2.jna.JnaUint32;
import de.mkammerer.argon2.jna.Size_t;
/**
* Argon2i password hashing function.
*
* This class is thread safe.
*/
class Argon2d extends BaseArgon2 {
/**
* Constructor.
*
* @param defaultSaltLength Default salt length in bytes. Can be overridden by some methods.
* @param defaultHashLength Default hash length in bytes. Can be overridden by some methods.
*/
Argon2d(int defaultSaltLength, int defaultHashLength) {
super(defaultSaltLength, defaultHashLength);
}
@Override
public final Argon2Factory.Argon2Types getType() {
return Argon2Factory.Argon2Types.ARGON2d;
}
@Override
protected int callLibraryHash(byte[] pwd, byte[] salt, JnaUint32 iterations, JnaUint32 memory, JnaUint32 parallelism, byte[] encoded) {
return Argon2Library.INSTANCE.argon2d_hash_encoded(
iterations, memory, parallelism, pwd, new Size_t(pwd.length),
salt, new Size_t(salt.length), new Size_t(getDefaultHashLength()), encoded, new Size_t(encoded.length)
);
}
@Override
protected int callLibraryRawHash(byte[] pwd, byte[] salt, JnaUint32 iterations, JnaUint32 memory, JnaUint32 parallelism, byte[] hash) {
return Argon2Library.INSTANCE.argon2d_hash_raw(
iterations, memory, parallelism, pwd, new Size_t(pwd.length),
salt, new Size_t(salt.length), hash, new Size_t(hash.length)
);
}
@Override
protected int callLibraryVerify(byte[] encoded, byte[] pwd) {
return Argon2Library.INSTANCE.argon2d_verify(encoded, pwd, new Size_t(pwd.length));
}
}