Skip to content

Commit

Permalink
added sig names for specific SLH-DSA keys - relates to github #1841
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Sep 21, 2024
1 parent 11877fc commit 694ba5d
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,53 @@ public void configure(ConfigurableProvider provider)
addKeyPairGeneratorAlgorithm(provider, "SLH-DSA-SHAKE-256S-WITH-SHAKE256", PREFIX + "SLHDSAKeyPairGeneratorSpi$HashShake_256s", NISTObjectIdentifiers.id_hash_slh_dsa_shake_256s_with_shake256);
addKeyPairGeneratorAlgorithm(provider, "SLH-DSA-SHAKE-256F-WITH-SHAKE256", PREFIX + "SLHDSAKeyPairGeneratorSpi$HashShake_256f", NISTObjectIdentifiers.id_hash_slh_dsa_shake_256f_with_shake256);

String[] algNames = new String[]
{
"SLH-DSA-SHA2-128S",
"SLH-DSA-SHA2-128F",
"SLH-DSA-SHA2-192S",
"SLH-DSA-SHA2-192F",
"SLH-DSA-SHA2-256S",
"SLH-DSA-SHA2-256F",
"SLH-DSA-SHAKE-128S",
"SLH-DSA-SHAKE-128F",
"SLH-DSA-SHAKE-192S",
"SLH-DSA-SHAKE-192F",
"SLH-DSA-SHAKE-256S",
"SLH-DSA-SHAKE-256F"
};

String[] hashAlgNames = new String[]
{
"SLH-DSA-SHA2-128S-WITH-SHA256",
"SLH-DSA-SHA2-128F-WITH-SHA256",
"SLH-DSA-SHA2-192S-WITH-SHA512",
"SLH-DSA-SHA2-192F-WITH-SHA512",
"SLH-DSA-SHA2-256S-WITH-SHA512",
"SLH-DSA-SHA2-256F-WITH-SHA512",
"SLH-DSA-SHAKE-128S-WITH-SHAKE128",
"SLH-DSA-SHAKE-128F-WITH-SHAKE128",
"SLH-DSA-SHAKE-192S-WITH-SHAKE256",
"SLH-DSA-SHAKE-192F-WITH-SHAKE256",
"SLH-DSA-SHAKE-256S-WITH-SHAKE256",
"SLH-DSA-SHAKE-256F-WITH-SHAKE256"
};

addSignatureAlgorithm(provider, "SLH-DSA", PREFIX + "SignatureSpi$Direct", (ASN1ObjectIdentifier)null);
provider.addAlgorithm("Alg.Alias.Signature.SLHDSA", "SLH-DSA");
addSignatureAlgorithm(provider, "HASH-SLH-DSA", PREFIX + "HashSignatureSpi$Direct", (ASN1ObjectIdentifier)null);
provider.addAlgorithm("Alg.Alias.Signature.HASHWITHSLHDSA", "HASH-SLH-DSA");

for (int i = 0; i != algNames.length; i++)
{
provider.addAlgorithm("Alg.Alias.Signature." + algNames[i], "SLH-DSA");
}

for (int i = 0; i != hashAlgNames.length; i++)
{
provider.addAlgorithm("Alg.Alias.Signature." + hashAlgNames[i], "HASH-SLH-DSA");
}

ASN1ObjectIdentifier[] nistOids = new ASN1ObjectIdentifier[]
{
NISTObjectIdentifiers.id_slh_dsa_sha2_128s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static Test suite()
suite.addTestSuite(CompositeKeyTest.class);
suite.addTestSuite(CompositeSignaturesTest.class);
suite.addTestSuite(BouncyCastleProviderTest.class);
suite.addTestSuite(PQCSignatureTest.class);

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

import java.security.Key;
import java.security.KeyPairGenerator;
import java.security.Security;
import java.security.Signature;

import junit.framework.TestCase;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class PQCSignatureTest
extends TestCase
{
public void setUp()
{
if (Security.getProvider("BC") == null)
{
Security.addProvider(new BouncyCastleProvider());
}
}

private static Signature deriveSignatureFromKey(Key key)
throws Exception
{
return Signature.getInstance(key.getAlgorithm(), "BC");
}

public void testNistSignature()
throws Exception
{
ASN1ObjectIdentifier[] nistOids = new ASN1ObjectIdentifier[]
{
NISTObjectIdentifiers.id_slh_dsa_sha2_128s,
NISTObjectIdentifiers.id_slh_dsa_sha2_128f,
NISTObjectIdentifiers.id_slh_dsa_shake_128s,
NISTObjectIdentifiers.id_slh_dsa_shake_128f,
NISTObjectIdentifiers.id_slh_dsa_sha2_192s,
NISTObjectIdentifiers.id_slh_dsa_sha2_192f,
NISTObjectIdentifiers.id_slh_dsa_shake_192s,
NISTObjectIdentifiers.id_slh_dsa_shake_192f,
NISTObjectIdentifiers.id_slh_dsa_sha2_256s,
NISTObjectIdentifiers.id_slh_dsa_sha2_256f,
NISTObjectIdentifiers.id_slh_dsa_shake_256s,
NISTObjectIdentifiers.id_slh_dsa_shake_256f,
NISTObjectIdentifiers.id_hash_slh_dsa_sha2_128s_with_sha256,
NISTObjectIdentifiers.id_hash_slh_dsa_sha2_128f_with_sha256,
NISTObjectIdentifiers.id_hash_slh_dsa_shake_128s_with_shake128,
NISTObjectIdentifiers.id_hash_slh_dsa_shake_128f_with_shake128,
NISTObjectIdentifiers.id_hash_slh_dsa_sha2_192s_with_sha512,
NISTObjectIdentifiers.id_hash_slh_dsa_sha2_192f_with_sha512,
NISTObjectIdentifiers.id_hash_slh_dsa_shake_192s_with_shake256,
NISTObjectIdentifiers.id_hash_slh_dsa_shake_192f_with_shake256,
NISTObjectIdentifiers.id_hash_slh_dsa_sha2_256s_with_sha512,
NISTObjectIdentifiers.id_hash_slh_dsa_sha2_256f_with_sha512,
NISTObjectIdentifiers.id_hash_slh_dsa_shake_256s_with_shake256,
NISTObjectIdentifiers.id_hash_slh_dsa_shake_256f_with_shake256
};

for (int i = 0; i != nistOids.length; i++)
{
KeyPairGenerator ml_dsa_kp = KeyPairGenerator.getInstance(nistOids[i].getId(), "BC");
Signature ml_dsa_sig = deriveSignatureFromKey(ml_dsa_kp.generateKeyPair().getPrivate());
}
}
}

0 comments on commit 694ba5d

Please sign in to comment.