Package org.bouncycastle.util.test

Examples of org.bouncycastle.util.test.SimpleTestResult


            cipher.init(Cipher.UNWRAP_MODE, wrapKey);
            Key key = cipher.unwrap(wrappedKey, "RSA", Cipher.PRIVATE_KEY);

            if (!MessageDigest.isEqual(priKey.getEncoded(), key.getEncoded()))
            {
                return new SimpleTestResult(false, "Unwrapped key does not match");
            }

            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": exception - " + e.toString(), e);
        }
    }
View Full Code Here


    {  
        org.bouncycastle.util.test.Test[] tests = RegressionTest.tests;
       
        for (int i = 0; i != tests.length; i++)
        {
            SimpleTestResult  result = (SimpleTestResult)tests[i].perform();
           
            if (!result.isSuccessful())
            {
                if (result.getException() != null)
                {
                    result.getException().printStackTrace();
                }
                fail(result.toString());
            }
        }
    }
View Full Code Here

       
        org.bouncycastle.util.test.Test[] tests = new org.bouncycastle.util.test.Test[] { new OCSPTest() };
       
        for (int i = 0; i != tests.length; i++)
        {
            SimpleTestResult  result = (SimpleTestResult)tests[i].perform();
           
            if (!result.isSuccessful())
            {
                fail(result.toString());
            }
        }
    }
View Full Code Here

    {  
        org.bouncycastle.util.test.Test[] tests = RegressionTest.tests;
       
        for (int i = 0; i != tests.length; i++)
        {
            SimpleTestResult  result = (SimpleTestResult)tests[i].perform();
           
            if (!result.isSuccessful())
            {
                fail(result.toString());
            }
        }
    }
View Full Code Here

            s.update(msg1a);
            byte[] sig = s.sign();

            if (!arrayEquals(sig1a, sig))
            {
                return new SimpleTestResult(false, "PSS Sign test expected " + new String(Hex.encode(sig1a)) + " got " + new String(Hex.encode(sig)));
            }

            s = Signature.getInstance("SHA1withRSAandMGF1", "BC");
           
            s.initVerify(pubKey);
            s.update(msg1a);
            if (!s.verify(sig1a))
            {
                return new SimpleTestResult(false, "SHA1 signature verification failed");
            }

            s = Signature.getInstance("SHA1withRSAandMGF1", "BC");
           
            s.setParameter(PSSParameterSpec.DEFAULT);
           
            s.initVerify(pubKey);
            s.update(msg1a);
            if (!s.verify(sig1a))
            {
                return new SimpleTestResult(false, "SHA1 signature verification with default parameters failed");
            }
           
            AlgorithmParameters pss = s.getParameters();
            if (!arrayEquals(pss.getEncoded(), new byte[] { 0x30, 0x00 }))
            {
                return new SimpleTestResult(false, "failed default encoding test.");
            }
           
            s = Signature.getInstance("SHA256withRSA/PSS", "BC");

            s.initSign(privKey, new FixedRandom(slt1a));
            s.update(msg1a);
            sig = s.sign();

            pss = s.getParameters();
           
            if (!arrayEquals(sig1b, sig))
            {
                return new SimpleTestResult(false, "PSS Sign test expected " + new String(Hex.encode(sig1b)) + " got " + new String(Hex.encode(sig)));
            }

            s = Signature.getInstance("SHA256withRSAandMGF1", "BC");
           
            s.setParameter(pss.getParameterSpec(PSSParameterSpec.class));
           
            s.initVerify(pubKey);
            s.update(msg1a);
            if (!s.verify(sig1b))
            {
                return new SimpleTestResult(false, "SHA256 signature verification failed");
            }

            //
            // 512 test -with zero salt length
            //
            s = Signature.getInstance("SHA512withRSAandMGF1", "BC");
           
            s.setParameter(new PSSParameterSpec("SHA-512", "MGF1", new MGF1ParameterSpec("SHA-512"), 0, 1));
            s.initSign(privKey);

            s.update(msg1a);
            sig = s.sign();

            pss = s.getParameters();
           
            if (!arrayEquals(sig1c, sig))
            {
                return new SimpleTestResult(false, "PSS Sign test expected " + new String(Hex.encode(sig1c)) + " got " + new String(Hex.encode(sig)));
            }

            s = Signature.getInstance("SHA512withRSAandMGF1", "BC");
           
            s.setParameter(pss.getParameterSpec(PSSParameterSpec.class));
           
            s.initVerify(pubKey);
            s.update(msg1a);
            if (!s.verify(sig1c))
            {
                return new SimpleTestResult(false, "SHA512 signature verification failed");
            }
           
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": exception - " + e.toString(), e);
        }
    }
View Full Code Here

       
        org.bouncycastle.util.test.Test[] tests = new org.bouncycastle.util.test.Test[] { new ReaderTest() };
       
        for (int i = 0; i != tests.length; i++)
        {
            SimpleTestResult  result = (SimpleTestResult)tests[i].perform();
           
            if (!result.isSuccessful())
            {
                fail(result.toString());
            }
        }
    }
View Full Code Here

            hmac.update(m, 0, m.length);
            hmac.doFinal(resBuf, 0);

            if (!arraysEqual(resBuf, Hex.decode(digests[i])))
            {
                return new SimpleTestResult(false, getName() + ": Vector " + i + " failed");
            }
        }

        //
        // test reset
        //
        int vector = 0; // vector used for test
        byte[] m = messages[vector].getBytes();
        if (messages[vector].startsWith("0x"))
        {
            m = Hex.decode(messages[vector].substring(2));
        }
        hmac.init(new KeyParameter(Hex.decode(keys[vector])));
        hmac.update(m, 0, m.length);
        hmac.doFinal(resBuf, 0);
        hmac.reset();
        hmac.update(m, 0, m.length);
        hmac.doFinal(resBuf, 0);

        if (!arraysEqual(resBuf, Hex.decode(digests[vector])))
        {
            return new SimpleTestResult(false, getName() +
                    "Reset with vector " + vector + " failed");
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

           
            decLen += cipher.doFinal(dec, decLen);
           
            if (!isEqualTo(data, dec))
            {
                return new SimpleTestResult(false, getName() + ": failed to decrypt - i = " + data.length + ", padding = " + padding.getPaddingName());
            }
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": Exception - " + e.toString(), e);
        }
       
        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

        {
            padding.addPadding(data, 3);
           
            if (!isEqualTo(data, ffVector))
            {
                return new SimpleTestResult(false, getName() + ": failed ff test for " + padding.getPaddingName());
            }
        }
       
        //
        // zero test
        //
        if (ZeroVector != null)
        {
            data = new byte[8];
            padding.addPadding(data, 4);
           
            if (!isEqualTo(data, ZeroVector))
            {
                return new SimpleTestResult(false, getName() + ": failed zero test for " + padding.getPaddingName());
            }
        }
       
        for (int i = 1; i != 200; i++)
        {
            data = new byte[i];
           
            rand.nextBytes(data);
           
            TestResult result = blockCheck(cipher, padding, key, data);
            if (!result.isSuccessful())
            {
                return result;
            }
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

        if (!res.isSuccessful())
        {
            return res;
        }
       
        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

TOP

Related Classes of org.bouncycastle.util.test.SimpleTestResult

Copyright © 2018 www.massapicom. 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.