what-the-bank/sources/org/bouncycastle/pqc/crypto/gmss/util/WinternitzOTSVerify.java

298 lines
11 KiB
Java

package org.bouncycastle.pqc.crypto.gmss.util;
import com.google.common.primitives.UnsignedBytes;
import org.bouncycastle.crypto.Digest;
/* loaded from: classes6.dex */
public class WinternitzOTSVerify {
private Digest messDigestOTS;
private int w;
public int getLog(int i) {
int i2 = 1;
int i3 = 2;
while (i3 < i) {
i3 <<= 1;
i2++;
}
return i2;
}
public int getSignatureLength() {
int digestSize = this.messDigestOTS.getDigestSize();
int i = this.w;
int i2 = ((digestSize << 3) + (i - 1)) / i;
int log = getLog((i2 << i) + 1);
return digestSize * (i2 + (((log + r3) - 1) / this.w));
}
public byte[] Verify(byte[] bArr, byte[] bArr2) {
int i;
int i2;
byte[] bArr3 = bArr2;
int digestSize = this.messDigestOTS.getDigestSize();
byte[] bArr4 = new byte[digestSize];
int i3 = 0;
this.messDigestOTS.update(bArr, 0, bArr.length);
int digestSize2 = this.messDigestOTS.getDigestSize();
byte[] bArr5 = new byte[digestSize2];
this.messDigestOTS.doFinal(bArr5, 0);
int i4 = digestSize << 3;
int i5 = this.w;
int i6 = ((i5 - 1) + i4) / i5;
int log = getLog((i6 << i5) + 1);
int i7 = this.w;
int i8 = ((((log + i7) - 1) / i7) + i6) * digestSize;
if (i8 != bArr3.length) {
return null;
}
byte[] bArr6 = new byte[i8];
int i9 = 8;
if (8 % i7 == 0) {
int i10 = 8 / i7;
int i11 = (1 << i7) - 1;
byte[] bArr7 = new byte[digestSize];
int i12 = 0;
int i13 = 0;
int i14 = 0;
while (i12 < digestSize2) {
while (i3 < i10) {
int i15 = bArr5[i12] & i11;
i13 += i15;
int i16 = digestSize2;
int i17 = i14 * digestSize;
int i18 = i10;
System.arraycopy(bArr3, i17, bArr7, 0, digestSize);
int i19 = i15;
while (i19 < i11) {
this.messDigestOTS.update(bArr7, 0, bArr7.length);
bArr7 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr7, 0);
i19++;
i13 = i13;
i8 = i8;
}
System.arraycopy(bArr7, 0, bArr6, i17, digestSize);
bArr5[i12] = (byte) (bArr5[i12] >>> this.w);
i14++;
i3++;
digestSize2 = i16;
bArr3 = bArr2;
i10 = i18;
}
i12++;
bArr3 = bArr2;
i3 = 0;
}
i = i8;
int i20 = (i6 << this.w) - i13;
int i21 = 0;
while (i21 < log) {
int i22 = i14 * digestSize;
System.arraycopy(bArr2, i22, bArr7, 0, digestSize);
for (int i23 = i20 & i11; i23 < i11; i23++) {
this.messDigestOTS.update(bArr7, 0, bArr7.length);
bArr7 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr7, 0);
}
System.arraycopy(bArr7, 0, bArr6, i22, digestSize);
int i24 = this.w;
i20 >>>= i24;
i14++;
i21 += i24;
}
} else {
i = i8;
if (i7 < 8) {
int i25 = digestSize / i7;
int i26 = (1 << i7) - 1;
byte[] bArr8 = new byte[digestSize];
int i27 = 0;
int i28 = 0;
int i29 = 0;
int i30 = 0;
while (i27 < i25) {
int i31 = 0;
long j = 0;
while (i31 < this.w) {
j ^= (bArr5[i28] & UnsignedBytes.MAX_VALUE) << (i31 << 3);
i28++;
i31++;
bArr8 = bArr8;
}
int i32 = 0;
while (i32 < i9) {
int i33 = i27;
int i34 = (int) (j & i26);
i29 += i34;
int i35 = i30 * digestSize;
System.arraycopy(bArr3, i35, bArr8, 0, digestSize);
while (true) {
int i36 = i25;
if (i34 < i26) {
this.messDigestOTS.update(bArr8, 0, bArr8.length);
bArr8 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr8, 0);
i34++;
i25 = i36;
i28 = i28;
}
}
System.arraycopy(bArr8, 0, bArr6, i35, digestSize);
j >>>= this.w;
i30++;
i32++;
i27 = i33;
i9 = 8;
}
i27++;
i9 = 8;
}
byte[] bArr9 = bArr8;
int i37 = digestSize % this.w;
long j2 = 0;
for (int i38 = 0; i38 < i37; i38++) {
j2 ^= (bArr5[i28] & 255) << (i38 << 3);
i28++;
}
byte[] bArr10 = bArr9;
int i39 = 0;
while (i39 < (i37 << 3)) {
int i40 = (int) (j2 & i26);
i29 += i40;
int i41 = i30 * digestSize;
System.arraycopy(bArr3, i41, bArr10, 0, digestSize);
while (i40 < i26) {
this.messDigestOTS.update(bArr10, 0, bArr10.length);
bArr10 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr10, 0);
i40++;
}
System.arraycopy(bArr10, 0, bArr6, i41, digestSize);
int i42 = this.w;
j2 >>>= i42;
i30++;
i39 += i42;
}
int i43 = (i6 << this.w) - i29;
int i44 = 0;
while (i44 < log) {
int i45 = i30 * digestSize;
System.arraycopy(bArr3, i45, bArr10, 0, digestSize);
for (int i46 = i43 & i26; i46 < i26; i46++) {
this.messDigestOTS.update(bArr10, 0, bArr10.length);
bArr10 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr10, 0);
}
System.arraycopy(bArr10, 0, bArr6, i45, digestSize);
int i47 = this.w;
i43 >>>= i47;
i30++;
i44 += i47;
}
} else if (i7 < 57) {
int i48 = i4 - i7;
int i49 = (1 << i7) - 1;
byte[] bArr11 = new byte[digestSize];
int i50 = 0;
int i51 = 0;
int i52 = 0;
while (i51 <= i48) {
int i53 = i51 >>> 3;
int i54 = this.w + i51;
int i55 = 0;
long j3 = 0;
while (true) {
i2 = i48;
if (i53 >= ((i54 + 7) >>> 3)) {
break;
}
j3 ^= (bArr5[i53] & UnsignedBytes.MAX_VALUE) << (i55 << 3);
i55++;
i53++;
log = log;
i48 = i2;
i6 = i6;
}
int i56 = log;
int i57 = i6;
long j4 = i49;
long j5 = (j3 >>> (i51 % 8)) & j4;
i50 = (int) (i50 + j5);
int i58 = i52 * digestSize;
System.arraycopy(bArr3, i58, bArr11, 0, digestSize);
while (true) {
int i59 = i50;
if (j5 < j4) {
this.messDigestOTS.update(bArr11, 0, bArr11.length);
bArr11 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr11, 0);
j5++;
i50 = i59;
j4 = j4;
}
}
System.arraycopy(bArr11, 0, bArr6, i58, digestSize);
i52++;
i51 = i54;
log = i56;
i48 = i2;
i6 = i57;
}
int i60 = log;
int i61 = i6;
int i62 = i51 >>> 3;
if (i62 < digestSize) {
int i63 = 0;
long j6 = 0;
while (i62 < digestSize) {
j6 ^= (bArr5[i62] & UnsignedBytes.MAX_VALUE) << (i63 << 3);
i63++;
i62++;
}
long j7 = i49;
long j8 = (j6 >>> (i51 % 8)) & j7;
i50 = (int) (i50 + j8);
int i64 = i52 * digestSize;
System.arraycopy(bArr3, i64, bArr11, 0, digestSize);
while (j8 < j7) {
this.messDigestOTS.update(bArr11, 0, bArr11.length);
bArr11 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr11, 0);
j8++;
}
System.arraycopy(bArr11, 0, bArr6, i64, digestSize);
i52++;
}
int i65 = (i61 << this.w) - i50;
int i66 = i52;
int i67 = 0;
while (i67 < i60) {
int i68 = i66 * digestSize;
System.arraycopy(bArr3, i68, bArr11, 0, digestSize);
for (long j9 = i65 & i49; j9 < i49; j9++) {
this.messDigestOTS.update(bArr11, 0, bArr11.length);
bArr11 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr11, 0);
}
System.arraycopy(bArr11, 0, bArr6, i68, digestSize);
int i69 = this.w;
i65 >>>= i69;
i66++;
i67 += i69;
}
}
}
byte[] bArr12 = new byte[digestSize];
this.messDigestOTS.update(bArr6, 0, i);
byte[] bArr13 = new byte[this.messDigestOTS.getDigestSize()];
this.messDigestOTS.doFinal(bArr13, 0);
return bArr13;
}
public WinternitzOTSVerify(Digest digest, int i) {
this.w = i;
this.messDigestOTS = digest;
}
}