@@ -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