Added auth jna

This commit is contained in:
Ugljesa Jovanovic 2021-02-21 21:50:21 +01:00
parent 531deb6a57
commit f0511e0ff1
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
2 changed files with 92 additions and 41 deletions

View File

@ -144,6 +144,7 @@ interface JnaLibsodiumInterface : Library {
base64End: Pointer?,
variant: Int
): Int
// size_t sodium_base64_encoded_len(const size_t bin_len, const int variant)
fun sodium_base64_encoded_len(binLength: Int, variant: Int): Int
@ -694,6 +695,7 @@ interface JnaLibsodiumInterface : Library {
nonce: ByteArray,
key: ByteArray
): Int
// int crypto_secretbox_open_easy(
// unsigned char *m, const unsigned char *c,
// unsigned long long clen, const unsigned char *n,
@ -706,19 +708,68 @@ interface JnaLibsodiumInterface : Library {
key: ByteArray
): Int
// // ---- SecretBox End ----
// ---- SecretBox 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 ----
// int crypto_auth(unsigned char *out, const unsigned char *in,
// unsigned long long inlen, const unsigned char *k)
fun crypto_auth(
out: ByteArray,
input: ByteArray,
inputLength: Long,
key: ByteArray
): Int
// void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES])
fun crypto_auth_keygen(key: ByteArray)
// int crypto_auth_verify(const unsigned char *h, const unsigned char *in,
// unsigned long long inlen, const unsigned char *k)
fun crypto_auth_verify(
hash: ByteArray,
input: ByteArray,
inputLength: Long,
key: ByteArray
): Int
//Same params as general variant
fun crypto_auth_hmacsha256(
out: ByteArray,
input: ByteArray,
inputLength: Long,
key: ByteArray
): Int
//Same params as general variant
fun crypto_auth_hmacsha256_keygen(key: ByteArray)
//Same params as general variant
fun crypto_auth_hmacsha256_verify(
hash: ByteArray,
input: ByteArray,
inputLength: Long,
key: ByteArray
): Int
//Same params as general variant
fun crypto_auth_hmacsha512(
out: ByteArray,
input: ByteArray,
inputLength: Long,
key: ByteArray
): Int
//Same params as general variant
fun crypto_auth_hmacsha512_keygen(key: ByteArray)
//Same params as general variant
fun crypto_auth_hmacsha512_verify(
hash: ByteArray,
input: ByteArray,
inputLength: Long,
key: ByteArray
): Int
//
// // ---- Auth end ----
//

View File

@ -1,17 +1,17 @@
package com.ionspin.kotlin.crypto.auth
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
actual object Auth {
actual fun authKeygen(): UByteArray {
val generatedKey = UByteArray(crypto_auth_KEYBYTES)
sodium.crypto_auth_keygen(generatedKey.asByteArray())
sodiumJna.crypto_auth_keygen(generatedKey.asByteArray())
return generatedKey
}
actual fun auth(message: UByteArray, key: UByteArray): UByteArray {
val mac = UByteArray(crypto_auth_BYTES)
sodium.crypto_auth(
sodiumJna.crypto_auth(
mac.asByteArray(),
message.asByteArray(),
message.size.toLong(),
@ -21,7 +21,7 @@ actual object Auth {
}
actual fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray): Boolean {
return sodium.crypto_auth_verify(
return sodiumJna.crypto_auth_verify(
tag.asByteArray(),
message.asByteArray(),
message.size.toLong(),
@ -31,13 +31,13 @@ actual object Auth {
actual fun authHmacSha256Keygen(): UByteArray {
val generatedKey = UByteArray(crypto_auth_hmacsha256_KEYBYTES)
sodium.crypto_auth_hmacsha256_keygen(generatedKey.asByteArray())
sodiumJna.crypto_auth_hmacsha256_keygen(generatedKey.asByteArray())
return generatedKey
}
actual fun authHmacSha256(message: UByteArray, key: UByteArray): UByteArray {
val mac = UByteArray(crypto_auth_hmacsha256_BYTES)
sodium.crypto_auth_hmacsha256(
sodiumJna.crypto_auth_hmacsha256(
mac.asByteArray(),
message.asByteArray(),
message.size.toLong(),
@ -51,7 +51,7 @@ actual object Auth {
message: UByteArray,
key: UByteArray
): Boolean {
return sodium.crypto_auth_hmacsha256_verify(
return sodiumJna.crypto_auth_hmacsha256_verify(
tag.asByteArray(),
message.asByteArray(),
message.size.toLong(),
@ -61,13 +61,13 @@ actual object Auth {
actual fun authHmacSha512Keygen(): UByteArray {
val generatedKey = UByteArray(crypto_auth_hmacsha512_KEYBYTES)
sodium.crypto_auth_hmacsha512_keygen(generatedKey.asByteArray())
sodiumJna.crypto_auth_hmacsha512_keygen(generatedKey.asByteArray())
return generatedKey
}
actual fun authHmacSha512(message: UByteArray, key: UByteArray): UByteArray {
val mac = UByteArray(crypto_auth_hmacsha512_BYTES)
sodium.crypto_auth_hmacsha512(
sodiumJna.crypto_auth_hmacsha512(
mac.asByteArray(),
message.asByteArray(),
message.size.toLong(),
@ -81,7 +81,7 @@ actual object Auth {
message: UByteArray,
key: UByteArray
): Boolean {
return sodium.crypto_auth_hmacsha512_verify(
return sodiumJna.crypto_auth_hmacsha512_verify(
tag.asByteArray(),
message.asByteArray(),
message.size.toLong(),