Skip to content

Commit

Permalink
objects: Cache curve name to avoid repetitive conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Jelen <[email protected]>
  • Loading branch information
Jakuje authored and simo5 committed Jan 5, 2023
1 parent abfe60c commit 7f0b9ab
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct p11prov_key {
CK_BBOOL always_auth;
CK_ULONG bit_size;
CK_ULONG size;
const char *curve_name;
};

struct p11prov_crt {
Expand Down Expand Up @@ -1202,6 +1203,11 @@ const char *p11prov_obj_get_ec_group_name(P11PROV_OBJ *obj)
int curve_nid;
CK_RV rv;

if (obj->data.key.curve_name != NULL) {
P11PROV_debug("Using cached curve name %s", obj->data.key.curve_name);
return obj->data.key.curve_name;
}

attrs[0].type = CKA_EC_PARAMS;

rv = get_public_attrs(obj, attrs, 1);
Expand All @@ -1228,6 +1234,9 @@ const char *p11prov_obj_get_ec_group_name(P11PROV_OBJ *obj)
if (curve_name == NULL) {
goto done;
}

obj->data.key.curve_name = curve_name;
P11PROV_debug("Caching curve name %s", curve_name);
return curve_name;

done:
Expand Down

0 comments on commit 7f0b9ab

Please sign in to comment.