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: serialize_ck.c: serialize AES-GCM mechanism parameters #364

Merged
merged 1 commit into from
Dec 7, 2023
Merged
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
45 changes: 45 additions & 0 deletions libckteec/src/serialize_ck.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,48 @@ static CK_RV serialize_mecha_aes_ctr(struct serializer *obj,
return rv;
}

static CK_RV serialize_mecha_aes_gcm(struct serializer *obj,
CK_MECHANISM_PTR mecha)
{
CK_GCM_PARAMS_PTR param = mecha->pParameter;
CK_RV rv = CKR_GENERAL_ERROR;
CK_ULONG aad_len = 0;

/* AAD is not manadatory */
if (param->pAAD)
aad_len = param->ulAADLen;

if (!param->pIv)
return CKR_MECHANISM_PARAM_INVALID;

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

rv = serialize_32b(obj, 3 * sizeof(uint32_t) +
param->ulIvLen + aad_len);
if (rv)
return rv;

rv = serialize_ck_ulong(obj, param->ulIvLen);
if (rv)
return rv;

rv = serialize_buffer(obj, param->pIv, param->ulIvLen);
if (rv)
return rv;

rv = serialize_ck_ulong(obj, aad_len);
if (rv)
return rv;

rv = serialize_buffer(obj, param->pAAD, aad_len);
if (rv)
return rv;

return serialize_ck_ulong(obj, param->ulTagBits);
}

static CK_RV serialize_mecha_aes_iv(struct serializer *obj,
CK_MECHANISM_PTR mecha)
{
Expand Down Expand Up @@ -753,6 +795,9 @@ CK_RV serialize_ck_mecha_params(struct serializer *obj,
case CKM_AES_CTR:
return serialize_mecha_aes_ctr(obj, &mecha);

case CKM_AES_GCM:
return serialize_mecha_aes_gcm(obj, &mecha);

case CKM_AES_ECB_ENCRYPT_DATA:
return serialize_mecha_key_deriv_str(obj, &mecha);

Expand Down