]>
git.ipfire.org Git - thirdparty/openssl.git/blob - providers/implementations/include/prov/digestcommon.h
2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #ifndef OSSL_PROVIDERS_DIGESTCOMMON_H
11 # define OSSL_PROVIDERS_DIGESTCOMMON_H
13 # include <openssl/core_dispatch.h>
14 # include <openssl/core_names.h>
15 # include <openssl/params.h>
21 #define PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
22 static OSSL_FUNC_digest_get_params_fn name##_get_params; \
23 static int name##_get_params(OSSL_PARAM params[]) \
25 return digest_default_get_params(params, blksize, dgstsize, flags); \
28 #define PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name) \
29 { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, \
30 { OSSL_FUNC_DIGEST_GETTABLE_PARAMS, \
31 (void (*)(void))digest_default_gettable_params }
33 # define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START( \
34 name, CTX, blksize, dgstsize, flags, init, upd, fin) \
35 static OSSL_FUNC_digest_newctx_fn name##_newctx; \
36 static OSSL_FUNC_digest_freectx_fn name##_freectx; \
37 static OSSL_FUNC_digest_dupctx_fn name##_dupctx; \
38 static void *name##_newctx(void *prov_ctx) \
40 CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); \
43 static void name##_freectx(void *vctx) \
45 CTX *ctx = (CTX *)vctx; \
46 OPENSSL_clear_free(ctx, sizeof(*ctx)); \
48 static void *name##_dupctx(void *ctx) \
50 CTX *in = (CTX *)ctx; \
51 CTX *ret = OPENSSL_malloc(sizeof(*ret)); \
56 static OSSL_FUNC_digest_final_fn name##_internal_final; \
57 static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \
60 if (outsz >= dgstsize && fin(out, ctx)) { \
66 PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
67 const OSSL_DISPATCH name##_functions[] = { \
68 { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \
69 { OSSL_FUNC_DIGEST_INIT, (void (*)(void))init }, \
70 { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))upd }, \
71 { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final }, \
72 { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \
73 { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx }, \
74 PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name)
76 # define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END \
80 # define IMPLEMENT_digest_functions( \
81 name, CTX, blksize, dgstsize, flags, init, upd, fin) \
82 PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
84 PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
86 # define IMPLEMENT_digest_functions_with_settable_ctx( \
87 name, CTX, blksize, dgstsize, flags, init, upd, fin, \
88 settable_ctx_params, set_ctx_params) \
89 PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
91 { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \
92 { OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params }, \
93 PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
96 const OSSL_PARAM
*digest_default_gettable_params(void);
97 int digest_default_get_params(OSSL_PARAM params
[], size_t blksz
, size_t paramsz
,
104 #endif /* OSSL_PROVIDERS_DIGESTCOMMON_H */