Search in sources :

Example 61 with KeyParameter

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;
}
Also used : KDFCounterParameters(com.github.zhenwei.core.crypto.params.KDFCounterParameters) KeyParameter(com.github.zhenwei.core.crypto.params.KeyParameter) BigInteger(java.math.BigInteger)

Example 62 with KeyParameter

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;
}
Also used : KeyParameter(com.github.zhenwei.core.crypto.params.KeyParameter) BigInteger(java.math.BigInteger) KDFDoublePipelineIterationParameters(com.github.zhenwei.core.crypto.params.KDFDoublePipelineIterationParameters)

Example 63 with KeyParameter

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;
}
Also used : KDFFeedbackParameters(com.github.zhenwei.core.crypto.params.KDFFeedbackParameters) KeyParameter(com.github.zhenwei.core.crypto.params.KeyParameter) BigInteger(java.math.BigInteger)

Example 64 with KeyParameter

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);
}
Also used : ParametersWithIV(com.github.zhenwei.core.crypto.params.ParametersWithIV) KeyParameter(com.github.zhenwei.core.crypto.params.KeyParameter)

Example 65 with KeyParameter

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");
    }
}
Also used : ParametersWithIV(com.github.zhenwei.core.crypto.params.ParametersWithIV) AEADParameters(com.github.zhenwei.core.crypto.params.AEADParameters) KeyParameter(com.github.zhenwei.core.crypto.params.KeyParameter)

Aggregations

KeyParameter (com.github.zhenwei.core.crypto.params.KeyParameter)91 ParametersWithIV (com.github.zhenwei.core.crypto.params.ParametersWithIV)41 CipherParameters (com.github.zhenwei.core.crypto.CipherParameters)15 AEADParameters (com.github.zhenwei.core.crypto.params.AEADParameters)10 InvalidCipherTextException (com.github.zhenwei.core.crypto.InvalidCipherTextException)6 ParametersWithSBox (com.github.zhenwei.core.crypto.params.ParametersWithSBox)6 RC2Parameters (com.github.zhenwei.core.crypto.params.RC2Parameters)6 BigInteger (java.math.BigInteger)6 BufferedBlockCipher (com.github.zhenwei.core.crypto.BufferedBlockCipher)4 StreamCipher (com.github.zhenwei.core.crypto.StreamCipher)4 PKCS5S2ParametersGenerator (com.github.zhenwei.core.crypto.generators.PKCS5S2ParametersGenerator)4 HMac (com.github.zhenwei.core.crypto.macs.HMac)4 AsymmetricKeyParameter (com.github.zhenwei.core.crypto.params.AsymmetricKeyParameter)4 IESWithCipherParameters (com.github.zhenwei.core.crypto.params.IESWithCipherParameters)4 ParametersWithRandom (com.github.zhenwei.core.crypto.params.ParametersWithRandom)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)4 IvParameterSpec (javax.crypto.spec.IvParameterSpec)4 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)3 RC5Parameters (com.github.zhenwei.core.crypto.params.RC5Parameters)3 CMSException (com.github.zhenwei.pkix.cms.CMSException)3