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);
}
}
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);
}
}
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");
}
}
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);
}
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);
}
}
Aggregations