]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: x86/aes-gcm - use the new scatterwalk functions
authorEric Biggers <ebiggers@google.com>
Wed, 19 Feb 2025 18:23:36 +0000 (10:23 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sun, 2 Mar 2025 07:19:44 +0000 (15:19 +0800)
In gcm_process_assoc(), use scatterwalk_next() which consolidates
scatterwalk_clamp() and scatterwalk_map().  Use scatterwalk_done_src()
which consolidates scatterwalk_unmap(), scatterwalk_advance(), and
scatterwalk_done().

Also rename some variables to avoid implying that anything is actually
mapped (it's not), or that the loop is going page by page (it is for
now, but nothing actually requires that to be the case).

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/x86/crypto/aesni-intel_glue.c

index 82225fe50ec12d7b6d00a48a0f70484f2f915424..c4bd05688b558322b7e967c17e8506bbb53323d6 100644 (file)
@@ -1306,41 +1306,41 @@ static void gcm_process_assoc(const struct aes_gcm_key *key, u8 ghash_acc[16],
        scatterwalk_start(&walk, sg_src);
 
        while (assoclen) {
-               unsigned int len_this_page = scatterwalk_clamp(&walk, assoclen);
-               void *mapped = scatterwalk_map(&walk);
-               const void *src = mapped;
+               unsigned int orig_len_this_step;
+               const u8 *orig_src = scatterwalk_next(&walk, assoclen,
+                                                     &orig_len_this_step);
+               unsigned int len_this_step = orig_len_this_step;
                unsigned int len;
+               const u8 *src = orig_src;
 
-               assoclen -= len_this_page;
-               scatterwalk_advance(&walk, len_this_page);
                if (unlikely(pos)) {
-                       len = min(len_this_page, 16 - pos);
+                       len = min(len_this_step, 16 - pos);
                        memcpy(&buf[pos], src, len);
                        pos += len;
                        src += len;
-                       len_this_page -= len;
+                       len_this_step -= len;
                        if (pos < 16)
                                goto next;
                        aes_gcm_aad_update(key, ghash_acc, buf, 16, flags);
                        pos = 0;
                }
-               len = len_this_page;
+               len = len_this_step;
                if (unlikely(assoclen)) /* Not the last segment yet? */
                        len = round_down(len, 16);
                aes_gcm_aad_update(key, ghash_acc, src, len, flags);
                src += len;
-               len_this_page -= len;
-               if (unlikely(len_this_page)) {
-                       memcpy(buf, src, len_this_page);
-                       pos = len_this_page;
+               len_this_step -= len;
+               if (unlikely(len_this_step)) {
+                       memcpy(buf, src, len_this_step);
+                       pos = len_this_step;
                }
 next:
-               scatterwalk_unmap(mapped);
-               scatterwalk_pagedone(&walk, 0, assoclen);
+               scatterwalk_done_src(&walk, orig_src, orig_len_this_step);
                if (need_resched()) {
                        kernel_fpu_end();
                        kernel_fpu_begin();
                }
+               assoclen -= orig_len_this_step;
        }
        if (unlikely(pos))
                aes_gcm_aad_update(key, ghash_acc, buf, pos, flags);