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