From patchwork Wed Feb 2 19:12:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 539341 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1840951imr; Wed, 2 Feb 2022 11:57:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRHxevRNSpRHH4TQoWO2TMbTIaNbkbpzZsPR0768yMvDImIp3Gkpwy+1TH9MkLWoEZvemy X-Received: by 2002:a25:dd06:: with SMTP id u6mr42283367ybg.357.1643831874503; Wed, 02 Feb 2022 11:57:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643831874; cv=none; d=google.com; s=arc-20160816; b=cP1d7dbUG6E/WxpgL1dMTAj5utF/OJQMmAwuwts5CsDr+HYpUnTcYhKXPA7oebJha7 oBNlBmJTkSRT0/TEunyMM0Ur1EvuOFzr+W1IZjQkmMmeJ1T87W+WpQt4TR+DBTaSn3Og 0Tzc3YmWVzEvQCoJLejUGhJZxrcRlnz93k3ureop8hTjhVKDxjZteRl2T4myRZQtPop1 uNc2CZUOPBDMPq8ZkynIMW6ucDhJrZxCs6HzV8/UBP7ObTVt8jBwpi+J8KY8jtStpbPC ZeGQoMrtOuT3cWnFnpEZsmGTg8Q79+kK51NazAnDH456/BpBBJ2EgkTBHX1ef7H/Jgxh uMPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=cVqzLTk554WZOO+XZFbwn8o1c5aR1NKLbErrI/M/iPM=; b=ISI4Xb8X/4ChTZ3VoUwg9uNWb16wO8GmLTinXLPVwqEm+VmfIWUA3nD5lMHi8O5Uqt TQqTJsuWiY5wXtA5y+rDu4h3FUyNr2AtU9SjiZWrEKmaERuLg80LZXsyztwPig2qvxC/ I/yfYLOZOu+eJJvHfaFAdbaCzbhPC6hLBMHQGV2CBJUpLuA1UbkBZSEYKbEKKH6RRzKx 8RE+G+IGMW6C95uzmCKT3brvYXat9vGIUWpjjyg4l7avukhkbrceB8EsStLngka8q/Pl gXTpYxfjLBCXdaq7aB07FdogBqRzLzRcpDtncjT0TBiKgx96l1OvxSFpWgt26MOzXyC/ pp0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=x1aKfjia; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p79si20559840yba.704.2022.02.02.11.57.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Feb 2022 11:57:54 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=x1aKfjia; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFLlJ-0004Ps-Vc for patch@linaro.org; Wed, 02 Feb 2022 14:57:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFL3f-0000p3-He for qemu-devel@nongnu.org; Wed, 02 Feb 2022 14:12:48 -0500 Received: from [2a00:1450:4864:20::329] (port=35715 helo=mail-wm1-x329.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nFL3d-00076B-P6 for qemu-devel@nongnu.org; Wed, 02 Feb 2022 14:12:47 -0500 Received: by mail-wm1-x329.google.com with SMTP id f80-20020a1c1f53000000b0035399b8bedcso5089813wmf.0 for ; Wed, 02 Feb 2022 11:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cVqzLTk554WZOO+XZFbwn8o1c5aR1NKLbErrI/M/iPM=; b=x1aKfjiaWMxkQBB6DM+ClwgQPa5KtgysGU4+rWyRRySKbUwQFtFsfrTbj/Y911zYTk WnPu5rsDu3enr33rT5tqp3DK0dcoJUVXW7SJlKI8zwRZk/1YPVJj/adFFd8oW6C4JZ6C +gKiQQXhDISoq3Jq0e50WOA/YPny3g66mnzZqqhzSVdMiWw4hJIcIb+blHZRetMwInFQ uC0rn7Kf8U+K0+JS2d/seJsb8K2lod03hpchtYpo6qF6UzwVEHz0hMo0fw60Qhvgwfer s879gmVFyw9nXYUCgXbyEmc0MqbGFzNggVz7S3ocsrLNhcrrZyHvOrobG2FMzd0w0UXX zWiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cVqzLTk554WZOO+XZFbwn8o1c5aR1NKLbErrI/M/iPM=; b=PAduta3WJjiJoPauUU1xYS5EGRqxDeG+1P94O4TAammasFnAjsvMDvaWKBxnmFXmky e+v2BbYn7X5UivB8g5ZdrdLT06WLi+rjXTjbLfHrm3i5AJtbPEMCFlYfSMbSJ4ZPMSE6 edMh2gzKA/aD3fEaObvopw6Q5zpC99WaZiuyjcaK53g7JSMn4dkfE8ReXbco11D3nbCK NIU67769DBdqiKew4gnMvCwhnOqDiKWdyFpIr89WybSbUo5aQSByyOEhakutM4L0kSi6 49bHeaYip9lINfpAOOfCZzpnhELcQkQGwOY0vThsJ+9J9FapP26rw/962yBS2w3BQqGW IDsA== X-Gm-Message-State: AOAM530Sy8ZUDMbXmubp5ac5XyDS/GMq2ttp/ktpnEWScbvD6vFm27aQ ngGZxKAp5cgxaiTxPYqI9gd3nw== X-Received: by 2002:a05:600c:4341:: with SMTP id r1mr7412505wme.99.1643829164259; Wed, 02 Feb 2022 11:12:44 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f13sm17900966wrp.105.2022.02.02.11.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 11:12:43 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D96591FFB8; Wed, 2 Feb 2022 19:12:42 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [RFC PATCH 1/4] tests/tcg: cleanup sha1 source code Date: Wed, 2 Feb 2022 19:12:39 +0000 Message-Id: <20220202191242.652607-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220202191242.652607-1-alex.bennee@linaro.org> References: <20220202191242.652607-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::329 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, berrange@redhat.com, f4bug@amsat.org, qemu-arm@nongnu.org, stefanha@redhat.com, crosa@redhat.com, pbonzini@redhat.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We have a lot of legacy mess in this imported code which makes figuring out what is going on harder. Clean it up: - delete non-SHA1HANDSOFF legs, remove symbol - don't bother clearing variables at the end - remove #if 0 dead code - some light indentation fixes Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- tests/tcg/multiarch/sha1.c | 67 ++++++++++---------------------------- 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/tests/tcg/multiarch/sha1.c b/tests/tcg/multiarch/sha1.c index 0081bd7657..3b1e18f3d4 100644 --- a/tests/tcg/multiarch/sha1.c +++ b/tests/tcg/multiarch/sha1.c @@ -17,9 +17,6 @@ A million repetitions of "a" */ /* #define LITTLE_ENDIAN * This should be #define'd already, if true. */ -/* #define SHA1HANDSOFF * Copies data before messing with it. */ - -#define SHA1HANDSOFF #include #include @@ -69,24 +66,17 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context); /* Hash a single 512-bit block. This is the core of the algorithm. */ -void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) +inline void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) { -uint32_t a, b, c, d, e; -typedef union { - unsigned char c[64]; - uint32_t l[16]; -} CHAR64LONG16; -#ifdef SHA1HANDSOFF -CHAR64LONG16 block[1]; /* use array to appear as a pointer */ - memcpy(block, buffer, 64); -#else - /* The following had better never be used because it causes the - * pointer-to-const buffer to be cast into a pointer to non-const. - * And the result is written through. I threw a "const" in, hoping - * this will cause a diagnostic. - */ -CHAR64LONG16* block = (const CHAR64LONG16*)buffer; -#endif + uint32_t a, b, c, d, e; + typedef union { + unsigned char c[64]; + uint32_t l[16]; + } CHAR64LONG16; + + CHAR64LONG16 block[1]; /* use array to appear as a pointer */ + memcpy(&block[0], buffer, sizeof(block)); + /* Copy context->state[] to working vars */ a = state[0]; b = state[1]; @@ -120,14 +110,8 @@ CHAR64LONG16* block = (const CHAR64LONG16*)buffer; state[2] += c; state[3] += d; state[4] += e; - /* Wipe variables */ - a = b = c = d = e = 0; -#ifdef SHA1HANDSOFF - memset(block, '\0', sizeof(block)); -#endif } - /* SHA1Init - Initialize new context */ void SHA1Init(SHA1_CTX* context) @@ -146,8 +130,8 @@ void SHA1Init(SHA1_CTX* context) void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len) { -uint32_t i; -uint32_t j; + uint32_t i; + uint32_t j; j = context->count[0]; if ((context->count[0] += len << 3) < j) @@ -171,32 +155,15 @@ uint32_t j; void SHA1Final(unsigned char digest[20], SHA1_CTX* context) { -unsigned i; -unsigned char finalcount[8]; -unsigned char c; - -#if 0 /* untested "improvement" by DHR */ - /* Convert context->count to a sequence of bytes - * in finalcount. Second element first, but - * big-endian order within element. - * But we do it all backwards. - */ - unsigned char *fcp = &finalcount[8]; - - for (i = 0; i < 2; i++) - { - uint32_t t = context->count[i]; - int j; - - for (j = 0; j < 4; t >>= 8, j++) - *--fcp = (unsigned char) t; - } -#else + unsigned i; + unsigned char finalcount[8]; + unsigned char c; + for (i = 0; i < 8; i++) { finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ } -#endif + c = 0200; SHA1Update(context, &c, 1); while ((context->count[0] & 504) != 448) {