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

crypto: sha-s390 - Switch to shash

This patch converts the S390 sha algorithms to the new shash interface.

With fixes by Jan Glauber.

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

+103 -89
+4 -2
arch/s390/crypto/sha.h
··· 29 29 int func; /* KIMD function to use */ 30 30 }; 31 31 32 - void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len); 33 - void s390_sha_final(struct crypto_tfm *tfm, u8 *out); 32 + struct shash_desc; 33 + 34 + int s390_sha_update(struct shash_desc *desc, const u8 *data, unsigned int len); 35 + int s390_sha_final(struct shash_desc *desc, u8 *out); 34 36 35 37 #endif
+21 -19
arch/s390/crypto/sha1_s390.c
··· 23 23 * any later version. 24 24 * 25 25 */ 26 + #include <crypto/internal/hash.h> 26 27 #include <linux/init.h> 27 28 #include <linux/module.h> 28 - #include <linux/crypto.h> 29 29 #include <crypto/sha.h> 30 30 31 31 #include "crypt_s390.h" 32 32 #include "sha.h" 33 33 34 - static void sha1_init(struct crypto_tfm *tfm) 34 + static int sha1_init(struct shash_desc *desc) 35 35 { 36 - struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm); 36 + struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 37 37 38 38 sctx->state[0] = SHA1_H0; 39 39 sctx->state[1] = SHA1_H1; ··· 42 42 sctx->state[4] = SHA1_H4; 43 43 sctx->count = 0; 44 44 sctx->func = KIMD_SHA_1; 45 + 46 + return 0; 45 47 } 46 48 47 - static struct crypto_alg alg = { 48 - .cra_name = "sha1", 49 - .cra_driver_name= "sha1-s390", 50 - .cra_priority = CRYPT_S390_PRIORITY, 51 - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 52 - .cra_blocksize = SHA1_BLOCK_SIZE, 53 - .cra_ctxsize = sizeof(struct s390_sha_ctx), 54 - .cra_module = THIS_MODULE, 55 - .cra_list = LIST_HEAD_INIT(alg.cra_list), 56 - .cra_u = { .digest = { 57 - .dia_digestsize = SHA1_DIGEST_SIZE, 58 - .dia_init = sha1_init, 59 - .dia_update = s390_sha_update, 60 - .dia_final = s390_sha_final } } 49 + static struct shash_alg alg = { 50 + .digestsize = SHA1_DIGEST_SIZE, 51 + .init = sha1_init, 52 + .update = s390_sha_update, 53 + .final = s390_sha_final, 54 + .descsize = sizeof(struct s390_sha_ctx), 55 + .base = { 56 + .cra_name = "sha1", 57 + .cra_driver_name= "sha1-s390", 58 + .cra_priority = CRYPT_S390_PRIORITY, 59 + .cra_flags = CRYPTO_ALG_TYPE_SHASH, 60 + .cra_blocksize = SHA1_BLOCK_SIZE, 61 + .cra_module = THIS_MODULE, 62 + } 61 63 }; 62 64 63 65 static int __init sha1_s390_init(void) 64 66 { 65 67 if (!crypt_s390_func_available(KIMD_SHA_1)) 66 68 return -EOPNOTSUPP; 67 - return crypto_register_alg(&alg); 69 + return crypto_register_shash(&alg); 68 70 } 69 71 70 72 static void __exit sha1_s390_fini(void) 71 73 { 72 - crypto_unregister_alg(&alg); 74 + crypto_unregister_shash(&alg); 73 75 } 74 76 75 77 module_init(sha1_s390_init);
+21 -19
arch/s390/crypto/sha256_s390.c
··· 16 16 * any later version. 17 17 * 18 18 */ 19 + #include <crypto/internal/hash.h> 19 20 #include <linux/init.h> 20 21 #include <linux/module.h> 21 - #include <linux/crypto.h> 22 22 #include <crypto/sha.h> 23 23 24 24 #include "crypt_s390.h" 25 25 #include "sha.h" 26 26 27 - static void sha256_init(struct crypto_tfm *tfm) 27 + static int sha256_init(struct shash_desc *desc) 28 28 { 29 - struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm); 29 + struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 30 30 31 31 sctx->state[0] = SHA256_H0; 32 32 sctx->state[1] = SHA256_H1; ··· 38 38 sctx->state[7] = SHA256_H7; 39 39 sctx->count = 0; 40 40 sctx->func = KIMD_SHA_256; 41 + 42 + return 0; 41 43 } 42 44 43 - static struct crypto_alg alg = { 44 - .cra_name = "sha256", 45 - .cra_driver_name = "sha256-s390", 46 - .cra_priority = CRYPT_S390_PRIORITY, 47 - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 48 - .cra_blocksize = SHA256_BLOCK_SIZE, 49 - .cra_ctxsize = sizeof(struct s390_sha_ctx), 50 - .cra_module = THIS_MODULE, 51 - .cra_list = LIST_HEAD_INIT(alg.cra_list), 52 - .cra_u = { .digest = { 53 - .dia_digestsize = SHA256_DIGEST_SIZE, 54 - .dia_init = sha256_init, 55 - .dia_update = s390_sha_update, 56 - .dia_final = s390_sha_final } } 45 + static struct shash_alg alg = { 46 + .digestsize = SHA256_DIGEST_SIZE, 47 + .init = sha256_init, 48 + .update = s390_sha_update, 49 + .final = s390_sha_final, 50 + .descsize = sizeof(struct s390_sha_ctx), 51 + .base = { 52 + .cra_name = "sha256", 53 + .cra_driver_name= "sha256-s390", 54 + .cra_priority = CRYPT_S390_PRIORITY, 55 + .cra_flags = CRYPTO_ALG_TYPE_SHASH, 56 + .cra_blocksize = SHA256_BLOCK_SIZE, 57 + .cra_module = THIS_MODULE, 58 + } 57 59 }; 58 60 59 61 static int sha256_s390_init(void) ··· 63 61 if (!crypt_s390_func_available(KIMD_SHA_256)) 64 62 return -EOPNOTSUPP; 65 63 66 - return crypto_register_alg(&alg); 64 + return crypto_register_shash(&alg); 67 65 } 68 66 69 67 static void __exit sha256_s390_fini(void) 70 68 { 71 - crypto_unregister_alg(&alg); 69 + crypto_unregister_shash(&alg); 72 70 } 73 71 74 72 module_init(sha256_s390_init);
+42 -38
arch/s390/crypto/sha512_s390.c
··· 12 12 * any later version. 13 13 * 14 14 */ 15 + #include <crypto/internal/hash.h> 15 16 #include <linux/init.h> 16 17 #include <linux/module.h> 17 - #include <linux/crypto.h> 18 18 19 19 #include "sha.h" 20 20 #include "crypt_s390.h" 21 21 22 - static void sha512_init(struct crypto_tfm *tfm) 22 + static int sha512_init(struct shash_desc *desc) 23 23 { 24 - struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 24 + struct s390_sha_ctx *ctx = shash_desc_ctx(desc); 25 25 26 26 *(__u64 *)&ctx->state[0] = 0x6a09e667f3bcc908ULL; 27 27 *(__u64 *)&ctx->state[2] = 0xbb67ae8584caa73bULL; ··· 33 33 *(__u64 *)&ctx->state[14] = 0x5be0cd19137e2179ULL; 34 34 ctx->count = 0; 35 35 ctx->func = KIMD_SHA_512; 36 + 37 + return 0; 36 38 } 37 39 38 - static struct crypto_alg sha512_alg = { 39 - .cra_name = "sha512", 40 - .cra_driver_name = "sha512-s390", 41 - .cra_priority = CRYPT_S390_PRIORITY, 42 - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 43 - .cra_blocksize = SHA512_BLOCK_SIZE, 44 - .cra_ctxsize = sizeof(struct s390_sha_ctx), 45 - .cra_module = THIS_MODULE, 46 - .cra_list = LIST_HEAD_INIT(sha512_alg.cra_list), 47 - .cra_u = { .digest = { 48 - .dia_digestsize = SHA512_DIGEST_SIZE, 49 - .dia_init = sha512_init, 50 - .dia_update = s390_sha_update, 51 - .dia_final = s390_sha_final } } 40 + static struct shash_alg sha512_alg = { 41 + .digestsize = SHA512_DIGEST_SIZE, 42 + .init = sha512_init, 43 + .update = s390_sha_update, 44 + .final = s390_sha_final, 45 + .descsize = sizeof(struct s390_sha_ctx), 46 + .base = { 47 + .cra_name = "sha512", 48 + .cra_driver_name= "sha512-s390", 49 + .cra_priority = CRYPT_S390_PRIORITY, 50 + .cra_flags = CRYPTO_ALG_TYPE_SHASH, 51 + .cra_blocksize = SHA512_BLOCK_SIZE, 52 + .cra_module = THIS_MODULE, 53 + } 52 54 }; 53 55 54 56 MODULE_ALIAS("sha512"); 55 57 56 - static void sha384_init(struct crypto_tfm *tfm) 58 + static int sha384_init(struct shash_desc *desc) 57 59 { 58 - struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 60 + struct s390_sha_ctx *ctx = shash_desc_ctx(desc); 59 61 60 62 *(__u64 *)&ctx->state[0] = 0xcbbb9d5dc1059ed8ULL; 61 63 *(__u64 *)&ctx->state[2] = 0x629a292a367cd507ULL; ··· 69 67 *(__u64 *)&ctx->state[14] = 0x47b5481dbefa4fa4ULL; 70 68 ctx->count = 0; 71 69 ctx->func = KIMD_SHA_512; 70 + 71 + return 0; 72 72 } 73 73 74 - static struct crypto_alg sha384_alg = { 75 - .cra_name = "sha384", 76 - .cra_driver_name = "sha384-s390", 77 - .cra_priority = CRYPT_S390_PRIORITY, 78 - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 79 - .cra_blocksize = SHA384_BLOCK_SIZE, 80 - .cra_ctxsize = sizeof(struct s390_sha_ctx), 81 - .cra_module = THIS_MODULE, 82 - .cra_list = LIST_HEAD_INIT(sha384_alg.cra_list), 83 - .cra_u = { .digest = { 84 - .dia_digestsize = SHA384_DIGEST_SIZE, 85 - .dia_init = sha384_init, 86 - .dia_update = s390_sha_update, 87 - .dia_final = s390_sha_final } } 74 + static struct shash_alg sha384_alg = { 75 + .digestsize = SHA384_DIGEST_SIZE, 76 + .init = sha384_init, 77 + .update = s390_sha_update, 78 + .final = s390_sha_final, 79 + .descsize = sizeof(struct s390_sha_ctx), 80 + .base = { 81 + .cra_name = "sha384", 82 + .cra_driver_name= "sha384-s390", 83 + .cra_priority = CRYPT_S390_PRIORITY, 84 + .cra_flags = CRYPTO_ALG_TYPE_SHASH, 85 + .cra_ctxsize = sizeof(struct s390_sha_ctx), 86 + .cra_module = THIS_MODULE, 87 + } 88 88 }; 89 89 90 90 MODULE_ALIAS("sha384"); ··· 97 93 98 94 if (!crypt_s390_func_available(KIMD_SHA_512)) 99 95 return -EOPNOTSUPP; 100 - if ((ret = crypto_register_alg(&sha512_alg)) < 0) 96 + if ((ret = crypto_register_shash(&sha512_alg)) < 0) 101 97 goto out; 102 - if ((ret = crypto_register_alg(&sha384_alg)) < 0) 103 - crypto_unregister_alg(&sha512_alg); 98 + if ((ret = crypto_register_shash(&sha384_alg)) < 0) 99 + crypto_unregister_shash(&sha512_alg); 104 100 out: 105 101 return ret; 106 102 } 107 103 108 104 static void __exit fini(void) 109 105 { 110 - crypto_unregister_alg(&sha512_alg); 111 - crypto_unregister_alg(&sha384_alg); 106 + crypto_unregister_shash(&sha512_alg); 107 + crypto_unregister_shash(&sha384_alg); 112 108 } 113 109 114 110 module_init(init);
+12 -8
arch/s390/crypto/sha_common.c
··· 13 13 * 14 14 */ 15 15 16 - #include <linux/crypto.h> 16 + #include <crypto/internal/hash.h> 17 17 #include "sha.h" 18 18 #include "crypt_s390.h" 19 19 20 - void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) 20 + int s390_sha_update(struct shash_desc *desc, const u8 *data, unsigned int len) 21 21 { 22 - struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 23 - unsigned int bsize = crypto_tfm_alg_blocksize(tfm); 22 + struct s390_sha_ctx *ctx = shash_desc_ctx(desc); 23 + unsigned int bsize = crypto_shash_blocksize(desc->tfm); 24 24 unsigned int index; 25 25 int ret; 26 26 ··· 51 51 store: 52 52 if (len) 53 53 memcpy(ctx->buf + index , data, len); 54 + 55 + return 0; 54 56 } 55 57 EXPORT_SYMBOL_GPL(s390_sha_update); 56 58 57 - void s390_sha_final(struct crypto_tfm *tfm, u8 *out) 59 + int s390_sha_final(struct shash_desc *desc, u8 *out) 58 60 { 59 - struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 60 - unsigned int bsize = crypto_tfm_alg_blocksize(tfm); 61 + struct s390_sha_ctx *ctx = shash_desc_ctx(desc); 62 + unsigned int bsize = crypto_shash_blocksize(desc->tfm); 61 63 u64 bits; 62 64 unsigned int index, end, plen; 63 65 int ret; ··· 89 87 BUG_ON(ret != end); 90 88 91 89 /* copy digest to out */ 92 - memcpy(out, ctx->state, crypto_hash_digestsize(crypto_hash_cast(tfm))); 90 + memcpy(out, ctx->state, crypto_shash_digestsize(desc->tfm)); 93 91 /* wipe context */ 94 92 memset(ctx, 0, sizeof *ctx); 93 + 94 + return 0; 95 95 } 96 96 EXPORT_SYMBOL_GPL(s390_sha_final); 97 97
+3 -3
drivers/crypto/Kconfig
··· 86 86 config CRYPTO_SHA1_S390 87 87 tristate "SHA1 digest algorithm" 88 88 depends on S390 89 - select CRYPTO_ALGAPI 89 + select CRYPTO_HASH 90 90 help 91 91 This is the s390 hardware accelerated implementation of the 92 92 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2). ··· 94 94 config CRYPTO_SHA256_S390 95 95 tristate "SHA256 digest algorithm" 96 96 depends on S390 97 - select CRYPTO_ALGAPI 97 + select CRYPTO_HASH 98 98 help 99 99 This is the s390 hardware accelerated implementation of the 100 100 SHA256 secure hash standard (DFIPS 180-2). ··· 105 105 config CRYPTO_SHA512_S390 106 106 tristate "SHA384 and SHA512 digest algorithm" 107 107 depends on S390 108 - select CRYPTO_ALGAPI 108 + select CRYPTO_HASH 109 109 help 110 110 This is the s390 hardware accelerated implementation of the 111 111 SHA512 secure hash standard.