You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GH-455: ensure BaseCipher.update() fulfills the contract
The org.apache.sshd.common.cipher.Cipher interface specifies for
update(byte[] buffer, int offset, int length) that length bytes are
encrypted or decrypted in-place in the given buffer, starting at the
given offset.
The BaseCipher implementation just called javax.crypto.Cipher.update().
That, however, may buffer blocks and not update all data right away.
(For instance, AES pipelined implementations may behave that way.)
Buffered blocks may be returned/updated in subsequent update() calls.
To ensure that really all bytes given are updated, one needs to call
doFinal(), which always returns/updates such buffered blocks.
But javax.crypto.Cipher.doFinal() resets the cipher to its initial
state. For use in SSH, this is not appropriate: the cipher must be
reset not to the initial state but to the final state. This is done
for CTR ciphers by adding the number of processed blocks to the initial
IV and then using that IV for re-initialization. For CBC ciphers, the
re-initialization IV must be the last encrypted block processed.
Note that in CTR mode, we cannot check for IV re-use. This is not a
problem in practice because in the SSH protocol key exchanges happen
long before an IV can wrap around.
0 commit comments