Skip to content

Commit 17fee07

Browse files
nhukcherbertx
authored andcommitted
crypto: xctr - Add XCTR support
Add a generic implementation of XCTR mode as a template. XCTR is a blockcipher mode similar to CTR mode. XCTR uses XORs and little-endian addition rather than big-endian arithmetic which has two advantages: It is slightly faster on little-endian CPUs and it is less likely to be implemented incorrect since integer overflows are not possible on practical input sizes. XCTR is used as a component to implement HCTR2. More information on XCTR mode can be found in the HCTR2 paper: https://eprint.iacr.org/2021/1441.pdf Signed-off-by: Nathan Huckleberry <[email protected]> Reviewed-by: Eric Biggers <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 7df7563 commit 17fee07

File tree

6 files changed

+901
-0
lines changed

6 files changed

+901
-0
lines changed

crypto/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,15 @@ config CRYPTO_PCBC
460460
PCBC: Propagating Cipher Block Chaining mode
461461
This block cipher algorithm is required for RxRPC.
462462

463+
config CRYPTO_XCTR
464+
tristate
465+
select CRYPTO_SKCIPHER
466+
select CRYPTO_MANAGER
467+
help
468+
XCTR: XOR Counter mode. This blockcipher mode is a variant of CTR mode
469+
using XORs and little-endian addition rather than big-endian arithmetic.
470+
XCTR mode is used to implement HCTR2.
471+
463472
config CRYPTO_XTS
464473
tristate "XTS support"
465474
select CRYPTO_SKCIPHER

crypto/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ obj-$(CONFIG_CRYPTO_CTS) += cts.o
9494
obj-$(CONFIG_CRYPTO_LRW) += lrw.o
9595
obj-$(CONFIG_CRYPTO_XTS) += xts.o
9696
obj-$(CONFIG_CRYPTO_CTR) += ctr.o
97+
obj-$(CONFIG_CRYPTO_XCTR) += xctr.o
9798
obj-$(CONFIG_CRYPTO_KEYWRAP) += keywrap.o
9899
obj-$(CONFIG_CRYPTO_ADIANTUM) += adiantum.o
99100
obj-$(CONFIG_CRYPTO_NHPOLY1305) += nhpoly1305.o

crypto/tcrypt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,7 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
15561556
ret += tcrypt_test("rfc3686(ctr(aes))");
15571557
ret += tcrypt_test("ofb(aes)");
15581558
ret += tcrypt_test("cfb(aes)");
1559+
ret += tcrypt_test("xctr(aes)");
15591560
break;
15601561

15611562
case 11:

crypto/testmgr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,6 +5548,12 @@ static const struct alg_test_desc alg_test_descs[] = {
55485548
.suite = {
55495549
.cipher = __VECS(xchacha20_tv_template)
55505550
},
5551+
}, {
5552+
.alg = "xctr(aes)",
5553+
.test = alg_test_skcipher,
5554+
.suite = {
5555+
.cipher = __VECS(aes_xctr_tv_template)
5556+
}
55515557
}, {
55525558
.alg = "xts(aes)",
55535559
.generic_driver = "xts(ecb(aes-generic))",

0 commit comments

Comments
 (0)