Search in sources :

Example 1 with ParametersWithIV

use of org.gudy.bouncycastle.crypto.params.ParametersWithIV in project BiglyBT by BiglySoftware.

the class PGPCFBBlockCipher 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 forEncryption if true the cipher is initialised for
 *  encryption, if false for decryption.
 * @param param the key and other data required by the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
@Override
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException {
    this.forEncryption = forEncryption;
    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.gudy.bouncycastle.crypto.params.ParametersWithIV)

Example 2 with ParametersWithIV

use of org.gudy.bouncycastle.crypto.params.ParametersWithIV in project BiglyBT by BiglySoftware.

the class SICBlockCipher method init.

@Override
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException {
    this.encrypting = forEncryption;
    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());
    }
}
Also used : ParametersWithIV(org.gudy.bouncycastle.crypto.params.ParametersWithIV)

Example 3 with ParametersWithIV

use of org.gudy.bouncycastle.crypto.params.ParametersWithIV in project BiglyBT by BiglySoftware.

the class PKCS12ParametersGenerator 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.
 */
@Override
public CipherParameters generateDerivedParameters(int keySize, int ivSize) {
    keySize = keySize / 8;
    ivSize = ivSize / 8;
    byte[] dKey = generateDerivedKey(KEY_MATERIAL, keySize);
    byte[] iv = generateDerivedKey(IV_MATERIAL, ivSize);
    return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), iv, 0, ivSize);
}
Also used : ParametersWithIV(org.gudy.bouncycastle.crypto.params.ParametersWithIV) KeyParameter(org.gudy.bouncycastle.crypto.params.KeyParameter)

Example 4 with ParametersWithIV

use of org.gudy.bouncycastle.crypto.params.ParametersWithIV in project BiglyBT by BiglySoftware.

the class CBCBlockCipher 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.
 *
 * @param forEncryption if true the cipher is initialised for
 *  encryption, if false for decryption.
 * @param param the key and other data required by the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
@Override
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 != blockSize) {
            throw new IllegalArgumentException("initialisation vector must be the same length as block size");
        }
        System.arraycopy(iv, 0, IV, 0, iv.length);
        reset();
        cipher.init(encrypting, ivParam.getParameters());
    } else {
        reset();
        cipher.init(encrypting, params);
    }
}
Also used : ParametersWithIV(org.gudy.bouncycastle.crypto.params.ParametersWithIV)

Example 5 with ParametersWithIV

use of org.gudy.bouncycastle.crypto.params.ParametersWithIV in project BiglyBT by BiglySoftware.

the class OpenSSLPBEParametersGenerator 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.
 */
@Override
public CipherParameters generateDerivedParameters(int keySize, int ivSize) {
    keySize = keySize / 8;
    ivSize = ivSize / 8;
    byte[] dKey = generateDerivedKey(keySize + ivSize);
    return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), dKey, keySize, ivSize);
}
Also used : ParametersWithIV(org.gudy.bouncycastle.crypto.params.ParametersWithIV) KeyParameter(org.gudy.bouncycastle.crypto.params.KeyParameter)

Aggregations

ParametersWithIV (org.gudy.bouncycastle.crypto.params.ParametersWithIV)8 KeyParameter (org.gudy.bouncycastle.crypto.params.KeyParameter)3