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