Make sure "previous counter" is never negative.

This commit is contained in:
Moxie Marlinspike 2014-07-22 17:48:02 -07:00
parent 4caebdcd06
commit c94a7b1eff

View File

@ -261,7 +261,7 @@ public class SessionCipher {
sessionState.setRootKey(senderChain.first());
sessionState.addReceiverChain(theirEphemeral, receiverChain.second());
sessionState.setPreviousCounter(sessionState.getSenderChainKey().getIndex()-1);
sessionState.setPreviousCounter(Math.max(sessionState.getSenderChainKey().getIndex()-1, 0));
sessionState.setSenderChain(ourNewEphemeral, senderChain.second());
return receiverChain.second();