use of com.github.zhenwei.core.crypto.params.KeyParameter in project LinLong-Java by zhenwei1108.
the class KDFCounterBytesGenerator method init.
public void init(DerivationParameters param) {
if (!(param instanceof KDFCounterParameters)) {
throw new IllegalArgumentException("Wrong type of arguments given");
}
KDFCounterParameters kdfParams = (KDFCounterParameters) param;
// --- init mac based PRF ---
this.prf.init(new KeyParameter(kdfParams.getKI()));
// --- set arguments ---
this.fixedInputDataCtrPrefix = kdfParams.getFixedInputDataCounterPrefix();
this.fixedInputData_afterCtr = kdfParams.getFixedInputDataCounterSuffix();
int r = kdfParams.getR();
this.ios = new byte[r / 8];
BigInteger maxSize = TWO.pow(r).multiply(BigInteger.valueOf(h));
this.maxSizeExcl = maxSize.compareTo(INTEGER_MAX) == 1 ? Integer.MAX_VALUE : maxSize.intValue();
// --- set operational state ---
generatedBytes = 0;
}
use of com.github.zhenwei.core.crypto.params.KeyParameter in project LinLong-Java by zhenwei1108.
the class KDFDoublePipelineIterationBytesGenerator method init.
public void init(DerivationParameters params) {
if (!(params instanceof KDFDoublePipelineIterationParameters)) {
throw new IllegalArgumentException("Wrong type of arguments given");
}
KDFDoublePipelineIterationParameters dpiParams = (KDFDoublePipelineIterationParameters) params;
// --- init mac based PRF ---
this.prf.init(new KeyParameter(dpiParams.getKI()));
// --- set arguments ---
this.fixedInputData = dpiParams.getFixedInputData();
int r = dpiParams.getR();
this.ios = new byte[r / 8];
if (dpiParams.useCounter()) {
// this is more conservative than the spec
BigInteger maxSize = TWO.pow(r).multiply(BigInteger.valueOf(h));
this.maxSizeExcl = maxSize.compareTo(INTEGER_MAX) == 1 ? Integer.MAX_VALUE : maxSize.intValue();
} else {
this.maxSizeExcl = Integer.MAX_VALUE;
}
this.useCounter = dpiParams.useCounter();
// --- set operational state ---
generatedBytes = 0;
}
use of com.github.zhenwei.core.crypto.params.KeyParameter in project LinLong-Java by zhenwei1108.
the class KDFFeedbackBytesGenerator method init.
public void init(DerivationParameters params) {
if (!(params instanceof KDFFeedbackParameters)) {
throw new IllegalArgumentException("Wrong type of arguments given");
}
KDFFeedbackParameters feedbackParams = (KDFFeedbackParameters) params;
// --- init mac based PRF ---
this.prf.init(new KeyParameter(feedbackParams.getKI()));
// --- set arguments ---
this.fixedInputData = feedbackParams.getFixedInputData();
int r = feedbackParams.getR();
this.ios = new byte[r / 8];
if (feedbackParams.useCounter()) {
// this is more conservative than the spec
BigInteger maxSize = TWO.pow(r).multiply(BigInteger.valueOf(h));
this.maxSizeExcl = maxSize.compareTo(INTEGER_MAX) == 1 ? Integer.MAX_VALUE : maxSize.intValue();
} else {
this.maxSizeExcl = Integer.MAX_VALUE;
}
this.iv = feedbackParams.getIV();
this.useCounter = feedbackParams.useCounter();
// --- set operational state ---
generatedBytes = 0;
}
use of com.github.zhenwei.core.crypto.params.KeyParameter in project LinLong-Java by zhenwei1108.
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.
* @throws 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 com.github.zhenwei.core.crypto.params.KeyParameter in project LinLong-Java by zhenwei1108.
the class GMac method init.
/**
* Initialises the GMAC - requires a {@link ParametersWithIV} providing a {@link KeyParameter} and
* a nonce.
*/
public void init(final CipherParameters params) throws IllegalArgumentException {
if (params instanceof ParametersWithIV) {
final ParametersWithIV param = (ParametersWithIV) params;
final byte[] iv = param.getIV();
final KeyParameter keyParam = (KeyParameter) param.getParameters();
// GCM is always operated in encrypt mode to calculate MAC
cipher.init(true, new AEADParameters(keyParam, macSizeBits, iv));
} else {
throw new IllegalArgumentException("GMAC requires ParametersWithIV");
}
}
Aggregations