Skip to content

Commit ee16879

Browse files
author
royb
committed
Fixed MLS test: converted encoded P521 private keys to match required length
1 parent 8b813e1 commit ee16879

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: mls/src/test/java/org/bouncycastle/mls/test/ClientVectorTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.BufferedReader;
44
import java.io.InputStream;
55
import java.io.InputStreamReader;
6+
import java.math.BigInteger;
67
import java.util.ArrayList;
78
import java.util.HashMap;
89
import java.util.List;
@@ -11,6 +12,7 @@
1112

1213
import junit.framework.TestCase;
1314
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
15+
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
1416
import org.bouncycastle.mls.TreeKEM.TreeKEMPublicKey;
1517
import org.bouncycastle.mls.codec.MLSInputStream;
1618
import org.bouncycastle.mls.codec.MLSMessage;
@@ -20,6 +22,7 @@
2022
import org.bouncycastle.mls.protocol.Group;
2123
import org.bouncycastle.test.TestResourceFinder;
2224
import org.bouncycastle.util.Arrays;
25+
import org.bouncycastle.util.BigIntegers;
2326
import org.bouncycastle.util.encoders.Hex;
2427

2528
public class ClientVectorTest
@@ -134,6 +137,14 @@ public Epoch(List<byte[]> proposals, byte[] commit, byte[] epoch_authenticator)
134137
}
135138

136139
MlsCipherSuite suite = MlsCipherSuite.getSuite(cipherSuite);
140+
141+
if(cipherSuite == MlsCipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521)
142+
{
143+
//Converts encoded HPKE private key for P521 to comply with length constraints
144+
encryption_priv = BigIntegers.asUnsignedByteArray(66, new BigInteger(1, encryption_priv));
145+
init_priv = BigIntegers.asUnsignedByteArray(66, new BigInteger(1, init_priv));
146+
}
147+
137148
AsymmetricCipherKeyPair leafKeyPair = suite.getHPKE().deserializePrivateKey(encryption_priv, null);
138149
Map<Secret, byte[]> externalPsks = new HashMap<Secret, byte[]>();
139150
for (PreSharedKeyID ext : externalPSKs)

0 commit comments

Comments
 (0)