All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.pqc.crypto.ntru.NTRUKeyPairGenerator Maven / Gradle / Ivy

Go to download

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.4.

The newest version!
package org.bouncycastle.pqc.crypto.ntru;

import java.security.SecureRandom;

import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
import org.bouncycastle.crypto.KeyGenerationParameters;
import org.bouncycastle.pqc.math.ntru.parameters.NTRUParameterSet;
import org.bouncycastle.util.Arrays;

/**
 * Key generator for NTRU.
 * 

* Note: the {@link #init(KeyGenerationParameters)} method only accepts {@link NTRUKeyParameters}. Otherwise, a * {@link ClassCastException} may occur. */ public class NTRUKeyPairGenerator implements AsymmetricCipherKeyPairGenerator { private NTRUKeyGenerationParameters params; private SecureRandom random; public void init(KeyGenerationParameters param) { this.params = (NTRUKeyGenerationParameters)param; this.random = param.getRandom(); } public AsymmetricCipherKeyPair generateKeyPair() { NTRUParameters parameters = params.getParameters(); NTRUParameterSet parameterSet = parameters.getParameterSet(); byte[] seed = new byte[parameterSet.sampleFgBytes()]; random.nextBytes(seed); NTRUOWCPA owcpa = new NTRUOWCPA(parameterSet); OWCPAKeyPair owcpaKeys = owcpa.keypair(seed); byte[] publicKey = owcpaKeys.publicKey; byte[] prfBytes = new byte[parameterSet.prfKeyBytes()]; random.nextBytes(prfBytes); byte[] privateKey = Arrays.concatenate(owcpaKeys.privateKey, prfBytes); return new AsymmetricCipherKeyPair( new NTRUPublicKeyParameters(parameters, publicKey), new NTRUPrivateKeyParameters(parameters, privateKey)); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy