pkcs11: Rewrite ec params to use sc_asn1_put_tag()
This commit is contained in:
parent
ae771a135f
commit
c39e31b274
|
@ -5542,7 +5542,8 @@ get_ec_pubkey_params(struct sc_pkcs15_pubkey *key, CK_ATTRIBUTE_PTR attr)
|
||||||
{
|
{
|
||||||
struct sc_ec_parameters *ecp;
|
struct sc_ec_parameters *ecp;
|
||||||
unsigned long expected_size = 0;
|
unsigned long expected_size = 0;
|
||||||
unsigned char *out = NULL;
|
char *curve_name = NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
return CKR_ATTRIBUTE_TYPE_INVALID;
|
return CKR_ATTRIBUTE_TYPE_INVALID;
|
||||||
|
@ -5551,30 +5552,28 @@ get_ec_pubkey_params(struct sc_pkcs15_pubkey *key, CK_ATTRIBUTE_PTR attr)
|
||||||
|
|
||||||
switch (key->algorithm) {
|
switch (key->algorithm) {
|
||||||
case SC_ALGORITHM_EDDSA:
|
case SC_ALGORITHM_EDDSA:
|
||||||
#define CURVE "edwards25519"
|
|
||||||
/* TODO key->alg_id->oid contains OID which we need to convert to curve name */
|
|
||||||
/* For now, using hardcoded curve names */
|
|
||||||
expected_size = strlen(CURVE) + 2;
|
|
||||||
check_attribute_buffer(attr, expected_size);
|
|
||||||
out = attr->pValue;
|
|
||||||
out[0] = 0x13; /* Tag PrintableString */
|
|
||||||
out[1] = strlen(CURVE);
|
|
||||||
memcpy(&out[2], CURVE, strlen(CURVE));
|
|
||||||
return CKR_OK;
|
|
||||||
#undef CURVE
|
|
||||||
|
|
||||||
case SC_ALGORITHM_XEDDSA:
|
case SC_ALGORITHM_XEDDSA:
|
||||||
#define CURVE "curve25519"
|
|
||||||
/* TODO key->alg_id->oid contains OID which we need to convert to curve name */
|
/* TODO key->alg_id->oid contains OID which we need to convert to curve name */
|
||||||
/* For now, using hardcoded curve names */
|
/* For now, using hardcoded curve names */
|
||||||
expected_size = strlen(CURVE) + 2;
|
if (key->algorithm == SC_ALGORITHM_EDDSA) {
|
||||||
|
curve_name = "edwards25519";
|
||||||
|
} else if (key->algorithm == SC_ALGORITHM_XEDDSA) {
|
||||||
|
curve_name = "curve25519";
|
||||||
|
} else {
|
||||||
|
return CKR_GENERAL_ERROR;
|
||||||
|
}
|
||||||
|
r = sc_asn1_put_tag(0x13, (u8 *)curve_name, strlen(curve_name), NULL, 0, NULL);
|
||||||
|
if (r <= 0) {
|
||||||
|
return CKR_GENERAL_ERROR;
|
||||||
|
}
|
||||||
|
expected_size = r;
|
||||||
check_attribute_buffer(attr, expected_size);
|
check_attribute_buffer(attr, expected_size);
|
||||||
out = attr->pValue;
|
/* Tag PrintableString */
|
||||||
out[0] = 0x13; /* Tag PrintableString */
|
r = sc_asn1_put_tag(0x13, (u8 *)curve_name, strlen(curve_name), attr->pValue, expected_size, NULL);
|
||||||
out[1] = strlen(CURVE);
|
if (r != SC_SUCCESS) {
|
||||||
memcpy(&out[2], CURVE, strlen(CURVE));
|
return sc_to_cryptoki_error(r, NULL);
|
||||||
|
}
|
||||||
return CKR_OK;
|
return CKR_OK;
|
||||||
#undef CURVE
|
|
||||||
|
|
||||||
case SC_ALGORITHM_EC:
|
case SC_ALGORITHM_EC:
|
||||||
/* TODO parms should not be in two places */
|
/* TODO parms should not be in two places */
|
||||||
|
|
Loading…
Reference in New Issue