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>
This commit is contained in:
Prasad J Pandit 2017-02-20 16:53:07 +05:30 committed by Daniel P. Berrange
parent 0072d2a9fc
commit 32c813e6c2
1 changed files with 2 additions and 6 deletions

View File

@ -63,18 +63,14 @@ static bool mode_need_iv[QCRYPTO_CIPHER_MODE__MAX] = {
size_t qcrypto_cipher_get_block_len(QCryptoCipherAlgorithm alg) size_t qcrypto_cipher_get_block_len(QCryptoCipherAlgorithm alg)
{ {
if (alg >= G_N_ELEMENTS(alg_key_len)) { assert(alg < G_N_ELEMENTS(alg_key_len));
return 0;
}
return alg_block_len[alg]; return alg_block_len[alg];
} }
size_t qcrypto_cipher_get_key_len(QCryptoCipherAlgorithm alg) size_t qcrypto_cipher_get_key_len(QCryptoCipherAlgorithm alg)
{ {
if (alg >= G_N_ELEMENTS(alg_key_len)) { assert(alg < G_N_ELEMENTS(alg_key_len));
return 0;
}
return alg_key_len[alg]; return alg_key_len[alg];
} }