diff options
author | Eric Biggers <ebiggers@google.com> | 2019-02-14 03:03:51 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2019-02-21 23:47:27 -0500 |
commit | 8efd972ef96a3f77ded9a838005d49efa9a96243 (patch) | |
tree | 0279da489d21a11db4895e5f630918054243de2d | |
parent | c9e1d48a1122ef1d0f753cbbe6e9a309214b5430 (diff) |
crypto: testmgr - support checking skcipher output IV
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>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/testmgr.c | 6 | ||||
-rw-r--r-- | 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, | |||
1542 | if (ivsize) { | 1542 | if (ivsize) { |
1543 | if (WARN_ON(ivsize > MAX_IVLEN)) | 1543 | if (WARN_ON(ivsize > MAX_IVLEN)) |
1544 | return -EINVAL; | 1544 | return -EINVAL; |
1545 | if (vec->iv && !(vec->generates_iv && enc)) | 1545 | if (vec->generates_iv && !enc) |
1546 | memcpy(iv, vec->iv_out, ivsize); | ||
1547 | else if (vec->iv) | ||
1546 | memcpy(iv, vec->iv, ivsize); | 1548 | memcpy(iv, vec->iv, ivsize); |
1547 | else | 1549 | else |
1548 | memset(iv, 0, ivsize); | 1550 | memset(iv, 0, ivsize); |
@@ -1635,7 +1637,7 @@ static int test_skcipher_vec_cfg(const char *driver, int enc, | |||
1635 | } | 1637 | } |
1636 | 1638 | ||
1637 | /* If applicable, check that the algorithm generated the correct IV */ | 1639 | /* If applicable, check that the algorithm generated the correct IV */ |
1638 | if (vec->generates_iv && enc && memcmp(iv, vec->iv, ivsize) != 0) { | 1640 | if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) { |
1639 | pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n", | 1641 | pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n", |
1640 | driver, op, vec_num, cfg->name); | 1642 | driver, op, vec_num, cfg->name); |
1641 | hexdump(iv, ivsize); | 1643 | 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 { | |||
47 | * cipher_testvec: structure to describe a symmetric cipher test | 47 | * cipher_testvec: structure to describe a symmetric cipher test |
48 | * @key: Pointer to key | 48 | * @key: Pointer to key |
49 | * @klen: Length of @key in bytes | 49 | * @klen: Length of @key in bytes |
50 | * @iv: Pointer to IV (optional for some ciphers) | 50 | * @iv: Pointer to IV. If NULL, an all-zeroes IV is used. |
51 | * @iv_out: Pointer to output IV, if applicable for the cipher. | ||
51 | * @ptext: Pointer to plaintext | 52 | * @ptext: Pointer to plaintext |
52 | * @ctext: Pointer to ciphertext | 53 | * @ctext: Pointer to ciphertext |
53 | * @len: Length of @ptext and @ctext in bytes | 54 | * @len: Length of @ptext and @ctext in bytes |
@@ -55,12 +56,13 @@ struct hash_testvec { | |||
55 | * @wk: Does the test need CRYPTO_TFM_REQ_FORBID_WEAK_KEYS? | 56 | * @wk: Does the test need CRYPTO_TFM_REQ_FORBID_WEAK_KEYS? |
56 | * ( e.g. test needs to fail due to a weak key ) | 57 | * ( e.g. test needs to fail due to a weak key ) |
57 | * @fips_skip: Skip the test vector in FIPS mode | 58 | * @fips_skip: Skip the test vector in FIPS mode |
58 | * @generates_iv: Encryption should ignore the given IV, and output @iv. | 59 | * @generates_iv: Encryption should ignore the given IV, and output @iv_out. |
59 | * Decryption takes @iv. Needed for AES Keywrap ("kw(aes)"). | 60 | * Decryption takes @iv_out. Needed for AES Keywrap ("kw(aes)"). |
60 | */ | 61 | */ |
61 | struct cipher_testvec { | 62 | struct cipher_testvec { |
62 | const char *key; | 63 | const char *key; |
63 | const char *iv; | 64 | const char *iv; |
65 | const char *iv_out; | ||
64 | const char *ptext; | 66 | const char *ptext; |
65 | const char *ctext; | 67 | const char *ctext; |
66 | bool fail; | 68 | bool fail; |
@@ -21771,7 +21773,7 @@ static const struct cipher_testvec aes_kw_tv_template[] = { | |||
21771 | .ctext = "\xf6\x85\x94\x81\x6f\x64\xca\xa3" | 21773 | .ctext = "\xf6\x85\x94\x81\x6f\x64\xca\xa3" |
21772 | "\xf5\x6f\xab\xea\x25\x48\xf5\xfb", | 21774 | "\xf5\x6f\xab\xea\x25\x48\xf5\xfb", |
21773 | .len = 16, | 21775 | .len = 16, |
21774 | .iv = "\x03\x1f\x6b\xd7\xe6\x1e\x64\x3d", | 21776 | .iv_out = "\x03\x1f\x6b\xd7\xe6\x1e\x64\x3d", |
21775 | .generates_iv = true, | 21777 | .generates_iv = true, |
21776 | }, { | 21778 | }, { |
21777 | .key = "\x80\xaa\x99\x73\x27\xa4\x80\x6b" | 21779 | .key = "\x80\xaa\x99\x73\x27\xa4\x80\x6b" |
@@ -21784,7 +21786,7 @@ static const struct cipher_testvec aes_kw_tv_template[] = { | |||
21784 | .ctext = "\xd3\x3d\x3d\x97\x7b\xf0\xa9\x15" | 21786 | .ctext = "\xd3\x3d\x3d\x97\x7b\xf0\xa9\x15" |
21785 | "\x59\xf9\x9c\x8a\xcd\x29\x3d\x43", | 21787 | "\x59\xf9\x9c\x8a\xcd\x29\x3d\x43", |
21786 | .len = 16, | 21788 | .len = 16, |
21787 | .iv = "\x42\x3c\x96\x0d\x8a\x2a\xc4\xc1", | 21789 | .iv_out = "\x42\x3c\x96\x0d\x8a\x2a\xc4\xc1", |
21788 | .generates_iv = true, | 21790 | .generates_iv = true, |
21789 | }, | 21791 | }, |
21790 | }; | 21792 | }; |