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