Skip to content

Commit 32b4e12

Browse files
Streamlined ChachaPolyCipher.update() method
1 parent 243f64c commit 32b4e12

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/main/java/com/hierynomus/sshj/transport/cipher/ChachaPolyCipher.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,15 @@ public void update(byte[] input, int inputOffset, int inputLen) {
147147
if (!MessageDigest.isEqual(actualPolyTag, expectedPolyTag)) {
148148
throw new SSHRuntimeException("MAC Error");
149149
}
150+
}
150151

151-
try {
152-
cipher.update(input, inputOffset, inputLen, input, inputOffset);
153-
} catch (GeneralSecurityException e) {
154-
throw new SSHRuntimeException("ChaCha20 decryption failed", e);
155-
}
156-
} else {
157-
try {
158-
cipher.update(input, inputOffset, inputLen, input, inputOffset);
159-
} catch (GeneralSecurityException e) {
160-
throw new SSHRuntimeException("ChaCha20 encryption failed", e);
161-
}
152+
try {
153+
cipher.update(input, inputOffset, inputLen, input, inputOffset);
154+
} catch (GeneralSecurityException e) {
155+
throw new SSHRuntimeException("ChaCha20 cipher processing failed", e);
156+
}
162157

158+
if (mode == Mode.Encrypt) {
163159
byte[] macInput = Arrays.copyOf(input, macInputLength);
164160
byte[] polyTag = mac.doFinal(macInput);
165161
System.arraycopy(polyTag, 0, input, macInputLength, POLY_TAG_LENGTH);

0 commit comments

Comments
 (0)