Skip to content

[refactor][api] simplify stse_get_ecc_key_type_from_curve_id() signature#101

Open
parmi93 wants to merge 2 commits into
STMicroelectronics:dev/1.2.0from
parmi93:key_type_from_curve_id
Open

[refactor][api] simplify stse_get_ecc_key_type_from_curve_id() signature#101
parmi93 wants to merge 2 commits into
STMicroelectronics:dev/1.2.0from
parmi93:key_type_from_curve_id

Conversation

@parmi93

@parmi93 parmi93 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Reworks stse_get_ecc_key_type_from_curve_id():

  • New signature: returns the resolved stse_ecc_key_type_t directly (or STSE_ECC_KT_INVALID if the curve is unknown) and takes a single packed stsafea_ecc_curve_id_t pointer, instead of the previous three parameters (PLAT_UI8 curve_id_length, const PLAT_UI8 *pCurve_id_value, stse_ecc_key_type_t *pKey_type output).
  • Guards removed: the #if defined(STSE_CONF_ECC_*) conditional-compilation blocks around the declaration and definition are dropped; the function is now always available.

Why this change

  1. Direct interoperability with the slot-info API.
    The curve identifier returned by stse_get_ecc_key_slot_info(), the curve_id field of stsafea_private_key_slot_information_t, is already a stsafea_ecc_curve_id_t. With the old signature the caller had to manually unpack it into a scalar length (length is a 2-byte array) and a value pointer before resolving the key type. The new signature lets that output be passed straight through:
  • Before:
    stsafea_private_key_slot_information_t slot_info;
    stse_ecc_key_type_t key_type;
    PLAT_UI16 global_usage_limit;
    
    stse_get_ecc_key_slot_info(pSTSE, slot_number, &global_usage_limit, &slot_info);
    
    /* length is a 2-byte (big-endian) field, had to be reduced to a scalar
     * and split from the value before resolving the key type */
    PLAT_UI8 curve_id_length = slot_info.curve_id.length[1];
    stse_ReturnCode_t ret = stse_get_ecc_key_type_from_curve_id(
        curve_id_length,
        slot_info.curve_id.value,
        &key_type);
    
    if (ret == STSE_OK) {
        /* No point performing this check, because stse_get_ecc_key_type_from_curve_id() 
         * always return STSE_OK */
    }
    
    if (key_type == STSE_ECC_KT_INVALID) {
        /* unrecognized curve */
    }
  • After
    stsafea_private_key_slot_information_t slot_info;
    PLAT_UI16 global_usage_limit;
    
    stse_get_ecc_key_slot_info(pSTSE, slot_number, &global_usage_limit, &slot_info);
    
    /* the slot's curve_id can be passed directly */
    stse_ecc_key_type_t key_type = stse_get_ecc_key_type_from_curve_id(&slot_info.curve_id);
    
    if (key_type == STSE_ECC_KT_INVALID) {
        /* unrecognized curve */
    }
  1. A clearer, less error-prone contract.
    The function never had a real failure path, it always returned STSE_OK and signalled "not found" through *pKey_type == STSE_ECC_KT_INVALID. Returning the key type directly makes that the single, obvious result value and removes the redundant output pointer and return-code plumbing. The [static 1] array parameter also documents (and, on supporting compilers, enforces) that a non-null pointer is required.

  2. Removing the config guards.
    Guarding the symbol behind STSE_CONF_ECC_* made its availability depend on which curves happen to be enabled, so any generic caller had to replicate the same long #if defined(...) condition to avoid link errors. Since the function only reads stse_ecc_info_table and safely returns STSE_ECC_KT_INVALID when no curve matches, there is no reason to compile it out. Exposing it unconditionally gives callers a stable API surface.

Notes

  • The byte-for-byte memcmp over the packed struct is safe because stsafea_ecc_curve_id_t is a PLAT_PACKED_STRUCT (no padding between length and value); this is now documented with an inline comment.
  • Doxygen documentation and CHANGELOG.md updated to match the new signature.

⚠️ Breaking change: existing callers must be updated to the new signature.

@parmi93 parmi93 changed the base branch from main to dev/1.2.0 July 3, 2026 13:22
@parmi93 parmi93 changed the title [refactor][api] simplify stse_get_ecc_key_type_from_curve_id signature [refactor][api] simplify stse_get_ecc_key_type_from_curve_id signature Jul 3, 2026
@parmi93 parmi93 changed the title [refactor][api] simplify stse_get_ecc_key_type_from_curve_id signature [refactor][api] simplify stse_get_ecc_key_type_from_curve_id() signature Jul 3, 2026
@parmi93 parmi93 force-pushed the key_type_from_curve_id branch from 7deaab7 to 533f561 Compare July 3, 2026 14:34
parmi93 added 2 commits July 3, 2026 15:41
Return the key type directly and accept a single packed
stsafea_ecc_curve_id_t argument instead of separate length/value pointers
and an output parameter.
Remove the STSE_CONF_ECC_* conditional-compilation guards around the
stse_get_ecc_key_type_from_curve_id declaration and definition. The
function is now always compiled and exposed regardless of which ECC
curves are enabled in the configuration.
@parmi93 parmi93 force-pushed the key_type_from_curve_id branch from e94bdf8 to f481a1f Compare July 3, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant