@@ -630,6 +630,58 @@ struct Sigma1Params
630
630
static constexpr bool expectSuccess = true ;
631
631
};
632
632
633
+ TEST_F (TestCASESession, DestinationIdTest)
634
+ {
635
+ // Validate example test vector from CASE section of spec
636
+
637
+ const uint8_t kRootPubKeyFromSpec [Crypto::CHIP_CRYPTO_PUBLIC_KEY_SIZE_BYTES] = {
638
+ 0x04 , 0x4a , 0x9f , 0x42 , 0xb1 , 0xca , 0x48 , 0x40 , 0xd3 , 0x72 , 0x92 , 0xbb , 0xc7 , 0xf6 , 0xa7 , 0xe1 , 0x1e ,
639
+ 0x22 , 0x20 , 0x0c , 0x97 , 0x6f , 0xc9 , 0x00 , 0xdb , 0xc9 , 0x8a , 0x7a , 0x38 , 0x3a , 0x64 , 0x1c , 0xb8 , 0x25 ,
640
+ 0x4a , 0x2e , 0x56 , 0xd4 , 0xe2 , 0x95 , 0xa8 , 0x47 , 0x94 , 0x3b , 0x4e , 0x38 , 0x97 , 0xc4 , 0xa7 , 0x73 , 0xe9 ,
641
+ 0x30 , 0x27 , 0x7b , 0x4d , 0x9f , 0xbe , 0xde , 0x8a , 0x05 , 0x26 , 0x86 , 0xbf , 0xac , 0xfa
642
+ };
643
+
644
+ const uint8_t kIpkOperationalGroupKeyFromSpec [Crypto::CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES] = {
645
+ 0x9b , 0xc6 , 0x1c , 0xd9 , 0xc6 , 0x2a , 0x2d , 0xf6 , 0xd6 , 0x4d , 0xfc , 0xaa , 0x9d , 0xc4 , 0x72 , 0xd4
646
+ };
647
+
648
+ const uint8_t kInitiatorRandomFromSpec [Sigma1Params::initiatorRandomLen] = { 0x7e , 0x17 , 0x12 , 0x31 , 0x56 , 0x8d , 0xfa , 0x17 ,
649
+ 0x20 , 0x6b , 0x3a , 0xcc , 0xf8 , 0xfa , 0xec , 0x2f ,
650
+ 0x4d , 0x21 , 0xb5 , 0x80 , 0x11 , 0x31 , 0x96 , 0xf4 ,
651
+ 0x7c , 0x7c , 0x4d , 0xeb , 0x81 , 0x0a , 0x73 , 0xdc };
652
+
653
+ const uint8_t kExpectedDestinationIdFromSpec [Crypto::kSHA256_Hash_Length ] = { 0xdc , 0x35 , 0xdd , 0x5f , 0xc9 , 0x13 , 0x4c , 0xc5 ,
654
+ 0x54 , 0x45 , 0x38 , 0xc9 , 0xc3 , 0xfc , 0x42 , 0x97 ,
655
+ 0xc1 , 0xec , 0x33 , 0x70 , 0xc8 , 0x39 , 0x13 , 0x6a ,
656
+ 0x80 , 0xe1 , 0x07 , 0x96 , 0x45 , 0x1d , 0x4c , 0x53 };
657
+
658
+ const FabricId kFabricIdFromSpec = 0x2906C908D115D362 ;
659
+ const NodeId kNodeIdFromSpec = 0xCD5544AA7B13EF14 ;
660
+
661
+ uint8_t destinationIdBuf[Crypto::kSHA256_Hash_Length ] = { 0 };
662
+ MutableByteSpan destinationIdSpan (destinationIdBuf);
663
+
664
+ // Test exact example
665
+ CHIP_ERROR err =
666
+ GenerateCaseDestinationId (ByteSpan (kIpkOperationalGroupKeyFromSpec ), ByteSpan (kInitiatorRandomFromSpec ),
667
+ ByteSpan (kRootPubKeyFromSpec ), kFabricIdFromSpec , kNodeIdFromSpec , destinationIdSpan);
668
+ EXPECT_EQ (err, CHIP_NO_ERROR);
669
+ EXPECT_EQ (destinationIdSpan.size (), sizeof (destinationIdBuf));
670
+ EXPECT_TRUE (destinationIdSpan.data_equal (ByteSpan (kExpectedDestinationIdFromSpec )));
671
+
672
+ memset (destinationIdSpan.data (), 0 , destinationIdSpan.size ());
673
+
674
+ // Test changing input: should yield different
675
+ err = GenerateCaseDestinationId (ByteSpan (kIpkOperationalGroupKeyFromSpec ), ByteSpan (kInitiatorRandomFromSpec ),
676
+ ByteSpan (kRootPubKeyFromSpec ), kFabricIdFromSpec ,
677
+ kNodeIdFromSpec + 1 , // <--- Change node ID
678
+ destinationIdSpan);
679
+ EXPECT_EQ (err, CHIP_NO_ERROR);
680
+ EXPECT_EQ (destinationIdSpan.size (), sizeof (destinationIdBuf));
681
+ EXPECT_FALSE (destinationIdSpan.data_equal (ByteSpan (kExpectedDestinationIdFromSpec )));
682
+ }
683
+
684
+
633
685
template <typename Params>
634
686
static CHIP_ERROR EncodeSigma1 (MutableByteSpan & buf)
635
687
{
@@ -867,57 +919,6 @@ struct SessionResumptionTestStorage : SessionResumptionStorage
867
919
Crypto::P256ECDHDerivedSecret * mSharedSecret = nullptr ;
868
920
};
869
921
870
- TEST_F (TestCASESession, DestinationIdTest)
871
- {
872
- // Validate example test vector from CASE section of spec
873
-
874
- const uint8_t kRootPubKeyFromSpec [Crypto::CHIP_CRYPTO_PUBLIC_KEY_SIZE_BYTES] = {
875
- 0x04 , 0x4a , 0x9f , 0x42 , 0xb1 , 0xca , 0x48 , 0x40 , 0xd3 , 0x72 , 0x92 , 0xbb , 0xc7 , 0xf6 , 0xa7 , 0xe1 , 0x1e ,
876
- 0x22 , 0x20 , 0x0c , 0x97 , 0x6f , 0xc9 , 0x00 , 0xdb , 0xc9 , 0x8a , 0x7a , 0x38 , 0x3a , 0x64 , 0x1c , 0xb8 , 0x25 ,
877
- 0x4a , 0x2e , 0x56 , 0xd4 , 0xe2 , 0x95 , 0xa8 , 0x47 , 0x94 , 0x3b , 0x4e , 0x38 , 0x97 , 0xc4 , 0xa7 , 0x73 , 0xe9 ,
878
- 0x30 , 0x27 , 0x7b , 0x4d , 0x9f , 0xbe , 0xde , 0x8a , 0x05 , 0x26 , 0x86 , 0xbf , 0xac , 0xfa
879
- };
880
-
881
- const uint8_t kIpkOperationalGroupKeyFromSpec [Crypto::CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES] = {
882
- 0x9b , 0xc6 , 0x1c , 0xd9 , 0xc6 , 0x2a , 0x2d , 0xf6 , 0xd6 , 0x4d , 0xfc , 0xaa , 0x9d , 0xc4 , 0x72 , 0xd4
883
- };
884
-
885
- const uint8_t kInitiatorRandomFromSpec [Sigma1Params::initiatorRandomLen] = { 0x7e , 0x17 , 0x12 , 0x31 , 0x56 , 0x8d , 0xfa , 0x17 ,
886
- 0x20 , 0x6b , 0x3a , 0xcc , 0xf8 , 0xfa , 0xec , 0x2f ,
887
- 0x4d , 0x21 , 0xb5 , 0x80 , 0x11 , 0x31 , 0x96 , 0xf4 ,
888
- 0x7c , 0x7c , 0x4d , 0xeb , 0x81 , 0x0a , 0x73 , 0xdc };
889
-
890
- const uint8_t kExpectedDestinationIdFromSpec [Crypto::kSHA256_Hash_Length ] = { 0xdc , 0x35 , 0xdd , 0x5f , 0xc9 , 0x13 , 0x4c , 0xc5 ,
891
- 0x54 , 0x45 , 0x38 , 0xc9 , 0xc3 , 0xfc , 0x42 , 0x97 ,
892
- 0xc1 , 0xec , 0x33 , 0x70 , 0xc8 , 0x39 , 0x13 , 0x6a ,
893
- 0x80 , 0xe1 , 0x07 , 0x96 , 0x45 , 0x1d , 0x4c , 0x53 };
894
-
895
- const FabricId kFabricIdFromSpec = 0x2906C908D115D362 ;
896
- const NodeId kNodeIdFromSpec = 0xCD5544AA7B13EF14 ;
897
-
898
- uint8_t destinationIdBuf[Crypto::kSHA256_Hash_Length ] = { 0 };
899
- MutableByteSpan destinationIdSpan (destinationIdBuf);
900
-
901
- // Test exact example
902
- CHIP_ERROR err =
903
- GenerateCaseDestinationId (ByteSpan (kIpkOperationalGroupKeyFromSpec ), ByteSpan (kInitiatorRandomFromSpec ),
904
- ByteSpan (kRootPubKeyFromSpec ), kFabricIdFromSpec , kNodeIdFromSpec , destinationIdSpan);
905
- EXPECT_EQ (err, CHIP_NO_ERROR);
906
- EXPECT_EQ (destinationIdSpan.size (), sizeof (destinationIdBuf));
907
- EXPECT_TRUE (destinationIdSpan.data_equal (ByteSpan (kExpectedDestinationIdFromSpec )));
908
-
909
- memset (destinationIdSpan.data (), 0 , destinationIdSpan.size ());
910
-
911
- // Test changing input: should yield different
912
- err = GenerateCaseDestinationId (ByteSpan (kIpkOperationalGroupKeyFromSpec ), ByteSpan (kInitiatorRandomFromSpec ),
913
- ByteSpan (kRootPubKeyFromSpec ), kFabricIdFromSpec ,
914
- kNodeIdFromSpec + 1 , // <--- Change node ID
915
- destinationIdSpan);
916
- EXPECT_EQ (err, CHIP_NO_ERROR);
917
- EXPECT_EQ (destinationIdSpan.size (), sizeof (destinationIdBuf));
918
- EXPECT_FALSE (destinationIdSpan.data_equal (ByteSpan (kExpectedDestinationIdFromSpec )));
919
- }
920
-
921
922
TEST_F (TestCASESession, SessionResumptionStorage)
922
923
{
923
924
// Test the SessionResumptionStorage external interface.
0 commit comments