Handle ULong -> UInt conversions, update api to reflect stream_chacha20_ietf takes UInt for initial counter

This commit is contained in:
Ugljesa Jovanovic committed 2022-03-25 12:47:22 +01:00
1 parent ce868fc598
commit cd3ec109a3
8 files changed
+27 -9

No files matched your search

@@ -22,6 +22,9 @@ actual object PasswordHash {
memLimit: Int,
algorithm: Int
): UByteArray {
if (opsLimit > UInt.MAX_VALUE) {
throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit")
}
return getSodium().crypto_pwhash(
outputLength,
password.encodeToUByteArray().toUInt8Array(),
@@ -43,6 +46,9 @@ actual object PasswordHash {
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
if (opslimit > UInt.MAX_VALUE) {
throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit")
}
return getSodium().crypto_pwhash_str(
password.encodeToUByteArray().toUInt8Array(),
opslimit.toInt(), // TODO check this narrowing
@@ -61,6 +67,9 @@ actual object PasswordHash {
opslimit: ULong,
memlimit: Int
): Int {
if (opslimit > UInt.MAX_VALUE) {
throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit")
}
return if (
getSodium().crypto_pwhash_str_needs_rehash(
passwordHash.asByteArray().decodeToString(),
@@ -29,10 +29,9 @@ actual object Stream {
actual fun chacha20IetfXorIc(
message: UByteArray,
nonce: UByteArray,
initialCounter: ULong,
initialCounter: UInt,
key: UByteArray
): UByteArray {
val result = getSodium().crypto_stream_chacha20_ietf_xor_ic(
message.toUInt8Array(),
nonce.toUInt8Array(),
@@ -69,6 +68,9 @@ actual object Stream {
initialCounter: ULong,
key: UByteArray
): UByteArray {
if (initialCounter > UInt.MAX_VALUE) {
throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for initial counter")
}
val result = getSodium().crypto_stream_chacha20_xor_ic(
message.toUInt8Array(),
nonce.toUInt8Array(),