Completed crypto auth and added tests
This commit is contained in:
1 parent
d2fda34807
commit
16cb5c2dee
6 files changed
+136
-37
No files matched your search
+53
-9
@@ -1,24 +1,49 @@
|
||||
package com.ionspin.kotlin.crypto.auth
|
||||
|
||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium
|
||||
|
||||
actual object Auth {
|
||||
actual fun authKeygen(): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
val generatedKey = UByteArray(crypto_auth_KEYBYTES)
|
||||
sodium.crypto_auth_keygen(generatedKey.asByteArray())
|
||||
return generatedKey
|
||||
}
|
||||
|
||||
actual fun auth(message: UByteArray, key: UByteArray): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
val mac = UByteArray(crypto_auth_BYTES)
|
||||
sodium.crypto_auth(
|
||||
mac.asByteArray(),
|
||||
message.asByteArray(),
|
||||
message.size.toLong(),
|
||||
key.asByteArray()
|
||||
)
|
||||
return mac
|
||||
}
|
||||
|
||||
actual fun authVerify(mac: UByteArray, message: UByteArray, key: UByteArray): Boolean {
|
||||
TODO("not implemented yet")
|
||||
return sodium.crypto_auth_verify(
|
||||
mac.asByteArray(),
|
||||
message.asByteArray(),
|
||||
message.size.toLong(),
|
||||
key.asByteArray()
|
||||
) == 0
|
||||
}
|
||||
|
||||
actual fun authHmacSha256Keygen(): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
val generatedKey = UByteArray(crypto_auth_hmacsha256_KEYBYTES)
|
||||
sodium.crypto_auth_hmacsha256_keygen(generatedKey.asByteArray())
|
||||
return generatedKey
|
||||
}
|
||||
|
||||
actual fun authHmacSha256(message: UByteArray, key: UByteArray): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
val mac = UByteArray(crypto_auth_hmacsha256_BYTES)
|
||||
sodium.crypto_auth_hmacsha256(
|
||||
mac.asByteArray(),
|
||||
message.asByteArray(),
|
||||
message.size.toLong(),
|
||||
key.asByteArray()
|
||||
)
|
||||
return mac
|
||||
}
|
||||
|
||||
actual fun authHmacSha256Verify(
|
||||
@@ -26,15 +51,29 @@ actual object Auth {
|
||||
message: UByteArray,
|
||||
key: UByteArray
|
||||
): Boolean {
|
||||
TODO("not implemented yet")
|
||||
return sodium.crypto_auth_hmacsha256_verify(
|
||||
mac.asByteArray(),
|
||||
message.asByteArray(),
|
||||
message.size.toLong(),
|
||||
key.asByteArray()
|
||||
) == 0
|
||||
}
|
||||
|
||||
actual fun authHmacSha512Keygen(): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
val generatedKey = UByteArray(crypto_auth_hmacsha512_KEYBYTES)
|
||||
sodium.crypto_auth_hmacsha512_keygen(generatedKey.asByteArray())
|
||||
return generatedKey
|
||||
}
|
||||
|
||||
actual fun authHmacSha512(message: UByteArray, key: UByteArray): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
val mac = UByteArray(crypto_auth_hmacsha512_BYTES)
|
||||
sodium.crypto_auth_hmacsha512(
|
||||
mac.asByteArray(),
|
||||
message.asByteArray(),
|
||||
message.size.toLong(),
|
||||
key.asByteArray()
|
||||
)
|
||||
return mac
|
||||
}
|
||||
|
||||
actual fun authHmacSha512Verify(
|
||||
@@ -42,7 +81,12 @@ actual object Auth {
|
||||
message: UByteArray,
|
||||
key: UByteArray
|
||||
): Boolean {
|
||||
TODO("not implemented yet")
|
||||
return sodium.crypto_auth_hmacsha512_verify(
|
||||
mac.asByteArray(),
|
||||
message.asByteArray(),
|
||||
message.size.toLong(),
|
||||
key.asByteArray()
|
||||
) == 0
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user