Search in sources :

Example 6 with ParametersWithIV

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

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.
 */
@Override
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.gudy.bouncycastle.crypto.params.ParametersWithIV) KeyParameter(org.gudy.bouncycastle.crypto.params.KeyParameter)

Example 7 with ParametersWithIV

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

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 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 < 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 8 with ParametersWithIV

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

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 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 < 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)

Aggregations

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