summaryrefslogtreecommitdiff
path: root/src/fundamental/sha256.h
blob: e53197f2ef9b1c71da16483946a65d71136ce8f6 (plain)
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
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once

#ifdef SD_BOOT
#include <efi.h>
#include <efilib.h>
#endif

#include "types-fundamental.h"

#define SHA256_DIGEST_SIZE 32

struct sha256_ctx {
        uint32_t H[8];

        union {
                uint64_t total64;
#define TOTAL64_low (1 - (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
#define TOTAL64_high (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
                uint32_t total[2];
        };

        uint32_t buflen;

        union {
                uint8_t  buffer[128]; /* NB: always correctly aligned for UINT32.  */
                uint32_t buffer32[32];
                uint64_t buffer64[16];
        };
};

void sha256_init_ctx(struct sha256_ctx *ctx);
void *sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf);
void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx);