diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2016-09-07 12:43:29 +0100 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2016-09-19 16:30:45 +0100 |
commit | e74aabcffb74e6c15de05255480d43771ec63d8b (patch) | |
tree | afe834d8b8f613b933bcc20e2c2f88e712d58564 /include | |
parent | 8813800b7d995d8b54ef0a1e16d41fc13d8b5f3a (diff) | |
download | qemu-e74aabcffb74e6c15de05255480d43771ec63d8b.zip qemu-e74aabcffb74e6c15de05255480d43771ec63d8b.tar.gz qemu-e74aabcffb74e6c15de05255480d43771ec63d8b.tar.bz2 |
crypto: use correct derived key size when timing pbkdf
Currently when timing the pbkdf algorithm a fixed key
size of 32 bytes is used. This results in inaccurate
timings for certain hashes depending on their digest
size. For example when using sha1 with aes-256, this
causes us to measure time for the master key digest
doing 2 sha1 operations per iteration, instead of 1.
Instead we should pass in the desired key size to the
timing routine that matches the key size that will be
used for real later.
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/pbkdf.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/include/crypto/pbkdf.h b/include/crypto/pbkdf.h index 6f4ac85..ef209b3 100644 --- a/include/crypto/pbkdf.h +++ b/include/crypto/pbkdf.h @@ -133,6 +133,7 @@ int qcrypto_pbkdf2(QCryptoHashAlgorithm hash, * @nkey: the length of @key in bytes * @salt: a random salt * @nsalt: length of @salt in bytes + * @nout: size of desired derived key * @errp: pointer to a NULL-initialized error object * * Time the PBKDF2 algorithm to determine how many @@ -140,13 +141,16 @@ int qcrypto_pbkdf2(QCryptoHashAlgorithm hash, * key from a user password provided in @key in 1 * second of compute time. The result of this can * be used as a the @iterations parameter of a later - * call to qcrypto_pbkdf2(). + * call to qcrypto_pbkdf2(). The value of @nout should + * match that value that will later be provided with + * a call to qcrypto_pbkdf2(). * * Returns: number of iterations in 1 second, -1 on error */ uint64_t qcrypto_pbkdf2_count_iters(QCryptoHashAlgorithm hash, const uint8_t *key, size_t nkey, const uint8_t *salt, size_t nsalt, + size_t nout, Error **errp); #endif /* QCRYPTO_PBKDF_H */ |