]>
Commit | Line | Data |
---|---|---|
c85d5e02 | 1 | /* |
fbd2ece1 | 2 | * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. |
c85d5e02 SL |
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 | 12 | |
23c48d94 | 13 | # include <openssl/core_dispatch.h> |
c85d5e02 SL |
14 | # include <openssl/core_names.h> |
15 | # include <openssl/params.h> | |
1c1daab9 | 16 | # include "prov/providercommon.h" |
c85d5e02 | 17 | |
af53092c SL |
18 | /* Internal flags that can be queried */ |
19 | #define PROV_DIGEST_FLAG_XOF 0x0001 | |
20 | #define PROV_DIGEST_FLAG_ALGID_ABSENT 0x0002 | |
21 | ||
c85d5e02 SL |
22 | # ifdef __cplusplus |
23 | extern "C" { | |
24 | # endif | |
25 | ||
26 | #define PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \ | |
47c076ac | 27 | static OSSL_FUNC_digest_get_params_fn name##_get_params; \ |
c85d5e02 SL |
28 | static int name##_get_params(OSSL_PARAM params[]) \ |
29 | { \ | |
47c076ac | 30 | return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \ |
c85d5e02 SL |
31 | } |
32 | ||
33 | #define PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name) \ | |
34 | { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, \ | |
35 | { OSSL_FUNC_DIGEST_GETTABLE_PARAMS, \ | |
47c076ac | 36 | (void (*)(void))ossl_digest_default_gettable_params } |
c85d5e02 SL |
37 | |
38 | # define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START( \ | |
39 | name, CTX, blksize, dgstsize, flags, init, upd, fin) \ | |
47c076ac SL |
40 | static OSSL_FUNC_digest_newctx_fn name##_newctx; \ |
41 | static OSSL_FUNC_digest_freectx_fn name##_freectx; \ | |
42 | static OSSL_FUNC_digest_dupctx_fn name##_dupctx; \ | |
c85d5e02 SL |
43 | static void *name##_newctx(void *prov_ctx) \ |
44 | { \ | |
47c076ac | 45 | CTX *ctx = ossl_prov_is_running() ? OPENSSL_zalloc(sizeof(*ctx)) : NULL; \ |
c85d5e02 SL |
46 | return ctx; \ |
47 | } \ | |
48 | static void name##_freectx(void *vctx) \ | |
49 | { \ | |
50 | CTX *ctx = (CTX *)vctx; \ | |
51 | OPENSSL_clear_free(ctx, sizeof(*ctx)); \ | |
52 | } \ | |
53 | static void *name##_dupctx(void *ctx) \ | |
54 | { \ | |
55 | CTX *in = (CTX *)ctx; \ | |
47c076ac | 56 | CTX *ret = ossl_prov_is_running() ? OPENSSL_malloc(sizeof(*ret)) : NULL; \ |
c676ff42 P |
57 | if (ret != NULL) \ |
58 | *ret = *in; \ | |
c85d5e02 SL |
59 | return ret; \ |
60 | } \ | |
1c1daab9 P |
61 | static OSSL_FUNC_digest_init_fn name##_internal_init; \ |
62 | static int name##_internal_init(void *ctx) \ | |
63 | { \ | |
47c076ac | 64 | return ossl_prov_is_running() ? init(ctx) : 0; \ |
1c1daab9 P |
65 | } \ |
66 | static OSSL_FUNC_digest_final_fn name##_internal_final; \ | |
c85d5e02 SL |
67 | static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \ |
68 | size_t outsz) \ | |
69 | { \ | |
47c076ac | 70 | if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) { \ |
c85d5e02 SL |
71 | *outl = dgstsize; \ |
72 | return 1; \ | |
73 | } \ | |
74 | return 0; \ | |
75 | } \ | |
76 | PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \ | |
1be63951 | 77 | const OSSL_DISPATCH ossl_##name##_functions[] = { \ |
c85d5e02 | 78 | { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \ |
1c1daab9 | 79 | { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init }, \ |
c85d5e02 SL |
80 | { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))upd }, \ |
81 | { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final }, \ | |
82 | { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \ | |
83 | { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx }, \ | |
84 | PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name) | |
85 | ||
86 | # define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END \ | |
87 | { 0, NULL } \ | |
88 | }; | |
89 | ||
90 | # define IMPLEMENT_digest_functions( \ | |
91 | name, CTX, blksize, dgstsize, flags, init, upd, fin) \ | |
92 | PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \ | |
93 | init, upd, fin), \ | |
94 | PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END | |
95 | ||
96 | # define IMPLEMENT_digest_functions_with_settable_ctx( \ | |
97 | name, CTX, blksize, dgstsize, flags, init, upd, fin, \ | |
98 | settable_ctx_params, set_ctx_params) \ | |
99 | PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \ | |
100 | init, upd, fin), \ | |
101 | { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \ | |
102 | { OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params }, \ | |
103 | PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END | |
104 | ||
105 | ||
47c076ac SL |
106 | const OSSL_PARAM *ossl_digest_default_gettable_params(void *provctx); |
107 | int ossl_digest_default_get_params(OSSL_PARAM params[], size_t blksz, | |
108 | size_t paramsz, unsigned long flags); | |
c85d5e02 SL |
109 | |
110 | # ifdef __cplusplus | |
111 | } | |
112 | # endif | |
113 | ||
ae4186b0 | 114 | #endif /* OSSL_PROVIDERS_DIGESTCOMMON_H */ |