From: "Alex Bennée" <alex.bennee@linaro.org>
To: richard.henderson@linaro.org, qemu-devel@nongnu.org
Cc: fam@euphon.net, berrange@redhat.com, f4bug@amsat.org,
qemu-arm@nongnu.org, stefanha@redhat.com, crosa@redhat.com,
pbonzini@redhat.com, "Alex Bennée" <alex.bennee@linaro.org>,
aurelien@aurel32.net
Subject: [RFC PATCH 1/4] tests/tcg: cleanup sha1 source code
Date: Wed, 2 Feb 2022 19:12:39 +0000 [thread overview]
Message-ID: <20220202191242.652607-2-alex.bennee@linaro.org> (raw)
In-Reply-To: <20220202191242.652607-1-alex.bennee@linaro.org>
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 <alex.bennee@linaro.org>
---
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 <stdio.h>
#include <string.h>
@@ -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) {
--
2.30.2
next prev parent reply other threads:[~2022-02-02 19:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-02 19:12 [RFC PATCH 0/4] improve coverage of vector backend Alex Bennée
2022-02-02 19:12 ` Alex Bennée [this message]
2022-02-02 21:05 ` [RFC PATCH 1/4] tests/tcg: cleanup sha1 source code Richard Henderson
2022-02-02 19:12 ` [RFC PATCH 2/4] tests/tcg: build sha1-vector for SVE and compare Alex Bennée
2022-02-02 21:09 ` Richard Henderson
2022-02-02 19:12 ` [RFC PATCH 3/4] tests/tcg: add sha512 test Alex Bennée
2022-02-02 21:19 ` Richard Henderson
2022-02-02 19:12 ` [RFC PATCH 4/4] tests/tcg: add vectorised sha512 versions Alex Bennée
2022-02-02 21:18 ` Richard Henderson
2022-02-02 23:16 ` [RFC PATCH 0/4] improve coverage of vector backend Alex Bennée
2022-02-03 1:45 ` Taylor Simpson
2022-02-03 16:33 ` Taylor Simpson
2022-02-03 17:50 ` Alex Bennée
2022-02-03 17:57 ` Taylor Simpson
2022-02-03 18:26 ` Alex Bennée
2022-02-03 19:01 ` Taylor Simpson
2022-02-03 20:00 ` Alex Bennée
2022-02-03 21:05 ` Taylor Simpson
2022-02-03 21:31 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220202191242.652607-2-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=aurelien@aurel32.net \
--cc=berrange@redhat.com \
--cc=crosa@redhat.com \
--cc=f4bug@amsat.org \
--cc=fam@euphon.net \
--cc=pbonzini@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).