From 156bd0676312e36f0ec04e943744e8604e78ec8c Mon Sep 17 00:00:00 2001 From: Werner Dittmann Date: Wed, 4 Feb 2009 13:32:48 +0000 Subject: [PATCH] Fix handling of roll-over-counter. Sequence numbers are unsigned short, thus store them as unsigned short (mask with 0xffff). Add missing code to handle replay checks. --- .../media/transform/srtp/SRTPCryptoContext.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/net/java/sip/communicator/impl/media/transform/srtp/SRTPCryptoContext.java b/src/net/java/sip/communicator/impl/media/transform/srtp/SRTPCryptoContext.java index 8648e37cd..146595d0b 100755 --- a/src/net/java/sip/communicator/impl/media/transform/srtp/SRTPCryptoContext.java +++ b/src/net/java/sip/communicator/impl/media/transform/srtp/SRTPCryptoContext.java @@ -561,7 +561,7 @@ boolean checkReplay(int seqNum) } long guessedIndex = guessIndex( seqNum ); - long localIndex = (((long)this.roc) << 16 & 0xFFFF) | this.seqNum; + long localIndex = ((long)this.roc) << 16 | this.seqNum; long delta = guessedIndex - localIndex; if (delta > 0) @@ -751,16 +751,25 @@ private long guessIndex(int seqNum) */ private void update(int seqNum) { - guessIndex(seqNum); + long delta = guessIndex(seqNum) - (((long) this.roc) << 16 | this.seqNum); + + /* update the replay bit mask */ + if( delta > 0 ){ + replayWindow = replayWindow << delta; + replayWindow |= 1; + } + else { + replayWindow |= ( 1 << delta ); + } if (seqNum > this.seqNum) { - this.seqNum = seqNum; + this.seqNum = seqNum & 0xffff; // make short } if (this.guessedROC > this.roc) { this.roc = this.guessedROC; - this.seqNum = seqNum; + this.seqNum = seqNum & 0xffff; // make short } }