size_t tag_size, const void *plain,
size_t plain_size, void *encr, size_t encr_size)
{
+ int ret;
+
/* proper AEAD cipher */
if (unlikely(encr_size - tag_size < plain_size))
return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER);
- aes_gcm_setiv(ctx, nonce, nonce_size);
- aes_gcm_auth(ctx, auth, auth_size);
+ ret = aes_gcm_setiv(ctx, nonce, nonce_size);
+ if (ret < 0) {
+ return gnutls_assert_val(ret);
+ }
+
+ /* Always succeeds in this call sequence. */
+ (void)aes_gcm_auth(ctx, auth, auth_size);
aes_gcm_encrypt(ctx, plain, plain_size, encr, encr_size);
size_t plain_size)
{
uint8_t tag[MAX_HASH_SIZE];
+ int ret;
if (unlikely(encr_size < tag_size))
return gnutls_assert_val(GNUTLS_E_DECRYPTION_FAILED);
if (unlikely(plain_size < encr_size - tag_size))
return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER);
- aes_gcm_setiv(ctx, nonce, nonce_size);
- aes_gcm_auth(ctx, auth, auth_size);
+ ret = aes_gcm_setiv(ctx, nonce, nonce_size);
+ if (ret < 0) {
+ return gnutls_assert_val(ret);
+ }
+
+ /* Always succeeds in this call sequence. */
+ (void)aes_gcm_auth(ctx, auth, auth_size);
encr_size -= tag_size;
aes_gcm_decrypt(ctx, encr, encr_size, plain, plain_size);
{
struct aes_gcm_ctx *ctx = _ctx;
size_t s = 0;
+ int ret;
if (encr_size < plain_size + tag_size)
return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER);
- aes_gcm_setiv(ctx, nonce, nonce_size);
- aes_gcm_auth(ctx, auth, auth_size);
+ ret = aes_gcm_setiv(ctx, nonce, nonce_size);
+ if (ret < 0) {
+ return gnutls_assert_val(ret);
+ }
+
+ /* Always succeeds in this call sequence. */
+ (void)aes_gcm_auth(ctx, auth, auth_size);
if (plain_size >= 96) {
s = aesni_gcm_encrypt(plain, encr, plain_size,
struct aes_gcm_ctx *ctx = _ctx;
uint8_t tag[MAX_HASH_SIZE];
size_t s = 0;
+ int ret;
if (unlikely(encr_size < tag_size))
return gnutls_assert_val(GNUTLS_E_DECRYPTION_FAILED);
if (unlikely(plain_size < encr_size - tag_size))
return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER);
- aes_gcm_setiv(ctx, nonce, nonce_size);
- aes_gcm_auth(ctx, auth, auth_size);
+ ret = aes_gcm_setiv(ctx, nonce, nonce_size);
+ if (ret < 0) {
+ return gnutls_assert_val(ret);
+ }
+
+ /* Always succeeds in this call sequence. */
+ (void)aes_gcm_auth(ctx, auth, auth_size);
encr_size -= tag_size;