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: Reorder some code

First, move the declarations of sha224_init/update/final to be just
above the corresponding SHA-256 code, matching the order that I used for
SHA-384 and SHA-512. In sha2.h, the end result is that SHA-224,
SHA-256, SHA-384, and SHA-512 are all in the logical order.

Second, move sha224_block_init() and sha256_block_init() to be just
below crypto_sha256_state. In later changes, these functions as well as
struct crypto_sha256_state will no longer be used by the library
functions. They'll remain just for some legacy offload drivers. This
gets them into a logical place in the file for that.

No code changes other than reordering.

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

+36 -36
+30 -30
include/crypto/sha2.h
··· 71 71 u64 count; 72 72 }; 73 73 74 + static inline void sha224_block_init(struct crypto_sha256_state *sctx) 75 + { 76 + sctx->state[0] = SHA224_H0; 77 + sctx->state[1] = SHA224_H1; 78 + sctx->state[2] = SHA224_H2; 79 + sctx->state[3] = SHA224_H3; 80 + sctx->state[4] = SHA224_H4; 81 + sctx->state[5] = SHA224_H5; 82 + sctx->state[6] = SHA224_H6; 83 + sctx->state[7] = SHA224_H7; 84 + sctx->count = 0; 85 + } 86 + 87 + static inline void sha256_block_init(struct crypto_sha256_state *sctx) 88 + { 89 + sctx->state[0] = SHA256_H0; 90 + sctx->state[1] = SHA256_H1; 91 + sctx->state[2] = SHA256_H2; 92 + sctx->state[3] = SHA256_H3; 93 + sctx->state[4] = SHA256_H4; 94 + sctx->state[5] = SHA256_H5; 95 + sctx->state[6] = SHA256_H6; 96 + sctx->state[7] = SHA256_H7; 97 + sctx->count = 0; 98 + } 99 + 74 100 struct sha256_state { 75 101 union { 76 102 struct crypto_sha256_state ctx; ··· 114 88 u8 buf[SHA512_BLOCK_SIZE]; 115 89 }; 116 90 117 - static inline void sha256_block_init(struct crypto_sha256_state *sctx) 91 + static inline void sha224_init(struct sha256_state *sctx) 118 92 { 119 - sctx->state[0] = SHA256_H0; 120 - sctx->state[1] = SHA256_H1; 121 - sctx->state[2] = SHA256_H2; 122 - sctx->state[3] = SHA256_H3; 123 - sctx->state[4] = SHA256_H4; 124 - sctx->state[5] = SHA256_H5; 125 - sctx->state[6] = SHA256_H6; 126 - sctx->state[7] = SHA256_H7; 127 - sctx->count = 0; 93 + sha224_block_init(&sctx->ctx); 128 94 } 95 + /* Simply use sha256_update as it is equivalent to sha224_update. */ 96 + void sha224_final(struct sha256_state *sctx, u8 out[SHA224_DIGEST_SIZE]); 129 97 130 98 static inline void sha256_init(struct sha256_state *sctx) 131 99 { ··· 128 108 void sha256_update(struct sha256_state *sctx, const u8 *data, size_t len); 129 109 void sha256_final(struct sha256_state *sctx, u8 out[SHA256_DIGEST_SIZE]); 130 110 void sha256(const u8 *data, size_t len, u8 out[SHA256_DIGEST_SIZE]); 131 - 132 - static inline void sha224_block_init(struct crypto_sha256_state *sctx) 133 - { 134 - sctx->state[0] = SHA224_H0; 135 - sctx->state[1] = SHA224_H1; 136 - sctx->state[2] = SHA224_H2; 137 - sctx->state[3] = SHA224_H3; 138 - sctx->state[4] = SHA224_H4; 139 - sctx->state[5] = SHA224_H5; 140 - sctx->state[6] = SHA224_H6; 141 - sctx->state[7] = SHA224_H7; 142 - sctx->count = 0; 143 - } 144 - 145 - static inline void sha224_init(struct sha256_state *sctx) 146 - { 147 - sha224_block_init(&sctx->ctx); 148 - } 149 - /* Simply use sha256_update as it is equivalent to sha224_update. */ 150 - void sha224_final(struct sha256_state *sctx, u8 out[SHA224_DIGEST_SIZE]); 151 111 152 112 /* State for the SHA-512 (and SHA-384) compression function */ 153 113 struct sha512_block_state {
+6 -6
lib/crypto/sha256.c
··· 58 58 memzero_explicit(sctx, sizeof(*sctx)); 59 59 } 60 60 61 - void sha256_final(struct sha256_state *sctx, u8 out[SHA256_DIGEST_SIZE]) 62 - { 63 - __sha256_final(sctx, out, SHA256_DIGEST_SIZE); 64 - } 65 - EXPORT_SYMBOL(sha256_final); 66 - 67 61 void sha224_final(struct sha256_state *sctx, u8 out[SHA224_DIGEST_SIZE]) 68 62 { 69 63 __sha256_final(sctx, out, SHA224_DIGEST_SIZE); 70 64 } 71 65 EXPORT_SYMBOL(sha224_final); 66 + 67 + void sha256_final(struct sha256_state *sctx, u8 out[SHA256_DIGEST_SIZE]) 68 + { 69 + __sha256_final(sctx, out, SHA256_DIGEST_SIZE); 70 + } 71 + EXPORT_SYMBOL(sha256_final); 72 72 73 73 void sha256(const u8 *data, size_t len, u8 out[SHA256_DIGEST_SIZE]) 74 74 {