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

项目:gwt-crypto    文件:ISAACTest.java   
public void performTest()
{
    ISAACEngine engine = new ISAACEngine();

    doTest(engine, Hex.decode("00000000"), out);
    doTest(engine, Hex.decode("ffffffff"), outFFFFFFFF);

    byte[] k = new byte[256 * 4];
    for (int i = 0; i != k.length; i++)
    {
        k[i] = (byte)((i % 4 == 0 || i % 4 == 1) ? 0xff : 0x00);
    }
    doTest(engine, k, outFFFF0000);
    k = new byte[256 * 4];
    for (int i = 0; i != k.length; i++)
    {
        k[i] = (byte)((i % 4 == 2 || i % 4 == 3) ? 0xff : 0x00);
    }
    doTest(engine, k, out0000FFFF);
}
项目:gwt-crypto    文件:ISAACTest.java   
private void doTest(ISAACEngine engine, byte[] key, byte[] output)
{
    byte[] in = new byte[output.length];
    byte[] enc = new byte[output.length];
    engine.init(true, new KeyParameter(key));
    engine.processBytes(in, 0, in.length, enc, 0);
    if (!areEqual(enc, output))
    {
        fail("ciphertext mismatch");
    }
    engine.init(false, new KeyParameter(key));
    engine.processBytes(enc, 0, enc.length, enc, 0);
    if (!areEqual(enc, in))
    {
        fail("plaintext mismatch");
    }
}
项目:gwt-crypto    文件:StreamCipherResetTest.java   
public void performTest()
    throws Exception
{
    testReset(new Salsa20Engine(), new Salsa20Engine(), new ParametersWithIV(new KeyParameter(random(32)),
        random(8)));
    testReset(new Salsa20Engine(), new Salsa20Engine(), new ParametersWithIV(new KeyParameter(random(16)),
        random(8)));
    testReset(new XSalsa20Engine(), new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(random(32)),
        random(24)));
    testReset(new ChaChaEngine(), new ChaChaEngine(), new ParametersWithIV(new KeyParameter(random(32)), random(8)));
    testReset(new ChaChaEngine(), new ChaChaEngine(), new ParametersWithIV(new KeyParameter(random(16)), random(8)));
    testReset(new RC4Engine(), new RC4Engine(), new KeyParameter(random(16)));
    testReset(new ISAACEngine(), new ISAACEngine(), new KeyParameter(random(16)));
    testReset(new HC128Engine(), new HC128Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(16)));
    testReset(new HC256Engine(), new HC256Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(16)));
    testReset(new Grainv1Engine(), new Grainv1Engine(), new ParametersWithIV(new KeyParameter(random(16)),
        random(8)));
    testReset(new Grain128Engine(), new Grain128Engine(), new ParametersWithIV(new KeyParameter(random(16)),
        random(12)));
}
项目:subshare    文件:StreamCipherImpl.java   
@Override
public int getIVSize()
{
    if (ivSize < 0) {
        if (delegate instanceof Grainv1Engine)
            ivSize = 8;
        else if (delegate instanceof Grain128Engine)
            ivSize = 12;
        else if (delegate instanceof HC128Engine)
            ivSize = 16;
        else if (delegate instanceof HC256Engine)
            ivSize = 32;
        else if (delegate instanceof ISAACEngine)
            ivSize = 0;
        else if (delegate instanceof RC4Engine)
            ivSize = 0;
        else if (delegate instanceof Salsa20Engine)
            ivSize = 8;
        else
            throw new UnsupportedOperationException("For this delegate cipher type, this operation is not yet supported!");
    }
    return ivSize;
}
项目:irma_future_id    文件:ISAACTest.java   
public void performTest()
{
    ISAACEngine engine = new ISAACEngine();

    doTest(engine, Hex.decode("00000000"), out);
    doTest(engine, Hex.decode("ffffffff"), outFFFFFFFF);

    byte[] k = new byte[256 * 4];
    for (int i = 0; i != k.length; i++)
    {
        k[i] = (byte)((i % 4 == 0 || i % 4 == 1) ? 0xff : 0x00);
    }
    doTest(engine, k, outFFFF0000);
    k = new byte[256 * 4];
    for (int i = 0; i != k.length; i++)
    {
        k[i] = (byte)((i % 4 == 2 || i % 4 == 3) ? 0xff : 0x00);
    }
    doTest(engine, k, out0000FFFF);
}
项目:irma_future_id    文件:ISAACTest.java   
private void doTest(ISAACEngine engine, byte[] key, byte[] output)
{
    byte[] in = new byte[output.length];
    byte[] enc = new byte[output.length];
    engine.init(true, new KeyParameter(key));
    engine.processBytes(in, 0, in.length, enc, 0);
    if (!areEqual(enc, output))
    {
        fail("ciphertext mismatch");
    }
    engine.init(false, new KeyParameter(key));
    engine.processBytes(enc, 0, enc.length, enc, 0);
    if (!areEqual(enc, in))
    {
        fail("plaintext mismatch");
    }
}
项目:bc-java    文件:ISAACTest.java   
public void performTest()
{
    ISAACEngine engine = new ISAACEngine();

    doTest(engine, Hex.decode("00000000"), out);
    doTest(engine, Hex.decode("ffffffff"), outFFFFFFFF);

    byte[] k = new byte[256 * 4];
    for (int i = 0; i != k.length; i++)
    {
        k[i] = (byte)((i % 4 == 0 || i % 4 == 1) ? 0xff : 0x00);
    }
    doTest(engine, k, outFFFF0000);
    k = new byte[256 * 4];
    for (int i = 0; i != k.length; i++)
    {
        k[i] = (byte)((i % 4 == 2 || i % 4 == 3) ? 0xff : 0x00);
    }
    doTest(engine, k, out0000FFFF);
}
项目:bc-java    文件:ISAACTest.java   
private void doTest(ISAACEngine engine, byte[] key, byte[] output)
{
    byte[] in = new byte[output.length];
    byte[] enc = new byte[output.length];
    engine.init(true, new KeyParameter(key));
    engine.processBytes(in, 0, in.length, enc, 0);
    if (!areEqual(enc, output))
    {
        fail("ciphertext mismatch");
    }
    engine.init(false, new KeyParameter(key));
    engine.processBytes(enc, 0, enc.length, enc, 0);
    if (!areEqual(enc, in))
    {
        fail("plaintext mismatch");
    }
}