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

org.bouncycastle.crypto.fips.FipsMACOperatorFactory Maven / Gradle / Ivy

Go to download

The FIPS 140-2 Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms certified to FIPS 140-2 level 1. This jar contains the debug version JCE provider and low-level API for the BC-FJA version 1.0.2.3, FIPS Certificate #3514. Please note the debug jar is not certified.

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

import org.bouncycastle.crypto.AuthenticationParameters;
import org.bouncycastle.crypto.MACOperatorFactory;
import org.bouncycastle.crypto.SymmetricKey;
import org.bouncycastle.crypto.internal.Mac;
import org.bouncycastle.crypto.internal.io.MacOutputStream;

/**
 * Base class for the approved mode MACOperatorFactory implementations.
 *
 * @param  the parameters type associated with the final implementation of this factory.
 */
public abstract class FipsMACOperatorFactory
    implements MACOperatorFactory
{
    // package protect constructor
    FipsMACOperatorFactory()
    {
        FipsStatus.isReady();
    }

    public final FipsOutputMACCalculator createOutputMACCalculator(SymmetricKey key, final T parameters)
    {
        final Mac mac = createMAC(key, parameters);

        return new FipsOutputMACCalculator()
        {
            public T getParameters()
            {
                return parameters;
            }

            public int getMACSize()
            {
                return mac.getMacSize();
            }

            public org.bouncycastle.crypto.UpdateOutputStream getMACStream()
            {
                return new MacOutputStream(mac);
            }

            public int getMAC(byte[] output, int off)
            {
                return mac.doFinal(output, off);
            }

            public void reset()
            {
                mac.reset();
            }
        };
    }

    protected abstract int calculateMACSize(T parameters);

    protected abstract Mac createMAC(SymmetricKey key, T parameters);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy