summaryrefslogtreecommitdiff
path: root/src/fundamental
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-12-07 18:19:29 +0100
committerLennart Poettering <lennart@poettering.net>2022-12-08 15:30:41 +0100
commita0ccc18e89a9cb04b4177a0f5bbf3bb571397ca6 (patch)
tree66587e2b704426b045882e5fb12ab8514b2ae2a8 /src/fundamental
parent4f07388360a3513b9fc8d2773568b8def941f4a4 (diff)
downloadsystemd-a0ccc18e89a9cb04b4177a0f5bbf3bb571397ca6.tar.gz
sha256: port to new generic IS_ALIGNED32() macro
This drops the special casing for s390 and other archs, which was cargo-culted from glibc. Given it's not obvious why it exists, and is at best an optimization let's simply avoid it, in particular as the archs are relatively non-mainstream. Inspired by: #25636
Diffstat (limited to 'src/fundamental')
-rw-r--r--src/fundamental/sha256.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/fundamental/sha256.c b/src/fundamental/sha256.c
index fcbf531bd2..307f672507 100644
--- a/src/fundamental/sha256.c
+++ b/src/fundamental/sha256.c
@@ -49,14 +49,6 @@
# define SWAP64(n) (n)
#endif
-/* The condition below is from glibc's string/string-inline.c.
- * See definition of _STRING_INLINE_unaligned. */
-#if !defined(__mc68020__) && !defined(__s390__) && !defined(__i386__)
-# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__(uint32_t) != 0)
-#else
-# define UNALIGNED_P(p) false
-#endif
-
/* This array contains the bytes used to pad the buffer to the next
64-byte boundary. (FIPS 180-2:5.1.1) */
static const uint8_t fillbuf[64] = {
@@ -162,18 +154,17 @@ void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx
/* Process available complete blocks. */
if (len >= 64) {
- if (UNALIGNED_P(buffer))
+ if (IS_ALIGNED32(buffer)) {
+ sha256_process_block(buffer, len & ~63, ctx);
+ buffer = (const char *) buffer + (len & ~63);
+ len &= 63;
+ } else
while (len > 64) {
memcpy(ctx->buffer, buffer, 64);
sha256_process_block(ctx->buffer, 64, ctx);
buffer = (const char *) buffer + 64;
len -= 64;
}
- else {
- sha256_process_block(buffer, len & ~63, ctx);
- buffer = (const char *) buffer + (len & ~63);
- len &= 63;
- }
}
/* Move remaining bytes into internal buffer. */