1616#include "gost_lcl.h"
1717#include "gost_gost2015.h"
1818#include "gost_tls12_additional.h"
19+ #include "gost_digest_details.h"
1920
2021#if !defined(CCGOST_DEBUG ) && !defined(DEBUG )
2122# ifndef NDEBUG
@@ -290,23 +291,20 @@ GOST_cipher magma_cbc_cipher = {
290291
291292/* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
292293/* Init functions which set specific parameters */
293- static int gost_imit_init_cpa (EVP_MD_CTX * ctx );
294- static int gost_imit_init_cp_12 (EVP_MD_CTX * ctx );
295- /* process block of data */
296- static int gost_imit_update (EVP_MD_CTX * ctx , const void * data , size_t count );
297- /* Return computed value */
298- static int gost_imit_final (EVP_MD_CTX * ctx , unsigned char * md );
299- /* Copies context */
300- static int gost_imit_copy (EVP_MD_CTX * to , const EVP_MD_CTX * from );
301- static int gost_imit_cleanup (EVP_MD_CTX * ctx );
302- /* Control function, knows how to set MAC key.*/
303- static int gost_imit_ctrl (EVP_MD_CTX * ctx , int type , int arg , void * ptr );
304-
305- GOST_digest Gost28147_89_MAC_digest = {
294+ static int gost_imit_init_cpa (GOST_digest_ctx * ctx );
295+ static int gost_imit_init_cp_12 (GOST_digest_ctx * ctx );
296+ static int gost_imit_update (GOST_digest_ctx * ctx , const void * data ,
297+ size_t count );
298+ static int gost_imit_final (GOST_digest_ctx * ctx , unsigned char * md );
299+ static int gost_imit_copy (GOST_digest_ctx * to , const GOST_digest_ctx * from );
300+ static int gost_imit_cleanup (GOST_digest_ctx * ctx );
301+ static int gost_imit_ctrl (GOST_digest_ctx * ctx , int cmd , int p1 , void * p2 );
302+
303+ GOST_digest Gost28147_89_mac = {
306304 .nid = NID_id_Gost28147_89_MAC ,
307305 .result_size = 4 ,
308306 .input_blocksize = 8 ,
309- .app_datasize = sizeof (struct ossl_gost_imit_ctx ),
307+ .algctx_size = sizeof (struct ossl_gost_imit_ctx ),
310308 .flags = EVP_MD_FLAG_XOF ,
311309 .init = gost_imit_init_cpa ,
312310 .update = gost_imit_update ,
@@ -316,11 +314,11 @@ GOST_digest Gost28147_89_MAC_digest = {
316314 .ctrl = gost_imit_ctrl ,
317315};
318316
319- GOST_digest Gost28147_89_mac_12_digest = {
317+ GOST_digest Gost28147_89_mac_12 = {
320318 .nid = NID_gost_mac_12 ,
321319 .result_size = 4 ,
322320 .input_blocksize = 8 ,
323- .app_datasize = sizeof (struct ossl_gost_imit_ctx ),
321+ .algctx_size = sizeof (struct ossl_gost_imit_ctx ),
324322 .flags = EVP_MD_FLAG_XOF ,
325323 .init = gost_imit_init_cp_12 ,
326324 .update = gost_imit_update ,
@@ -1512,9 +1510,9 @@ static int magma_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
15121510 return 1 ;
15131511}
15141512
1515- static int gost_imit_init (EVP_MD_CTX * ctx , gost_subst_block * block )
1513+ static int gost_imit_init (GOST_digest_ctx * ctx , gost_subst_block * block )
15161514{
1517- struct ossl_gost_imit_ctx * c = EVP_MD_CTX_md_data (ctx );
1515+ struct ossl_gost_imit_ctx * c = GOST_digest_ctx_data (ctx );
15181516 memset (c -> buffer , 0 , sizeof (c -> buffer ));
15191517 memset (c -> partial_block , 0 , sizeof (c -> partial_block ));
15201518 c -> count = 0 ;
@@ -1525,12 +1523,12 @@ static int gost_imit_init(EVP_MD_CTX *ctx, gost_subst_block * block)
15251523 return 1 ;
15261524}
15271525
1528- static int gost_imit_init_cpa (EVP_MD_CTX * ctx )
1526+ static int gost_imit_init_cpa (GOST_digest_ctx * ctx )
15291527{
15301528 return gost_imit_init (ctx , & Gost28147_CryptoProParamSetA );
15311529}
15321530
1533- static int gost_imit_init_cp_12 (EVP_MD_CTX * ctx )
1531+ static int gost_imit_init_cp_12 (GOST_digest_ctx * ctx )
15341532{
15351533 return gost_imit_init (ctx , & Gost28147_TC26ParamSetZ );
15361534}
@@ -1551,9 +1549,9 @@ static void mac_block_mesh(struct ossl_gost_imit_ctx *c,
15511549 c -> count = c -> count % 1024 + 8 ;
15521550}
15531551
1554- static int gost_imit_update (EVP_MD_CTX * ctx , const void * data , size_t count )
1552+ static int gost_imit_update (GOST_digest_ctx * ctx , const void * data , size_t count )
15551553{
1556- struct ossl_gost_imit_ctx * c = EVP_MD_CTX_md_data (ctx );
1554+ struct ossl_gost_imit_ctx * c = GOST_digest_ctx_data (ctx );
15571555 const unsigned char * p = data ;
15581556 size_t bytes = count ;
15591557 if (!(c -> key_set )) {
@@ -1584,9 +1582,9 @@ static int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count)
15841582 return 1 ;
15851583}
15861584
1587- static int gost_imit_final (EVP_MD_CTX * ctx , unsigned char * md )
1585+ static int gost_imit_final (GOST_digest_ctx * ctx , unsigned char * md )
15881586{
1589- struct ossl_gost_imit_ctx * c = EVP_MD_CTX_md_data (ctx );
1587+ struct ossl_gost_imit_ctx * c = GOST_digest_ctx_data (ctx );
15901588 if (!c -> key_set ) {
15911589 GOSTerr (GOST_F_GOST_IMIT_FINAL , GOST_R_MAC_KEY_NOT_SET );
15921590 return 0 ;
@@ -1607,21 +1605,21 @@ static int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md)
16071605 return 1 ;
16081606}
16091607
1610- static int gost_imit_ctrl (EVP_MD_CTX * ctx , int type , int arg , void * ptr )
1608+ static int gost_imit_ctrl (GOST_digest_ctx * ctx , int type , int arg , void * ptr )
16111609{
16121610 switch (type ) {
16131611 case EVP_MD_CTRL_KEY_LEN :
16141612 * ((unsigned int * )(ptr )) = 32 ;
16151613 return 1 ;
16161614 case EVP_MD_CTRL_SET_KEY :
16171615 {
1618- struct ossl_gost_imit_ctx * gost_imit_ctx = EVP_MD_CTX_md_data (ctx );
1616+ struct ossl_gost_imit_ctx * gost_imit_ctx = GOST_digest_ctx_data (ctx );
16191617
1620- if (EVP_MD_meth_get_init ( EVP_MD_CTX_md (ctx )) (ctx ) <= 0 ) {
1618+ if (GOST_digest_meth_get_init ( GOST_digest_ctx_digest (ctx ))(ctx ) <= 0 ) {
16211619 GOSTerr (GOST_F_GOST_IMIT_CTRL , GOST_R_MAC_KEY_NOT_SET );
16221620 return 0 ;
16231621 }
1624- EVP_MD_CTX_set_flags (ctx , EVP_MD_CTX_FLAG_NO_INIT );
1622+ GOST_digest_ctx_set_flags (ctx , EVP_MD_CTX_FLAG_NO_INIT );
16251623
16261624 if (arg == 0 ) {
16271625 struct gost_mac_key * key = (struct gost_mac_key * )ptr ;
@@ -1649,7 +1647,7 @@ static int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
16491647 }
16501648 case EVP_MD_CTRL_XOF_LEN :
16511649 {
1652- struct ossl_gost_imit_ctx * c = EVP_MD_CTX_md_data (ctx );
1650+ struct ossl_gost_imit_ctx * c = GOST_digest_ctx_data (ctx );
16531651 if (arg < 1 || arg > 8 ) {
16541652 GOSTerr (GOST_F_GOST_IMIT_CTRL , GOST_R_INVALID_MAC_SIZE );
16551653 return 0 ;
@@ -1663,19 +1661,19 @@ static int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
16631661 }
16641662}
16651663
1666- static int gost_imit_copy (EVP_MD_CTX * to , const EVP_MD_CTX * from )
1664+ static int gost_imit_copy (GOST_digest_ctx * to , const GOST_digest_ctx * from )
16671665{
1668- if (EVP_MD_CTX_md_data (to ) && EVP_MD_CTX_md_data (from )) {
1669- memcpy (EVP_MD_CTX_md_data (to ), EVP_MD_CTX_md_data (from ),
1666+ if (GOST_digest_ctx_data (to ) && GOST_digest_ctx_data (from )) {
1667+ memcpy (GOST_digest_ctx_data (to ), GOST_digest_ctx_data (from ),
16701668 sizeof (struct ossl_gost_imit_ctx ));
16711669 }
16721670 return 1 ;
16731671}
16741672
16751673/* Clean up imit ctx */
1676- static int gost_imit_cleanup (EVP_MD_CTX * ctx )
1674+ static int gost_imit_cleanup (GOST_digest_ctx * ctx )
16771675{
1678- memset ( EVP_MD_CTX_md_data (ctx ), 0 , sizeof (struct ossl_gost_imit_ctx ));
1676+ OPENSSL_cleanse ( GOST_digest_ctx_data (ctx ), sizeof (struct ossl_gost_imit_ctx ));
16791677 return 1 ;
16801678}
16811679/* vim: set expandtab cinoptions=\:0,l1,t0,g0,(0 sw=4 : */
0 commit comments