Skip to content

Commit 2fe366c

Browse files
committed
wolfcrypt/test/test.c: add test coverage for WOLFSSL_AESXTS_STREAM.
linuxkm/lkcapi_glue.c: typographic cleanups, and failsafe error return constructs when skcipher_walk_virt() returns zero walk.nbytes. wolfcrypt/src/aes.c: additional comments and inline documentation. .github/workflows/openvpn.yml: disable test on master branch.
1 parent 8392748 commit 2fe366c

4 files changed

Lines changed: 363 additions & 30 deletions

File tree

.github/workflows/openvpn.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ jobs:
3939
fail-fast: false
4040
matrix:
4141
# List of refs to test
42-
ref: [ release/2.6, v2.6.0, master ]
42+
# disabled master on 20240514 -- see https://github.com/wolfSSL/wolfssl/issues/7508
43+
ref: [ release/2.6, v2.6.0 ]
4344
name: ${{ matrix.ref }}
4445
runs-on: ubuntu-latest
4546
# This should be a safe limit for the tests to run.

linuxkm/lkcapi_glue.c

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ static int km_AesXtsEncrypt(struct skcipher_request *req)
925925

926926
err = skcipher_walk_virt(&walk, req, false);
927927
if (!walk.nbytes)
928-
return err;
928+
return err ? : -EINVAL;
929929
} else {
930930
tail = 0;
931931
}
@@ -939,6 +939,9 @@ static int km_AesXtsEncrypt(struct skcipher_request *req)
939939
}
940940

941941
while ((nbytes = walk.nbytes) != 0) {
942+
/* if this isn't the final call, pass block-aligned data to prevent
943+
* end-of-message ciphertext stealing.
944+
*/
942945
if (nbytes < walk.total)
943946
nbytes &= ~(AES_BLOCK_SIZE - 1);
944947

@@ -961,7 +964,7 @@ static int km_AesXtsEncrypt(struct skcipher_request *req)
961964
}
962965
}
963966

964-
if (unlikely(tail > 0 && !err)) {
967+
if (unlikely(tail > 0)) {
965968
struct scatterlist sg_src[2], sg_dst[2];
966969
struct scatterlist *src, *dst;
967970

@@ -1048,7 +1051,7 @@ static int km_AesXtsDecrypt(struct skcipher_request *req)
10481051

10491052
err = skcipher_walk_virt(&walk, req, false);
10501053
if (!walk.nbytes)
1051-
return err;
1054+
return err ? : -EINVAL;
10521055
} else {
10531056
tail = 0;
10541057
}
@@ -1062,6 +1065,9 @@ static int km_AesXtsDecrypt(struct skcipher_request *req)
10621065
}
10631066

10641067
while ((nbytes = walk.nbytes) != 0) {
1068+
/* if this isn't the final call, pass block-aligned data to prevent
1069+
* end-of-message ciphertext stealing.
1070+
*/
10651071
if (nbytes < walk.total)
10661072
nbytes &= ~(AES_BLOCK_SIZE - 1);
10671073

@@ -1084,32 +1090,32 @@ static int km_AesXtsDecrypt(struct skcipher_request *req)
10841090
}
10851091
}
10861092

1087-
if (unlikely(tail > 0 && !err)) {
1088-
struct scatterlist sg_src[2], sg_dst[2];
1089-
struct scatterlist *src, *dst;
1093+
if (unlikely(tail > 0)) {
1094+
struct scatterlist sg_src[2], sg_dst[2];
1095+
struct scatterlist *src, *dst;
10901096

1091-
dst = src = scatterwalk_ffwd(sg_src, req->src, req->cryptlen);
1092-
if (req->dst != req->src)
1093-
dst = scatterwalk_ffwd(sg_dst, req->dst, req->cryptlen);
1097+
dst = src = scatterwalk_ffwd(sg_src, req->src, req->cryptlen);
1098+
if (req->dst != req->src)
1099+
dst = scatterwalk_ffwd(sg_dst, req->dst, req->cryptlen);
10941100

1095-
skcipher_request_set_crypt(req, src, dst, AES_BLOCK_SIZE + tail,
1096-
req->iv);
1101+
skcipher_request_set_crypt(req, src, dst, AES_BLOCK_SIZE + tail,
1102+
req->iv);
10971103

1098-
err = skcipher_walk_virt(&walk, &subreq, false);
1099-
if (err)
1100-
return err;
1104+
err = skcipher_walk_virt(&walk, &subreq, false);
1105+
if (err)
1106+
return err;
11011107

1102-
err = wc_AesXtsDecryptUpdate(ctx->aesXts, walk.dst.virt.addr,
1103-
walk.src.virt.addr, walk.nbytes,
1104-
walk.iv);
1108+
err = wc_AesXtsDecryptUpdate(ctx->aesXts, walk.dst.virt.addr,
1109+
walk.src.virt.addr, walk.nbytes,
1110+
walk.iv);
11051111

1106-
if (unlikely(err)) {
1107-
pr_err("%s: wc_AesXtsDecryptUpdate failed: %d\n",
1108-
crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm)), err);
1109-
return -EINVAL;
1110-
}
1112+
if (unlikely(err)) {
1113+
pr_err("%s: wc_AesXtsDecryptUpdate failed: %d\n",
1114+
crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm)), err);
1115+
return -EINVAL;
1116+
}
11111117

1112-
err = skcipher_walk_done(&walk, 0);
1118+
err = skcipher_walk_done(&walk, 0);
11131119
}
11141120

11151121
}

wolfcrypt/src/aes.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12840,6 +12840,15 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1284012840

1284112841
#ifdef WOLFSSL_AESXTS_STREAM
1284212842

12843+
/* Block-streaming AES-XTS.
12844+
*
12845+
* xaes AES keys to use for block encrypt/decrypt
12846+
* i readwrite value to use for tweak
12847+
* iSz size of i buffer, should always be AES_BLOCK_SIZE but having this input
12848+
* adds a sanity check on how the user calls the function.
12849+
*
12850+
* returns 0 on success
12851+
*/
1284312852
int wc_AesXtsEncryptInit(XtsAes* xaes, byte* i, word32 iSz)
1284412853
{
1284512854
int ret;
@@ -12894,12 +12903,15 @@ int wc_AesXtsEncryptInit(XtsAes* xaes, byte* i, word32 iSz)
1289412903
return ret;
1289512904
}
1289612905

12897-
/* AES with XTS mode. (XTS) XEX encryption with Tweak and cipher text Stealing.
12906+
/* Block-streaming AES-XTS
12907+
*
12908+
* Note that sz must be greater than AES_BLOCK_SIZE in each call, and must be a
12909+
* multiple of AES_BLOCK_SIZE in all but the final call.
1289812910
*
1289912911
* xaes AES keys to use for block encrypt/decrypt
1290012912
* out output buffer to hold cipher text
1290112913
* in input plain text buffer to encrypt
12902-
* sz size of both out and in buffers
12914+
* sz size of both out and in buffers -- must be >= AES_BLOCK_SIZE.
1290312915
* i value to use for tweak
1290412916
* iSz size of i buffer, should always be AES_BLOCK_SIZE but having this input
1290512917
* adds a sanity check on how the user calls the function.
@@ -13211,7 +13223,6 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1321113223
* i readwrite value to use for tweak
1321213224
* iSz size of i buffer, should always be AES_BLOCK_SIZE but having this input
1321313225
* adds a sanity check on how the user calls the function.
13214-
* tweak_block buffer of size AES_BLOCK_SIZE to use for tweak state
1321513226
*
1321613227
* returns 0 on success
1321713228
*/
@@ -13269,7 +13280,10 @@ int wc_AesXtsDecryptInit(XtsAes* xaes, byte* i, word32 iSz)
1326913280
return ret;
1327013281
}
1327113282

13272-
/* Same process as encryption but Aes key is AES_DECRYPTION type.
13283+
/* Block-streaming AES-XTS
13284+
*
13285+
* Note that sz must be greater than AES_BLOCK_SIZE in each call, and must be a
13286+
* multiple of AES_BLOCK_SIZE in all but the final call.
1327313287
*
1327413288
* xaes AES keys to use for block encrypt/decrypt
1327513289
* out output buffer to hold plain text

0 commit comments

Comments
 (0)