xref: /netbsd-src/crypto/external/bsd/openssl/dist/providers/implementations/digests/mdc2_prov.c (revision b0d1725196a7921d003d2c66a14f186abda4176b)
1*b0d17251Schristos /*
2*b0d17251Schristos  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3*b0d17251Schristos  *
4*b0d17251Schristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*b0d17251Schristos  * this file except in compliance with the License.  You can obtain a copy
6*b0d17251Schristos  * in the file LICENSE in the source distribution or at
7*b0d17251Schristos  * https://www.openssl.org/source/license.html
8*b0d17251Schristos  */
9*b0d17251Schristos 
10*b0d17251Schristos /*
11*b0d17251Schristos  * MDC2 low level APIs are deprecated for public use, but still ok for
12*b0d17251Schristos  * internal use.
13*b0d17251Schristos  */
14*b0d17251Schristos #include "internal/deprecated.h"
15*b0d17251Schristos 
16*b0d17251Schristos #include <openssl/crypto.h>
17*b0d17251Schristos #include <openssl/params.h>
18*b0d17251Schristos #include <openssl/mdc2.h>
19*b0d17251Schristos #include <openssl/core_names.h>
20*b0d17251Schristos #include <openssl/err.h>
21*b0d17251Schristos #include <openssl/proverr.h>
22*b0d17251Schristos #include "prov/digestcommon.h"
23*b0d17251Schristos #include "prov/implementations.h"
24*b0d17251Schristos 
25*b0d17251Schristos static OSSL_FUNC_digest_set_ctx_params_fn mdc2_set_ctx_params;
26*b0d17251Schristos static OSSL_FUNC_digest_settable_ctx_params_fn mdc2_settable_ctx_params;
27*b0d17251Schristos 
28*b0d17251Schristos static const OSSL_PARAM known_mdc2_settable_ctx_params[] = {
29*b0d17251Schristos     OSSL_PARAM_uint(OSSL_DIGEST_PARAM_PAD_TYPE, NULL),
30*b0d17251Schristos     OSSL_PARAM_END
31*b0d17251Schristos };
32*b0d17251Schristos 
mdc2_settable_ctx_params(ossl_unused void * ctx,ossl_unused void * provctx)33*b0d17251Schristos static const OSSL_PARAM *mdc2_settable_ctx_params(ossl_unused void *ctx,
34*b0d17251Schristos                                                   ossl_unused void *provctx)
35*b0d17251Schristos {
36*b0d17251Schristos     return known_mdc2_settable_ctx_params;
37*b0d17251Schristos }
38*b0d17251Schristos 
mdc2_set_ctx_params(void * vctx,const OSSL_PARAM params[])39*b0d17251Schristos static int mdc2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
40*b0d17251Schristos {
41*b0d17251Schristos     const OSSL_PARAM *p;
42*b0d17251Schristos     MDC2_CTX *ctx = (MDC2_CTX *)vctx;
43*b0d17251Schristos 
44*b0d17251Schristos     if (ctx == NULL)
45*b0d17251Schristos         return 0;
46*b0d17251Schristos     if (params == NULL)
47*b0d17251Schristos         return 1;
48*b0d17251Schristos 
49*b0d17251Schristos     p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_PAD_TYPE);
50*b0d17251Schristos     if (p != NULL && !OSSL_PARAM_get_uint(p, &ctx->pad_type)) {
51*b0d17251Schristos         ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
52*b0d17251Schristos         return 0;
53*b0d17251Schristos     }
54*b0d17251Schristos     return 1;
55*b0d17251Schristos }
56*b0d17251Schristos 
57*b0d17251Schristos /* ossl_mdc2_functions */
58*b0d17251Schristos IMPLEMENT_digest_functions_with_settable_ctx(
59*b0d17251Schristos     mdc2, MDC2_CTX, MDC2_BLOCK, MDC2_DIGEST_LENGTH, 0,
60*b0d17251Schristos     MDC2_Init, MDC2_Update, MDC2_Final,
61*b0d17251Schristos     mdc2_settable_ctx_params, mdc2_set_ctx_params)
62