Added generic hash

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-21 19:21:40 +02:00
1 parent 6a6119dec1
commit 92058a7ba5
11 files changed
+218 -91

No files matched your search

@@ -12,7 +12,7 @@ interface JsSodiumInterface {
fun randombytes_buf(numberOfBytes: Int): Uint8Array
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array,): Uint8Array
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
fun crypto_hash_sha256(message: Uint8Array): Uint8Array
@@ -57,4 +57,5 @@ interface JsSodiumInterface {
}
@@ -0,0 +1,25 @@
package com.ionspin.kotlin.crypto.generichash
import com.ionspin.kotlin.crypto.getSodium
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
import org.khronos.webgl.Uint8Array
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 21-Aug-2020
*/
actual object GenericHashing {
actual fun genericHash(
message: UByteArray,
requestedHashLength: Int,
key: UByteArray?
): UByteArray {
return getSodium().crypto_generichash(
requestedHashLength,
message.toUInt8Array(),
key?.toUInt8Array() ?: Uint8Array(0)
).toUByteArray()
}
}
@@ -70,7 +70,7 @@ actual class Crypto internal actual constructor() {
getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
val state = stateAndHeader.state
val header = (stateAndHeader.header as Uint8Array).toUByteArray()
return SecretStreamStateAndHeader(state, header)
return SecretStreamStateAndHeader(state, header)
}
/**
@@ -104,9 +104,10 @@ actual class Crypto internal actual constructor() {
state: SecretStreamState,
c: UByteArray,
ad: UByteArray
): UByte {
): DecryptedDataAndTag {
println("Debug crypto_secretstream_xchacha20poly1305_pull")
return getSodium().crypto_secretstream_xchacha20poly1305_pull(state, c.toUInt8Array(),
ad.toUInt8Array())
// return getSodium().crypto_secretstream_xchacha20poly1305_pull(state, c.toUInt8Array(),
// ad.toUInt8Array())
return DecryptedDataAndTag(ubyteArrayOf(), 0U)
}
}