* [PATCH 0/6] crypto: test that CBC and CTR update the IV
@ 2019-02-14 8:03 Eric Biggers
2019-02-14 8:03 ` [PATCH 1/6] crypto: testmgr - remove extra bytes from 3DES-CTR IVs Eric Biggers
` (6 more replies)
0 siblings, 7 replies; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:03 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Hello,
This series makes the crypto self-tests test that all CBC and CTR
implementations update req->iv to contain the IV for the next block.
This apparently has been a requirement for a long time, but it wasn't
actually tested for.
With this series applied, all self-tests pass on x86_64, arm32, and
arm64. But I'm not able to test hardware drivers, so possibly some of
them will fail and still need to be fixed.
Eric Biggers (6):
crypto: testmgr - remove extra bytes from 3DES-CTR IVs
crypto: testmgr - support checking skcipher output IV
crypto: testmgr - add iv_out to all CBC test vectors
crypto: testmgr - add iv_out to all CTR test vectors
crypto: arm64/aes-blk - update IV after partial final CTR block
crypto: arm/aes-ce - update IV after partial final CTR block
arch/arm/crypto/aes-ce-core.S | 26 ++++----
arch/arm64/crypto/aes-modes.S | 3 +-
crypto/testmgr.c | 6 +-
crypto/testmgr.h | 111 +++++++++++++++++++++++++++++++---
4 files changed, 120 insertions(+), 26 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/6] crypto: testmgr - remove extra bytes from 3DES-CTR IVs
2019-02-14 8:03 [PATCH 0/6] crypto: test that CBC and CTR update the IV Eric Biggers
@ 2019-02-14 8:03 ` Eric Biggers
2019-02-14 8:03 ` [PATCH 2/6] crypto: testmgr - support checking skcipher output IV Eric Biggers
` (5 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:03 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
From: Eric Biggers <ebiggers@google.com>
3DES only has an 8-byte block size, but the 3DES-CTR test vectors use
16-byte IVs. Remove the unused 8 bytes from the ends of the IVs.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/testmgr.h | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 8f1d30b54a76..e01c77eeded3 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -7580,8 +7580,7 @@ static const struct cipher_testvec des3_ede_ctr_tv_template[] = {
"\x5A\x67\x00\x2D\xCE\xEB\x2D\xCE"
"\xEB\xB4\x51\x72\xB4\x51\x72\x1F",
.klen = 24,
- .iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
- "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD",
+ .iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
.ptext = "\x05\xEC\x77\xFB\x42\xD5\x59\x20"
"\x8B\x12\x86\x69\xF0\x5B\xCF\x56"
"\x39\xAD\x34\x9F\x66\xEA\x7D\xC4"
@@ -7712,8 +7711,7 @@ static const struct cipher_testvec des3_ede_ctr_tv_template[] = {
"\x5A\x67\x00\x2D\xCE\xEB\x2D\xCE"
"\xEB\xB4\x51\x72\xB4\x51\x72\x1F",
.klen = 24,
- .iv = "\xB2\xD7\x48\xED\x06\x44\xF9\x12"
- "\xB7\x28\x4D\x83\x24\x59\xF2\x17",
+ .iv = "\xB2\xD7\x48\xED\x06\x44\xF9\x12",
.ptext = "\x05\xEC\x77\xFB\x42\xD5\x59\x20"
"\x8B\x12\x86\x69\xF0\x5B\xCF\x56"
"\x39\xAD\x34\x9F\x66\xEA\x7D\xC4"
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/6] crypto: testmgr - support checking skcipher output IV
2019-02-14 8:03 [PATCH 0/6] crypto: test that CBC and CTR update the IV Eric Biggers
2019-02-14 8:03 ` [PATCH 1/6] crypto: testmgr - remove extra bytes from 3DES-CTR IVs Eric Biggers
@ 2019-02-14 8:03 ` Eric Biggers
2019-02-14 8:03 ` [PATCH 3/6] crypto: testmgr - add iv_out to all CBC test vectors Eric Biggers
` (4 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:03 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
From: Eric Biggers <ebiggers@google.com>
Allow skcipher test vectors to declare the value the IV buffer should be
updated to at the end of the encryption or decryption operation.
(This check actually used to be supported in testmgr, but it was never
used and therefore got removed except for the AES-Keywrap special case.
But it will be used by CBC and CTR now, so re-add it.)
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/testmgr.c | 6 ++++--
crypto/testmgr.h | 12 +++++++-----
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index d582a2758feb..8386038d67c7 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1542,7 +1542,9 @@ static int test_skcipher_vec_cfg(const char *driver, int enc,
if (ivsize) {
if (WARN_ON(ivsize > MAX_IVLEN))
return -EINVAL;
- if (vec->iv && !(vec->generates_iv && enc))
+ if (vec->generates_iv && !enc)
+ memcpy(iv, vec->iv_out, ivsize);
+ else if (vec->iv)
memcpy(iv, vec->iv, ivsize);
else
memset(iv, 0, ivsize);
@@ -1635,7 +1637,7 @@ static int test_skcipher_vec_cfg(const char *driver, int enc,
}
/* If applicable, check that the algorithm generated the correct IV */
- if (vec->generates_iv && enc && memcmp(iv, vec->iv, ivsize) != 0) {
+ if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) {
pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n",
driver, op, vec_num, cfg->name);
hexdump(iv, ivsize);
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index e01c77eeded3..980f7abb6115 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -47,7 +47,8 @@ struct hash_testvec {
* cipher_testvec: structure to describe a symmetric cipher test
* @key: Pointer to key
* @klen: Length of @key in bytes
- * @iv: Pointer to IV (optional for some ciphers)
+ * @iv: Pointer to IV. If NULL, an all-zeroes IV is used.
+ * @iv_out: Pointer to output IV, if applicable for the cipher.
* @ptext: Pointer to plaintext
* @ctext: Pointer to ciphertext
* @len: Length of @ptext and @ctext in bytes
@@ -55,12 +56,13 @@ struct hash_testvec {
* @wk: Does the test need CRYPTO_TFM_REQ_FORBID_WEAK_KEYS?
* ( e.g. test needs to fail due to a weak key )
* @fips_skip: Skip the test vector in FIPS mode
- * @generates_iv: Encryption should ignore the given IV, and output @iv.
- * Decryption takes @iv. Needed for AES Keywrap ("kw(aes)").
+ * @generates_iv: Encryption should ignore the given IV, and output @iv_out.
+ * Decryption takes @iv_out. Needed for AES Keywrap ("kw(aes)").
*/
struct cipher_testvec {
const char *key;
const char *iv;
+ const char *iv_out;
const char *ptext;
const char *ctext;
bool fail;
@@ -21771,7 +21773,7 @@ static const struct cipher_testvec aes_kw_tv_template[] = {
.ctext = "\xf6\x85\x94\x81\x6f\x64\xca\xa3"
"\xf5\x6f\xab\xea\x25\x48\xf5\xfb",
.len = 16,
- .iv = "\x03\x1f\x6b\xd7\xe6\x1e\x64\x3d",
+ .iv_out = "\x03\x1f\x6b\xd7\xe6\x1e\x64\x3d",
.generates_iv = true,
}, {
.key = "\x80\xaa\x99\x73\x27\xa4\x80\x6b"
@@ -21784,7 +21786,7 @@ static const struct cipher_testvec aes_kw_tv_template[] = {
.ctext = "\xd3\x3d\x3d\x97\x7b\xf0\xa9\x15"
"\x59\xf9\x9c\x8a\xcd\x29\x3d\x43",
.len = 16,
- .iv = "\x42\x3c\x96\x0d\x8a\x2a\xc4\xc1",
+ .iv_out = "\x42\x3c\x96\x0d\x8a\x2a\xc4\xc1",
.generates_iv = true,
},
};
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/6] crypto: testmgr - add iv_out to all CBC test vectors
2019-02-14 8:03 [PATCH 0/6] crypto: test that CBC and CTR update the IV Eric Biggers
2019-02-14 8:03 ` [PATCH 1/6] crypto: testmgr - remove extra bytes from 3DES-CTR IVs Eric Biggers
2019-02-14 8:03 ` [PATCH 2/6] crypto: testmgr - support checking skcipher output IV Eric Biggers
@ 2019-02-14 8:03 ` Eric Biggers
2019-02-14 8:03 ` [PATCH 4/6] crypto: testmgr - add iv_out to all CTR " Eric Biggers
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:03 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
From: Eric Biggers <ebiggers@google.com>
Test that all CBC implementations update the IV buffer to contain the
last ciphertext block, aka the IV to continue the encryption/decryption
of a larger message. Users may rely on this for chaining.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/testmgr.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 980f7abb6115..3e68d4062e51 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -7007,6 +7007,7 @@ static const struct cipher_testvec des_cbc_tv_template[] = {
.key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
.klen = 8,
.iv = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
+ .iv_out = "\x46\x8e\x91\x15\x78\x88\xba\x68",
.ptext = "\x37\x36\x35\x34\x33\x32\x31\x20"
"\x4e\x6f\x77\x20\x69\x73\x20\x74"
"\x68\x65\x20\x74\x69\x6d\x65\x20",
@@ -7018,6 +7019,7 @@ static const struct cipher_testvec des_cbc_tv_template[] = {
.key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
.klen = 8,
.iv = "\x12\x34\x56\x78\x90\xab\xcd\xef",
+ .iv_out = "\xe5\xc7\xcd\xde\x87\x2b\xf2\x7c",
.ptext = "\x4e\x6f\x77\x20\x69\x73\x20\x74",
.ctext = "\xe5\xc7\xcd\xde\x87\x2b\xf2\x7c",
.len = 8,
@@ -7025,6 +7027,7 @@ static const struct cipher_testvec des_cbc_tv_template[] = {
.key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
.klen = 8,
.iv = "\xe5\xc7\xcd\xde\x87\x2b\xf2\x7c",
+ .iv_out = "\x43\xe9\x34\x00\x8c\x38\x9c\x0f",
.ptext = "\x68\x65\x20\x74\x69\x6d\x65\x20",
.ctext = "\x43\xe9\x34\x00\x8c\x38\x9c\x0f",
.len = 8,
@@ -7032,6 +7035,7 @@ static const struct cipher_testvec des_cbc_tv_template[] = {
.key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
.klen = 8,
.iv = "\x43\xe9\x34\x00\x8c\x38\x9c\x0f",
+ .iv_out = "\x68\x37\x88\x49\x9a\x7c\x05\xf6",
.ptext = "\x66\x6f\x72\x20\x61\x6c\x6c\x20",
.ctext = "\x68\x37\x88\x49\x9a\x7c\x05\xf6",
.len = 8,
@@ -7039,6 +7043,7 @@ static const struct cipher_testvec des_cbc_tv_template[] = {
.key = "\xC9\x83\xA6\xC9\xEC\x0F\x32\x55",
.klen = 8,
.iv = "\xE7\x82\x1D\xB8\x53\x11\xAC\x47",
+ .iv_out = "\xC6\x4A\xF3\x55\xC7\x29\x2E\x63",
.ptext = "\x50\xB9\x22\xAE\x17\x80\x0C\x75"
"\xDE\x47\xD3\x3C\xA5\x0E\x9A\x03"
"\x6C\xF8\x61\xCA\x33\xBF\x28\x91"
@@ -7408,6 +7413,7 @@ static const struct cipher_testvec des3_ede_cbc_tv_template[] = {
"\xEA\xC2\x84\xE8\x14\x95\xDB\xE8",
.klen = 24,
.iv = "\x7D\x33\x88\x93\x0F\x93\xB2\x42",
+ .iv_out = "\x6b\xfa\xb1\x91\x13\xb0\xd9\x19",
.ptext = "\x6f\x54\x20\x6f\x61\x4d\x79\x6e"
"\x53\x20\x63\x65\x65\x72\x73\x74"
"\x54\x20\x6f\x6f\x4d\x20\x6e\x61"
@@ -7448,6 +7454,7 @@ static const struct cipher_testvec des3_ede_cbc_tv_template[] = {
.klen = 24,
.iv = "\xB2\xD7\x48\xED\x06\x44\xF9\x12"
"\xB7\x28\x4D\x83\x24\x59\xF2\x17",
+ .iv_out = "\x95\x63\x73\xA2\x44\xAC\xF8\xA5",
.ptext = "\x05\xEC\x77\xFB\x42\xD5\x59\x20"
"\x8B\x12\x86\x69\xF0\x5B\xCF\x56"
"\x39\xAD\x34\x9F\x66\xEA\x7D\xC4"
@@ -8035,6 +8042,7 @@ static const struct cipher_testvec bf_cbc_tv_template[] = {
"\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87",
.klen = 16,
.iv = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
+ .iv_out = "\x59\xf1\x65\x2b\xd5\xff\x92\xcc",
.ptext = "\x37\x36\x35\x34\x33\x32\x31\x20"
"\x4e\x6f\x77\x20\x69\x73\x20\x74"
"\x68\x65\x20\x74\x69\x6d\x65\x20"
@@ -8051,6 +8059,7 @@ static const struct cipher_testvec bf_cbc_tv_template[] = {
"\x78\xBE\x9B\x78\x55\x32\x0F\x55",
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+ .iv_out = "\xB4\x98\xD8\x6B\x74\xE7\x65\xF4",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -8756,6 +8765,8 @@ static const struct cipher_testvec tf_cbc_tv_template[] = {
.key = zeroed_string,
.klen = 16,
.iv = zeroed_string,
+ .iv_out = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
+ "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
.ptext = zeroed_string,
.ctext = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
"\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
@@ -8765,6 +8776,8 @@ static const struct cipher_testvec tf_cbc_tv_template[] = {
.klen = 16,
.iv = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
"\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
+ .iv_out = "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
+ "\x86\xcb\x08\x6b\x78\x9f\x54\x19",
.ptext = zeroed_string,
.ctext = "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
"\x86\xcb\x08\x6b\x78\x9f\x54\x19",
@@ -8774,6 +8787,8 @@ static const struct cipher_testvec tf_cbc_tv_template[] = {
.klen = 16,
.iv = "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
"\x86\xcb\x08\x6b\x78\x9f\x54\x19",
+ .iv_out = "\x05\xef\x8c\x61\xa8\x11\x58\x26"
+ "\x34\xba\x5c\xb7\x10\x6a\xa6\x41",
.ptext = zeroed_string,
.ctext = "\x05\xef\x8c\x61\xa8\x11\x58\x26"
"\x34\xba\x5c\xb7\x10\x6a\xa6\x41",
@@ -8782,6 +8797,8 @@ static const struct cipher_testvec tf_cbc_tv_template[] = {
.key = zeroed_string,
.klen = 16,
.iv = zeroed_string,
+ .iv_out = "\x05\xef\x8c\x61\xa8\x11\x58\x26"
+ "\x34\xba\x5c\xb7\x10\x6a\xa6\x41",
.ptext = zeroed_string,
.ctext = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
"\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a"
@@ -8798,6 +8815,8 @@ static const struct cipher_testvec tf_cbc_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\x30\x70\x56\xA4\x37\xDD\x7C\xC0"
+ "\x0A\xA3\x30\x10\x26\x25\x41\x2C",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -10166,6 +10185,8 @@ static const struct cipher_testvec serpent_cbc_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xFC\x66\xAA\x37\xF2\x37\x39\x6B"
+ "\xBC\x08\x3A\xA2\x29\xB3\xDF\xD1",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -11375,6 +11396,8 @@ static const struct cipher_testvec sm4_cbc_tv_template[] = {
"\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb",
.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
+ .iv_out = "\x4C\xB7\x01\x69\x51\x90\x92\x26"
+ "\x97\x9B\x0D\x15\xDC\x6A\x8F\x6D",
.ctext = "\x78\xEB\xB1\x1C\xC4\x0B\x0A\x48"
"\x31\x2A\xAE\xB2\x04\x02\x44\xCB"
"\x4C\xB7\x01\x69\x51\x90\x92\x26"
@@ -11390,6 +11413,8 @@ static const struct cipher_testvec sm4_cbc_tv_template[] = {
"\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb",
.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
+ .iv_out = "\x91\xf2\xc1\x47\x91\x1a\x41\x44"
+ "\x66\x5e\x1f\xa1\xd4\x0b\xae\x38",
.ctext = "\x0d\x3a\x6d\xdc\x2d\x21\xc6\x98"
"\x85\x72\x15\x58\x7b\x7b\xb5\x9a"
"\x91\xf2\xc1\x47\x91\x1a\x41\x44"
@@ -11622,6 +11647,8 @@ static const struct cipher_testvec cast6_cbc_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\x4D\x59\x7D\xC5\x28\x69\xFA\x92"
+ "\x22\x46\x89\x2D\x0F\x2B\x08\x24",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -12365,6 +12392,8 @@ static const struct cipher_testvec aes_cbc_tv_template[] = {
.klen = 16,
.iv = "\x3d\xaf\xba\x42\x9d\x9e\xb4\x30"
"\xb4\x22\xda\x80\x2c\x9f\xac\x41",
+ .iv_out = "\xe3\x53\x77\x9c\x10\x79\xae\xb8"
+ "\x27\x08\x94\x2d\xbe\x77\x18\x1a",
.ptext = "Single block msg",
.ctext = "\xe3\x53\x77\x9c\x10\x79\xae\xb8"
"\x27\x08\x94\x2d\xbe\x77\x18\x1a",
@@ -12375,6 +12404,8 @@ static const struct cipher_testvec aes_cbc_tv_template[] = {
.klen = 16,
.iv = "\x56\x2e\x17\x99\x6d\x09\x3d\x28"
"\xdd\xb3\xba\x69\x5a\x2e\x6f\x58",
+ .iv_out = "\x75\x86\x60\x2d\x25\x3c\xff\xf9"
+ "\x1b\x82\x66\xbe\xa6\xd6\x1a\xb1",
.ptext = "\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
"\x10\x11\x12\x13\x14\x15\x16\x17"
@@ -12391,6 +12422,8 @@ static const struct cipher_testvec aes_cbc_tv_template[] = {
.klen = 24,
.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
+ .iv_out = "\x08\xb0\xe2\x79\x88\x59\x88\x81"
+ "\xd9\x20\xa9\xe6\x4f\x56\x15\xcd",
.ptext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
"\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
"\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
@@ -12416,6 +12449,8 @@ static const struct cipher_testvec aes_cbc_tv_template[] = {
.klen = 32,
.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
+ .iv_out = "\xb2\xeb\x05\xe2\xc3\x9b\xe9\xfc"
+ "\xda\x6c\x19\x07\x8c\x6a\x9d\x1b",
.ptext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
"\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
"\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
@@ -12441,6 +12476,8 @@ static const struct cipher_testvec aes_cbc_tv_template[] = {
.klen = 32,
.iv = "\xE7\x82\x1D\xB8\x53\x11\xAC\x47"
"\xE2\x7D\x18\xD6\x71\x0C\xA7\x42",
+ .iv_out = "\xE0\x1F\x91\xF8\x82\x96\x2D\x65"
+ "\xA3\xAA\x13\xCC\x50\xFF\x7B\x02",
.ptext = "\x50\xB9\x22\xAE\x17\x80\x0C\x75"
"\xDE\x47\xD3\x3C\xA5\x0E\x9A\x03"
"\x6C\xF8\x61\xCA\x33\xBF\x28\x91"
@@ -22874,6 +22911,7 @@ static const struct cipher_testvec cast5_cbc_tv_template[] = {
"\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A",
.klen = 16,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+ .iv_out = "\x1D\x18\x66\x44\x5B\x8F\x14\xEB",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -23405,6 +23443,8 @@ static const struct cipher_testvec anubis_cbc_tv_template[] = {
.key = "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe",
.klen = 16,
+ .iv_out = "\x86\xd8\xb5\x6f\x98\x5e\x8a\x66"
+ "\x4f\x1f\x78\xa1\xbb\x37\xf1\xbe",
.ptext = "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
@@ -23421,6 +23461,8 @@ static const struct cipher_testvec anubis_cbc_tv_template[] = {
"\x35\x35\x35\x35\x35\x35\x35\x35"
"\x35\x35\x35\x35\x35\x35\x35\x35",
.klen = 40,
+ .iv_out = "\xa2\xbc\x06\x98\xc6\x4b\xda\x75"
+ "\x2e\xaa\xbe\x58\xce\x01\x5b\xc7",
.ptext = "\x35\x35\x35\x35\x35\x35\x35\x35"
"\x35\x35\x35\x35\x35\x35\x35\x35"
"\x35\x35\x35\x35\x35\x35\x35\x35"
@@ -23823,6 +23865,8 @@ static const struct cipher_testvec camellia_cbc_tv_template[] = {
.klen = 16,
.iv = "\x3d\xaf\xba\x42\x9d\x9e\xb4\x30"
"\xb4\x22\xda\x80\x2c\x9f\xac\x41",
+ .iv_out = "\xea\x32\x12\x76\x3b\x50\x10\xe7"
+ "\x18\xf6\xfd\x5d\xf6\x8f\x13\x51",
.ptext = "Single block msg",
.ctext = "\xea\x32\x12\x76\x3b\x50\x10\xe7"
"\x18\xf6\xfd\x5d\xf6\x8f\x13\x51",
@@ -23833,6 +23877,8 @@ static const struct cipher_testvec camellia_cbc_tv_template[] = {
.klen = 16,
.iv = "\x56\x2e\x17\x99\x6d\x09\x3d\x28"
"\xdd\xb3\xba\x69\x5a\x2e\x6f\x58",
+ .iv_out = "\x19\xb4\x3e\x57\x1c\x02\x5e\xa0"
+ "\x15\x78\xe0\x5e\xf2\xcb\x87\x16",
.ptext = "\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
"\x10\x11\x12\x13\x14\x15\x16\x17"
@@ -23850,6 +23896,8 @@ static const struct cipher_testvec camellia_cbc_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\x55\x01\xD4\x58\xB2\xF2\x85\x49"
+ "\x70\xC5\xB9\x0B\x3B\x7A\x6E\x6C",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/6] crypto: testmgr - add iv_out to all CTR test vectors
2019-02-14 8:03 [PATCH 0/6] crypto: test that CBC and CTR update the IV Eric Biggers
` (2 preceding siblings ...)
2019-02-14 8:03 ` [PATCH 3/6] crypto: testmgr - add iv_out to all CBC test vectors Eric Biggers
@ 2019-02-14 8:03 ` Eric Biggers
2019-02-14 8:03 ` [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block Eric Biggers
` (2 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:03 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
From: Eric Biggers <ebiggers@google.com>
Test that all CTR implementations update the IV buffer to contain the
next counter block, aka the IV to continue the encryption/decryption of
a larger message. When the length processed is a multiple of the block
size, users may rely on this for chaining.
When the length processed is *not* a multiple of the block size, simple
chaining doesn't work. However, as noted in commit 88a3f582bea9
("crypto: arm64/aes - don't use IV buffer to return final keystream
block"), the generic CCM implementation assumes that the CTR IV is
handled in some sane way, not e.g. overwritten with part of the
keystream. Since this was gotten wrong once already, it's desirable to
test for it. And, the most straightforward way to do this is to enforce
that all CTR implementations have the same behavior as the generic
implementation, which returns the *next* counter following the final
partial block. This behavior also has the advantage that if someone
does misuse this case for chaining, then the keystream won't be
repeated. Thus, this patch makes the tests expect this behavior.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/testmgr.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 3e68d4062e51..31bacd0f6823 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -7115,6 +7115,7 @@ static const struct cipher_testvec des_ctr_tv_template[] = {
.key = "\xC9\x83\xA6\xC9\xEC\x0F\x32\x55",
.klen = 8,
.iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD",
+ .iv_out = "\x00\x00\x00\x00\x00\x00\x00\x1C",
.ptext = "\x50\xB9\x22\xAE\x17\x80\x0C\x75"
"\xDE\x47\xD3\x3C\xA5\x0E\x9A\x03"
"\x6C\xF8\x61\xCA\x33\xBF\x28\x91"
@@ -7182,6 +7183,7 @@ static const struct cipher_testvec des_ctr_tv_template[] = {
.key = "\xC9\x83\xA6\xC9\xEC\x0F\x32\x55",
.klen = 8,
.iv = "\xE7\x82\x1D\xB8\x53\x11\xAC\x47",
+ .iv_out = "\xE7\x82\x1D\xB8\x53\x11\xAC\x66",
.ptext = "\x50\xB9\x22\xAE\x17\x80\x0C\x75"
"\xDE\x47\xD3\x3C\xA5\x0E\x9A\x03"
"\x6C\xF8\x61\xCA\x33\xBF\x28\x91"
@@ -7590,6 +7592,7 @@ static const struct cipher_testvec des3_ede_ctr_tv_template[] = {
"\xEB\xB4\x51\x72\xB4\x51\x72\x1F",
.klen = 24,
.iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
+ .iv_out = "\x00\x00\x00\x00\x00\x00\x00\x3D",
.ptext = "\x05\xEC\x77\xFB\x42\xD5\x59\x20"
"\x8B\x12\x86\x69\xF0\x5B\xCF\x56"
"\x39\xAD\x34\x9F\x66\xEA\x7D\xC4"
@@ -7721,6 +7724,7 @@ static const struct cipher_testvec des3_ede_ctr_tv_template[] = {
"\xEB\xB4\x51\x72\xB4\x51\x72\x1F",
.klen = 24,
.iv = "\xB2\xD7\x48\xED\x06\x44\xF9\x12",
+ .iv_out = "\xB2\xD7\x48\xED\x06\x44\xF9\x51",
.ptext = "\x05\xEC\x77\xFB\x42\xD5\x59\x20"
"\x8B\x12\x86\x69\xF0\x5B\xCF\x56"
"\x39\xAD\x34\x9F\x66\xEA\x7D\xC4"
@@ -8198,6 +8202,7 @@ static const struct cipher_testvec bf_ctr_tv_template[] = {
"\x78\xBE\x9B\x78\x55\x32\x0F\x55",
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x9E",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -8332,6 +8337,7 @@ static const struct cipher_testvec bf_ctr_tv_template[] = {
"\x78\xBE\x9B\x78\x55\x32\x0F\x55",
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x9E",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -8466,6 +8472,7 @@ static const struct cipher_testvec bf_ctr_tv_template[] = {
"\x78\xBE\x9B\x78\x55\x32\x0F\x55",
.klen = 32,
.iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD",
+ .iv_out = "\x00\x00\x00\x00\x00\x00\x00\x3C",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -8954,6 +8961,8 @@ static const struct cipher_testvec tf_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+ "\xC4\x29\x8E\xF3\x35\x9A\xFF\x83",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -9087,6 +9096,8 @@ static const struct cipher_testvec tf_ctr_tv_template[] = {
.klen = 32,
.iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD",
+ .iv_out = "\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x1C",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -9220,6 +9231,8 @@ static const struct cipher_testvec tf_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+ "\xC4\x29\x8E\xF3\x35\x9A\xFF\x84",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -10324,6 +10337,8 @@ static const struct cipher_testvec serpent_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+ "\xC4\x29\x8E\xF3\x35\x9A\xFF\x83",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -10457,6 +10472,8 @@ static const struct cipher_testvec serpent_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+ "\xC4\x29\x8E\xF3\x35\x9A\xFF\x84",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -10592,6 +10609,8 @@ static const struct cipher_testvec serpent_ctr_tv_template[] = {
.klen = 32,
.iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD",
+ .iv_out = "\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x1C",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -11438,6 +11457,8 @@ static const struct cipher_testvec sm4_ctr_tv_template[] = {
"\xbb\xbb\xbb\xbb\xbb\xbb\xbb\xbb",
.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
+ .iv_out = "\x00\x01\x02\x03\x04\x05\x06\x07"
+ "\x08\x09\x0A\x0B\x0C\x0D\x0E\x13",
.ctext = "\xac\x32\x36\xcb\x97\x0c\xc2\x07"
"\x91\x36\x4c\x39\x5a\x13\x42\xd1"
"\xa3\xcb\xc1\x87\x8c\x6f\x30\xcd"
@@ -11461,6 +11482,8 @@ static const struct cipher_testvec sm4_ctr_tv_template[] = {
"\xbb\xbb\xbb\xbb\xbb\xbb\xbb\xbb",
.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
+ .iv_out = "\x00\x01\x02\x03\x04\x05\x06\x07"
+ "\x08\x09\x0A\x0B\x0C\x0D\x0E\x13",
.ctext = "\x5d\xcc\xcd\x25\xb9\x5a\xb0\x74"
"\x17\xa0\x85\x12\xee\x16\x0e\x2f"
"\x8f\x66\x15\x21\xcb\xba\xb4\x4c"
@@ -11786,6 +11809,8 @@ static const struct cipher_testvec cast6_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+ "\xC4\x29\x8E\xF3\x35\x9A\xFF\x66",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A",
@@ -11801,6 +11826,8 @@ static const struct cipher_testvec cast6_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+ "\xC4\x29\x8E\xF3\x35\x9A\xFF\x83",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -14924,6 +14951,8 @@ static const struct cipher_testvec aes_ctr_tv_template[] = {
.klen = 16,
.iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
"\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
+ .iv_out = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
+ "\xf8\xf9\xfa\xfb\xfc\xfd\xff\x03",
.ptext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
"\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
"\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
@@ -14948,6 +14977,8 @@ static const struct cipher_testvec aes_ctr_tv_template[] = {
.klen = 24,
.iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
"\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
+ .iv_out = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
+ "\xf8\xf9\xfa\xfb\xfc\xfd\xff\x03",
.ptext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
"\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
"\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
@@ -14973,6 +15004,8 @@ static const struct cipher_testvec aes_ctr_tv_template[] = {
.klen = 32,
.iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
"\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
+ .iv_out = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
+ "\xf8\xf9\xfa\xfb\xfc\xfd\xff\x03",
.ptext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
"\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
"\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
@@ -14998,6 +15031,8 @@ static const struct cipher_testvec aes_ctr_tv_template[] = {
.klen = 32,
.iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD",
+ .iv_out = "\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x1C",
.ptext = "\x50\xB9\x22\xAE\x17\x80\x0C\x75"
"\xDE\x47\xD3\x3C\xA5\x0E\x9A\x03"
"\x6C\xF8\x61\xCA\x33\xBF\x28\x91"
@@ -15131,6 +15166,8 @@ static const struct cipher_testvec aes_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE7\x82\x1D\xB8\x53\x11\xAC\x47"
"\xE2\x7D\x18\xD6\x71\x0C\xA7\x42",
+ .iv_out = "\xE7\x82\x1D\xB8\x53\x11\xAC\x47"
+ "\xE2\x7D\x18\xD6\x71\x0C\xA7\x62",
.ptext = "\x50\xB9\x22\xAE\x17\x80\x0C\x75"
"\xDE\x47\xD3\x3C\xA5\x0E\x9A\x03"
"\x6C\xF8\x61\xCA\x33\xBF\x28\x91"
@@ -23046,6 +23083,7 @@ static const struct cipher_testvec cast5_ctr_tv_template[] = {
"\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A",
.klen = 16,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x62",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A",
@@ -23058,6 +23096,7 @@ static const struct cipher_testvec cast5_ctr_tv_template[] = {
"\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A",
.klen = 16,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x9D",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -24163,6 +24202,8 @@ static const struct cipher_testvec camellia_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+ "\xC4\x29\x8E\xF3\x35\x9A\xFF\x83",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -24296,6 +24337,8 @@ static const struct cipher_testvec camellia_ctr_tv_template[] = {
.klen = 32,
.iv = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
"\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+ .iv_out = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+ "\xC4\x29\x8E\xF3\x35\x9A\xFF\xA4",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
@@ -24559,6 +24602,8 @@ static const struct cipher_testvec camellia_ctr_tv_template[] = {
.klen = 32,
.iv = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD",
+ .iv_out = "\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x3C",
.ptext = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
"\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
"\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block
2019-02-14 8:03 [PATCH 0/6] crypto: test that CBC and CTR update the IV Eric Biggers
` (3 preceding siblings ...)
2019-02-14 8:03 ` [PATCH 4/6] crypto: testmgr - add iv_out to all CTR " Eric Biggers
@ 2019-02-14 8:03 ` Eric Biggers
2019-02-14 8:14 ` Ard Biesheuvel
2019-02-14 8:03 ` [PATCH 6/6] crypto: arm/aes-ce " Eric Biggers
2019-02-22 12:00 ` [PATCH 0/6] crypto: test that CBC and CTR update the IV Herbert Xu
6 siblings, 1 reply; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:03 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
From: Eric Biggers <ebiggers@google.com>
Make the arm64 ctr-aes-neon and ctr-aes-ce algorithms update the IV
buffer to contain the next counter after processing a partial final
block, rather than leave it as the last counter. This makes these
algorithms pass the updated AES-CTR tests.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
arch/arm64/crypto/aes-modes.S | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/arm64/crypto/aes-modes.S b/arch/arm64/crypto/aes-modes.S
index 67700045a0e0..4c7ce231963c 100644
--- a/arch/arm64/crypto/aes-modes.S
+++ b/arch/arm64/crypto/aes-modes.S
@@ -320,8 +320,7 @@ AES_ENTRY(aes_ctr_encrypt)
.Lctrtailblock:
st1 {v0.16b}, [x0]
- ldp x29, x30, [sp], #16
- ret
+ b .Lctrout
.Lctrcarry:
umov x7, v4.d[0] /* load upper word of ctr */
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 6/6] crypto: arm/aes-ce - update IV after partial final CTR block
2019-02-14 8:03 [PATCH 0/6] crypto: test that CBC and CTR update the IV Eric Biggers
` (4 preceding siblings ...)
2019-02-14 8:03 ` [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block Eric Biggers
@ 2019-02-14 8:03 ` Eric Biggers
2019-02-22 12:00 ` [PATCH 0/6] crypto: test that CBC and CTR update the IV Herbert Xu
6 siblings, 0 replies; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:03 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
From: Eric Biggers <ebiggers@google.com>
Make the arm ctr-aes-ce algorithm update the IV buffer to contain the
next counter after processing a partial final block, rather than leave
it as the last counter. This makes ctr-aes-ce pass the updated AES-CTR
tests. This change also makes the code match the arm64 version in
arch/arm64/crypto/aes-modes.S more closely.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
arch/arm/crypto/aes-ce-core.S | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/arch/arm/crypto/aes-ce-core.S b/arch/arm/crypto/aes-ce-core.S
index ba8e6a32fdc9..bc53bcaa772e 100644
--- a/arch/arm/crypto/aes-ce-core.S
+++ b/arch/arm/crypto/aes-ce-core.S
@@ -317,25 +317,27 @@ ENTRY(ce_aes_ctr_encrypt)
.Lctrloop:
vmov q0, q6
bl aes_encrypt
- subs r4, r4, #1
- bmi .Lctrtailblock @ blocks < 0 means tail block
- vld1.8 {q3}, [r1]!
- veor q3, q0, q3
- vst1.8 {q3}, [r0]!
adds r6, r6, #1 @ increment BE ctr
rev ip, r6
vmov s27, ip
bcs .Lctrcarry
- teq r4, #0
+
+.Lctrcarrydone:
+ subs r4, r4, #1
+ bmi .Lctrtailblock @ blocks < 0 means tail block
+ vld1.8 {q3}, [r1]!
+ veor q3, q0, q3
+ vst1.8 {q3}, [r0]!
bne .Lctrloop
+
.Lctrout:
- vst1.8 {q6}, [r5]
+ vst1.8 {q6}, [r5] @ return next CTR value
pop {r4-r6, pc}
.Lctrtailblock:
- vst1.8 {q0}, [r0, :64] @ return just the key stream
- pop {r4-r6, pc}
+ vst1.8 {q0}, [r0, :64] @ return the key stream
+ b .Lctrout
.Lctrcarry:
.irp sreg, s26, s25, s24
@@ -344,11 +346,9 @@ ENTRY(ce_aes_ctr_encrypt)
adds ip, ip, #1
rev ip, ip
vmov \sreg, ip
- bcc 0f
+ bcc .Lctrcarrydone
.endr
-0: teq r4, #0
- beq .Lctrout
- b .Lctrloop
+ b .Lctrcarrydone
ENDPROC(ce_aes_ctr_encrypt)
/*
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block
2019-02-14 8:03 ` [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block Eric Biggers
@ 2019-02-14 8:14 ` Ard Biesheuvel
2019-02-14 8:28 ` Eric Biggers
0 siblings, 1 reply; 12+ messages in thread
From: Ard Biesheuvel @ 2019-02-14 8:14 UTC (permalink / raw)
To: Eric Biggers; +Cc: open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Herbert Xu
On Thu, 14 Feb 2019 at 09:04, Eric Biggers <ebiggers@kernel.org> wrote:
>
> From: Eric Biggers <ebiggers@google.com>
>
> Make the arm64 ctr-aes-neon and ctr-aes-ce algorithms update the IV
> buffer to contain the next counter after processing a partial final
> block, rather than leave it as the last counter. This makes these
> algorithms pass the updated AES-CTR tests.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
I take it this means we return an output IV even if the algorithm
could never proceed in a meaningful way, given that we throw away some
keystream bits that would be needed in that case.
That means this change is strictly there to make the test framework
happy, even for cases that can never appear in reality.
Wouldn't it be better not to set out_iv for input buffers whose size
is not a multiple of the block size?
> ---
> arch/arm64/crypto/aes-modes.S | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/arm64/crypto/aes-modes.S b/arch/arm64/crypto/aes-modes.S
> index 67700045a0e0..4c7ce231963c 100644
> --- a/arch/arm64/crypto/aes-modes.S
> +++ b/arch/arm64/crypto/aes-modes.S
> @@ -320,8 +320,7 @@ AES_ENTRY(aes_ctr_encrypt)
>
> .Lctrtailblock:
> st1 {v0.16b}, [x0]
> - ldp x29, x30, [sp], #16
> - ret
> + b .Lctrout
>
> .Lctrcarry:
> umov x7, v4.d[0] /* load upper word of ctr */
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block
2019-02-14 8:14 ` Ard Biesheuvel
@ 2019-02-14 8:28 ` Eric Biggers
2019-02-14 8:33 ` Ard Biesheuvel
0 siblings, 1 reply; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:28 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Herbert Xu
On Thu, Feb 14, 2019 at 09:14:13AM +0100, Ard Biesheuvel wrote:
> On Thu, 14 Feb 2019 at 09:04, Eric Biggers <ebiggers@kernel.org> wrote:
> >
> > From: Eric Biggers <ebiggers@google.com>
> >
> > Make the arm64 ctr-aes-neon and ctr-aes-ce algorithms update the IV
> > buffer to contain the next counter after processing a partial final
> > block, rather than leave it as the last counter. This makes these
> > algorithms pass the updated AES-CTR tests.
> >
> > Signed-off-by: Eric Biggers <ebiggers@google.com>
>
> I take it this means we return an output IV even if the algorithm
> could never proceed in a meaningful way, given that we throw away some
> keystream bits that would be needed in that case.
>
> That means this change is strictly there to make the test framework
> happy, even for cases that can never appear in reality.
>
> Wouldn't it be better not to set out_iv for input buffers whose size
> is not a multiple of the block size?
>
See the explanation in patch 4 for why the tests test for this. It's not a
super strong argument but this seems like the best thing to do.
- Eric
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block
2019-02-14 8:28 ` Eric Biggers
@ 2019-02-14 8:33 ` Ard Biesheuvel
2019-02-14 8:43 ` Eric Biggers
0 siblings, 1 reply; 12+ messages in thread
From: Ard Biesheuvel @ 2019-02-14 8:33 UTC (permalink / raw)
To: Eric Biggers; +Cc: open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Herbert Xu
On Thu, 14 Feb 2019 at 09:28, Eric Biggers <ebiggers@kernel.org> wrote:
>
> On Thu, Feb 14, 2019 at 09:14:13AM +0100, Ard Biesheuvel wrote:
> > On Thu, 14 Feb 2019 at 09:04, Eric Biggers <ebiggers@kernel.org> wrote:
> > >
> > > From: Eric Biggers <ebiggers@google.com>
> > >
> > > Make the arm64 ctr-aes-neon and ctr-aes-ce algorithms update the IV
> > > buffer to contain the next counter after processing a partial final
> > > block, rather than leave it as the last counter. This makes these
> > > algorithms pass the updated AES-CTR tests.
> > >
> > > Signed-off-by: Eric Biggers <ebiggers@google.com>
> >
> > I take it this means we return an output IV even if the algorithm
> > could never proceed in a meaningful way, given that we throw away some
> > keystream bits that would be needed in that case.
> >
> > That means this change is strictly there to make the test framework
> > happy, even for cases that can never appear in reality.
> >
> > Wouldn't it be better not to set out_iv for input buffers whose size
> > is not a multiple of the block size?
> >
>
> See the explanation in patch 4 for why the tests test for this. It's not a
> super strong argument but this seems like the best thing to do.
>
Fair enough.
Do you have a branch with this stuff that I can drop into kernelci
again? Preferably one that already has the tests enabled by default,
and panics on failure.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block
2019-02-14 8:33 ` Ard Biesheuvel
@ 2019-02-14 8:43 ` Eric Biggers
0 siblings, 0 replies; 12+ messages in thread
From: Eric Biggers @ 2019-02-14 8:43 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Herbert Xu
On Thu, Feb 14, 2019 at 09:33:51AM +0100, Ard Biesheuvel wrote:
> On Thu, 14 Feb 2019 at 09:28, Eric Biggers <ebiggers@kernel.org> wrote:
> >
> > On Thu, Feb 14, 2019 at 09:14:13AM +0100, Ard Biesheuvel wrote:
> > > On Thu, 14 Feb 2019 at 09:04, Eric Biggers <ebiggers@kernel.org> wrote:
> > > >
> > > > From: Eric Biggers <ebiggers@google.com>
> > > >
> > > > Make the arm64 ctr-aes-neon and ctr-aes-ce algorithms update the IV
> > > > buffer to contain the next counter after processing a partial final
> > > > block, rather than leave it as the last counter. This makes these
> > > > algorithms pass the updated AES-CTR tests.
> > > >
> > > > Signed-off-by: Eric Biggers <ebiggers@google.com>
> > >
> > > I take it this means we return an output IV even if the algorithm
> > > could never proceed in a meaningful way, given that we throw away some
> > > keystream bits that would be needed in that case.
> > >
> > > That means this change is strictly there to make the test framework
> > > happy, even for cases that can never appear in reality.
> > >
> > > Wouldn't it be better not to set out_iv for input buffers whose size
> > > is not a multiple of the block size?
> > >
> >
> > See the explanation in patch 4 for why the tests test for this. It's not a
> > super strong argument but this seems like the best thing to do.
> >
>
> Fair enough.
>
> Do you have a branch with this stuff that I can drop into kernelci
> again? Preferably one that already has the tests enabled by default,
> and panics on failure.
I pushed it out to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git
branch "iv-out-testing", and added a hack to enable self-tests by default and
panic on test failure.
- Eric
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/6] crypto: test that CBC and CTR update the IV
2019-02-14 8:03 [PATCH 0/6] crypto: test that CBC and CTR update the IV Eric Biggers
` (5 preceding siblings ...)
2019-02-14 8:03 ` [PATCH 6/6] crypto: arm/aes-ce " Eric Biggers
@ 2019-02-22 12:00 ` Herbert Xu
6 siblings, 0 replies; 12+ messages in thread
From: Herbert Xu @ 2019-02-22 12:00 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-crypto
On Thu, Feb 14, 2019 at 12:03:49AM -0800, Eric Biggers wrote:
> Hello,
>
> This series makes the crypto self-tests test that all CBC and CTR
> implementations update req->iv to contain the IV for the next block.
> This apparently has been a requirement for a long time, but it wasn't
> actually tested for.
>
> With this series applied, all self-tests pass on x86_64, arm32, and
> arm64. But I'm not able to test hardware drivers, so possibly some of
> them will fail and still need to be fixed.
>
> Eric Biggers (6):
> crypto: testmgr - remove extra bytes from 3DES-CTR IVs
> crypto: testmgr - support checking skcipher output IV
> crypto: testmgr - add iv_out to all CBC test vectors
> crypto: testmgr - add iv_out to all CTR test vectors
> crypto: arm64/aes-blk - update IV after partial final CTR block
> crypto: arm/aes-ce - update IV after partial final CTR block
>
> arch/arm/crypto/aes-ce-core.S | 26 ++++----
> arch/arm64/crypto/aes-modes.S | 3 +-
> crypto/testmgr.c | 6 +-
> crypto/testmgr.h | 111 +++++++++++++++++++++++++++++++---
> 4 files changed, 120 insertions(+), 26 deletions(-)
All applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2019-02-22 12:00 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-14 8:03 [PATCH 0/6] crypto: test that CBC and CTR update the IV Eric Biggers
2019-02-14 8:03 ` [PATCH 1/6] crypto: testmgr - remove extra bytes from 3DES-CTR IVs Eric Biggers
2019-02-14 8:03 ` [PATCH 2/6] crypto: testmgr - support checking skcipher output IV Eric Biggers
2019-02-14 8:03 ` [PATCH 3/6] crypto: testmgr - add iv_out to all CBC test vectors Eric Biggers
2019-02-14 8:03 ` [PATCH 4/6] crypto: testmgr - add iv_out to all CTR " Eric Biggers
2019-02-14 8:03 ` [PATCH 5/6] crypto: arm64/aes-blk - update IV after partial final CTR block Eric Biggers
2019-02-14 8:14 ` Ard Biesheuvel
2019-02-14 8:28 ` Eric Biggers
2019-02-14 8:33 ` Ard Biesheuvel
2019-02-14 8:43 ` Eric Biggers
2019-02-14 8:03 ` [PATCH 6/6] crypto: arm/aes-ce " Eric Biggers
2019-02-22 12:00 ` [PATCH 0/6] crypto: test that CBC and CTR update the IV Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).