summaryrefslogtreecommitdiff
path: root/src/fundamental
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-08-17 11:32:38 +0200
committerLennart Poettering <lennart@poettering.net>2022-08-19 12:53:04 +0200
commit558d96240bea7d910144fa2cad1fe2f8061ffa74 (patch)
tree38cf1c02d55236dfa3865d570818c9882671ad66 /src/fundamental
parent00b4663813829ad3391d03383b82eee5d439de70 (diff)
downloadsystemd-558d96240bea7d910144fa2cad1fe2f8061ffa74.tar.gz
sha256: add sha256_direct()/SHA256_DIRECT() helpers
Diffstat (limited to 'src/fundamental')
-rw-r--r--src/fundamental/sha256.c7
-rw-r--r--src/fundamental/sha256.h4
2 files changed, 11 insertions, 0 deletions
diff --git a/src/fundamental/sha256.c b/src/fundamental/sha256.c
index 7ead5f169c..43ee996b6f 100644
--- a/src/fundamental/sha256.c
+++ b/src/fundamental/sha256.c
@@ -289,3 +289,10 @@ static void sha256_process_block(const void *buffer, size_t len, struct sha256_c
ctx->H[6] = g;
ctx->H[7] = h;
}
+
+uint8_t* sha256_direct(const void *buffer, size_t sz, uint8_t result[static SHA256_DIGEST_SIZE]) {
+ struct sha256_ctx ctx;
+ sha256_init_ctx(&ctx);
+ sha256_process_bytes(buffer, sz, &ctx);
+ return sha256_finish_ctx(&ctx, result);
+}
diff --git a/src/fundamental/sha256.h b/src/fundamental/sha256.h
index 337e746c49..31790c2ebd 100644
--- a/src/fundamental/sha256.h
+++ b/src/fundamental/sha256.h
@@ -27,3 +27,7 @@ struct sha256_ctx {
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);
+
+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]) {})