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

libckteec: Add EDDSA attribute serialization #324

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions libckteec/include/pkcs11.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ typedef CK_KEY_TYPE *CK_KEY_TYPE_PTR;
#define CKK_SHA384_HMAC 0x02c
#define CKK_SHA512_HMAC 0x02d
#define CKK_SHA224_HMAC 0x02e
#define CKK_EC_EDWARDS 0x040 /* PKCS#11 v3.1-cs01 */

/*
* Certificates
Expand Down Expand Up @@ -351,6 +352,8 @@ typedef CK_MECHANISM_TYPE *CK_MECHANISM_TYPE_PTR;
#define CKM_ECMQV_DERIVE 0x01052
#define CKM_ECDH_AES_KEY_WRAP 0x01053
#define CKM_RSA_AES_KEY_WRAP 0x01054
#define CKM_EC_EDWARDS_KEY_PAIR_GEN 0x01055
#define CKM_EDDSA 0x01057
#define CKM_AES_KEY_GEN 0x01080
#define CKM_AES_ECB 0x01081
#define CKM_AES_CBC 0x01082
Expand Down Expand Up @@ -492,6 +495,15 @@ struct CK_GCM_PARAMS {
CK_ULONG ulTagBits;
};

/* EdDSA (RFC 8032) */
typedef struct CK_EDDSA_PARAMS {
CK_BYTE phFlag;
CK_ULONG ulContextDataLen;
CK_BYTE_PTR pContextData;
} CK_EDDSA_PARAMS;

typedef CK_EDDSA_PARAMS *CK_EDDSA_PARAMS_PTR;

/* AES CCM parameters */
typedef struct CK_CCM_PARAMS CK_CCM_PARAMS;
typedef struct CK_CCM_PARAMS *CK_CCM_PARAMS_PTR;
Expand Down
1 change: 1 addition & 0 deletions libckteec/include/pkcs11_ta.h
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,7 @@ enum pkcs11_mechanism_id {
PKCS11_CKM_ECMQV_DERIVE = 0x01052,
PKCS11_CKM_ECDH_AES_KEY_WRAP = 0x01053,
PKCS11_CKM_RSA_AES_KEY_WRAP = 0x01054,
PKCS11_CKM_EDDSA = 0x01057,
PKCS11_CKM_AES_KEY_GEN = 0x01080,
PKCS11_CKM_AES_ECB = 0x01081,
PKCS11_CKM_AES_CBC = 0x01082,
Expand Down
29 changes: 29 additions & 0 deletions libckteec/src/serialize_ck.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,31 @@ static CK_RV serialize_mecha_rsa_oaep_param(struct serializer *obj,
params->ulSourceDataLen);
}

static CK_RV serialize_mecha_eddsa(struct serializer *obj,
CK_MECHANISM_PTR mecha)
{
CK_RV rv = CKR_GENERAL_ERROR;
CK_EDDSA_PARAMS *params = mecha->pParameter;

rv = serialize_32b(obj, obj->type);
if (rv)
return rv;

rv = serialize_32b(obj, 2 * sizeof(uint32_t) + params->ulContextDataLen);
if (rv)
return rv;

rv = serialize_32b(obj, params->phFlag);
if (rv)
return rv;

rv = serialize_32b(obj, params->ulContextDataLen);
if (rv)
return rv;

return serialize_buffer(obj, params->pContextData, params->ulContextDataLen);
}

static CK_RV serialize_mecha_mac_general_param(struct serializer *obj,
CK_MECHANISM_PTR mecha)
{
Expand Down Expand Up @@ -649,6 +674,7 @@ CK_RV serialize_ck_mecha_params(struct serializer *obj,
case CKM_SHA384_HMAC:
case CKM_SHA512_HMAC:
case CKM_EC_KEY_PAIR_GEN:
case CKM_EC_EDWARDS_KEY_PAIR_GEN:
case CKM_ECDSA:
case CKM_ECDSA_SHA1:
case CKM_ECDSA_SHA224:
Expand All @@ -673,6 +699,9 @@ CK_RV serialize_ck_mecha_params(struct serializer *obj,

return serialize_32b(obj, 0);

case CKM_EDDSA:
return serialize_mecha_eddsa(obj, &mecha);

case CKM_AES_CBC:
case CKM_AES_CBC_PAD:
case CKM_AES_CTS:
Expand Down