Added box:
This commit is contained in:
parent
f0511e0ff1
commit
f7815d009e
@ -770,39 +770,126 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray
|
key: ByteArray
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//
|
//
|
||||||
// // ---- Auth end ----
|
// // ---- Auth end ----
|
||||||
//
|
//
|
||||||
// // ---- Box ----
|
// // ---- Box ----
|
||||||
//
|
//
|
||||||
// fun crypto_box_keypair() : dynamic
|
// int crypto_box_keypair(unsigned char *pk, unsigned char *sk)
|
||||||
// fun crypto_box_seed_keypair(seed : Uint8Array) : dynamic
|
fun crypto_box_keypair(publicKey: ByteArray, secretKey: ByteArray)
|
||||||
// fun crypto_box_easy(message: Uint8Array,
|
|
||||||
// nonce: Uint8Array,
|
// int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,
|
||||||
// recipientsPublicKey: Uint8Array,
|
// const unsigned char *seed)
|
||||||
// sendersSecretKey: Uint8Array) : Uint8Array
|
fun crypto_box_seed_keypair(
|
||||||
// fun crypto_box_open_easy(ciphertext: Uint8Array,
|
publicKey: ByteArray,
|
||||||
// nonce: Uint8Array,
|
secretKey: ByteArray,
|
||||||
// sendersPublicKey: Uint8Array,
|
seed: ByteArray
|
||||||
// recipientsSecretKey: Uint8Array) : Uint8Array
|
) : Int
|
||||||
// fun crypto_box_detached(message: Uint8Array,
|
|
||||||
// nonce: Uint8Array,
|
// int crypto_box_easy(unsigned char *c, const unsigned char *m,
|
||||||
// recipientsPublicKey: Uint8Array,
|
// unsigned long long mlen, const unsigned char *n,
|
||||||
// sendersSecretKey: Uint8Array) : dynamic
|
// const unsigned char *pk, const unsigned char *sk)
|
||||||
// fun crypto_box_open_detached(ciphertext: Uint8Array,
|
fun crypto_box_easy(
|
||||||
// tag: Uint8Array,
|
ciphertext: ByteArray,
|
||||||
// nonce: Uint8Array,
|
message: ByteArray,
|
||||||
// sendersPublicKey: Uint8Array,
|
messageLength: Long,
|
||||||
// recipientsSecretKey: Uint8Array) : Uint8Array
|
nonce: ByteArray,
|
||||||
// fun crypto_box_beforenm(publicKey: Uint8Array, secretKey: Uint8Array) : Uint8Array
|
recipientPublicKey: ByteArray,
|
||||||
// fun crypto_box_easy_afternm(message: Uint8Array,
|
senderSecretKey: ByteArray
|
||||||
// nonce: Uint8Array,
|
) : Int
|
||||||
// precomputedKey: Uint8Array) : Uint8Array
|
|
||||||
// fun crypto_box_open_easy_afternm(ciphertext: Uint8Array,
|
// int crypto_box_open_easy(unsigned char *m, const unsigned char *c,
|
||||||
// nonce: Uint8Array,
|
// unsigned long long clen, const unsigned char *n,
|
||||||
// precomputedKey: Uint8Array) : Uint8Array
|
// const unsigned char *pk, const unsigned char *sk)
|
||||||
// fun crypto_box_seal(message: Uint8Array, recipientsPublicKey: Uint8Array) : Uint8Array
|
fun crypto_box_open_easy(
|
||||||
// fun crypto_box_seal_open(ciphertext: Uint8Array, recipientsPublicKey: Uint8Array, recipientsSecretKey: Uint8Array) : Uint8Array
|
message: ByteArray,
|
||||||
|
ciphertext: ByteArray,
|
||||||
|
ciphertextLength: Long,
|
||||||
|
nonce: ByteArray,
|
||||||
|
senderPublickKey: ByteArray,
|
||||||
|
recipientSecretKey: ByteArray
|
||||||
|
) : Int
|
||||||
|
|
||||||
|
// int crypto_box_detached(unsigned char *c, unsigned char *mac,
|
||||||
|
// const unsigned char *m, unsigned long long mlen,
|
||||||
|
// const unsigned char *n, const unsigned char *pk,
|
||||||
|
// const unsigned char *sk)
|
||||||
|
fun crypto_box_detached(
|
||||||
|
ciphertext: ByteArray,
|
||||||
|
mac: ByteArray,
|
||||||
|
message: ByteArray,
|
||||||
|
messageLength: Long,
|
||||||
|
nonce: ByteArray,
|
||||||
|
recipientPublicKey: ByteArray,
|
||||||
|
senderSecretKey: ByteArray
|
||||||
|
) : Int
|
||||||
|
|
||||||
|
// int crypto_box_open_detached(
|
||||||
|
// unsigned char *m, const unsigned char *c,
|
||||||
|
// const unsigned char *mac,
|
||||||
|
// unsigned long long clen,
|
||||||
|
// const unsigned char *n,
|
||||||
|
// const unsigned char *pk,
|
||||||
|
// const unsigned char *sk)
|
||||||
|
fun crypto_box_open_detached(
|
||||||
|
message: ByteArray,
|
||||||
|
ciphertext: ByteArray,
|
||||||
|
mac: ByteArray,
|
||||||
|
ciphertextLength: Long,
|
||||||
|
nonce: ByteArray,
|
||||||
|
senderPublickKey: ByteArray,
|
||||||
|
recipientSecretKey: ByteArray
|
||||||
|
) : Int
|
||||||
|
|
||||||
|
// int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
|
||||||
|
// const unsigned char *sk)
|
||||||
|
fun crypto_box_beforenm(
|
||||||
|
sessionKey: ByteArray,
|
||||||
|
publicKey: ByteArray,
|
||||||
|
secretKey: ByteArray
|
||||||
|
) : Int
|
||||||
|
// int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
|
||||||
|
// unsigned long long mlen, const unsigned char *n,
|
||||||
|
// const unsigned char *k)
|
||||||
|
fun crypto_box_easy_afternm(
|
||||||
|
ciphertext: ByteArray,
|
||||||
|
message: ByteArray,
|
||||||
|
messageLength: Long,
|
||||||
|
nonce: ByteArray,
|
||||||
|
sessionKey: ByteArray
|
||||||
|
) : Int
|
||||||
|
|
||||||
|
// int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
|
||||||
|
// unsigned long long clen, const unsigned char *n,
|
||||||
|
// const unsigned char *k)
|
||||||
|
fun crypto_box_open_easy_afternm(
|
||||||
|
message: ByteArray,
|
||||||
|
ciphertext: ByteArray,
|
||||||
|
ciphertextLength: Long,
|
||||||
|
nonce: ByteArray,
|
||||||
|
sessionKey: ByteArray
|
||||||
|
) : Int
|
||||||
|
// int crypto_box_seal(unsigned char *c, const unsigned char *m,
|
||||||
|
// unsigned long long mlen, const unsigned char *pk)
|
||||||
|
fun crypto_box_seal(
|
||||||
|
ciphertext: ByteArray,
|
||||||
|
message: ByteArray,
|
||||||
|
messageLength: Long,
|
||||||
|
recipientPublicKey: ByteArray
|
||||||
|
) : Int
|
||||||
|
|
||||||
|
|
||||||
|
// int crypto_box_seal_open(unsigned char *m, const unsigned char *c,
|
||||||
|
// unsigned long long clen,
|
||||||
|
// const unsigned char *pk, const unsigned char *sk)
|
||||||
|
fun crypto_box_seal_open(
|
||||||
|
message: ByteArray,
|
||||||
|
ciphertext: ByteArray,
|
||||||
|
ciphertextLength: Long,
|
||||||
|
senderPublickKey: ByteArray,
|
||||||
|
recipientSecretKey: ByteArray
|
||||||
|
) : Int
|
||||||
//
|
//
|
||||||
// // ---- Box end ----
|
// // ---- Box end ----
|
||||||
//
|
//
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.ionspin.kotlin.crypto.box
|
package com.ionspin.kotlin.crypto.box
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
||||||
|
|
||||||
actual object Box {
|
actual object Box {
|
||||||
/**
|
/**
|
||||||
@ -11,7 +11,7 @@ actual object Box {
|
|||||||
actual fun keypair(): BoxKeyPair {
|
actual fun keypair(): BoxKeyPair {
|
||||||
val publicKey = UByteArray(crypto_box_PUBLICKEYBYTES)
|
val publicKey = UByteArray(crypto_box_PUBLICKEYBYTES)
|
||||||
val secretKey = UByteArray(crypto_box_SECRETKEYBYTES)
|
val secretKey = UByteArray(crypto_box_SECRETKEYBYTES)
|
||||||
sodium.crypto_box_keypair(publicKey.asByteArray(), secretKey.asByteArray())
|
sodiumJna.crypto_box_keypair(publicKey.asByteArray(), secretKey.asByteArray())
|
||||||
return BoxKeyPair(publicKey, secretKey)
|
return BoxKeyPair(publicKey, secretKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ actual object Box {
|
|||||||
actual fun seedKeypair(seed: UByteArray): BoxKeyPair {
|
actual fun seedKeypair(seed: UByteArray): BoxKeyPair {
|
||||||
val publicKey = UByteArray(crypto_box_PUBLICKEYBYTES)
|
val publicKey = UByteArray(crypto_box_PUBLICKEYBYTES)
|
||||||
val secretKey = UByteArray(crypto_box_SECRETKEYBYTES)
|
val secretKey = UByteArray(crypto_box_SECRETKEYBYTES)
|
||||||
sodium.crypto_box_seed_keypair(publicKey.asByteArray(), secretKey.asByteArray(), seed.asByteArray())
|
sodiumJna.crypto_box_seed_keypair(publicKey.asByteArray(), secretKey.asByteArray(), seed.asByteArray())
|
||||||
return BoxKeyPair(publicKey, secretKey)
|
return BoxKeyPair(publicKey, secretKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ actual object Box {
|
|||||||
sendersSecretKey: UByteArray
|
sendersSecretKey: UByteArray
|
||||||
): UByteArray {
|
): UByteArray {
|
||||||
val ciphertext = UByteArray(message.size + crypto_box_MACBYTES)
|
val ciphertext = UByteArray(message.size + crypto_box_MACBYTES)
|
||||||
sodium.crypto_box_easy(
|
sodiumJna.crypto_box_easy(
|
||||||
ciphertext.asByteArray(),
|
ciphertext.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
@ -64,7 +64,7 @@ actual object Box {
|
|||||||
recipientsSecretKey: UByteArray
|
recipientsSecretKey: UByteArray
|
||||||
): UByteArray {
|
): UByteArray {
|
||||||
val message = UByteArray(ciphertext.size - crypto_box_MACBYTES)
|
val message = UByteArray(ciphertext.size - crypto_box_MACBYTES)
|
||||||
val validationResult = sodium.crypto_box_open_easy(
|
val validationResult = sodiumJna.crypto_box_open_easy(
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
ciphertext.asByteArray(),
|
ciphertext.asByteArray(),
|
||||||
ciphertext.size.toLong(),
|
ciphertext.size.toLong(),
|
||||||
@ -85,7 +85,7 @@ actual object Box {
|
|||||||
*/
|
*/
|
||||||
actual fun beforeNM(publicKey: UByteArray, secretKey: UByteArray): UByteArray {
|
actual fun beforeNM(publicKey: UByteArray, secretKey: UByteArray): UByteArray {
|
||||||
val sessionKey = UByteArray(crypto_box_BEFORENMBYTES)
|
val sessionKey = UByteArray(crypto_box_BEFORENMBYTES)
|
||||||
sodium.crypto_box_beforenm(sessionKey.asByteArray(), publicKey.asByteArray(), secretKey.asByteArray())
|
sodiumJna.crypto_box_beforenm(sessionKey.asByteArray(), publicKey.asByteArray(), secretKey.asByteArray())
|
||||||
return sessionKey
|
return sessionKey
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ actual object Box {
|
|||||||
): UByteArray {
|
): UByteArray {
|
||||||
val ciphertext = UByteArray(message.size + crypto_box_MACBYTES)
|
val ciphertext = UByteArray(message.size + crypto_box_MACBYTES)
|
||||||
|
|
||||||
sodium.crypto_box_easy_afternm(
|
sodiumJna.crypto_box_easy_afternm(
|
||||||
ciphertext.asByteArray(),
|
ciphertext.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
@ -119,7 +119,7 @@ actual object Box {
|
|||||||
precomputedKey: UByteArray
|
precomputedKey: UByteArray
|
||||||
): UByteArray {
|
): UByteArray {
|
||||||
val message = UByteArray(ciphertext.size - crypto_box_MACBYTES)
|
val message = UByteArray(ciphertext.size - crypto_box_MACBYTES)
|
||||||
val validationResult = sodium.crypto_box_open_easy_afternm(
|
val validationResult = sodiumJna.crypto_box_open_easy_afternm(
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
ciphertext.asByteArray(),
|
ciphertext.asByteArray(),
|
||||||
ciphertext.size.toLong(),
|
ciphertext.size.toLong(),
|
||||||
@ -149,7 +149,7 @@ actual object Box {
|
|||||||
val ciphertext = UByteArray(message.size)
|
val ciphertext = UByteArray(message.size)
|
||||||
val tag = UByteArray(crypto_box_MACBYTES)
|
val tag = UByteArray(crypto_box_MACBYTES)
|
||||||
|
|
||||||
sodium.crypto_box_detached(
|
sodiumJna.crypto_box_detached(
|
||||||
ciphertext.asByteArray(),
|
ciphertext.asByteArray(),
|
||||||
tag.asByteArray(),
|
tag.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
@ -177,7 +177,7 @@ actual object Box {
|
|||||||
): UByteArray {
|
): UByteArray {
|
||||||
val message = UByteArray(ciphertext.size)
|
val message = UByteArray(ciphertext.size)
|
||||||
|
|
||||||
val validationResult = sodium.crypto_box_open_detached(
|
val validationResult = sodiumJna.crypto_box_open_detached(
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
ciphertext.asByteArray(),
|
ciphertext.asByteArray(),
|
||||||
tag.asByteArray(),
|
tag.asByteArray(),
|
||||||
@ -196,7 +196,7 @@ actual object Box {
|
|||||||
|
|
||||||
actual fun seal(message: UByteArray, recipientsPublicKey: UByteArray): UByteArray {
|
actual fun seal(message: UByteArray, recipientsPublicKey: UByteArray): UByteArray {
|
||||||
val ciphertextWithPublicKey = UByteArray(message.size + crypto_box_SEALBYTES)
|
val ciphertextWithPublicKey = UByteArray(message.size + crypto_box_SEALBYTES)
|
||||||
sodium.crypto_box_seal(
|
sodiumJna.crypto_box_seal(
|
||||||
ciphertextWithPublicKey.asByteArray(),
|
ciphertextWithPublicKey.asByteArray(),
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
message.size.toLong(),
|
message.size.toLong(),
|
||||||
@ -207,7 +207,7 @@ actual object Box {
|
|||||||
|
|
||||||
actual fun sealOpen(ciphertext: UByteArray, recipientsPublicKey: UByteArray, recipientsSecretKey: UByteArray): UByteArray {
|
actual fun sealOpen(ciphertext: UByteArray, recipientsPublicKey: UByteArray, recipientsSecretKey: UByteArray): UByteArray {
|
||||||
val message = UByteArray(ciphertext.size - crypto_box_SEALBYTES)
|
val message = UByteArray(ciphertext.size - crypto_box_SEALBYTES)
|
||||||
val validationResult = sodium.crypto_box_seal_open(
|
val validationResult = sodiumJna.crypto_box_seal_open(
|
||||||
message.asByteArray(),
|
message.asByteArray(),
|
||||||
ciphertext.asByteArray(),
|
ciphertext.asByteArray(),
|
||||||
ciphertext.size.toLong(),
|
ciphertext.size.toLong(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user