Skip to content

Commit

Permalink
change internal callback function names
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel40791765 committed Nov 29, 2023
1 parent a8f1c87 commit 3ad353c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions crypto/dilithium/p_dilithium3.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ const EVP_PKEY_METHOD dilithium3_pkey_meth = {
NULL /* ctrl */,
NULL /* encapsulate */,
NULL /* decapsulate */,
NULL /* hmac_sign_init */,
NULL /* hmac_sign */
NULL /* hmac_init_set_up */,
NULL /* hmac_final */
};
4 changes: 2 additions & 2 deletions crypto/evp_extra/p_ed25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ const EVP_PKEY_METHOD ed25519_pkey_meth = {
NULL /* ctrl */,
NULL /* encapsulate */,
NULL /* decapsulate */,
NULL /* hmac_sign_init */,
NULL /* hmac_sign */
NULL /* hmac_init_set_up */,
NULL /* hmac_final */
};
4 changes: 2 additions & 2 deletions crypto/evp_extra/p_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ const EVP_PKEY_METHOD kem_pkey_meth = {
NULL,
pkey_kem_encapsulate,
pkey_kem_decapsulate,
NULL /* hmac_sign_init */,
NULL /* hmac_sign */
NULL /* hmac_init_set_up */,
NULL /* hmac_final */
};

// Additional KEM specific EVP functions.
Expand Down
4 changes: 2 additions & 2 deletions crypto/evp_extra/p_x25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ const EVP_PKEY_METHOD x25519_pkey_meth = {
pkey_x25519_ctrl,
NULL /* encapsulate */,
NULL /* decapsulate */,
NULL /* hmac_sign_init */,
NULL /* hmac_sign */
NULL /* hmac_init_set_up */,
NULL /* hmac_final */
};
10 changes: 5 additions & 5 deletions crypto/fipsmodule/evp/digestsign.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ static int uses_prehash(EVP_MD_CTX *ctx, enum evp_sign_verify_t op) {

int used_for_hmac(EVP_MD_CTX *ctx) {
return ctx->pctx != NULL &&
ctx->pctx->pmeth->hmac_sign_init != NULL &&
ctx->pctx->pmeth->hmac_sign != NULL;
ctx->pctx->pmeth->hmac_init_set_up != NULL &&
ctx->pctx->pmeth->hmac_final != NULL;
}

static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
Expand All @@ -101,7 +101,7 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
} else {
if (used_for_hmac(ctx)) {
// This is only defined in |EVP_PKEY_HMAC|.
if (!ctx->pctx->pmeth->hmac_sign_init(ctx->pctx, ctx)) {
if (!ctx->pctx->pmeth->hmac_init_set_up(ctx->pctx, ctx)) {
return 0;
}
ctx->pctx->operation = EVP_PKEY_OP_HMACSIGN;
Expand Down Expand Up @@ -180,7 +180,7 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig,
if (used_for_hmac(ctx)) {
// This is only defined in |EVP_PKEY_HMAC|.
ret = EVP_MD_CTX_copy_ex(&tmp_ctx, ctx) &&
tmp_ctx.pctx->pmeth->hmac_sign(tmp_ctx.pctx, out_sig, out_sig_len,
tmp_ctx.pctx->pmeth->hmac_final(tmp_ctx.pctx, out_sig, out_sig_len,
&tmp_ctx);
} else {
ret = EVP_MD_CTX_copy_ex(&tmp_ctx, ctx) &&
Expand All @@ -200,7 +200,7 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig,
// crypto is being done.
if (used_for_hmac(ctx)) {
// This is only defined in |EVP_PKEY_HMAC|.
return ctx->pctx->pmeth->hmac_sign(ctx->pctx, out_sig, out_sig_len, ctx);
return ctx->pctx->pmeth->hmac_final(ctx->pctx, out_sig, out_sig_len, ctx);
} else {
size_t s = EVP_MD_size(ctx->digest);
return EVP_PKEY_sign(ctx->pctx, out_sig, out_sig_len, NULL, s);
Expand Down
4 changes: 2 additions & 2 deletions crypto/fipsmodule/evp/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ struct evp_pkey_method_st {
const uint8_t *ciphertext, size_t ciphertext_len);

// The following are operations defined specifically for HMAC.
int (*hmac_sign_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
int (*hmac_sign)(EVP_PKEY_CTX *ctx, uint8_t *sig, size_t *siglen,
int (*hmac_init_set_up)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
int (*hmac_final)(EVP_PKEY_CTX *ctx, uint8_t *sig, size_t *siglen,
EVP_MD_CTX *mctx);
}; // EVP_PKEY_METHOD

Expand Down
58 changes: 29 additions & 29 deletions crypto/fipsmodule/evp/p_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef struct {
HMAC_CTX ctx;
} HMAC_PKEY_CTX;

static int pkey_hmac_init(EVP_PKEY_CTX *ctx) {
static int hmac_init(EVP_PKEY_CTX *ctx) {
HMAC_PKEY_CTX *hctx;
hctx = OPENSSL_malloc(sizeof(HMAC_PKEY_CTX));
if (hctx == NULL) {
Expand All @@ -85,9 +85,9 @@ static int pkey_hmac_init(EVP_PKEY_CTX *ctx) {
return 1;
}

static int pkey_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) {
static int hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) {
HMAC_PKEY_CTX *sctx, *dctx;
if (!pkey_hmac_init(dst)) {
if (!hmac_init(dst)) {
return 0;
}
sctx = src->data;
Expand All @@ -106,7 +106,7 @@ static int pkey_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) {
return 1;
}

static void pkey_hmac_cleanup(EVP_PKEY_CTX *ctx) {
static void hmac_cleanup(EVP_PKEY_CTX *ctx) {
HMAC_PKEY_CTX *hctx = ctx->data;

if (hctx == NULL) {
Expand All @@ -124,7 +124,7 @@ static void pkey_hmac_cleanup(EVP_PKEY_CTX *ctx) {
OPENSSL_free(hctx);
}

static int pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
static int hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
ASN1_OCTET_STRING *hkey = NULL;
HMAC_PKEY_CTX *hctx = ctx->data;

Expand All @@ -139,23 +139,23 @@ static int pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
return EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey);
}

static void pkey_hmac_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
static void hmac_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
HMAC_PKEY_CTX *hctx = ctx->pctx->data;
HMAC_Update(&hctx->ctx, data, count);
}

static int pkey_hmac_sign_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) {
static int hmac_init_set_up(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) {
// |mctx| gets repurposed as a hook to call |HMAC_Update|. |mctx->update| is
// normally copied from |mctx->digest->update|, but |EVP_PKEY_HMAC| has its
// own definition. We suppress the automatic setting of |mctx->update| and the
// rest of its initialization here.
mctx->flags |= EVP_MD_CTX_FLAG_NO_INIT_FOR_HMAC;
mctx->update = pkey_hmac_update;
mctx->update = hmac_update;
return 1;
}

static int pkey_hmac_sign(EVP_PKEY_CTX *ctx, uint8_t *sig, size_t *siglen,
EVP_MD_CTX *mctx) {
static int hmac_final(EVP_PKEY_CTX *ctx, uint8_t *sig, size_t *siglen,
EVP_MD_CTX *mctx) {
unsigned int hlen;
HMAC_PKEY_CTX *hctx = ctx->data;
size_t md_size = EVP_MD_CTX_size(mctx);
Expand All @@ -175,7 +175,7 @@ static int pkey_hmac_sign(EVP_PKEY_CTX *ctx, uint8_t *sig, size_t *siglen,
return 1;
}

static int pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
static int hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
HMAC_PKEY_CTX *hctx = ctx->data;
ASN1_OCTET_STRING *key;

Expand Down Expand Up @@ -210,22 +210,22 @@ static int pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {

DEFINE_METHOD_FUNCTION(EVP_PKEY_METHOD, EVP_PKEY_hmac_pkey_meth) {
out->pkey_id = EVP_PKEY_HMAC;
out->init = pkey_hmac_init;
out->copy = pkey_hmac_copy;
out->cleanup = pkey_hmac_cleanup;
out->keygen = pkey_hmac_keygen; /* keygen */
out->sign_init = NULL; /* sign_init */
out->sign = NULL; /* sign */
out->sign_message = NULL; /* sign_message */
out->verify_init = NULL; /* verify_init */
out->verify = NULL; /* verify */
out->verify_message = NULL; /* verify_message */
out->verify_recover = NULL; /* verify_recover */
out->encrypt = NULL; /* encrypt */
out->decrypt = NULL; /* decrypt */
out->derive = NULL; /* derive */
out->paramgen = NULL; /* paramgen */
out->ctrl = pkey_hmac_ctrl;
out->hmac_sign_init = pkey_hmac_sign_init;
out->hmac_sign = pkey_hmac_sign;
out->init = hmac_init;
out->copy = hmac_copy;
out->cleanup = hmac_cleanup;
out->keygen = hmac_keygen; /* keygen */
out->sign_init = NULL; /* sign_init */
out->sign = NULL; /* sign */
out->sign_message = NULL; /* sign_message */
out->verify_init = NULL; /* verify_init */
out->verify = NULL; /* verify */
out->verify_message = NULL; /* verify_message */
out->verify_recover = NULL; /* verify_recover */
out->encrypt = NULL; /* encrypt */
out->decrypt = NULL; /* decrypt */
out->derive = NULL; /* derive */
out->paramgen = NULL; /* paramgen */
out->ctrl = hmac_ctrl;
out->hmac_init_set_up = hmac_init_set_up;
out->hmac_final = hmac_final;
}

0 comments on commit 3ad353c

Please sign in to comment.