xref: /linux/include/crypto/aes-cbc.h (revision d47db9bf50d28647689e6743ee93c45cb755ffc3)
1*3cbcf6a2SEric Biggers /* SPDX-License-Identifier: GPL-2.0 */
2*3cbcf6a2SEric Biggers /*
3*3cbcf6a2SEric Biggers  * AES-CBC and AES-CBC-CTS unauthenticated encryption and decryption
4*3cbcf6a2SEric Biggers  *
5*3cbcf6a2SEric Biggers  * Copyright 2026 Google LLC
6*3cbcf6a2SEric Biggers  */
7*3cbcf6a2SEric Biggers #ifndef _CRYPTO_AES_CBC_H
8*3cbcf6a2SEric Biggers #define _CRYPTO_AES_CBC_H
9*3cbcf6a2SEric Biggers 
10*3cbcf6a2SEric Biggers #include <crypto/aes.h>
11*3cbcf6a2SEric Biggers 
12*3cbcf6a2SEric Biggers /**
13*3cbcf6a2SEric Biggers  * aes_cbc_encrypt() - Encrypt data using AES-CBC
14*3cbcf6a2SEric Biggers  * @dst: The destination buffer.  Can be in-place or out-of-place.  For other
15*3cbcf6a2SEric Biggers  *	 overlaps the behavior is unspecified.
16*3cbcf6a2SEric Biggers  * @src: The source data
17*3cbcf6a2SEric Biggers  * @len: Number of bytes to encrypt.  Must be a multiple of AES_BLOCK_SIZE.
18*3cbcf6a2SEric Biggers  * @iv: The initialization vector.  It is updated with the next value, i.e. the
19*3cbcf6a2SEric Biggers  *	last ciphertext block (or left unchanged if @len == 0).
20*3cbcf6a2SEric Biggers  * @key: The key, already prepared using aes_preparekey() or aes_prepareenckey()
21*3cbcf6a2SEric Biggers  *
22*3cbcf6a2SEric Biggers  * This supports incremental encryption.  The length of each chunk must be a
23*3cbcf6a2SEric Biggers  * multiple of AES_BLOCK_SIZE, and the updated @iv must be passed in each time.
24*3cbcf6a2SEric Biggers  *
25*3cbcf6a2SEric Biggers  * Context: Any context.
26*3cbcf6a2SEric Biggers  */
27*3cbcf6a2SEric Biggers void aes_cbc_encrypt(u8 *dst, const u8 *src, size_t len,
28*3cbcf6a2SEric Biggers 		     u8 iv[at_least AES_BLOCK_SIZE], aes_encrypt_arg key);
29*3cbcf6a2SEric Biggers 
30*3cbcf6a2SEric Biggers /**
31*3cbcf6a2SEric Biggers  * aes_cbc_decrypt() - Decrypt data using AES-CBC
32*3cbcf6a2SEric Biggers  * @dst: The destination buffer.  Can be in-place or out-of-place.  For other
33*3cbcf6a2SEric Biggers  *	 overlaps the behavior is unspecified.
34*3cbcf6a2SEric Biggers  * @src: The source data
35*3cbcf6a2SEric Biggers  * @len: Number of bytes to decrypt.  Must be a multiple of AES_BLOCK_SIZE.
36*3cbcf6a2SEric Biggers  * @iv: The initialization vector.  It is updated with the next value, i.e. the
37*3cbcf6a2SEric Biggers  *	last ciphertext block (or left unchanged if @len == 0).
38*3cbcf6a2SEric Biggers  * @key: The key, already prepared using aes_preparekey()
39*3cbcf6a2SEric Biggers  *
40*3cbcf6a2SEric Biggers  * This supports incremental decryption.  The length of each chunk must be a
41*3cbcf6a2SEric Biggers  * multiple of AES_BLOCK_SIZE, and the updated @iv must be passed in each time.
42*3cbcf6a2SEric Biggers  *
43*3cbcf6a2SEric Biggers  * Context: Any context.
44*3cbcf6a2SEric Biggers  */
45*3cbcf6a2SEric Biggers void aes_cbc_decrypt(u8 *dst, const u8 *src, size_t len,
46*3cbcf6a2SEric Biggers 		     u8 iv[at_least AES_BLOCK_SIZE], const struct aes_key *key);
47*3cbcf6a2SEric Biggers 
48*3cbcf6a2SEric Biggers /**
49*3cbcf6a2SEric Biggers  * aes_cbc_cts_encrypt() - Encrypt data using AES-CBC-CTS (CS3 variant)
50*3cbcf6a2SEric Biggers  * @dst: The destination buffer.  Can be in-place or out-of-place.  For other
51*3cbcf6a2SEric Biggers  *	 overlaps the behavior is unspecified.
52*3cbcf6a2SEric Biggers  * @src: The source data
53*3cbcf6a2SEric Biggers  * @len: Number of bytes to encrypt, at least AES_BLOCK_SIZE
54*3cbcf6a2SEric Biggers  * @iv: The initialization vector, clobbered by this function
55*3cbcf6a2SEric Biggers  * @key: The key, already prepared using aes_preparekey() or aes_prepareenckey()
56*3cbcf6a2SEric Biggers  *
57*3cbcf6a2SEric Biggers  * Context: Any context.
58*3cbcf6a2SEric Biggers  */
59*3cbcf6a2SEric Biggers void aes_cbc_cts_encrypt(u8 *dst, const u8 *src, size_t len,
60*3cbcf6a2SEric Biggers 			 u8 iv[at_least AES_BLOCK_SIZE], aes_encrypt_arg key);
61*3cbcf6a2SEric Biggers 
62*3cbcf6a2SEric Biggers /**
63*3cbcf6a2SEric Biggers  * aes_cbc_cts_decrypt() - Decrypt data using AES-CBC-CTS (CS3 variant)
64*3cbcf6a2SEric Biggers  * @dst: The destination buffer.  Can be in-place or out-of-place.  For other
65*3cbcf6a2SEric Biggers  *	 overlaps the behavior is unspecified.
66*3cbcf6a2SEric Biggers  * @src: The source data
67*3cbcf6a2SEric Biggers  * @len: Number of bytes to decrypt, at least AES_BLOCK_SIZE
68*3cbcf6a2SEric Biggers  * @iv: The initialization vector, clobbered by this function
69*3cbcf6a2SEric Biggers  * @key: The key, already prepared using aes_preparekey()
70*3cbcf6a2SEric Biggers  *
71*3cbcf6a2SEric Biggers  * Context: Any context.
72*3cbcf6a2SEric Biggers  */
73*3cbcf6a2SEric Biggers void aes_cbc_cts_decrypt(u8 *dst, const u8 *src, size_t len,
74*3cbcf6a2SEric Biggers 			 u8 iv[at_least AES_BLOCK_SIZE],
75*3cbcf6a2SEric Biggers 			 const struct aes_key *key);
76*3cbcf6a2SEric Biggers 
77*3cbcf6a2SEric Biggers #endif /* _CRYPTO_AES_CBC_H */
78