Cleanup 1

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-07-04 19:05:15 +02:00
1 parent a1a56487ff
commit 2db5523893
9 files changed
+19 -172

No files matched your search

@@ -171,32 +171,14 @@ object Crypto {
class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKey, additionalData: UByteArray) : MultipartAuthenticatedEncryption {
val primitive = XChaCha20Poly1305Delegated(key.value, additionalData)
override fun encryptPartialData(data: UByteArray): EncryptedDataPart {
return EncryptedDataPart(primitive.encryptPartialData(data))
}
override fun finish(): MultipartEncryptedDataDescriptor {
val finished = primitive.finishEncryption()
return MultipartEncryptedDataDescriptor(finished.first, finished.second)
return EncryptedDataPart(primitive.encrypt(data))
}
}
class MultiplatformAuthenticatedVerificator internal constructor(key: SymmetricKey, multipartEncryptedDataDescriptor: MultipartEncryptedDataDescriptor, additionalData: UByteArray) : MultipartAuthenticatedVerification {
val primitive = XChaCha20Poly1305Delegated(key.value, additionalData)
val tag = multipartEncryptedDataDescriptor.data.sliceArray(
multipartEncryptedDataDescriptor.data.size - 16 until multipartEncryptedDataDescriptor.data.size
)
override fun verifyPartialData(data: EncryptedDataPart) {
primitive.verifyPartialData(data.data)
}
override fun finalizeVerificationAndPrepareDecryptor(): MultipartAuthenticatedDecryption {
primitive.checkTag(tag)
return MultipartAuthenticatedDecryptor(primitive)
}
}
class MultipartAuthenticatedDecryptor internal constructor(val encryptor: XChaCha20Poly1305Delegated) : MultipartAuthenticatedDecryption {
override fun decryptPartialData(data: EncryptedDataPart): DecryptedDataPart {
@@ -13,11 +13,9 @@ expect class XChaCha20Poly1305Delegated constructor(key: UByteArray, additionalD
fun decrypt(key: UByteArray, nonce: UByteArray, ciphertext: UByteArray, additionalData: UByteArray) : UByteArray
}
fun encryptPartialData(data: UByteArray) : UByteArray
fun verifyPartialData(data: UByteArray)
fun checkTag(expectedTag: UByteArray)
fun encrypt(data: UByteArray) : UByteArray
fun decrypt(data: UByteArray) : UByteArray
fun finishEncryption() : Pair<UByteArray, UByteArray>
}
@@ -4,8 +4,6 @@ import com.ionspin.kotlin.crypto.CryptoInitializerDelegated
import com.ionspin.kotlin.crypto.hash.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.hexColumsPrint
import com.ionspin.kotlin.crypto.util.testBlocking
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertTrue
@@ -145,7 +143,7 @@ class XChaCha20Poly1305Test {
0xcfU, 0x49U
)
val xChaChaPoly = XChaCha20Poly1305Delegated(key, additionalData)
val firstChunk = xChaChaPoly.encryptPartialData(message)
val firstChunk = xChaChaPoly.encrypt(message)
val finalChunk = xChaChaPoly.finishEncryption().first
val result = firstChunk + finalChunk
@@ -176,7 +174,7 @@ class XChaCha20Poly1305Test {
0x84U, 0x6fU, 0xfcU, 0x75U, 0x31U, 0xbfU, 0x0cU, 0x2dU
)
val xChaChaPoly = XChaCha20Poly1305Delegated(key, additionalData)
val firstChunk = xChaChaPoly.encryptPartialData(message)
val firstChunk = xChaChaPoly.encrypt(message)
val finalChunk = xChaChaPoly.finishEncryption().first
val result = firstChunk + finalChunk
result.contentEquals(expected)
@@ -55,7 +55,7 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, addi
}
actual fun encryptPartialData(data: UByteArray): UByteArray {
actual fun encrypt(data: UByteArray): UByteArray {
TODO("not implemented yet")
}
@@ -59,7 +59,7 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, addi
}
actual fun encryptPartialData(data: UByteArray): UByteArray {
actual fun encrypt(data: UByteArray): UByteArray {
TODO("not implemented yet")
}
@@ -97,7 +97,7 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray,v
}
actual fun encryptPartialData(data: UByteArray): UByteArray {
actual fun encrypt(data: UByteArray): UByteArray {
val ciphertextWithTag = UByteArray(data.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt())
val ciphertextWithTagPinned = ciphertextWithTag.pin()
crypto_secretstream_xchacha20poly1305_push(