X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost_crypt.c;h=feca0b6e2ec030361b6aed90ce8de25f4b67c873;hb=30860f940321eb4762d6449ffef48fc93ad2d2e8;hp=8277fa2536b3713bf1f9d37a427049c3bd0994af;hpb=c6b44c8eaf68bf045805163a8825e5440632653e;p=openssl-gost%2Fengine.git diff --git a/gost_crypt.c b/gost_crypt.c index 8277fa2..feca0b6 100644 --- a/gost_crypt.c +++ b/gost_crypt.c @@ -256,70 +256,33 @@ 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; - -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; -} - -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, 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; -} +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, +}; -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_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, +}; /* * Correspondence between gost parameter OIDs and substitution blocks @@ -327,7 +290,7 @@ void imit_gost_cp_12_destroy(void) * upon engine initialization */ -struct gost_cipher_info gost_cipher_list[] = { +static struct gost_cipher_info gost_cipher_list[] = { /*- NID *//* * Subst block *//* @@ -461,7 +424,7 @@ static int gost_cipher_init_cp_12(EVP_CIPHER_CTX *ctx, } /* Initializes EVP_CIPHER_CTX with default values */ -int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, +static int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { return gost_cipher_init_param(ctx, key, iv, enc, NID_undef, @@ -469,7 +432,7 @@ int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, } /* Initializes EVP_CIPHER_CTX with default values */ -int gost_cipher_init_cbc(EVP_CIPHER_CTX *ctx, const unsigned char *key, +static int gost_cipher_init_cbc(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { return gost_cipher_init_param(ctx, key, iv, enc, NID_undef, @@ -477,7 +440,7 @@ int gost_cipher_init_cbc(EVP_CIPHER_CTX *ctx, const unsigned char *key, } /* Initializes EVP_CIPHER_CTX with default values */ -int magma_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, +static int magma_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx); @@ -513,7 +476,7 @@ int magma_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, } /* Initializes EVP_CIPHER_CTX with default values */ -int magma_cipher_init_ctr_acpkm_omac(EVP_CIPHER_CTX *ctx, const unsigned char *key, +static int magma_cipher_init_ctr_acpkm_omac(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { if (key) { @@ -589,7 +552,7 @@ static void gost_cnt_next(void *ctx, unsigned char *iv, unsigned char *buf) } /* GOST encryption in CBC mode */ -int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { unsigned char b[8]; @@ -626,7 +589,7 @@ int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, } /* MAGMA encryption in CBC mode */ -int magma_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int magma_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { unsigned char b[8]; @@ -768,7 +731,7 @@ static int magma_cipher_do_ctr_acpkm_omac(EVP_CIPHER_CTX *ctx, unsigned char *ou return inl; } /* GOST encryption in CFB mode */ -int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { const unsigned char *in_ptr = in; @@ -887,7 +850,7 @@ static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out, } /* Cleaning up of EVP_CIPHER_CTX */ -int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx) +static int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx) { struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx); EVP_MD_CTX_free(c->omac_ctx); @@ -897,7 +860,7 @@ int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx) } /* Control function for gost cipher */ -int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) +static int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) { switch (type) { case EVP_CTRL_RAND_KEY: @@ -980,7 +943,7 @@ int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) } /* Control function for gost cipher */ -int magma_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) +static int magma_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) { switch (type) { case EVP_CTRL_RAND_KEY: @@ -1044,7 +1007,7 @@ static int magma_cipher_ctl_acpkm_omac(EVP_CIPHER_CTX *ctx, int type, int arg, v } /* Set cipher parameters from ASN1 structure */ -int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) +static int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) { int len = 0; unsigned char *buf = NULL; @@ -1089,7 +1052,7 @@ int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) } /* Store parameters into ASN1 structure */ -int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) +static int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) { int len; GOST_CIPHER_PARAMS *gcp = NULL; @@ -1201,7 +1164,7 @@ static void mac_block_mesh(struct ossl_gost_imit_ctx *c, c->count = c->count % 1024 + 8; } -int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count) +static int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count) { struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx); const unsigned char *p = data; @@ -1234,7 +1197,7 @@ int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count) return 1; } -int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md) +static int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md) { struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx); if (!c->key_set) { @@ -1257,7 +1220,7 @@ int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md) return 1; } -int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) +static int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) { switch (type) { case EVP_MD_CTRL_KEY_LEN: @@ -1313,7 +1276,7 @@ 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) +static int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) { 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), @@ -1323,7 +1286,7 @@ int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) } /* Clean up imit ctx */ -int gost_imit_cleanup(EVP_MD_CTX *ctx) +static int gost_imit_cleanup(EVP_MD_CTX *ctx) { memset(EVP_MD_CTX_md_data(ctx), 0, sizeof(struct ossl_gost_imit_ctx)); return 1;