Skip to content

Commit 8fd0eec

Browse files
ebiggersherbertx
authored andcommitted
crypto: arm64 - use the new scatterwalk functions
Use scatterwalk_next() which consolidates scatterwalk_clamp() and scatterwalk_map(), and use scatterwalk_done_src() which consolidates scatterwalk_unmap(), scatterwalk_advance(), and scatterwalk_done(). Remove unnecessary code that seemed to be intended to advance to the next sg entry, which is already handled by the scatterwalk functions. Adjust variable naming slightly to keep things consistent. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5dc14e0 commit 8fd0eec

File tree

4 files changed

+32
-59
lines changed

4 files changed

+32
-59
lines changed

arch/arm64/crypto/aes-ce-ccm-glue.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,14 @@ static void ccm_calculate_auth_mac(struct aead_request *req, u8 mac[])
156156
scatterwalk_start(&walk, req->src);
157157

158158
do {
159-
u32 n = scatterwalk_clamp(&walk, len);
160-
u8 *p;
161-
162-
if (!n) {
163-
scatterwalk_start(&walk, sg_next(walk.sg));
164-
n = scatterwalk_clamp(&walk, len);
165-
}
166-
p = scatterwalk_map(&walk);
159+
unsigned int n;
160+
const u8 *p;
167161

162+
p = scatterwalk_next(&walk, len, &n);
168163
macp = ce_aes_ccm_auth_data(mac, p, n, macp, ctx->key_enc,
169164
num_rounds(ctx));
170-
165+
scatterwalk_done_src(&walk, p, n);
171166
len -= n;
172-
173-
scatterwalk_unmap(p);
174-
scatterwalk_advance(&walk, n);
175-
scatterwalk_done(&walk, 0, len);
176167
} while (len);
177168
}
178169

arch/arm64/crypto/ghash-ce-glue.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,13 @@ static void gcm_calculate_auth_mac(struct aead_request *req, u64 dg[], u32 len)
308308
scatterwalk_start(&walk, req->src);
309309

310310
do {
311-
u32 n = scatterwalk_clamp(&walk, len);
312-
u8 *p;
313-
314-
if (!n) {
315-
scatterwalk_start(&walk, sg_next(walk.sg));
316-
n = scatterwalk_clamp(&walk, len);
317-
}
318-
p = scatterwalk_map(&walk);
311+
unsigned int n;
312+
const u8 *p;
319313

314+
p = scatterwalk_next(&walk, len, &n);
320315
gcm_update_mac(dg, p, n, buf, &buf_count, ctx);
316+
scatterwalk_done_src(&walk, p, n);
321317
len -= n;
322-
323-
scatterwalk_unmap(p);
324-
scatterwalk_advance(&walk, n);
325-
scatterwalk_done(&walk, 0, len);
326318
} while (len);
327319

328320
if (buf_count) {

arch/arm64/crypto/sm4-ce-ccm-glue.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,12 @@ static void ccm_calculate_auth_mac(struct aead_request *req, u8 mac[])
112112
scatterwalk_start(&walk, req->src);
113113

114114
do {
115-
u32 n = scatterwalk_clamp(&walk, assoclen);
116-
u8 *p, *ptr;
115+
unsigned int n, orig_n;
116+
const u8 *p, *orig_p;
117117

118-
if (!n) {
119-
scatterwalk_start(&walk, sg_next(walk.sg));
120-
n = scatterwalk_clamp(&walk, assoclen);
121-
}
122-
123-
p = ptr = scatterwalk_map(&walk);
124-
assoclen -= n;
125-
scatterwalk_advance(&walk, n);
118+
orig_p = scatterwalk_next(&walk, assoclen, &orig_n);
119+
p = orig_p;
120+
n = orig_n;
126121

127122
while (n > 0) {
128123
unsigned int l, nblocks;
@@ -136,9 +131,9 @@ static void ccm_calculate_auth_mac(struct aead_request *req, u8 mac[])
136131
} else {
137132
nblocks = n / SM4_BLOCK_SIZE;
138133
sm4_ce_cbcmac_update(ctx->rkey_enc,
139-
mac, ptr, nblocks);
134+
mac, p, nblocks);
140135

141-
ptr += nblocks * SM4_BLOCK_SIZE;
136+
p += nblocks * SM4_BLOCK_SIZE;
142137
n %= SM4_BLOCK_SIZE;
143138

144139
continue;
@@ -147,15 +142,15 @@ static void ccm_calculate_auth_mac(struct aead_request *req, u8 mac[])
147142

148143
l = min(n, SM4_BLOCK_SIZE - len);
149144
if (l) {
150-
crypto_xor(mac + len, ptr, l);
145+
crypto_xor(mac + len, p, l);
151146
len += l;
152-
ptr += l;
147+
p += l;
153148
n -= l;
154149
}
155150
}
156151

157-
scatterwalk_unmap(p);
158-
scatterwalk_done(&walk, 0, assoclen);
152+
scatterwalk_done_src(&walk, orig_p, orig_n);
153+
assoclen -= orig_n;
159154
} while (assoclen);
160155
}
161156

arch/arm64/crypto/sm4-ce-gcm-glue.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,24 @@ static void gcm_calculate_auth_mac(struct aead_request *req, u8 ghash[])
8282
scatterwalk_start(&walk, req->src);
8383

8484
do {
85-
u32 n = scatterwalk_clamp(&walk, assoclen);
86-
u8 *p, *ptr;
85+
unsigned int n, orig_n;
86+
const u8 *p, *orig_p;
8787

88-
if (!n) {
89-
scatterwalk_start(&walk, sg_next(walk.sg));
90-
n = scatterwalk_clamp(&walk, assoclen);
91-
}
92-
93-
p = ptr = scatterwalk_map(&walk);
94-
assoclen -= n;
95-
scatterwalk_advance(&walk, n);
88+
orig_p = scatterwalk_next(&walk, assoclen, &orig_n);
89+
p = orig_p;
90+
n = orig_n;
9691

9792
if (n + buflen < GHASH_BLOCK_SIZE) {
98-
memcpy(&buffer[buflen], ptr, n);
93+
memcpy(&buffer[buflen], p, n);
9994
buflen += n;
10095
} else {
10196
unsigned int nblocks;
10297

10398
if (buflen) {
10499
unsigned int l = GHASH_BLOCK_SIZE - buflen;
105100

106-
memcpy(&buffer[buflen], ptr, l);
107-
ptr += l;
101+
memcpy(&buffer[buflen], p, l);
102+
p += l;
108103
n -= l;
109104

110105
pmull_ghash_update(ctx->ghash_table, ghash,
@@ -114,17 +109,17 @@ static void gcm_calculate_auth_mac(struct aead_request *req, u8 ghash[])
114109
nblocks = n / GHASH_BLOCK_SIZE;
115110
if (nblocks) {
116111
pmull_ghash_update(ctx->ghash_table, ghash,
117-
ptr, nblocks);
118-
ptr += nblocks * GHASH_BLOCK_SIZE;
112+
p, nblocks);
113+
p += nblocks * GHASH_BLOCK_SIZE;
119114
}
120115

121116
buflen = n % GHASH_BLOCK_SIZE;
122117
if (buflen)
123-
memcpy(&buffer[0], ptr, buflen);
118+
memcpy(&buffer[0], p, buflen);
124119
}
125120

126-
scatterwalk_unmap(p);
127-
scatterwalk_done(&walk, 0, assoclen);
121+
scatterwalk_done_src(&walk, orig_p, orig_n);
122+
assoclen -= orig_n;
128123
} while (assoclen);
129124

130125
/* padding with '0' */

0 commit comments

Comments
 (0)