]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/common/include/internal/digestcommon.h
Fix header file include guard names
[thirdparty/openssl.git] / providers / common / include / internal / digestcommon.h
CommitLineData
c85d5e02
SL
1/*
2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
ae4186b0
DMSP
10#ifndef OSSL_PROVIDERS_DIGESTCOMMON_H
11# define OSSL_PROVIDERS_DIGESTCOMMON_H
c85d5e02
SL
12
13# include <openssl/core_numbers.h>
14# include <openssl/core_names.h>
15# include <openssl/params.h>
16
17# ifdef __cplusplus
18extern "C" {
19# endif
20
21#define PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
22static OSSL_OP_digest_get_params_fn name##_get_params; \
23static int name##_get_params(OSSL_PARAM params[]) \
24{ \
25 return digest_default_get_params(params, blksize, dgstsize, flags); \
26}
27
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 }
32
33# define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START( \
34 name, CTX, blksize, dgstsize, flags, init, upd, fin) \
35static OSSL_OP_digest_newctx_fn name##_newctx; \
36static OSSL_OP_digest_freectx_fn name##_freectx; \
37static OSSL_OP_digest_dupctx_fn name##_dupctx; \
38static void *name##_newctx(void *prov_ctx) \
39{ \
40 CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); \
41 return ctx; \
42} \
43static void name##_freectx(void *vctx) \
44{ \
45 CTX *ctx = (CTX *)vctx; \
46 OPENSSL_clear_free(ctx, sizeof(*ctx)); \
47} \
48static void *name##_dupctx(void *ctx) \
49{ \
50 CTX *in = (CTX *)ctx; \
51 CTX *ret = OPENSSL_malloc(sizeof(*ret)); \
52 *ret = *in; \
53 return ret; \
54} \
55static OSSL_OP_digest_final_fn name##_internal_final; \
56static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \
57 size_t outsz) \
58{ \
59 if (outsz >= dgstsize && fin(out, ctx)) { \
60 *outl = dgstsize; \
61 return 1; \
62 } \
63 return 0; \
64} \
65PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
66const OSSL_DISPATCH name##_functions[] = { \
67 { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \
68 { OSSL_FUNC_DIGEST_INIT, (void (*)(void))init }, \
69 { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))upd }, \
70 { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final }, \
71 { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \
72 { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx }, \
73 PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name)
74
75# define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END \
76 { 0, NULL } \
77};
78
79# define IMPLEMENT_digest_functions( \
80 name, CTX, blksize, dgstsize, flags, init, upd, fin) \
81PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
82 init, upd, fin), \
83PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
84
85# define IMPLEMENT_digest_functions_with_settable_ctx( \
86 name, CTX, blksize, dgstsize, flags, init, upd, fin, \
87 settable_ctx_params, set_ctx_params) \
88PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
89 init, upd, fin), \
90{ OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \
91{ OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params }, \
92PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
93
94
95const OSSL_PARAM *digest_default_gettable_params(void);
1c3ace68 96int digest_default_get_params(OSSL_PARAM params[], size_t blksz, size_t paramsz,
c85d5e02
SL
97 unsigned long flags);
98
99# ifdef __cplusplus
100}
101# endif
102
ae4186b0 103#endif /* OSSL_PROVIDERS_DIGESTCOMMON_H */