package org.bouncycastle.crypto.agreement.kdf;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class ECDHKEKGenerator implements org.bouncycastle.crypto.DigestDerivationFunction {
    private org.bouncycastle.crypto.DigestDerivationFunction a;
    private org.bouncycastle.asn1.ASN1ObjectIdentifier b;
    private int c;
    private byte[] d;

    @Override // org.bouncycastle.crypto.DerivationFunction
    public int generateBytes(byte[] bArr, int i, int i2) {
        if (i + i2 > bArr.length) {
            throw new org.bouncycastle.crypto.DataLengthException("output buffer too small");
        }
        org.bouncycastle.asn1.ASN1EncodableVector aSN1EncodableVector = new org.bouncycastle.asn1.ASN1EncodableVector();
        aSN1EncodableVector.a(new org.bouncycastle.asn1.x509.AlgorithmIdentifier(this.b, org.bouncycastle.asn1.DERNull.b));
        aSN1EncodableVector.a(new org.bouncycastle.asn1.DERTaggedObject(true, 2, new org.bouncycastle.asn1.DEROctetString(org.bouncycastle.util.Pack.j(this.c))));
        try {
            this.a.init(new org.bouncycastle.crypto.params.KDFParameters(this.d, new org.bouncycastle.asn1.DERSequence(aSN1EncodableVector).m("DER")));
            return this.a.generateBytes(bArr, i, i2);
        } catch (java.io.IOException e) {
            throw new java.lang.IllegalArgumentException("unable to initialise kdf: " + e.getMessage());
        }
    }

    @Override // org.bouncycastle.crypto.DerivationFunction
    public void init(org.bouncycastle.crypto.DerivationParameters derivationParameters) {
        org.bouncycastle.crypto.agreement.kdf.DHKDFParameters dHKDFParameters = (org.bouncycastle.crypto.agreement.kdf.DHKDFParameters) derivationParameters;
        this.b = dHKDFParameters.a();
        this.c = dHKDFParameters.c();
        this.d = dHKDFParameters.d();
    }
}
