1 #include <openssl/core.h>
2 #include <openssl/core_numbers.h>
3 #include <openssl/params.h>
6 #include "gosthash2012.h"
8 const char micalg_256[] = "gostr3411-2012-256";
9 const char micalg_512[] = "gostr3411-2012-512";
11 /* Context management */
12 static void *STREEBOG256_newctx(void *provctx);
13 static void STREEBOG_freectx(void *dctx);
14 static void *STREEBOG_dupctx(void *dctx);
16 /* Digest generation */
17 static int STREEBOG256_digest_init(void *dctx);
18 static int STREEBOG_digest_update(void *dctx, const unsigned char *in, size_t inl);
19 static int STREEBOG_digest_final(void *dctx, unsigned char *out, size_t *outl,
22 /* Digest parameter descriptors */
23 static const OSSL_PARAM *STREEBOG_gettable_params(void);
24 static int STREEBOG256_digest_get_params(OSSL_PARAM params[]);
26 OSSL_DISPATCH streebog256_funcs[] = {
27 { OSSL_FUNC_DIGEST_NEWCTX, (funcptr_t)STREEBOG256_newctx },
28 { OSSL_FUNC_DIGEST_FREECTX, (funcptr_t)STREEBOG_freectx },
29 { OSSL_FUNC_DIGEST_DUPCTX, (funcptr_t)STREEBOG_dupctx },
31 { OSSL_FUNC_DIGEST_INIT, (funcptr_t)STREEBOG256_digest_init },
32 { OSSL_FUNC_DIGEST_UPDATE, (funcptr_t)STREEBOG_digest_update },
33 { OSSL_FUNC_DIGEST_FINAL, (funcptr_t)STREEBOG_digest_final },
35 { OSSL_FUNC_DIGEST_GETTABLE_PARAMS, (funcptr_t)STREEBOG_gettable_params },
36 { OSSL_FUNC_DIGEST_GET_PARAMS, (funcptr_t)STREEBOG256_digest_get_params },
41 static void *STREEBOG256_newctx(void *provctx)
43 gost2012_hash_ctx *pctx = OPENSSL_zalloc(sizeof(gost2012_hash_ctx));
47 static void STREEBOG_freectx(void *dctx)
52 static void *STREEBOG_dupctx(void *dctx)
54 gost2012_hash_ctx *pctx = OPENSSL_zalloc(sizeof(gost2012_hash_ctx));
59 memcpy(pctx, dctx, sizeof(gost2012_hash_ctx));
64 static int STREEBOG256_digest_init(void *dctx)
66 init_gost2012_hash_ctx((gost2012_hash_ctx *)dctx, 256);
70 static int STREEBOG_digest_update(void *dctx, const unsigned char *in, size_t inl)
72 gost2012_hash_block((gost2012_hash_ctx *)dctx, in, inl);
76 static int STREEBOG_digest_final(void *dctx, unsigned char *out, size_t *outl,
79 gost2012_hash_ctx *pctx = (gost2012_hash_ctx *)dctx;
81 if (pctx->digest_size/8 > outsz)
84 gost2012_finish_hash(pctx, out);
85 *outl = pctx->digest_size/8;
89 static const OSSL_PARAM *STREEBOG_gettable_params(void)
91 static const OSSL_PARAM table[] = {
92 OSSL_PARAM_size_t("blocksize", NULL),
93 OSSL_PARAM_size_t("size", NULL),
94 /* OSSL_PARAM_utf8_ptr("micalg", NULL, strlen(micalg_256)+1), */
101 static int STREEBOG256_digest_get_params(OSSL_PARAM params[])
105 if ((p = OSSL_PARAM_locate(params, "blocksize")) != NULL)
106 if (!OSSL_PARAM_set_size_t(p, 64))
108 if ((p = OSSL_PARAM_locate(params, "size")) != NULL)
109 if (!OSSL_PARAM_set_size_t(p, 32))
111 /* if ((p = OSSL_PARAM_locate(params, "micalg")) != NULL)
112 if (!OSSL_PARAM_set_utf8_ptr(p, micalg_256))