Skip to content

Commit 32a8f08

Browse files
committed
chore: be explicit with cipher mode
1 parent 7eee1b7 commit 32a8f08

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/ChaCha20ParamFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ConnectBot SSH Library
3-
* Copyright 2025 Kenny Root
3+
* Copyright 2025-2026 Kenny Root
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ internal object ChaCha20ParamFactory {
4040
val testParams = ctor.newInstance(testNonce, 0) as AlgorithmParameterSpec
4141
val testKeySpec = SecretKeySpec(testKey, "ChaCha20")
4242

43-
val testCipher = Cipher.getInstance("ChaCha20")
43+
val testCipher = Cipher.getInstance("ChaCha20/None/NoPadding")
4444
testCipher.init(Cipher.DECRYPT_MODE, testKeySpec, testParams)
4545

4646
useSpec = true

sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/ChaCha20Poly1305Cipher.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ConnectBot SSH Library
3-
* Copyright 2025 Kenny Root
3+
* Copyright 2025-2026 Kenny Root
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -35,6 +35,8 @@ internal class ChaCha20Poly1305Cipher(private val key: ByteArray) : PacketAead {
3535
const val KEY_SIZE = 64
3636
const val TAG_SIZE = 16
3737
const val BLOCK_SIZE = 8
38+
const val KEYSPEC_ALGO = "ChaCha20"
39+
const val CIPHER_ALGO = "ChaCha20/None/NoPadding"
3840
}
3941

4042
override val tagLength: Int = TAG_SIZE
@@ -58,12 +60,12 @@ internal class ChaCha20Poly1305Cipher(private val key: ByteArray) : PacketAead {
5860
init {
5961
require(key.size == KEY_SIZE) { "ChaCha20-Poly1305 requires 64 bytes of key material" }
6062

61-
mainKeySpec = SecretKeySpec(key, 0, 32, "ChaCha20")
62-
headerKeySpec = SecretKeySpec(key, 32, 32, "ChaCha20")
63+
mainKeySpec = SecretKeySpec(key, 0, 32, KEYSPEC_ALGO)
64+
headerKeySpec = SecretKeySpec(key, 32, 32, KEYSPEC_ALGO)
6365

64-
headerCipher = Cipher.getInstance("ChaCha20")
65-
polyKeyCipher = Cipher.getInstance("ChaCha20")
66-
payloadCipher = Cipher.getInstance("ChaCha20")
66+
headerCipher = Cipher.getInstance(CIPHER_ALGO)
67+
polyKeyCipher = Cipher.getInstance(CIPHER_ALGO)
68+
payloadCipher = Cipher.getInstance(CIPHER_ALGO)
6769
}
6870

6971
private fun updateNonce(seqNum: Long) {

0 commit comments

Comments
 (0)