From patchwork Mon Feb 13 13:55:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 64891 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 254B03887F60 for ; Mon, 13 Feb 2023 13:57:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 254B03887F60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676296638; bh=xQ+vGF12wv5GTU13ypjjo3+Fm3vsWH4OxazGFdIyshc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=CF4ySp6o5uAuT4+bZrvptY8B3ZvKaIO962LgnA57IZm97x36oVmaLcikA+PQkOokV 9MS4wdu70PgVfEKEANfPcDk6DLbblcKOCOW4uCJhxhpR0KpEovKt7RFMJgIcrj0j/4 vhp2u14HGqkhssU62wj0bn71OnmB+oC6mEOvTAjw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by sourceware.org (Postfix) with ESMTPS id C9265383FB93 for ; Mon, 13 Feb 2023 13:56:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9265383FB93 Received: by mail-oo1-xc32.google.com with SMTP id z138-20020a4a4990000000b005175b8ae66cso1186821ooa.6 for ; Mon, 13 Feb 2023 05:56:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xQ+vGF12wv5GTU13ypjjo3+Fm3vsWH4OxazGFdIyshc=; b=HKd7nOjuaCIZz1nLbA+VHEgF7MAlT8SK9kzJSyFW0smj7rc80jjVcsX5weznq+SYjL Vpq4jKxYAIUs8GVgN1FZUYTsp8GEN768EZMbw3Yweq+/nqovFEc1iHiBo4Ix2Xa0TODN hvrkytIqjyCyMnLSvktiBd9qZGz3LGajI6qU89INtFEJGae5vJh8p7Dc6waZpFvArJrg 6AUO0ZJnGarAsbR6gQecnA8XGAw1jwhmDtfPYi6jOBoGwR4tjW0Tm0anIA72fnXoKsWT aXZZnluTO4llCjRIqGYvfo7uFzFADlkLDL18+buTewb+dIwMPZ1guZeuhBw+VQEt6jsT iIow== X-Gm-Message-State: AO0yUKW1tJgr8hvaukAjiYy9pcUUPyl9he+9gae9ce7pI/LjVwnkor5k zHcVbUasi4nl5eU312UbFCJH3WSxTwMb1d/pmGw= X-Google-Smtp-Source: AK7set/n/HSJNFhJ/GHOvGEb9GI37fBWvKA5JqxkwFFzYggkAnxxWx3+l4RB8/EAuaEbj8Cdv3q/2Q== X-Received: by 2002:a4a:6342:0:b0:517:752d:678a with SMTP id r2-20020a4a6342000000b00517752d678amr10558360oof.1.1676296564561; Mon, 13 Feb 2023 05:56:04 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:f662:138b:cd0c:7b7a:8860]) by smtp.gmail.com with ESMTPSA id y11-20020a4ade0b000000b0051762a73553sm4797168oot.18.2023.02.13.05.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 05:56:04 -0800 (PST) To: libc-alpha@sourceware.org, Wilco Dijkstra Subject: [PATCH 1/7] crypto: Remove _STRING_ARCH_unaligned usage Date: Mon, 13 Feb 2023 10:55:52 -0300 Message-Id: <20230213135558.3328727-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213135558.3328727-1-adhemerval.zanella@linaro.org> References: <20230213135558.3328727-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Assume unaligned inputs on all cases. The code is built and used only in compat mode. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Wilco Dijkstra --- crypt/md5.c | 24 ++++-------------------- crypt/sha256.c | 28 ++++------------------------ crypt/sha512.c | 26 +++++--------------------- 3 files changed, 13 insertions(+), 65 deletions(-) diff --git a/crypt/md5.c b/crypt/md5.c index c7a232ad38..03240a9a36 100644 --- a/crypt/md5.c +++ b/crypt/md5.c @@ -229,27 +229,11 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) /* Process available complete blocks. */ if (len >= 64) { -#if !_STRING_ARCH_unaligned -/* To check alignment gcc has an appropriate operator. Other - compilers don't. */ -# if __GNUC__ >= 2 -# define UNALIGNED_P(p) (((md5_uintptr) p) % __alignof__ (md5_uint32) != 0) -# else -# define UNALIGNED_P(p) (((md5_uintptr) p) % sizeof (md5_uint32) != 0) -# endif - if (UNALIGNED_P (buffer)) - while (len > 64) - { - __md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); - buffer = (const char *) buffer + 64; - len -= 64; - } - else -#endif + while (len > 64) { - __md5_process_block (buffer, len & ~63, ctx); - buffer = (const char *) buffer + (len & ~63); - len &= 63; + __md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); + buffer = (const char *) buffer + 64; + len -= 64; } } diff --git a/crypt/sha256.c b/crypt/sha256.c index 93b73997c7..96153d67dc 100644 --- a/crypt/sha256.c +++ b/crypt/sha256.c @@ -120,13 +120,9 @@ __sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf) memcpy (&ctx->buffer[bytes], fillbuf, pad); /* Put the 64-bit file length in *bits* at the end of the buffer. */ -#if _STRING_ARCH_unaligned - ctx->buffer64[(bytes + pad) / 8] = SWAP64 (ctx->total64 << 3); -#else ctx->buffer32[(bytes + pad + 4) / 4] = SWAP (ctx->total[TOTAL64_low] << 3); ctx->buffer32[(bytes + pad) / 4] = SWAP ((ctx->total[TOTAL64_high] << 3) | (ctx->total[TOTAL64_low] >> 29)); -#endif /* Process last bytes. */ __sha256_process_block (ctx->buffer, bytes + pad + 8, ctx); @@ -169,27 +165,11 @@ __sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx) /* Process available complete blocks. */ if (len >= 64) { -#if !_STRING_ARCH_unaligned -/* To check alignment gcc has an appropriate operator. Other - compilers don't. */ -# if __GNUC__ >= 2 -# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0) -# else -# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0) -# endif - if (UNALIGNED_P (buffer)) - while (len > 64) - { - __sha256_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); - buffer = (const char *) buffer + 64; - len -= 64; - } - else -#endif + while (len > 64) { - __sha256_process_block (buffer, len & ~63, ctx); - buffer = (const char *) buffer + (len & ~63); - len &= 63; + __sha256_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); + buffer = (const char *) buffer + 64; + len -= 64; } } diff --git a/crypt/sha512.c b/crypt/sha512.c index d7e51b3604..ceabad1bf7 100644 --- a/crypt/sha512.c +++ b/crypt/sha512.c @@ -192,28 +192,12 @@ __sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx) /* Process available complete blocks. */ if (len >= 128) { -#if !_STRING_ARCH_unaligned -/* To check alignment gcc has an appropriate operator. Other - compilers don't. */ -# if __GNUC__ >= 2 -# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0) -# else -# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint64_t) != 0) -# endif - if (UNALIGNED_P (buffer)) - while (len > 128) - { - __sha512_process_block (memcpy (ctx->buffer, buffer, 128), 128, - ctx); - buffer = (const char *) buffer + 128; - len -= 128; - } - else -#endif + while (len > 128) { - __sha512_process_block (buffer, len & ~127, ctx); - buffer = (const char *) buffer + (len & ~127); - len &= 127; + __sha512_process_block (memcpy (ctx->buffer, buffer, 128), 128, + ctx); + buffer = (const char *) buffer + 128; + len -= 128; } }