コード例 #1
0
        /**
         * Derives the srtp session keys from the master key
         *
         * @param index
         *            the 48 bit SRTP packet index
         */
        public void DeriveSrtpKeys(long index)
        {
            // compute the session encryption key
            long label = 0;

            ComputeIv(label, index);

            KeyParameter encryptionKey = new KeyParameter(masterKey);

            cipher.Init(true, encryptionKey);
            Arrays.Fill(masterKey, (byte)0);

            cipherCtr.GetCipherStream(cipher, encKey, policy.EncKeyLength, ivStore);

            // compute the session authentication key
            if (authKey != null)
            {
                label = 0x01;
                ComputeIv(label, index);
                cipherCtr.GetCipherStream(cipher, authKey, policy.AuthKeyLength, ivStore);

                switch ((policy.AuthType))
                {
                case SrtpPolicy.HMACSHA1_AUTHENTICATION:
                    KeyParameter key = new KeyParameter(authKey);
                    mac.Init(key);
                    break;

                default:
                    break;
                }
            }

            Arrays.Fill(authKey, (byte)0);

            // compute the session salt
            label = 0x02;
            ComputeIv(label, index);
            cipherCtr.GetCipherStream(cipher, saltKey, policy.SaltKeyLength, 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);
        }