norrisjeremy commented on a change in pull request #173:
URL: https://github.com/apache/mina-sshd/pull/173#discussion_r504054808



##########
File path: 
sshd-common/src/main/java/org/apache/sshd/common/cipher/BaseGCMCipher.java
##########
@@ -78,19 +78,25 @@ public void update(byte[] input, int inputOffset, int 
inputLen) throws Exception
      */
     protected static class CounterGCMParameterSpec extends GCMParameterSpec {
         protected final byte[] iv;
+        protected final long initialCounter;
 
         protected CounterGCMParameterSpec(int tLen, byte[] src) {
             super(tLen, src);
             if (src.length != 12) {
                 throw new IllegalArgumentException("GCM nonce must be 12 
bytes, but given len=" + src.length);
             }
             iv = src.clone();
+            initialCounter = BufferUtils.getLong(iv, iv.length - Long.BYTES, 
Long.BYTES);
         }
 
         protected void incrementCounter() {
             int off = iv.length - Long.BYTES;
             long counter = BufferUtils.getLong(iv, off, Long.BYTES);
-            BufferUtils.putLong(Math.addExact(counter, 1L), iv, off, 
Long.BYTES);
+            long newCounter = counter + 1L;
+            if (newCounter == initialCounter) {

Review comment:
       Yes, I agree, but I figured it would be better to be safer than sorry 
incase there was some sort of misuse or issue in the future, since IV reuse 
could be disastrous.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to