Added generichash keygen
This commit is contained in:
parent
16cb5c2dee
commit
1878144b8f
@ -6,6 +6,8 @@ package com.ionspin.kotlin.crypto.generichash
|
|||||||
* on 21-Aug-2020
|
* on 21-Aug-2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
val crypto_generichash_BYTES = 32
|
||||||
|
|
||||||
data class GenericHashState(val hashLength: Int, val internalState: GenericHashStateInternal)
|
data class GenericHashState(val hashLength: Int, val internalState: GenericHashStateInternal)
|
||||||
|
|
||||||
expect class GenericHashStateInternal
|
expect class GenericHashStateInternal
|
||||||
@ -18,6 +20,8 @@ expect object GenericHash {
|
|||||||
fun genericHashUpdate(state: GenericHashState, messagePart : UByteArray)
|
fun genericHashUpdate(state: GenericHashState, messagePart : UByteArray)
|
||||||
fun genericHashFinal(state : GenericHashState) : UByteArray
|
fun genericHashFinal(state : GenericHashState) : UByteArray
|
||||||
|
|
||||||
|
fun genericHashKeygen() : UByteArray
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ interface JsSodiumInterface {
|
|||||||
|
|
||||||
fun crypto_generichash_final(state: dynamic, hashLength: Int) : Uint8Array
|
fun crypto_generichash_final(state: dynamic, hashLength: Int) : Uint8Array
|
||||||
|
|
||||||
|
fun crypto_generichash_keygen() : Uint8Array
|
||||||
|
|
||||||
//Short hash
|
//Short hash
|
||||||
fun crypto_shorthash(data : Uint8Array, key: Uint8Array) : Uint8Array
|
fun crypto_shorthash(data : Uint8Array, key: Uint8Array) : Uint8Array
|
||||||
|
|
||||||
|
@ -44,4 +44,8 @@ actual object GenericHash {
|
|||||||
actual fun genericHashFinal(state: GenericHashState): UByteArray {
|
actual fun genericHashFinal(state: GenericHashState): UByteArray {
|
||||||
return getSodium().crypto_generichash_final(state.internalState, state.hashLength).toUByteArray()
|
return getSodium().crypto_generichash_final(state.internalState, state.hashLength).toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actual fun genericHashKeygen(): UByteArray {
|
||||||
|
return getSodium().crypto_generichash_keygen().toUByteArray()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,5 +49,11 @@ actual object GenericHash {
|
|||||||
return hashResult.asUByteArray()
|
return hashResult.asUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actual fun genericHashKeygen(): UByteArray {
|
||||||
|
val generatedKey = UByteArray(crypto_generichash_BYTES)
|
||||||
|
sodium.crypto_generichash_keygen(generatedKey.asByteArray())
|
||||||
|
return generatedKey
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import kotlinx.cinterop.reinterpret
|
|||||||
import libsodium.crypto_generichash
|
import libsodium.crypto_generichash
|
||||||
import libsodium.crypto_generichash_final
|
import libsodium.crypto_generichash_final
|
||||||
import libsodium.crypto_generichash_init
|
import libsodium.crypto_generichash_init
|
||||||
|
import libsodium.crypto_generichash_keygen
|
||||||
import libsodium.crypto_generichash_update
|
import libsodium.crypto_generichash_update
|
||||||
import platform.posix.malloc
|
import platform.posix.malloc
|
||||||
|
|
||||||
@ -88,5 +89,13 @@ actual object GenericHash {
|
|||||||
return hashResult
|
return hashResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actual fun genericHashKeygen(): UByteArray {
|
||||||
|
val generatedKey = UByteArray(crypto_generichash_BYTES)
|
||||||
|
val generatedKeyPinned = generatedKey.pin()
|
||||||
|
crypto_generichash_keygen(generatedKeyPinned.toPtr())
|
||||||
|
generatedKeyPinned.unpin()
|
||||||
|
return generatedKey
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
| crypto_generichash_blake2b_salt_personal | |
|
| crypto_generichash_blake2b_salt_personal | |
|
||||||
| crypto_generichash_final | :heavy_check_mark: |
|
| crypto_generichash_final | :heavy_check_mark: |
|
||||||
| crypto_generichash_init | :heavy_check_mark: |
|
| crypto_generichash_init | :heavy_check_mark: |
|
||||||
| crypto_generichash_keygen | |
|
| crypto_generichash_keygen | :heavy_check_mark: |
|
||||||
| crypto_generichash_update | :heavy_check_mark: |
|
| crypto_generichash_update | :heavy_check_mark: |
|
||||||
| crypto_hash | |
|
| crypto_hash | |
|
||||||
| crypto_hash_sha256 | |
|
| crypto_hash_sha256 | |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user