/* See README and COPYING for more details. aes_128_cbc_encrypt - AES-128 CBC encryption @key: Encryption key @iv: Encryption IV for CBC mode (16 bytes) @data: Data to encrypt in-place @data_len: Length of data in bytes (must be divisible by 16) Returns: 0 on success, -1 on failure  */
int aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
/* See README and COPYING for more details. aes_128_cbc_encrypt - AES-128 CBC encryption @key: Encryption key @iv: Encryption IV for CBC mode (16 bytes) @data: Data to encrypt in-place @data_len: Length of data in bytes (must be divisible by 16) Returns: 0 on success, -1 on failure  */
int aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
{
	void *ctx;
	u8 cbc[AES_BLOCK_SIZE];
	u8 *pos = data;
	int i, j, blocks;
	ctx = aes_encrypt_init(key, 16);
	if (ctx == NULL)
		return -1;
	os_memcpy(cbc, iv, AES_BLOCK_SIZE);
	blocks = data_len / AES_BLOCK_SIZE;
	for (i = 0; i < blocks; i++) {
		for (j = 0; j < AES_BLOCK_SIZE; j++)
			cbc[j] ^= pos[j];
		aes_encrypt(ctx, cbc, cbc);
		os_memcpy(pos, cbc, AES_BLOCK_SIZE);
		pos += AES_BLOCK_SIZE;
	}
	aes_encrypt_deinit(ctx);
	return 0;
}