83 lines
2.8 KiB
Java
83 lines
2.8 KiB
Java
|
package org.bouncycastle.pqc.jcajce.provider.newhope;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import org.bouncycastle.asn1.ASN1OctetString;
|
||
|
import org.bouncycastle.asn1.DEROctetString;
|
||
|
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
||
|
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
||
|
import org.bouncycastle.crypto.CipherParameters;
|
||
|
import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;
|
||
|
import org.bouncycastle.pqc.crypto.newhope.NHPrivateKeyParameters;
|
||
|
import org.bouncycastle.pqc.jcajce.interfaces.NHPrivateKey;
|
||
|
import org.bouncycastle.util.Arrays;
|
||
|
import org.bouncycastle.util.Pack;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class BCNHPrivateKey implements NHPrivateKey {
|
||
|
private static final long serialVersionUID = 1;
|
||
|
private final NHPrivateKeyParameters params;
|
||
|
|
||
|
public int hashCode() {
|
||
|
return Arrays.hashCode(this.params.getSecData());
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.pqc.jcajce.interfaces.NHPrivateKey
|
||
|
public short[] getSecretData() {
|
||
|
return this.params.getSecData();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public CipherParameters getKeyParams() {
|
||
|
return this.params;
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public String getFormat() {
|
||
|
return "PKCS#8";
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public byte[] getEncoded() {
|
||
|
try {
|
||
|
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.newHope);
|
||
|
short[] secData = this.params.getSecData();
|
||
|
byte[] bArr = new byte[secData.length << 1];
|
||
|
for (int i = 0; i != secData.length; i++) {
|
||
|
Pack.shortToLittleEndian(secData[i], bArr, i << 1);
|
||
|
}
|
||
|
return new PrivateKeyInfo(algorithmIdentifier, new DEROctetString(bArr)).getEncoded();
|
||
|
} catch (IOException unused) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public final String getAlgorithm() {
|
||
|
return "NH";
|
||
|
}
|
||
|
|
||
|
public boolean equals(Object obj) {
|
||
|
if (obj == null || !(obj instanceof BCNHPrivateKey)) {
|
||
|
return false;
|
||
|
}
|
||
|
return Arrays.areEqual(this.params.getSecData(), ((BCNHPrivateKey) obj).params.getSecData());
|
||
|
}
|
||
|
|
||
|
private static short[] convert(byte[] bArr) {
|
||
|
int length = bArr.length / 2;
|
||
|
short[] sArr = new short[length];
|
||
|
for (int i = 0; i != length; i++) {
|
||
|
sArr[i] = Pack.littleEndianToShort(bArr, i << 1);
|
||
|
}
|
||
|
return sArr;
|
||
|
}
|
||
|
|
||
|
public BCNHPrivateKey(NHPrivateKeyParameters nHPrivateKeyParameters) {
|
||
|
this.params = nHPrivateKeyParameters;
|
||
|
}
|
||
|
|
||
|
public BCNHPrivateKey(PrivateKeyInfo privateKeyInfo) throws IOException {
|
||
|
this.params = new NHPrivateKeyParameters(convert(ASN1OctetString.getInstance(privateKeyInfo.parsePrivateKey()).getOctets()));
|
||
|
}
|
||
|
}
|