aboutsummaryrefslogtreecommitdiff
path: root/gost_crypt.c
diff options
context:
space:
mode:
authorVitaly Chikunov <vt@altlinux.org>2020-05-13 00:53:01 +0300
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>2020-05-13 20:12:23 +0300
commitd3756bbed444cfe1072e9469c469bfba8b6c6dbe (patch)
treeec51553d9f3039a8e28a10e582156d3d5d725838 /gost_crypt.c
parent2893b979bdb5ff1d902dc78c478162854eeb4a4b (diff)
downloadgost-engine-d3756bbed444cfe1072e9469c469bfba8b6c6dbe.zip
gost-engine-d3756bbed444cfe1072e9469c469bfba8b6c6dbe.tar.gz
gost-engine-d3756bbed444cfe1072e9469c469bfba8b6c6dbe.tar.bz2
gost_crypt: Add Gost28147_89_MAC_digest, Gost28147_89_mac_12_digest
Covert their registration to table method.
Diffstat (limited to 'gost_crypt.c')
-rw-r--r--gost_crypt.c79
1 files changed, 31 insertions, 48 deletions
diff --git a/gost_crypt.c b/gost_crypt.c
index 8277fa2..66885bf 100644
--- a/gost_crypt.c
+++ b/gost_crypt.c
@@ -256,69 +256,52 @@ 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);
-static EVP_MD *_hidden_Gost28147_89_MAC_md = NULL;
-static EVP_MD *_hidden_Gost28147_89_12_MAC_md = NULL;
+GOST_digest Gost28147_89_MAC_digest = {
+ .nid = NID_id_Gost28147_89_MAC,
+ .result_size = 4,
+ .input_blocksize = 8,
+ .app_datasize = sizeof(struct ossl_gost_imit_ctx),
+ .flags = EVP_MD_FLAG_XOF,
+ .init = gost_imit_init_cpa,
+ .update = gost_imit_update,
+ .final = gost_imit_final,
+ .copy = gost_imit_copy,
+ .cleanup = gost_imit_cleanup,
+ .ctrl = 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, EVP_MD_FLAG_XOF)
- || !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;
+ return GOST_init_digest(&Gost28147_89_MAC_digest);
}
void imit_gost_cpa_destroy(void)
{
- EVP_MD_meth_free(_hidden_Gost28147_89_MAC_md);
- _hidden_Gost28147_89_MAC_md = NULL;
+ GOST_deinit_digest(&Gost28147_89_MAC_digest);
}
+GOST_digest Gost28147_89_mac_12_digest = {
+ .nid = NID_gost_mac_12,
+ .result_size = 4,
+ .input_blocksize = 8,
+ .app_datasize = sizeof(struct ossl_gost_imit_ctx),
+ .flags = EVP_MD_FLAG_XOF,
+ .init = gost_imit_init_cp_12,
+ .update = gost_imit_update,
+ .final = gost_imit_final,
+ .copy = gost_imit_copy,
+ .cleanup = gost_imit_cleanup,
+ .ctrl = gost_imit_ctrl,
+};
+
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, EVP_MD_FLAG_XOF)
- || !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;
+ return GOST_init_digest(&Gost28147_89_mac_12_digest);
}
void imit_gost_cp_12_destroy(void)
{
- EVP_MD_meth_free(_hidden_Gost28147_89_12_MAC_md);
- _hidden_Gost28147_89_12_MAC_md = NULL;
+ GOST_deinit_digest(&Gost28147_89_mac_12_digest);
}
/*