Skip to content

Commit 5b13b8a

Browse files
committed
Linux kernel: updates to meet all extended test requirements
The following tests are not (yet) successful from the Linux extended test harness: - XTS fails as testing uses multiple SGLs - as outlined in the code only one SGL is supported - ChaCha20: testing uses fancy input data which is rejected by leancrypto with -EINVAL. - ChaCha20-Poly1305: testing uses fancy input data which is rejected by leancrypto with -EINVAL. Signed-off-by: Stephan Mueller <smueller@chronox.de>
1 parent f77f8fc commit 5b13b8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+549
-57
lines changed

aead/src/gcm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*******************************************************************************/
4646

4747
#include "aes_c.h"
48+
#include "../../sym/src/aes_internal.h"
4849
#include "alignment.h"
4950
#include "bitshift_be.h"
5051
#include "compare.h"
@@ -327,6 +328,10 @@ static int gcm_setkey(struct lc_aes_gcm_cryptor *ctx, const uint8_t *key,
327328
*/
328329
CKNULL(key, 0);
329330

331+
ret = aes_check_keylen(keylen);
332+
if (ret)
333+
return ret;
334+
330335
memset(h, 0, AES_BLOCKSIZE); /* initialize the block to encrypt */
331336

332337
/*

aead/tests/leancrypto_kernel_chacha20_poly1305_tester.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static int rfc7539_cc20p1305_tester(void)
392392
0xe2, 0x6a, 0x7e, 0x90, 0x2e, 0xcb,
393393
0xd0, 0x60, 0x06, 0x91 };
394394
pr_info("ChaCha20 Poly1305 crypt\n");
395-
return lc_aead_test("chacha20-rfc7539-poly1305-leancrypto", pt,
395+
return lc_aead_test("rfc7539-chacha20-poly1305-leancrypto", pt,
396396
sizeof(pt), iv, sizeof(iv), aad, sizeof(aad), key,
397397
sizeof(key), exp_ct, exp_tag, sizeof(exp_tag), 0);
398398
}
@@ -475,7 +475,7 @@ static int rfc7539esp_cc20p1305_tester(void)
475475
0xe2, 0x6a, 0x7e, 0x90, 0x2e, 0xcb,
476476
0xd0, 0x60, 0x06, 0x91 };
477477
pr_info("ESP ChaCha20 Poly1305 crypt\n");
478-
return lc_aead_test("chacha20-rfc7539esp-poly1305-leancrypto", pt,
478+
return lc_aead_test("rfc7539esp-chacha20-poly1305-leancrypto", pt,
479479
sizeof(pt), iv, sizeof(iv), aad, sizeof(aad), key,
480480
sizeof(key), exp_ct, exp_tag, sizeof(exp_tag), 1);
481481
}

linux_kernel/Kbuild.basics

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
################################################################################
2-
# Anchor to compile the leancrypto kernel support.
3-
#
4-
# When compiling leancrypto as a kernel module either in-tree or out-of-tree
5-
# use `obj-m`.
6-
#
7-
# When compiling leancrypto statically bound into the Linux kernel binary
8-
# from inside the Linux kernel tree, use `obj-y`.
9-
#
10-
obj-m := leancrypto.o
1+
obj-$(CONFIG_LEANCRYPTO) := leancrypto.o
112

123
# Kernel module framework
134
ccflags-y += -DLINUX_KERNEL

linux_kernel/Kbuild.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
############################## Basic Configuration #############################
1111

12+
#
13+
# Enable Leancrypto compilation
14+
# Dependencies: N/A
15+
# The option can either be either 'y' for static linking into the Linux kernel
16+
# (only applicable when compiling as part of the Linux kernel compilation) or
17+
# 'm' for compiling as a kernel module.
18+
#
19+
20+
CONFIG_LEANCRYPTO=m
21+
1222
#
1323
# Enable test kernel modules to be built
1424
# Dependencies: N/A

linux_kernel/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ the following steps have to be taken:
3939
`obj-y += leancrypto/linux_kernel/`
4040

4141
3. tell leancrypto to be compiled statically into the kernel by editing the file
42-
`leancrypto/linux_kernel/Kbuild.basics` and modifying the very first line
43-
to change `obj-m` to `obj-y`.
42+
`leancrypto/linux_kernel/Kbuild.config` and modify the option
43+
`CONFIG_LEANCRYPTO` to `y`.
4444

4545
At this point, leancrypto will now be built statically into the Linux kernel
4646
when compiling it. Naturally, all Linux kernel options can be set as leancrypto

linux_kernel/leancrypto_kernel_aes_cbc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ static int lc_aes_cbc_common(struct skcipher_request *req,
8080
err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
8181
}
8282

83-
return err;
83+
if (err)
84+
return err;
85+
86+
return lc_sym_getiv(ctx, req->iv, AES_BLOCK_SIZE);
8487
}
8588

8689
static int lc_aes_cbc_encrypt(struct skcipher_request *req)

linux_kernel/leancrypto_kernel_aes_ctr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ static int lc_aes_ctr_common(struct skcipher_request *req,
7777
err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
7878
}
7979

80-
return err;
80+
if (err)
81+
return err;
82+
83+
return lc_sym_getiv(ctx, req->iv, AES_BLOCK_SIZE);
8184
}
8285

8386
static int lc_aes_ctr_encrypt(struct skcipher_request *req)

linux_kernel/leancrypto_kernel_aes_xts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static int lc_aes_xts_common(struct skcipher_request *req,
153153
req->dst->length >= req->cryptlen)) {
154154
crypt_func(ctx, sg_virt(req->src), sg_virt(req->dst),
155155
req->cryptlen);
156-
return 0;
156+
return lc_sym_getiv(ctx, req->iv, AES_BLOCK_SIZE);
157157
}
158158

159159
return lc_aes_xts_slowpath(req, crypt_func);

linux_kernel/leancrypto_kernel_chacha20_poly1305.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ static void lc_cc20p1305_exit(struct crypto_aead *aead)
253253
static struct aead_alg lc_cc20p1305_algs[] = {
254254
{
255255
.base = {
256-
.cra_name = "chacha20(rfc7539,poly1305)",
257-
.cra_driver_name = "chacha20-rfc7539-poly1305-leancrypto",
256+
.cra_name = "rfc7539(chacha20,poly1305)",
257+
.cra_driver_name = "rfc7539-chacha20-poly1305-leancrypto",
258258
.cra_priority = LC_KERNEL_DEFAULT_PRIO,
259259
.cra_blocksize = 1,
260260
.cra_ctxsize = sizeof(struct lc_rfc7539_cc20p1305_ctx),
@@ -271,8 +271,8 @@ static struct aead_alg lc_cc20p1305_algs[] = {
271271
.maxauthsize = POLY1305_DIGEST_SIZE,
272272
}, {
273273
.base = {
274-
.cra_name = "chacha20(rfc7539esp,poly1305)",
275-
.cra_driver_name = "chacha20-rfc7539esp-poly1305-leancrypto",
274+
.cra_name = "rfc7539esp(chacha20,poly1305)",
275+
.cra_driver_name = "rfc7539esp-chacha20-poly1305-leancrypto",
276276
.cra_priority = LC_KERNEL_DEFAULT_PRIO,
277277
.cra_blocksize = 1,
278278
.cra_ctxsize = sizeof(struct lc_rfc7539_cc20p1305_ctx),

linux_kernel/leancrypto_kernel_sha3.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ static struct shash_alg lc_sha3_algs[] = {
8585
.update = lc_kernel_sha3_update,
8686
.final = lc_kernel_sha3_final,
8787
.descsize = LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_224_CTX_SIZE),
88-
.statesize = LC_SHA3_STATE_SIZE,
8988
.base.cra_name = "sha3-224",
9089
.base.cra_driver_name = "sha3-224-leancrypto",
9190
.base.cra_blocksize = LC_SHA3_224_SIZE_BLOCK,
@@ -98,7 +97,6 @@ static struct shash_alg lc_sha3_algs[] = {
9897
.update = lc_kernel_sha3_update,
9998
.final = lc_kernel_sha3_final,
10099
.descsize = LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_256_CTX_SIZE),
101-
.statesize = LC_SHA3_STATE_SIZE,
102100
.base.cra_name = "sha3-256",
103101
.base.cra_driver_name = "sha3-256-leancrypto",
104102
.base.cra_blocksize = LC_SHA3_256_SIZE_BLOCK,
@@ -111,7 +109,6 @@ static struct shash_alg lc_sha3_algs[] = {
111109
.update = lc_kernel_sha3_update,
112110
.final = lc_kernel_sha3_final,
113111
.descsize = LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_384_CTX_SIZE),
114-
.statesize = LC_SHA3_STATE_SIZE,
115112
.base.cra_name = "sha3-384",
116113
.base.cra_driver_name = "sha3-384-leancrypto",
117114
.base.cra_blocksize = LC_SHA3_384_SIZE_BLOCK,
@@ -124,7 +121,6 @@ static struct shash_alg lc_sha3_algs[] = {
124121
.update = lc_kernel_sha3_update,
125122
.final = lc_kernel_sha3_final,
126123
.descsize = LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_512_CTX_SIZE),
127-
.statesize = LC_SHA3_STATE_SIZE,
128124
.base.cra_name = "sha3-512",
129125
.base.cra_driver_name = "sha3-512-leancrypto",
130126
.base.cra_blocksize = LC_SHA3_512_SIZE_BLOCK,

0 commit comments

Comments
 (0)