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

@@ -0,0 +1,27 @@
package com.ionspin.kotlin.crypto.generichash
import com.ionspin.kotlin.crypto.Initializer.sodium
/**
* 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 {
val hash = UByteArray(requestedHashLength)
sodium.crypto_generichash(
hash.asByteArray(),
requestedHashLength,
message.asByteArray(),
message.size.toLong(),
key?.asByteArray(),
(key?.size ?: 0)
)
return hash
}
}
@@ -121,7 +121,7 @@ actual class Crypto internal actual constructor() {
val m = UByteArray(c.size - 17)
var tag_p : UByte = 0U
println("Debug crypto_secretstream_xchacha20poly1305_pull")
sodium.crypto_secretstream_xchacha20poly1305_pull(state, m.asByteArray(), null, tag_p.toByte(),
sodium.crypto_secretstream_xchacha20poly1305_pull(state, m.asByteArray(), null, byteArrayOf(),
c.asByteArray(), c.size.toLong(), ad.asByteArray(), ad.size.toLong())
return debug.test.DecryptedDataAndTag(m, tag_p)
}