1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#include <openssl/crypto.h>
11e1051a39Sopenharmony_ci#include "prov/digestcommon.h"
12e1051a39Sopenharmony_ci#include "prov/implementations.h"
13e1051a39Sopenharmony_ci
14e1051a39Sopenharmony_citypedef struct {
15e1051a39Sopenharmony_ci    unsigned char nothing;
16e1051a39Sopenharmony_ci} NULLMD_CTX;
17e1051a39Sopenharmony_ci
18e1051a39Sopenharmony_cistatic int null_init(NULLMD_CTX *ctx)
19e1051a39Sopenharmony_ci{
20e1051a39Sopenharmony_ci    return 1;
21e1051a39Sopenharmony_ci}
22e1051a39Sopenharmony_ci
23e1051a39Sopenharmony_cistatic int null_update(NULLMD_CTX *ctx, const void *data, size_t datalen)
24e1051a39Sopenharmony_ci{
25e1051a39Sopenharmony_ci    return 1;
26e1051a39Sopenharmony_ci}
27e1051a39Sopenharmony_ci
28e1051a39Sopenharmony_cistatic int null_final(unsigned char *md, NULLMD_CTX *ctx)
29e1051a39Sopenharmony_ci{
30e1051a39Sopenharmony_ci    return 1;
31e1051a39Sopenharmony_ci}
32e1051a39Sopenharmony_ci
33e1051a39Sopenharmony_ci/*
34e1051a39Sopenharmony_ci * We must override the PROV_FUNC_DIGEST_FINAL as dgstsize == 0
35e1051a39Sopenharmony_ci * and that would cause compilation warnings with the default implementation.
36e1051a39Sopenharmony_ci */
37e1051a39Sopenharmony_ci#undef PROV_FUNC_DIGEST_FINAL
38e1051a39Sopenharmony_ci#define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin)                            \
39e1051a39Sopenharmony_cistatic OSSL_FUNC_digest_final_fn name##_internal_final;                        \
40e1051a39Sopenharmony_cistatic int name##_internal_final(void *ctx, unsigned char *out, size_t *outl,  \
41e1051a39Sopenharmony_ci                                 size_t outsz)                                 \
42e1051a39Sopenharmony_ci{                                                                              \
43e1051a39Sopenharmony_ci    if (ossl_prov_is_running() && fin(out, ctx)) {                             \
44e1051a39Sopenharmony_ci        *outl = dgstsize;                                                      \
45e1051a39Sopenharmony_ci        return 1;                                                              \
46e1051a39Sopenharmony_ci    }                                                                          \
47e1051a39Sopenharmony_ci    return 0;                                                                  \
48e1051a39Sopenharmony_ci}
49e1051a39Sopenharmony_ci
50e1051a39Sopenharmony_ciIMPLEMENT_digest_functions(nullmd, NULLMD_CTX,
51e1051a39Sopenharmony_ci                           0, 0, 0,
52e1051a39Sopenharmony_ci                           null_init, null_update, null_final)
53