File: null_prov.c

package info (click to toggle)
openssl 3.0.17-1~deb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 66,480 kB
  • sloc: ansic: 473,090; perl: 192,620; asm: 6,546; sh: 1,185; makefile: 231; pascal: 43; lisp: 35; python: 29; ruby: 14; cpp: 10; sed: 6
file content (52 lines) | stat: -rw-r--r-- 1,850 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include <openssl/crypto.h>
#include "prov/digestcommon.h"
#include "prov/implementations.h"

typedef struct {
    unsigned char nothing;
} NULLMD_CTX;

static int null_init(NULLMD_CTX *ctx)
{
    return 1;
}

static int null_update(NULLMD_CTX *ctx, const void *data, size_t datalen)
{
    return 1;
}

static int null_final(unsigned char *md, NULLMD_CTX *ctx)
{
    return 1;
}

/*
 * We must override the PROV_FUNC_DIGEST_FINAL as dgstsize == 0
 * and that would cause compilation warnings with the default implementation.
 */
#undef PROV_FUNC_DIGEST_FINAL
#define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin)                            \
static OSSL_FUNC_digest_final_fn name##_internal_final;                        \
static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl,  \
                                 size_t outsz)                                 \
{                                                                              \
    if (ossl_prov_is_running() && fin(out, ctx)) {                             \
        *outl = dgstsize;                                                      \
        return 1;                                                              \
    }                                                                          \
    return 0;                                                                  \
}

IMPLEMENT_digest_functions(nullmd, NULLMD_CTX,
                           0, 0, 0,
                           null_init, null_update, null_final)