Add state cleanup for delegated and pure. There doesn't seem to be a easy way to clean js state

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-07-10 22:08:08 +02:00
1 parent 1293b9ea75
commit 52b6a4ad8e
11 files changed
+51 -6

No files matched your search

@@ -137,6 +137,10 @@ class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKe
override fun startEncryption(): MultipartEncryptionHeader {
return header
}
override fun cleanup() {
primitive.cleanup()
}
}
class MultipartAuthenticatedDecryptor internal constructor(val decryptor: XChaCha20Poly1305Pure) : MultipartAuthenticatedDecryption {
@@ -144,4 +148,8 @@ class MultipartAuthenticatedDecryptor internal constructor(val decryptor: XChaCh
return DecryptedDataPart(decryptor.streamDecrypt(data.data, additionalData, 0U))
}
override fun cleanup() {
decryptor.cleanup()
}
}
@@ -84,6 +84,8 @@ class XChaCha20Poly1305Pure(val key: UByteArray, val nonce: UByteArray) {
calcNonce[1] = 0U
calcNonce[2] = 0U
calcNonce[3] = 0U
key.overwriteWithZeroes()
nonce.overwriteWithZeroes()
println("Calckey-------=")
calcKey.hexColumsPrint()
println("Calckey-------=")
@@ -184,6 +186,13 @@ class XChaCha20Poly1305Pure(val key: UByteArray, val nonce: UByteArray) {
return plaintext
}
fun cleanup() {
key.overwriteWithZeroes()
nonce.overwriteWithZeroes()
calcKey.overwriteWithZeroes()
calcNonce.overwriteWithZeroes()
}
private fun processPolyBytes(updateableMacPrimitive: Poly1305, data: UByteArray) {