xref: /freebsd/crypto/openssl/providers/implementations/digests/mdc2_prov.c (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
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 /*
11*b077aed3SPierre Pronchery  * MDC2 low level APIs are deprecated for public use, but still ok for
12*b077aed3SPierre Pronchery  * internal use.
13*b077aed3SPierre Pronchery  */
14*b077aed3SPierre Pronchery #include "internal/deprecated.h"
15*b077aed3SPierre Pronchery 
16*b077aed3SPierre Pronchery #include <openssl/crypto.h>
17*b077aed3SPierre Pronchery #include <openssl/params.h>
18*b077aed3SPierre Pronchery #include <openssl/mdc2.h>
19*b077aed3SPierre Pronchery #include <openssl/core_names.h>
20*b077aed3SPierre Pronchery #include <openssl/err.h>
21*b077aed3SPierre Pronchery #include <openssl/proverr.h>
22*b077aed3SPierre Pronchery #include "prov/digestcommon.h"
23*b077aed3SPierre Pronchery #include "prov/implementations.h"
24*b077aed3SPierre Pronchery 
25*b077aed3SPierre Pronchery static OSSL_FUNC_digest_set_ctx_params_fn mdc2_set_ctx_params;
26*b077aed3SPierre Pronchery static OSSL_FUNC_digest_settable_ctx_params_fn mdc2_settable_ctx_params;
27*b077aed3SPierre Pronchery 
28*b077aed3SPierre Pronchery static const OSSL_PARAM known_mdc2_settable_ctx_params[] = {
29*b077aed3SPierre Pronchery     OSSL_PARAM_uint(OSSL_DIGEST_PARAM_PAD_TYPE, NULL),
30*b077aed3SPierre Pronchery     OSSL_PARAM_END
31*b077aed3SPierre Pronchery };
32*b077aed3SPierre Pronchery 
mdc2_settable_ctx_params(ossl_unused void * ctx,ossl_unused void * provctx)33*b077aed3SPierre Pronchery static const OSSL_PARAM *mdc2_settable_ctx_params(ossl_unused void *ctx,
34*b077aed3SPierre Pronchery                                                   ossl_unused void *provctx)
35*b077aed3SPierre Pronchery {
36*b077aed3SPierre Pronchery     return known_mdc2_settable_ctx_params;
37*b077aed3SPierre Pronchery }
38*b077aed3SPierre Pronchery 
mdc2_set_ctx_params(void * vctx,const OSSL_PARAM params[])39*b077aed3SPierre Pronchery static int mdc2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
40*b077aed3SPierre Pronchery {
41*b077aed3SPierre Pronchery     const OSSL_PARAM *p;
42*b077aed3SPierre Pronchery     MDC2_CTX *ctx = (MDC2_CTX *)vctx;
43*b077aed3SPierre Pronchery 
44*b077aed3SPierre Pronchery     if (ctx == NULL)
45*b077aed3SPierre Pronchery         return 0;
46*b077aed3SPierre Pronchery     if (params == NULL)
47*b077aed3SPierre Pronchery         return 1;
48*b077aed3SPierre Pronchery 
49*b077aed3SPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_PAD_TYPE);
50*b077aed3SPierre Pronchery     if (p != NULL && !OSSL_PARAM_get_uint(p, &ctx->pad_type)) {
51*b077aed3SPierre Pronchery         ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
52*b077aed3SPierre Pronchery         return 0;
53*b077aed3SPierre Pronchery     }
54*b077aed3SPierre Pronchery     return 1;
55*b077aed3SPierre Pronchery }
56*b077aed3SPierre Pronchery 
57*b077aed3SPierre Pronchery /* ossl_mdc2_functions */
58*b077aed3SPierre Pronchery IMPLEMENT_digest_functions_with_settable_ctx(
59*b077aed3SPierre Pronchery     mdc2, MDC2_CTX, MDC2_BLOCK, MDC2_DIGEST_LENGTH, 0,
60*b077aed3SPierre Pronchery     MDC2_Init, MDC2_Update, MDC2_Final,
61*b077aed3SPierre Pronchery     mdc2_settable_ctx_params, mdc2_set_ctx_params)
62