package org.bouncycastle.crypto.agreement.kdf;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class GSKKFDGenerator implements org.bouncycastle.crypto.DigestDerivationFunction {
    private final org.bouncycastle.crypto.Digest a;
    private byte[] b;
    private int c;
    private byte[] d;
    private byte[] e;

    @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.crypto.Digest digest = this.a;
        byte[] bArr2 = this.b;
        digest.update(bArr2, 0, bArr2.length);
        int i3 = this.c;
        this.c = i3 + 1;
        byte[] bArrJ = org.bouncycastle.util.Pack.j(i3);
        this.a.update(bArrJ, 0, bArrJ.length);
        byte[] bArr3 = this.d;
        if (bArr3 != null) {
            this.a.update(bArr3, 0, bArr3.length);
        }
        this.a.doFinal(this.e, 0);
        java.lang.System.arraycopy(this.e, 0, bArr, i, i2);
        org.bouncycastle.util.Arrays.i(this.e);
        return i2;
    }

    @Override // org.bouncycastle.crypto.DerivationFunction
    public void init(org.bouncycastle.crypto.DerivationParameters derivationParameters) {
        if (!(derivationParameters instanceof org.bouncycastle.crypto.agreement.kdf.GSKKDFParameters)) {
            throw new java.lang.IllegalArgumentException("unkown parameters type");
        }
        org.bouncycastle.crypto.agreement.kdf.GSKKDFParameters gSKKDFParameters = (org.bouncycastle.crypto.agreement.kdf.GSKKDFParameters) derivationParameters;
        this.b = gSKKDFParameters.c();
        this.c = gSKKDFParameters.b();
        this.d = gSKKDFParameters.a();
    }
}
