1*b077aed3SPierre Pronchery /*
2*b077aed3SPierre Pronchery * Copyright 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/crypto.h>
11*b077aed3SPierre Pronchery #include "prov/digestcommon.h"
12*b077aed3SPierre Pronchery #include "prov/implementations.h"
13*b077aed3SPierre Pronchery
14*b077aed3SPierre Pronchery typedef struct {
15*b077aed3SPierre Pronchery unsigned char nothing;
16*b077aed3SPierre Pronchery } NULLMD_CTX;
17*b077aed3SPierre Pronchery
null_init(NULLMD_CTX * ctx)18*b077aed3SPierre Pronchery static int null_init(NULLMD_CTX *ctx)
19*b077aed3SPierre Pronchery {
20*b077aed3SPierre Pronchery return 1;
21*b077aed3SPierre Pronchery }
22*b077aed3SPierre Pronchery
null_update(NULLMD_CTX * ctx,const void * data,size_t datalen)23*b077aed3SPierre Pronchery static int null_update(NULLMD_CTX *ctx, const void *data, size_t datalen)
24*b077aed3SPierre Pronchery {
25*b077aed3SPierre Pronchery return 1;
26*b077aed3SPierre Pronchery }
27*b077aed3SPierre Pronchery
null_final(unsigned char * md,NULLMD_CTX * ctx)28*b077aed3SPierre Pronchery static int null_final(unsigned char *md, NULLMD_CTX *ctx)
29*b077aed3SPierre Pronchery {
30*b077aed3SPierre Pronchery return 1;
31*b077aed3SPierre Pronchery }
32*b077aed3SPierre Pronchery
33*b077aed3SPierre Pronchery /*
34*b077aed3SPierre Pronchery * We must override the PROV_FUNC_DIGEST_FINAL as dgstsize == 0
35*b077aed3SPierre Pronchery * and that would cause compilation warnings with the default implementation.
36*b077aed3SPierre Pronchery */
37*b077aed3SPierre Pronchery #undef PROV_FUNC_DIGEST_FINAL
38*b077aed3SPierre Pronchery #define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin) \
39*b077aed3SPierre Pronchery static OSSL_FUNC_digest_final_fn name##_internal_final; \
40*b077aed3SPierre Pronchery static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \
41*b077aed3SPierre Pronchery size_t outsz) \
42*b077aed3SPierre Pronchery { \
43*b077aed3SPierre Pronchery if (ossl_prov_is_running() && fin(out, ctx)) { \
44*b077aed3SPierre Pronchery *outl = dgstsize; \
45*b077aed3SPierre Pronchery return 1; \
46*b077aed3SPierre Pronchery } \
47*b077aed3SPierre Pronchery return 0; \
48*b077aed3SPierre Pronchery }
49*b077aed3SPierre Pronchery
50*b077aed3SPierre Pronchery IMPLEMENT_digest_functions(nullmd, NULLMD_CTX,
51*b077aed3SPierre Pronchery 0, 0, 0,
52*b077aed3SPierre Pronchery null_init, null_update, null_final)
53