Search in sources :

Example 36 with ParametersWithIV

use of org.bouncycastle.crypto.params.ParametersWithIV in project XobotOS by xamarin.

the class GOFBBlockCipher method init.

/**
     * Initialise the cipher and, possibly, the initialisation vector (IV).
     * If an IV isn't passed as part of the parameter, the IV will be all zeros.
     * An IV which is too short is handled in FIPS compliant fashion.
     *
     * @param encrypting if true the cipher is initialised for
     *  encryption, if false for decryption.
     * @param params the key and other data required by the cipher.
     * @exception IllegalArgumentException if the params argument is
     * inappropriate.
     */
public void init(//ignored by this CTR mode
boolean encrypting, CipherParameters params) throws IllegalArgumentException {
    firstStep = true;
    N3 = 0;
    N4 = 0;
    if (params instanceof ParametersWithIV) {
        ParametersWithIV ivParam = (ParametersWithIV) params;
        byte[] iv = ivParam.getIV();
        if (iv.length < IV.length) {
            // prepend the supplied IV with zeros (per FIPS PUB 81)
            System.arraycopy(iv, 0, IV, IV.length - iv.length, iv.length);
            for (int i = 0; i < IV.length - iv.length; i++) {
                IV[i] = 0;
            }
        } else {
            System.arraycopy(iv, 0, IV, 0, IV.length);
        }
        reset();
        cipher.init(true, ivParam.getParameters());
    } else {
        reset();
        cipher.init(true, params);
    }
}
Also used : ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV)

Example 37 with ParametersWithIV

use of org.bouncycastle.crypto.params.ParametersWithIV in project XobotOS by xamarin.

the class OFBBlockCipher method init.

/**
     * Initialise the cipher and, possibly, the initialisation vector (IV).
     * If an IV isn't passed as part of the parameter, the IV will be all zeros.
     * An IV which is too short is handled in FIPS compliant fashion.
     *
     * @param encrypting if true the cipher is initialised for
     *  encryption, if false for decryption.
     * @param params the key and other data required by the cipher.
     * @exception IllegalArgumentException if the params argument is
     * inappropriate.
     */
public void init(//ignored by this OFB mode
boolean encrypting, CipherParameters params) throws IllegalArgumentException {
    if (params instanceof ParametersWithIV) {
        ParametersWithIV ivParam = (ParametersWithIV) params;
        byte[] iv = ivParam.getIV();
        if (iv.length < IV.length) {
            // prepend the supplied IV with zeros (per FIPS PUB 81)
            System.arraycopy(iv, 0, IV, IV.length - iv.length, iv.length);
            for (int i = 0; i < IV.length - iv.length; i++) {
                IV[i] = 0;
            }
        } else {
            System.arraycopy(iv, 0, IV, 0, IV.length);
        }
        reset();
        cipher.init(true, ivParam.getParameters());
    } else {
        reset();
        cipher.init(true, params);
    }
}
Also used : ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV)

Example 38 with ParametersWithIV

use of org.bouncycastle.crypto.params.ParametersWithIV in project XobotOS by xamarin.

the class SICBlockCipher method init.

public void init(//ignored by this CTR mode
boolean forEncryption, CipherParameters params) throws IllegalArgumentException {
    if (params instanceof ParametersWithIV) {
        ParametersWithIV ivParam = (ParametersWithIV) params;
        byte[] iv = ivParam.getIV();
        System.arraycopy(iv, 0, IV, 0, IV.length);
        reset();
        cipher.init(true, ivParam.getParameters());
    } else {
        throw new IllegalArgumentException("SIC mode requires ParametersWithIV");
    }
}
Also used : ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV)

Example 39 with ParametersWithIV

use of org.bouncycastle.crypto.params.ParametersWithIV in project XobotOS by xamarin.

the class PKCS5S1ParametersGenerator method generateDerivedParameters.

/**
     * Generate a key with initialisation vector parameter derived from
     * the password, salt, and iteration count we are currently initialised
     * with.
     *
     * @param keySize the size of the key we want (in bits)
     * @param ivSize the size of the iv we want (in bits)
     * @return a ParametersWithIV object.
     * @exception IllegalArgumentException if keySize + ivSize is larger than the base hash size.
     */
public CipherParameters generateDerivedParameters(int keySize, int ivSize) {
    keySize = keySize / 8;
    ivSize = ivSize / 8;
    if ((keySize + ivSize) > digest.getDigestSize()) {
        throw new IllegalArgumentException("Can't generate a derived key " + (keySize + ivSize) + " bytes long.");
    }
    byte[] dKey = generateDerivedKey();
    return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), dKey, keySize, ivSize);
}
Also used : ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV) KeyParameter(org.bouncycastle.crypto.params.KeyParameter)

Example 40 with ParametersWithIV

use of org.bouncycastle.crypto.params.ParametersWithIV in project Skein3Fish by wernerd.

the class CFBBlockCipher method init.

/**
     * Initialise the cipher and, possibly, the initialisation vector (IV).
     * If an IV isn't passed as part of the parameter, the IV will be all zeros.
     * An IV which is too short is handled in FIPS compliant fashion.
     *
     * @param encrypting if true the cipher is initialised for
     *  encryption, if false for decryption.
     * @param params the key and other data required by the cipher.
     * @exception IllegalArgumentException if the params argument is
     * inappropriate.
     */
public void init(boolean encrypting, CipherParameters params) throws IllegalArgumentException {
    this.encrypting = encrypting;
    if (params instanceof ParametersWithIV) {
        ParametersWithIV ivParam = (ParametersWithIV) params;
        byte[] iv = ivParam.getIV();
        if (iv.length < IV.length) {
            // prepend the supplied IV with zeros (per FIPS PUB 81)
            System.arraycopy(iv, 0, IV, IV.length - iv.length, iv.length);
            for (int i = 0; i < IV.length - iv.length; i++) {
                IV[i] = 0;
            }
        } else {
            System.arraycopy(iv, 0, IV, 0, IV.length);
        }
        reset();
        cipher.init(true, ivParam.getParameters());
    } else {
        reset();
        cipher.init(true, params);
    }
}
Also used : ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV)

Aggregations

ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)49 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)28 CipherParameters (org.bouncycastle.crypto.CipherParameters)15 InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)12 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)9 IvParameterSpec (javax.crypto.spec.IvParameterSpec)9 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)9 CBCBlockCipher (org.bouncycastle.crypto.modes.CBCBlockCipher)9 InvalidKeyException (java.security.InvalidKeyException)7 SecureRandom (java.security.SecureRandom)7 AESEngine (org.bouncycastle.crypto.engines.AESEngine)7 PaddedBufferedBlockCipher (org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher)7 SecretKey (javax.crypto.SecretKey)5 PKCS7Padding (org.bouncycastle.crypto.paddings.PKCS7Padding)5 DataLengthException (org.bouncycastle.crypto.DataLengthException)4 AEADParameters (org.bouncycastle.crypto.params.AEADParameters)4 ParametersWithRandom (org.bouncycastle.crypto.params.ParametersWithRandom)4 BufferedBlockCipher (org.bouncycastle.crypto.BufferedBlockCipher)3 InvalidParameterException (java.security.InvalidParameterException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2