diff options
author | Jan Glauber <jang@linux.vnet.ibm.com> | 2008-03-06 06:53:50 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-04-20 22:19:21 -0400 |
commit | 4e2c6d7f4d8f466f4420e10dda7126537de09c94 (patch) | |
tree | 9fcec4b344ee79bd23f9cf8a9818b137591c886a /arch/s390/crypto | |
parent | 291dc7c0996b09a7c58b2cf6e9cc3495123a607e (diff) |
[CRYPTO] sha384: Hardware acceleration for s390
Exploit the System z10 hardware acceleration for SHA384.
Signed-off-by: Jan Glauber <jang@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'arch/s390/crypto')
-rw-r--r-- | arch/s390/crypto/sha512_s390.c | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/arch/s390/crypto/sha512_s390.c b/arch/s390/crypto/sha512_s390.c index 4d651bbce0f..23c7861f6ae 100644 --- a/arch/s390/crypto/sha512_s390.c +++ b/arch/s390/crypto/sha512_s390.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Cryptographic API. | 2 | * Cryptographic API. |
3 | * | 3 | * |
4 | * s390 implementation of the SHA512 Secure Hash Algorithm. | 4 | * s390 implementation of the SHA512 and SHA38 Secure Hash Algorithm. |
5 | * | 5 | * |
6 | * Copyright IBM Corp. 2007 | 6 | * Copyright IBM Corp. 2007 |
7 | * Author(s): Jan Glauber (jang@de.ibm.com) | 7 | * Author(s): Jan Glauber (jang@de.ibm.com) |
@@ -35,7 +35,7 @@ static void sha512_init(struct crypto_tfm *tfm) | |||
35 | ctx->func = KIMD_SHA_512; | 35 | ctx->func = KIMD_SHA_512; |
36 | } | 36 | } |
37 | 37 | ||
38 | static struct crypto_alg alg = { | 38 | static struct crypto_alg sha512_alg = { |
39 | .cra_name = "sha512", | 39 | .cra_name = "sha512", |
40 | .cra_driver_name = "sha512-s390", | 40 | .cra_driver_name = "sha512-s390", |
41 | .cra_priority = CRYPT_S390_PRIORITY, | 41 | .cra_priority = CRYPT_S390_PRIORITY, |
@@ -43,7 +43,7 @@ static struct crypto_alg alg = { | |||
43 | .cra_blocksize = SHA512_BLOCK_SIZE, | 43 | .cra_blocksize = SHA512_BLOCK_SIZE, |
44 | .cra_ctxsize = sizeof(struct s390_sha_ctx), | 44 | .cra_ctxsize = sizeof(struct s390_sha_ctx), |
45 | .cra_module = THIS_MODULE, | 45 | .cra_module = THIS_MODULE, |
46 | .cra_list = LIST_HEAD_INIT(alg.cra_list), | 46 | .cra_list = LIST_HEAD_INIT(sha512_alg.cra_list), |
47 | .cra_u = { .digest = { | 47 | .cra_u = { .digest = { |
48 | .dia_digestsize = SHA512_DIGEST_SIZE, | 48 | .dia_digestsize = SHA512_DIGEST_SIZE, |
49 | .dia_init = sha512_init, | 49 | .dia_init = sha512_init, |
@@ -51,21 +51,64 @@ static struct crypto_alg alg = { | |||
51 | .dia_final = s390_sha_final } } | 51 | .dia_final = s390_sha_final } } |
52 | }; | 52 | }; |
53 | 53 | ||
54 | MODULE_ALIAS("sha512"); | ||
55 | |||
56 | static void sha384_init(struct crypto_tfm *tfm) | ||
57 | { | ||
58 | struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); | ||
59 | |||
60 | *(__u64 *)&ctx->state[0] = 0xcbbb9d5dc1059ed8ULL; | ||
61 | *(__u64 *)&ctx->state[2] = 0x629a292a367cd507ULL; | ||
62 | *(__u64 *)&ctx->state[4] = 0x9159015a3070dd17ULL; | ||
63 | *(__u64 *)&ctx->state[6] = 0x152fecd8f70e5939ULL; | ||
64 | *(__u64 *)&ctx->state[8] = 0x67332667ffc00b31ULL; | ||
65 | *(__u64 *)&ctx->state[10] = 0x8eb44a8768581511ULL; | ||
66 | *(__u64 *)&ctx->state[12] = 0xdb0c2e0d64f98fa7ULL; | ||
67 | *(__u64 *)&ctx->state[14] = 0x47b5481dbefa4fa4ULL; | ||
68 | ctx->count = 0; | ||
69 | ctx->func = KIMD_SHA_512; | ||
70 | } | ||
71 | |||
72 | static struct crypto_alg sha384_alg = { | ||
73 | .cra_name = "sha384", | ||
74 | .cra_driver_name = "sha384-s390", | ||
75 | .cra_priority = CRYPT_S390_PRIORITY, | ||
76 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | ||
77 | .cra_blocksize = SHA384_BLOCK_SIZE, | ||
78 | .cra_ctxsize = sizeof(struct s390_sha_ctx), | ||
79 | .cra_module = THIS_MODULE, | ||
80 | .cra_list = LIST_HEAD_INIT(sha384_alg.cra_list), | ||
81 | .cra_u = { .digest = { | ||
82 | .dia_digestsize = SHA384_DIGEST_SIZE, | ||
83 | .dia_init = sha384_init, | ||
84 | .dia_update = s390_sha_update, | ||
85 | .dia_final = s390_sha_final } } | ||
86 | }; | ||
87 | |||
88 | MODULE_ALIAS("sha384"); | ||
89 | |||
54 | static int __init init(void) | 90 | static int __init init(void) |
55 | { | 91 | { |
92 | int ret; | ||
93 | |||
56 | if (!crypt_s390_func_available(KIMD_SHA_512)) | 94 | if (!crypt_s390_func_available(KIMD_SHA_512)) |
57 | return -EOPNOTSUPP; | 95 | return -EOPNOTSUPP; |
58 | return crypto_register_alg(&alg); | 96 | if ((ret = crypto_register_alg(&sha512_alg)) < 0) |
97 | goto out; | ||
98 | if ((ret = crypto_register_alg(&sha384_alg)) < 0) | ||
99 | crypto_unregister_alg(&sha512_alg); | ||
100 | out: | ||
101 | return ret; | ||
59 | } | 102 | } |
60 | 103 | ||
61 | static void __exit fini(void) | 104 | static void __exit fini(void) |
62 | { | 105 | { |
63 | crypto_unregister_alg(&alg); | 106 | crypto_unregister_alg(&sha512_alg); |
107 | crypto_unregister_alg(&sha384_alg); | ||
64 | } | 108 | } |
65 | 109 | ||
66 | module_init(init); | 110 | module_init(init); |
67 | module_exit(fini); | 111 | module_exit(fini); |
68 | 112 | ||
69 | MODULE_ALIAS("sha512"); | ||
70 | MODULE_LICENSE("GPL"); | 113 | MODULE_LICENSE("GPL"); |
71 | MODULE_DESCRIPTION("SHA512 Secure Hash Algorithm"); | 114 | MODULE_DESCRIPTION("SHA512 and SHA-384 Secure Hash Algorithm"); |