]> git.ipfire.org Git - thirdparty/linux.git/commit
lib/crypto: sm3: Add SM3 library API
authorEric Biggers <ebiggers@kernel.org>
Sat, 21 Mar 2026 04:09:27 +0000 (21:09 -0700)
committerEric Biggers <ebiggers@kernel.org>
Tue, 24 Mar 2026 00:50:59 +0000 (17:50 -0700)
commit324bb3bb75ac21adbbc7e6ea5cdb0a735fb78a56
tree50fd9976634d569bdb0a42872e63338bcb4a864a
parent6dc7fce91041ec8d2f5e6fd589ee2962898d9f44
lib/crypto: sm3: Add SM3 library API

Add a straightforward library API for SM3, mirroring the ones for the
other hash algorithms.  It uses the existing generic implementation of
SM3's compression function in lib/crypto/sm3.c.  Hooks are added for
architecture-optimized implementations, which later commits will wire up
to the existing optimized SM3 code for arm64, riscv, and x86.

Note that the rationale for this is *not* that SM3 should be used, or
that any kernel subsystem currently seems like a candidate for switching
from the sm3 crypto_shash to SM3 library.  (SM3, in fact, shouldn't be
used.  Likewise you shouldn't use MD5, SHA-1, RC4, etc...)

Rather, it's just that this will simplify how the kernel's existing SM3
code is integrated and make it much easier to maintain and test.  SM3 is
one of the only hash algorithms with arch-optimized code that is still
integrated in the old way.  By converting it to the new lib/crypto/ code
organization, we'll only have to keep track of one way of doing things.
The library will also get a KUnit test suite (as usual for lib/crypto/),
so it will become more easily and comprehensively tested as well.

Skip adding functions for HMAC-SM3 for now, though.  There's not as much
point in adding those right now.

Note: similar to the other hash algorithms, the library API uses
'struct sm3_ctx', not 'struct sm3_state'.  The existing 'struct
sm3_state' and the sm3_block_generic() function which uses it are
temporarily kept around until their users are updated by later commits.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20260321040935.410034-5-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
include/crypto/sm3.h
lib/crypto/Kconfig
lib/crypto/sm3.c