Adding pwhash native and tests

This commit is contained in:
Ugljesa Jovanovic committed 2020-09-21 19:07:06 +02:00
1 parent 65bf54765f
commit 2b4d8aa4b1
4 files changed
+110 -29

No files matched your search

@@ -7,25 +7,25 @@ package com.ionspin.kotlin.crypto.pwhash
const val crypto_pwhash_BYTES_MIN = 16U
const val crypto_pwhash_MEMLIMIT_INTERACTIVE = 67108864U
const val crypto_pwhash_MEMLIMIT_MIN = 8192U
const val crypto_pwhash_MEMLIMIT_MODERATE = 268435456U
const val crypto_pwhash_MEMLIMIT_SENSITIVE = 1073741824U
const val crypto_pwhash_OPSLIMIT_INTERACTIVE = 2U
const val crypto_pwhash_OPSLIMIT_MAX = 4294967295U
const val crypto_pwhash_OPSLIMIT_MIN = 1U
const val crypto_pwhash_OPSLIMIT_MODERATE = 3U
const val crypto_pwhash_OPSLIMIT_SENSITIVE = 4U
const val crypto_pwhash_PASSWD_MAX = 4294967295U
const val crypto_pwhash_PASSWD_MIN = 0U
const val crypto_pwhash_SALTBYTES = 16U
const val crypto_pwhash_STRBYTES = 128U
const val crypto_pwhash_MEMLIMIT_MIN = 8192
const val crypto_pwhash_MEMLIMIT_MODERATE = 268435456
const val crypto_pwhash_MEMLIMIT_SENSITIVE = 1073741824
const val crypto_pwhash_OPSLIMIT_INTERACTIVE = 2
const val crypto_pwhash_OPSLIMIT_MAX = 4294967295UL
const val crypto_pwhash_OPSLIMIT_MIN = 1UL
const val crypto_pwhash_OPSLIMIT_MODERATE = 3UL
const val crypto_pwhash_OPSLIMIT_SENSITIVE = 4UL
const val crypto_pwhash_PASSWD_MAX = 4294967295
const val crypto_pwhash_PASSWD_MIN = 0
const val crypto_pwhash_SALTBYTES = 16
const val crypto_pwhash_STRBYTES = 128
const val crypto_pwhash_STRPREFIX = "\$argon2id$"
val crypto_pwhash_argon2id_ALG_ARGON2ID13 = 2
val crypto_pwhash_argon2i_ALG_ARGON2I13 = 1
val crypto_pwhash_ALG_DEFAULT = crypto_pwhash_argon2id_ALG_ARGON2ID13
class PasswordHashFailed() : RuntimeException("Password hashing failed")
class PasswordHashingFailed() : RuntimeException("Password hashing failed")
expect object PasswordHash {
/**
@@ -55,7 +55,7 @@ expect object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
fun str(password: String, opslimit: ULong, memlimit: Int): String
fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray
/**
* Check if a password verification string str matches the parameters opslimit and memlimit, and the current default algorithm.
@@ -63,6 +63,13 @@ expect object PasswordHash {
* The function returns 0 if the parameters already match the given ones.
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
fun strNeedsRehash(password: String, opslimit: ULong, memlimit: Int): Boolean
fun strVerify(passwordHash: String, password: UByteArray): Boolean
}
fun strNeedsRehash(passwordHash: UByteArray, opslimit: ULong, memlimit: Int): Int
/**
* his function verifies that str is a valid password verification string (as generated by crypto_pwhash_str()) for passwd whose length is passwdlen.
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
fun strVerify(passwordHash: UByteArray, password: String): Boolean
}