Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X25519 improvements 2 in PKCS11-tool, PKCS15 routines and tools and openpgp #3090

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
dcc7346
pkcs11-tool.c - fix tag len in OID
dengert Dec 8, 2023
c060f7d
pkcs11-tool.c - Incorrect OID for edwards25519
dengert Dec 9, 2023
d85b52c
pkcs11-tool.c - CKK_GENERIC_SECRET do not have CKA_ENCRYPT or CKA_DEC…
dengert Dec 8, 2023
43d58d4
pkcs11-tool.c Add derive key support for CKK_MONTGOMERY
dengert Dec 9, 2023
a633845
pkcs11-tool.c - Update EC type curves
dengert Dec 10, 2023
584e7cc
pkcs11-tool.c - EVP_KEY_X448 not defined in LibreSSL
dengert Jan 21, 2024
2a63099
pkcs11-tool.c calculate size in bits for eddsa and xeddsa CKA_EC_POINT
dengert Jan 21, 2024
f8ce754
pkcs11-tool.c - EC_POINT DER in BIT STRING or OCTET STRING
dengert Jan 29, 2024
f83208b
pkcs11-tool.c - remore wrap/unwrap from template
dengert Apr 17, 2024
556c0cc
pkcs15.h - PKCS11 ecparams are used by CKK_EC, CKK_EDWARDS and CKK_MO…
dengert Dec 9, 2023
e8bbf37
pkcs15-prkey.c pkcs15-pubkey.c - Use common EC params
dengert Dec 9, 2023
732eda2
card-openpgp.c - Use common "ec_pointQ" for EC, EDDSA and XEDDSA
dengert Dec 9, 2023
c9e1de3
pkcs15init/pkcs15-lib.c pkcs15init/pkcs15-openpgp.c - EDDSA and XEDDSA
dengert Dec 10, 2023
a1c1fb6
card-openpgp.c - add SC_ALGORITHM_ONBOARD_KEY_GEN
dengert Dec 10, 2023
ad86f56
pkcs15-pubkey.c update ec curves and map printable strings
dengert Dec 10, 2023
61df246
pkcs15-init.c squash adding additional if statement
dengert Jan 21, 2024
b428eb0
pkcs15-algo.c - add Ed448, X448 and openpgp oids
dengert Jan 15, 2024
5fe507f
OpenPGP - Move mapping of OpenPGP specifix OIDs
dengert Jan 15, 2024
1c8bff8
pkcs15init/pkcs15-opensc.c unused variable
dengert Jan 15, 2024
82b7213
tools/pkcs15-init.c accept and case and convert to correct case
dengert Jan 20, 2024
80effc1
card-openpgp.c card-openpgp.h
dengert Jan 20, 2024
fba9f26
doc/tools/pkcs15-init.1.xml document Curve names for eddsa and xeddsa
dengert Jan 21, 2024
3042e6b
framework-pkcs15.c - Support CKA_PUBKEY_KEY_INFO
dengert Jan 28, 2024
491977c
WIP to accept pkcs11 ec_point encoded in bit string or byte string
dengert Feb 9, 2024
70d2496
pkcs15-pubkey.c make default for CKA_EC_POINT to return old OCTET S…
dengert Feb 16, 2024
1493774
test-oseid.sh use restart-pcscd.sh
dengert Feb 16, 2024
7e84589
Revert "test-oseid.sh use restart-pcscd.sh"
dengert Mar 28, 2024
a4543d4
pkcs15-pubkey.c fix bug found by fuzzer
dengert Mar 28, 2024
58ccef4
pkcs15-pubkey.c - no need to test if key is null before free
dengert Mar 28, 2024
a4265fd
pkcs15-pubkey.c - comments, whitespace and code style
dengert Mar 30, 2024
e0800ed
card-openpgp.c - whitespace and code style
dengert Mar 30, 2024
4d454fc
framework-pkcs15,c - whitespace and code style
dengert Mar 30, 2024
19b56b3
pkcs15-alg.c whitespace and code style
dengert Mar 30, 2024
7f5931e
pkcs15-init.c whitespace and code style
dengert Mar 30, 2024
2dfbe4d
files.html, tools.html - rebuild
dengert Mar 30, 2024
95696f0
pkcs15-pubkey.c - readability of mapped_string
dengert Apr 17, 2024
57c1f6f
card-openpgp.c - renove TODO comments as code was added
dengert Apr 18, 2024
a45ab3e
pkcs15-algo.c - removed comments and added asn1 calls
dengert Apr 18, 2024
064b805
pkcs15-prkey.c - moved comment
dengert Apr 18, 2024
30ec795
pkcs11-tool.c - formating
dengert Apr 19, 2024
8ef8507
pkcs15-pubkey.c - Use sc_asn1_read_tag for printable string
dengert Apr 21, 2024
64a7100
pkcs15-pubkey.c opensc.h - Add SC_ALGORITHM_* to ec_curve_info
dengert Apr 22, 2024
2009bfc
card-openpgp.c card-openpgp.h - Add SC_ALGORITHM_* to ec_curves_open…
dengert Apr 22, 2024
fc7c6d2
card.c - when adding an EC type alg call sc_pkcs15_fix_ec_parameters
dengert Apr 23, 2024
818d26a
pkcs15-pubkey.c - FIXUP order of key_type in sc_curve_info
dengert Apr 23, 2024
be1e3d9
card.c - fix bug in sc_copy_ec_params
dengert Apr 23, 2024
17834c5
pkcs15init/pkcs15-openpgp.c - test id and ec type keys
dengert Apr 24, 2024
97a8d3a
card.c when copying sc_ec_parameters get new key_type too
dengert Apr 24, 2024
9c7c398
pkcs15init/pkcs15-openpgp.c - set key_info.algorithm so EDDSA and XE…
dengert Apr 24, 2024
9b1d102
card-openpgp.c - fix invalid read found by valgrind
dengert Apr 26, 2024
951567b
pkcs15init/pkcs15-lib.c - fix double free
dengert Apr 27, 2024
8f55e45
cardctl.h - add key_type as SC_ALGORITHM_* to sc_cardctl_openpgp_keyg…
dengert Apr 28, 2024
d8546f2
opensc.h - add
dengert May 16, 2024
8550203
opensc.h - add sc_clear_ec_params
dengert May 16, 2024
bb099fb
pkcs11-tool.c - CKK_EC_EDWARDS and CKK_EC_MONTGOMERY improvements
dengert May 16, 2024
5df6fc8
card.c - add sc_clear_ec_params expand sc_card_find_alg
dengert May 16, 2024
3215bcf
pkcs15init/pkcs15-lib.c - Changes for sc_clear_ec_params
dengert May 16, 2024
4856c56
card-openpgp.c pkcs15init/pkcs15-openpgp.c - fixes
dengert May 16, 2024
42b82bf
libopensc.exports - export sc_clear_ec_params
dengert May 16, 2024
d0da85d
framework-pkcs15.c - added support for more 448 size keys
dengert May 16, 2024
1f2ada9
pkcs15-isoApplet.c - use sc_clear_ec_params
dengert May 16, 2024
3fa1d48
pkcs15-algo.c, pkcs15-prkey.c and pkcs15-pubkey.c
dengert May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
pkcs15-prkey.c pkcs15-pubkey.c - Use common EC params
 On branch X25519-improvements-2
 Changes to be committed:
	modified:   libopensc/pkcs15-prkey.c
	modified:   libopensc/pkcs15-pubkey.c
  • Loading branch information
dengert committed May 17, 2024
commit e8bbf37cf2d834092e2b8c4f72498385dc3b4123
10 changes: 1 addition & 9 deletions src/libopensc/pkcs15-prkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,20 +569,12 @@ sc_pkcs15_erase_prkey(struct sc_pkcs15_prkey *key)
case SC_ALGORITHM_GOSTR3410:
free(key->u.gostr3410.d.data);
break;
case SC_ALGORITHM_EC:
case SC_ALGORITHM_EC: /* EC, Edwards and Montgomery use common ec params */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this comment into a new line

free(key->u.ec.params.der.value);
free(key->u.ec.params.named_curve);
free(key->u.ec.privateD.data);
free(key->u.ec.ecpointQ.value);
Jakuje marked this conversation as resolved.
Show resolved Hide resolved
break;
case SC_ALGORITHM_EDDSA:
free(key->u.eddsa.pubkey.value);
key->u.eddsa.pubkey.value = NULL;
key->u.eddsa.pubkey.len = 0;
free(key->u.eddsa.value.value);
key->u.eddsa.value.value = NULL;
key->u.eddsa.value.len = 0;
break;
}
sc_mem_clear(key, sizeof(*key));
}
Expand Down
115 changes: 28 additions & 87 deletions src/libopensc/pkcs15-pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,6 @@ static struct sc_asn1_entry c_asn1_ec_pointQ[C_ASN1_EC_POINTQ_SIZE] = {
{ NULL, 0, 0, 0, NULL, NULL }
};

#define C_ASN1_EDDSA_PUBKEY_SIZE 2
static struct sc_asn1_entry c_asn1_eddsa_pubkey[C_ASN1_EDDSA_PUBKEY_SIZE] = {
{ "pubkey", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, NULL, NULL },
{ NULL, 0, 0, 0, NULL, NULL }
};


int
sc_pkcs15_decode_pubkey_rsa(sc_context_t *ctx, struct sc_pkcs15_pubkey_rsa *key,
const u8 *buf, size_t buflen)
Expand Down Expand Up @@ -690,47 +683,27 @@ sc_pkcs15_encode_pubkey_ec(sc_context_t *ctx, struct sc_pkcs15_pubkey_ec *key,
}

/*
* EdDSA keys are just byte strings. For now only
* for Ed25519 keys 32B length are supported
all "ec" keys uses same pubkey format, keep this external entrypoint
* keys are just byte strings.
*/
int
sc_pkcs15_decode_pubkey_eddsa(sc_context_t *ctx,
struct sc_pkcs15_pubkey_eddsa *key,
struct sc_pkcs15_pubkey_ec *key,
const u8 *buf, size_t buflen)
{
int r;
u8 * pubkey = NULL;
size_t pubkey_len;
struct sc_asn1_entry asn1_eddsa_pubkey[C_ASN1_EDDSA_PUBKEY_SIZE];

LOG_FUNC_CALLED(ctx);
sc_copy_asn1_entry(c_asn1_eddsa_pubkey, asn1_eddsa_pubkey);
sc_format_asn1_entry(asn1_eddsa_pubkey + 0, &pubkey, &pubkey_len, 1);
r = sc_asn1_decode(ctx, asn1_eddsa_pubkey, buf, buflen, NULL, NULL);
if (r < 0)
LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");

key->pubkey.len = pubkey_len;
key->pubkey.value = pubkey;

LOG_FUNC_RETURN(ctx, SC_SUCCESS);
return sc_pkcs15_decode_pubkey_ec(ctx, key, buf, buflen);
}

/*
* all "ec" keys uses same pubkey format, keep this external entrypoint
*/
int
sc_pkcs15_encode_pubkey_eddsa(sc_context_t *ctx, struct sc_pkcs15_pubkey_eddsa *key,
sc_pkcs15_encode_pubkey_eddsa(sc_context_t *ctx, struct sc_pkcs15_pubkey_ec *key,
u8 **buf, size_t *buflen)
{
struct sc_asn1_entry asn1_eddsa_pubkey[C_ASN1_EDDSA_PUBKEY_SIZE];

LOG_FUNC_CALLED(ctx);
sc_copy_asn1_entry(c_asn1_eddsa_pubkey, asn1_eddsa_pubkey);
sc_format_asn1_entry(asn1_eddsa_pubkey + 0, key->pubkey.value, &key->pubkey.len, 1);

LOG_FUNC_RETURN(ctx,
sc_asn1_encode(ctx, asn1_eddsa_pubkey, buf, buflen));
return sc_pkcs15_encode_pubkey_ec(ctx, key, buf, buflen);
}


int
sc_pkcs15_encode_pubkey(sc_context_t *ctx, struct sc_pkcs15_pubkey *key,
u8 **buf, size_t *len)
Expand All @@ -739,11 +712,8 @@ sc_pkcs15_encode_pubkey(sc_context_t *ctx, struct sc_pkcs15_pubkey *key,
return sc_pkcs15_encode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
if (key->algorithm == SC_ALGORITHM_GOSTR3410)
return sc_pkcs15_encode_pubkey_gostr3410(ctx, &key->u.gostr3410, buf, len);
if (key->algorithm == SC_ALGORITHM_EC)
if (key->algorithm == SC_ALGORITHM_EC || key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
return sc_pkcs15_encode_pubkey_ec(ctx, &key->u.ec, buf, len);
if (key->algorithm == SC_ALGORITHM_EDDSA ||
key->algorithm == SC_ALGORITHM_XEDDSA) /* XXX encoding is the same here */
return sc_pkcs15_encode_pubkey_eddsa(ctx, &key->u.eddsa, buf, len);

sc_log(ctx, "Encoding of public key type %lu not supported", key->algorithm);
LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
Expand Down Expand Up @@ -789,6 +759,8 @@ sc_pkcs15_encode_pubkey_as_spki(sc_context_t *ctx, struct sc_pkcs15_pubkey *pubk

switch (pubkey->algorithm) {
case SC_ALGORITHM_EC:
case SC_ALGORITHM_EDDSA:
case SC_ALGORITHM_XEDDSA:
/*
* most keys, but not EC have only one encoding.
* For a SPKI, the ecpoint is placed directly in the
Expand Down Expand Up @@ -826,14 +798,6 @@ sc_pkcs15_encode_pubkey_as_spki(sc_context_t *ctx, struct sc_pkcs15_pubkey *pubk
r = sc_pkcs15_encode_pubkey(ctx, pubkey, &pkey.value, &pkey.len);
key_len = pkey.len * 8;
break;
case SC_ALGORITHM_EDDSA:
case SC_ALGORITHM_XEDDSA:
/* For a SPKI, the pubkey is placed directly in the BIT STRING */
pkey.value = malloc(pubkey->u.eddsa.pubkey.len);
memcpy(pkey.value, pubkey->u.eddsa.pubkey.value, pubkey->u.eddsa.pubkey.len);
// Should be pkey.len = 0 there?
key_len = pubkey->u.eddsa.pubkey.len * 8;
break;
default:
r = sc_pkcs15_encode_pubkey(ctx, pubkey, &pkey.value, &pkey.len);
key_len = pkey.len * 8;
Expand Down Expand Up @@ -865,11 +829,8 @@ sc_pkcs15_decode_pubkey(sc_context_t *ctx, struct sc_pkcs15_pubkey *key,
return sc_pkcs15_decode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
if (key->algorithm == SC_ALGORITHM_GOSTR3410)
return sc_pkcs15_decode_pubkey_gostr3410(ctx, &key->u.gostr3410, buf, len);
if (key->algorithm == SC_ALGORITHM_EC)
if (key->algorithm == SC_ALGORITHM_EC || key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
return sc_pkcs15_decode_pubkey_ec(ctx, &key->u.ec, buf, len);
if (key->algorithm == SC_ALGORITHM_EDDSA ||
key->algorithm == SC_ALGORITHM_XEDDSA)
return sc_pkcs15_decode_pubkey_eddsa(ctx, &key->u.eddsa, buf, len);

sc_log(ctx, "Decoding of public key type %lu not supported", key->algorithm);
return SC_ERROR_NOT_SUPPORTED;
Expand Down Expand Up @@ -1030,29 +991,20 @@ sc_pkcs15_pubkey_from_prvkey(struct sc_context *ctx, struct sc_pkcs15_prkey *prv
case SC_ALGORITHM_GOSTR3410:
break;
case SC_ALGORITHM_EC:
pubkey->u.ec.ecpointQ.value = malloc(prvkey->u.ec.ecpointQ.len);
if (!pubkey->u.ec.ecpointQ.value) {
sc_pkcs15_free_pubkey(pubkey);
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
}
memcpy(pubkey->u.ec.ecpointQ.value, prvkey->u.ec.ecpointQ.value, prvkey->u.ec.ecpointQ.len);
pubkey->u.ec.ecpointQ.len = prvkey->u.ec.ecpointQ.len;
break;
case SC_ALGORITHM_EDDSA:
case SC_ALGORITHM_XEDDSA:
/* Copy pubkey */
if (prvkey->u.eddsa.pubkey.value == NULL || prvkey->u.eddsa.pubkey.len <= 0) {
if (prvkey->u.ec.ecpointQ.value == NULL || prvkey->u.ec.ecpointQ.len <= 0) {
sc_pkcs15_free_pubkey(pubkey);
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
}
pubkey->u.eddsa.pubkey.value = malloc(prvkey->u.eddsa.pubkey.len);
if (!pubkey->u.eddsa.pubkey.value) {
pubkey->u.ec.ecpointQ.value = malloc(prvkey->u.ec.ecpointQ.len);
if (!pubkey->u.ec.ecpointQ.value) {
sc_pkcs15_free_pubkey(pubkey);
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
}
memcpy(pubkey->u.eddsa.pubkey.value, prvkey->u.eddsa.pubkey.value, prvkey->u.eddsa.pubkey.len);
pubkey->u.eddsa.pubkey.len = prvkey->u.eddsa.pubkey.len;

memcpy(pubkey->u.ec.ecpointQ.value, prvkey->u.ec.ecpointQ.value, prvkey->u.ec.ecpointQ.len);
pubkey->u.ec.ecpointQ.len = prvkey->u.ec.ecpointQ.len;
break;
default:
sc_log(ctx, "Unsupported private key algorithm");
Expand Down Expand Up @@ -1111,6 +1063,8 @@ sc_pkcs15_dup_pubkey(struct sc_context *ctx, struct sc_pkcs15_pubkey *key, struc
case SC_ALGORITHM_GOSTR3410:
break;
case SC_ALGORITHM_EC:
case SC_ALGORITHM_EDDSA:
case SC_ALGORITHM_XEDDSA:
pubkey->u.ec.ecpointQ.value = malloc(key->u.ec.ecpointQ.len);
if (!pubkey->u.ec.ecpointQ.value) {
rv = SC_ERROR_OUT_OF_MEMORY;
Expand All @@ -1137,18 +1091,6 @@ sc_pkcs15_dup_pubkey(struct sc_context *ctx, struct sc_pkcs15_pubkey *key, struc
rv = SC_ERROR_NOT_SUPPORTED;
}

break;
case SC_ALGORITHM_EDDSA:
case SC_ALGORITHM_XEDDSA:
/* Copy pubkey */
pubkey->u.eddsa.pubkey.value = malloc(key->u.eddsa.pubkey.len);
if (!pubkey->u.eddsa.pubkey.value) {
rv = SC_ERROR_OUT_OF_MEMORY;
break;
}
memcpy(pubkey->u.eddsa.pubkey.value, key->u.eddsa.pubkey.value, key->u.eddsa.pubkey.len);
pubkey->u.eddsa.pubkey.len = key->u.eddsa.pubkey.len;

break;
default:
sc_log(ctx, "Unsupported private key algorithm");
Expand Down Expand Up @@ -1187,19 +1129,15 @@ sc_pkcs15_erase_pubkey(struct sc_pkcs15_pubkey *key)
free(key->u.gostr3410.xy.data);
break;
case SC_ALGORITHM_EC:
case SC_ALGORITHM_EDDSA:
case SC_ALGORITHM_XEDDSA:
if (key->u.ec.params.der.value)
free(key->u.ec.params.der.value);
if (key->u.ec.params.named_curve)
free(key->u.ec.params.named_curve);
if (key->u.ec.ecpointQ.value)
free(key->u.ec.ecpointQ.value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needless if(x) free(x). Please remove the needless if here, similarly as it was done in the eddsa case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following the coding style in the routine which does the same for RSA, GOST and EC.

a7a524be1c (Doug Engert         2023-12-08 20:18:51 -0600 1169)         case SC_ALGORITHM_EDDSA:
a7a524be1c (Doug Engert         2023-12-08 20:18:51 -0600 1170)         case SC_ALGORITHM_XEDDSA:

I can remove all the needless if if you want..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. This was common antipatern in the past and in a lot of places, probably making people feel safer, but there is not a single case when this would be useful for anything

break;
case SC_ALGORITHM_EDDSA:
case SC_ALGORITHM_XEDDSA:
free(key->u.eddsa.pubkey.value);
key->u.eddsa.pubkey.value = NULL;
key->u.eddsa.pubkey.len = 0;
break;
}
sc_mem_clear(key, sizeof(*key));
}
Expand Down Expand Up @@ -1402,9 +1340,9 @@ sc_pkcs15_pubkey_from_spki_fields(struct sc_context *ctx, struct sc_pkcs15_pubke
} else if (pk_alg.algorithm == SC_ALGORITHM_EDDSA ||
pk_alg.algorithm == SC_ALGORITHM_XEDDSA) {
/* EDDSA/XEDDSA public key is not encapsulated into BIT STRING -- it's a BIT STRING */
pubkey->u.eddsa.pubkey.value = malloc(pk.len);
memcpy(pubkey->u.eddsa.pubkey.value, pk.value, pk.len);
pubkey->u.eddsa.pubkey.len = pk.len;
pubkey->u.ec.ecpointQ.value = malloc(pk.len);
memcpy(pubkey->u.ec.ecpointQ.value, pk.value, pk.len);
pubkey->u.ec.ecpointQ.len = pk.len;
} else {
/* Public key is expected to be encapsulated into BIT STRING */
r = sc_pkcs15_decode_pubkey(ctx, pubkey, pk.value, pk.len);
Expand Down Expand Up @@ -1511,11 +1449,14 @@ static struct ec_curve_info {

{"ed25519", "1.3.6.1.4.1.11591.15.1", "06092B06010401DA470F01", 255},
{"curve25519", "1.3.6.1.4.1.3029.1.5.1", "060A2B060104019755010501", 255},
{"Ed25519", "1.3.101.112", "06032b6570", 255},
{"X25519", "1.3.101.110", "06032b656e", 255},

{NULL, NULL, NULL, 0}, /* Do not touch this */
};


/* TODO DEE add changes for mapping */
int
sc_pkcs15_fix_ec_parameters(struct sc_context *ctx, struct sc_ec_parameters *ecparams)
{
Expand Down
20 changes: 8 additions & 12 deletions src/pkcs11/framework-pkcs15.c
Original file line number Diff line number Diff line change
Expand Up @@ -3357,7 +3357,7 @@ pkcs15_gen_keypair(struct sc_pkcs11_slot *slot, CK_MECHANISM_PTR pMechanism,
keybits = 1024; /* Default key size */
/* TODO: check allowed values of keybits */
}
else if (keytype == CKK_EC) {
else if (keytype == CKK_EC || keytype == CKK_EC_EDWARDS || keytype == CKK_EC_MONTGOMERY) {
struct sc_lv_data *der = &keygen_args.prkey_args.key.u.ec.params.der;
void *ptr = NULL;

Expand All @@ -3369,26 +3369,22 @@ pkcs15_gen_keypair(struct sc_pkcs11_slot *slot, CK_MECHANISM_PTR pMechanism,
return rv;
}

}

if (keytype == CKK_EC) {
keygen_args.prkey_args.key.algorithm = SC_ALGORITHM_EC;
pub_args.key.algorithm = SC_ALGORITHM_EC;
}
else if (keytype == CKK_EC_EDWARDS) {
/* TODO Validate EC_PARAMS contains curveName "edwards25519" or "edwards448" (from RFC 8032)
* or id-Ed25519 or id-Ed448 (or equivalent OIDs in oId field) (from RFC 8410)
* otherwise return CKR_CURVE_NOT_SUPPORTED
*/
keygen_args.prkey_args.key.algorithm = SC_ALGORITHM_EDDSA;
keygen_args.prkey_args.usage |= SC_PKCS15_PRKEY_USAGE_SIGN;
pub_args.key.algorithm = SC_ALGORITHM_EDDSA;
return CKR_CURVE_NOT_SUPPORTED;
}
else if (keytype == CKK_EC_MONTGOMERY) {
/* TODO Validate EC_PARAMS contains curveName "curve25519" or "curve448" (from RFC 7748)
* or id-X25519 or id-X448 (or equivalent OIDs in oId field) (from RFC 8410)
* otherwise return CKR_CURVE_NOT_SUPPORTED
*/
keygen_args.prkey_args.key.algorithm = SC_ALGORITHM_XEDDSA;
/* Can not sign. To created a cert, see: openssl x509 -force_pubkey */
keygen_args.prkey_args.usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
pub_args.key.algorithm = SC_ALGORITHM_XEDDSA;
return CKR_CURVE_NOT_SUPPORTED;
}
else {
/* CKA_KEY_TYPE is set, but keytype isn't correct */
Expand Down Expand Up @@ -5989,7 +5985,7 @@ get_ec_pubkey_point(struct sc_pkcs15_pubkey *key, CK_ATTRIBUTE_PTR attr)
switch (key->algorithm) {
case SC_ALGORITHM_EDDSA:
case SC_ALGORITHM_XEDDSA:
rc = sc_pkcs15_encode_pubkey_eddsa(context, &key->u.eddsa, &value, &value_len);
rc = sc_pkcs15_encode_pubkey_eddsa(context, &key->u.ec, &value, &value_len);
if (rc != SC_SUCCESS)
return sc_to_cryptoki_error(rc, NULL);

Expand Down
4 changes: 2 additions & 2 deletions src/tools/pkcs15-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ static int read_ssh_key(void)
unsigned char buf[64];
size_t n, len;

n = pubkey->u.eddsa.pubkey.len;
n = pubkey->u.ec.ecpointQ.len;
if (n != 32) {
fprintf(stderr, "Wrong public key length\n");
goto fail2;
Expand All @@ -1039,7 +1039,7 @@ static int read_ssh_key(void)
buf[len++] = 0;
buf[len++] = 0;
buf[len++] = n & 0xff;
memcpy(buf + len, pubkey->u.eddsa.pubkey.value, n);
memcpy(buf + len, pubkey->u.ec.ecpointQ.value, n);
len += n;

print_ssh_key(outf, alg, obj, buf, len);
Expand Down