Added jvm and js implementation for sha256/512

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-31 20:56:36 +02:00
1 parent 15be707114
commit 1894a5d995
6 files changed
+131 -64

No files matched your search

@@ -23,16 +23,17 @@ actual typealias Sha256State = crypto_hash_sha256_state
actual typealias Sha512State = crypto_hash_sha512_state
actual object Hash {
actual fun hash(data: UByteArray): UByteArray {
val hashResult = UByteArray(crypto_hash_BYTES)
val hashResultPinned = hashResult.pin()
val dataPinned = data.pin()
crypto_hash(hashResultPinned.toPtr(), dataPinned.toPtr(), data.size.convert())
hashResultPinned.unpin()
dataPinned.unpin()
return hashResult
}
//Not present in Lazy Sodium
// actual fun hash(data: UByteArray): UByteArray {
// val hashResult = UByteArray(crypto_hash_BYTES)
// val hashResultPinned = hashResult.pin()
// val dataPinned = data.pin()
// crypto_hash(hashResultPinned.toPtr(), dataPinned.toPtr(), data.size.convert())
// hashResultPinned.unpin()
// dataPinned.unpin()
//
// return hashResult
// }
actual fun sha256(data: UByteArray): UByteArray {
val hashResult = UByteArray(crypto_hash_sha256_BYTES)