| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-02-18 22:57:13 +08:00
										 |  |  |  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							|  |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:57 +08:00
										 |  |  | #ifndef OSSL_PROVIDERS_DIGESTCOMMON_H
 | 
					
						
							|  |  |  | # define OSSL_PROVIDERS_DIGESTCOMMON_H
 | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-21 07:21:19 +08:00
										 |  |  | # include <openssl/core_dispatch.h>
 | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | # include <openssl/core_names.h>
 | 
					
						
							|  |  |  | # include <openssl/params.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-07 10:41:00 +08:00
										 |  |  | # include "prov/providercommon.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-17 14:42:05 +08:00
										 |  |  | /* Internal flags that can be queried */ | 
					
						
							|  |  |  | #define PROV_DIGEST_FLAG_XOF             0x0001
 | 
					
						
							|  |  |  | #define PROV_DIGEST_FLAG_ALGID_ABSENT    0x0002
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | # ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | # endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags)             \
 | 
					
						
							| 
									
										
										
											
												Fix external symbols in the provider digest implementations.
Partial fix for #12964
This adds ossl_ names for the following symbols:
blake2b512_init,blake2b_final,blake2b_init,blake2b_init_key,
blake2b_param_init,blake2b_param_set_digest_length,blake2b_param_set_key_length,
blake2b_param_set_personal,blake2b_param_set_salt,blake2b_update,
blake2s256_init,blake2s_final,blake2s_init,blake2s_init_key,
blake2s_param_init,blake2s_param_set_digest_length,blake2s_param_set_key_length,
blake2s_param_set_personal,blake2s_param_set_salt,blake2s_update,
digest_default_get_params,digest_default_gettable_params
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14211)
											
										 
											2021-02-17 17:56:35 +08:00
										 |  |  | static OSSL_FUNC_digest_get_params_fn name##_get_params;                       \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | static int name##_get_params(OSSL_PARAM params[])                              \ | 
					
						
							|  |  |  | {                                                                              \ | 
					
						
							| 
									
										
										
											
												Fix external symbols in the provider digest implementations.
Partial fix for #12964
This adds ossl_ names for the following symbols:
blake2b512_init,blake2b_final,blake2b_init,blake2b_init_key,
blake2b_param_init,blake2b_param_set_digest_length,blake2b_param_set_key_length,
blake2b_param_set_personal,blake2b_param_set_salt,blake2b_update,
blake2s256_init,blake2s_final,blake2s_init,blake2s_init_key,
blake2s_param_init,blake2s_param_set_digest_length,blake2s_param_set_key_length,
blake2s_param_set_personal,blake2s_param_set_salt,blake2s_update,
digest_default_get_params,digest_default_gettable_params
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14211)
											
										 
											2021-02-17 17:56:35 +08:00
										 |  |  |     return ossl_digest_default_get_params(params, blksize, dgstsize, flags);   \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name)                             \
 | 
					
						
							|  |  |  | { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params },            \ | 
					
						
							|  |  |  | { OSSL_FUNC_DIGEST_GETTABLE_PARAMS,                                            \ | 
					
						
							| 
									
										
										
											
												Fix external symbols in the provider digest implementations.
Partial fix for #12964
This adds ossl_ names for the following symbols:
blake2b512_init,blake2b_final,blake2b_init,blake2b_init_key,
blake2b_param_init,blake2b_param_set_digest_length,blake2b_param_set_key_length,
blake2b_param_set_personal,blake2b_param_set_salt,blake2b_update,
blake2s256_init,blake2s_final,blake2s_init,blake2s_init_key,
blake2s_param_init,blake2s_param_set_digest_length,blake2s_param_set_key_length,
blake2s_param_set_personal,blake2s_param_set_salt,blake2s_update,
digest_default_get_params,digest_default_gettable_params
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14211)
											
										 
											2021-02-17 17:56:35 +08:00
										 |  |  |   (void (*)(void))ossl_digest_default_gettable_params } | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-12 23:31:35 +08:00
										 |  |  | # define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin)                           \
 | 
					
						
							|  |  |  | static OSSL_FUNC_digest_final_fn name##_internal_final;                        \ | 
					
						
							|  |  |  | static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl,  \ | 
					
						
							|  |  |  |                                  size_t outsz)                                 \ | 
					
						
							|  |  |  | {                                                                              \ | 
					
						
							|  |  |  |     if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) {        \ | 
					
						
							|  |  |  |         *outl = dgstsize;                                                      \ | 
					
						
							|  |  |  |         return 1;                                                              \ | 
					
						
							|  |  |  |     }                                                                          \ | 
					
						
							|  |  |  |     return 0;                                                                  \ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | # define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(                            \
 | 
					
						
							| 
									
										
										
										
											2021-03-02 20:42:41 +08:00
										 |  |  |     name, CTX, blksize, dgstsize, flags, upd, fin)                             \ | 
					
						
							| 
									
										
										
											
												Fix external symbols in the provider digest implementations.
Partial fix for #12964
This adds ossl_ names for the following symbols:
blake2b512_init,blake2b_final,blake2b_init,blake2b_init_key,
blake2b_param_init,blake2b_param_set_digest_length,blake2b_param_set_key_length,
blake2b_param_set_personal,blake2b_param_set_salt,blake2b_update,
blake2s256_init,blake2s_final,blake2s_init,blake2s_init_key,
blake2s_param_init,blake2s_param_set_digest_length,blake2s_param_set_key_length,
blake2s_param_set_personal,blake2s_param_set_salt,blake2s_update,
digest_default_get_params,digest_default_gettable_params
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14211)
											
										 
											2021-02-17 17:56:35 +08:00
										 |  |  | static OSSL_FUNC_digest_newctx_fn name##_newctx;                               \ | 
					
						
							|  |  |  | static OSSL_FUNC_digest_freectx_fn name##_freectx;                             \ | 
					
						
							|  |  |  | static OSSL_FUNC_digest_dupctx_fn name##_dupctx;                               \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | static void *name##_newctx(void *prov_ctx)                                     \ | 
					
						
							|  |  |  | {                                                                              \ | 
					
						
							| 
									
										
										
											
												Fix external symbols in the provider digest implementations.
Partial fix for #12964
This adds ossl_ names for the following symbols:
blake2b512_init,blake2b_final,blake2b_init,blake2b_init_key,
blake2b_param_init,blake2b_param_set_digest_length,blake2b_param_set_key_length,
blake2b_param_set_personal,blake2b_param_set_salt,blake2b_update,
blake2s256_init,blake2s_final,blake2s_init,blake2s_init_key,
blake2s_param_init,blake2s_param_set_digest_length,blake2s_param_set_key_length,
blake2s_param_set_personal,blake2s_param_set_salt,blake2s_update,
digest_default_get_params,digest_default_gettable_params
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14211)
											
										 
											2021-02-17 17:56:35 +08:00
										 |  |  |     CTX *ctx = ossl_prov_is_running() ? OPENSSL_zalloc(sizeof(*ctx)) : NULL;   \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  |     return ctx;                                                                \ | 
					
						
							|  |  |  | }                                                                              \ | 
					
						
							|  |  |  | static void name##_freectx(void *vctx)                                         \ | 
					
						
							|  |  |  | {                                                                              \ | 
					
						
							|  |  |  |     CTX *ctx = (CTX *)vctx;                                                    \ | 
					
						
							|  |  |  |     OPENSSL_clear_free(ctx,  sizeof(*ctx));                                    \ | 
					
						
							|  |  |  | }                                                                              \ | 
					
						
							|  |  |  | static void *name##_dupctx(void *ctx)                                          \ | 
					
						
							|  |  |  | {                                                                              \ | 
					
						
							|  |  |  |     CTX *in = (CTX *)ctx;                                                      \ | 
					
						
							| 
									
										
										
											
												Fix external symbols in the provider digest implementations.
Partial fix for #12964
This adds ossl_ names for the following symbols:
blake2b512_init,blake2b_final,blake2b_init,blake2b_init_key,
blake2b_param_init,blake2b_param_set_digest_length,blake2b_param_set_key_length,
blake2b_param_set_personal,blake2b_param_set_salt,blake2b_update,
blake2s256_init,blake2s_final,blake2s_init,blake2s_init_key,
blake2s_param_init,blake2s_param_set_digest_length,blake2s_param_set_key_length,
blake2s_param_set_personal,blake2s_param_set_salt,blake2s_update,
digest_default_get_params,digest_default_gettable_params
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14211)
											
										 
											2021-02-17 17:56:35 +08:00
										 |  |  |     CTX *ret = ossl_prov_is_running() ? OPENSSL_malloc(sizeof(*ret)) : NULL;   \ | 
					
						
							| 
									
										
										
										
											2019-11-21 04:47:57 +08:00
										 |  |  |     if (ret != NULL)                                                           \ | 
					
						
							|  |  |  |         *ret = *in;                                                            \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  |     return ret;                                                                \ | 
					
						
							|  |  |  | }                                                                              \ | 
					
						
							| 
									
										
										
										
											2021-11-12 23:31:35 +08:00
										 |  |  | PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin)                                    \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags)                     \ | 
					
						
							| 
									
										
										
										
											2020-09-28 10:28:29 +08:00
										 |  |  | const OSSL_DISPATCH ossl_##name##_functions[] = {                              \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  |     { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx },                \ | 
					
						
							|  |  |  |     { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))upd },                          \ | 
					
						
							|  |  |  |     { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final },         \ | 
					
						
							|  |  |  |     { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx },              \ | 
					
						
							|  |  |  |     { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx },                \ | 
					
						
							|  |  |  |     PROV_DISPATCH_FUNC_DIGEST_GET_PARAMS(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END                               \
 | 
					
						
							|  |  |  |     { 0, NULL }                                                                \ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # define IMPLEMENT_digest_functions(                                           \
 | 
					
						
							|  |  |  |     name, CTX, blksize, dgstsize, flags, init, upd, fin)                       \ | 
					
						
							| 
									
										
										
										
											2021-03-02 20:42:41 +08:00
										 |  |  | static OSSL_FUNC_digest_init_fn name##_internal_init;                          \ | 
					
						
							|  |  |  | static int name##_internal_init(void *ctx,                                     \ | 
					
						
							|  |  |  |                                 ossl_unused const OSSL_PARAM params[])         \ | 
					
						
							|  |  |  | {                                                                              \ | 
					
						
							|  |  |  |     return ossl_prov_is_running() && init(ctx);                                \ | 
					
						
							|  |  |  | }                                                                              \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \ | 
					
						
							| 
									
										
										
										
											2021-03-02 20:42:41 +08:00
										 |  |  |                                           upd, fin),                           \ | 
					
						
							|  |  |  |     { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init },           \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # define IMPLEMENT_digest_functions_with_settable_ctx(                         \
 | 
					
						
							|  |  |  |     name, CTX, blksize, dgstsize, flags, init, upd, fin,                       \ | 
					
						
							|  |  |  |     settable_ctx_params, set_ctx_params)                                       \ | 
					
						
							| 
									
										
										
										
											2021-03-02 20:42:41 +08:00
										 |  |  | static OSSL_FUNC_digest_init_fn name##_internal_init;                          \ | 
					
						
							|  |  |  | static int name##_internal_init(void *ctx, const OSSL_PARAM params[])          \ | 
					
						
							|  |  |  | {                                                                              \ | 
					
						
							|  |  |  |     return ossl_prov_is_running()                                              \ | 
					
						
							|  |  |  |            && init(ctx)                                                        \ | 
					
						
							|  |  |  |            && set_ctx_params(ctx, params);                                     \ | 
					
						
							|  |  |  | }                                                                              \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \ | 
					
						
							| 
									
										
										
										
											2021-03-02 20:42:41 +08:00
										 |  |  |                                           upd, fin),                           \ | 
					
						
							|  |  |  |     { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init },           \ | 
					
						
							|  |  |  |     { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \ | 
					
						
							|  |  |  |     { OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params },       \ | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Fix external symbols in the provider digest implementations.
Partial fix for #12964
This adds ossl_ names for the following symbols:
blake2b512_init,blake2b_final,blake2b_init,blake2b_init_key,
blake2b_param_init,blake2b_param_set_digest_length,blake2b_param_set_key_length,
blake2b_param_set_personal,blake2b_param_set_salt,blake2b_update,
blake2s256_init,blake2s_final,blake2s_init,blake2s_init_key,
blake2s_param_init,blake2s_param_set_digest_length,blake2s_param_set_key_length,
blake2s_param_set_personal,blake2s_param_set_salt,blake2s_update,
digest_default_get_params,digest_default_gettable_params
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14211)
											
										 
											2021-02-17 17:56:35 +08:00
										 |  |  | const OSSL_PARAM *ossl_digest_default_gettable_params(void *provctx); | 
					
						
							|  |  |  | int ossl_digest_default_get_params(OSSL_PARAM params[], size_t blksz, | 
					
						
							|  |  |  |                                    size_t paramsz, unsigned long flags); | 
					
						
							| 
									
										
										
										
											2019-08-20 07:07:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | # endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:57 +08:00
										 |  |  | #endif /* OSSL_PROVIDERS_DIGESTCOMMON_H */
 |