Openssl is already have output result size in EVP_MD.md_size
We should not exceed its value when writing digest output.
This should be fixed more consistently, probably, by removing
dgst_size from OMAC_CTX.
return 1;
}
+static int EVP_MD_meth_get_result_size(const EVP_MD *md)
+{
+ return md->md_size;
+}
+
static inline int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize)
{
md->block_size = blocksize;
#include "e_gost_err.h"
#include "gost_lcl.h"
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+
typedef struct omac_ctx {
CMAC_CTX *cmac_ctx;
size_t dgst_size;
CMAC_Final(c->cmac_ctx, mac, &mac_size);
- memcpy(md, mac, c->dgst_size);
+ int md_size = EVP_MD_meth_get_result_size(EVP_MD_CTX_md(ctx));
+ memcpy(md, mac, min(md_size, c->dgst_size));
return 1;
}