Example usage for org.bouncycastle.crypto.engines TwofishEngine TwofishEngine

List of usage examples for org.bouncycastle.crypto.engines TwofishEngine TwofishEngine

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.engines TwofishEngine TwofishEngine.

Prototype

public TwofishEngine() 

Source Link

Usage

From source file:ECIESTest.java

public TestResult perform() {
    SecureRandom random = new SecureRandom();
    ECCurve.Fp curve = new ECCurve.Fp(
            new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
            new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
            new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    ECDomainParameters params = new ECDomainParameters(curve,
            curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
            new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n

    ECKeyPairGenerator pGen = new ECKeyPairGenerator();
    ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(params, random);

    pGen.init(genParam);/*from   ww  w. j  av a  2 s  . co  m*/

    AsymmetricCipherKeyPair p1 = pGen.generateKeyPair();
    AsymmetricCipherKeyPair p2 = pGen.generateKeyPair();

    //
    // stream test
    //
    IESEngine i1 = new IESEngine(new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()),
            new HMac(new SHA1Digest()));
    IESEngine i2 = new IESEngine(new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()),
            new HMac(new SHA1Digest()));
    byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
    IESParameters p = new IESParameters(d, e, 64);

    i1.init(true, p1.getPrivate(), p2.getPublic(), p);
    i2.init(false, p2.getPrivate(), p1.getPublic(), p);

    byte[] message = Hex.decode("1234567890abcdef");

    try {
        byte[] out1 = i1.processBlock(message, 0, message.length);

        byte[] out2 = i2.processBlock(out1, 0, out1.length);

        if (!sameAs(out2, message)) {
            return new SimpleTestResult(false, this.getName() + ": stream cipher test failed");
        }

    } catch (Exception ex) {
        return new SimpleTestResult(false, this.getName() + ": stream cipher test exception " + ex.toString());
    }

    //
    // twofish with IV0 test
    //
    BufferedBlockCipher c1 = new PaddedBufferedBlockCipher(new CBCBlockCipher(new TwofishEngine()));
    BufferedBlockCipher c2 = new PaddedBufferedBlockCipher(new CBCBlockCipher(new TwofishEngine()));
    i1 = new IESEngine(new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()),
            new HMac(new SHA1Digest()), c1);
    i2 = new IESEngine(new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()),
            new HMac(new SHA1Digest()), c2);
    d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
    p = new IESWithCipherParameters(d, e, 64, 128);

    i1.init(true, p1.getPrivate(), p2.getPublic(), p);
    i2.init(false, p2.getPrivate(), p1.getPublic(), p);

    message = Hex.decode("1234567890abcdef");

    try {
        byte[] out1 = i1.processBlock(message, 0, message.length);

        byte[] out2 = i2.processBlock(out1, 0, out1.length);

        if (!sameAs(out2, message)) {
            return new SimpleTestResult(false, this.getName() + ": twofish cipher test failed");
        }
    } catch (Exception ex) {
        return new SimpleTestResult(false, this.getName() + ": twofish cipher test exception " + ex.toString());
    }

    return new SimpleTestResult(true, this.getName() + ": Okay");
}

From source file:cologne.eck.peafactory.gui.Menu.java

License:Open Source License

@Override
public void actionPerformed(ActionEvent ape) {

    //JComponent source = (JComponent) ape.getSource();
    String command = ape.getActionCommand();

    //Menu/*from   ww w . ja  v a  2 s. co  m*/
    if (command.equals("newProject")) {
        ProjectSelection proj = new ProjectSelection();
        Point p = MainView.getFrameLocation();
        proj.setLocation((int) p.getX() + 100, (int) p.getY() + 60);
        proj.setVisible(true);
    } else if (command.equals("randomPassword")) {
        PasswordGeneratorDialog pg = new PasswordGeneratorDialog(PeaFactory.getFrame());
        pg.setVisible(true);
    } else if (command.equals("keyboard")) {
        int input = JOptionPane.showConfirmDialog(PeaFactory.getFrame(),
                languageBundle.getString("add_keyboard"), " ", JOptionPane.YES_NO_OPTION);
        if (input == 0) {
            FileModifier.setSetKeyboard(true);
        } else {
            FileModifier.setSetKeyboard(false);
        }
    } else if (command.equals("psw_generator")) {
        int input = JOptionPane.showConfirmDialog(PeaFactory.getFrame(),
                languageBundle.getString("add_psw_generator"), " ", JOptionPane.YES_NO_OPTION);
        if (input == 0) {
            FileModifier.setPswGenerator(true);
        } else {
            FileModifier.setPswGenerator(false);
        }
    } else if (command.equals("quit")) {
        System.exit(0);

    } else if (command.equals("generalPeaSettings")) {

        @SuppressWarnings("unused")
        GeneralPeaSettings imageSetting = new GeneralPeaSettings();

    } else if (command.equals("setThoughtless")) {
        securityLevel = 1;
        setSecurityLevel(1);
    } else if (command.equals("setLow")) {
        securityLevel = 2;
        setSecurityLevel(2);
    } else if (command.equals("setStandard")) {
        securityLevel = 3;
        setSecurityLevel(3);
    } else if (command.equals("setHigh")) {
        securityLevel = 4;
        setSecurityLevel(4);
    } else if (command.equals("setParanoid")) {
        securityLevel = 5;
        setSecurityLevel(5);

    } else if (command.equals("setBcrypt")) {
        setSecurityLevel(securityLevel);
        KeyDerivation.setKdf(new BcryptKDF());
    } else if (command.equals("setScrypt")) {
        setSecurityLevel(securityLevel);
        KeyDerivation.setKdf(new ScryptKDF());
    } else if (command.equals("setDragonfly")) {
        setSecurityLevel(securityLevel);
        CatenaKDF.setVersionID("Dragonfly-Full");
        KeyDerivation.setKdf(new CatenaKDF());
    } else if (command.equals("setButterfly")) {
        setSecurityLevel(securityLevel);
        CatenaKDF.setVersionID("Butterfly-Full");
        KeyDerivation.setKdf(new CatenaKDF());
    } else if (command.equals("setPomelo")) {
        setSecurityLevel(securityLevel);
        KeyDerivation.setKdf(new PomeloKDF());

    } else if (command.equals("setBcryptParameters")) {

        @SuppressWarnings("unused")
        BcryptSetting bcryptSetting = new BcryptSetting();

    } else if (command.equals("setPomeloParameters")) {

        @SuppressWarnings("unused")
        PomeloSetting pomeloSetting = new PomeloSetting();

    } else if (command.equals("setScryptParameters")) {

        @SuppressWarnings("unused")
        ScryptSetting scryptSetting = new ScryptSetting();

    } else if (command.equals("setCatenaParameters")) {

        @SuppressWarnings("unused")
        CatenaSetting catenaSetting = new CatenaSetting();

    } else if (command.equals("setImageParameters")) {

        @SuppressWarnings("unused")
        ImageSetting imageSetting = new ImageSetting();

    } else if (command.equals("setShacal2")) {
        CipherStuff.setCipherAlgo(new Shacal2Engine());
    } else if (command.equals("setThreefish256")) {
        CipherStuff.setCipherAlgo(new ThreefishEngine(256));
    } else if (command.equals("setThreefish512")) {
        CipherStuff.setCipherAlgo(new ThreefishEngine(512));
    } else if (command.equals("setThreefish1024")) {
        CipherStuff.setCipherAlgo(new ThreefishEngine(1024));
    } else if (command.equals("setTwofish")) {
        CipherStuff.setCipherAlgo(new TwofishEngine());
    } else if (command.equals("setSerpent")) {
        CipherStuff.setCipherAlgo(new SerpentEngine());
    } else if (command.equals("setAES")) {
        CipherStuff.setCipherAlgo(new AESEngine());
    } else if (command.equals("setAESFast")) {
        CipherStuff.setCipherAlgo(new AESFastEngine());

        // hash function:
    } else if (command.equals("setWhirlpool")) {
        HashStuff.setHashAlgo(new WhirlpoolDigest());
    } else if (command.equals("setKeccak")) {
        HashStuff.setHashAlgo(new SHA3Digest());
    } else if (command.equals("setSha512")) {
        HashStuff.setHashAlgo(new SHA512Digest());
    } else if (command.equals("setSha384")) {
        HashStuff.setHashAlgo(new SHA384Digest());
    } else if (command.equals("setSkein512")) {
        HashStuff.setHashAlgo(new SkeinDigest(512, 512));
    } else if (command.equals("setBlake512")) {
        HashStuff.setHashAlgo(new Blake2bDigest());
        //      } else if (command.equals("setRipemd256")) {
        //         HashStuff.setHashAlgo( new RIPEMD256Digest() );          
    } else if (command.equals("setRipemd320")) {
        HashStuff.setHashAlgo(new RIPEMD320Digest());

    } else if (command.equals("setDE")) {
        PeaFactory.setI18n("de");
    } else if (command.equals("setEN")) {
        PeaFactory.setI18n("en");

    } else if (command.equals("notes")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog(languageBundle.getString("notes_description"), null, "notes");
    } else if (command.equals("editor")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog(languageBundle.getString("editor_description"), null, "editor");
    } else if (command.equals("image")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog(languageBundle.getString("image_description"), null, "image");
    } else if (command.equals("keyboard_info")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog("Onscreen Keyboard", null, "keyboard");
    } else if (command.equals("file")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog(languageBundle.getString("file_description"), null, "file");

    } else if (command.equals("problemHelp")) {
        JOptionPane pane = new JOptionPane(languageBundle.getString("problem_help_dialog"),
                JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION, null, null);//new ImageIcon(PswDialogView.getImage()), null);
        pane.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
        //pane.setIconImage(PswDialogView.getImage());
        pane.setVisible(true);
        //pane.showMessageDialog(null, languageBundle.getString("problem_help_dialog"), null, JOptionPane.PLAIN_MESSAGE);
    } else if (command.equals("howToUse")) {
        JOptionPane.showMessageDialog(PeaFactory.getFrame(), languageBundle.getString("how_to_use_dialog"),
                null, JOptionPane.PLAIN_MESSAGE);
    } else if (command.equals("aboutLicense")) {
        JOptionPane.showMessageDialog(PeaFactory.getFrame(), languageBundle.getString("about_license_dialog"),
                null, JOptionPane.PLAIN_MESSAGE);
    }
}

From source file:com.javacreed.api.secureproperties.bouncycastle.TwoFishCipherFactory.java

License:Apache License

@Override
protected InputStream wrapInToCipheredInputStream(final InputStream in) throws Exception {
    final BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new TwofishEngine()));
    cipher.init(false, new KeyParameter(key.getBytes("UTF-8")));
    final CipherInputStream stream = new CipherInputStream(in, cipher);
    return stream;
}

From source file:com.javacreed.api.secureproperties.bouncycastle.TwoFishCipherFactory.java

License:Apache License

@Override
protected OutputStream wrapInToCipheredOutputStream(final OutputStream out) throws Exception {
    final BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new TwofishEngine()));
    cipher.init(true, new KeyParameter(key.getBytes("UTF-8")));
    final CipherOutputStream stream = new CipherOutputStream(out, cipher);
    return stream;
}

From source file:com.smedia.sqzserver.common.util.SerialNumber.java

public byte[] decrypt(String cookieValue, byte[] keyBytes)
        throws InvalidKeyException, UnsupportedEncodingException {
    byte[] encryptedData;
    byte[] decryptedData;
    TwofishEngine t = new TwofishEngine();

    // ///////////////////

    BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new TwofishEngine()));

    cipher.init(false, new KeyParameter(keyBytes));

    // create the key
    // byte[] keyBytes = key.getBytes();
    // Object keyObject = twofish.makeKey(keyBytes, 16);
    // make the length of the string a multiple of
    // the block size
    while (cookieValue.length() < (32 * 8 / 5)) {
        cookieValue += "A";
    }/*from  w  w  w.  j  a  v a 2s  . com*/
    // initialize byte arrays that will hold encrypted/decrypted
    // text

    encryptedData = sorensonBase32Decode(cookieValue);
    decryptedData = new byte[cookieValue.length() * 2];

    /*
     * int oLen = cipher.processBytes(encryptedData, 0,
     * encryptedData.length, decryptedData, 0); try {
     * cipher.doFinal(decryptedData, oLen); } catch (CryptoException ce) {
     * ce.printStackTrace(); }
     */
    // String test = new String(rv).trim();

    // ///

    encryptedData = sorensonBase32Decode(cookieValue);
    decryptedData = new byte[cookieValue.length() * 2];
    // Iterate over the byte arrays by 16-byte blocks and decrypt.
    for (int i = 0; i < Array.getLength(encryptedData); i += 16) {
        // twofish.decrypt(encryptedData, i, decryptedData, i, keyObject,
        // 16);

        cipher.processBytes(encryptedData, i, 16, decryptedData, 0);

    }

    return decryptedData;
}

From source file:de.gs_sys.kp2016.crypto.SymmetricCipher.java

License:Open Source License

public static void setEngine(ENGINE e) {
    activeEngine = e;/*  w  w  w. j av a2s  .  c  o  m*/
    switch (e) {
    case AES:
        engine = new AESEngine();
        break;
    //    case AES_WRAP:
    //        engine = new AESWrapEngine();
    //        break;
    case Rijndael:
        engine = new RijndaelEngine();
        break;
    case Camellia:
        engine = new CamelliaEngine();
        break;
    case Blowfish:
        engine = new BlowfishEngine();
        break;
    case Serpent:
        engine = new SerpentEngine();
        break;
    case Threefish:
        //engine = new ThreefishEngine(256);
        engine = new ThreefishEngine(ThreefishSize);
        break;
    case Twofish:
    default:
        engine = new TwofishEngine();
    }
}

From source file:de.gs_sys.kp2016.crypto.SymmetricCipher.java

License:Open Source License

@Deprecated
protected static BlockCipher getEngine(ENGINE engine) {
    switch (engine) {
    case AES:/*from  w w w  .  java 2s.c om*/
        return new AESEngine();
    //    case AES_WRAP:
    //        return new AESWrapEngine();
    case Rijndael:
        return new RijndaelEngine();
    case Camellia:
        return new CamelliaEngine();
    case Blowfish:
        return new BlowfishEngine();
    case Serpent:
        return new SerpentEngine();
    case Threefish:
        // return new ThreefishEngine(256);
        return new ThreefishEngine(ThreefishSize);
    case Twofish:
    default:
        return new TwofishEngine();
    }
}

From source file:gnu.java.zrtp.jmf.transform.srtp.SRTCPCryptoContext.java

License:LGPL

/**
 * Construct a normal SRTPCryptoContext based on the given parameters.
 * /*from   w w  w. ja  va  2s . com*/
 * @param ssrcIn
 *            the RTP SSRC that this SRTP cryptographic context protects.
 * @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
 */
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:gnu.java.zrtp.jmf.transform.srtp.SRTPCryptoContext.java

License:LGPL

/**
 * Construct a normal SRTPCryptoContext based on the given parameters.
 * /*from   ww  w  .j  a  va2s. co m*/
 * @param ssrcIn
 *            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
 */
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());

    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:jazmin.server.relay.udp.webrtc.SRTCPCryptoContext.java

License:LGPL

/**
 * Construct a normal SRTPCryptoContext based on the given parameters.
 * /*from w w w  .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, masterK.length);
    masterSalt = new byte[policy.getSaltKeyLength()];
    System.arraycopy(masterS, 0, masterSalt, 0, masterS.length);

    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:
        authKey = new byte[policy.getAuthKeyLength()];
        tagStore = new byte[policy.getAuthTagLength()];
        break;

    default:
        tagStore = null;
    }
}