109 lines
4.1 KiB
Java
109 lines
4.1 KiB
Java
|
package org.bouncycastle.pqc.jcajce.provider.rainbow;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.security.PrivateKey;
|
||
|
import org.bouncycastle.asn1.DERNull;
|
||
|
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
||
|
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
||
|
import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;
|
||
|
import org.bouncycastle.pqc.asn1.RainbowPrivateKey;
|
||
|
import org.bouncycastle.pqc.crypto.rainbow.Layer;
|
||
|
import org.bouncycastle.pqc.crypto.rainbow.RainbowPrivateKeyParameters;
|
||
|
import org.bouncycastle.pqc.crypto.rainbow.util.RainbowUtil;
|
||
|
import org.bouncycastle.pqc.jcajce.spec.RainbowPrivateKeySpec;
|
||
|
import org.bouncycastle.util.Arrays;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class BCRainbowPrivateKey implements PrivateKey {
|
||
|
private static final long serialVersionUID = 1;
|
||
|
private short[][] A1inv;
|
||
|
private short[][] A2inv;
|
||
|
private short[] b1;
|
||
|
private short[] b2;
|
||
|
private Layer[] layers;
|
||
|
private int[] vi;
|
||
|
|
||
|
public int hashCode() {
|
||
|
int length = (((((((((this.layers.length * 37) + Arrays.hashCode(this.A1inv)) * 37) + Arrays.hashCode(this.b1)) * 37) + Arrays.hashCode(this.A2inv)) * 37) + Arrays.hashCode(this.b2)) * 37) + Arrays.hashCode(this.vi);
|
||
|
for (int length2 = this.layers.length - 1; length2 >= 0; length2--) {
|
||
|
length = (length * 37) + this.layers[length2].hashCode();
|
||
|
}
|
||
|
return length;
|
||
|
}
|
||
|
|
||
|
public int[] getVi() {
|
||
|
return this.vi;
|
||
|
}
|
||
|
|
||
|
public Layer[] getLayers() {
|
||
|
return this.layers;
|
||
|
}
|
||
|
|
||
|
public short[][] getInvA2() {
|
||
|
return this.A2inv;
|
||
|
}
|
||
|
|
||
|
public short[][] getInvA1() {
|
||
|
return this.A1inv;
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public String getFormat() {
|
||
|
return "PKCS#8";
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public byte[] getEncoded() {
|
||
|
try {
|
||
|
return new PrivateKeyInfo(new AlgorithmIdentifier(PQCObjectIdentifiers.rainbow, DERNull.INSTANCE), new RainbowPrivateKey(this.A1inv, this.b1, this.A2inv, this.b2, this.vi, this.layers)).getEncoded();
|
||
|
} catch (IOException unused) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public short[] getB2() {
|
||
|
return this.b2;
|
||
|
}
|
||
|
|
||
|
public short[] getB1() {
|
||
|
return this.b1;
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public final String getAlgorithm() {
|
||
|
return "Rainbow";
|
||
|
}
|
||
|
|
||
|
public boolean equals(Object obj) {
|
||
|
if (obj == null || !(obj instanceof BCRainbowPrivateKey)) {
|
||
|
return false;
|
||
|
}
|
||
|
BCRainbowPrivateKey bCRainbowPrivateKey = (BCRainbowPrivateKey) obj;
|
||
|
boolean z = RainbowUtil.equals(this.A1inv, bCRainbowPrivateKey.getInvA1()) && RainbowUtil.equals(this.A2inv, bCRainbowPrivateKey.getInvA2()) && RainbowUtil.equals(this.b1, bCRainbowPrivateKey.getB1()) && RainbowUtil.equals(this.b2, bCRainbowPrivateKey.getB2()) && java.util.Arrays.equals(this.vi, bCRainbowPrivateKey.getVi());
|
||
|
if (this.layers.length != bCRainbowPrivateKey.getLayers().length) {
|
||
|
return false;
|
||
|
}
|
||
|
for (int length = this.layers.length - 1; length >= 0; length--) {
|
||
|
z &= this.layers[length].equals(bCRainbowPrivateKey.getLayers()[length]);
|
||
|
}
|
||
|
return z;
|
||
|
}
|
||
|
|
||
|
public BCRainbowPrivateKey(short[][] sArr, short[] sArr2, short[][] sArr3, short[] sArr4, int[] iArr, Layer[] layerArr) {
|
||
|
this.A1inv = sArr;
|
||
|
this.b1 = sArr2;
|
||
|
this.A2inv = sArr3;
|
||
|
this.b2 = sArr4;
|
||
|
this.vi = iArr;
|
||
|
this.layers = layerArr;
|
||
|
}
|
||
|
|
||
|
public BCRainbowPrivateKey(RainbowPrivateKeySpec rainbowPrivateKeySpec) {
|
||
|
this(rainbowPrivateKeySpec.getInvA1(), rainbowPrivateKeySpec.getB1(), rainbowPrivateKeySpec.getInvA2(), rainbowPrivateKeySpec.getB2(), rainbowPrivateKeySpec.getVi(), rainbowPrivateKeySpec.getLayers());
|
||
|
}
|
||
|
|
||
|
public BCRainbowPrivateKey(RainbowPrivateKeyParameters rainbowPrivateKeyParameters) {
|
||
|
this(rainbowPrivateKeyParameters.getInvA1(), rainbowPrivateKeyParameters.getB1(), rainbowPrivateKeyParameters.getInvA2(), rainbowPrivateKeyParameters.getB2(), rainbowPrivateKeyParameters.getVi(), rainbowPrivateKeyParameters.getLayers());
|
||
|
}
|
||
|
}
|