Interface PwHash.Native

All Known Implementing Classes:
LazySodium, LazySodiumJava
Enclosing interface:
PwHash

public static interface PwHash.Native
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    cryptoPwHash(byte[] outputHash, int outputHashLen, byte[] password, int passwordLen, byte[] salt, long opsLimit, com.sun.jna.NativeLong memLimit, PwHash.Alg alg)
    Based on a password you provide, hash that password and put the output into outputHash.
    boolean
    cryptoPwHashStr(byte[] outputStr, byte[] password, int passwordLen, long opsLimit, com.sun.jna.NativeLong memLimit)
    Hashes a password and stores it into an array.
    boolean
    cryptoPwHashStrNeedsRehash(byte[] hash, long opsLimit, com.sun.jna.NativeLong memLimit)
    Checks whether the hash needs a rehash.
    boolean
    cryptoPwHashStrVerify(byte[] hash, byte[] password, int passwordLen)
    Verifies a hashed password.
  • Method Details

    • cryptoPwHash

      boolean cryptoPwHash(byte[] outputHash, int outputHashLen, byte[] password, int passwordLen, byte[] salt, long opsLimit, com.sun.jna.NativeLong memLimit, PwHash.Alg alg)
      Based on a password you provide, hash that password and put the output into outputHash. Take note that the output of this does NOT output a traditional Argon 2 string as the underlying native implementation calls argon2id_hash_raw instead of argon2id_hash_encoded. If you want an Argon 2 encoded string please refer to cryptoPwHashStr(byte[], byte[], int, long, NativeLong) instead.
      Parameters:
      outputHash - Where to store the resulting password hash.
      outputHashLen - The password hash's length. Must be at least PwHash.BYTES_MIN.
      password - The password that you want to hash.
      passwordLen - The length of the password's bytes.
      salt - A salt that's randomly generated.
      opsLimit - The number of cycles to perform whilst hashing. Between PwHash.OPSLIMIT_MIN and PwHash.OPSLIMIT_MAX.
      memLimit - The amount of memory to use. Between PwHash.MEMLIMIT_MIN and PwHash.MEMLIMIT_MAX.
      alg - The algorithm to use. Please use PwHash.Alg.PWHASH_ALG_ARGON2ID13 for now.
      Returns:
      True if the hash succeeded.
    • cryptoPwHashStr

      boolean cryptoPwHashStr(byte[] outputStr, byte[] password, int passwordLen, long opsLimit, com.sun.jna.NativeLong memLimit)
      Hashes a password and stores it into an array. The output is an ASCII encoded string in a byte array.
      Parameters:
      outputStr - An array to hold the hash. Must be at least PwHash.STR_BYTES.
      password - A password that you want to hash.
      passwordLen - The password's byte length.
      opsLimit - The number of cycles to perform whilst hashing. Between PwHash.OPSLIMIT_MIN and PwHash.OPSLIMIT_MAX.
      memLimit - The amount of memory to use. Between PwHash.MEMLIMIT_MIN and PwHash.MEMLIMIT_MAX.
      Returns:
      True if the hash succeeded.
      See Also:
    • cryptoPwHashStrVerify

      boolean cryptoPwHashStrVerify(byte[] hash, byte[] password, int passwordLen)
      Verifies a hashed password. Remember: you must add a null byte to the end of the hash so that this works properly!
      Parameters:
      hash - The hash of the password.
      password - The password to check if it equals the hash's password.
      passwordLen - The checking password's length.
      Returns:
      True if the password matches the unhashed hash.
    • cryptoPwHashStrNeedsRehash

      boolean cryptoPwHashStrNeedsRehash(byte[] hash, long opsLimit, com.sun.jna.NativeLong memLimit)
      Checks whether the hash needs a rehash.
      Parameters:
      hash - The hash.
      opsLimit - The operations limit used.
      memLimit - The memory limit used.
      Returns:
      True if the hash needs to be rehashed.