Skip to content

Commit 413808b

Browse files
ebiggersherbertx
authored andcommitted
crypto: lib/chacha20poly1305 - use chacha20_crypt()
Use chacha20_crypt() instead of chacha_crypt(), since it's not really appropriate for users of the ChaCha library API to be passing the number of rounds as an argument. Signed-off-by: Eric Biggers <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent b62755a commit 413808b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/crypto/chacha20poly1305.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ __chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
6666
__le64 lens[2];
6767
} b;
6868

69-
chacha_crypt(chacha_state, b.block0, pad0, sizeof(b.block0), 20);
69+
chacha20_crypt(chacha_state, b.block0, pad0, sizeof(b.block0));
7070
poly1305_init(&poly1305_state, b.block0);
7171

7272
poly1305_update(&poly1305_state, ad, ad_len);
7373
if (ad_len & 0xf)
7474
poly1305_update(&poly1305_state, pad0, 0x10 - (ad_len & 0xf));
7575

76-
chacha_crypt(chacha_state, dst, src, src_len, 20);
76+
chacha20_crypt(chacha_state, dst, src, src_len);
7777

7878
poly1305_update(&poly1305_state, dst, src_len);
7979
if (src_len & 0xf)
@@ -140,7 +140,7 @@ __chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
140140
if (unlikely(src_len < POLY1305_DIGEST_SIZE))
141141
return false;
142142

143-
chacha_crypt(chacha_state, b.block0, pad0, sizeof(b.block0), 20);
143+
chacha20_crypt(chacha_state, b.block0, pad0, sizeof(b.block0));
144144
poly1305_init(&poly1305_state, b.block0);
145145

146146
poly1305_update(&poly1305_state, ad, ad_len);
@@ -160,7 +160,7 @@ __chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
160160

161161
ret = crypto_memneq(b.mac, src + dst_len, POLY1305_DIGEST_SIZE);
162162
if (likely(!ret))
163-
chacha_crypt(chacha_state, dst, src, dst_len, 20);
163+
chacha20_crypt(chacha_state, dst, src, dst_len);
164164

165165
memzero_explicit(&b, sizeof(b));
166166

@@ -241,7 +241,7 @@ bool chacha20poly1305_crypt_sg_inplace(struct scatterlist *src,
241241
b.iv[1] = cpu_to_le64(nonce);
242242

243243
chacha_init(chacha_state, b.k, (u8 *)b.iv);
244-
chacha_crypt(chacha_state, b.block0, pad0, sizeof(b.block0), 20);
244+
chacha20_crypt(chacha_state, b.block0, pad0, sizeof(b.block0));
245245
poly1305_init(&poly1305_state, b.block0);
246246

247247
if (unlikely(ad_len)) {
@@ -278,14 +278,14 @@ bool chacha20poly1305_crypt_sg_inplace(struct scatterlist *src,
278278

279279
if (unlikely(length < sl))
280280
l &= ~(CHACHA_BLOCK_SIZE - 1);
281-
chacha_crypt(chacha_state, addr, addr, l, 20);
281+
chacha20_crypt(chacha_state, addr, addr, l);
282282
addr += l;
283283
length -= l;
284284
}
285285

286286
if (unlikely(length > 0)) {
287-
chacha_crypt(chacha_state, b.chacha_stream, pad0,
288-
CHACHA_BLOCK_SIZE, 20);
287+
chacha20_crypt(chacha_state, b.chacha_stream, pad0,
288+
CHACHA_BLOCK_SIZE);
289289
crypto_xor(addr, b.chacha_stream, length);
290290
partial = length;
291291
}

0 commit comments

Comments
 (0)