org.bouncycastle.pqc.crypto.bike.BIKEKEMGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-debug-jdk15to18 Show documentation
Show all versions of bcprov-debug-jdk15to18 Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.
The newest version!
package org.bouncycastle.pqc.crypto.bike;
import java.security.SecureRandom;
import org.bouncycastle.crypto.EncapsulatedSecretGenerator;
import org.bouncycastle.crypto.SecretWithEncapsulation;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.pqc.crypto.util.SecretWithEncapsulationImpl;
import org.bouncycastle.util.Arrays;
public class BIKEKEMGenerator
implements EncapsulatedSecretGenerator
{
private final SecureRandom sr;
public BIKEKEMGenerator(SecureRandom random)
{
this.sr = random;
}
@Override
public SecretWithEncapsulation generateEncapsulated(AsymmetricKeyParameter recipientKey)
{
BIKEPublicKeyParameters key = (BIKEPublicKeyParameters)recipientKey;
BIKEEngine engine = key.getParameters().getEngine();
byte[] K = new byte[key.getParameters().getLByte()];
byte[] c0 = new byte[key.getParameters().getRByte()];
byte[] c1 = new byte[key.getParameters().getLByte()];
byte[] h = key.publicKey;
engine.encaps(c0, c1, K, h, this.sr);
byte[] cipherText = Arrays.concatenate(c0, c1);
return new SecretWithEncapsulationImpl(Arrays.copyOfRange(K, 0, key.getParameters().getSessionKeySize() / 8), cipherText);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy