what-the-bank/sources/org/bouncycastle/crypto/agreement/kdf/ECDHKEKGenerator.java

59 lines
2.5 KiB
Java

package org.bouncycastle.crypto.agreement.kdf;
import java.io.IOException;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.DerivationParameters;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.DigestDerivationFunction;
import org.bouncycastle.crypto.generators.KDF2BytesGenerator;
import org.bouncycastle.crypto.params.KDFParameters;
import org.bouncycastle.util.Pack;
/* loaded from: classes6.dex */
public class ECDHKEKGenerator implements DigestDerivationFunction {
private ASN1ObjectIdentifier algorithm;
private DigestDerivationFunction kdf;
private int keySize;
private byte[] z;
@Override // org.bouncycastle.crypto.DerivationFunction
public void init(DerivationParameters derivationParameters) {
DHKDFParameters dHKDFParameters = (DHKDFParameters) derivationParameters;
this.algorithm = dHKDFParameters.getAlgorithm();
this.keySize = dHKDFParameters.getKeySize();
this.z = dHKDFParameters.getZ();
}
@Override // org.bouncycastle.crypto.DigestDerivationFunction
public Digest getDigest() {
return this.kdf.getDigest();
}
@Override // org.bouncycastle.crypto.DerivationFunction
public int generateBytes(byte[] bArr, int i, int i2) throws DataLengthException, IllegalArgumentException {
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
aSN1EncodableVector.add(new AlgorithmIdentifier(this.algorithm, DERNull.INSTANCE));
aSN1EncodableVector.add(new DERTaggedObject(true, 2, new DEROctetString(Pack.intToBigEndian(this.keySize))));
try {
this.kdf.init(new KDFParameters(this.z, new DERSequence(aSN1EncodableVector).getEncoded(ASN1Encoding.DER)));
return this.kdf.generateBytes(bArr, i, i2);
} catch (IOException e) {
StringBuilder sb = new StringBuilder("unable to initialise kdf: ");
sb.append(e.getMessage());
throw new IllegalArgumentException(sb.toString());
}
}
public ECDHKEKGenerator(Digest digest) {
this.kdf = new KDF2BytesGenerator(digest);
}
}