1 // SPDX-License-Identifier: GPL-2.0-only
3 * Accelerated CRC-T10DIF using ARM NEON and Crypto Extensions instructions
5 * Copyright (C) 2016 Linaro Ltd <ard.biesheuvel@linaro.org>
8 #include <linux/crc-t10dif.h>
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/string.h>
14 #include <crypto/internal/hash.h>
15 #include <crypto/internal/simd.h>
20 #define CRC_T10DIF_PMULL_CHUNK_SIZE 16U
22 asmlinkage u16
crc_t10dif_pmull64(u16 init_crc
, const u8
*buf
, size_t len
);
23 asmlinkage
void crc_t10dif_pmull8(u16 init_crc
, const u8
*buf
, size_t len
,
26 static int crct10dif_init(struct shash_desc
*desc
)
28 u16
*crc
= shash_desc_ctx(desc
);
34 static int crct10dif_update_ce(struct shash_desc
*desc
, const u8
*data
,
37 u16
*crc
= shash_desc_ctx(desc
);
39 if (length
>= CRC_T10DIF_PMULL_CHUNK_SIZE
&& crypto_simd_usable()) {
41 *crc
= crc_t10dif_pmull64(*crc
, data
, length
);
44 *crc
= crc_t10dif_generic(*crc
, data
, length
);
50 static int crct10dif_update_neon(struct shash_desc
*desc
, const u8
*data
,
53 u16
*crcp
= shash_desc_ctx(desc
);
54 u8 buf
[16] __aligned(16);
57 if (length
> CRC_T10DIF_PMULL_CHUNK_SIZE
&& crypto_simd_usable()) {
59 crc_t10dif_pmull8(crc
, data
, length
, buf
);
67 *crcp
= crc_t10dif_generic(crc
, data
, length
);
71 static int crct10dif_final(struct shash_desc
*desc
, u8
*out
)
73 u16
*crc
= shash_desc_ctx(desc
);
79 static struct shash_alg algs
[] = {{
80 .digestsize
= CRC_T10DIF_DIGEST_SIZE
,
81 .init
= crct10dif_init
,
82 .update
= crct10dif_update_neon
,
83 .final
= crct10dif_final
,
84 .descsize
= CRC_T10DIF_DIGEST_SIZE
,
86 .base
.cra_name
= "crct10dif",
87 .base
.cra_driver_name
= "crct10dif-arm-neon",
88 .base
.cra_priority
= 150,
89 .base
.cra_blocksize
= CRC_T10DIF_BLOCK_SIZE
,
90 .base
.cra_module
= THIS_MODULE
,
92 .digestsize
= CRC_T10DIF_DIGEST_SIZE
,
93 .init
= crct10dif_init
,
94 .update
= crct10dif_update_ce
,
95 .final
= crct10dif_final
,
96 .descsize
= CRC_T10DIF_DIGEST_SIZE
,
98 .base
.cra_name
= "crct10dif",
99 .base
.cra_driver_name
= "crct10dif-arm-ce",
100 .base
.cra_priority
= 200,
101 .base
.cra_blocksize
= CRC_T10DIF_BLOCK_SIZE
,
102 .base
.cra_module
= THIS_MODULE
,
105 static int __init
crc_t10dif_mod_init(void)
107 if (!(elf_hwcap
& HWCAP_NEON
))
110 return crypto_register_shashes(algs
, 1 + !!(elf_hwcap2
& HWCAP2_PMULL
));
113 static void __exit
crc_t10dif_mod_exit(void)
115 crypto_unregister_shashes(algs
, 1 + !!(elf_hwcap2
& HWCAP2_PMULL
));
118 module_init(crc_t10dif_mod_init
);
119 module_exit(crc_t10dif_mod_exit
);
121 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
122 MODULE_DESCRIPTION("Accelerated CRC-T10DIF using ARM NEON and Crypto Extensions");
123 MODULE_LICENSE("GPL v2");
124 MODULE_ALIAS_CRYPTO("crct10dif");