mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 23:25:56 -05:00
[raop] Fix gcrypt error handling in raop_verification.c
And I learnt that gcrypt doesn't follow the negative-on-error pattern
This commit is contained in:
parent
c2a563eec7
commit
666af127d5
@ -296,7 +296,14 @@ hash_init(enum hash_alg alg, HashCTX *c)
|
|||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
#elif CONFIG_GCRYPT
|
#elif CONFIG_GCRYPT
|
||||||
return gcry_md_open(c, alg, 0);
|
gcry_error_t err;
|
||||||
|
|
||||||
|
err = gcry_md_open(c, alg, 0);
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,31 +790,38 @@ encrypt_gcm(unsigned char *ciphertext, int ciphertext_len, unsigned char *tag, u
|
|||||||
return -1;
|
return -1;
|
||||||
#elif CONFIG_GCRYPT
|
#elif CONFIG_GCRYPT
|
||||||
gcry_cipher_hd_t hd;
|
gcry_cipher_hd_t hd;
|
||||||
int ret;
|
gcry_error_t err;
|
||||||
|
|
||||||
ret = gcry_cipher_open(&hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_GCM, 0);
|
err = gcry_cipher_open(&hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_GCM, 0);
|
||||||
if (ret < 0)
|
if (err)
|
||||||
{
|
{
|
||||||
*errmsg = "Error initialising AES 128 GCM encryption";
|
*errmsg = "Error initialising AES 128 GCM encryption";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (gcry_cipher_setkey(hd, key, gcry_cipher_get_algo_keylen(GCRY_CIPHER_AES128)) < 0) ||
|
err = gcry_cipher_setkey(hd, key, gcry_cipher_get_algo_keylen(GCRY_CIPHER_AES128));
|
||||||
(gcry_cipher_setiv(hd, iv, gcry_cipher_get_algo_blklen(GCRY_CIPHER_AES128)) < 0))
|
if (err)
|
||||||
{
|
{
|
||||||
*errmsg = "Could not set key or iv for AES 128 GCM";
|
*errmsg = "Could not set key for AES 128 GCM";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gcry_cipher_encrypt(hd, ciphertext, ciphertext_len, plaintext, plaintext_len);
|
err = gcry_cipher_setiv(hd, iv, gcry_cipher_get_algo_blklen(GCRY_CIPHER_AES128));
|
||||||
if (ret < 0)
|
if (err)
|
||||||
|
{
|
||||||
|
*errmsg = "Could not set iv for AES 128 GCM";
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gcry_cipher_encrypt(hd, ciphertext, ciphertext_len, plaintext, plaintext_len);
|
||||||
|
if (err)
|
||||||
{
|
{
|
||||||
*errmsg = "Error GCM encrypting";
|
*errmsg = "Error GCM encrypting";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gcry_cipher_gettag(hd, tag, AUTHTAG_LENGTH);
|
err = gcry_cipher_gettag(hd, tag, AUTHTAG_LENGTH);
|
||||||
if (ret < 0)
|
if (err)
|
||||||
{
|
{
|
||||||
*errmsg = "Error getting authtag";
|
*errmsg = "Error getting authtag";
|
||||||
goto error;
|
goto error;
|
||||||
@ -860,24 +874,39 @@ encrypt_ctr(unsigned char *ciphertext, int ciphertext_len,
|
|||||||
return -1;
|
return -1;
|
||||||
#elif CONFIG_GCRYPT
|
#elif CONFIG_GCRYPT
|
||||||
gcry_cipher_hd_t hd;
|
gcry_cipher_hd_t hd;
|
||||||
|
gcry_error_t err;
|
||||||
|
|
||||||
if (gcry_cipher_open(&hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0) < 0)
|
err = gcry_cipher_open(&hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0);
|
||||||
|
if (err)
|
||||||
{
|
{
|
||||||
*errmsg = "Error initialising AES 128 CTR encryption";
|
*errmsg = "Error initialising AES 128 CTR encryption";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
err = gcry_cipher_setkey(hd, key, gcry_cipher_get_algo_keylen(GCRY_CIPHER_AES128));
|
||||||
if ( (gcry_cipher_setkey(hd, key, gcry_cipher_get_algo_keylen(GCRY_CIPHER_AES128)) < 0) ||
|
if (err)
|
||||||
(gcry_cipher_setctr(hd, iv, gcry_cipher_get_algo_blklen(GCRY_CIPHER_AES128)) < 0) )
|
|
||||||
{
|
{
|
||||||
*errmsg = "Could not set key or iv for AES 128 CTR";
|
*errmsg = "Could not set key for AES 128 CTR";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (gcry_cipher_encrypt(hd, ciphertext, ciphertext_len, plaintext1, plaintext1_len) < 0) ||
|
err = gcry_cipher_setctr(hd, iv, gcry_cipher_get_algo_blklen(GCRY_CIPHER_AES128));
|
||||||
(gcry_cipher_encrypt(hd, ciphertext, ciphertext_len, plaintext2, plaintext2_len) < 0) )
|
if (err)
|
||||||
{
|
{
|
||||||
*errmsg = "Error CTR encrypting";
|
*errmsg = "Could not set iv for AES 128 CTR";
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gcry_cipher_encrypt(hd, ciphertext, ciphertext_len, plaintext1, plaintext1_len);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
*errmsg = "Error CTR encrypting plaintext 1";
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gcry_cipher_encrypt(hd, ciphertext, ciphertext_len, plaintext2, plaintext2_len);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
*errmsg = "Error CTR encrypting plaintext 2";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user