@@ -101,6 +101,7 @@ bool bt_pub_key_is_valid(const uint8_t key[BT_PUB_KEY_LEN])
101101 return true;
102102 }
103103
104+ LOG_ERR ("psa_import_key() returned status %d" , ret );
104105 return false;
105106}
106107
@@ -120,18 +121,20 @@ static void generate_pub_key(struct k_work *work)
120121 uint8_t tmp_pub_key_buf [BT_PUB_KEY_LEN + 1 ];
121122 size_t tmp_len ;
122123 int err ;
124+ psa_status_t ret ;
123125
124126 set_key_attributes (& attr );
125127
126- if (psa_generate_key (& attr , & key_id ) != PSA_SUCCESS ) {
127- LOG_ERR ("Failed to generate ECC key" );
128+ ret = psa_generate_key (& attr , & key_id );
129+ if (ret != PSA_SUCCESS ) {
130+ LOG_ERR ("Failed to generate ECC key %d" , ret );
128131 err = BT_HCI_ERR_UNSPECIFIED ;
129132 goto done ;
130133 }
131134
132- if ( psa_export_public_key (key_id , tmp_pub_key_buf , sizeof (tmp_pub_key_buf ),
133- & tmp_len ) != PSA_SUCCESS ) {
134- LOG_ERR ("Failed to export ECC public key" );
135+ ret = psa_export_public_key (key_id , tmp_pub_key_buf , sizeof (tmp_pub_key_buf ), & tmp_len );
136+ if ( ret != PSA_SUCCESS ) {
137+ LOG_ERR ("Failed to export ECC public key %d" , ret );
135138 err = BT_HCI_ERR_UNSPECIFIED ;
136139 goto done ;
137140 }
@@ -141,15 +144,16 @@ static void generate_pub_key(struct k_work *work)
141144 */
142145 memcpy (ecc .public_key_be , & tmp_pub_key_buf [1 ], BT_PUB_KEY_LEN );
143146
144- if ( psa_export_key (key_id , ecc .private_key_be , BT_PRIV_KEY_LEN ,
145- & tmp_len ) != PSA_SUCCESS ) {
146- LOG_ERR ("Failed to export ECC private key" );
147+ ret = psa_export_key (key_id , ecc .private_key_be , BT_PRIV_KEY_LEN , & tmp_len );
148+ if ( ret != PSA_SUCCESS ) {
149+ LOG_ERR ("Failed to export ECC private key %d" , ret );
147150 err = BT_HCI_ERR_UNSPECIFIED ;
148151 goto done ;
149152 }
150153
151- if (psa_destroy_key (key_id ) != PSA_SUCCESS ) {
152- LOG_ERR ("Failed to destroy ECC key ID" );
154+ ret = psa_destroy_key (key_id );
155+ if (ret != PSA_SUCCESS ) {
156+ LOG_ERR ("Failed to destroy ECC key ID %d" , ret );
153157 err = BT_HCI_ERR_UNSPECIFIED ;
154158 goto done ;
155159 }
@@ -184,6 +188,7 @@ static void generate_dh_key(struct k_work *work)
184188
185189 psa_key_attributes_t attr = PSA_KEY_ATTRIBUTES_INIT ;
186190 psa_key_id_t key_id ;
191+ psa_status_t ret ;
187192 /* PSA expects secp256r1 public key to start with a predefined 0x04 byte
188193 * at the beginning the buffer.
189194 */
@@ -195,23 +200,25 @@ static void generate_dh_key(struct k_work *work)
195200 const uint8_t * priv_key = (IS_ENABLED (CONFIG_BT_USE_DEBUG_KEYS ) ?
196201 debug_private_key_be :
197202 ecc .private_key_be );
198- if (psa_import_key (& attr , priv_key , BT_PRIV_KEY_LEN , & key_id ) != PSA_SUCCESS ) {
203+ ret = psa_import_key (& attr , priv_key , BT_PRIV_KEY_LEN , & key_id );
204+ if (ret != PSA_SUCCESS ) {
199205 err = - EIO ;
200- LOG_ERR ("Failed to import the private key for key agreement" );
206+ LOG_ERR ("Failed to import the private key for key agreement %d" , ret );
201207 goto exit ;
202208 }
203209
204210 memcpy (& tmp_pub_key_buf [1 ], ecc .public_key_be , BT_PUB_KEY_LEN );
205- if ( psa_raw_key_agreement (PSA_ALG_ECDH , key_id , tmp_pub_key_buf ,
206- sizeof ( tmp_pub_key_buf ), ecc .dhkey_be , BT_DH_KEY_LEN ,
207- & tmp_len ) != PSA_SUCCESS ) {
211+ ret = psa_raw_key_agreement (PSA_ALG_ECDH , key_id , tmp_pub_key_buf , sizeof ( tmp_pub_key_buf ) ,
212+ ecc .dhkey_be , BT_DH_KEY_LEN , & tmp_len );
213+ if ( ret != PSA_SUCCESS ) {
208214 err = - EIO ;
209- LOG_ERR ("Raw key agreement failed" );
215+ LOG_ERR ("Raw key agreement failed %d" , ret );
210216 goto exit ;
211217 }
212218
213- if (psa_destroy_key (key_id ) != PSA_SUCCESS ) {
214- LOG_ERR ("Failed to destroy the key" );
219+ ret = psa_destroy_key (key_id );
220+ if (ret != PSA_SUCCESS ) {
221+ LOG_ERR ("Failed to destroy the key %d" , ret );
215222 err = - EIO ;
216223 }
217224
0 commit comments