Skip to content

Commit

Permalink
added ML-DSA-44/Ed25519 test.
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Dec 22, 2024
1 parent 26b77b5 commit 185cf12
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,51 @@ public void testMLDSA44andP256()
CompositePublicKey puKey = (CompositePublicKey)keyConverter.getPublicKey((SubjectPublicKeyInfo)pPrs.readObject());
}

public void testMLDSA44andEd25519()
throws Exception
{
//
// set up the keys
//
KeyPairGenerator ecKpg = KeyPairGenerator.getInstance("ED25519", "BC");

KeyPair ecKp = ecKpg.generateKeyPair();

PrivateKey ecPriv = ecKp.getPrivate();
PublicKey ecPub = ecKp.getPublic();

KeyPairGenerator rmldsaKpg = KeyPairGenerator.getInstance("ML-DSA-44", "BC");

KeyPair mldsaKp = rmldsaKpg.generateKeyPair();

PrivateKey mldsaPriv = mldsaKp.getPrivate();
PublicKey mldsaPub = mldsaKp.getPublic();

CompositePrivateKey mlecPriv = new CompositePrivateKey(MiscObjectIdentifiers.id_MLDSA44_Ed25519_SHA512, mldsaPriv, ecPriv);

StringWriter sWrt = new StringWriter();
JcaPEMWriter pWrt = new JcaPEMWriter(sWrt);

pWrt.writeObject(mlecPriv);

pWrt.close();

CompositePublicKey mlecPub = new CompositePublicKey(mldsaPub, ecPub);

pWrt = new JcaPEMWriter(sWrt);

pWrt.writeObject(mlecPub);

pWrt.close();

PEMParser pPrs = new PEMParser(new StringReader(sWrt.toString()));

JcaPEMKeyConverter keyConverter = new JcaPEMKeyConverter().setProvider("BC");
CompositePrivateKey prKey = (CompositePrivateKey)keyConverter.getPrivateKey((PrivateKeyInfo)pPrs.readObject());

CompositePublicKey puKey = (CompositePublicKey)keyConverter.getPublicKey((SubjectPublicKeyInfo)pPrs.readObject());
}

public void testMLDSA87andEd448()
throws Exception
{
Expand Down

0 comments on commit 185cf12

Please sign in to comment.