1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#include <openssl/err.h> 11e1051a39Sopenharmony_ci#include <openssl/proverr.h> 12e1051a39Sopenharmony_ci#include "prov/digestcommon.h" 13e1051a39Sopenharmony_ci 14e1051a39Sopenharmony_ciint ossl_digest_default_get_params(OSSL_PARAM params[], size_t blksz, 15e1051a39Sopenharmony_ci size_t paramsz, unsigned long flags) 16e1051a39Sopenharmony_ci{ 17e1051a39Sopenharmony_ci OSSL_PARAM *p = NULL; 18e1051a39Sopenharmony_ci 19e1051a39Sopenharmony_ci p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_BLOCK_SIZE); 20e1051a39Sopenharmony_ci if (p != NULL && !OSSL_PARAM_set_size_t(p, blksz)) { 21e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); 22e1051a39Sopenharmony_ci return 0; 23e1051a39Sopenharmony_ci } 24e1051a39Sopenharmony_ci p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE); 25e1051a39Sopenharmony_ci if (p != NULL && !OSSL_PARAM_set_size_t(p, paramsz)) { 26e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); 27e1051a39Sopenharmony_ci return 0; 28e1051a39Sopenharmony_ci } 29e1051a39Sopenharmony_ci p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_XOF); 30e1051a39Sopenharmony_ci if (p != NULL 31e1051a39Sopenharmony_ci && !OSSL_PARAM_set_int(p, (flags & PROV_DIGEST_FLAG_XOF) != 0)) { 32e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); 33e1051a39Sopenharmony_ci return 0; 34e1051a39Sopenharmony_ci } 35e1051a39Sopenharmony_ci p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_ALGID_ABSENT); 36e1051a39Sopenharmony_ci if (p != NULL 37e1051a39Sopenharmony_ci && !OSSL_PARAM_set_int(p, (flags & PROV_DIGEST_FLAG_ALGID_ABSENT) != 0)) { 38e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); 39e1051a39Sopenharmony_ci return 0; 40e1051a39Sopenharmony_ci } 41e1051a39Sopenharmony_ci return 1; 42e1051a39Sopenharmony_ci} 43e1051a39Sopenharmony_ci 44e1051a39Sopenharmony_cistatic const OSSL_PARAM digest_default_known_gettable_params[] = { 45e1051a39Sopenharmony_ci OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_BLOCK_SIZE, NULL), 46e1051a39Sopenharmony_ci OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_SIZE, NULL), 47e1051a39Sopenharmony_ci OSSL_PARAM_int(OSSL_DIGEST_PARAM_XOF, NULL), 48e1051a39Sopenharmony_ci OSSL_PARAM_int(OSSL_DIGEST_PARAM_ALGID_ABSENT, NULL), 49e1051a39Sopenharmony_ci OSSL_PARAM_END 50e1051a39Sopenharmony_ci}; 51e1051a39Sopenharmony_ciconst OSSL_PARAM *ossl_digest_default_gettable_params(void *provctx) 52e1051a39Sopenharmony_ci{ 53e1051a39Sopenharmony_ci return digest_default_known_gettable_params; 54e1051a39Sopenharmony_ci} 55