Skip to content

Commit f59a27c

Browse files
committed
Support PKCS#11 ECDSA verify with stored key
1 parent 55946d5 commit f59a27c

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

wolfcrypt/src/wc_pkcs11.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,12 +3325,14 @@ static int Pkcs11ECDSA_Sign(Pkcs11Session* session, wc_CryptoInfo* info)
33253325
static int Pkcs11ECDSA_Verify(Pkcs11Session* session, wc_CryptoInfo* info)
33263326
{
33273327
int ret = 0;
3328+
int sessionKey = 0;
33283329
CK_RV rv;
33293330
CK_MECHANISM mech;
33303331
CK_MECHANISM_INFO mechInfo;
33313332
CK_OBJECT_HANDLE publicKey = NULL_PTR;
33323333
unsigned char* sig = NULL;
3333-
word32 sz = info->pk.eccverify.key->dp->size;
3334+
ecc_key* key = info->pk.eccverify.key;
3335+
word32 sz = key->dp->size;
33343336

33353337
/* Check operation is supported. */
33363338
rv = session->func->C_GetMechanismInfo(session->slotId, CKM_ECDSA,
@@ -3346,12 +3348,32 @@ static int Pkcs11ECDSA_Verify(Pkcs11Session* session, wc_CryptoInfo* info)
33463348
if (ret == 0) {
33473349
WOLFSSL_MSG("PKCS#11: EC Verification Operation");
33483350

3349-
ret = Pkcs11CreateEccPublicKey(&publicKey, session,
3350-
info->pk.eccverify.key, CKA_VERIFY);
3351+
if (key->labelLen > 0) {
3352+
ret = Pkcs11FindKeyByLabel(&publicKey, CKO_PUBLIC_KEY, CKK_EC,
3353+
session, key->label, key->labelLen);
3354+
if (ret == 0 && key->dp == NULL) {
3355+
ret = Pkcs11GetEccParams(session, publicKey, key);
3356+
}
3357+
}
3358+
else if (key->idLen > 0) {
3359+
ret = Pkcs11FindKeyById(&publicKey, CKO_PUBLIC_KEY, CKK_EC,
3360+
session, key->id, key->idLen);
3361+
if (ret == 0 && key->dp == NULL) {
3362+
ret = Pkcs11GetEccParams(session, publicKey, key);
3363+
}
3364+
}
3365+
else if (!mp_iszero(key->pubkey.x)) {
3366+
ret = Pkcs11CreateEccPublicKey(&publicKey, session, key,
3367+
CKA_VERIFY);
3368+
sessionKey = 1;
3369+
}
3370+
else
3371+
ret = Pkcs11FindEccKey(&publicKey, CKO_PUBLIC_KEY, session,
3372+
info->pk.eccsign.key, CKA_VERIFY);
33513373
}
33523374

33533375
if (ret == 0) {
3354-
sig = (unsigned char *)XMALLOC(sz * 2, info->pk.eccverify.key->heap,
3376+
sig = (unsigned char *)XMALLOC(sz * 2, key->heap,
33553377
DYNAMIC_TYPE_TMP_BUFFER);
33563378
if (sig == NULL)
33573379
ret = MEMORY_E;
@@ -3388,7 +3410,7 @@ static int Pkcs11ECDSA_Verify(Pkcs11Session* session, wc_CryptoInfo* info)
33883410
*info->pk.eccverify.res = 1;
33893411
}
33903412

3391-
if (publicKey != NULL_PTR)
3413+
if (sessionKey && publicKey != NULL_PTR)
33923414
session->func->C_DestroyObject(session->handle, publicKey);
33933415

33943416
if (sig != NULL)

0 commit comments

Comments
 (0)