]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
lib/accelerated: use unlikely on buffer length checks more consistently
authorAlexander Sosedkin <asosedkin@redhat.com>
Wed, 26 Jan 2022 15:25:01 +0000 (16:25 +0100)
committerAlexander Sosedkin <asosedkin@redhat.com>
Wed, 26 Jan 2022 15:50:35 +0000 (16:50 +0100)
Signed-off-by: Alexander Sosedkin <asosedkin@redhat.com>
lib/accelerated/afalg.c
lib/accelerated/cryptodev-gcm.c

index 03a8e957b5d334fdd02d8104f6fac3c5b0f74794..024925143201cbca59062dfac1ce9362531cdd93 100644 (file)
@@ -421,7 +421,7 @@ static int afalg_aead_encrypt(void *_ctx, const void *nonce, size_t nonce_size,
                return GNUTLS_E_MEMORY_ERROR;
        }
 
-       if (encr_size - tag_size < plain_size) {
+       if (unlikely(encr_size - tag_size < plain_size)) {
                ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
                gnutls_assert();
                goto end;
index d75ea45b9051bcbf8033a6f183d41c114423bef3..f729406b8ea14db72f6a0cda0a135b40d02743ab 100644 (file)
@@ -137,7 +137,7 @@ aes_gcm_encrypt(void *_ctx, const void *src, size_t src_size,
        /* the GCM in kernel will place the tag after the
         * encrypted data.
         */
-       if (dst_size - GCM_BLOCK_SIZE < src_size)
+       if (unlikely(dst_size - GCM_BLOCK_SIZE < src_size))
                return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER);
 
        ctx->cryp.len = src_size;
@@ -176,7 +176,7 @@ aes_gcm_decrypt(void *_ctx, const void *src, size_t src_size,
        ctx->cryp.auth_len = ctx->auth_data_size;
        ctx->cryp.auth_src = ctx->auth_data;
 
-       if (dst_size < src_size - GCM_BLOCK_SIZE)
+       if (unlikely(dst_size < src_size - GCM_BLOCK_SIZE))
                return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER);
 
        if (ioctl(ctx->cfd, CIOCAUTHCRYPT, &ctx->cryp)) {