Commit 32c813e6 authored by Prasad J Pandit's avatar Prasad J Pandit Committed by Daniel P. Berrangé
Browse files

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: default avatarPrasad J Pandit <pjp@fedoraproject.org>
Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 0072d2a9
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -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];
}