Re-enables benchmark with native android ChaCha functions

This commit is contained in:
Vitor Pamplona
2026-03-25 11:17:17 -04:00
parent 60a44d25eb
commit 617db3613f
2 changed files with 25 additions and 30 deletions
@@ -27,9 +27,12 @@ import com.vitorpamplona.quartz.nip01Core.crypto.Nip01Crypto
import com.vitorpamplona.quartz.nip44Encryption.Nip44v2
import com.vitorpamplona.quartz.nip44Encryption.crypto.ChaCha20
import com.vitorpamplona.quartz.utils.RandomInstance
import com.vitorpamplona.quartz.utils.mac.FixedKey
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
@RunWith(AndroidJUnit4::class)
class ChaCha20Benchmark {
@@ -58,15 +61,12 @@ class ChaCha20Benchmark {
}
}
/*
Removed in the conversion to KMP
@Test
fun encryptNative() {
benchmarkRule.measureRepeated {
chaCha.encryptNative(padded, messageKeys.chachaNonce, messageKeys.chachaKey)
encryptNative(padded, messageKeys.chachaNonce, messageKeys.chachaKey)
}
}
*/
@Test
fun decryptLibSodium() {
@@ -75,13 +75,30 @@ class ChaCha20Benchmark {
}
}
/*
Removed in the conversion to KMP
@Test
fun decryptNative() {
benchmarkRule.measureRepeated {
chaCha.decryptNative(padded, messageKeys.chachaNonce, messageKeys.chachaKey)
decryptNative(padded, messageKeys.chachaNonce, messageKeys.chachaKey)
}
}
*/
fun encryptNative(
message: ByteArray,
nonce: ByteArray,
key: ByteArray,
): ByteArray {
val cipher = Cipher.getInstance("ChaCha20")
cipher.init(Cipher.ENCRYPT_MODE, FixedKey(key, "ChaCha20"), IvParameterSpec(nonce))
return cipher.doFinal(message)
}
fun decryptNative(
message: ByteArray,
nonce: ByteArray,
key: ByteArray,
): ByteArray {
val cipher = Cipher.getInstance("ChaCha20")
cipher.init(Cipher.DECRYPT_MODE, FixedKey(key, "ChaCha20"), IvParameterSpec(nonce))
return cipher.doFinal(message)
}
}
@@ -38,28 +38,6 @@ class ChaCha20 {
key: ByteArray,
) = decryptLibSodium(message, nonce, key)
/*
fun encryptNative(
message: ByteArray,
nonce: ByteArray,
key: ByteArray,
): ByteArray {
val cipher = Cipher.getInstance("ChaCha20")
cipher.init(Cipher.ENCRYPT_MODE, FixedKey(key, "ChaCha20"), IvParameterSpec(nonce))
return cipher.doFinal(message)
}
fun decryptNative(
message: ByteArray,
nonce: ByteArray,
key: ByteArray,
): ByteArray {
val cipher = Cipher.getInstance("ChaCha20")
cipher.init(Cipher.DECRYPT_MODE, FixedKey(key, "ChaCha20"), IvParameterSpec(nonce))
return cipher.doFinal(message)
}
*/
fun encryptLibSodium(
message: ByteArray,
nonce: ByteArray,