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