Skip to content

Commit

Permalink
added tests New Hope/Sphincs-256 key gen.
Browse files Browse the repository at this point in the history
fixed New Hope strength at size of dimension.
  • Loading branch information
dghgit committed Aug 29, 2016
1 parent 0ee67d5 commit cdc6e9a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public void initialize(
int strength,
SecureRandom random)
{
if (strength != 1024)
{
throw new IllegalArgumentException("strength must be 1024 bits");
}
engine.init(new KeyGenerationParameters(random, 1024));
initialised = true;
}
Expand All @@ -37,8 +41,7 @@ public void initialize(
SecureRandom random)
throws InvalidAlgorithmParameterException
{
engine.init(new KeyGenerationParameters(random, 1024));
initialised = true;
throw new InvalidAlgorithmParameterException("parameter object not recognised");
}

public KeyPair generateKeyPair()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public static Test suite()
suite.addTestSuite(McElieceKeyPairGeneratorTest.class);
suite.addTestSuite(McElieceCCA2KeyPairGeneratorTest.class);
suite.addTestSuite(NewHopeTest.class);
suite.addTestSuite(NewHopeKeyPairGeneratorTest.class);
suite.addTestSuite(Sphincs256Test.class);
suite.addTestSuite(Sphincs256KeyPairGeneratorTest.class);

return new BCTestSetup(suite);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.bouncycastle.pqc.jcajce.provider.test;

import java.security.KeyFactory;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;

import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;


public class NewHopeKeyPairGeneratorTest
extends KeyPairGeneratorTest
{

protected void setUp()
{
super.setUp();
}

public void testKeyFactory()
throws Exception
{
kf = KeyFactory.getInstance("NH", "BCPQC");
kf = KeyFactory.getInstance(PQCObjectIdentifiers.newHope.getId(), "BCPQC");
}

public void testKeyPairEncoding()
throws Exception
{
kf = KeyFactory.getInstance("NH", "BCPQC");

kpg = KeyPairGenerator.getInstance("NH", "BCPQC");
kpg.initialize(1024, new SecureRandom());

performKeyPairEncodingTest(kpg.generateKeyPair());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testKeyExchange()
{
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("NH", "BCPQC");

kpGen.initialize(2048, aliceRand);
kpGen.initialize(1024, aliceRand);

KeyPair aliceKp = kpGen.generateKeyPair();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected final void performSignVerifyTest(int numPassesKPG,
{
// generate new signature instance for verification
// sigVerify = (Signature) sig.getClass().newInstance();
sigVerify = Signature.getInstance("SHA384WITHRainbow");
sigVerify = Signature.getInstance("SHA384withRainbow", "BCPQC");

for (int j = 0; j < numPassesKPG; j++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.bouncycastle.pqc.jcajce.provider.test;

import java.security.KeyFactory;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;

import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;
import org.bouncycastle.pqc.jcajce.spec.SPHINCS256KeyGenParameterSpec;


public class Sphincs256KeyPairGeneratorTest
extends KeyPairGeneratorTest
{

protected void setUp()
{
super.setUp();
}

public void testKeyFactory()
throws Exception
{
kf = KeyFactory.getInstance("SPHINCS256", "BCPQC");
kf = KeyFactory.getInstance(PQCObjectIdentifiers.newHope.getId(), "BCPQC");
}

public void testKeyPairEncoding()
throws Exception
{
kf = KeyFactory.getInstance("SPHINCS256", "BCPQC");

kpg = KeyPairGenerator.getInstance("SPHINCS256", "BCPQC");
kpg.initialize(new SPHINCS256KeyGenParameterSpec(SPHINCS256KeyGenParameterSpec.SHA512_256), new SecureRandom());
performKeyPairEncodingTest(kpg.generateKeyPair());
}

}

0 comments on commit cdc6e9a

Please sign in to comment.