]> git.ipfire.org Git - thirdparty/openssl.git/commit
SLH-DSA speed up hash calculations. master
authorslontis <shane.lontis@oracle.com>
Fri, 17 Oct 2025 05:32:06 +0000 (16:32 +1100)
committerslontis <shane.lontis@oracle.com>
Tue, 17 Feb 2026 01:20:04 +0000 (12:20 +1100)
commit9f01bfa158b2129c2bc03259a4d97214df5f5416
treec5bb7a1abfb16209c0a0fa39fc0d9064e5a75ca3
parentd66c748300c7650e36c4c720da950ad4ac70fc54
SLH-DSA speed up hash calculations.

SLH-DSA spends a significant amount of time performing large
numbers of hash calculations. Initially this was done using
EVP layer calls. The overhead is significant when there are thousands
of calls. To reduce this overhead the lower level sha functions for
KECCAK1600_CTX, SHA256_CTX and SHA512_CTX are accessed directly.

Profiling showed that a significant amount of time is spent in
"WOTS+ Public key generation" (FIPS 205 Section 5.1 Algorithm 6) so
this was inlined for shake and sha2 (See slh_wots_pk_gen_sha2()).

In FIPS 205 Section 11 there is a list of Hash functions.
Many of these functions use a pattern of
Trunc(n)(SHA256(PK.Seed || toByte(0, 64-n) || ....)
Because this operation is done many times, this prehashed
value is calculated once and stored into a low level SHA256_CTX or
KECCAK1600_CTX.
This can then be block copied to stack based KECCAK1600_CTX or
SHA256_CTX that we can then perform low level SHA functions on.
The md_len field is written to directly before the SHA final() to
control the length of the output (which avoids performing a memcpy).

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28941)
12 files changed:
crypto/sha/sha3.c
crypto/sha/sha512.c
crypto/slh_dsa/slh_dsa_hash_ctx.c
crypto/slh_dsa/slh_dsa_key.c
crypto/slh_dsa/slh_dsa_key.h
crypto/slh_dsa/slh_dsa_local.h
crypto/slh_dsa/slh_hash.c
crypto/slh_dsa/slh_hash.h
crypto/slh_dsa/slh_wots.c
include/crypto/md32_common.h
include/crypto/slh_dsa.h
include/internal/sha3.h