- {
- OMAC_CTX *c = EVP_MD_CTX_md_data(ctx);
- const EVP_MD *md = EVP_MD_CTX_md(ctx);
- const EVP_CIPHER *cipher = NULL;
-
- if (c->cipher_nid == NID_undef)
- {
- switch (EVP_MD_nid(md))
- {
- case NID_magma_mac:
- c->cipher_nid = NID_magma_cbc;
- break;
-
- case NID_grasshopper_mac:
- c->cipher_nid = NID_grasshopper_cbc;
- break;
- }
- }
- cipher = EVP_get_cipherbynid(c->cipher_nid);
-
- if (cipher == NULL)
- {
- GOSTerr(GOST_F_OMAC_IMIT_CTRL, GOST_R_CIPHER_NOT_FOUND);
- }
-
- if (EVP_MD_meth_get_init(EVP_MD_CTX_md(ctx)) (ctx) <= 0) {
- GOSTerr(GOST_F_OMAC_IMIT_CTRL, GOST_R_MAC_KEY_NOT_SET);
- return 0;
- }
- EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NO_INIT);
-
- if (c->key_set)
- {
- GOSTerr(GOST_F_OMAC_IMIT_CTRL, GOST_R_BAD_ORDER);
- return 0;
- }
-
- if (arg == 0) {
- struct gost_mac_key *key = (struct gost_mac_key *)ptr;
- return omac_key(c, cipher, key->key, 32);
-
- } else if (arg == 32) {
- return omac_key(c, cipher, ptr, 32);
- }
- GOSTerr(GOST_F_OMAC_IMIT_CTRL, GOST_R_INVALID_MAC_KEY_SIZE);
- return 0;
- }
- case EVP_MD_CTRL_MAC_LEN: