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

org.bouncycastle.crypto.StreamBlockCipher Maven / Gradle / Ivy

Go to download

The Long Term Stable (LTS) Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains the JCA/JCE provider and low-level API for the BC LTS version 2.73.7 for Java 8 and later.

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

/**
 * A parent class for block cipher modes that do not require block aligned data to be processed, but can function in
 * a streaming mode.
 */
public abstract class StreamBlockCipher
    extends DefaultMultiBlockCipher
    implements StreamCipher
{
    private final BlockCipher cipher;

    protected StreamBlockCipher(BlockCipher cipher)
    {
        this.cipher = cipher;
    }

    /**
     * return the underlying block cipher that we are wrapping.
     *
     * @return the underlying block cipher that we are wrapping.
     */
    public BlockCipher getUnderlyingCipher()
    {
        return cipher;
    }

    public final byte returnByte(byte in)
    {
        return calculateByte(in);
    }

    public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff)
        throws DataLengthException
    {
        if (inOff + len > in.length)
        {
            throw new DataLengthException("input buffer too small");
        }
        if (outOff + len > out.length)
        {
            throw new OutputLengthException("output buffer too short");
        }

        int inStart = inOff;
        int inEnd = inOff + len;
        int outStart = outOff;

        while (inStart < inEnd)
        {
             out[outStart++] = calculateByte(in[inStart++]);
        }

        return len;
    }

    protected abstract byte calculateByte(byte b);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy