]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sha256: change digest buffer type to uint8_t[]
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Aug 2022 09:24:24 +0000 (11:24 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 19 Aug 2022 10:53:04 +0000 (12:53 +0200)
This way we can specify a size with "static". All users use uint8_t
already, hence this comes at no price.

src/fundamental/sha256.c
src/fundamental/sha256.h

index 31d9674d09e5778c8e577b11874d0b53da941111..7ead5f169c50745d6bd94652b62073ef32ead5ba 100644 (file)
@@ -104,7 +104,7 @@ void sha256_init_ctx(struct sha256_ctx *ctx) {
 
 /* Process the remaining bytes in the internal buffer and the usual
    prolog according to the standard and write the result to RESBUF. */
-void *sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) {
+uint8_t *sha256_finish_ctx(struct sha256_ctx *ctx, uint8_t resbuf[static SHA256_DIGEST_SIZE]) {
         /* Take yet unprocessed bytes into account.  */
         uint32_t bytes = ctx->buflen;
         size_t pad;
@@ -129,7 +129,7 @@ void *sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) {
         /* Put result from CTX in first 32 bytes following RESBUF.  */
         for (size_t i = 0; i < 8; ++i)
                 if (UNALIGNED_P(resbuf))
-                        memcpy((uint8_t*) resbuf + i * sizeof(uint32_t), (uint32_t[]) { SWAP(ctx->H[i]) }, sizeof(uint32_t));
+                        memcpy(resbuf + i * sizeof(uint32_t), (uint32_t[]) { SWAP(ctx->H[i]) }, sizeof(uint32_t));
                 else
                         ((uint32_t *) resbuf)[i] = SWAP(ctx->H[i]);
 
index f296f76ae8e05bf8add8b3ec33e53a082043f248..337e746c49802ccd822a7d879a1926d84a901108 100644 (file)
@@ -25,5 +25,5 @@ struct sha256_ctx {
 };
 
 void sha256_init_ctx(struct sha256_ctx *ctx);
-void *sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf);
+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);