Skip to content

Commit d40c854

Browse files
author
gefeili
committed
Remove the ML-KEM branch from pqc.crypto.util.PQCOtherInfoGenerator.PartyU/PartyV, as ML-KEM's OtherInfo generation is already covered by org.bouncycastle.crypto.util.OtherInfoGenerator; only NTRU remains here now, so the constructor parameter reverts from CipherParameters back to org.bouncycastle.pqc.crypto.KEMParameters (which NTRUParameters, unlike the canonical MLKEMParameters, still implements).
1 parent 15145b3 commit d40c854

2 files changed

Lines changed: 5 additions & 49 deletions

File tree

‎core/src/main/java/org/bouncycastle/pqc/crypto/util/PQCOtherInfoGenerator.java‎

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55

66
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
77
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
8-
import org.bouncycastle.crypto.CipherParameters;
98
import org.bouncycastle.crypto.EncapsulatedSecretExtractor;
109
import org.bouncycastle.crypto.EncapsulatedSecretGenerator;
1110
import org.bouncycastle.crypto.SecretWithEncapsulation;
1211
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
1312
import org.bouncycastle.crypto.util.DEROtherInfo;
14-
import org.bouncycastle.crypto.generators.MLKEMKeyPairGenerator;
15-
import org.bouncycastle.crypto.kems.MLKEMExtractor;
16-
import org.bouncycastle.crypto.kems.MLKEMGenerator;
17-
import org.bouncycastle.crypto.params.MLKEMKeyGenerationParameters;
18-
import org.bouncycastle.crypto.params.MLKEMParameters;
19-
import org.bouncycastle.crypto.params.MLKEMPrivateKeyParameters;
13+
import org.bouncycastle.pqc.crypto.KEMParameters;
2014
import org.bouncycastle.pqc.crypto.ntru.NTRUKEMExtractor;
2115
import org.bouncycastle.pqc.crypto.ntru.NTRUKEMGenerator;
2216
import org.bouncycastle.pqc.crypto.ntru.NTRUKeyGenerationParameters;
@@ -67,21 +61,11 @@ public static class PartyU
6761
* @param partyVInfo receiver party info.
6862
* @param random a source of randomness.
6963
*/
70-
public PartyU(CipherParameters kemParams, AlgorithmIdentifier algorithmID, byte[] partyUInfo, byte[] partyVInfo, SecureRandom random)
64+
public PartyU(KEMParameters kemParams, AlgorithmIdentifier algorithmID, byte[] partyUInfo, byte[] partyVInfo, SecureRandom random)
7165
{
7266
super(algorithmID, partyUInfo, partyVInfo, random);
7367

74-
if (kemParams instanceof MLKEMParameters)
75-
{
76-
MLKEMKeyPairGenerator kPg = new MLKEMKeyPairGenerator();
77-
78-
kPg.init(new MLKEMKeyGenerationParameters(random, (MLKEMParameters)kemParams));
79-
80-
aKp = kPg.generateKeyPair();
81-
82-
encSE = new MLKEMExtractor((MLKEMPrivateKeyParameters)aKp.getPrivate());
83-
}
84-
else if (kemParams instanceof NTRUParameters)
68+
if (kemParams instanceof NTRUParameters)
8569
{
8670
NTRUKeyPairGenerator kPg = new NTRUKeyPairGenerator();
8771

@@ -140,15 +124,11 @@ public static class PartyV
140124
* @param partyVInfo receiver party info.
141125
* @param random a source of randomness.
142126
*/
143-
public PartyV(CipherParameters kemParams, AlgorithmIdentifier algorithmID, byte[] partyUInfo, byte[] partyVInfo, SecureRandom random)
127+
public PartyV(KEMParameters kemParams, AlgorithmIdentifier algorithmID, byte[] partyUInfo, byte[] partyVInfo, SecureRandom random)
144128
{
145129
super(algorithmID, partyUInfo, partyVInfo, random);
146130

147-
if (kemParams instanceof MLKEMParameters)
148-
{
149-
encSG = new MLKEMGenerator(random);
150-
}
151-
else if (kemParams instanceof NTRUParameters)
131+
if (kemParams instanceof NTRUParameters)
152132
{
153133
encSG = new NTRUKEMGenerator(random);
154134
}

‎core/src/test/java/org/bouncycastle/pqc/crypto/test/MLKEMTest.java‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.bouncycastle.crypto.util.PrivateKeyInfoFactory;
2727
import org.bouncycastle.crypto.util.PublicKeyFactory;
2828
import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory;
29-
import org.bouncycastle.pqc.crypto.util.PQCOtherInfoGenerator;
3029
import org.bouncycastle.internal.asn1.oiw.OIWObjectIdentifiers;
3130
import org.bouncycastle.test.TestResourceFinder;
3231
import org.bouncycastle.util.Arrays;
@@ -557,29 +556,6 @@ public void testPrivInfoGeneration()
557556

558557
assertTrue(Arrays.areEqual(otherInfoU.getEncoded(), otherInfoV.getEncoded()));
559558
}
560-
561-
public void testPqcOtherInfoGeneration()
562-
throws IOException
563-
{
564-
// Exercises org.bouncycastle.pqc.crypto.util.PQCOtherInfoGenerator's ML-KEM branch - a
565-
// separate class from org.bouncycastle.crypto.util.OtherInfoGenerator already exercised
566-
// above - which, until now, had no test coverage at all (only NTRU's branch was tested).
567-
PQCOtherInfoGenerator.PartyU partyU = new PQCOtherInfoGenerator.PartyU(MLKEMParameters.ml_kem_512,
568-
new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1), Hex.decode("beef"), Hex.decode("cafe"), RANDOM);
569-
570-
byte[] partA = partyU.getSuppPrivInfoPartA();
571-
572-
PQCOtherInfoGenerator.PartyV partyV = new PQCOtherInfoGenerator.PartyV(MLKEMParameters.ml_kem_512,
573-
new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1), Hex.decode("beef"), Hex.decode("cafe"), RANDOM);
574-
575-
byte[] partB = partyV.getSuppPrivInfoPartB(partA);
576-
577-
DEROtherInfo otherInfoU = partyU.generate(partB);
578-
579-
DEROtherInfo otherInfoV = partyV.generate();
580-
581-
assertTrue(Arrays.areEqual(otherInfoU.getEncoded(), otherInfoV.getEncoded()));
582-
}
583559

584560
public void testMLKEM()
585561
{

0 commit comments

Comments
 (0)