Commit b7e8bdad authored by Herbert Xu's avatar Herbert Xu

crypto: crc32c-intel - Switch to shash

This patch changes crc32c-intel to the new shash interface.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent faccc4bb
...@@ -84,99 +84,92 @@ static u32 __pure crc32c_intel_le_hw(u32 crc, unsigned char const *p, size_t len ...@@ -84,99 +84,92 @@ static u32 __pure crc32c_intel_le_hw(u32 crc, unsigned char const *p, size_t len
* If your algorithm starts with ~0, then XOR with ~0 before you set * If your algorithm starts with ~0, then XOR with ~0 before you set
* the seed. * the seed.
*/ */
static int crc32c_intel_setkey(struct crypto_ahash *hash, const u8 *key, static int crc32c_intel_setkey(struct crypto_shash *hash, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
u32 *mctx = crypto_ahash_ctx(hash); u32 *mctx = crypto_shash_ctx(hash);
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32)) {
crypto_ahash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN); crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
*mctx = le32_to_cpup((__le32 *)key); *mctx = le32_to_cpup((__le32 *)key);
return 0; return 0;
} }
static int crc32c_intel_init(struct ahash_request *req) static int crc32c_intel_init(struct shash_desc *desc)
{ {
u32 *mctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req)); u32 *mctx = crypto_shash_ctx(desc->tfm);
u32 *crcp = ahash_request_ctx(req); u32 *crcp = shash_desc_ctx(desc);
*crcp = *mctx; *crcp = *mctx;
return 0; return 0;
} }
static int crc32c_intel_update(struct ahash_request *req) static int crc32c_intel_update(struct shash_desc *desc, const u8 *data,
unsigned int len)
{ {
struct crypto_hash_walk walk; u32 *crcp = shash_desc_ctx(desc);
u32 *crcp = ahash_request_ctx(req);
u32 crc = *crcp;
int nbytes;
for (nbytes = crypto_hash_walk_first(req, &walk); nbytes; *crcp = crc32c_intel_le_hw(*crcp, data, len);
nbytes = crypto_hash_walk_done(&walk, 0))
crc = crc32c_intel_le_hw(crc, walk.data, nbytes);
*crcp = crc;
return 0; return 0;
} }
static int crc32c_intel_final(struct ahash_request *req) static int __crc32c_intel_finup(u32 *crcp, const u8 *data, unsigned int len,
u8 *out)
{ {
u32 *crcp = ahash_request_ctx(req); *(__le32 *)out = ~cpu_to_le32(crc32c_intel_le_hw(*crcp, data, len));
*(__le32 *)req->result = ~cpu_to_le32p(crcp);
return 0; return 0;
} }
static int crc32c_intel_digest(struct ahash_request *req) static int crc32c_intel_finup(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out)
{ {
struct crypto_hash_walk walk; return __crc32c_intel_finup(shash_desc_ctx(desc), data, len, out);
u32 *mctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req)); }
u32 crc = *mctx;
int nbytes;
for (nbytes = crypto_hash_walk_first(req, &walk); nbytes; static int crc32c_intel_final(struct shash_desc *desc, u8 *out)
nbytes = crypto_hash_walk_done(&walk, 0)) {
crc = crc32c_intel_le_hw(crc, walk.data, nbytes); u32 *crcp = shash_desc_ctx(desc);
*(__le32 *)req->result = ~cpu_to_le32(crc); *(__le32 *)out = ~cpu_to_le32p(crcp);
return 0; return 0;
} }
static int crc32c_intel_digest(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out)
{
return __crc32c_intel_finup(crypto_shash_ctx(desc->tfm), data, len,
out);
}
static int crc32c_intel_cra_init(struct crypto_tfm *tfm) static int crc32c_intel_cra_init(struct crypto_tfm *tfm)
{ {
u32 *key = crypto_tfm_ctx(tfm); u32 *key = crypto_tfm_ctx(tfm);
*key = ~0; *key = ~0;
tfm->crt_ahash.reqsize = sizeof(u32);
return 0; return 0;
} }
static struct crypto_alg alg = { static struct shash_alg alg = {
.cra_name = "crc32c", .setkey = crc32c_intel_setkey,
.cra_driver_name = "crc32c-intel", .init = crc32c_intel_init,
.cra_priority = 200, .update = crc32c_intel_update,
.cra_flags = CRYPTO_ALG_TYPE_AHASH, .final = crc32c_intel_final,
.cra_blocksize = CHKSUM_BLOCK_SIZE, .finup = crc32c_intel_finup,
.cra_alignmask = 3, .digest = crc32c_intel_digest,
.cra_ctxsize = sizeof(u32), .descsize = sizeof(u32),
.cra_module = THIS_MODULE, .digestsize = CHKSUM_DIGEST_SIZE,
.cra_list = LIST_HEAD_INIT(alg.cra_list), .base = {
.cra_init = crc32c_intel_cra_init, .cra_name = "crc32c",
.cra_type = &crypto_ahash_type, .cra_driver_name = "crc32c-intel",
.cra_u = { .cra_priority = 200,
.ahash = { .cra_blocksize = CHKSUM_BLOCK_SIZE,
.digestsize = CHKSUM_DIGEST_SIZE, .cra_ctxsize = sizeof(u32),
.setkey = crc32c_intel_setkey, .cra_module = THIS_MODULE,
.init = crc32c_intel_init, .cra_init = crc32c_intel_cra_init,
.update = crc32c_intel_update,
.final = crc32c_intel_final,
.digest = crc32c_intel_digest,
}
} }
}; };
...@@ -184,14 +177,14 @@ static struct crypto_alg alg = { ...@@ -184,14 +177,14 @@ static struct crypto_alg alg = {
static int __init crc32c_intel_mod_init(void) static int __init crc32c_intel_mod_init(void)
{ {
if (cpu_has_xmm4_2) if (cpu_has_xmm4_2)
return crypto_register_alg(&alg); return crypto_register_shash(&alg);
else else
return -ENODEV; return -ENODEV;
} }
static void __exit crc32c_intel_mod_fini(void) static void __exit crc32c_intel_mod_fini(void)
{ {
crypto_unregister_alg(&alg); crypto_unregister_shash(&alg);
} }
module_init(crc32c_intel_mod_init); module_init(crc32c_intel_mod_init);
......
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