Completed crypto auth and added tests

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-30 19:02:40 +02:00
1 parent d2fda34807
commit 16cb5c2dee
6 files changed
+136 -37

No files matched your search

@@ -91,6 +91,20 @@ interface JsSodiumInterface {
// ---- AEAD end ----
// ---- Auth ----
fun crypto_auth(message: Uint8Array, key: Uint8Array) : Uint8Array
fun crypto_auth_keygen() : Uint8Array
fun crypto_auth_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean
fun crypto_auth_hmacsha256(message: Uint8Array, key: Uint8Array) : Uint8Array
fun crypto_auth_hmacsha256_keygen() : Uint8Array
fun crypto_auth_hmacsha256_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean
fun crypto_auth_hmacsha512(message: Uint8Array, key: Uint8Array) : Uint8Array
fun crypto_auth_hmacsha512_keygen() : Uint8Array
fun crypto_auth_hmacsha512_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean
// ---- Auth end ----
//util
fun memzero(array: Uint8Array)
@@ -1,24 +1,40 @@
package com.ionspin.kotlin.crypto.auth
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
actual object Auth {
actual fun authKeygen(): UByteArray {
TODO("not implemented yet")
return getSodium().crypto_auth_keygen().toUByteArray()
}
actual fun auth(message: UByteArray, key: UByteArray): UByteArray {
TODO("not implemented yet")
return getSodium().crypto_auth(
message.toUInt8Array(),
key.toUInt8Array()
).toUByteArray()
}
actual fun authVerify(mac: UByteArray, message: UByteArray, key: UByteArray): Boolean {
TODO("not implemented yet")
return getSodium().crypto_auth_verify(
mac.toUInt8Array(),
message.toUInt8Array(),
key.toUInt8Array()
)
}
actual fun authHmacSha256Keygen(): UByteArray {
TODO("not implemented yet")
return getSodium().crypto_auth_hmacsha256_keygen().toUByteArray()
}
actual fun authHmacSha256(message: UByteArray, key: UByteArray): UByteArray {
TODO("not implemented yet")
return getSodium().crypto_auth_hmacsha256(
message.toUInt8Array(),
key.toUInt8Array()
).toUByteArray()
}
actual fun authHmacSha256Verify(
@@ -26,15 +42,22 @@ actual object Auth {
message: UByteArray,
key: UByteArray
): Boolean {
TODO("not implemented yet")
return getSodium().crypto_auth_hmacsha256_verify(
mac.toUInt8Array(),
message.toUInt8Array(),
key.toUInt8Array()
)
}
actual fun authHmacSha512Keygen(): UByteArray {
TODO("not implemented yet")
return getSodium().crypto_auth_hmacsha512_keygen().toUByteArray()
}
actual fun authHmacSha512(message: UByteArray, key: UByteArray): UByteArray {
TODO("not implemented yet")
return getSodium().crypto_auth_hmacsha512(
message.toUInt8Array(),
key.toUInt8Array()
).toUByteArray()
}
actual fun authHmacSha512Verify(
@@ -42,7 +65,11 @@ actual object Auth {
message: UByteArray,
key: UByteArray
): Boolean {
TODO("not implemented yet")
return getSodium().crypto_auth_hmacsha512_verify(
mac.toUInt8Array(),
message.toUInt8Array(),
key.toUInt8Array()
)
}
}