From 56c5e3414135c9443739db3b2b1409c3be265a50 Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Sun, 3 Jan 2016 17:30:05 +0300 Subject: [PATCH] Allow to pass mac_size via -macopt --- e_gost_err.c | 2 ++ e_gost_err.h | 11 ++++++----- gost_lcl.h | 1 + gost_pmeth.c | 22 ++++++++++++++-------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/e_gost_err.c b/e_gost_err.c index 488e0e9..baaeb44 100644 --- a/e_gost_err.c +++ b/e_gost_err.c @@ -98,6 +98,8 @@ static ERR_STRING_DATA GOST_str_functs[] = { {ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL), "PKEY_GOST_MAC_CTRL"}, {ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL_STR), "PKEY_GOST_MAC_CTRL_STR"}, {ERR_FUNC(GOST_F_PKEY_GOST_MAC_KEYGEN), "PKEY_GOST_MAC_KEYGEN"}, + {ERR_FUNC(GOST_F_PKEY_GOST_MAC_SIGNCTX_INIT), + "PKEY_GOST_MAC_SIGNCTX_INIT"}, {ERR_FUNC(GOST_F_PRINT_GOST_EC_PUB), "PRINT_GOST_EC_PUB"}, {ERR_FUNC(GOST_F_PRIV_DECODE_GOST), "PRIV_DECODE_GOST"}, {ERR_FUNC(GOST_F_PUB_DECODE_GOST_EC), "PUB_DECODE_GOST_EC"}, diff --git a/e_gost_err.h b/e_gost_err.h index c624713..e8a5f28 100644 --- a/e_gost_err.h +++ b/e_gost_err.h @@ -64,9 +64,9 @@ extern "C" { * The following lines are auto generated by the script mkerr.pl. Any changes * made after this point may be overwritten when the script is next run. */ - void ERR_load_GOST_strings(void); - void ERR_unload_GOST_strings(void); - void ERR_GOST_error(int function, int reason, char *file, int line); +void ERR_load_GOST_strings(void); +void ERR_unload_GOST_strings(void); +void ERR_GOST_error(int function, int reason, char *file, int line); # define GOSTerr(f,r) ERR_GOST_error((f),(r),__FILE__,__LINE__) /* Error codes for the GOST functions. */ @@ -98,6 +98,7 @@ extern "C" { # define GOST_F_PKEY_GOST_MAC_CTRL 123 # define GOST_F_PKEY_GOST_MAC_CTRL_STR 124 # define GOST_F_PKEY_GOST_MAC_KEYGEN 125 +# define GOST_F_PKEY_GOST_MAC_SIGNCTX_INIT 132 # define GOST_F_PRINT_GOST_EC_PUB 126 # define GOST_F_PRIV_DECODE_GOST 127 # define GOST_F_PUB_DECODE_GOST_EC 128 @@ -138,7 +139,7 @@ extern "C" { # define GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND 126 # define GOST_R_UNSUPPORTED_PARAMETER_SET 127 -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/gost_lcl.h b/gost_lcl.h index b089eb2..bb18ff1 100644 --- a/gost_lcl.h +++ b/gost_lcl.h @@ -80,6 +80,7 @@ struct gost_mac_pmeth_data { struct gost_mac_key { int mac_param_nid; unsigned char key[32]; + short int mac_size; }; /* GOST-specific ASN1 structures */ diff --git a/gost_pmeth.c b/gost_pmeth.c index de35388..2d580ae 100644 --- a/gost_pmeth.c +++ b/gost_pmeth.c @@ -478,6 +478,7 @@ static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx) struct gost_mac_key *key = EVP_PKEY_get0(pkey); if (key) { data->mac_param_nid = key->mac_param_nid; + data->mac_size = key->mac_size; } } @@ -546,14 +547,6 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) { struct gost_cipher_info *param = p2; data->mac_param_nid = param->nid; - struct gost_mac_key *key = NULL; - EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); - if (pkey) { - key = EVP_PKEY_get0(pkey); - if (key) { - key->mac_param_nid = param->nid; - } - } return 1; } case EVP_PKEY_CTRL_DIGESTINIT: @@ -665,6 +658,7 @@ static int pkey_gost_mac_keygen_base(EVP_PKEY_CTX *ctx, return 0; memcpy(keydata->key, data->key, 32); keydata->mac_param_nid = data->mac_param_nid; + keydata->mac_size = data->mac_size; EVP_PKEY_assign(pkey, mac_nid, keydata); return 1; } @@ -681,6 +675,18 @@ static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) { + struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); + + if (data == NULL) { + pkey_gost_mac_init(ctx); + } + + data = EVP_PKEY_CTX_get_data(ctx); + if (!data) { + GOSTerr(GOST_F_PKEY_GOST_MAC_SIGNCTX_INIT, GOST_R_MAC_KEY_NOT_SET); + return 0; + } + return 1; } -- 2.39.5