what-the-bank/sources/org/bouncycastle/pqc/jcajce/provider/gmss/BCGMSSPublicKey.java

75 lines
2.8 KiB
Java

package org.bouncycastle.pqc.jcajce.provider.gmss;
import java.security.PublicKey;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.pqc.asn1.GMSSPublicKey;
import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;
import org.bouncycastle.pqc.asn1.ParSet;
import org.bouncycastle.pqc.crypto.gmss.GMSSParameters;
import org.bouncycastle.pqc.crypto.gmss.GMSSPublicKeyParameters;
import org.bouncycastle.pqc.jcajce.provider.util.KeyUtil;
import org.bouncycastle.util.encoders.Hex;
/* loaded from: classes6.dex */
public class BCGMSSPublicKey implements CipherParameters, PublicKey {
private static final long serialVersionUID = 1;
private GMSSParameters gmssParameterSet;
private GMSSParameters gmssParams;
private byte[] publicKeyBytes;
public String toString() {
StringBuilder sb = new StringBuilder("GMSS public key : ");
sb.append(new String(Hex.encode(this.publicKeyBytes)));
sb.append("\nHeight of Trees: \n");
String obj = sb.toString();
for (int i = 0; i < this.gmssParameterSet.getHeightOfTrees().length; i++) {
StringBuilder sb2 = new StringBuilder();
sb2.append(obj);
sb2.append("Layer ");
sb2.append(i);
sb2.append(" : ");
sb2.append(this.gmssParameterSet.getHeightOfTrees()[i]);
sb2.append(" WinternitzParameter: ");
sb2.append(this.gmssParameterSet.getWinternitzParameter()[i]);
sb2.append(" K: ");
sb2.append(this.gmssParameterSet.getK()[i]);
sb2.append("\n");
obj = sb2.toString();
}
return obj;
}
public byte[] getPublicKeyBytes() {
return this.publicKeyBytes;
}
public GMSSParameters getParameterSet() {
return this.gmssParameterSet;
}
@Override // java.security.Key
public String getFormat() {
return "X.509";
}
@Override // java.security.Key
public byte[] getEncoded() {
return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PQCObjectIdentifiers.gmss, new ParSet(this.gmssParameterSet.getNumOfLayers(), this.gmssParameterSet.getHeightOfTrees(), this.gmssParameterSet.getWinternitzParameter(), this.gmssParameterSet.getK()).toASN1Primitive()), new GMSSPublicKey(this.publicKeyBytes));
}
@Override // java.security.Key
public String getAlgorithm() {
return "GMSS";
}
public BCGMSSPublicKey(byte[] bArr, GMSSParameters gMSSParameters) {
this.gmssParameterSet = gMSSParameters;
this.publicKeyBytes = bArr;
}
public BCGMSSPublicKey(GMSSPublicKeyParameters gMSSPublicKeyParameters) {
this(gMSSPublicKeyParameters.getPublicKey(), gMSSPublicKeyParameters.getParameters());
}
}