@ -26,6 +26,8 @@
* /
package net.java.sip.communicator.impl.neomedia.transform.srtp ;
import java.util.Arrays ;
import net.java.sip.communicator.impl.neomedia.* ;
import org.bouncycastle.crypto.* ;
@ -256,23 +258,23 @@ public SRTPCryptoContext(long ssrcIn, int rocIn, long kdr,
saltKey = null ;
break ;
case SRTPPolicy . AESF8_ENCRYPTION :
cipherF8 = new AESFastEngine ( ) ;
//$FALL-THROUGH$
case SRTPPolicy . AESCM_ENCRYPTION :
cipher = new AESFastEngine ( ) ;
encKey = new byte [ policy . getEncKeyLength ( ) ] ;
saltKey = new byte [ policy . getSaltKeyLength ( ) ] ;
//$FALL-THROUGH$
case SRTPPolicy . AESF8_ENCRYPTION :
cipherF8 = new AESFastEngine ( ) ;
break ;
case SRTPPolicy . TWOFISHF8_ENCRYPTION :
cipherF8 = new TwofishEngine ( ) ;
case SRTPPolicy . TWOFISH_ENCRYPTION :
cipher = new TwofishEngine ( ) ;
encKey = new byte [ this . policy . getEncKeyLength ( ) ] ;
saltKey = new byte [ this . policy . getSaltKeyLength ( ) ] ;
case SRTPPolicy . TWOFISHF8_ENCRYPTION :
cipherF8 = new TwofishEngine ( ) ;
break ;
}
@ -553,9 +555,8 @@ public void processPacketAESF8(RawPacket pkt)
final int payloadOffset = pkt . getHeaderLength ( ) ;
final int payloadLength = pkt . getPayloadLength ( ) ;
SRTPCipherF8 . process ( cipher , pkt . getBuffer ( ) , pkt . getOffset ( ) +
payloadOffset , payloadLength , ivStore , encKey , saltKey ,
cipherF8 ) ;
SRTPCipherF8 . process ( cipher , pkt . getBuffer ( ) , pkt . getOffset ( ) + payloadOffset ,
payloadLength , ivStore , cipherF8 ) ;
}
/ * *
@ -675,8 +676,9 @@ public void deriveSrtpKeys(long index)
KeyParameter encryptionKey = new KeyParameter ( masterKey ) ;
cipher . init ( true , encryptionKey ) ;
cipherCtr . getCipherStream ( cipher , encKey , policy . getEncKeyLength ( ) ,
ivStore ) ;
Arrays . fill ( masterKey , ( byte ) 0 ) ;
cipherCtr . getCipherStream ( cipher , encKey , policy . getEncKeyLength ( ) , ivStore ) ;
// compute the session authentication key
if ( authKey ! = null )
@ -702,15 +704,20 @@ public void deriveSrtpKeys(long index)
break ;
}
}
Arrays . fill ( authKey , ( byte ) 0 ) ;
// compute the session salt
label = 0x02 ;
computeIv ( label , index ) ;
cipherCtr . getCipherStream ( cipher , saltKey , policy . getSaltKeyLength ( ) ,
ivStore ) ;
cipherCtr . getCipherStream ( cipher , saltKey , policy . getSaltKeyLength ( ) , ivStore ) ;
Arrays . fill ( masterSalt , ( byte ) 0 ) ;
// As last step: initialize cipher with derived encryption key.
if ( cipherF8 ! = null )
SRTPCipherF8 . deriveForIV ( cipherF8 , encKey , saltKey ) ;
encryptionKey = new KeyParameter ( encKey ) ;
cipher . init ( true , encryptionKey ) ;
Arrays . fill ( encKey , ( byte ) 0 ) ;
}
/ * *