mirror of https://github.com/openssl/openssl.git
				
				
				
			blake2: update to use generated param decoders
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> (Merged from https://github.com/openssl/openssl/pull/28151)
This commit is contained in:
		
							parent
							
								
									9edc474676
								
							
						
					
					
						commit
						1c5780ee52
					
				|  | @ -6,48 +6,56 @@ | ||||||
|  * in the file LICENSE in the source distribution or at |  * in the file LICENSE in the source distribution or at | ||||||
|  * https://www.openssl.org/source/license.html
 |  * https://www.openssl.org/source/license.html
 | ||||||
|  */ |  */ | ||||||
|  | {- | ||||||
|  | use OpenSSL::paramnames qw(produce_param_decoder); | ||||||
|  | -} | ||||||
| 
 | 
 | ||||||
|  | #include <string.h> | ||||||
| #include <openssl/crypto.h> | #include <openssl/crypto.h> | ||||||
| #include <openssl/core_names.h> | #include <openssl/core_names.h> | ||||||
| #include <openssl/proverr.h> | #include <openssl/proverr.h> | ||||||
| #include <openssl/err.h> | #include <openssl/err.h> | ||||||
|  | #include "internal/cryptlib.h" | ||||||
| #include "prov/blake2.h" | #include "prov/blake2.h" | ||||||
| #include "prov/digestcommon.h" | #include "prov/digestcommon.h" | ||||||
| #include "prov/implementations.h" | #include "prov/implementations.h" | ||||||
| 
 | 
 | ||||||
|  | static OSSL_FUNC_digest_gettable_ctx_params_fn blake_gettable_ctx_params; | ||||||
|  | static OSSL_FUNC_digest_settable_ctx_params_fn blake_settable_ctx_params; | ||||||
|  | 
 | ||||||
|  | {- produce_param_decoder('blake_get_ctx_params', | ||||||
|  |                          (['DIGEST_PARAM_SIZE',     'size',   'uint'], | ||||||
|  |                          )); -} | ||||||
|  | 
 | ||||||
|  | static const OSSL_PARAM *blake_gettable_ctx_params(ossl_unused void *ctx, | ||||||
|  |                                                    ossl_unused void *pctx) | ||||||
|  | { | ||||||
|  |     return blake_get_ctx_params_list; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | {- produce_param_decoder('blake_set_ctx_params', | ||||||
|  |                          (['DIGEST_PARAM_SIZE',     'size',   'uint'], | ||||||
|  |                          )); -} | ||||||
|  | 
 | ||||||
|  | static const OSSL_PARAM *blake_settable_ctx_params(ossl_unused void *ctx, | ||||||
|  |                                                    ossl_unused void *pctx) | ||||||
|  | { | ||||||
|  |     return blake_set_ctx_params_list; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #define IMPLEMENT_BLAKE_functions(variant, VARIANT, variantsize) \ | #define IMPLEMENT_BLAKE_functions(variant, VARIANT, variantsize) \ | ||||||
| static const OSSL_PARAM known_blake##variant##_ctx_params[] = { \ |  | ||||||
|     {OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0}, \ |  | ||||||
|     OSSL_PARAM_END \ |  | ||||||
| }; \ |  | ||||||
|  \ |  | ||||||
| const OSSL_PARAM *ossl_blake##variant##_gettable_ctx_params(ossl_unused void *ctx, \ |  | ||||||
|                                                    ossl_unused void *pctx) \ |  | ||||||
| { \ |  | ||||||
|     return known_blake##variant##_ctx_params; \ |  | ||||||
| } \ |  | ||||||
|  \ |  | ||||||
| const OSSL_PARAM *ossl_blake##variant##_settable_ctx_params(ossl_unused void *ctx, \ |  | ||||||
|                                                    ossl_unused void *pctx) \ |  | ||||||
| { \ |  | ||||||
|     return known_blake##variant##_ctx_params; \ |  | ||||||
| } \ |  | ||||||
|  \ |  | ||||||
| int ossl_blake##variant##_get_ctx_params(void *vctx, OSSL_PARAM params[]) \ | int ossl_blake##variant##_get_ctx_params(void *vctx, OSSL_PARAM params[]) \ | ||||||
| { \ | { \ | ||||||
|     struct blake##variant##_md_data_st *mdctx = vctx; \ |     struct blake##variant##_md_data_st *mdctx = vctx; \ | ||||||
|     OSSL_PARAM *p; \ |     struct blake_get_ctx_params_st p; \ | ||||||
|  \ |  \ | ||||||
|     BLAKE##VARIANT##_CTX *ctx = &mdctx->ctx; \ |     BLAKE##VARIANT##_CTX *ctx = &mdctx->ctx; \ | ||||||
|  \ |  \ | ||||||
|     if (ctx == NULL) \ |     if (ctx == NULL || !blake_get_ctx_params_decoder(params, &p)) \ | ||||||
|         return 0; \ |         return 0; \ | ||||||
|     if (ossl_param_is_empty(params)) \ |  | ||||||
|         return 1; \ |  | ||||||
|  \ |  \ | ||||||
|     p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE); \ |     if (p.size != NULL \ | ||||||
|     if (p != NULL \ |         && !OSSL_PARAM_set_uint(p.size, (unsigned int)mdctx->params.digest_length)) { \ | ||||||
|         && !OSSL_PARAM_set_uint(p, (unsigned int)mdctx->params.digest_length)) { \ |  | ||||||
|         ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); \ |         ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); \ | ||||||
|         return 0; \ |         return 0; \ | ||||||
|     } \ |     } \ | ||||||
|  | @ -57,20 +65,17 @@ int ossl_blake##variant##_get_ctx_params(void *vctx, OSSL_PARAM params[]) \ | ||||||
|  \ |  \ | ||||||
| int ossl_blake##variant##_set_ctx_params(void *vctx, const OSSL_PARAM params[]) \ | int ossl_blake##variant##_set_ctx_params(void *vctx, const OSSL_PARAM params[]) \ | ||||||
| { \ | { \ | ||||||
|     size_t size; \ |     unsigned int size; \ | ||||||
|     struct blake##variant##_md_data_st *mdctx = vctx; \ |     struct blake##variant##_md_data_st *mdctx = vctx; \ | ||||||
|     const OSSL_PARAM *p; \ |     struct blake_set_ctx_params_st p; \ | ||||||
|  \ |  \ | ||||||
|     BLAKE##VARIANT##_CTX *ctx = &mdctx->ctx; \ |     BLAKE##VARIANT##_CTX *ctx = &mdctx->ctx; \ | ||||||
|  \ |  \ | ||||||
|     if (ctx == NULL) \ |     if (ctx == NULL || !blake_set_ctx_params_decoder(params, &p)) \ | ||||||
|         return 0; \ |         return 0; \ | ||||||
|     if (ossl_param_is_empty(params)) \ |  | ||||||
|         return 1; \ |  | ||||||
|  \ |  \ | ||||||
|     p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SIZE); \ |     if (p.size != NULL) { \ | ||||||
|     if (p != NULL) { \ |         if (!OSSL_PARAM_get_uint(p.size, &size)) { \ | ||||||
|         if (!OSSL_PARAM_get_size_t(p, &size)) { \ |  | ||||||
|             ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); \ |             ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); \ | ||||||
|             return 0; \ |             return 0; \ | ||||||
|         } \ |         } \ | ||||||
|  | @ -184,9 +189,9 @@ const OSSL_DISPATCH ossl_blake##variantsize##_functions[] = { \ | ||||||
|      (void (*)(void))ossl_digest_default_gettable_params}, \ |      (void (*)(void))ossl_digest_default_gettable_params}, \ | ||||||
|     {OSSL_FUNC_DIGEST_INIT, (void (*)(void))blake##variantsize##_internal_init}, \ |     {OSSL_FUNC_DIGEST_INIT, (void (*)(void))blake##variantsize##_internal_init}, \ | ||||||
|     {OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS, \ |     {OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS, \ | ||||||
|      (void (*)(void))ossl_blake##variant##_gettable_ctx_params}, \ |      (void (*)(void))blake_gettable_ctx_params}, \ | ||||||
|     {OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, \ |     {OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, \ | ||||||
|      (void (*)(void))ossl_blake##variant##_settable_ctx_params}, \ |      (void (*)(void))blake_settable_ctx_params}, \ | ||||||
|     {OSSL_FUNC_DIGEST_GET_CTX_PARAMS, \ |     {OSSL_FUNC_DIGEST_GET_CTX_PARAMS, \ | ||||||
|      (void (*)(void))ossl_blake##variant##_get_ctx_params}, \ |      (void (*)(void))ossl_blake##variant##_get_ctx_params}, \ | ||||||
|     {OSSL_FUNC_DIGEST_SET_CTX_PARAMS, \ |     {OSSL_FUNC_DIGEST_SET_CTX_PARAMS, \ | ||||||
|  |  | ||||||
|  | @ -101,8 +101,6 @@ int ossl_blake2b_final(unsigned char *md, BLAKE2B_CTX *c); | ||||||
| 
 | 
 | ||||||
| OSSL_FUNC_digest_get_ctx_params_fn ossl_blake2b_get_ctx_params; | OSSL_FUNC_digest_get_ctx_params_fn ossl_blake2b_get_ctx_params; | ||||||
| OSSL_FUNC_digest_set_ctx_params_fn ossl_blake2b_set_ctx_params; | OSSL_FUNC_digest_set_ctx_params_fn ossl_blake2b_set_ctx_params; | ||||||
| OSSL_FUNC_digest_gettable_ctx_params_fn ossl_blake2b_gettable_ctx_params; |  | ||||||
| OSSL_FUNC_digest_settable_ctx_params_fn ossl_blake2b_settable_ctx_params; |  | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  * These setters are internal and do not check the validity of their parameters. |  * These setters are internal and do not check the validity of their parameters. | ||||||
|  | @ -132,7 +130,5 @@ void ossl_blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt, | ||||||
| 
 | 
 | ||||||
| OSSL_FUNC_digest_get_ctx_params_fn ossl_blake2s_get_ctx_params; | OSSL_FUNC_digest_get_ctx_params_fn ossl_blake2s_get_ctx_params; | ||||||
| OSSL_FUNC_digest_set_ctx_params_fn ossl_blake2s_set_ctx_params; | OSSL_FUNC_digest_set_ctx_params_fn ossl_blake2s_set_ctx_params; | ||||||
| OSSL_FUNC_digest_gettable_ctx_params_fn ossl_blake2s_gettable_ctx_params; |  | ||||||
| OSSL_FUNC_digest_settable_ctx_params_fn ossl_blake2s_settable_ctx_params; |  | ||||||
| 
 | 
 | ||||||
| #endif /* OSSL_PROV_BLAKE2_H */ | #endif /* OSSL_PROV_BLAKE2_H */ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue