From a170809d792816448cb4c95f3473531a1a917e69 Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Sun, 3 Jan 2016 23:09:13 +0300 Subject: [PATCH] openssl 1.1.0 compatibility --- gost_crypt.c | 118 +++++++++++++++++++++++++++++++------------------ gost_ec_keyx.c | 14 +++--- gost_eng.c | 61 +++++++++++++++---------- gost_lcl.h | 15 ++++--- gost_md.c | 63 +++++++++++++++----------- gost_md2012.c | 111 ++++++++++++++++++++++++++++------------------ gost_pmeth.c | 16 ++++--- 7 files changed, 245 insertions(+), 153 deletions(-) diff --git a/gost_crypt.c b/gost_crypt.c index 680406f..9351bc6 100644 --- a/gost_crypt.c +++ b/gost_crypt.c @@ -128,41 +128,70 @@ static int gost_imit_cleanup(EVP_MD_CTX *ctx); /* Control function, knows how to set MAC key.*/ static int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr); -EVP_MD imit_gost_cpa = { - NID_id_Gost28147_89_MAC, - NID_undef, - 4, - 0, - gost_imit_init_cpa, - gost_imit_update, - gost_imit_final, - gost_imit_copy, - gost_imit_cleanup, - NULL, - NULL, - {0, 0, 0, 0, 0}, - 8, - sizeof(struct ossl_gost_imit_ctx), - gost_imit_ctrl -}; +static EVP_MD *_hidden_Gost28147_89_MAC_md = NULL; +static EVP_MD *_hidden_Gost28147_89_12_MAC_md = NULL; -EVP_MD imit_gost_cp_12 = { - NID_gost_mac_12, - NID_undef, - 4, - 0, - gost_imit_init_cp_12, - gost_imit_update, - gost_imit_final, - gost_imit_copy, - gost_imit_cleanup, - NULL, - NULL, - {0, 0, 0, 0, 0}, - 8, - sizeof(struct ossl_gost_imit_ctx), - gost_imit_ctrl -}; +EVP_MD *imit_gost_cpa(void) +{ + if (_hidden_Gost28147_89_MAC_md == NULL) { + EVP_MD *md; + + if ((md = EVP_MD_meth_new(NID_id_Gost28147_89_MAC, NID_undef)) == NULL + || !EVP_MD_meth_set_result_size(md, 4) + || !EVP_MD_meth_set_input_blocksize(md, 8) + || !EVP_MD_meth_set_app_datasize(md, + sizeof(struct ossl_gost_imit_ctx)) + || !EVP_MD_meth_set_flags(md, 0) + || !EVP_MD_meth_set_init(md, gost_imit_init_cpa) + || !EVP_MD_meth_set_update(md, gost_imit_update) + || !EVP_MD_meth_set_final(md, gost_imit_final) + || !EVP_MD_meth_set_copy(md, gost_imit_copy) + || !EVP_MD_meth_set_cleanup(md, gost_imit_cleanup) + || !EVP_MD_meth_set_ctrl(md, gost_imit_ctrl)) { + EVP_MD_meth_free(md); + md = NULL; + } + _hidden_Gost28147_89_MAC_md = md; + } + return _hidden_Gost28147_89_MAC_md; +} + +void imit_gost_cpa_destroy(void) +{ + EVP_MD_meth_free(_hidden_Gost28147_89_MAC_md); + _hidden_Gost28147_89_MAC_md = NULL; +} + +EVP_MD *imit_gost_cp_12(void) +{ + if (_hidden_Gost28147_89_12_MAC_md == NULL) { + EVP_MD *md; + + if ((md = EVP_MD_meth_new(NID_gost_mac_12, NID_undef)) == NULL + || !EVP_MD_meth_set_result_size(md, 4) + || !EVP_MD_meth_set_input_blocksize(md, 8) + || !EVP_MD_meth_set_app_datasize(md, + sizeof(struct ossl_gost_imit_ctx)) + || !EVP_MD_meth_set_flags(md, 0) + || !EVP_MD_meth_set_init(md, gost_imit_init_cp_12) + || !EVP_MD_meth_set_update(md, gost_imit_update) + || !EVP_MD_meth_set_final(md, gost_imit_final) + || !EVP_MD_meth_set_copy(md, gost_imit_copy) + || !EVP_MD_meth_set_cleanup(md, gost_imit_cleanup) + || !EVP_MD_meth_set_ctrl(md, gost_imit_ctrl)) { + EVP_MD_meth_free(md); + md = NULL; + } + _hidden_Gost28147_89_12_MAC_md = md; + } + return _hidden_Gost28147_89_12_MAC_md; +} + +void imit_gost_cp_12_destroy(void) +{ + EVP_MD_meth_free(_hidden_Gost28147_89_12_MAC_md); + _hidden_Gost28147_89_12_MAC_md = NULL; +} /* * Correspondence between gost parameter OIDs and substitution blocks @@ -658,7 +687,7 @@ int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) static int gost_imit_init(EVP_MD_CTX *ctx, gost_subst_block * block) { - struct ossl_gost_imit_ctx *c = ctx->md_data; + struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx); memset(c->buffer, 0, sizeof(c->buffer)); memset(c->partial_block, 0, sizeof(c->partial_block)); c->count = 0; @@ -698,7 +727,7 @@ static void mac_block_mesh(struct ossl_gost_imit_ctx *c, int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count) { - struct ossl_gost_imit_ctx *c = ctx->md_data; + struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx); const unsigned char *p = data; size_t bytes = count, i; if (!(c->key_set)) { @@ -730,7 +759,7 @@ int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count) int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md) { - struct ossl_gost_imit_ctx *c = ctx->md_data; + struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx); if (!c->key_set) { GOSTerr(GOST_F_GOST_IMIT_FINAL, GOST_R_MAC_KEY_NOT_SET); return 0; @@ -759,13 +788,13 @@ int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) return 1; case EVP_MD_CTRL_SET_KEY: { - struct ossl_gost_imit_ctx *gost_imit_ctx = ctx->md_data; + struct ossl_gost_imit_ctx *gost_imit_ctx = EVP_MD_CTX_md_data(ctx); - if (ctx->digest->init(ctx) <= 0) { + if (EVP_DigestInit(ctx, EVP_MD_CTX_md(ctx)) <= 0) { GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_MAC_KEY_NOT_SET); return 0; } - ctx->flags |= EVP_MD_CTX_FLAG_NO_INIT; + EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NO_INIT); if (arg == 0) { struct gost_mac_key *key = (struct gost_mac_key *)ptr; @@ -794,7 +823,7 @@ int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) } case EVP_MD_CTRL_MAC_LEN: { - struct ossl_gost_imit_ctx *c = ctx->md_data; + struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx); if (arg < 1 || arg > 8) { GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_SIZE); return 0; @@ -810,13 +839,16 @@ int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) { - memcpy(to->md_data, from->md_data, sizeof(struct ossl_gost_imit_ctx)); + if (EVP_MD_CTX_md_data(to) && EVP_MD_CTX_md_data(from)) { + memcpy(EVP_MD_CTX_md_data(to), EVP_MD_CTX_md_data(from), + sizeof(struct ossl_gost_imit_ctx)); + } return 1; } /* Clean up imit ctx */ int gost_imit_cleanup(EVP_MD_CTX *ctx) { - memset(ctx->md_data, 0, sizeof(struct ossl_gost_imit_ctx)); + memset(EVP_MD_CTX_md_data(ctx), 0, sizeof(struct ossl_gost_imit_ctx)); return 1; } diff --git a/gost_ec_keyx.c b/gost_ec_keyx.c index 7043347..af773e2 100644 --- a/gost_ec_keyx.c +++ b/gost_ec_keyx.c @@ -28,8 +28,8 @@ static int VKO_compute_key(unsigned char *shared_key, size_t shared_key_size, EC_POINT *pnt = EC_POINT_new(EC_KEY_get0_group(priv_key)); int i; BN_CTX *ctx = BN_CTX_new(); - EVP_MD_CTX mdctx; - const EVP_MD *md; + EVP_MD_CTX *mdctx = NULL; + const EVP_MD *md = NULL; int effective_dgst_nid = (dgst_nid == NID_id_GostR3411_2012_512) ? NID_id_GostR3411_2012_256 : dgst_nid; int buf_len = (dgst_nid == NID_id_GostR3411_2012_512) ? 128 : 64, @@ -77,11 +77,11 @@ static int VKO_compute_key(unsigned char *shared_key, size_t shared_key_size, for (i = 0; i < buf_len; i++) { hashbuf[buf_len - 1 - i] = databuf[i]; } - EVP_MD_CTX_init(&mdctx); - EVP_DigestInit_ex(&mdctx, md, NULL); - EVP_DigestUpdate(&mdctx, hashbuf, buf_len); - EVP_DigestFinal_ex(&mdctx, shared_key, NULL); - EVP_MD_CTX_cleanup(&mdctx); + EVP_MD_CTX_init(mdctx); + EVP_DigestInit_ex(mdctx, md, NULL); + EVP_DigestUpdate(mdctx, hashbuf, buf_len); + EVP_DigestFinal_ex(mdctx, shared_key, NULL); + EVP_MD_CTX_free(mdctx); err: BN_free(UKM); BN_CTX_end(ctx); diff --git a/gost_eng.c b/gost_eng.c index 097563e..8c20827 100644 --- a/gost_eng.c +++ b/gost_eng.c @@ -41,14 +41,30 @@ static int gost_cipher_nids[] = { 0 }; -static int gost_digest_nids[] = { - NID_id_GostR3411_94, - NID_id_Gost28147_89_MAC, - NID_id_GostR3411_2012_256, - NID_id_GostR3411_2012_512, - NID_gost_mac_12, - 0 -}; +static int gost_digest_nids(const int **nids) +{ + static int digest_nids[6] = { 0, 0, 0, 0, 0, 0 }; + static int pos = 0; + static int init = 0; + + if (!init) { + const EVP_MD *md; + if ((md = digest_gost()) != NULL) + digest_nids[pos++] = EVP_MD_type(md); + if ((md = imit_gost_cpa()) != NULL) + digest_nids[pos++] = EVP_MD_type(md); + if ((md = digest_gost2012_256()) != NULL) + digest_nids[pos++] = EVP_MD_type(md); + if ((md = digest_gost2012_512()) != NULL) + digest_nids[pos++] = EVP_MD_type(md); + if ((md = imit_gost_cp_12()) != NULL) + digest_nids[pos++] = EVP_MD_type(md); + digest_nids[pos] = 0; + init = 1; + } + *nids = digest_nids; + return pos; +} static int gost_pkey_meth_nids[] = { NID_id_GostR3410_2001, @@ -81,6 +97,12 @@ static int gost_engine_finish(ENGINE *e) static int gost_engine_destroy(ENGINE *e) { + digest_gost_destroy(); + digest_gost2012_256_destroy(); + digest_gost2012_512_destroy(); + imit_gost_cpa_destroy(); + imit_gost_cp_12_destroy(); + gost_param_free(); pmeth_GostR3410_2001 = NULL; @@ -188,11 +210,11 @@ static int bind_gost(ENGINE *e, const char *id) || !EVP_add_cipher(&cipher_gost_cbc) || !EVP_add_cipher(&cipher_gost_cpacnt) || !EVP_add_cipher(&cipher_gost_cpcnt_12) - || !EVP_add_digest(&digest_gost) - || !EVP_add_digest(&digest_gost2012_512) - || !EVP_add_digest(&digest_gost2012_256) - || !EVP_add_digest(&imit_gost_cpa) - || !EVP_add_digest(&imit_gost_cp_12) + || !EVP_add_digest(digest_gost()) + || !EVP_add_digest(digest_gost2012_512()) + || !EVP_add_digest(digest_gost2012_256()) + || !EVP_add_digest(imit_gost_cpa()) + || !EVP_add_digest(imit_gost_cp_12()) ) { goto end; } @@ -212,19 +234,12 @@ static int gost_digests(ENGINE *e, const EVP_MD **digest, { int ok = 1; if (!digest) { - *nids = gost_digest_nids; - return sizeof(gost_digest_nids) / sizeof(gost_digest_nids[0]) - 1; + return gost_digest_nids(nids); } if (nid == NID_id_GostR3411_94) { - *digest = &digest_gost; - } else if (nid == NID_id_GostR3411_2012_256) { - *digest = &digest_gost2012_256; - } else if (nid == NID_id_GostR3411_2012_512) { - *digest = &digest_gost2012_512; + *digest = digest_gost(); } else if (nid == NID_id_Gost28147_89_MAC) { - *digest = &imit_gost_cpa; - } else if (nid == NID_gost_mac_12) { - *digest = &imit_gost_cp_12; + *digest = imit_gost_cpa(); } else { ok = 0; *digest = NULL; diff --git a/gost_lcl.h b/gost_lcl.h index bb18ff1..3cc15f7 100644 --- a/gost_lcl.h +++ b/gost_lcl.h @@ -164,13 +164,18 @@ struct ossl_gost_digest_ctx { gost_ctx cctx; }; /* EVP_MD structure for GOST R 34.11 */ -extern EVP_MD digest_gost; +EVP_MD *digest_gost(void); +void digest_gost_destroy(void); /* EVP MD structure for GOST R 34.11-2012 algorithms */ -extern EVP_MD digest_gost2012_256; -extern EVP_MD digest_gost2012_512; +EVP_MD *digest_gost2012_256(void); +EVP_MD *digest_gost2012_512(void); +void digest_gost2012_256_destroy(void); +void digest_gost2012_512_destroy(void); /* EVP_MD structure for GOST 28147 in MAC mode */ -extern EVP_MD imit_gost_cpa; -extern EVP_MD imit_gost_cp_12; +EVP_MD *imit_gost_cpa(void); +void imit_gost_cpa_destroy(void); +EVP_MD *imit_gost_cp_12(void); +void imit_gost_cp_12_destroy(void); /* Cipher context used for EVP_CIPHER operation */ struct ossl_gost_cipher_ctx { int paramNID; diff --git a/gost_md.c b/gost_md.c index 1ccc6be..54a2fe5 100644 --- a/gost_md.c +++ b/gost_md.c @@ -19,27 +19,40 @@ static int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md); static int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from); static int gost_digest_cleanup(EVP_MD_CTX *ctx); -EVP_MD digest_gost = { - NID_id_GostR3411_94, - NID_undef, - 32, - EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, - gost_digest_init, - gost_digest_update, - gost_digest_final, - gost_digest_copy, - gost_digest_cleanup, - NULL, - NULL, - {NID_undef, NID_undef, 0, 0, 0}, - 32, - sizeof(struct ossl_gost_digest_ctx), - NULL -}; +static EVP_MD *_hidden_GostR3411_94_md = NULL; + +EVP_MD *digest_gost(void) +{ + if (_hidden_GostR3411_94_md == NULL) { + EVP_MD *md; + + if ((md = EVP_MD_meth_new(NID_id_GostR3411_94, NID_undef)) == NULL + || !EVP_MD_meth_set_result_size(md, 32) + || !EVP_MD_meth_set_input_blocksize(md, 32) + || !EVP_MD_meth_set_app_datasize(md, + sizeof(struct ossl_gost_digest_ctx)) + || !EVP_MD_meth_set_init(md, gost_digest_init) + || !EVP_MD_meth_set_update(md, gost_digest_update) + || !EVP_MD_meth_set_final(md, gost_digest_final) + || !EVP_MD_meth_set_copy(md, gost_digest_copy) + || !EVP_MD_meth_set_cleanup(md, gost_digest_cleanup)) { + EVP_MD_meth_free(md); + md = NULL; + } + _hidden_GostR3411_94_md = md; + } + return _hidden_GostR3411_94_md; +} + +void digest_gost_destroy(void) +{ + EVP_MD_meth_free(_hidden_GostR3411_94_md); + _hidden_GostR3411_94_md = NULL; +} int gost_digest_init(EVP_MD_CTX *ctx) { - struct ossl_gost_digest_ctx *c = ctx->md_data; + struct ossl_gost_digest_ctx *c = EVP_MD_CTX_md_data(ctx); memset(&(c->dctx), 0, sizeof(gost_hash_ctx)); gost_init(&(c->cctx), &GostR3411_94_CryptoProParamSet); c->dctx.cipher_ctx = &(c->cctx); @@ -48,20 +61,20 @@ int gost_digest_init(EVP_MD_CTX *ctx) int gost_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count) { - return hash_block((gost_hash_ctx *) ctx->md_data, data, count); + return hash_block((gost_hash_ctx *) EVP_MD_CTX_md_data(ctx), data, count); } int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md) { - return finish_hash((gost_hash_ctx *) ctx->md_data, md); + return finish_hash((gost_hash_ctx *) EVP_MD_CTX_md_data(ctx), md); } int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) { - struct ossl_gost_digest_ctx *md_ctx = to->md_data; - if (to->md_data && from->md_data) { - memcpy(to->md_data, from->md_data, + struct ossl_gost_digest_ctx *md_ctx = EVP_MD_CTX_md_data(to); + if (EVP_MD_CTX_md_data(to) && EVP_MD_CTX_md_data(from)) { + memcpy(EVP_MD_CTX_md_data(to), EVP_MD_CTX_md_data(from), sizeof(struct ossl_gost_digest_ctx)); md_ctx->dctx.cipher_ctx = &(md_ctx->cctx); } @@ -70,7 +83,7 @@ int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) int gost_digest_cleanup(EVP_MD_CTX *ctx) { - if (ctx->md_data) - memset(ctx->md_data, 0, sizeof(struct ossl_gost_digest_ctx)); + if (EVP_MD_CTX_md_data(ctx)) + memset(EVP_MD_CTX_md_data(ctx), 0, sizeof(struct ossl_gost_digest_ctx)); return 1; } diff --git a/gost_md2012.c b/gost_md2012.c index 098208d..52522ee 100644 --- a/gost_md2012.c +++ b/gost_md2012.c @@ -27,78 +27,103 @@ static int gost_digest_ctrl_512(EVP_MD_CTX *ctx, int type, int arg, const char micalg_256[] = "gostr3411-2012-256"; const char micalg_512[] = "gostr3411-2012-512"; -EVP_MD digest_gost2012_512 = { - NID_id_GostR3411_2012_512, - NID_undef, - 64, /* digest size */ - EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, - gost_digest_init512, - gost_digest_update, - gost_digest_final, - gost_digest_copy, - gost_digest_cleanup, - NULL, - NULL, - {NID_undef, NID_undef, 0, 0, 0}, - 64, /* block size */ - sizeof(gost2012_hash_ctx), - gost_digest_ctrl_512, -}; - -EVP_MD digest_gost2012_256 = { - NID_id_GostR3411_2012_256, - NID_undef, - 32, /* digest size */ - EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, - gost_digest_init256, - gost_digest_update, - gost_digest_final, - gost_digest_copy, - gost_digest_cleanup, - NULL, - NULL, - {NID_undef, NID_undef, 0, 0, 0}, - 64, /* block size */ - sizeof(gost2012_hash_ctx), - gost_digest_ctrl_256 -}; +static EVP_MD *_hidden_GostR3411_2012_256_md = NULL; +static EVP_MD *_hidden_GostR3411_2012_512_md = NULL; + +EVP_MD *digest_gost2012_256(void) +{ + if (_hidden_GostR3411_2012_256_md == NULL) { + EVP_MD *md; + + if ((md = EVP_MD_meth_new(NID_id_GostR3411_2012_256, NID_undef)) == NULL + || !EVP_MD_meth_set_result_size(md, 32) + || !EVP_MD_meth_set_input_blocksize(md, 64) + || !EVP_MD_meth_set_app_datasize(md, sizeof(gost2012_hash_ctx)) + || !EVP_MD_meth_set_init(md, gost_digest_init256) + || !EVP_MD_meth_set_update(md, gost_digest_update) + || !EVP_MD_meth_set_final(md, gost_digest_final) + || !EVP_MD_meth_set_copy(md, gost_digest_copy) + || !EVP_MD_meth_set_ctrl(md, gost_digest_ctrl_256) + || !EVP_MD_meth_set_cleanup(md, gost_digest_cleanup)) { + EVP_MD_meth_free(md); + md = NULL; + } + _hidden_GostR3411_2012_256_md = md; + } + return _hidden_GostR3411_2012_256_md; +} + +void digest_gost2012_256_destroy(void) +{ + EVP_MD_meth_free(_hidden_GostR3411_2012_256_md); + _hidden_GostR3411_2012_256_md = NULL; +} + +EVP_MD *digest_gost2012_512(void) +{ + if (_hidden_GostR3411_2012_512_md == NULL) { + EVP_MD *md; + + if ((md = EVP_MD_meth_new(NID_id_GostR3411_2012_512, NID_undef)) == NULL + || !EVP_MD_meth_set_result_size(md, 64) + || !EVP_MD_meth_set_input_blocksize(md, 64) + || !EVP_MD_meth_set_app_datasize(md, sizeof(gost2012_hash_ctx)) + || !EVP_MD_meth_set_init(md, gost_digest_init512) + || !EVP_MD_meth_set_update(md, gost_digest_update) + || !EVP_MD_meth_set_final(md, gost_digest_final) + || !EVP_MD_meth_set_copy(md, gost_digest_copy) + || !EVP_MD_meth_set_ctrl(md, gost_digest_ctrl_512) + || !EVP_MD_meth_set_cleanup(md, gost_digest_cleanup)) { + EVP_MD_meth_free(md); + md = NULL; + } + _hidden_GostR3411_2012_512_md = md; + } + return _hidden_GostR3411_2012_512_md; +} + +void digest_gost2012_512_destroy(void) +{ + EVP_MD_meth_free(_hidden_GostR3411_2012_512_md); + _hidden_GostR3411_2012_512_md = NULL; +} static int gost_digest_init512(EVP_MD_CTX *ctx) { - init_gost2012_hash_ctx((gost2012_hash_ctx *) ctx->md_data, 512); + init_gost2012_hash_ctx((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx), 512); return 1; } static int gost_digest_init256(EVP_MD_CTX *ctx) { - init_gost2012_hash_ctx((gost2012_hash_ctx *) ctx->md_data, 256); + init_gost2012_hash_ctx((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx), 256); return 1; } static int gost_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count) { - gost2012_hash_block((gost2012_hash_ctx *) ctx->md_data, data, count); + gost2012_hash_block((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx), data, count); return 1; } static int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md) { - gost2012_finish_hash((gost2012_hash_ctx *) ctx->md_data, md); + gost2012_finish_hash((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx), md); return 1; } static int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) { - if (to->md_data && from->md_data) - memcpy(to->md_data, from->md_data, sizeof(gost2012_hash_ctx)); + if (EVP_MD_CTX_md_data(to) && EVP_MD_CTX_md_data(from)) + memcpy(EVP_MD_CTX_md_data(to), EVP_MD_CTX_md_data(from), sizeof(gost2012_hash_ctx)); return 1; } static int gost_digest_cleanup(EVP_MD_CTX *ctx) { - if (ctx->md_data) - memset(ctx->md_data, 0x00, sizeof(gost2012_hash_ctx)); + if (EVP_MD_CTX_md_data(ctx)) + memset(EVP_MD_CTX_md_data(ctx), 0x00, sizeof(gost2012_hash_ctx)); return 1; } diff --git a/gost_pmeth.c b/gost_pmeth.c index 2d580ae..6b38e60 100644 --- a/gost_pmeth.c +++ b/gost_pmeth.c @@ -146,8 +146,10 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) case EVP_PKEY_CTRL_SET_IV: OPENSSL_assert(p2 != NULL); pctx->shared_ukm = OPENSSL_malloc((int)p1); - if (!pctx->shared_ukm) + if (pctx->shared_ukm == NULL) { + GOSTerr(GOST_F_PKEY_GOST_CTRL, ERR_R_MALLOC_FAILURE); return 0; + } memcpy(pctx->shared_ukm, p2, (int)p1); return 1; case EVP_PKEY_CTRL_PEER_KEY: @@ -566,13 +568,12 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) GOST_R_MAC_KEY_NOT_SET); return 0; } - return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 0, - key); + return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx)) + (mctx, EVP_MD_CTRL_SET_KEY, 0, key); } else { - return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, - &(data->key)); + return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx)) + (mctx, EVP_MD_CTRL_SET_KEY, 32, &(data->key)); } - return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, key); } case EVP_PKEY_CTRL_MAC_LEN: { @@ -707,7 +708,8 @@ static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, return 1; } - mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_MAC_LEN, data->mac_size, NULL); + EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx)) + (mctx, EVP_MD_CTRL_MAC_LEN, data->mac_size, NULL); ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen); *siglen = data->mac_size; return ret; -- 2.39.2