All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.general.SelfTestExecutor Maven / Gradle / Ivy

Go to download

The FIPS 140-3 Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms certified to FIPS 140-3 level 1. This jar contains JCE provider and low-level API for the BC-FJA version 2.0.0, FIPS Certificate #4743. Please see certificate for certified platform details.

There is a newer version: 2.0.0
Show newest version
package org.bouncycastle.crypto.general;

import org.bouncycastle.crypto.Algorithm;
import org.bouncycastle.crypto.internal.test.BasicKatTest;
import org.bouncycastle.crypto.internal.test.ConsistencyTest;

class SelfTestExecutor
{
    static  T validate(Algorithm algorithm, T engine, BasicKatTest test)
    {
        try
        {
            if (!test.hasTestPassed(engine))
            {
                throw new OperationError("Self test failed: " + algorithm.getName());
            }

            return engine;
        }
        catch (Exception e)
        {
            throw new OperationError("Exception on self test: " + algorithm.getName(), e);
        }
    }

    static  T validate(Algorithm algorithm, T parameters, ConsistencyTest test)
    {
        try
        {
            if (!test.hasTestPassed(parameters))
            {
                throw new OperationError("Consistency test failed: " + algorithm.getName());
            }

            return parameters;
        }
        catch (Exception e)
        {
            throw new OperationError("Consistency test exception: " + algorithm.getName(), e);
        }
    }

    static  T validate(Algorithm algorithm, T engine, VariantKatTest test)
    {
        try
        {
            test.evaluate(engine);

            return engine;
        }
        catch (TestFailedException e)
        {
            throw new OperationError(e.getMessage() + ": " + algorithm.getName());
        }
        catch (Exception e)
        {
            throw new OperationError("Exception on self test: " + algorithm.getName(), e);
        }
    }

    static class TestFailedException
        extends RuntimeException
    {

        public TestFailedException(String message)
        {
            super(message);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy