Add stateless implementation
This commit is contained in:
1 parent
3a81d8e57c
commit
710ac43e8c
9 files changed
+66
-11
No files matched your search
+2
@@ -9,6 +9,8 @@ import org.khronos.webgl.Uint8Array
|
||||
*/
|
||||
interface JsSodiumInterface {
|
||||
|
||||
fun crypto_hash_sha256(message: Uint8Array) : Uint8Array
|
||||
|
||||
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array
|
||||
|
||||
fun randombytes_buf(numberOfBytes: Int) : Uint8Array
|
||||
|
||||
+14
-1
@@ -1,5 +1,9 @@
|
||||
package com.ionspin.kotlin.crypto.hash.sha
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegatedStateless
|
||||
import org.khronos.webgl.Uint8Array
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
@@ -25,6 +29,15 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In
|
||||
actual object Sha256StatelessDelegated : StatelessSha256 {
|
||||
|
||||
override fun digest(inputMessage: UByteArray): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
val hashed = getSodium().crypto_hash_sha256(Uint8Array(inputMessage.toByteArray().toTypedArray()))
|
||||
val hash = UByteArray(MAX_HASH_BYTES)
|
||||
for (i in 0 until MAX_HASH_BYTES) {
|
||||
js(
|
||||
"""
|
||||
hash[i] = hashed[i]
|
||||
"""
|
||||
)
|
||||
}
|
||||
return hash
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,7 @@ import kotlin.js.Promise
|
||||
@JsName("ready")
|
||||
external val _libsodiumPromise : Promise<dynamic>
|
||||
|
||||
external fun crypto_generichash(hashLength: Int, inputMessage: String) : String
|
||||
external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array
|
||||
|
||||
Reference in new issue
Block a user