diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-12-20 11:53:37 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-01-04 15:18:10 +0100 |
commit | a16c65f3c4c93e24eda9cf7f14d5da4062c6ca10 (patch) | |
tree | 9392786a0877654168fbd41171535e81e064e461 /src/fundamental/sha256.h | |
parent | 114172fbe75b247883dd873cafb9209e4a2bd778 (diff) | |
download | systemd-a16c65f3c4c93e24eda9cf7f14d5da4062c6ca10.tar.gz |
sha256: add helper than hashes a buffer *and* its size
We use this pattern all the time in order to thward extension attacks,
add a helper to make it shorter.
Diffstat (limited to 'src/fundamental/sha256.h')
-rw-r--r-- | src/fundamental/sha256.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/fundamental/sha256.h b/src/fundamental/sha256.h index 7c29c785cb..4805cc553a 100644 --- a/src/fundamental/sha256.h +++ b/src/fundamental/sha256.h @@ -28,6 +28,11 @@ void sha256_init_ctx(struct sha256_ctx *ctx); uint8_t *sha256_finish_ctx(struct sha256_ctx *ctx, uint8_t resbuf[static SHA256_DIGEST_SIZE]); void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx); +static inline void sha256_process_bytes_and_size(const void *buffer, size_t len, struct sha256_ctx *ctx) { + sha256_process_bytes(&len, sizeof(len), ctx); + sha256_process_bytes(buffer, len, ctx); +} + uint8_t* sha256_direct(const void *buffer, size_t sz, uint8_t result[static SHA256_DIGEST_SIZE]); #define SHA256_DIRECT(buffer, sz) sha256_direct(buffer, sz, (uint8_t[SHA256_DIGEST_SIZE]) {}) |