1 /* SPDX-License-Identifier: MIT */
3 * Copyright (C) 2016 The Android Open Source Project
6 #ifdef AVB_INSIDE_LIBAVB_H
7 #error "You can't include avb_sha.h in the public header libavb.h."
10 #ifndef AVB_COMPILATION
11 #error "Never include this file, it may only be used from internal avb code."
21 #include "avb_crypto.h"
22 #include "avb_sysdeps.h"
24 /* Block size in bytes of a SHA-256 digest. */
25 #define AVB_SHA256_BLOCK_SIZE 64
27 /* Block size in bytes of a SHA-512 digest. */
28 #define AVB_SHA512_BLOCK_SIZE 128
30 /* Data structure used for SHA-256. */
35 uint8_t block[2 * AVB_SHA256_BLOCK_SIZE];
36 uint8_t buf[AVB_SHA256_DIGEST_SIZE]; /* Used for storing the final digest. */
39 /* Data structure used for SHA-512. */
44 uint8_t block[2 * AVB_SHA512_BLOCK_SIZE];
45 uint8_t buf[AVB_SHA512_DIGEST_SIZE]; /* Used for storing the final digest. */
48 /* Initializes the SHA-256 context. */
49 void avb_sha256_init(AvbSHA256Ctx* ctx);
51 /* Updates the SHA-256 context with |len| bytes from |data|. */
52 void avb_sha256_update(AvbSHA256Ctx* ctx, const uint8_t* data, size_t len);
54 /* Returns the SHA-256 digest. */
55 uint8_t* avb_sha256_final(AvbSHA256Ctx* ctx) AVB_ATTR_WARN_UNUSED_RESULT;
57 /* Initializes the SHA-512 context. */
58 void avb_sha512_init(AvbSHA512Ctx* ctx);
60 /* Updates the SHA-512 context with |len| bytes from |data|. */
61 void avb_sha512_update(AvbSHA512Ctx* ctx, const uint8_t* data, size_t len);
63 /* Returns the SHA-512 digest. */
64 uint8_t* avb_sha512_final(AvbSHA512Ctx* ctx) AVB_ATTR_WARN_UNUSED_RESULT;
70 #endif /* AVB_SHA_H_ */