14 #include <linux/module.h>
16 #include <linux/kernel.h>
25 #define GHASH_BLOCK_SIZE 16
26 #define GHASH_DIGEST_SIZE 16
52 memset(dctx, 0,
sizeof(*dctx));
58 const u8 *
key,
unsigned int keylen)
72 static int ghash_update(
struct shash_desc *desc,
73 const u8 *
src,
unsigned int srclen)
98 src += srclen - (srclen & 0xf);
115 while (dctx->
bytes--)
126 static int ghash_final(
struct shash_desc *desc,
u8 *dst)
132 ghash_flush(ctx, dctx);
141 .update = ghash_update,
142 .final = ghash_final,
143 .setkey = ghash_setkey,
146 .cra_name =
"__ghash",
147 .cra_driver_name =
"__ghash-pclmulqdqni",
164 memcpy(cryptd_req, req,
sizeof(*req));
165 ahash_request_set_tfm(cryptd_req, &cryptd_tfm->
base);
166 return crypto_ahash_init(cryptd_req);
173 return crypto_shash_init(desc);
186 memcpy(cryptd_req, req,
sizeof(*req));
187 ahash_request_set_tfm(cryptd_req, &cryptd_tfm->
base);
188 return crypto_ahash_update(cryptd_req);
204 memcpy(cryptd_req, req,
sizeof(*req));
205 ahash_request_set_tfm(cryptd_req, &cryptd_tfm->
base);
221 memcpy(cryptd_req, req,
sizeof(*req));
222 ahash_request_set_tfm(cryptd_req, &cryptd_tfm->
base);
234 static int ghash_async_setkey(
struct crypto_ahash *tfm,
const u8 *key,
242 crypto_ahash_set_flags(child, crypto_ahash_get_flags(tfm)
245 crypto_ahash_set_flags(tfm, crypto_ahash_get_flags(child)
251 static int ghash_async_init_tfm(
struct crypto_tfm *tfm)
257 if (IS_ERR(cryptd_tfm))
258 return PTR_ERR(cryptd_tfm);
260 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
262 crypto_ahash_reqsize(&cryptd_tfm->
base));
267 static void ghash_async_exit_tfm(
struct crypto_tfm *tfm)
274 static struct ahash_alg ghash_async_alg = {
275 .init = ghash_async_init,
276 .update = ghash_async_update,
277 .final = ghash_async_final,
278 .setkey = ghash_async_setkey,
279 .digest = ghash_async_digest,
284 .cra_driver_name =
"ghash-clmulni",
290 .cra_init = ghash_async_init_tfm,
291 .cra_exit = ghash_async_exit_tfm,
296 static const struct x86_cpu_id pcmul_cpu_id[] = {
302 static int __init ghash_pclmulqdqni_mod_init(
void)
324 static void __exit ghash_pclmulqdqni_mod_exit(
void)
335 "acclerated by PCLMULQDQ-NI");