Skip to content

Commit e9787de

Browse files
ebiggersherbertx
authored andcommitted
crypto: x86/aes-gcm - use the new scatterwalk functions
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>
1 parent 95c4751 commit e9787de

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

arch/x86/crypto/aesni-intel_glue.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,41 +1306,41 @@ static void gcm_process_assoc(const struct aes_gcm_key *key, u8 ghash_acc[16],
13061306
scatterwalk_start(&walk, sg_src);
13071307

13081308
while (assoclen) {
1309-
unsigned int len_this_page = scatterwalk_clamp(&walk, assoclen);
1310-
void *mapped = scatterwalk_map(&walk);
1311-
const void *src = mapped;
1309+
unsigned int orig_len_this_step;
1310+
const u8 *orig_src = scatterwalk_next(&walk, assoclen,
1311+
&orig_len_this_step);
1312+
unsigned int len_this_step = orig_len_this_step;
13121313
unsigned int len;
1314+
const u8 *src = orig_src;
13131315

1314-
assoclen -= len_this_page;
1315-
scatterwalk_advance(&walk, len_this_page);
13161316
if (unlikely(pos)) {
1317-
len = min(len_this_page, 16 - pos);
1317+
len = min(len_this_step, 16 - pos);
13181318
memcpy(&buf[pos], src, len);
13191319
pos += len;
13201320
src += len;
1321-
len_this_page -= len;
1321+
len_this_step -= len;
13221322
if (pos < 16)
13231323
goto next;
13241324
aes_gcm_aad_update(key, ghash_acc, buf, 16, flags);
13251325
pos = 0;
13261326
}
1327-
len = len_this_page;
1327+
len = len_this_step;
13281328
if (unlikely(assoclen)) /* Not the last segment yet? */
13291329
len = round_down(len, 16);
13301330
aes_gcm_aad_update(key, ghash_acc, src, len, flags);
13311331
src += len;
1332-
len_this_page -= len;
1333-
if (unlikely(len_this_page)) {
1334-
memcpy(buf, src, len_this_page);
1335-
pos = len_this_page;
1332+
len_this_step -= len;
1333+
if (unlikely(len_this_step)) {
1334+
memcpy(buf, src, len_this_step);
1335+
pos = len_this_step;
13361336
}
13371337
next:
1338-
scatterwalk_unmap(mapped);
1339-
scatterwalk_pagedone(&walk, 0, assoclen);
1338+
scatterwalk_done_src(&walk, orig_src, orig_len_this_step);
13401339
if (need_resched()) {
13411340
kernel_fpu_end();
13421341
kernel_fpu_begin();
13431342
}
1343+
assoclen -= orig_len_this_step;
13441344
}
13451345
if (unlikely(pos))
13461346
aes_gcm_aad_update(key, ghash_acc, buf, pos, flags);

0 commit comments

Comments
 (0)