Adding secret stream impl, completed generichash impl

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-26 22:15:03 +02:00
1 parent 6f38a01195
commit 39f0817308
9 files changed
+162 -63

No files matched your search

@@ -0,0 +1,47 @@
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 typealias GenericHashStateInternal = Any
actual object GenericHash {
actual fun genericHash(
message: UByteArray,
requestedHashLength: Int,
key: UByteArray?
): UByteArray {
return getSodium().crypto_generichash(
requestedHashLength,
message.toUInt8Array(),
key?.toUInt8Array() ?: Uint8Array(0)
).toUByteArray()
}
actual fun genericHashInit(
requestedHashLength: Int,
key: UByteArray?
): GenericHashState {
val state = getSodium().crypto_generichash_init(key.toUInt8Array(), requestedHashLength)
return GenericHashState(requestedHashLength, state)
}
actual fun genericHashUpdate(
state: GenericHashState,
messagePart: UByteArray
) {
getSodium().crypto_generichash_update(state.internalState, messagePart.toUInt8Array())
}
actual fun genericHashFinal(state: GenericHashState): UByteArray {
return getSodium().crypto_generichash_final(state.internalState, state.hashLength).toUByteArray()
}
}
@@ -1,25 +0,0 @@
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()
}
}