siv: return error if key is not set

Avoid encryption or decryption using uninitialized data, or causing a
crash, if a key was not set for the SIV instance.
This commit is contained in:
Miroslav Lichvar
2020-09-09 14:00:32 +02:00
parent 9820c22c1d
commit 2bb88b45c6
3 changed files with 27 additions and 0 deletions

View File

@@ -204,6 +204,9 @@ SIV_Encrypt(SIV_Instance instance,
{
size_t clen = ciphertext_length;
if (!instance->cipher)
return 0;
if (nonce_length < 1 || assoc_length < 0 ||
plaintext_length < 0 || ciphertext_length < 0)
return 0;
@@ -232,6 +235,9 @@ SIV_Decrypt(SIV_Instance instance,
{
size_t plen = plaintext_length;
if (!instance->cipher)
return 0;
if (nonce_length < 1 || assoc_length < 0 ||
plaintext_length < 0 || ciphertext_length < 0)
return 0;