Skip to content

Commit 48b91ae

Browse files
committed
Support for FW based NOC key-pair generation.
1 parent 739f7d4 commit 48b91ae

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,12 @@ static CHIP_ERROR get_trustm_keyid_from_keypair(const P256KeypairContext mKeypai
9393

9494
P256Keypair::~P256Keypair()
9595
{
96-
// Add method to get the keyid
9796
if (CHIP_NO_ERROR != get_trustm_keyid_from_keypair(mKeypair, &keyid))
9897
{
9998
Clear();
10099
}
101100
else
102101
{
103-
// Delete the key in SE
104102
}
105103
}
106104

@@ -110,6 +108,7 @@ CHIP_ERROR P256Keypair::Initialize(ECPKeyTarget key_target)
110108

111109
if (key_target == ECPKeyTarget::ECDSA)
112110
{
111+
printf("Generating ECDSA key");
113112
// Use the mbedtls based method
114113
if (CHIP_NO_ERROR == Initialize_H(this, &mPublicKey, &mKeypair))
115114
{
@@ -166,7 +165,9 @@ CHIP_ERROR P256Keypair::Initialize(ECPKeyTarget key_target)
166165

167166
CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, size_t msg_length, P256ECDSASignature & out_signature) const
168167
{
168+
VerifyOrReturnError(mInitialized, CHIP_ERROR_UNINITIALIZED);
169169
uint16_t keyid = (mKeypair.mBytes[CRYPTO_KEYPAIR_KEYID_OFFSET+1]) | (mKeypair.mBytes[CRYPTO_KEYPAIR_KEYID_OFFSET] << 8);
170+
170171
// Check if there is any matching key_id to Optiga OID
171172
if (keyid == OPTIGA_KEY_ID_E0F0)
172173
{
@@ -211,9 +212,8 @@ CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, size_t msg_length, P
211212
// Use the mbedtls based method
212213
else
213214
{
214-
printf("ECDSA sing msg sw\n");
215+
printf("ECDSA sing msg mbedtls\n");
215216
return ECDSA_sign_msg_H(&mKeypair, msg, msg_length, out_signature);
216-
217217
}
218218
}
219219

@@ -306,6 +306,13 @@ CHIP_ERROR P256Keypair::Serialize(P256SerializedKeypair & output) const
306306
uint8_t privkey[kP256_PrivateKey_Length] = {
307307
0,
308308
};
309+
310+
if (0 != memcmp(&mKeypair.mBytes[0], trustm_magic_no, sizeof(trustm_magic_no)))
311+
{
312+
VerifyOrReturnError(mInitialized, CHIP_ERROR_UNINITIALIZED);
313+
return Serialize_H(mKeypair, mPublicKey, output);
314+
315+
}
309316

310317
/* Set the public key */
311318
P256PublicKey & public_key = const_cast<P256PublicKey &>(Pubkey());

0 commit comments

Comments
 (0)