Examples of RC5ParameterSpec


Examples of javax.crypto.spec.RC5ParameterSpec

        int wordSize = 16;
        byte[] iv = {1, 2, 3, 4, 5, 6};
        int offset = 2;

        try {
            new RC5ParameterSpec(version, rounds, wordSize, null, offset);
            fail("An IllegalArgumentException should be thrown "
                    + "in the case of null iv.");
        } catch (IllegalArgumentException e) {
        }

        try {
            new RC5ParameterSpec(version, rounds, wordSize+8, iv, offset);
            fail("An IllegalArgumentException should be thrown "
                    + "in the case of short iv.");
        } catch (IllegalArgumentException e) {
        }

        try {
            new RC5ParameterSpec(version, rounds, wordSize, iv, offset+1);
            fail("An IllegalArgumentException should be thrown "
                    + "in the case of short iv.");
        } catch (IllegalArgumentException e) {
        }

        try {
            new RC5ParameterSpec(version, rounds, wordSize, new byte[] { 1, 2,
                    3, 4 }, offset);
            fail("An IllegalArgumentException should be thrown "
                    + "in the case of short iv.");
        } catch (IllegalArgumentException e) {
        }

        RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, wordSize,
                                                                    iv, offset);
        iv[offset] ++;
        assertFalse("The change of iv specified in the constructor "
                    + "should not cause the change of internal array.",
                    iv[offset] == ps.getIV()[0]);

        // Regression test for HARMONY-1077
        try {
            new RC5ParameterSpec(0, 9, 77, new byte[] { 2 }, -100);
            fail("ArrayIndexOutOfBoundsException expected");
        } catch (ArrayIndexOutOfBoundsException e) {
            // expected
        }
    }
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

    public void testGetVersion() {
        int version = 1;
        int rounds = 5;
        int wordSize = 16;

        RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, wordSize);
        assertTrue("The returned version value should be equal to the "
                + "value specified in the constructor.",
                ps.getVersion() == version);
    }
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

    public void testGetRounds() {
        int version = 1;
        int rounds = 5;
        int wordSize = 16;

        RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, wordSize);
        assertTrue("The returned rounds value should be equal to the "
                + "value specified in the constructor.",
                ps.getRounds() == rounds);
    }
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

    public void testGetWordSize() {
        int version = 1;
        int rounds = 5;
        int wordSize = 16;

        RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, wordSize);
        assertTrue("The returned wordSize value should be equal to the "
                + "value specified in the constructor.",
                ps.getWordSize() == wordSize);
    }
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

        int version = 1;
        int rounds = 5;
        int wordSize = 16;
        byte[] iv = {1, 2, 3, 4};

        RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds,
                                                            wordSize, iv);
        byte[] result = ps.getIV();
        if (! Arrays.equals(iv, result)) {
            fail("The returned iv is not equal to the specified "
                    + "in the constructor.");
        }
        result[0] ++;
        assertFalse("The change of returned by getIV() method iv "
                    + "should not cause the change of internal array.",
                    result[0] == ps.getIV()[0]);
        ps = new RC5ParameterSpec(version, rounds, wordSize);
        assertNull("The getIV() method should return null if the parameter "
                    + "set does not contain IV.", ps.getIV());
    }
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

        int version = 1;
        int rounds = 5;
        int wordSize = 16;
        byte[] iv = {1, 2, 3, 4, 5, 6};

        RC5ParameterSpec ps1 = new RC5ParameterSpec(version, rounds,
                                                                wordSize, iv);
        RC5ParameterSpec ps2 = new RC5ParameterSpec(version, rounds,
                                                                wordSize, iv);
        RC5ParameterSpec ps3 = new RC5ParameterSpec(version, rounds, wordSize,
                                                    new byte[] {1, 2, 3, 4});
        // checking for reflexive law:
        assertTrue("The equivalence relation should be reflexive.",
                                                        ps1.equals(ps1));

        assertTrue("Objects built on the same parameters should be equal.",
                                                        ps1.equals(ps2));
        // checking for symmetric law:
        assertTrue("The equivalence relation should be symmetric.",
                                                        ps2.equals(ps1));

        assertTrue("Objects built on the equal parameters should be equal.",
                                                        ps2.equals(ps3));

        // checking for transitive law:
        assertTrue("The equivalence relation should be transitive.",
                                                        ps1.equals(ps3));

        assertFalse("Should return not be equal to null object.",
                                                        ps1.equals(null));

        ps2 = new RC5ParameterSpec(version+1, rounds, wordSize, iv);
        assertFalse("Objects should not be equal.", ps1.equals(ps2));

        ps2 = new RC5ParameterSpec(version, rounds+1, wordSize, iv);
        assertFalse("Objects should not be equal.", ps1.equals(ps2));

        ps2 = new RC5ParameterSpec(version, rounds, wordSize/2, iv);
        assertFalse("Objects should not be equal.", ps1.equals(ps2));

        ps2 = new RC5ParameterSpec(version, rounds, wordSize,
                                                    new byte[] {4, 3, 2, 1});
        assertFalse("Objects should not be equal.", ps1.equals(ps2));
    }
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

            } else {
                rcParams = new RC2ParameterSpec(keySize, ivParams.getIV());
            }
            c.init(cipherMode, secret, rcParams);
        } else if (cipherUpper.startsWith("RC5")) {
            RC5ParameterSpec rcParams;
            if (mode.startsWith("ECB") || ivParams == null) {
                // ECB doesn't take an IV.
                rcParams = new RC5ParameterSpec(16, 12, 32);
            } else {
                rcParams = new RC5ParameterSpec(16, 12, 32, ivParams.getIV());
            }
            c.init(cipherMode, secret, rcParams);
        } else if (mode.startsWith("ECB") || cipherUpper.startsWith("RC4")) {
            // RC4 doesn't require any params.
            // Any cipher using ECB does not require an IV.
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

                ivParam = (ParametersWithIV)param;
            }
        }
        else if (params instanceof RC5ParameterSpec)
        {
            RC5ParameterSpec    rc5Param = (RC5ParameterSpec)params;

            param = new RC5Parameters(key.getEncoded(), ((RC5ParameterSpec)params).getRounds());
            if (baseEngine.getAlgorithmName().startsWith("RC5"))
            {
                if (baseEngine.getAlgorithmName().equals("RC5-32"))
                {
                    if (rc5Param.getWordSize() != 32)
                    {
                        throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 32 not " + rc5Param.getWordSize() + ".");
                    }
                }
                else if (baseEngine.getAlgorithmName().equals("RC5-64"))
                {
                    if (rc5Param.getWordSize() != 64)
                    {
                        throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 64 not " + rc5Param.getWordSize() + ".");
                    }
                }
            }
            else
            {
                throw new InvalidAlgorithmParameterException("RC5 parameters passed to a cipher that is not RC5.");
            }
            if ((rc5Param.getIV() != null) && (ivLength != 0))
            {
                param = new ParametersWithIV(param, rc5Param.getIV());
                ivParam = (ParametersWithIV)param;
            }
        }
        else
        {
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

        byte[] iv_2 = {
            (byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22
        };

        try {
            RC5ParameterSpec rc5Params = new RC5ParameterSpec(1, 2, 8, iv_1);
            throw new Exception("expected IllegalArgumentException");
        } catch (IllegalArgumentException iae) {}

        try {
            RC5ParameterSpec rc5Params = new RC5ParameterSpec(1, 2, 8, iv_2, 3);
            throw new Exception("expected IllegalArgumentException");
        } catch (IllegalArgumentException iae) {}

    }
View Full Code Here

Examples of javax.crypto.spec.RC5ParameterSpec

                ivParam = (ParametersWithIV)param;
            }
        }
        else if (params instanceof RC5ParameterSpec)
        {
            RC5ParameterSpec    rc5Param = (RC5ParameterSpec)params;

            param = new RC5Parameters(key.getEncoded(), ((RC5ParameterSpec)params).getRounds());
            if (baseEngine.getAlgorithmName().startsWith("RC5"))
            {
                if (baseEngine.getAlgorithmName().equals("RC5-32"))
                {
                    if (rc5Param.getWordSize() != 32)
                    {
                        throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 32 not " + rc5Param.getWordSize() + ".");
                    }
                }
                else if (baseEngine.getAlgorithmName().equals("RC5-64"))
                {
                    if (rc5Param.getWordSize() != 64)
                    {
                        throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 64 not " + rc5Param.getWordSize() + ".");
                    }
                }
            }
            else
            {
                throw new InvalidAlgorithmParameterException("RC5 parameters passed to a cipher that is not RC5.");
            }
            if ((rc5Param.getIV() != null) && (ivLength != 0))
            {
                param = new ParametersWithIV(param, rc5Param.getIV());
                ivParam = (ParametersWithIV)param;
            }
        }
        else
        {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.