Example usage for org.bouncycastle.crypto.macs SkeinMac SkeinMac

List of usage examples for org.bouncycastle.crypto.macs SkeinMac SkeinMac

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.macs SkeinMac SkeinMac.

Prototype

SkeinMac

Source Link

Usage

From source file:net.java.sip.communicator.impl.neomedia.transform.srtp.SRTCPCryptoContext.java

License:LGPL

/**
 * Construct a normal SRTPCryptoContext based on the given parameters.
 * /*from   www  .j  a  v a  2  s.c  o  m*/
 * @param ssrc
 *            the RTP SSRC that this SRTP cryptographic context protects.
 * @param masterKey
 *            byte array holding the master key for this SRTP cryptographic
 *            context. Refer to chapter 3.2.1 of the RFC about the role of
 *            the master key.
 * @param masterSalt
 *            byte array holding the master salt for this SRTP cryptographic
 *            context. It is used to computer the initialization vector that
 *            in turn is input to compute the session key, session
 *            authentication key and the session salt.
 * @param policy
 *            SRTP policy for this SRTP cryptographic context, defined the
 *            encryption algorithm, the authentication algorithm, etc
 */
@SuppressWarnings("fallthrough")
public SRTCPCryptoContext(long ssrcIn, byte[] masterK, byte[] masterS, SRTPPolicy policyIn) {
    ssrcCtx = ssrcIn;
    mki = null;

    policy = policyIn;

    masterKey = new byte[policy.getEncKeyLength()];
    System.arraycopy(masterK, 0, masterKey, 0, policy.getEncKeyLength());

    masterSalt = new byte[policy.getSaltKeyLength()];
    System.arraycopy(masterS, 0, masterSalt, 0, policy.getSaltKeyLength());

    switch (policy.getEncType()) {
    case SRTPPolicy.NULL_ENCRYPTION:
        encKey = null;
        saltKey = null;
        break;

    case SRTPPolicy.AESF8_ENCRYPTION:
        cipherF8 = new AESFastEngine();

    case SRTPPolicy.AESCM_ENCRYPTION:
        cipher = new AESFastEngine();
        encKey = new byte[this.policy.getEncKeyLength()];
        saltKey = new byte[this.policy.getSaltKeyLength()];
        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()];
        break;
    }

    switch (policy.getAuthType()) {
    case SRTPPolicy.NULL_AUTHENTICATION:
        authKey = null;
        tagStore = null;
        break;

    case SRTPPolicy.HMACSHA1_AUTHENTICATION:
        mac = new HMac(new SHA1Digest());
        authKey = new byte[policy.getAuthKeyLength()];
        tagStore = new byte[mac.getMacSize()];
        break;

    case SRTPPolicy.SKEIN_AUTHENTICATION:
        mac = new SkeinMac();
        authKey = new byte[policy.getAuthKeyLength()];
        tagStore = new byte[policy.getAuthTagLength()];
        break;

    default:
        tagStore = null;
    }
}

From source file:net.java.sip.communicator.impl.neomedia.transform.srtp.SRTPCryptoContext.java

License:LGPL

/**
 * Construct a normal SRTPCryptoContext based on the given parameters.
 *
 * @param ssrcIn/*from ww  w . j ava2s  .  co  m*/
 *            the RTP SSRC that this SRTP cryptographic context protects.
 * @param rocIn
 *            the initial Roll-Over-Counter according to RFC 3711. These are
 *            the upper 32 bit of the overall 48 bit SRTP packet index.
 *            Refer to chapter 3.2.1 of the RFC.
 * @param kdr
 *            the key derivation rate defines when to recompute the SRTP
 *            session keys. Refer to chapter 4.3.1 in the RFC.
 * @param masterK
 *            byte array holding the master key for this SRTP cryptographic
 *            context. Refer to chapter 3.2.1 of the RFC about the role of
 *            the master key.
 * @param masterS
 *            byte array holding the master salt for this SRTP cryptographic
 *            context. It is used to computer the initialization vector that
 *            in turn is input to compute the session key, session
 *            authentication key and the session salt.
 * @param policyIn
 *            SRTP policy for this SRTP cryptographic context, defined the
 *            encryption algorithm, the authentication algorithm, etc
 */
@SuppressWarnings("fallthrough")
public SRTPCryptoContext(long ssrcIn, int rocIn, long kdr, byte[] masterK, byte[] masterS,
        SRTPPolicy policyIn) {
    ssrcCtx = ssrcIn;
    mki = null;
    roc = rocIn;
    guessedROC = 0;
    seqNum = 0;
    keyDerivationRate = kdr;
    seqNumSet = false;

    policy = policyIn;

    masterKey = new byte[policy.getEncKeyLength()];
    System.arraycopy(masterK, 0, masterKey, 0, policy.getEncKeyLength());

    masterSalt = new byte[policy.getSaltKeyLength()];
    System.arraycopy(masterS, 0, masterSalt, 0, policy.getSaltKeyLength());

    mac = new HMac(new SHA1Digest());

    switch (policy.getEncType()) {
    case SRTPPolicy.NULL_ENCRYPTION:
        encKey = null;
        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()];
        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()];
        break;
    }

    switch (policy.getAuthType()) {
    case SRTPPolicy.NULL_AUTHENTICATION:
        authKey = null;
        tagStore = null;
        break;

    case SRTPPolicy.HMACSHA1_AUTHENTICATION:
        mac = new HMac(new SHA1Digest());
        authKey = new byte[policy.getAuthKeyLength()];
        tagStore = new byte[mac.getMacSize()];
        break;

    case SRTPPolicy.SKEIN_AUTHENTICATION:
        mac = new SkeinMac();
        authKey = new byte[policy.getAuthKeyLength()];
        tagStore = new byte[policy.getAuthTagLength()];
        break;

    default:
        tagStore = null;
    }
}