@@ -562,27 +562,24 @@ class P256Keypair : public P256KeypairBase
562
562
bool mInitialized = false ;
563
563
};
564
564
565
- using Symmetric128BitsKeyByteArray = uint8_t [CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES];
566
-
567
565
/* *
568
- * @brief Platform-specific Symmetric key handle
566
+ * @brief Platform-specific symmetric key handle
569
567
*
570
568
* The class represents a key used by the Matter stack either in the form of raw key material or key
571
569
* reference, depending on the platform. To achieve that, it contains an opaque context that can be
572
- * cast to a concrete representation used by the given platform. Note that currently Matter uses
573
- * 128-bit symmetric keys only.
570
+ * cast to a concrete representation used by the given platform.
574
571
*
575
- * @note Symmetric128BitsKeyHandle is an abstract class to force child classes for each key handle type.
576
- * Symmetric128BitsKeyHandle class implements all the necessary components for handles.
577
- * Child classes only need to implement a constructor and delete all the copy operators.
572
+ * @note SymmetricKeyHandle is an abstract class to force child classes for each key handle type.
573
+ * SymmetricKeyHandle class implements all the necessary components for handles.
578
574
*/
579
- class Symmetric128BitsKeyHandle
575
+ template <size_t ContextSize>
576
+ class SymmetricKeyHandle
580
577
{
581
578
public:
582
- Symmetric128BitsKeyHandle (const Symmetric128BitsKeyHandle &) = delete ;
583
- Symmetric128BitsKeyHandle (Symmetric128BitsKeyHandle &&) = delete ;
584
- void operator =(const Symmetric128BitsKeyHandle &) = delete ;
585
- void operator =(Symmetric128BitsKeyHandle &&) = delete ;
579
+ SymmetricKeyHandle (const SymmetricKeyHandle &) = delete ;
580
+ SymmetricKeyHandle (SymmetricKeyHandle &&) = delete ;
581
+ void operator =(const SymmetricKeyHandle &) = delete ;
582
+ void operator =(SymmetricKeyHandle &&) = delete ;
586
583
587
584
/* *
588
585
* @brief Get internal context cast to the desired key representation
@@ -603,44 +600,44 @@ class Symmetric128BitsKeyHandle
603
600
}
604
601
605
602
protected:
606
- Symmetric128BitsKeyHandle () = default ;
607
- ~Symmetric128BitsKeyHandle () { ClearSecretData (mContext .mOpaque ); }
603
+ SymmetricKeyHandle () = default ;
604
+ ~SymmetricKeyHandle () { ClearSecretData (mContext .mOpaque ); }
608
605
609
606
private:
610
- static constexpr size_t kContextSize = CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES;
611
-
612
607
struct alignas (uintptr_t ) OpaqueContext
613
608
{
614
- uint8_t mOpaque [kContextSize ] = {};
609
+ uint8_t mOpaque [ContextSize ] = {};
615
610
} mContext ;
616
611
};
617
612
613
+ using Symmetric128BitsKeyByteArray = uint8_t [CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES];
614
+
618
615
/* *
619
- * @brief Platform-specific AES key handle
616
+ * @brief Platform-specific 128-bit symmetric key handle
620
617
*/
621
- class Aes128KeyHandle final : public Symmetric128BitsKeyHandle
618
+ class Symmetric128BitsKeyHandle : public SymmetricKeyHandle <CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES>
622
619
{
623
- public:
624
- Aes128KeyHandle () = default ;
620
+ };
625
621
626
- Aes128KeyHandle (const Aes128KeyHandle &) = delete ;
627
- Aes128KeyHandle (Aes128KeyHandle &&) = delete ;
628
- void operator =(const Aes128KeyHandle &) = delete ;
629
- void operator =(Aes128KeyHandle &&) = delete ;
622
+ /* *
623
+ * @brief Platform-specific 128-bit AES key handle
624
+ */
625
+ class Aes128KeyHandle final : public Symmetric128BitsKeyHandle
626
+ {
630
627
};
631
628
632
629
/* *
633
- * @brief Platform-specific HMAC key handle
630
+ * @brief Platform-specific 128-bit HMAC key handle
634
631
*/
635
632
class Hmac128KeyHandle final : public Symmetric128BitsKeyHandle
636
633
{
637
- public:
638
- Hmac128KeyHandle () = default ;
634
+ };
639
635
640
- Hmac128KeyHandle (const Hmac128KeyHandle &) = delete ;
641
- Hmac128KeyHandle (Hmac128KeyHandle &&) = delete ;
642
- void operator =(const Hmac128KeyHandle &) = delete ;
643
- void operator =(Hmac128KeyHandle &&) = delete ;
636
+ /* *
637
+ * @brief Platform-specific HKDF key handle
638
+ */
639
+ class HkdfKeyHandle final : public SymmetricKeyHandle<CHIP_CONFIG_HKDF_KEY_HANDLE_CONTEXT_SIZE>
640
+ {
644
641
};
645
642
646
643
/* *
@@ -1059,6 +1056,9 @@ class PBKDF2_sha256
1059
1056
unsigned int iteration_count, uint32_t key_length, uint8_t * output);
1060
1057
};
1061
1058
1059
+ // TODO: Extract Spake2p to a separate header and replace the forward declaration with #include SessionKeystore.h
1060
+ class SessionKeystore ;
1061
+
1062
1062
/* *
1063
1063
* The below class implements the draft 01 version of the Spake2+ protocol as
1064
1064
* defined in https://www.ietf.org/id/draft-bar-cfrg-spake2plus-01.html.
@@ -1174,14 +1174,17 @@ class Spake2p
1174
1174
virtual CHIP_ERROR KeyConfirm (const uint8_t * in, size_t in_len);
1175
1175
1176
1176
/* *
1177
- * @brief Return the shared secret.
1177
+ * @brief Return the shared HKDF key.
1178
+ *
1179
+ * Returns the shared key established during the Spake2+ process, which can be used
1180
+ * to derive application-specific keys using HKDF.
1178
1181
*
1179
- * @param out The output secret .
1180
- * @param out_len The output secret length .
1182
+ * @param keystore The session keystore for managing the HKDF key lifetime .
1183
+ * @param key The output HKDF key .
1181
1184
*
1182
1185
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
1183
1186
**/
1184
- CHIP_ERROR GetKeys (uint8_t * out, size_t * out_len) ;
1187
+ CHIP_ERROR GetKeys (SessionKeystore & keystore, HkdfKeyHandle & key) const ;
1185
1188
1186
1189
CHIP_ERROR InternalHash (const uint8_t * in, size_t in_len);
1187
1190
CHIP_ERROR WriteMN ();
0 commit comments