Exemplo n.º 1
0
        /**
         * Perform Counter Mode AES encryption / decryption
         *
         * @param pkt
         *            the RTP packet to be encrypted / decrypted
         */
        public void ProcessPacketAESCM(RawPacket pkt)
        {
            long ssrc  = pkt.GetSSRC();
            int  seqNo = pkt.GetSequenceNumber();

#pragma warning disable CS0675 // Bitwise-or operator used on a sign-extended operand
            long index = ((long)roc << 16) | seqNo;
#pragma warning restore CS0675 // Bitwise-or operator used on a sign-extended operand

            ivStore[0] = saltKey[0];
            ivStore[1] = saltKey[1];
            ivStore[2] = saltKey[2];
            ivStore[3] = saltKey[3];

            int i;
            for (i = 4; i < 8; i++)
            {
                ivStore[i] = (byte)((0xFF & (ssrc >> ((7 - i) * 8))) ^ this.saltKey[i]);
            }

            for (i = 8; i < 14; i++)
            {
                ivStore[i] = (byte)((0xFF & (byte)(index >> ((13 - i) * 8))) ^ this.saltKey[i]);
            }

            ivStore[14] = ivStore[15] = 0;

            int payloadOffset = pkt.GetHeaderLength();
            int payloadLength = pkt.GetPayloadLength();

            cipherCtr.Process(cipher, pkt.GetBuffer(), payloadOffset, payloadLength, ivStore);
        }
Exemplo n.º 2
0
        public byte[] Transform(byte[] pkt, int offset, int length)
        {
            // Updates the contents of raw packet with new incoming packet
            this.rawPacket.Wrap(pkt, offset, length);

            // Associate packet to a crypto context
            long ssrc = rawPacket.GetSSRC();
            SrtpCryptoContext context = null;

            contexts.TryGetValue(ssrc, out context);

            if (context == null)
            {
                context = forwardEngine.GetDefaultContext().deriveContext(ssrc, 0, 0);
                context.DeriveSrtpKeys(0);
                contexts[ssrc] = context;
            }

            // Transform RTP packet into SRTP
            context.TransformPacket(this.rawPacket);
            return(this.rawPacket.GetData());
        }