what-the-bank/sources/org/bouncycastle/pqc/crypto/sphincs/SPHINCS256KeyPairGenerator....

36 lines
1.6 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.pqc.crypto.sphincs;
import java.security.SecureRandom;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.KeyGenerationParameters;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.pqc.crypto.sphincs.Tree;
/* loaded from: classes6.dex */
public class SPHINCS256KeyPairGenerator implements AsymmetricCipherKeyPairGenerator {
private SecureRandom random;
private Digest treeDigest;
@Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
public void init(KeyGenerationParameters keyGenerationParameters) {
this.random = keyGenerationParameters.getRandom();
this.treeDigest = ((SPHINCS256KeyGenerationParameters) keyGenerationParameters).getTreeDigest();
}
@Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
public AsymmetricCipherKeyPair generateKeyPair() {
Tree.leafaddr leafaddrVar = new Tree.leafaddr();
byte[] bArr = new byte[1088];
this.random.nextBytes(bArr);
byte[] bArr2 = new byte[1056];
System.arraycopy(bArr, 32, bArr2, 0, 1024);
leafaddrVar.level = 11;
leafaddrVar.subtree = 0L;
leafaddrVar.subleaf = 0L;
Tree.treehash(new HashFunctions(this.treeDigest), bArr2, 1024, 5, bArr, leafaddrVar, bArr2, 0);
return new AsymmetricCipherKeyPair((AsymmetricKeyParameter) new SPHINCSPublicKeyParameters(bArr2), (AsymmetricKeyParameter) new SPHINCSPrivateKeyParameters(bArr));
}
}