Completed cha cha aead variants
This commit is contained in:
1 parent
3f9f316e04
commit
dd0895b5f3
5 files changed
+395
-27
No files matched your search
+23
-3
@@ -44,9 +44,9 @@ interface JsSodiumInterface {
|
||||
|
||||
fun crypto_hash_sha512_final(state: dynamic): Uint8Array
|
||||
|
||||
//XChaCha20Poly1305
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, associatedData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
//XChaCha20Poly1305 - also in bindings
|
||||
//fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
//fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, associatedData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
|
||||
//XChaCha20Poly1305
|
||||
//encrypt
|
||||
@@ -71,6 +71,26 @@ interface JsSodiumInterface {
|
||||
|
||||
// ---- SecretBox End ----
|
||||
|
||||
|
||||
// ---- AEAD ----
|
||||
fun crypto_aead_chacha20poly1305_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_chacha20poly1305_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array
|
||||
fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic
|
||||
fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_chacha20poly1305_ietf_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array
|
||||
fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic
|
||||
fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array
|
||||
fun crypto_aead_chacha20poly1305_keygen() : Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic
|
||||
fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array
|
||||
|
||||
// ---- AEAD end ----
|
||||
|
||||
//util
|
||||
fun memzero(array: Uint8Array)
|
||||
|
||||
|
||||
+140
-12
@@ -1,5 +1,10 @@
|
||||
package com.ionspin.kotlin.crypto.aead
|
||||
|
||||
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 AuthenticatedEncryptionWithAssociatedData {
|
||||
|
||||
// Ietf
|
||||
@@ -11,7 +16,13 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
return getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt(
|
||||
message.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
null,
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array(),
|
||||
).toUByteArray()
|
||||
}
|
||||
|
||||
actual fun xChaCha20Poly1305IetfDecrypt(
|
||||
@@ -20,7 +31,17 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
try {
|
||||
return getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt(
|
||||
null,
|
||||
ciphertext.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
).toUByteArray()
|
||||
} catch (error: Throwable) {
|
||||
throw AeadCorrupedOrTamperedDataException()
|
||||
}
|
||||
}
|
||||
|
||||
actual fun xChaCha20Poly1305IetfEncryptDetached(
|
||||
@@ -29,7 +50,17 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): AeadEncryptedDataAndTag {
|
||||
TODO("not implemented yet")
|
||||
val result = getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt_detached(
|
||||
message.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
null,
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array(),
|
||||
)
|
||||
return AeadEncryptedDataAndTag(
|
||||
(result.ciphertext as Uint8Array).toUByteArray(),
|
||||
(result.mac as Uint8Array).toUByteArray()
|
||||
)
|
||||
}
|
||||
|
||||
actual fun xChaCha20Poly1305IetfDecryptDetached(
|
||||
@@ -39,7 +70,18 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
try {
|
||||
return getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt_detached(
|
||||
null,
|
||||
ciphertext.toUInt8Array(),
|
||||
tag.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
).toUByteArray()
|
||||
} catch (error: Throwable) {
|
||||
throw AeadCorrupedOrTamperedDataException()
|
||||
}
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305IetfEncrypt(
|
||||
@@ -48,7 +90,13 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
return getSodium().crypto_aead_chacha20poly1305_ietf_encrypt(
|
||||
message.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
null,
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array(),
|
||||
).toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305IetfDecrypt(
|
||||
@@ -57,7 +105,17 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
try {
|
||||
return getSodium().crypto_aead_chacha20poly1305_ietf_decrypt(
|
||||
null,
|
||||
ciphertext.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
).toUByteArray()
|
||||
} catch (error: Throwable) {
|
||||
throw AeadCorrupedOrTamperedDataException()
|
||||
}
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305IetfEncryptDetached(
|
||||
@@ -66,7 +124,17 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): AeadEncryptedDataAndTag {
|
||||
TODO("not implemented yet")
|
||||
val result = getSodium().crypto_aead_chacha20poly1305_ietf_encrypt_detached(
|
||||
message.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
null,
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array(),
|
||||
)
|
||||
return AeadEncryptedDataAndTag(
|
||||
(result.ciphertext as Uint8Array).toUByteArray(),
|
||||
(result.mac as Uint8Array).toUByteArray()
|
||||
)
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305IetfDecryptDetached(
|
||||
@@ -76,7 +144,18 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
try {
|
||||
return getSodium().crypto_aead_chacha20poly1305_ietf_decrypt_detached(
|
||||
null,
|
||||
ciphertext.toUInt8Array(),
|
||||
tag.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
).toUByteArray()
|
||||
} catch (error: Throwable) {
|
||||
throw AeadCorrupedOrTamperedDataException()
|
||||
}
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305Encrypt(
|
||||
@@ -85,7 +164,13 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
return getSodium().crypto_aead_chacha20poly1305_encrypt(
|
||||
message.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
null,
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array(),
|
||||
).toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305Decrypt(
|
||||
@@ -94,7 +179,17 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
try {
|
||||
return getSodium().crypto_aead_chacha20poly1305_decrypt(
|
||||
null,
|
||||
ciphertext.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
).toUByteArray()
|
||||
} catch (error: Throwable) {
|
||||
throw AeadCorrupedOrTamperedDataException()
|
||||
}
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305EncryptDetached(
|
||||
@@ -103,7 +198,17 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): AeadEncryptedDataAndTag {
|
||||
TODO("not implemented yet")
|
||||
val result = getSodium().crypto_aead_chacha20poly1305_encrypt_detached(
|
||||
message.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
null,
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array(),
|
||||
)
|
||||
return AeadEncryptedDataAndTag(
|
||||
(result.ciphertext as Uint8Array).toUByteArray(),
|
||||
(result.mac as Uint8Array).toUByteArray()
|
||||
)
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305DecryptDetached(
|
||||
@@ -113,7 +218,30 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
try {
|
||||
return getSodium().crypto_aead_chacha20poly1305_decrypt_detached(
|
||||
null,
|
||||
ciphertext.toUInt8Array(),
|
||||
tag.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
).toUByteArray()
|
||||
} catch (error: Throwable) {
|
||||
throw AeadCorrupedOrTamperedDataException()
|
||||
}
|
||||
}
|
||||
|
||||
actual fun xChaCha20Poly1305IetfKeygen(): UByteArray {
|
||||
return getSodium().crypto_aead_xchacha20poly1305_ietf_keygen().toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305IetfKeygen(): UByteArray {
|
||||
return getSodium().crypto_aead_chacha20poly1305_ietf_keygen().toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chaCha20Poly1305Keygen(): UByteArray {
|
||||
return getSodium().crypto_aead_chacha20poly1305_keygen().toUByteArray()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user