@@ -197,67 +197,5 @@ CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::GetKeys(SessionKeystore & keystore,
197
197
return CHIP_NO_ERROR;
198
198
}
199
199
200
- CHIP_ERROR Spake2pVerifier::Generate (uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t setupPin)
201
- {
202
- psa_status_t status = PSA_SUCCESS;
203
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
204
- psa_key_id_t passwordKey = PSA_KEY_ID_NULL;
205
- psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
206
- psa_key_id_t spakeKey = PSA_KEY_ID_NULL;
207
- uint8_t verifier[kP256_FE_Length + kP256_Point_Length ];
208
- size_t verifierLen;
209
-
210
- // Prepare password key
211
- uint8_t password[sizeof (uint32_t )];
212
- Encoding::LittleEndian::Put32 (password, setupPin);
213
-
214
- psa_set_key_usage_flags (&attributes, PSA_KEY_USAGE_DERIVE);
215
- psa_set_key_algorithm (&attributes, PSA_ALG_PBKDF2_HMAC (PSA_ALG_SHA_256));
216
- psa_set_key_type (&attributes, PSA_KEY_TYPE_PASSWORD);
217
-
218
- status = psa_import_key (&attributes, password, sizeof (password), &passwordKey);
219
- psa_reset_key_attributes (&attributes);
220
- VerifyOrExit (status == PSA_SUCCESS, );
221
-
222
- // Run PBKDF
223
- status = psa_key_derivation_setup (&operation, PSA_ALG_PBKDF2_HMAC (PSA_ALG_SHA_256));
224
- VerifyOrExit (status == PSA_SUCCESS, );
225
-
226
- status = psa_key_derivation_input_integer (&operation, PSA_KEY_DERIVATION_INPUT_COST, pbkdf2IterCount);
227
- VerifyOrExit (status == PSA_SUCCESS, );
228
-
229
- status = psa_key_derivation_input_bytes (&operation, PSA_KEY_DERIVATION_INPUT_SALT, salt.data (), salt.size ());
230
- VerifyOrExit (status == PSA_SUCCESS, );
231
-
232
- status = psa_key_derivation_input_key (&operation, PSA_KEY_DERIVATION_INPUT_PASSWORD, passwordKey);
233
- VerifyOrExit (status == PSA_SUCCESS, );
234
-
235
- attributes = psa_key_attributes_init ();
236
- psa_set_key_usage_flags (&attributes, PSA_KEY_USAGE_DERIVE | PSA_KEY_USAGE_EXPORT);
237
- psa_set_key_algorithm (&attributes, PSA_ALG_SPAKE2P_MATTER);
238
- psa_set_key_type (&attributes, PSA_KEY_TYPE_SPAKE2P_KEY_PAIR (PSA_ECC_FAMILY_SECP_R1));
239
- psa_set_key_bits (&attributes, kP256_FE_Length * 8 );
240
-
241
- status = psa_key_derivation_output_key (&attributes, &operation, &spakeKey);
242
- psa_reset_key_attributes (&attributes);
243
- VerifyOrExit (status == PSA_SUCCESS, );
244
-
245
- // Export verifier as raw bytes
246
- status = psa_export_public_key (spakeKey, verifier, sizeof (verifier), &verifierLen);
247
-
248
- exit :
249
- psa_key_derivation_abort (&operation);
250
- psa_destroy_key (passwordKey);
251
- psa_destroy_key (spakeKey);
252
-
253
- if (status != PSA_SUCCESS)
254
- {
255
- ChipLogError (Crypto, " PSA error: %d" , static_cast <int >(status));
256
- return CHIP_ERROR_INTERNAL;
257
- }
258
-
259
- return Deserialize (ByteSpan (verifier, verifierLen));
260
- }
261
-
262
200
} // namespace Crypto
263
201
} // namespace chip
0 commit comments