1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 #pragma once 3 4 #ifdef SD_BOOT 5 #include <efi.h> 6 #include <efilib.h> 7 #endif 8 9 #include "types-fundamental.h" 10 11 #define SHA256_DIGEST_SIZE 32 12 13 struct sha256_ctx { 14 uint32_t H[8]; 15 16 union { 17 uint64_t total64; 18 #define TOTAL64_low (1 - (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) 19 #define TOTAL64_high (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 20 uint32_t total[2]; 21 }; 22 23 uint32_t buflen; 24 25 union { 26 uint8_t buffer[128]; /* NB: always correctly aligned for UINT32. */ 27 uint32_t buffer32[32]; 28 uint64_t buffer64[16]; 29 }; 30 }; 31 32 void sha256_init_ctx(struct sha256_ctx *ctx); 33 void *sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf); 34 void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx); 35