Skip to content

Commit 1ac8c02

Browse files
committed
TLS: Cleanup KEM tests
1 parent 42a4b26 commit 1ac8c02

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

tls/src/test/java/org/bouncycastle/tls/test/MockTlsKemClient.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import java.io.IOException;
44
import java.io.PrintStream;
5-
import java.security.SecureRandom;
65
import java.util.Hashtable;
76
import java.util.Vector;
87

98
import org.bouncycastle.asn1.x509.Certificate;
10-
import org.bouncycastle.jce.provider.BouncyCastleProvider;
119
import org.bouncycastle.tls.AlertDescription;
1210
import org.bouncycastle.tls.AlertLevel;
1311
import org.bouncycastle.tls.CertificateRequest;
@@ -29,8 +27,6 @@
2927
import org.bouncycastle.tls.TlsUtils;
3028
import org.bouncycastle.tls.crypto.TlsCertificate;
3129
import org.bouncycastle.tls.crypto.TlsCrypto;
32-
import org.bouncycastle.tls.crypto.impl.bc.BcTlsCrypto;
33-
import org.bouncycastle.tls.crypto.impl.jcajce.JcaTlsCryptoProvider;
3430
import org.bouncycastle.util.Arrays;
3531
import org.bouncycastle.util.Integers;
3632
import org.bouncycastle.util.encoders.Hex;

tls/src/test/java/org/bouncycastle/tls/test/MockTlsKemServer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import java.io.IOException;
44
import java.io.PrintStream;
5-
import java.security.SecureRandom;
65
import java.util.Hashtable;
76
import java.util.Vector;
87

98
import org.bouncycastle.asn1.x500.X500Name;
109
import org.bouncycastle.asn1.x509.Certificate;
11-
import org.bouncycastle.jce.provider.BouncyCastleProvider;
1210
import org.bouncycastle.tls.AlertDescription;
1311
import org.bouncycastle.tls.AlertLevel;
1412
import org.bouncycastle.tls.CertificateRequest;
@@ -26,9 +24,6 @@
2624
import org.bouncycastle.tls.TlsUtils;
2725
import org.bouncycastle.tls.crypto.TlsCertificate;
2826
import org.bouncycastle.tls.crypto.TlsCrypto;
29-
import org.bouncycastle.tls.crypto.impl.bc.BcTlsCrypto;
30-
import org.bouncycastle.tls.crypto.impl.jcajce.JcaTlsCrypto;
31-
import org.bouncycastle.tls.crypto.impl.jcajce.JcaTlsCryptoProvider;
3227
import org.bouncycastle.util.encoders.Hex;
3328

3429
class MockTlsKemServer

tls/src/test/java/org/bouncycastle/tls/test/TlsProtocolKemTest.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ protected TlsProtocolKemTest(TlsCrypto crypto)
2323
{
2424
this.crypto = crypto;
2525
}
26-
// mismatched ML-KEM strengths w/o classical crypto
27-
public void testMismatchStrength() throws Exception
26+
27+
// mismatched ML-KEM groups w/o classical crypto
28+
public void testMismatchedGroups() throws Exception
2829
{
2930
PipedInputStream clientRead = TlsTestUtils.createPipedInputStream();
3031
PipedInputStream serverRead = TlsTestUtils.createPipedInputStream();
@@ -42,6 +43,7 @@ public void testMismatchStrength() throws Exception
4243
catch (Exception ignored)
4344
{
4445
}
46+
4547
MockTlsKemClient client = new MockTlsKemClient(crypto, null);
4648
client.setNamedGroups(new int[]{ NamedGroup.MLKEM512 });
4749
try
@@ -56,7 +58,22 @@ public void testMismatchStrength() throws Exception
5658
serverThread.join();
5759
}
5860

59-
public void testClientServer() throws Exception
61+
public void testMLKEM512() throws Exception
62+
{
63+
implTestClientServer(NamedGroup.MLKEM512);
64+
}
65+
66+
public void testMLKEM768() throws Exception
67+
{
68+
implTestClientServer(NamedGroup.MLKEM768);
69+
}
70+
71+
public void testMLKEM1024() throws Exception
72+
{
73+
implTestClientServer(NamedGroup.MLKEM1024);
74+
}
75+
76+
private void implTestClientServer(int kemGroup) throws Exception
6077
{
6178
PipedInputStream clientRead = TlsTestUtils.createPipedInputStream();
6279
PipedInputStream serverRead = TlsTestUtils.createPipedInputStream();
@@ -66,10 +83,12 @@ public void testClientServer() throws Exception
6683
TlsClientProtocol clientProtocol = new TlsClientProtocol(clientRead, clientWrite);
6784
TlsServerProtocol serverProtocol = new TlsServerProtocol(serverRead, serverWrite);
6885

69-
ServerThread serverThread = new ServerThread(crypto, serverProtocol, null, false);
86+
ServerThread serverThread = new ServerThread(crypto, serverProtocol, new int[]{ kemGroup }, false);
7087
serverThread.start();
7188

7289
MockTlsKemClient client = new MockTlsKemClient(crypto, null);
90+
client.setNamedGroups(new int[]{ kemGroup });
91+
7392
clientProtocol.connect(client);
7493

7594
// NOTE: Because we write-all before we read-any, this length can't be more than the pipe capacity

0 commit comments

Comments
 (0)