@@ -33,14 +33,6 @@ CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::Init(const uint8_t * context, size_
33
33
34
34
VerifyOrReturnError (context_len <= sizeof (mContext ), CHIP_ERROR_BUFFER_TOO_SMALL);
35
35
36
- psa_pake_cipher_suite_t cs = PSA_PAKE_CIPHER_SUITE_INIT;
37
- psa_pake_cs_set_algorithm (&cs, PSA_ALG_SPAKE2P);
38
- psa_pake_cs_set_primitive (&cs, PSA_PAKE_PRIMITIVE (PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256 ));
39
- psa_pake_cs_set_hash (&cs, PSA_ALG_SHA_256);
40
-
41
- psa_status_t status = psa_pake_setup (&mOperation , &cs);
42
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
43
-
44
36
memcpy (mContext , context, context_len);
45
37
mContextLen = context_len;
46
38
@@ -64,33 +56,38 @@ CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::BeginVerifier(const uint8_t * my_id
64
56
VerifyOrReturnError (w0in_len <= kSpake2p_WS_Length , CHIP_ERROR_INVALID_ARGUMENT);
65
57
VerifyOrReturnError (Lin_len == kP256_Point_Length , CHIP_ERROR_INVALID_ARGUMENT);
66
58
67
- mRole = PSA_PAKE_ROLE_SERVER;
68
- psa_status_t status = psa_pake_set_role (&mOperation , PSA_PAKE_ROLE_SERVER);
69
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
70
-
71
- status = psa_pake_set_peer (&mOperation , peer_identity, peer_identity_len);
72
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
73
-
74
- status = psa_pake_set_user (&mOperation , my_identity, my_identity_len);
75
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
76
-
77
59
uint8_t password[kSpake2p_WS_Length + kP256_Point_Length ];
78
60
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
61
+ psa_pake_cipher_suite_t cp = PSA_PAKE_CIPHER_SUITE_INIT;
62
+
63
+ psa_pake_cs_set_algorithm (&cp, PSA_ALG_SPAKE2P_MATTER);
64
+ psa_pake_cs_set_primitive (&cp, PSA_PAKE_PRIMITIVE (PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256 ));
79
65
80
66
memcpy (password + 0 , w0in, w0in_len);
81
67
memcpy (password + w0in_len, Lin, Lin_len);
82
68
psa_set_key_usage_flags (&attributes, PSA_KEY_USAGE_DERIVE);
83
- psa_set_key_algorithm (&attributes, PSA_ALG_SPAKE2P);
84
- psa_set_key_type (&attributes, PSA_KEY_TYPE_PASSWORD);
69
+ psa_set_key_algorithm (&attributes, PSA_ALG_SPAKE2P_MATTER);
70
+ psa_set_key_type (&attributes, PSA_KEY_TYPE_SPAKE2P_PUBLIC_KEY (PSA_ECC_FAMILY_SECP_R1));
71
+
72
+ psa_status_t status = psa_import_key (&attributes, password, w0in_len + Lin_len, &mKey );
85
73
86
- status = psa_import_key (&attributes, password, w0in_len + Lin_len, &mKey );
87
74
psa_reset_key_attributes (&attributes);
88
75
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
89
76
90
- status = psa_pake_set_password_key (&mOperation , mKey );
77
+ status = psa_pake_setup (&mOperation , mKey , &cp);
78
+ VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
79
+
80
+ mRole = PSA_PAKE_ROLE_SERVER;
81
+ status = psa_pake_set_role (&mOperation , PSA_PAKE_ROLE_SERVER);
91
82
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
92
83
93
- status = psa_pake_input (&mOperation , PSA_PAKE_STEP_CONTEXT, mContext , mContextLen );
84
+ status = psa_pake_set_peer (&mOperation , peer_identity, peer_identity_len);
85
+ VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
86
+
87
+ status = psa_pake_set_user (&mOperation , my_identity, my_identity_len);
88
+ VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
89
+
90
+ status = psa_pake_set_context (&mOperation , mContext , mContextLen );
94
91
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
95
92
96
93
return CHIP_NO_ERROR;
@@ -104,33 +101,38 @@ CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::BeginProver(const uint8_t * my_iden
104
101
VerifyOrReturnError (w0in_len <= kSpake2p_WS_Length , CHIP_ERROR_INVALID_ARGUMENT);
105
102
VerifyOrReturnError (w1in_len <= kSpake2p_WS_Length , CHIP_ERROR_INVALID_ARGUMENT);
106
103
107
- mRole = PSA_PAKE_ROLE_CLIENT;
108
- psa_status_t status = psa_pake_set_role (&mOperation , PSA_PAKE_ROLE_CLIENT);
109
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
110
-
111
- status = psa_pake_set_user (&mOperation , my_identity, my_identity_len);
112
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
113
-
114
- status = psa_pake_set_peer (&mOperation , peer_identity, peer_identity_len);
115
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
116
-
117
104
uint8_t password[kSpake2p_WS_Length * 2 ];
118
105
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
106
+ psa_pake_cipher_suite_t cp = PSA_PAKE_CIPHER_SUITE_INIT;
107
+
108
+ psa_pake_cs_set_algorithm (&cp, PSA_ALG_SPAKE2P_MATTER);
109
+ psa_pake_cs_set_primitive (&cp, PSA_PAKE_PRIMITIVE (PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256 ));
119
110
120
111
memcpy (password + 0 , w0in, w0in_len);
121
112
memcpy (password + w0in_len, w1in, w1in_len);
122
113
psa_set_key_usage_flags (&attributes, PSA_KEY_USAGE_DERIVE);
123
- psa_set_key_algorithm (&attributes, PSA_ALG_SPAKE2P);
124
- psa_set_key_type (&attributes, PSA_KEY_TYPE_PASSWORD);
114
+ psa_set_key_algorithm (&attributes, PSA_ALG_SPAKE2P_MATTER);
115
+ psa_set_key_type (&attributes, PSA_KEY_TYPE_SPAKE2P_KEY_PAIR (PSA_ECC_FAMILY_SECP_R1));
116
+
117
+ psa_status_t status = psa_import_key (&attributes, password, w0in_len + w1in_len, &mKey );
125
118
126
- status = psa_import_key (&attributes, password, w0in_len + w1in_len, &mKey );
127
119
psa_reset_key_attributes (&attributes);
128
120
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
129
121
130
- status = psa_pake_set_password_key (&mOperation , mKey );
122
+ status = psa_pake_setup (&mOperation , mKey , &cp);
123
+ VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
124
+
125
+ mRole = PSA_PAKE_ROLE_CLIENT;
126
+ status = psa_pake_set_role (&mOperation , PSA_PAKE_ROLE_CLIENT);
131
127
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
132
128
133
- status = psa_pake_input (&mOperation , PSA_PAKE_STEP_CONTEXT, mContext , mContextLen );
129
+ status = psa_pake_set_user (&mOperation , my_identity, my_identity_len);
130
+ VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
131
+
132
+ status = psa_pake_set_peer (&mOperation , peer_identity, peer_identity_len);
133
+ VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
134
+
135
+ status = psa_pake_set_context (&mOperation , mContext , mContextLen );
134
136
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
135
137
136
138
return CHIP_NO_ERROR;
@@ -182,29 +184,17 @@ CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::KeyConfirm(const uint8_t * in, size
182
184
183
185
CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::GetKeys (SessionKeystore & keystore, HkdfKeyHandle & key)
184
186
{
185
- /*
186
- * TODO: use psa_pake_shared_secret() proposed in https://github.com/ARM-software/psa-api/issues/86
187
- */
188
-
189
- psa_key_derivation_operation_t * kdf = Platform::New<psa_key_derivation_operation_t >();
190
- Platform::UniquePtr<psa_key_derivation_operation_t > kdfPtr (kdf);
191
-
192
- VerifyOrReturnError (kdfPtr, CHIP_ERROR_NO_MEMORY);
187
+ auto & keyId = key.AsMutable <psa_key_id_t >();
193
188
194
- *kdfPtr = PSA_KEY_DERIVATION_OPERATION_INIT ;
189
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT ;
195
190
196
- psa_status_t status = psa_key_derivation_setup (kdfPtr.get (), PSA_ALG_HKDF (PSA_ALG_SHA_256));
197
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
191
+ psa_set_key_type (&attributes, PSA_KEY_TYPE_DERIVE);
192
+ psa_set_key_usage_flags (&attributes, PSA_KEY_USAGE_DERIVE);
193
+ psa_set_key_algorithm (&attributes, PSA_ALG_HKDF (PSA_ALG_SHA_256));
198
194
199
- status = psa_pake_get_implicit_key (&mOperation , kdfPtr. get () );
195
+ psa_status_t status = psa_pake_get_shared_key (&mOperation , &attributes, &keyId );
200
196
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
201
197
202
- auto & hkdfKeyHandle = key.AsMutable <PsaHkdfKeyHandle>();
203
- hkdfKeyHandle.mKeyDerivationOp = kdfPtr.get ();
204
- hkdfKeyHandle.mIsKeyId = false ;
205
-
206
- kdfPtr.release ();
207
-
208
198
return CHIP_NO_ERROR;
209
199
}
210
200
0 commit comments