From: David Hildenbrand <david@redhat.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>,
qemu-s390x@nongnu.org, qemu-devel@nongnu.org
Cc: Thomas Huth <thuth@redhat.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Richard Henderson <richard.henderson@linaro.org>,
Cornelia Huck <cohuck@redhat.com>,
Harald Freudenberger <freude@linux.ibm.com>,
Holger Dengler <dengler@linux.ibm.com>
Subject: Re: [PATCH v4 2/2] target/s390x: support SHA-512 extensions
Date: Wed, 3 Aug 2022 13:55:21 +0200 [thread overview]
Message-ID: <5758f0a3-ee4e-97d4-3e32-469b56029208@redhat.com> (raw)
In-Reply-To: <20220802190011.458871-3-Jason@zx2c4.com>
On 02.08.22 21:00, Jason A. Donenfeld wrote:
> In order to fully support MSA_EXT_5, we have to also support the SHA-512
> special instructions. So implement those.
>
> The implementation began as something TweetNacl-like, and then was
> adjusted to be useful here. It's not very beautiful, but it is quite
> short and compact, which is what we're going for.
>
Do we have to worry about copyright/authorship of the original code or
did you write that from scratch?
[...]
I cannot really comment on the actual math, so I'll point out some code
style thingies.
> +static void kimd_sha512(CPUS390XState *env, uintptr_t ra, uint64_t parameter_block,
> + uint64_t *message_reg, uint64_t *len_reg, uint8_t *stack_buffer)
> +{
> + uint64_t z[8], b[8], a[8], w[16], t;
> + int i, j;
> +
> + for (i = 0; i < 8; ++i)
> + z[i] = a[i] = cpu_ldq_be_data_ra(env, wrap_address(env, parameter_block + 8 * i), ra);
Please always use curly brackets in QEMU for code blocks, they are
mandatory.
> +
> + while (*len_reg >= 128) {
> + for (i = 0; i < 16; ++i) {
i++, also for all cases below.
> + if (message_reg)
> + w[i] = cpu_ldq_be_data_ra(env, wrap_address(env, *message_reg + 8 * i), ra);
> + else
> + w[i] = be64_to_cpu(((uint64_t *)stack_buffer)[i]);
> + }
> +
> + for (i = 0; i < 80; ++i) {
> + for (j = 0; j < 8; ++j)
> + b[j] = a[j];
> + t = a[7] + Sigma1(a[4]) + Ch(a[4], a[5], a[6]) + K[i] + w[i % 16];
> + b[7] = t + Sigma0(a[0]) + Maj(a[0], a[1], a[2]);
> + b[3] += t;
> + for (j = 0; j < 8; ++j)
> + a[(j + 1) % 8] = b[j];
> + if (i % 16 == 15) {
> + for (j = 0; j < 16; ++j)
> + w[j] += w[(j + 9) % 16] + sigma0(w[(j + 1) % 16]) +
> + sigma1(w[(j + 14) % 16]);
> + }
> + }
> +
> + for (i = 0; i < 8; ++i) {
> + a[i] += z[i];
> + z[i] = a[i];
> + }
> +
> + if (message_reg)
> + *message_reg += 128;
> + else
> + stack_buffer += 128;
> + *len_reg -= 128;
> + }
> +
> + for (i = 0; i < 8; ++i)
> + cpu_stq_be_data_ra(env, wrap_address(env, parameter_block + 8 * i), z[i], ra);
> +}
> +
> +static void klmd_sha512(CPUS390XState *env, uintptr_t ra, uint64_t parameter_block,
> + uint64_t *message_reg, uint64_t *len_reg)
> +{
> + uint8_t x[256];
> + uint64_t i;
> + int j;
> +
> + kimd_sha512(env, ra, parameter_block, message_reg, len_reg, NULL);
> + for (i = 0; i < *len_reg; ++i)
> + x[i] = cpu_ldub_data_ra(env, wrap_address(env, *message_reg + i), ra);
> + *message_reg += *len_reg;
> + *len_reg = 0;
> + memset(x + i, 0, sizeof(x) - i);
> + x[i] = 128;
> + i = i < 112 ? 128 : 256;
> + for (j = 0; j < 16; ++j)
> + x[i - 16 + j] = cpu_ldub_data_ra(env, wrap_address(env, parameter_block + 64 + j), ra);
> + kimd_sha512(env, ra, parameter_block, NULL, &i, x);
> +}
Are we properly handling the length register (r2 + 1) in the
24-bit/31-bit addressing mode?
Similarly, are we properly handling updates to the message register (r2)
depending on the addressing mode?
It's worth noting that we might want to implement (also for PRNO-TRNG):
"The operation is ended when all
source bytes in the second operand have been pro-
cessed (called normal completion), or when a CPU-
determined number of blocks that is less than the
length of the second operand have been processed
(called partial completion). The CPU-determined
number of blocks depends on the model, and may be
a different number each time the instruction is exe-
cuted. The CPU-determined number of blocks is usu-
ally nonzero. In certain unusual situations, this
number may be zero, and condition code 3 may be
set with no progress."
Otherwise, a large length can make us loop quite a while in QEMU,
without the chance to deliver any other interrupts.
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2022-08-03 11:57 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 16:46 [PATCH qemu] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-07-19 9:54 ` David Hildenbrand
2022-07-19 11:23 ` Jason A. Donenfeld
2022-07-19 11:43 ` [PATCH v2] " Jason A. Donenfeld
2022-07-20 11:43 ` David Hildenbrand
2022-07-20 11:58 ` Jason A. Donenfeld
2022-07-20 12:08 ` [PATCH v3] " Jason A. Donenfeld
2022-07-20 18:41 ` David Hildenbrand
2022-07-20 19:44 ` Jason A. Donenfeld
2022-07-27 1:35 ` Jason A. Donenfeld
2022-07-27 6:32 ` Thomas Huth
2022-07-27 11:58 ` Jason A. Donenfeld
2022-08-02 13:26 ` Christian Borntraeger
2022-08-02 13:54 ` David Hildenbrand
2022-08-02 14:01 ` Christian Borntraeger
2022-08-02 14:53 ` David Hildenbrand
2022-08-02 15:15 ` Christian Borntraeger
2022-08-02 15:16 ` David Hildenbrand
2022-08-02 15:28 ` Jason A. Donenfeld
2022-08-02 15:32 ` David Hildenbrand
2022-08-02 18:59 ` Jason A. Donenfeld
2022-08-02 19:00 ` [PATCH v4 0/2] MSA EXT 5 for s390x Jason A. Donenfeld
2022-08-02 19:00 ` [PATCH v4 1/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-02 19:00 ` [PATCH v4 2/2] target/s390x: support SHA-512 extensions Jason A. Donenfeld
2022-08-03 11:55 ` David Hildenbrand [this message]
2022-08-03 12:14 ` Jason A. Donenfeld
2022-08-03 12:47 ` Jason A. Donenfeld
2022-08-03 12:51 ` [PATCH v5 1/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-03 12:51 ` [PATCH v5 2/2] target/s390x: support SHA-512 extensions Jason A. Donenfeld
2022-08-03 17:15 ` [PATCH 1/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-03 17:15 ` [PATCH 2/2] target/s390x: support SHA-512 extensions Jason A. Donenfeld
2022-08-03 17:15 ` [PATCH v6 1/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-03 17:15 ` [PATCH v6 2/2] target/s390x: support SHA-512 extensions Jason A. Donenfeld
2022-08-05 11:28 ` David Hildenbrand
2022-08-05 13:01 ` Jason A. Donenfeld
2022-08-09 15:03 ` [PATCH v7 1/2] " Jason A. Donenfeld
2022-08-09 15:03 ` [PATCH v7 2/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-26 11:28 ` Thomas Huth
2022-08-29 16:29 ` Jason A. Donenfeld
2022-09-21 10:59 ` Thomas Huth
2022-08-26 10:21 ` [PATCH v7 1/2] target/s390x: support SHA-512 extensions Thomas Huth
2022-08-29 16:27 ` Jason A. Donenfeld
2022-08-11 16:37 ` [PATCH v6 2/2] " David Hildenbrand
2022-08-04 6:51 ` [PATCH v4 " Harald Freudenberger
2022-08-04 6:56 ` Christian Borntraeger
2022-08-04 12:09 ` Jason A. Donenfeld
2022-08-04 8:10 ` David Hildenbrand
2022-08-04 12:07 ` Jason A. Donenfeld
2022-08-02 17:55 ` [PATCH v3] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-07-20 18:01 ` [PATCH v2] " David Hildenbrand
2022-08-02 11:54 ` Harald Freudenberger
2022-07-19 10:00 ` [PATCH qemu] " Thomas Huth
2022-07-19 11:27 ` Jason A. Donenfeld
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=5758f0a3-ee4e-97d4-3e32-469b56029208@redhat.com \
--to=david@redhat.com \
--cc=Jason@zx2c4.com \
--cc=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=dengler@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@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).