Change all occurences of additionalData to associatedData
This commit is contained in:
1 parent
54489ef6cb
commit
3de04749ba
21 files changed
+142
-142
No files matched your search
+8
-8
@@ -145,17 +145,17 @@ object Crypto {
|
||||
}
|
||||
|
||||
object Encryption : EncryptionApi {
|
||||
override fun encrypt(key: SymmetricKey, data : Encryptable<*>, additionalData : UByteArray) : EncryptedData {
|
||||
override fun encrypt(key: SymmetricKey, data : Encryptable<*>, associatedData : UByteArray) : EncryptedData {
|
||||
if (key.value.size != 32) {
|
||||
throw RuntimeException("Invalid key size! Required 32, supplied ${key.value.size}")
|
||||
}
|
||||
val nonce = SRNG.getRandomBytes(24)
|
||||
return EncryptedData(XChaCha20Poly1305Delegated.encrypt(key.value, nonce, data.toEncryptableForm(), additionalData), nonce)
|
||||
return EncryptedData(XChaCha20Poly1305Delegated.encrypt(key.value, nonce, data.toEncryptableForm(), associatedData), nonce)
|
||||
|
||||
}
|
||||
|
||||
override fun <T: Encryptable<T>> decrypt(key: SymmetricKey, encryptedData : EncryptedData, additionalData: UByteArray, byteArrayDeserializer : (UByteArray) -> T) : T {
|
||||
return byteArrayDeserializer(XChaCha20Poly1305Delegated.decrypt(key.value, encryptedData.nonce, encryptedData.ciphertext, additionalData))
|
||||
override fun <T: Encryptable<T>> decrypt(key: SymmetricKey, encryptedData : EncryptedData, associatedData: UByteArray, byteArrayDeserializer : (UByteArray) -> T) : T {
|
||||
return byteArrayDeserializer(XChaCha20Poly1305Delegated.decrypt(key.value, encryptedData.nonce, encryptedData.ciphertext, associatedData))
|
||||
|
||||
}
|
||||
|
||||
@@ -185,8 +185,8 @@ class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKe
|
||||
return header
|
||||
}
|
||||
|
||||
override fun encryptPartialData(data: UByteArray, additionalData: UByteArray): EncryptedDataPart {
|
||||
return EncryptedDataPart(primitive.encrypt(data, additionalData))
|
||||
override fun encryptPartialData(data: UByteArray, associatedData: UByteArray): EncryptedDataPart {
|
||||
return EncryptedDataPart(primitive.encrypt(data, associatedData))
|
||||
}
|
||||
|
||||
override fun cleanup() {
|
||||
@@ -196,8 +196,8 @@ class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKe
|
||||
|
||||
|
||||
class MultipartAuthenticatedDecryptor internal constructor(val decryptor: XChaCha20Poly1305Delegated) : MultipartAuthenticatedDecryption {
|
||||
override fun decryptPartialData(data: EncryptedDataPart, additionalData: UByteArray): DecryptedDataPart {
|
||||
return DecryptedDataPart(decryptor.decrypt(data.data, additionalData))
|
||||
override fun decryptPartialData(data: EncryptedDataPart, associatedData: UByteArray): DecryptedDataPart {
|
||||
return DecryptedDataPart(decryptor.decrypt(data.data, associatedData))
|
||||
}
|
||||
|
||||
override fun cleanup() {
|
||||
|
||||
+4
-4
@@ -9,13 +9,13 @@ package com.ionspin.kotlin.crypto.authenticated
|
||||
expect class XChaCha20Poly1305Delegated internal constructor() {
|
||||
internal constructor(key: UByteArray, testState : UByteArray, testHeader: UByteArray, isDecryptor: Boolean)
|
||||
companion object {
|
||||
fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, additionalData: UByteArray) : UByteArray
|
||||
fun decrypt(key: UByteArray, nonce: UByteArray, ciphertext: UByteArray, additionalData: UByteArray) : UByteArray
|
||||
fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, associatedData: UByteArray) : UByteArray
|
||||
fun decrypt(key: UByteArray, nonce: UByteArray, ciphertext: UByteArray, associatedData: UByteArray) : UByteArray
|
||||
}
|
||||
fun initializeForEncryption(key: UByteArray) : UByteArray
|
||||
fun initializeForDecryption(key: UByteArray, header: UByteArray)
|
||||
fun encrypt(data: UByteArray, additionalData: UByteArray = ubyteArrayOf()) : UByteArray
|
||||
fun decrypt(data: UByteArray, additionalData: UByteArray = ubyteArrayOf()) : UByteArray
|
||||
fun encrypt(data: UByteArray, associatedData: UByteArray = ubyteArrayOf()) : UByteArray
|
||||
fun decrypt(data: UByteArray, associatedData: UByteArray = ubyteArrayOf()) : UByteArray
|
||||
fun cleanup()
|
||||
|
||||
|
||||
|
||||
+10
-10
@@ -26,7 +26,7 @@ class XChaCha20Poly1305Test {
|
||||
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
|
||||
"only one tip for the future, sunscreen would be it.").encodeToUByteArray()
|
||||
|
||||
val additionalData = ubyteArrayOf(
|
||||
val associatedData = ubyteArrayOf(
|
||||
0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U
|
||||
)
|
||||
val key = ubyteArrayOf(
|
||||
@@ -61,9 +61,9 @@ class XChaCha20Poly1305Test {
|
||||
0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU,
|
||||
0xcfU, 0x49U
|
||||
)
|
||||
val encrypted = XChaCha20Poly1305Delegated.encrypt(key, nonce, message, additionalData)
|
||||
val encrypted = XChaCha20Poly1305Delegated.encrypt(key, nonce, message, associatedData)
|
||||
encrypted.hexColumsPrint()
|
||||
val decrypted = XChaCha20Poly1305Delegated.decrypt(key, nonce, encrypted, additionalData)
|
||||
val decrypted = XChaCha20Poly1305Delegated.decrypt(key, nonce, encrypted, associatedData)
|
||||
println("Decrypted")
|
||||
decrypted.hexColumsPrint()
|
||||
println("----------")
|
||||
@@ -74,7 +74,7 @@ class XChaCha20Poly1305Test {
|
||||
val message = ubyteArrayOf(
|
||||
0x00U
|
||||
)
|
||||
val additionalData = ubyteArrayOf(
|
||||
val associatedData = ubyteArrayOf(
|
||||
0x00U
|
||||
)
|
||||
val key = ubyteArrayOf(
|
||||
@@ -93,8 +93,8 @@ class XChaCha20Poly1305Test {
|
||||
0xbdU, 0x3bU, 0x8aU, 0xd7U, 0xa1U, 0x9dU, 0xe8U, 0xc4U, 0x55U,
|
||||
0x84U, 0x6fU, 0xfcU, 0x75U, 0x31U, 0xbfU, 0x0cU, 0x2dU
|
||||
)
|
||||
val encrypted = XChaCha20Poly1305Delegated.encrypt(key, nonce, message, additionalData)
|
||||
val decrypted = XChaCha20Poly1305Delegated.decrypt(key, nonce, encrypted, additionalData)
|
||||
val encrypted = XChaCha20Poly1305Delegated.encrypt(key, nonce, message, associatedData)
|
||||
val decrypted = XChaCha20Poly1305Delegated.decrypt(key, nonce, encrypted, associatedData)
|
||||
|
||||
encrypted.contentEquals(expected) && decrypted.contentEquals(message)
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class XChaCha20Poly1305Test {
|
||||
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
|
||||
"only one tip for the future, sunscreen would be it.").encodeToUByteArray()
|
||||
|
||||
val additionalData = ubyteArrayOf(
|
||||
val associatedData = ubyteArrayOf(
|
||||
0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U
|
||||
)
|
||||
val key = ubyteArrayOf(
|
||||
@@ -144,7 +144,7 @@ class XChaCha20Poly1305Test {
|
||||
0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU,
|
||||
0xcfU, 0x49U
|
||||
)
|
||||
// val xChaChaPoly = XChaCha20Poly1305Delegated(key, additionalData)
|
||||
// val xChaChaPoly = XChaCha20Poly1305Delegated(key, associatedData)
|
||||
// val firstChunk = xChaChaPoly.encrypt(message)
|
||||
// val finalChunk = xChaChaPoly.finishEncryption().first
|
||||
// val result = firstChunk + finalChunk
|
||||
@@ -157,7 +157,7 @@ class XChaCha20Poly1305Test {
|
||||
val message = ubyteArrayOf(
|
||||
0x00U
|
||||
)
|
||||
val additionalData = ubyteArrayOf(
|
||||
val associatedData = ubyteArrayOf(
|
||||
0x00U
|
||||
)
|
||||
val key = ubyteArrayOf(
|
||||
@@ -176,7 +176,7 @@ class XChaCha20Poly1305Test {
|
||||
0xbdU, 0x3bU, 0x8aU, 0xd7U, 0xa1U, 0x9dU, 0xe8U, 0xc4U, 0x55U,
|
||||
0x84U, 0x6fU, 0xfcU, 0x75U, 0x31U, 0xbfU, 0x0cU, 0x2dU
|
||||
)
|
||||
// val xChaChaPoly = XChaCha20Poly1305Delegated(key, additionalData)
|
||||
// val xChaChaPoly = XChaCha20Poly1305Delegated(key, associatedData)
|
||||
// val firstChunk = xChaChaPoly.encrypt(message)
|
||||
// val finalChunk = xChaChaPoly.finishEncryption().first
|
||||
// val result = firstChunk + finalChunk
|
||||
|
||||
+3
-3
@@ -22,17 +22,17 @@ class EncryptionTest {
|
||||
val plaintext = ("pUoR4JVXJUeMKNkt6ZGGzEdTo33ajNGXwXpivBKA0XKs8toGRYI9Eul4bELRDkaQDNhd4vZseEFU" +
|
||||
"ojsAn3c9zIifIrMnydSivHVZ2pBtpAQwYoJhYmEsfE0tROGnOwFWyB9K6LRSv1gB3YqKR9VyM8mpRoUM3UCRRjyiX7bnKdCE1" +
|
||||
"EiX0myiwcY1nUKTgB3keERWtMU07hX7bCtao5nRvDofSj3o3IInHRQh6opltr5asQwn4m1qn029QF").encodeToUByteArray()
|
||||
val additionalData = "Additional data 1".encodeToUByteArray()
|
||||
val associatedData = "Additional data 1".encodeToUByteArray()
|
||||
val keyValue = UByteArray(32) { it.toUByte() }
|
||||
val key = SymmetricKey(keyValue)
|
||||
val encryptor = Crypto.Encryption.createMultipartEncryptor(key)
|
||||
val header = encryptor.startEncryption()
|
||||
val ciphertext1 = encryptor.encryptPartialData(plaintext.sliceArray(0 until 100), additionalData)
|
||||
val ciphertext1 = encryptor.encryptPartialData(plaintext.sliceArray(0 until 100), associatedData)
|
||||
val ciphertext2 = encryptor.encryptPartialData(plaintext.sliceArray(100 until 200))
|
||||
val ciphertext3 = encryptor.encryptPartialData(plaintext.sliceArray(200 until 250))
|
||||
//decrypt
|
||||
val decryptor = Crypto.Encryption.createMultipartDecryptor(key, header)
|
||||
val plaintext1 = decryptor.decryptPartialData(ciphertext1, additionalData)
|
||||
val plaintext1 = decryptor.decryptPartialData(ciphertext1, associatedData)
|
||||
val plaintext2 = decryptor.decryptPartialData(ciphertext2)
|
||||
val plaintext3 = decryptor.decryptPartialData(ciphertext3)
|
||||
|
||||
|
||||
+4
-4
@@ -40,17 +40,17 @@ interface JsSodiumInterface {
|
||||
fun crypto_hash_sha512_final(state: dynamic): Uint8Array
|
||||
|
||||
//XChaCha20Poly1305
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, additionalData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, additionalData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
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
|
||||
fun crypto_secretstream_xchacha20poly1305_init_push(header: Uint8Array) : dynamic
|
||||
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: UByte) : Uint8Array
|
||||
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array
|
||||
|
||||
//decrypt
|
||||
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic
|
||||
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, additionalData: Uint8Array) : dynamic
|
||||
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, associatedData: Uint8Array) : dynamic
|
||||
|
||||
//util
|
||||
fun memzero(array: Uint8Array)
|
||||
|
||||
+8
-8
@@ -24,11 +24,11 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
key: UByteArray,
|
||||
nonce: UByteArray,
|
||||
message: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): UByteArray {
|
||||
val encrypted = getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt(
|
||||
message.toUInt8Array(),
|
||||
additionalData.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
Uint8Array(0),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
@@ -40,12 +40,12 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
key: UByteArray,
|
||||
nonce: UByteArray,
|
||||
ciphertext: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): UByteArray {
|
||||
val decrypted = getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt(
|
||||
Uint8Array(0),
|
||||
ciphertext.toUInt8Array(),
|
||||
additionalData.toUInt8Array(),
|
||||
associatedData.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
)
|
||||
@@ -92,25 +92,25 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
isEncryptor = !isDecryptor
|
||||
}
|
||||
|
||||
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
||||
actual fun encrypt(data: UByteArray, associatedData: UByteArray): UByteArray {
|
||||
if (!isInitialized) {
|
||||
throw RuntimeException("Not initalized!")
|
||||
}
|
||||
if (!isEncryptor) {
|
||||
throw RuntimeException("Initialized as decryptor, attempted to use as encryptor")
|
||||
}
|
||||
val encrypted = getSodium().crypto_secretstream_xchacha20poly1305_push(state, data.toUInt8Array(), additionalData.toUInt8Array(), 0U)
|
||||
val encrypted = getSodium().crypto_secretstream_xchacha20poly1305_push(state, data.toUInt8Array(), associatedData.toUInt8Array(), 0U)
|
||||
return encrypted.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun decrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
||||
actual fun decrypt(data: UByteArray, associatedData: UByteArray): UByteArray {
|
||||
if (!isInitialized) {
|
||||
throw RuntimeException("Not initalized!")
|
||||
}
|
||||
if (isEncryptor) {
|
||||
throw RuntimeException("Initialized as encryptor, attempted to use as decryptor")
|
||||
}
|
||||
val decryptedWithTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(state, data.toUInt8Array(), additionalData.toUInt8Array())
|
||||
val decryptedWithTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(state, data.toUInt8Array(), associatedData.toUInt8Array())
|
||||
val decrypted = decryptedWithTag.message as Uint8Array
|
||||
val validTag = decryptedWithTag.tag
|
||||
|
||||
|
||||
+11
-11
@@ -16,7 +16,7 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
key: UByteArray,
|
||||
nonce: UByteArray,
|
||||
message: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): UByteArray {
|
||||
val ciphertext = ByteArray(message.size + 16)
|
||||
SodiumJava().crypto_aead_xchacha20poly1305_ietf_encrypt(
|
||||
@@ -24,8 +24,8 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
longArrayOf(ciphertext.size.toLong()),
|
||||
message.toByteArray(),
|
||||
message.size.toLong(),
|
||||
additionalData.toByteArray(),
|
||||
additionalData.size.toLong(),
|
||||
associatedData.toByteArray(),
|
||||
associatedData.size.toLong(),
|
||||
null,
|
||||
nonce.toByteArray(),
|
||||
key.toByteArray()
|
||||
@@ -38,7 +38,7 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
key: UByteArray,
|
||||
nonce: UByteArray,
|
||||
ciphertext: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): UByteArray {
|
||||
val message = ByteArray(ciphertext.size - 16)
|
||||
SodiumJava().crypto_aead_xchacha20poly1305_ietf_decrypt(
|
||||
@@ -47,8 +47,8 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
null,
|
||||
ciphertext.toByteArray(),
|
||||
ciphertext.size.toLong(),
|
||||
additionalData.toByteArray(),
|
||||
additionalData.size.toLong(),
|
||||
associatedData.toByteArray(),
|
||||
associatedData.size.toLong(),
|
||||
nonce.toByteArray(),
|
||||
key.toByteArray()
|
||||
|
||||
@@ -89,7 +89,7 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
isEncryptor = false
|
||||
}
|
||||
|
||||
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
||||
actual fun encrypt(data: UByteArray, associatedData: UByteArray): UByteArray {
|
||||
if (!isInitialized) {
|
||||
throw RuntimeException("Not initalized!")
|
||||
}
|
||||
@@ -100,13 +100,13 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
sodium.crypto_secretstream_xchacha20poly1305_push(
|
||||
state, ciphertext, null,
|
||||
data.asByteArray(), data.size.toLong(),
|
||||
additionalData.asByteArray(), additionalData.size.toLong(),
|
||||
associatedData.asByteArray(), associatedData.size.toLong(),
|
||||
0
|
||||
)
|
||||
return ciphertext.asUByteArray()
|
||||
}
|
||||
|
||||
actual fun decrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
||||
actual fun decrypt(data: UByteArray, associatedData: UByteArray): UByteArray {
|
||||
if (!isInitialized) {
|
||||
throw RuntimeException("Not initalized!")
|
||||
}
|
||||
@@ -120,8 +120,8 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
null,
|
||||
data.asByteArray(),
|
||||
(data.size).toLong(),
|
||||
additionalData.asByteArray(),
|
||||
additionalData.size.toLong()
|
||||
associatedData.asByteArray(),
|
||||
associatedData.size.toLong()
|
||||
)
|
||||
if (validTag != 0) {
|
||||
println("Tag validation failed")
|
||||
|
||||
+12
-12
@@ -17,7 +17,7 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
key: UByteArray,
|
||||
nonce: UByteArray,
|
||||
message: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): UByteArray {
|
||||
val ciphertextLength = message.size + crypto_aead_xchacha20poly1305_IETF_ABYTES.toInt()
|
||||
val ciphertext = UByteArray(ciphertextLength)
|
||||
@@ -27,8 +27,8 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
ulongArrayOf(ciphertextLength.convert()).toCValues(),
|
||||
message.toCValues(),
|
||||
message.size.convert(),
|
||||
additionalData.toCValues(),
|
||||
additionalData.size.convert(),
|
||||
associatedData.toCValues(),
|
||||
associatedData.size.convert(),
|
||||
null,
|
||||
nonce.toCValues(),
|
||||
key.toCValues()
|
||||
@@ -41,7 +41,7 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
key: UByteArray,
|
||||
nonce: UByteArray,
|
||||
ciphertext: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): UByteArray {
|
||||
val messageLength = ciphertext.size - crypto_aead_xchacha20poly1305_IETF_ABYTES.toInt()
|
||||
val message = UByteArray(messageLength)
|
||||
@@ -52,8 +52,8 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
null,
|
||||
ciphertext.toCValues(),
|
||||
ciphertext.size.convert(),
|
||||
additionalData.toCValues(),
|
||||
additionalData.size.convert(),
|
||||
associatedData.toCValues(),
|
||||
associatedData.size.convert(),
|
||||
nonce.toCValues(),
|
||||
key.toCValues()
|
||||
)
|
||||
@@ -112,7 +112,7 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
}
|
||||
|
||||
|
||||
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
||||
actual fun encrypt(data: UByteArray, associatedData: UByteArray): UByteArray {
|
||||
val ciphertextWithTag = UByteArray(data.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt())
|
||||
val ciphertextWithTagPinned = ciphertextWithTag.pin()
|
||||
crypto_secretstream_xchacha20poly1305_push(
|
||||
@@ -121,8 +121,8 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
null,
|
||||
data.toCValues(),
|
||||
data.size.convert(),
|
||||
additionalData.toCValues(),
|
||||
additionalData.size.convert(),
|
||||
associatedData.toCValues(),
|
||||
associatedData.size.convert(),
|
||||
0U,
|
||||
)
|
||||
println("Encrypt partial")
|
||||
@@ -132,7 +132,7 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
return ciphertextWithTag
|
||||
}
|
||||
|
||||
actual fun decrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
||||
actual fun decrypt(data: UByteArray, associatedData: UByteArray): UByteArray {
|
||||
val plaintext = UByteArray(data.size - crypto_secretstream_xchacha20poly1305_ABYTES.toInt())
|
||||
val plaintextPinned = plaintext.pin()
|
||||
val validTag = crypto_secretstream_xchacha20poly1305_pull(
|
||||
@@ -142,8 +142,8 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||
null,
|
||||
data.toCValues(),
|
||||
data.size.convert(),
|
||||
additionalData.toCValues(),
|
||||
additionalData.size.convert()
|
||||
associatedData.toCValues(),
|
||||
associatedData.size.convert()
|
||||
)
|
||||
plaintextPinned.unpin()
|
||||
println("tag: $validTag")
|
||||
|
||||
Reference in new issue
Block a user