package org.bouncycastle.crypto.paddings;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class ISO10126d2Padding implements org.bouncycastle.crypto.paddings.BlockCipherPadding {
    java.security.SecureRandom a;

    @Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
    public int a(byte[] bArr, int i) {
        byte length = (byte) (bArr.length - i);
        while (i < bArr.length - 1) {
            bArr[i] = (byte) this.a.nextInt();
            i++;
        }
        bArr[i] = length;
        return length;
    }

    @Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
    public int b(byte[] bArr) throws org.bouncycastle.crypto.InvalidCipherTextException {
        int i = bArr[bArr.length - 1] & 255;
        if ((((bArr.length - i) | (i - 1)) >> 31) == 0) {
            return i;
        }
        throw new org.bouncycastle.crypto.InvalidCipherTextException("pad block corrupted");
    }

    @Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
    public void c(java.security.SecureRandom secureRandom) {
        this.a = org.bouncycastle.crypto.CryptoServicesRegistrar.e(secureRandom);
    }
}
