Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/openssl/providers/implementations/include/prov/digestcommon.h
105418 views
1
/*
2
* Copyright 2019-2021 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
10
#ifndef OSSL_PROVIDERS_DIGESTCOMMON_H
11
#define OSSL_PROVIDERS_DIGESTCOMMON_H
12
13
#include <openssl/core_dispatch.h>
14
#include <openssl/core_names.h>
15
#include <openssl/params.h>
16
#include "prov/providercommon.h"
17
18
/* Internal flags that can be queried */
19
#define PROV_DIGEST_FLAG_XOF 0x0001
20
#define PROV_DIGEST_FLAG_ALGID_ABSENT 0x0002
21
22
#ifdef __cplusplus
23
extern "C" {
24
#endif
25
26
#define PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
27
static OSSL_FUNC_digest_get_params_fn name##_get_params; \
28
static int name##_get_params(OSSL_PARAM params[]) \
29
{ \
30
return ossl_digest_default_get_params(params, blksize, dgstsize, flags); \
31
}
32
33
#define PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name) \
34
{ OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, \
35
{ \
36
OSSL_FUNC_DIGEST_GETTABLE_PARAMS, \
37
(void (*)(void))ossl_digest_default_gettable_params \
38
}
39
40
#define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin) \
41
static OSSL_FUNC_digest_final_fn name##_internal_final; \
42
static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \
43
size_t outsz) \
44
{ \
45
if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) { \
46
*outl = dgstsize; \
47
return 1; \
48
} \
49
return 0; \
50
}
51
52
#define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START( \
53
name, CTX, blksize, dgstsize, flags, upd, fin) \
54
static OSSL_FUNC_digest_newctx_fn name##_newctx; \
55
static OSSL_FUNC_digest_freectx_fn name##_freectx; \
56
static OSSL_FUNC_digest_dupctx_fn name##_dupctx; \
57
static void *name##_newctx(void *prov_ctx) \
58
{ \
59
CTX *ctx = ossl_prov_is_running() ? OPENSSL_zalloc(sizeof(*ctx)) : NULL; \
60
return ctx; \
61
} \
62
static void name##_freectx(void *vctx) \
63
{ \
64
CTX *ctx = (CTX *)vctx; \
65
OPENSSL_clear_free(ctx, sizeof(*ctx)); \
66
} \
67
static void *name##_dupctx(void *ctx) \
68
{ \
69
CTX *in = (CTX *)ctx; \
70
CTX *ret = ossl_prov_is_running() ? OPENSSL_malloc(sizeof(*ret)) : NULL; \
71
if (ret != NULL) \
72
*ret = *in; \
73
return ret; \
74
} \
75
static void name##_copyctx(void *voutctx, void *vinctx) \
76
{ \
77
CTX *outctx = (CTX *)voutctx; \
78
CTX *inctx = (CTX *)vinctx; \
79
*outctx = *inctx; \
80
} \
81
PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin) \
82
PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
83
const OSSL_DISPATCH ossl_##name##_functions[] = { \
84
{ OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \
85
{ OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))upd }, \
86
{ OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final }, \
87
{ OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \
88
{ OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx }, \
89
{ OSSL_FUNC_DIGEST_COPYCTX, (void (*)(void))name##_copyctx }, \
90
PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name)
91
92
#define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END \
93
{ \
94
0, NULL \
95
} \
96
} \
97
;
98
99
#define IMPLEMENT_digest_functions( \
100
name, CTX, blksize, dgstsize, flags, init, upd, fin) \
101
static OSSL_FUNC_digest_init_fn name##_internal_init; \
102
static int name##_internal_init(void *ctx, \
103
ossl_unused const OSSL_PARAM params[]) \
104
{ \
105
return ossl_prov_is_running() && init(ctx); \
106
} \
107
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
108
upd, fin), \
109
{ OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init }, \
110
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
111
112
#define IMPLEMENT_digest_functions_with_settable_ctx( \
113
name, CTX, blksize, dgstsize, flags, init, upd, fin, \
114
settable_ctx_params, set_ctx_params) \
115
static OSSL_FUNC_digest_init_fn name##_internal_init; \
116
static int name##_internal_init(void *ctx, const OSSL_PARAM params[]) \
117
{ \
118
return ossl_prov_is_running() \
119
&& init(ctx) \
120
&& set_ctx_params(ctx, params); \
121
} \
122
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
123
upd, fin), \
124
{ OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init }, \
125
{ OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \
126
{ OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params }, \
127
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
128
129
const OSSL_PARAM *ossl_digest_default_gettable_params(void *provctx);
130
int ossl_digest_default_get_params(OSSL_PARAM params[], size_t blksz,
131
size_t paramsz, unsigned long flags);
132
133
#ifdef __cplusplus
134
}
135
#endif
136
137
#endif /* OSSL_PROVIDERS_DIGESTCOMMON_H */
138
139