Skip to content

Commit

Permalink
fixup! build.info, cmp_{kem.c, local.h}: add functions for kemBasedMac
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeev-0 committed Aug 17, 2023
1 parent b2253d5 commit ae0c8b4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
51 changes: 35 additions & 16 deletions crypto/cmp/cmp_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,36 +377,55 @@ int ossl_cmp_kem_derivessk(OSSL_CMP_CTX *ctx,
return 1;
}

int OSSL_CMP_get_ssk(OSSL_CMP_CTX *ctx, unsigned char **out, int *len)
int ossl_cmp_kem_derivessk_using_kemctinfo(OSSL_CMP_CTX *ctx,
OSSL_CMP_ITAV *KemCiphertextInfo,
EVP_PKEY *pkey)
{
OSSL_CMP_ITAV *req, *itav;
ASN1_OCTET_STRING *ct;
size_t secret_len = 0;
unsigned char *secret = NULL;
unsigned char *secret = NULL, *ssk = NULL;
int ssk_len;

if (ctx == NULL || KemCiphertextInfo == NULL || pkey == NULL)
return 0;

if (NID_id_it_KemCiphertextInfo !=
OBJ_obj2nid(OSSL_CMP_ITAV_get0_type(KemCiphertextInfo)))
return 0;

ct = KemCiphertextInfo->infoValue.KemCiphertextInfoValue->ct;
if (!ossl_cmp_ctx_set1_ct(ctx, ct))
return 0;

if (!performKemDecapsulation(ctx, pkey,
ASN1_STRING_get0_data(ct),
ASN1_STRING_length(ct),
&secret, &secret_len))
return 0;

if (!ossl_cmp_kem_derivessk(ctx, secret, secret_len, &ssk, &ssk_len))
return 0;

if (out == NULL || len == NULL) {
OSSL_CMP_CTX_set1_ssk(ctx, ssk, ssk_len);
return 1;
}

int OSSL_CMP_get_ssk(OSSL_CMP_CTX *ctx)
{
OSSL_CMP_ITAV *req, *itav;

if (ctx == NULL) {
ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
return 0;
}
*out = NULL;
if ((req = OSSL_CMP_ITAV_create(OBJ_nid2obj(NID_id_it_KemCiphertextInfo),
NULL)) == NULL)
return 0;
if ((itav = ossl_cmp_genm_get_itav(ctx, req, NID_id_it_KemCiphertextInfo,
"KemCiphertextInfo")) == NULL)
return 0;

ct = itav->infoValue.KemCiphertextInfoValue->ct;
if (!ossl_cmp_ctx_set1_ct(ctx, ct))
return 0;

if (!performKemDecapsulation(ctx, ctx->pkey,
ASN1_STRING_get0_data(ctx->ct),
ASN1_STRING_length(ctx->ct),
&secret, &secret_len))
return 0;

if (!ossl_cmp_kem_derivessk(ctx, secret, secret_len, out, len))
if (!ossl_cmp_kem_derivessk_using_kemctinfo(ctx, itav, ctx->pkey))
return 0;

OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_KEM_STATUS,
Expand Down
3 changes: 3 additions & 0 deletions crypto/cmp/cmp_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,9 @@ int ossl_cmp_kem_BasedMac_required(OSSL_CMP_CTX *ctx);
int ossl_cmp_kem_derivessk(OSSL_CMP_CTX *ctx,
unsigned char *secret, int secret_len,
unsigned char **out, int *len);
int ossl_cmp_kem_derivessk_using_kemctinfo(OSSL_CMP_CTX *ctx,
OSSL_CMP_ITAV *KemCiphertextInfo,
EVP_PKEY *pkey);
int ossl_cmp_kem_get_ss_using_srvcert(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg);
int ossl_cmp_kem_derive_ssk_using_srvcert(OSSL_CMP_CTX *ctx,
const OSSL_CMP_MSG *msg);
Expand Down

0 comments on commit ae0c8b4

Please sign in to comment.