org.bouncycastle.pqc.crypto.newhope.NHExchangePairGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-ext-jdk15on Show documentation
Show all versions of bcprov-ext-jdk15on 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. Note: this package includes the NTRU encryption algorithms.
The newest version!
package org.bouncycastle.pqc.crypto.newhope;
import java.security.SecureRandom;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.pqc.crypto.ExchangePair;
import org.bouncycastle.pqc.crypto.ExchangePairGenerator;
public class NHExchangePairGenerator
implements ExchangePairGenerator
{
private final SecureRandom random;
public NHExchangePairGenerator(SecureRandom random)
{
this.random = random;
}
public ExchangePair GenerateExchange(AsymmetricKeyParameter senderPublicKey)
{
return generateExchange(senderPublicKey);
}
public ExchangePair generateExchange(AsymmetricKeyParameter senderPublicKey)
{
NHPublicKeyParameters pubKey = (NHPublicKeyParameters)senderPublicKey;
byte[] sharedValue = new byte[NewHope.AGREEMENT_SIZE];
byte[] publicKeyValue = new byte[NewHope.SENDB_BYTES];
NewHope.sharedB(random, sharedValue, publicKeyValue, pubKey.pubData);
return new ExchangePair(new NHPublicKeyParameters(publicKeyValue), sharedValue);
}
}