summaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorPrasad J Pandit <pjp@fedoraproject.org>2017-02-20 16:53:07 +0530
committerDaniel P. Berrange <berrange@redhat.com>2017-02-27 13:37:14 +0000
commit32c813e6c2a857b93b897901b7e20281397528a3 (patch)
tree949d518cce241451e88996cb0fa68193194c7410 /crypto
parent0072d2a9fce4835ab2b9ee70aaca0169fb25fa0c (diff)
downloadqemu-32c813e6c2a857b93b897901b7e20281397528a3.tar.gz
crypto: assert cipher algorithm is always valid
Crypto routines 'qcrypto_cipher_get_block_len' and 'qcrypto_cipher_get_key_len' return non-zero cipher block and key lengths from static arrays 'alg_block_len[]' and 'alg_key_len[]' respectively. Returning 'zero(0)' value from either of them would likely lead to an error condition. Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/cipher.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/crypto/cipher.c b/crypto/cipher.c
index 9ecaff702b..5a9648942f 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -63,18 +63,14 @@ static bool mode_need_iv[QCRYPTO_CIPHER_MODE__MAX] = {
size_t qcrypto_cipher_get_block_len(QCryptoCipherAlgorithm alg)
{
- if (alg >= G_N_ELEMENTS(alg_key_len)) {
- return 0;
- }
+ assert(alg < G_N_ELEMENTS(alg_key_len));
return alg_block_len[alg];
}
size_t qcrypto_cipher_get_key_len(QCryptoCipherAlgorithm alg)
{
- if (alg >= G_N_ELEMENTS(alg_key_len)) {
- return 0;
- }
+ assert(alg < G_N_ELEMENTS(alg_key_len));
return alg_key_len[alg];
}