Added auth jna
This commit is contained in:
parent
531deb6a57
commit
f0511e0ff1
@ -72,7 +72,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun sodium_memzero(array: ByteArray, len: Int)
|
fun sodium_memzero(array: ByteArray, len: Int)
|
||||||
|
|
||||||
// int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len)
|
// int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len)
|
||||||
fun sodium_memcmp(b1 : ByteArray, b2 : ByteArray, len: Int) : Int
|
fun sodium_memcmp(b1: ByteArray, b2: ByteArray, len: Int): Int
|
||||||
|
|
||||||
// char *sodium_bin2hex(char * const hex, const size_t hex_maxlen,
|
// char *sodium_bin2hex(char * const hex, const size_t hex_maxlen,
|
||||||
// const unsigned char * const bin, const size_t bin_len)
|
// const unsigned char * const bin, const size_t bin_len)
|
||||||
@ -80,8 +80,8 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
hex: ByteArray,
|
hex: ByteArray,
|
||||||
hexMaxlen: Int,
|
hexMaxlen: Int,
|
||||||
bin: ByteArray,
|
bin: ByteArray,
|
||||||
binLen : Int
|
binLen: Int
|
||||||
) : String
|
): String
|
||||||
|
|
||||||
// int sodium_hex2bin(
|
// int sodium_hex2bin(
|
||||||
// unsigned char * const bin, const size_t bin_maxlen,
|
// unsigned char * const bin, const size_t bin_maxlen,
|
||||||
@ -96,17 +96,17 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ignore: ByteArray?,
|
ignore: ByteArray?,
|
||||||
binLen: Pointer,
|
binLen: Pointer,
|
||||||
hexEnd: Pointer?
|
hexEnd: Pointer?
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// int sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
|
// int sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
|
||||||
// size_t unpadded_buflen, size_t blocksize, size_t max_buflen)
|
// size_t unpadded_buflen, size_t blocksize, size_t max_buflen)
|
||||||
fun sodium_pad(
|
fun sodium_pad(
|
||||||
paddedBufferLength : Pointer,
|
paddedBufferLength: Pointer,
|
||||||
buffer: ByteArray,
|
buffer: ByteArray,
|
||||||
unpaddedBufferLength : Int,
|
unpaddedBufferLength: Int,
|
||||||
blockSize: Int,
|
blockSize: Int,
|
||||||
maxBufferLength: Int
|
maxBufferLength: Int
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
|
// int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
|
||||||
// size_t padded_buflen, size_t blocksize)
|
// size_t padded_buflen, size_t blocksize)
|
||||||
@ -127,7 +127,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
bin: ByteArray,
|
bin: ByteArray,
|
||||||
binLength: Int,
|
binLength: Int,
|
||||||
variant: Int
|
variant: Int
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// int sodium_base642bin(
|
// int sodium_base642bin(
|
||||||
// unsigned char * const bin, const size_t bin_maxlen,
|
// unsigned char * const bin, const size_t bin_maxlen,
|
||||||
@ -135,7 +135,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
// const char * const ignore, size_t * const bin_len,
|
// const char * const ignore, size_t * const bin_len,
|
||||||
// const char ** const b64_end, const int variant)
|
// const char ** const b64_end, const int variant)
|
||||||
fun sodium_base642bin(
|
fun sodium_base642bin(
|
||||||
bin : ByteArray,
|
bin: ByteArray,
|
||||||
binMaxLength: Int,
|
binMaxLength: Int,
|
||||||
base64: ByteArray,
|
base64: ByteArray,
|
||||||
base64Length: Int,
|
base64Length: Int,
|
||||||
@ -143,9 +143,10 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
binLength: Pointer,
|
binLength: Pointer,
|
||||||
base64End: Pointer?,
|
base64End: Pointer?,
|
||||||
variant: Int
|
variant: Int
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// size_t sodium_base64_encoded_len(const size_t bin_len, const int variant)
|
// size_t sodium_base64_encoded_len(const size_t bin_len, const int variant)
|
||||||
fun sodium_base64_encoded_len(binLength: Int, variant: Int) : Int
|
fun sodium_base64_encoded_len(binLength: Int, variant: Int): Int
|
||||||
|
|
||||||
// --- Utils end ----
|
// --- Utils end ----
|
||||||
|
|
||||||
@ -576,7 +577,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
// ---- Secret stream -----
|
// ---- Secret stream -----
|
||||||
|
|
||||||
// crypto_secretstream_xchacha20poly1305_headerbytes
|
// crypto_secretstream_xchacha20poly1305_headerbytes
|
||||||
fun crypto_secretstream_xchacha20poly1305_headerbytes() : Int
|
fun crypto_secretstream_xchacha20poly1305_headerbytes(): Int
|
||||||
|
|
||||||
//encrypt
|
//encrypt
|
||||||
|
|
||||||
@ -616,7 +617,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
state: SecretStreamXChaCha20Poly1305State,
|
state: SecretStreamXChaCha20Poly1305State,
|
||||||
header: ByteArray,
|
header: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// int crypto_secretstream_xchacha20poly1305_pull
|
// int crypto_secretstream_xchacha20poly1305_pull
|
||||||
// (crypto_secretstream_xchacha20poly1305_state *state,
|
// (crypto_secretstream_xchacha20poly1305_state *state,
|
||||||
@ -632,13 +633,13 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long
|
additionalDataLength: Long
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
//keygen and rekey
|
//keygen and rekey
|
||||||
|
|
||||||
// void crypto_secretstream_xchacha20poly1305_keygen
|
// void crypto_secretstream_xchacha20poly1305_keygen
|
||||||
// (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])
|
// (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])
|
||||||
fun crypto_secretstream_xchacha20poly1305_keygen(key : ByteArray)
|
fun crypto_secretstream_xchacha20poly1305_keygen(key: ByteArray)
|
||||||
|
|
||||||
// void crypto_secretstream_xchacha20poly1305_rekey
|
// void crypto_secretstream_xchacha20poly1305_rekey
|
||||||
// (crypto_secretstream_xchacha20poly1305_state *state)
|
// (crypto_secretstream_xchacha20poly1305_state *state)
|
||||||
@ -662,7 +663,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// int crypto_secretbox_easy(
|
// int crypto_secretbox_easy(
|
||||||
// unsigned char *c, const unsigned char *m,
|
// unsigned char *c, const unsigned char *m,
|
||||||
@ -674,7 +675,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES])
|
// void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES])
|
||||||
fun crypto_secretbox_keygen(key: ByteArray)
|
fun crypto_secretbox_keygen(key: ByteArray)
|
||||||
@ -693,7 +694,8 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// int crypto_secretbox_open_easy(
|
// int crypto_secretbox_open_easy(
|
||||||
// unsigned char *m, const unsigned char *c,
|
// unsigned char *m, const unsigned char *c,
|
||||||
// unsigned long long clen, const unsigned char *n,
|
// unsigned long long clen, const unsigned char *n,
|
||||||
@ -704,21 +706,70 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray
|
||||||
) : Int
|
): Int
|
||||||
|
|
||||||
// // ---- SecretBox End ----
|
// ---- SecretBox End ----
|
||||||
|
|
||||||
// // ---- Auth ----
|
// ---- Auth ----
|
||||||
//
|
|
||||||
// fun crypto_auth(message: Uint8Array, key: Uint8Array) : Uint8Array
|
// int crypto_auth(unsigned char *out, const unsigned char *in,
|
||||||
// fun crypto_auth_keygen() : Uint8Array
|
// unsigned long long inlen, const unsigned char *k)
|
||||||
// fun crypto_auth_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean
|
fun crypto_auth(
|
||||||
// fun crypto_auth_hmacsha256(message: Uint8Array, key: Uint8Array) : Uint8Array
|
out: ByteArray,
|
||||||
// fun crypto_auth_hmacsha256_keygen() : Uint8Array
|
input: ByteArray,
|
||||||
// fun crypto_auth_hmacsha256_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean
|
inputLength: Long,
|
||||||
// fun crypto_auth_hmacsha512(message: Uint8Array, key: Uint8Array) : Uint8Array
|
key: ByteArray
|
||||||
// fun crypto_auth_hmacsha512_keygen() : Uint8Array
|
): Int
|
||||||
// fun crypto_auth_hmacsha512_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean
|
|
||||||
|
// 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 ----
|
// // ---- Auth end ----
|
||||||
//
|
//
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package com.ionspin.kotlin.crypto.auth
|
package com.ionspin.kotlin.crypto.auth
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
||||||
|
|
||||||
actual object Auth {
|
actual object Auth {
|
||||||
actual fun authKeygen(): UByteArray {
|
actual fun authKeygen(): UByteArray {
|
||||||
val generatedKey = UByteArray(crypto_auth_KEYBYTES)
|
val generatedKey = UByteArray(crypto_auth_KEYBYTES)
|
||||||
sodium.crypto_auth_keygen(generatedKey.asByteArray())
|
sodiumJna.crypto_auth_keygen(generatedKey.asByteArray())
|
||||||
return generatedKey
|
return generatedKey
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun auth(message: UByteArray, key: UByteArray): UByteArray {
|
actual fun auth(message: UByteArray, key: UByteArray): UByteArray {
|
||||||
val mac = UByteArray(crypto_auth_BYTES)
|
val mac = UByteArray(crypto_auth_BYTES)
|
||||||
sodium.crypto_auth(
|
sodiumJna.crypto_auth(
|
||||||
mac.asByteArray(),
|
mac.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
@ -21,7 +21,7 @@ actual object Auth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actual fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray): Boolean {
|
actual fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray): Boolean {
|
||||||
return sodium.crypto_auth_verify(
|
return sodiumJna.crypto_auth_verify(
|
||||||
tag.asByteArray(),
|
tag.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
@ -31,13 +31,13 @@ actual object Auth {
|
|||||||
|
|
||||||
actual fun authHmacSha256Keygen(): UByteArray {
|
actual fun authHmacSha256Keygen(): UByteArray {
|
||||||
val generatedKey = UByteArray(crypto_auth_hmacsha256_KEYBYTES)
|
val generatedKey = UByteArray(crypto_auth_hmacsha256_KEYBYTES)
|
||||||
sodium.crypto_auth_hmacsha256_keygen(generatedKey.asByteArray())
|
sodiumJna.crypto_auth_hmacsha256_keygen(generatedKey.asByteArray())
|
||||||
return generatedKey
|
return generatedKey
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun authHmacSha256(message: UByteArray, key: UByteArray): UByteArray {
|
actual fun authHmacSha256(message: UByteArray, key: UByteArray): UByteArray {
|
||||||
val mac = UByteArray(crypto_auth_hmacsha256_BYTES)
|
val mac = UByteArray(crypto_auth_hmacsha256_BYTES)
|
||||||
sodium.crypto_auth_hmacsha256(
|
sodiumJna.crypto_auth_hmacsha256(
|
||||||
mac.asByteArray(),
|
mac.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
@ -51,7 +51,7 @@ actual object Auth {
|
|||||||
message: UByteArray,
|
message: UByteArray,
|
||||||
key: UByteArray
|
key: UByteArray
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return sodium.crypto_auth_hmacsha256_verify(
|
return sodiumJna.crypto_auth_hmacsha256_verify(
|
||||||
tag.asByteArray(),
|
tag.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
@ -61,13 +61,13 @@ actual object Auth {
|
|||||||
|
|
||||||
actual fun authHmacSha512Keygen(): UByteArray {
|
actual fun authHmacSha512Keygen(): UByteArray {
|
||||||
val generatedKey = UByteArray(crypto_auth_hmacsha512_KEYBYTES)
|
val generatedKey = UByteArray(crypto_auth_hmacsha512_KEYBYTES)
|
||||||
sodium.crypto_auth_hmacsha512_keygen(generatedKey.asByteArray())
|
sodiumJna.crypto_auth_hmacsha512_keygen(generatedKey.asByteArray())
|
||||||
return generatedKey
|
return generatedKey
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun authHmacSha512(message: UByteArray, key: UByteArray): UByteArray {
|
actual fun authHmacSha512(message: UByteArray, key: UByteArray): UByteArray {
|
||||||
val mac = UByteArray(crypto_auth_hmacsha512_BYTES)
|
val mac = UByteArray(crypto_auth_hmacsha512_BYTES)
|
||||||
sodium.crypto_auth_hmacsha512(
|
sodiumJna.crypto_auth_hmacsha512(
|
||||||
mac.asByteArray(),
|
mac.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
@ -81,7 +81,7 @@ actual object Auth {
|
|||||||
message: UByteArray,
|
message: UByteArray,
|
||||||
key: UByteArray
|
key: UByteArray
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return sodium.crypto_auth_hmacsha512_verify(
|
return sodiumJna.crypto_auth_hmacsha512_verify(
|
||||||
tag.asByteArray(),
|
tag.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user