Java 类org.bouncycastle.crypto.engines.TwofishEngine 实例源码

项目:vsDiaryWriter    文件:BlockCiphers.java   
private static void initBlockCipherEngines() {
    blockCipherEngines.put("MARS", MarsEngine.class);
    blockCipherEngines.put("AES", AESEngine.class);
    blockCipherEngines.put("Blowfish", BlowfishEngine.class);
    blockCipherEngines.put("Camellia", CamelliaEngine.class);
    blockCipherEngines.put("CAST5", CAST5Engine.class);
    blockCipherEngines.put("CAST6", CAST6Engine.class);
    blockCipherEngines.put("DESede", DESedeEngine.class);
    blockCipherEngines.put("DES", DESEngine.class);
    blockCipherEngines.put("GOST28147", GOST28147Engine.class);
    blockCipherEngines.put("IDEA", IDEAEngine.class);
    blockCipherEngines.put("Noekeon", NoekeonEngine.class);
    blockCipherEngines.put("RC2", RC2Engine.class);
    blockCipherEngines.put("RC5", RC532Engine.class);
    blockCipherEngines.put("RC6", RC6Engine.class);
    blockCipherEngines.put("SEED", SEEDEngine.class);
    blockCipherEngines.put("Serpent", SerpentEngine.class);
    blockCipherEngines.put("Shacal2", Shacal2Engine.class);
    blockCipherEngines.put("Skipjack", SkipjackEngine.class);
    blockCipherEngines.put("SM4", SM4Engine.class);
    blockCipherEngines.put("TEA", TEAEngine.class);
    blockCipherEngines.put("Twofish", TwofishEngine.class);
    blockCipherEngines.put("XTEA", XTEAEngine.class);
    blockCipherEngines.put("Threefish", ThreefishEngine.class);
}
项目:javapasswordsafe    文件:TwofishPws.java   
public static byte[] processECB(byte[] key, boolean forEncryption, byte[] input) {

        final BufferedBlockCipher cipher = new BufferedBlockCipher(new TwofishEngine());
        final KeyParameter kp = new KeyParameter(key);
        cipher.init(forEncryption, kp);
        final byte[] out = new byte[input.length];

        final int len1 = cipher.processBytes(input, 0, input.length, out, 0);

        try {
            cipher.doFinal(out, len1);
        } catch (final CryptoException e) {
            throw new RuntimeException(e);
        }
        return out;
    }
项目:ipack    文件:Twofish.java   
public ECB()
{
    super(new BlockCipherProvider()
    {
        public BlockCipher get()
        {
            return new TwofishEngine();
        }
    });
}
项目:gwt-crypto    文件:CipherStreamTest.java   
private void performTests()
    throws Exception
{
    testModes(new BlowfishEngine(), new BlowfishEngine(), 16);
    testModes(new DESEngine(), new DESEngine(), 8);
    testModes(new DESedeEngine(), new DESedeEngine(), 24);
    testModes(new TEAEngine(), new TEAEngine(), 16);
    testModes(new CAST5Engine(), new CAST5Engine(), 16);
    testModes(new RC2Engine(), new RC2Engine(), 16);
    testModes(new XTEAEngine(), new XTEAEngine(), 16);

    testModes(new AESEngine(), new AESEngine(), 16);
    testModes(new NoekeonEngine(), new NoekeonEngine(), 16);
    testModes(new TwofishEngine(), new TwofishEngine(), 16);
    testModes(new CAST6Engine(), new CAST6Engine(), 16);
    testModes(new SEEDEngine(), new SEEDEngine(), 16);
    testModes(new SerpentEngine(), new SerpentEngine(), 16);
    testModes(new RC6Engine(), new RC6Engine(), 16);
    testModes(new CamelliaEngine(), new CamelliaEngine(), 16);
    testModes(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512),
        new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), 64);

    testMode(new RC4Engine(), new KeyParameter(new byte[16]));
    testMode(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8]));
    testMode(new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[32]), new byte[24]));
    testMode(new ChaChaEngine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8]));
    testMode(new Grainv1Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8]));
    testMode(new Grain128Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[12]));
    testMode(new HC128Engine(), new KeyParameter(new byte[16]));
    testMode(new HC256Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));

    testSkipping(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8]));
    testSkipping(new SICBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
}
项目:javapasswordsafe    文件:TwofishPws.java   
public TwofishPws(byte[] key, boolean forEncryption, byte[] IV) {

        final TwofishEngine tfe = new TwofishEngine();
        cipher = new CBCBlockCipher(tfe);
        final KeyParameter kp = new KeyParameter(key);
        final ParametersWithIV piv = new ParametersWithIV(kp, IV);
        cipher.init(forEncryption, piv);

    }
项目:Aki-SSL    文件:Twofish.java   
public ECB()
{
    super(new BlockCipherProvider()
    {
        public BlockCipher get()
        {
            return new TwofishEngine();
        }
    });
}
项目:CryptMeme    文件:Twofish.java   
public ECB()
{
    super(new BlockCipherProvider()
    {
        public BlockCipher get()
        {
            return new TwofishEngine();
        }
    });
}
项目:irma_future_id    文件:Twofish.java   
public ECB()
{
    super(new BlockCipherProvider()
    {
        public BlockCipher get()
        {
            return new TwofishEngine();
        }
    });
}
项目:bc-java    文件:Twofish.java   
public ECB()
{
    super(new BlockCipherProvider()
    {
        public BlockCipher get()
        {
            return new TwofishEngine();
        }
    });
}
项目:keepass2android    文件:JCEBlockCipher.java   
public Twofish()
{
    super(new TwofishEngine());
}
项目:keepass2android    文件:JCEBlockCipher.java   
public PBEWithSHAAndTwofish()
{
    super(new CBCBlockCipher(new TwofishEngine()));
}
项目:keepass2android    文件:JCEStreamCipher.java   
public Twofish_CFB8()
{
    super(new CFBBlockCipher(new TwofishEngine(), 8), 128);
}
项目:keepass2android    文件:JCEStreamCipher.java   
public Twofish_OFB8()
{
    super(new OFBBlockCipher(new TwofishEngine(), 8), 128);
}
项目:ipack    文件:JCEStreamCipher.java   
public Twofish_CFB8()
{
    super(new CFBBlockCipher(new TwofishEngine(), 8), 128);
}
项目:ipack    文件:JCEStreamCipher.java   
public Twofish_OFB8()
{
    super(new OFBBlockCipher(new TwofishEngine(), 8), 128);
}
项目:ipack    文件:BrokenJCEBlockCipher.java   
public OldPBEWithSHAAndTwofish()
{
    super(new CBCBlockCipher(new TwofishEngine()), OLD_PKCS12, SHA1, 256, 128);
}
项目:ipack    文件:Twofish.java   
public GMAC()
{
    super(new GMac(new GCMBlockCipher(new TwofishEngine())));
}
项目:ipack    文件:Twofish.java   
public PBEWithSHA()
{
    super(new CBCBlockCipher(new TwofishEngine()));
}
项目:KeePass2Android    文件:JCEBlockCipher.java   
public Twofish()
{
    super(new TwofishEngine());
}
项目:KeePass2Android    文件:JCEBlockCipher.java   
public PBEWithSHAAndTwofish()
{
    super(new CBCBlockCipher(new TwofishEngine()));
}
项目:KeePass2Android    文件:JCEStreamCipher.java   
public Twofish_CFB8()
{
    super(new CFBBlockCipher(new TwofishEngine(), 8), 128);
}
项目:KeePass2Android    文件:JCEStreamCipher.java   
public Twofish_OFB8()
{
    super(new OFBBlockCipher(new TwofishEngine(), 8), 128);
}
项目:gwt-crypto    文件:BlockCipherResetTest.java   
public void performTest()
    throws Exception
{
    // 128 bit block ciphers
    testReset("AESFastEngine", new AESFastEngine(), new AESFastEngine(), new KeyParameter(new byte[16]));
    testReset("AESEngine", new AESEngine(), new AESEngine(), new KeyParameter(new byte[16]));
    testReset("AESLightEngine", new AESLightEngine(), new AESLightEngine(), new KeyParameter(new byte[16]));
    testReset("Twofish", new TwofishEngine(), new TwofishEngine(), new KeyParameter(new byte[16]));
    testReset("NoekeonEngine", new NoekeonEngine(), new NoekeonEngine(), new KeyParameter(new byte[16]));
    testReset("SerpentEngine", new SerpentEngine(), new SerpentEngine(), new KeyParameter(new byte[16]));
    testReset("SEEDEngine", new SEEDEngine(), new SEEDEngine(), new KeyParameter(new byte[16]));
    testReset("CAST6Engine", new CAST6Engine(), new CAST6Engine(), new KeyParameter(new byte[16]));
    testReset("RC6Engine", new RC6Engine(), new RC6Engine(), new KeyParameter(new byte[16]));

    // 64 bit block ciphers
    testReset("DESEngine", new DESEngine(), new DESEngine(), new KeyParameter(new byte[8]));
    testReset("BlowfishEngine", new BlowfishEngine(), new BlowfishEngine(), new KeyParameter(new byte[8]));
    testReset("CAST5Engine", new CAST5Engine(), new CAST5Engine(), new KeyParameter(new byte[8]));
    testReset("DESedeEngine", new DESedeEngine(), new DESedeEngine(), new KeyParameter(new byte[24]));
    testReset("TEAEngine", new TEAEngine(), new TEAEngine(), new KeyParameter(new byte[16]));
    testReset("XTEAEngine", new XTEAEngine(), new XTEAEngine(), new KeyParameter(new byte[16]));

    // primitive block cipher modes (don't reset on processBlock)
    testModeReset("AES/CBC", new CBCBlockCipher(new AESEngine()), new CBCBlockCipher(new AESEngine()),
        new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
    testModeReset("AES/SIC", new SICBlockCipher(new AESEngine()), new SICBlockCipher(new AESEngine()),
        new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
    testModeReset("AES/CFB", new CFBBlockCipher(new AESEngine(), 128), new CFBBlockCipher(new AESEngine(), 128),
        new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
    testModeReset("AES/OFB", new OFBBlockCipher(new AESEngine(), 128), new OFBBlockCipher(new AESEngine(), 128),
        new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
    testModeReset("AES/GCTR", new GOFBBlockCipher(new DESEngine()), new GOFBBlockCipher(new DESEngine()),
        new ParametersWithIV(new KeyParameter(new byte[8]), new byte[8]));
    testModeReset("AES/OpenPGPCFB", new OpenPGPCFBBlockCipher(new AESEngine()), new OpenPGPCFBBlockCipher(
        new AESEngine()), new KeyParameter(new byte[16]));
    testModeReset("AES/PGPCFB", new PGPCFBBlockCipher(new AESEngine(), false), new PGPCFBBlockCipher(
        new AESEngine(), false), new KeyParameter(new byte[16]));

    // PGPCFB with IV is broken (it's also not a PRP, so probably shouldn't be a BlockCipher)
    // testModeReset("AES/PGPCFBwithIV", new PGPCFBBlockCipher(new AESEngine(), true), new
    // PGPCFBBlockCipher(
    // new AESEngine(), true), new ParametersWithIV(new KeyParameter(new byte[16]), new
    // byte[16]));
    // testModeReset("AES/PGPCFBwithIV_NoIV", new PGPCFBBlockCipher(new AESEngine(), true), new
    // PGPCFBBlockCipher(
    // new AESEngine(), true), new KeyParameter(new byte[16]));

}
项目:gwt-crypto    文件:TwofishTest.java   
TwofishTest()
{
    super(tests, new TwofishEngine(), new KeyParameter(new byte[32]));
}
项目:Aki-SSL    文件:BrokenJCEBlockCipher.java   
public OldPBEWithSHAAndTwofish()
{
    super(new CBCBlockCipher(new TwofishEngine()), OLD_PKCS12, SHA1, 256, 128);
}
项目:Aki-SSL    文件:Twofish.java   
public GMAC()
{
    super(new GMac(new GCMBlockCipher(new TwofishEngine())));
}
项目:Aki-SSL    文件:Twofish.java   
public Poly1305()
{
    super(new org.bouncycastle.crypto.macs.Poly1305(new TwofishEngine()));
}
项目:Aki-SSL    文件:Twofish.java   
public PBEWithSHA()
{
    super(new CBCBlockCipher(new TwofishEngine()), PKCS12, SHA1, 256, 16);
}
项目:Aki-SSL    文件:Serpent.java   
public Poly1305()
{
    super(new org.bouncycastle.crypto.macs.Poly1305(new TwofishEngine()));
}
项目:subshare    文件:GCMTest.java   
@Test
    public void testEncryptionWithBCLowLevelAPI() throws Exception
    {
        final byte[] plain = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
        final byte[] key = new byte[] {
                 1,  2,  3,  4,  5,  6,  7,  8,
                 9, 10, 11, 12, 13, 14, 15, 16,
                17, 18, 19, 20, 21, 22, 23, 24,
                25, 26, 27, 28, 29, 30, 31, 32
        };
        final byte[] iv = new byte[] {
                 1,  2,  3,  4,  5,  6,  7,  8,
                 9, 10, 11, 12, 13, 14, 15, 16
        };

//      { // first try CFB - works fine, currently (2011-09-23).
//          CipherParameters parameters = new ParametersWithIV(new KeyParameter(key), iv);
//          byte[] firstCiphertext = null;
//          BufferedBlockCipher cipher = new BufferedBlockCipher(new CFBBlockCipher(new TwofishEngine(), 128));
//
//          cipher.init(true, parameters);
//
//          for (int i = 0; i < 10000; ++i) {
//              System.out.println("*** cfb " + i + " ***");
//
//              // Whether we re-initialise with or without key does not matter.
//              cipher.init(true, parameters);
//
//              byte[] ciphertext = new byte[cipher.getOutputSize(plain.length)];
//              int encLength = cipher.processBytes(plain, 0, plain.length, ciphertext, 0);
//              cipher.doFinal(ciphertext, encLength);
//
//              if (firstCiphertext == null)
//                  firstCiphertext = ciphertext;
//              else
//                  Assert.assertArrayEquals(firstCiphertext, ciphertext);
//          }
//      }


        { // now try GCM - fails on 'fhernhache', currently (2011-09-23).
            byte[] firstCiphertext = null;
//          AEADParameters parameters = new AEADParameters(new KeyParameter(key), 128, iv, plain);
            final AEADBlockCipher cipher = new GCMBlockCipher(new TwofishEngine());
            final AEADBlockCipher invCipher = new GCMBlockCipher(new TwofishEngine());

            cipher.init(true, new ParametersWithIV(new KeyParameter(key), iv));
            invCipher.init(false, new ParametersWithIV(new KeyParameter(key), iv));

            for (int i = 0; i < 10000; ++i) {
                System.out.println("*** gcm " + i + " ***");
                random.nextBytes(iv);

                // Whether we re-initialise with or without key does not matter.
                cipher.init(true, new ParametersWithIV(null, iv));
                invCipher.init(false, new ParametersWithIV(null, iv));

                final byte[] ciphertext = new byte[cipher.getOutputSize(plain.length)];
                final int encLength = cipher.processBytes(plain, 0, plain.length, ciphertext, 0);
                cipher.doFinal(ciphertext, encLength);

                if (firstCiphertext == null)
                    firstCiphertext = ciphertext;
                else
                    assertThat(ciphertext).isNotEqualTo(firstCiphertext);

                final byte[] decrypted = new byte[cipher.getOutputSize(ciphertext.length)];
                int decLength = invCipher.processBytes(ciphertext, 0, ciphertext.length, decrypted, 0);
                decLength += invCipher.doFinal(decrypted, decLength);
                final byte[] decryptedTruncated = new byte[decLength];
                System.arraycopy(decrypted, 0, decryptedTruncated, 0, decLength);
                assertThat(decryptedTruncated).isEqualTo(plain);
            }
        }
    }
项目:CryptMeme    文件:JCEStreamCipher.java   
public Twofish_CFB8()
{
    super(new CFBBlockCipher(new TwofishEngine(), 8), 128);
}
项目:CryptMeme    文件:JCEStreamCipher.java   
public Twofish_OFB8()
{
    super(new OFBBlockCipher(new TwofishEngine(), 8), 128);
}
项目:CryptMeme    文件:BrokenJCEBlockCipher.java   
public OldPBEWithSHAAndTwofish()
{
    super(new CBCBlockCipher(new TwofishEngine()), OLD_PKCS12, SHA1, 256, 128);
}
项目:CryptMeme    文件:Twofish.java   
public GMAC()
{
    super(new GMac(new GCMBlockCipher(new TwofishEngine())));
}
项目:CryptMeme    文件:Twofish.java   
public Poly1305()
{
    super(new org.bouncycastle.crypto.macs.Poly1305(new TwofishEngine()));
}
项目:CryptMeme    文件:Twofish.java   
public PBEWithSHA()
{
    super(new CBCBlockCipher(new TwofishEngine()));
}
项目:CryptMeme    文件:Serpent.java   
public Poly1305()
{
    super(new org.bouncycastle.crypto.macs.Poly1305(new TwofishEngine()));
}
项目:irma_future_id    文件:BlockCipherResetTest.java   
@Override
public void performTest()
    throws Exception
{
    // 128 bit block ciphers
    testReset("AESFastEngine", new AESFastEngine(), new AESFastEngine(), new KeyParameter(new byte[16]));
    testReset("AESEngine", new AESEngine(), new AESEngine(), new KeyParameter(new byte[16]));
    testReset("AESLightEngine", new AESLightEngine(), new AESLightEngine(), new KeyParameter(new byte[16]));
    testReset("Twofish", new TwofishEngine(), new TwofishEngine(), new KeyParameter(new byte[16]));
    testReset("NoekeonEngine", new NoekeonEngine(), new NoekeonEngine(), new KeyParameter(new byte[16]));
    testReset("SerpentEngine", new SerpentEngine(), new SerpentEngine(), new KeyParameter(new byte[16]));
    testReset("SEEDEngine", new SEEDEngine(), new SEEDEngine(), new KeyParameter(new byte[16]));
    testReset("CAST6Engine", new CAST6Engine(), new CAST6Engine(), new KeyParameter(new byte[16]));
    testReset("RC6Engine", new RC6Engine(), new RC6Engine(), new KeyParameter(new byte[16]));

    // 64 bit block ciphers
    testReset("DESEngine", new DESEngine(), new DESEngine(), new KeyParameter(new byte[8]));
    testReset("BlowfishEngine", new BlowfishEngine(), new BlowfishEngine(), new KeyParameter(new byte[8]));
    testReset("CAST5Engine", new CAST5Engine(), new CAST5Engine(), new KeyParameter(new byte[8]));
    testReset("DESedeEngine", new DESedeEngine(), new DESedeEngine(), new KeyParameter(new byte[24]));
    testReset("TEAEngine", new TEAEngine(), new TEAEngine(), new KeyParameter(new byte[16]));
    testReset("XTEAEngine", new XTEAEngine(), new XTEAEngine(), new KeyParameter(new byte[16]));

    // primitive block cipher modes (don't reset on processBlock)
    testModeReset("AES/CBC", new CBCBlockCipher(new AESEngine()), new CBCBlockCipher(new AESEngine()),
        new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
    testModeReset("AES/SIC", new SICBlockCipher(new AESEngine()), new SICBlockCipher(new AESEngine()),
        new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
    testModeReset("AES/CFB", new CFBBlockCipher(new AESEngine(), 128), new CFBBlockCipher(new AESEngine(), 128),
        new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
    testModeReset("AES/OFB", new OFBBlockCipher(new AESEngine(), 128), new OFBBlockCipher(new AESEngine(), 128),
        new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
    testModeReset("AES/GCTR", new GOFBBlockCipher(new DESEngine()), new GOFBBlockCipher(new DESEngine()),
        new ParametersWithIV(new KeyParameter(new byte[8]), new byte[8]));
    testModeReset("AES/OpenPGPCFB", new OpenPGPCFBBlockCipher(new AESEngine()), new OpenPGPCFBBlockCipher(
        new AESEngine()), new KeyParameter(new byte[16]));
    testModeReset("AES/PGPCFB", new PGPCFBBlockCipher(new AESEngine(), false), new PGPCFBBlockCipher(
        new AESEngine(), false), new KeyParameter(new byte[16]));

    // PGPCFB with IV is broken (it's also not a PRP, so probably shouldn't be a BlockCipher)
    // testModeReset("AES/PGPCFBwithIV", new PGPCFBBlockCipher(new AESEngine(), true), new
    // PGPCFBBlockCipher(
    // new AESEngine(), true), new ParametersWithIV(new KeyParameter(new byte[16]), new
    // byte[16]));
    // testModeReset("AES/PGPCFBwithIV_NoIV", new PGPCFBBlockCipher(new AESEngine(), true), new
    // PGPCFBBlockCipher(
    // new AESEngine(), true), new KeyParameter(new byte[16]));

}
项目:irma_future_id    文件:TwofishTest.java   
TwofishTest()
{
    super(tests, new TwofishEngine(), new KeyParameter(new byte[32]));
}
项目:irma_future_id    文件:JCEStreamCipher.java   
public Twofish_CFB8()
{
    super(new CFBBlockCipher(new TwofishEngine(), 8), 128);
}