@@ -1170,9 +1170,10 @@ int wc_ed25519_import_public_ex(const byte* in, word32 inLen, ed25519_key* key,
11701170 return BAD_FUNC_ARG ;
11711171
11721172#ifdef WOLFSSL_SE050
1173- /* Importing new key material invalidates any prior SE050 object binding. */
1174- key -> keyIdSet = 0 ;
1175- key -> keyId = 0 ;
1173+ /* Importing new key material invalidates any prior SE050 object binding;
1174+ * erase the old object (no-op when keyIdSet == 0) so the host and the
1175+ * secure element agree on what's bound. */
1176+ se050_ed25519_free_key (key );
11761177#endif
11771178
11781179 /* compressed prefix according to draft
@@ -1262,9 +1263,10 @@ int wc_ed25519_import_private_only(const byte* priv, word32 privSz,
12621263 return BAD_FUNC_ARG ;
12631264
12641265#ifdef WOLFSSL_SE050
1265- /* Importing new key material invalidates any prior SE050 object binding. */
1266- key -> keyIdSet = 0 ;
1267- key -> keyId = 0 ;
1266+ /* Importing new key material invalidates any prior SE050 object binding;
1267+ * erase the old object (no-op when keyIdSet == 0) so the host and the
1268+ * secure element agree on what's bound. */
1269+ se050_ed25519_free_key (key );
12681270#endif
12691271
12701272 XMEMCPY (key -> k , priv , ED25519_KEY_SIZE );
@@ -1324,9 +1326,14 @@ int wc_ed25519_import_private_key_ex(const byte* priv, word32 privSz,
13241326 }
13251327
13261328#ifdef WOLFSSL_SE050
1327- /* Importing new key material invalidates any prior SE050 object binding. */
1328- key -> keyIdSet = 0 ;
1329- key -> keyId = 0 ;
1329+ /* Importing new key material invalidates any prior SE050 object binding;
1330+ * erase the old object (no-op when keyIdSet == 0) so the host and the
1331+ * secure element agree on what's bound. wc_ed25519_import_public_ex below
1332+ * does the same reset, but we also do it here explicitly: key->k is
1333+ * overwritten before that call, so the binding must be dropped first in
1334+ * case wc_ed25519_import_public_ex fails its own early-return argument
1335+ * checks before reaching its reset. */
1336+ se050_ed25519_free_key (key );
13301337#endif
13311338
13321339 XMEMCPY (key -> k , priv , ED25519_KEY_SIZE );
0 commit comments