package nk;

import java.security.InvalidAlgorithmParameterException;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

/* loaded from: classes3.dex */
public final class r implements lk.a {

    /* renamed from: a, reason: collision with root package name */
    private final SecretKey f30113a;

    /* renamed from: b, reason: collision with root package name */
    private byte[] f30114b;

    /* renamed from: c, reason: collision with root package name */
    private byte[] f30115c;

    public r(byte[] bArr) {
        w.a(bArr.length);
        this.f30113a = new SecretKeySpec(bArr, "AES");
        b();
    }

    private void b() {
        Cipher c10 = c();
        c10.init(1, this.f30113a);
        byte[] b10 = e.b(c10.doFinal(new byte[16]));
        this.f30114b = b10;
        this.f30115c = e.b(b10);
    }

    private static Cipher c() {
        return (Cipher) m.f30103f.a("AES/ECB/NoPadding");
    }

    @Override // lk.a
    public byte[] a(byte[] bArr, int i10) {
        if (i10 > 16) {
            throw new InvalidAlgorithmParameterException("outputLength too large, max is 16 bytes");
        }
        Cipher c10 = c();
        c10.init(1, this.f30113a);
        int max = Math.max(1, (int) Math.ceil(bArr.length / 16.0d));
        byte[] d10 = max * 16 == bArr.length ? g.d(bArr, (max - 1) * 16, this.f30114b, 0, 16) : g.e(e.a(Arrays.copyOfRange(bArr, (max - 1) * 16, bArr.length)), this.f30115c);
        byte[] bArr2 = new byte[16];
        for (int i11 = 0; i11 < max - 1; i11++) {
            bArr2 = c10.doFinal(g.d(bArr2, 0, bArr, i11 * 16, 16));
        }
        return Arrays.copyOf(c10.doFinal(g.e(d10, bArr2)), i10);
    }
}
