Get rid of the diversity of names for MAC parameters
[openssl.git] / providers / common / digests / digest_common.c
1 /*
2  * Copyright 2019 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 #include "openssl/err.h"
11 #include "internal/digestcommon.h"
12 #include "internal/providercommonerr.h"
13
14 int digest_default_get_params(OSSL_PARAM params[], int blksz, int paramsz,
15                               unsigned long flags)
16 {
17     OSSL_PARAM *p = NULL;
18
19     p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_BLOCK_SIZE);
20     if (p != NULL && !OSSL_PARAM_set_int(p, blksz)) {
21         ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
22         return 0;
23     }
24     p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE);
25     if (p != NULL && !OSSL_PARAM_set_int(p, paramsz)) {
26         ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
27         return 0;
28     }
29     p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_FLAGS);
30     if (p != NULL && !OSSL_PARAM_set_ulong(p, flags)) {
31         ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
32         return 0;
33     }
34     return 1;
35 }
36
37 static const OSSL_PARAM digest_default_known_gettable_params[] = {
38     { OSSL_DIGEST_PARAM_BLOCK_SIZE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0},
39     { OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0},
40     { OSSL_DIGEST_PARAM_FLAGS, OSSL_PARAM_INTEGER, NULL,
41       sizeof(unsigned long), 0},
42     OSSL_PARAM_END
43 };
44 const OSSL_PARAM *digest_default_gettable_params(void)
45 {
46     return digest_default_known_gettable_params;
47 }