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

crypto: hash - Make HASH_MAX_DESCSIZE a bit more obvious

Move S390_SHA_CTX_SIZE into crypto/hash.h so that the derivation
of HASH_MAX_DESCSIZE is less cryptic.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+21 -3
+7 -1
arch/s390/crypto/sha.h
··· 10 10 #ifndef _CRYPTO_ARCH_S390_SHA_H 11 11 #define _CRYPTO_ARCH_S390_SHA_H 12 12 13 + #include <crypto/hash.h> 13 14 #include <crypto/sha2.h> 14 15 #include <crypto/sha3.h> 16 + #include <linux/build_bug.h> 15 17 #include <linux/types.h> 16 18 17 19 /* must be big enough for the largest SHA variant */ 18 20 #define CPACF_MAX_PARMBLOCK_SIZE SHA3_STATE_SIZE 19 21 #define SHA_MAX_BLOCK_SIZE SHA3_224_BLOCK_SIZE 20 - #define S390_SHA_CTX_SIZE sizeof(struct s390_sha_ctx) 21 22 22 23 struct s390_sha_ctx { 23 24 u64 count; /* message length in bytes */ ··· 42 41 unsigned int len); 43 42 int s390_sha_finup(struct shash_desc *desc, const u8 *src, unsigned int len, 44 43 u8 *out); 44 + 45 + static inline void __check_s390_sha_ctx_size(void) 46 + { 47 + BUILD_BUG_ON(S390_SHA_CTX_SIZE != sizeof(struct s390_sha_ctx)); 48 + } 45 49 46 50 #endif
+14 -2
include/crypto/hash.h
··· 177 177 178 178 #define HASH_MAX_DIGESTSIZE 64 179 179 180 + /* 181 + * The size of a core hash state and a partial block. The final byte 182 + * is the length of the partial block. 183 + */ 184 + #define HASH_STATE_AND_BLOCK(state, block) ((state) + (block) + 1) 185 + 186 + 180 187 /* Worst case is sha3-224. */ 181 - #define HASH_MAX_STATESIZE 200 + 144 + 1 188 + #define HASH_MAX_STATESIZE HASH_STATE_AND_BLOCK(200, 144) 189 + 190 + /* This needs to match arch/s390/crypto/sha.h. */ 191 + #define S390_SHA_CTX_SIZE 216 182 192 183 193 /* 184 194 * Worst case is hmac(sha3-224-s390). Its context is a nested 'shash_desc' 185 195 * containing a 'struct s390_sha_ctx'. 186 196 */ 187 - #define HASH_MAX_DESCSIZE (sizeof(struct shash_desc) + 361) 197 + #define SHA3_224_S390_DESCSIZE HASH_STATE_AND_BLOCK(S390_SHA_CTX_SIZE, 144) 198 + #define HASH_MAX_DESCSIZE (sizeof(struct shash_desc) + \ 199 + SHA3_224_S390_DESCSIZE) 188 200 #define MAX_SYNC_HASH_REQSIZE (sizeof(struct ahash_request) + \ 189 201 HASH_MAX_DESCSIZE) 190 202