Skip to content

Commit 65e3e18

Browse files
committed
1)Tidy Up the code
1 parent 86f57cd commit 65e3e18

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/platform/Infineon/crypto/trustm/CHIPCryptoPALHsm_P256_trustm.cpp

+6-11
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
238238
return ECDH_derive_secret_H(&mKeypair, remote_public_key, out_secret);
239239
}
240240

241-
ChipLogDetail(Crypto, "ECDH_derive_secret: TrustM");
241+
ChipLogDetail(Crypto, "TrustM: ECDH_derive_secret");
242242
trustm_Open();
243243

244244
const uint8_t * const rem_pubKey = Uint8::to_const_uchar(remote_public_key);
@@ -281,7 +281,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_hash_signature(const uint8_t * hash, si
281281

282282
VerifyOrReturnError(hash != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
283283
VerifyOrReturnError(hash_length > 0, CHIP_ERROR_INVALID_ARGUMENT);
284-
ChipLogDetail(Crypto, "ECDSA_validate_hash_signature");
284+
ChipLogDetail(Crypto, "TrustM: ECDSA_validate_hash_signature");
285285

286286
// Trust M init
287287
trustm_Open();
@@ -338,20 +338,19 @@ CHIP_ERROR P256Keypair::Deserialize(P256SerializedKeypair & input)
338338

339339
VerifyOrReturnError(input.Length() == public_key.Length() + kP256_PrivateKey_Length, CHIP_ERROR_INVALID_ARGUMENT);
340340

341-
privkey = input.ConstBytes() /*Uint8::to_const_uchar(input) */ + public_key.Length();
341+
privkey = input.ConstBytes() + public_key.Length();
342342

343343
if (0 == memcmp(privkey, trustm_magic_no, sizeof(trustm_magic_no)))
344344
{
345345
/* trustm_magic_no + KeyID is passed */
346-
ChipLogDetail(Crypto, "Deserialize: ref key found");
346+
ChipLogDetail(Crypto, "Deserialize: key found");
347347
bbuf.Put(input.Bytes(), public_key.Length());
348348
VerifyOrReturnError(bbuf.Fit(), CHIP_ERROR_NO_MEMORY);
349349

350350
memcpy(&mKeypair.mBytes[0], trustm_magic_no, sizeof(trustm_magic_no));
351351

352352
mKeypair.mBytes[4] = *(privkey + 4);
353353
mKeypair.mBytes[5] = *(privkey + 5);
354-
// ChipLogDetail(Crypto, "Parsed keyId = 0x%02X%02X", mKeypair.mBytes[4], mKeypair.mBytes[5]);
355354

356355
mInitialized = true;
357356

@@ -390,7 +389,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_msg_signature(const uint8_t * msg, size
390389
VerifyOrReturnError(msg != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
391390
VerifyOrReturnError(msg_length > 0, CHIP_ERROR_INVALID_ARGUMENT);
392391

393-
ChipLogDetail(Crypto, "ECDSA_validate_msg_signature");
392+
ChipLogDetail(Crypto, "TrustM: ECDSA_validate_msg_signature");
394393

395394
// Trust M init
396395
trustm_Open();
@@ -399,8 +398,6 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_msg_signature(const uint8_t * msg, size
399398
out_der_sig_span);
400399
SuccessOrExit(error);
401400

402-
/* Set the public key */
403-
// P256PublicKeyHSM & public_key = const_cast<P256PublicKeyHSM &>(Pubkey());
404401
signature_trustm_len = out_der_sig_span.size();
405402
// Hash to get the digest
406403
memset(&digest[0], 0, sizeof(digest));
@@ -422,7 +419,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_msg_signature(const uint8_t * msg, size
422419

423420
static void add_tlv(uint8_t * buf, size_t buf_index, uint8_t tag, size_t len, uint8_t * val)
424421
{
425-
buf[buf_index++] = (uint8_t) tag;
422+
buf[buf_index++] = tag;
426423
buf[buf_index++] = (uint8_t) len;
427424
if (len > 0 && val != NULL)
428425
{
@@ -501,8 +498,6 @@ CHIP_ERROR P256Keypair::NewCertificateSigningRequest(uint8_t * csr, size_t & csr
501498

502499
// Add length
503500
buffer_index -= kTlvHeader;
504-
// Subject TLV ==> 1 + 1 + len(subject)
505-
// Org OID TLV ==> 1 + 1 + len(organisation_oid)
506501
VerifyOrExit(buffer_index > 0, error = CHIP_ERROR_INTERNAL);
507502
add_tlv(data_to_hash, buffer_index, (ASN1_CONSTRUCTED | ASN1_SEQUENCE),
508503
((2 * kTlvHeader) + (sizeof(SUBJECT_STR) - 1) + sizeof(organisation_oid)), NULL);

0 commit comments

Comments
 (0)