Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/crypto: sha256: Add sha224() and sha224_update()

Add a one-shot SHA-224 computation function sha224(), for consistency
with sha256(), sha384(), and sha512() which all already exist.

Similarly, add sha224_update(). While for now it's identical to
sha256_update(), omitting it makes the API harder to use since users
have to "know" which functions are the same between SHA-224 and SHA-256.
Also, this is a prerequisite for using different context types for each.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250630160645.3198-6-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+18 -2
+8 -2
include/crypto/sha2.h
··· 114 114 u8 buf[SHA512_BLOCK_SIZE]; 115 115 }; 116 116 117 + void sha256_update(struct sha256_state *sctx, const u8 *data, size_t len); 118 + 117 119 static inline void sha224_init(struct sha256_state *sctx) 118 120 { 119 121 sha224_block_init(&sctx->ctx); 120 122 } 121 - /* Simply use sha256_update as it is equivalent to sha224_update. */ 123 + static inline void sha224_update(struct sha256_state *sctx, 124 + const u8 *data, size_t len) 125 + { 126 + sha256_update(sctx, data, len); 127 + } 122 128 void sha224_final(struct sha256_state *sctx, u8 out[SHA224_DIGEST_SIZE]); 129 + void sha224(const u8 *data, size_t len, u8 out[SHA224_DIGEST_SIZE]); 123 130 124 131 static inline void sha256_init(struct sha256_state *sctx) 125 132 { 126 133 sha256_block_init(&sctx->ctx); 127 134 } 128 - void sha256_update(struct sha256_state *sctx, const u8 *data, size_t len); 129 135 void sha256_final(struct sha256_state *sctx, u8 out[SHA256_DIGEST_SIZE]); 130 136 void sha256(const u8 *data, size_t len, u8 out[SHA256_DIGEST_SIZE]); 131 137
+10
lib/crypto/sha256.c
··· 70 70 } 71 71 EXPORT_SYMBOL(sha256_final); 72 72 73 + void sha224(const u8 *data, size_t len, u8 out[SHA224_DIGEST_SIZE]) 74 + { 75 + struct sha256_state sctx; 76 + 77 + sha224_init(&sctx); 78 + sha224_update(&sctx, data, len); 79 + sha224_final(&sctx, out); 80 + } 81 + EXPORT_SYMBOL(sha224); 82 + 73 83 void sha256(const u8 *data, size_t len, u8 out[SHA256_DIGEST_SIZE]) 74 84 { 75 85 struct sha256_state sctx;