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>
This commit is contained in:
Eric Biggers 2019-02-14 00:03:51 -08:00 committed by Herbert Xu
parent c9e1d48a11
commit 8efd972ef9
2 changed files with 11 additions and 7 deletions

View File

@ -1542,7 +1542,9 @@ static int test_skcipher_vec_cfg(const char *driver, int enc,
if (ivsize) { if (ivsize) {
if (WARN_ON(ivsize > MAX_IVLEN)) if (WARN_ON(ivsize > MAX_IVLEN))
return -EINVAL; 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); memcpy(iv, vec->iv, ivsize);
else else
memset(iv, 0, ivsize); 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 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", pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n",
driver, op, vec_num, cfg->name); driver, op, vec_num, cfg->name);
hexdump(iv, ivsize); hexdump(iv, ivsize);

View File

@ -47,7 +47,8 @@ struct hash_testvec {
* cipher_testvec: structure to describe a symmetric cipher test * cipher_testvec: structure to describe a symmetric cipher test
* @key: Pointer to key * @key: Pointer to key
* @klen: Length of @key in bytes * @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 * @ptext: Pointer to plaintext
* @ctext: Pointer to ciphertext * @ctext: Pointer to ciphertext
* @len: Length of @ptext and @ctext in bytes * @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? * @wk: Does the test need CRYPTO_TFM_REQ_FORBID_WEAK_KEYS?
* ( e.g. test needs to fail due to a weak key ) * ( e.g. test needs to fail due to a weak key )
* @fips_skip: Skip the test vector in FIPS mode * @fips_skip: Skip the test vector in FIPS mode
* @generates_iv: Encryption should ignore the given IV, and output @iv. * @generates_iv: Encryption should ignore the given IV, and output @iv_out.
* Decryption takes @iv. Needed for AES Keywrap ("kw(aes)"). * Decryption takes @iv_out. Needed for AES Keywrap ("kw(aes)").
*/ */
struct cipher_testvec { struct cipher_testvec {
const char *key; const char *key;
const char *iv; const char *iv;
const char *iv_out;
const char *ptext; const char *ptext;
const char *ctext; const char *ctext;
bool fail; bool fail;
@ -21771,7 +21773,7 @@ static const struct cipher_testvec aes_kw_tv_template[] = {
.ctext = "\xf6\x85\x94\x81\x6f\x64\xca\xa3" .ctext = "\xf6\x85\x94\x81\x6f\x64\xca\xa3"
"\xf5\x6f\xab\xea\x25\x48\xf5\xfb", "\xf5\x6f\xab\xea\x25\x48\xf5\xfb",
.len = 16, .len = 16,
.iv = "\x03\x1f\x6b\xd7\xe6\x1e\x64\x3d", .iv_out = "\x03\x1f\x6b\xd7\xe6\x1e\x64\x3d",
.generates_iv = true, .generates_iv = true,
}, { }, {
.key = "\x80\xaa\x99\x73\x27\xa4\x80\x6b" .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" .ctext = "\xd3\x3d\x3d\x97\x7b\xf0\xa9\x15"
"\x59\xf9\x9c\x8a\xcd\x29\x3d\x43", "\x59\xf9\x9c\x8a\xcd\x29\x3d\x43",
.len = 16, .len = 16,
.iv = "\x42\x3c\x96\x0d\x8a\x2a\xc4\xc1", .iv_out = "\x42\x3c\x96\x0d\x8a\x2a\xc4\xc1",
.generates_iv = true, .generates_iv = true,
}, },
}; };