Commit 563f346d authored by Herbert Xu's avatar Herbert Xu

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: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 97495986
...@@ -29,7 +29,9 @@ struct s390_sha_ctx { ...@@ -29,7 +29,9 @@ struct s390_sha_ctx {
int func; /* KIMD function to use */ int func; /* KIMD function to use */
}; };
void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len); struct shash_desc;
void s390_sha_final(struct crypto_tfm *tfm, u8 *out);
int s390_sha_update(struct shash_desc *desc, const u8 *data, unsigned int len);
int s390_sha_final(struct shash_desc *desc, u8 *out);
#endif #endif
...@@ -23,17 +23,17 @@ ...@@ -23,17 +23,17 @@
* any later version. * any later version.
* *
*/ */
#include <crypto/internal/hash.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/crypto.h>
#include <crypto/sha.h> #include <crypto/sha.h>
#include "crypt_s390.h" #include "crypt_s390.h"
#include "sha.h" #include "sha.h"
static void sha1_init(struct crypto_tfm *tfm) static int sha1_init(struct shash_desc *desc)
{ {
struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm); struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
sctx->state[0] = SHA1_H0; sctx->state[0] = SHA1_H0;
sctx->state[1] = SHA1_H1; sctx->state[1] = SHA1_H1;
...@@ -42,34 +42,36 @@ static void sha1_init(struct crypto_tfm *tfm) ...@@ -42,34 +42,36 @@ static void sha1_init(struct crypto_tfm *tfm)
sctx->state[4] = SHA1_H4; sctx->state[4] = SHA1_H4;
sctx->count = 0; sctx->count = 0;
sctx->func = KIMD_SHA_1; sctx->func = KIMD_SHA_1;
return 0;
} }
static struct crypto_alg alg = { static struct shash_alg alg = {
.cra_name = "sha1", .digestsize = SHA1_DIGEST_SIZE,
.cra_driver_name= "sha1-s390", .init = sha1_init,
.cra_priority = CRYPT_S390_PRIORITY, .update = s390_sha_update,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .final = s390_sha_final,
.cra_blocksize = SHA1_BLOCK_SIZE, .descsize = sizeof(struct s390_sha_ctx),
.cra_ctxsize = sizeof(struct s390_sha_ctx), .base = {
.cra_module = THIS_MODULE, .cra_name = "sha1",
.cra_list = LIST_HEAD_INIT(alg.cra_list), .cra_driver_name= "sha1-s390",
.cra_u = { .digest = { .cra_priority = CRYPT_S390_PRIORITY,
.dia_digestsize = SHA1_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = sha1_init, .cra_blocksize = SHA1_BLOCK_SIZE,
.dia_update = s390_sha_update, .cra_module = THIS_MODULE,
.dia_final = s390_sha_final } } }
}; };
static int __init sha1_s390_init(void) static int __init sha1_s390_init(void)
{ {
if (!crypt_s390_func_available(KIMD_SHA_1)) if (!crypt_s390_func_available(KIMD_SHA_1))
return -EOPNOTSUPP; return -EOPNOTSUPP;
return crypto_register_alg(&alg); return crypto_register_shash(&alg);
} }
static void __exit sha1_s390_fini(void) static void __exit sha1_s390_fini(void)
{ {
crypto_unregister_alg(&alg); crypto_unregister_shash(&alg);
} }
module_init(sha1_s390_init); module_init(sha1_s390_init);
......
...@@ -16,17 +16,17 @@ ...@@ -16,17 +16,17 @@
* any later version. * any later version.
* *
*/ */
#include <crypto/internal/hash.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/crypto.h>
#include <crypto/sha.h> #include <crypto/sha.h>
#include "crypt_s390.h" #include "crypt_s390.h"
#include "sha.h" #include "sha.h"
static void sha256_init(struct crypto_tfm *tfm) static int sha256_init(struct shash_desc *desc)
{ {
struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm); struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
sctx->state[0] = SHA256_H0; sctx->state[0] = SHA256_H0;
sctx->state[1] = SHA256_H1; sctx->state[1] = SHA256_H1;
...@@ -38,22 +38,24 @@ static void sha256_init(struct crypto_tfm *tfm) ...@@ -38,22 +38,24 @@ static void sha256_init(struct crypto_tfm *tfm)
sctx->state[7] = SHA256_H7; sctx->state[7] = SHA256_H7;
sctx->count = 0; sctx->count = 0;
sctx->func = KIMD_SHA_256; sctx->func = KIMD_SHA_256;
return 0;
} }
static struct crypto_alg alg = { static struct shash_alg alg = {
.cra_name = "sha256", .digestsize = SHA256_DIGEST_SIZE,
.cra_driver_name = "sha256-s390", .init = sha256_init,
.cra_priority = CRYPT_S390_PRIORITY, .update = s390_sha_update,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .final = s390_sha_final,
.cra_blocksize = SHA256_BLOCK_SIZE, .descsize = sizeof(struct s390_sha_ctx),
.cra_ctxsize = sizeof(struct s390_sha_ctx), .base = {
.cra_module = THIS_MODULE, .cra_name = "sha256",
.cra_list = LIST_HEAD_INIT(alg.cra_list), .cra_driver_name= "sha256-s390",
.cra_u = { .digest = { .cra_priority = CRYPT_S390_PRIORITY,
.dia_digestsize = SHA256_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = sha256_init, .cra_blocksize = SHA256_BLOCK_SIZE,
.dia_update = s390_sha_update, .cra_module = THIS_MODULE,
.dia_final = s390_sha_final } } }
}; };
static int sha256_s390_init(void) static int sha256_s390_init(void)
...@@ -61,12 +63,12 @@ static int sha256_s390_init(void) ...@@ -61,12 +63,12 @@ static int sha256_s390_init(void)
if (!crypt_s390_func_available(KIMD_SHA_256)) if (!crypt_s390_func_available(KIMD_SHA_256))
return -EOPNOTSUPP; return -EOPNOTSUPP;
return crypto_register_alg(&alg); return crypto_register_shash(&alg);
} }
static void __exit sha256_s390_fini(void) static void __exit sha256_s390_fini(void)
{ {
crypto_unregister_alg(&alg); crypto_unregister_shash(&alg);
} }
module_init(sha256_s390_init); module_init(sha256_s390_init);
......
...@@ -12,16 +12,16 @@ ...@@ -12,16 +12,16 @@
* any later version. * any later version.
* *
*/ */
#include <crypto/internal/hash.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/crypto.h>
#include "sha.h" #include "sha.h"
#include "crypt_s390.h" #include "crypt_s390.h"
static void sha512_init(struct crypto_tfm *tfm) static int sha512_init(struct shash_desc *desc)
{ {
struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
*(__u64 *)&ctx->state[0] = 0x6a09e667f3bcc908ULL; *(__u64 *)&ctx->state[0] = 0x6a09e667f3bcc908ULL;
*(__u64 *)&ctx->state[2] = 0xbb67ae8584caa73bULL; *(__u64 *)&ctx->state[2] = 0xbb67ae8584caa73bULL;
...@@ -33,29 +33,31 @@ static void sha512_init(struct crypto_tfm *tfm) ...@@ -33,29 +33,31 @@ static void sha512_init(struct crypto_tfm *tfm)
*(__u64 *)&ctx->state[14] = 0x5be0cd19137e2179ULL; *(__u64 *)&ctx->state[14] = 0x5be0cd19137e2179ULL;
ctx->count = 0; ctx->count = 0;
ctx->func = KIMD_SHA_512; ctx->func = KIMD_SHA_512;
return 0;
} }
static struct crypto_alg sha512_alg = { static struct shash_alg sha512_alg = {
.cra_name = "sha512", .digestsize = SHA512_DIGEST_SIZE,
.cra_driver_name = "sha512-s390", .init = sha512_init,
.cra_priority = CRYPT_S390_PRIORITY, .update = s390_sha_update,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .final = s390_sha_final,
.cra_blocksize = SHA512_BLOCK_SIZE, .descsize = sizeof(struct s390_sha_ctx),
.cra_ctxsize = sizeof(struct s390_sha_ctx), .base = {
.cra_module = THIS_MODULE, .cra_name = "sha512",
.cra_list = LIST_HEAD_INIT(sha512_alg.cra_list), .cra_driver_name= "sha512-s390",
.cra_u = { .digest = { .cra_priority = CRYPT_S390_PRIORITY,
.dia_digestsize = SHA512_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = sha512_init, .cra_blocksize = SHA512_BLOCK_SIZE,
.dia_update = s390_sha_update, .cra_module = THIS_MODULE,
.dia_final = s390_sha_final } } }
}; };
MODULE_ALIAS("sha512"); MODULE_ALIAS("sha512");
static void sha384_init(struct crypto_tfm *tfm) static int sha384_init(struct shash_desc *desc)
{ {
struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
*(__u64 *)&ctx->state[0] = 0xcbbb9d5dc1059ed8ULL; *(__u64 *)&ctx->state[0] = 0xcbbb9d5dc1059ed8ULL;
*(__u64 *)&ctx->state[2] = 0x629a292a367cd507ULL; *(__u64 *)&ctx->state[2] = 0x629a292a367cd507ULL;
...@@ -67,22 +69,24 @@ static void sha384_init(struct crypto_tfm *tfm) ...@@ -67,22 +69,24 @@ static void sha384_init(struct crypto_tfm *tfm)
*(__u64 *)&ctx->state[14] = 0x47b5481dbefa4fa4ULL; *(__u64 *)&ctx->state[14] = 0x47b5481dbefa4fa4ULL;
ctx->count = 0; ctx->count = 0;
ctx->func = KIMD_SHA_512; ctx->func = KIMD_SHA_512;
return 0;
} }
static struct crypto_alg sha384_alg = { static struct shash_alg sha384_alg = {
.cra_name = "sha384", .digestsize = SHA384_DIGEST_SIZE,
.cra_driver_name = "sha384-s390", .init = sha384_init,
.cra_priority = CRYPT_S390_PRIORITY, .update = s390_sha_update,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .final = s390_sha_final,
.cra_blocksize = SHA384_BLOCK_SIZE, .descsize = sizeof(struct s390_sha_ctx),
.cra_ctxsize = sizeof(struct s390_sha_ctx), .base = {
.cra_module = THIS_MODULE, .cra_name = "sha384",
.cra_list = LIST_HEAD_INIT(sha384_alg.cra_list), .cra_driver_name= "sha384-s390",
.cra_u = { .digest = { .cra_priority = CRYPT_S390_PRIORITY,
.dia_digestsize = SHA384_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = sha384_init, .cra_ctxsize = sizeof(struct s390_sha_ctx),
.dia_update = s390_sha_update, .cra_module = THIS_MODULE,
.dia_final = s390_sha_final } } }
}; };
MODULE_ALIAS("sha384"); MODULE_ALIAS("sha384");
...@@ -93,18 +97,18 @@ static int __init init(void) ...@@ -93,18 +97,18 @@ static int __init init(void)
if (!crypt_s390_func_available(KIMD_SHA_512)) if (!crypt_s390_func_available(KIMD_SHA_512))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if ((ret = crypto_register_alg(&sha512_alg)) < 0) if ((ret = crypto_register_shash(&sha512_alg)) < 0)
goto out; goto out;
if ((ret = crypto_register_alg(&sha384_alg)) < 0) if ((ret = crypto_register_shash(&sha384_alg)) < 0)
crypto_unregister_alg(&sha512_alg); crypto_unregister_shash(&sha512_alg);
out: out:
return ret; return ret;
} }
static void __exit fini(void) static void __exit fini(void)
{ {
crypto_unregister_alg(&sha512_alg); crypto_unregister_shash(&sha512_alg);
crypto_unregister_alg(&sha384_alg); crypto_unregister_shash(&sha384_alg);
} }
module_init(init); module_init(init);
......
...@@ -13,14 +13,14 @@ ...@@ -13,14 +13,14 @@
* *
*/ */
#include <linux/crypto.h> #include <crypto/internal/hash.h>
#include "sha.h" #include "sha.h"
#include "crypt_s390.h" #include "crypt_s390.h"
void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) int s390_sha_update(struct shash_desc *desc, const u8 *data, unsigned int len)
{ {
struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
unsigned int bsize = crypto_tfm_alg_blocksize(tfm); unsigned int bsize = crypto_shash_blocksize(desc->tfm);
unsigned int index; unsigned int index;
int ret; int ret;
...@@ -51,13 +51,15 @@ void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) ...@@ -51,13 +51,15 @@ void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
store: store:
if (len) if (len)
memcpy(ctx->buf + index , data, len); memcpy(ctx->buf + index , data, len);
return 0;
} }
EXPORT_SYMBOL_GPL(s390_sha_update); EXPORT_SYMBOL_GPL(s390_sha_update);
void s390_sha_final(struct crypto_tfm *tfm, u8 *out) int s390_sha_final(struct shash_desc *desc, u8 *out)
{ {
struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
unsigned int bsize = crypto_tfm_alg_blocksize(tfm); unsigned int bsize = crypto_shash_blocksize(desc->tfm);
u64 bits; u64 bits;
unsigned int index, end, plen; unsigned int index, end, plen;
int ret; int ret;
...@@ -87,9 +89,11 @@ void s390_sha_final(struct crypto_tfm *tfm, u8 *out) ...@@ -87,9 +89,11 @@ void s390_sha_final(struct crypto_tfm *tfm, u8 *out)
BUG_ON(ret != end); BUG_ON(ret != end);
/* copy digest to out */ /* copy digest to out */
memcpy(out, ctx->state, crypto_hash_digestsize(crypto_hash_cast(tfm))); memcpy(out, ctx->state, crypto_shash_digestsize(desc->tfm));
/* wipe context */ /* wipe context */
memset(ctx, 0, sizeof *ctx); memset(ctx, 0, sizeof *ctx);
return 0;
} }
EXPORT_SYMBOL_GPL(s390_sha_final); EXPORT_SYMBOL_GPL(s390_sha_final);
......
...@@ -86,7 +86,7 @@ config ZCRYPT_MONOLITHIC ...@@ -86,7 +86,7 @@ config ZCRYPT_MONOLITHIC
config CRYPTO_SHA1_S390 config CRYPTO_SHA1_S390
tristate "SHA1 digest algorithm" tristate "SHA1 digest algorithm"
depends on S390 depends on S390
select CRYPTO_ALGAPI select CRYPTO_HASH
help help
This is the s390 hardware accelerated implementation of the This is the s390 hardware accelerated implementation of the
SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2). SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2).
...@@ -94,7 +94,7 @@ config CRYPTO_SHA1_S390 ...@@ -94,7 +94,7 @@ config CRYPTO_SHA1_S390
config CRYPTO_SHA256_S390 config CRYPTO_SHA256_S390
tristate "SHA256 digest algorithm" tristate "SHA256 digest algorithm"
depends on S390 depends on S390
select CRYPTO_ALGAPI select CRYPTO_HASH
help help
This is the s390 hardware accelerated implementation of the This is the s390 hardware accelerated implementation of the
SHA256 secure hash standard (DFIPS 180-2). SHA256 secure hash standard (DFIPS 180-2).
...@@ -105,7 +105,7 @@ config CRYPTO_SHA256_S390 ...@@ -105,7 +105,7 @@ config CRYPTO_SHA256_S390
config CRYPTO_SHA512_S390 config CRYPTO_SHA512_S390
tristate "SHA384 and SHA512 digest algorithm" tristate "SHA384 and SHA512 digest algorithm"
depends on S390 depends on S390
select CRYPTO_ALGAPI select CRYPTO_HASH
help help
This is the s390 hardware accelerated implementation of the This is the s390 hardware accelerated implementation of the
SHA512 secure hash standard. SHA512 secure hash standard.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment