2424import org .signal .libsignal .protocol .ecc .ECPublicKey ;
2525import org .signal .libsignal .protocol .groups .GroupCipher ;
2626import org .signal .libsignal .protocol .groups .GroupSessionBuilder ;
27+ import org .signal .libsignal .protocol .kem .KEMKeyPair ;
28+ import org .signal .libsignal .protocol .kem .KEMKeyType ;
2729import org .signal .libsignal .protocol .message .CiphertextMessage ;
2830import org .signal .libsignal .protocol .message .DecryptionErrorMessage ;
2931import org .signal .libsignal .protocol .message .PlaintextContent ;
3234import org .signal .libsignal .protocol .state .PreKeyRecord ;
3335import org .signal .libsignal .protocol .state .SessionRecord ;
3436import org .signal .libsignal .protocol .state .SignedPreKeyRecord ;
37+ import org .signal .libsignal .protocol .state .KyberPreKeyRecord ;
3538
3639import org .signal .libsignal .internal .Native ;
3740import org .signal .libsignal .internal .NativeHandleGuard ;
3841
3942import org .signal .libsignal .protocol .util .Hex ;
40- import org .signal .libsignal .protocol .util .Pair ;
4143
4244import java .util .ArrayList ;
4345import java .util .Arrays ;
@@ -55,6 +57,14 @@ private static SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityK
5557 return new SignedPreKeyRecord (signedPreKeyId , System .currentTimeMillis (), keyPair , signature );
5658 }
5759
60+ private static KyberPreKeyRecord generateKyberPreKey (IdentityKeyPair identityKeyPair , int kyberPreKeyId )
61+ throws InvalidKeyException {
62+ KEMKeyPair keyPair = KEMKeyPair .generate (KEMKeyType .KYBER_1024 );
63+ byte [] signature = Curve .calculateSignature (identityKeyPair .getPrivateKey (), keyPair .getPublicKey ().serialize ());
64+
65+ return new KyberPreKeyRecord (kyberPreKeyId , System .currentTimeMillis (), keyPair , signature );
66+ }
67+
5868 public void testEncryptDecrypt () throws UntrustedIdentityException , InvalidKeyException , InvalidCertificateException , InvalidMetadataMessageException , ProtocolDuplicateMessageException , ProtocolUntrustedIdentityException , ProtocolLegacyMessageException , ProtocolInvalidKeyException , InvalidMetadataVersionException , ProtocolInvalidVersionException , ProtocolInvalidMessageException , ProtocolInvalidKeyIdException , ProtocolNoSessionException , SelfSendException {
5969 TestInMemorySignalProtocolStore aliceStore = new TestInMemorySignalProtocolStore ();
6070 TestInMemorySignalProtocolStore bobStore = new TestInMemorySignalProtocolStore ();
@@ -201,8 +211,9 @@ public void testEncryptGroupWithBadRegistrationId() throws UntrustedIdentityExce
201211 ECKeyPair bobPreKey = Curve .generateKeyPair ();
202212 IdentityKeyPair bobIdentityKey = bobStore .getIdentityKeyPair ();
203213 SignedPreKeyRecord bobSignedPreKey = generateSignedPreKey (bobIdentityKey , 2 );
214+ KyberPreKeyRecord bobKyberPreKey = generateKyberPreKey (bobIdentityKey , 12 );
204215
205- PreKeyBundle bobBundle = new PreKeyBundle (0x4000 , 1 , 1 , bobPreKey .getPublicKey (), 2 , bobSignedPreKey .getKeyPair ().getPublicKey (), bobSignedPreKey .getSignature (), bobIdentityKey .getPublicKey ());
216+ PreKeyBundle bobBundle = new PreKeyBundle (0x4000 , 1 , 1 , bobPreKey .getPublicKey (), 2 , bobSignedPreKey .getKeyPair ().getPublicKey (), bobSignedPreKey .getSignature (), bobIdentityKey .getPublicKey (), 12 , bobKyberPreKey . getKeyPair (). getPublicKey (), bobKyberPreKey . getSignature () );
206217 SessionBuilder aliceSessionBuilder = new SessionBuilder (aliceStore , bobAddress );
207218 aliceSessionBuilder .process (bobBundle );
208219
@@ -239,16 +250,18 @@ public void testEncryptGroupWithManyRecipients() throws UntrustedIdentityExcepti
239250 ECKeyPair bobPreKey = Curve .generateKeyPair ();
240251 IdentityKeyPair bobIdentityKey = bobStore .getIdentityKeyPair ();
241252 SignedPreKeyRecord bobSignedPreKey = generateSignedPreKey (bobIdentityKey , 2 );
253+ KyberPreKeyRecord bobKyberPreKey = generateKyberPreKey (bobIdentityKey , 12 );
242254
243- PreKeyBundle bobBundle = new PreKeyBundle (0x1234 , 1 , 1 , bobPreKey .getPublicKey (), 2 , bobSignedPreKey .getKeyPair ().getPublicKey (), bobSignedPreKey .getSignature (), bobIdentityKey .getPublicKey ());
255+ PreKeyBundle bobBundle = new PreKeyBundle (0x1234 , 1 , 1 , bobPreKey .getPublicKey (), 2 , bobSignedPreKey .getKeyPair ().getPublicKey (), bobSignedPreKey .getSignature (), bobIdentityKey .getPublicKey (), 12 , bobKyberPreKey . getKeyPair (). getPublicKey (), bobKyberPreKey . getSignature () );
244256 SessionBuilder aliceSessionBuilderForBob = new SessionBuilder (aliceStore , bobAddress );
245257 aliceSessionBuilderForBob .process (bobBundle );
246258
247259 ECKeyPair carolPreKey = Curve .generateKeyPair ();
248260 IdentityKeyPair carolIdentityKey = carolStore .getIdentityKeyPair ();
249261 SignedPreKeyRecord carolSignedPreKey = generateSignedPreKey (carolIdentityKey , 2 );
262+ KyberPreKeyRecord carolKyberPreKey = generateKyberPreKey (carolIdentityKey , 12 );
250263
251- PreKeyBundle carolBundle = new PreKeyBundle (0x1111 , 1 , 1 , carolPreKey .getPublicKey (), 2 , carolSignedPreKey .getKeyPair ().getPublicKey (), carolSignedPreKey .getSignature (), carolIdentityKey .getPublicKey ());
264+ PreKeyBundle carolBundle = new PreKeyBundle (0x1111 , 1 , 1 , carolPreKey .getPublicKey (), 2 , carolSignedPreKey .getKeyPair ().getPublicKey (), carolSignedPreKey .getSignature (), carolIdentityKey .getPublicKey (), 12 , carolKyberPreKey . getKeyPair (). getPublicKey (), carolKyberPreKey . getSignature () );
252265 SessionBuilder aliceSessionBuilderForCarol = new SessionBuilder (aliceStore , carolAddress );
253266 aliceSessionBuilderForCarol .process (carolBundle );
254267
@@ -384,13 +397,14 @@ private void initializeSessions(TestInMemorySignalProtocolStore aliceStore, Test
384397 ECKeyPair bobPreKey = Curve .generateKeyPair ();
385398 IdentityKeyPair bobIdentityKey = bobStore .getIdentityKeyPair ();
386399 SignedPreKeyRecord bobSignedPreKey = generateSignedPreKey (bobIdentityKey , 2 );
400+ KyberPreKeyRecord bobKyberPreKey = generateKyberPreKey (bobIdentityKey , 12 );
387401
388- PreKeyBundle bobBundle = new PreKeyBundle (1 , 1 , 1 , bobPreKey .getPublicKey (), 2 , bobSignedPreKey .getKeyPair ().getPublicKey (), bobSignedPreKey .getSignature (), bobIdentityKey .getPublicKey ());
402+ PreKeyBundle bobBundle = new PreKeyBundle (1 , 1 , 1 , bobPreKey .getPublicKey (), 2 , bobSignedPreKey .getKeyPair ().getPublicKey (), bobSignedPreKey .getSignature (), bobIdentityKey .getPublicKey (), 12 , bobKyberPreKey . getKeyPair (). getPublicKey (), bobKyberPreKey . getSignature () );
389403 SessionBuilder aliceSessionBuilder = new SessionBuilder (aliceStore , bobAddress );
390404 aliceSessionBuilder .process (bobBundle );
391405
392406 bobStore .storeSignedPreKey (2 , bobSignedPreKey );
407+ bobStore .storeKyberPreKey (12 , bobKyberPreKey );
393408 bobStore .storePreKey (1 , new PreKeyRecord (1 , bobPreKey ));
394-
395409 }
396410}
0 commit comments