package org.bouncycastle.crypto.paddings;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class X923Padding implements org.bouncycastle.crypto.paddings.BlockCipherPadding {
    java.security.SecureRandom a = null;

    @Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
    public int a(byte[] bArr, int i) {
        byte length = (byte) (bArr.length - i);
        while (i < bArr.length - 1) {
            java.security.SecureRandom secureRandom = this.a;
            if (secureRandom == null) {
                bArr[i] = 0;
            } else {
                bArr[i] = (byte) secureRandom.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 = secureRandom;
    }
}
