4 * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
17 * aes_128_ctr_encrypt - AES-128 CTR mode encryption
18 * @key: Key for encryption (16 bytes)
19 * @nonce: Nonce for counter mode (16 bytes)
20 * @data: Data to encrypt in-place
21 * @data_len: Length of data in bytes
22 * Returns: 0 on success, -1 on failure
24 int aes_128_ctr_encrypt(const u8 *key, const u8 *nonce,
25 u8 *data, size_t data_len)
28 size_t j, len, left = data_len;
31 u8 counter[AES_BLOCK_SIZE], buf[AES_BLOCK_SIZE];
33 ctx = aes_encrypt_init(key, 16);
36 os_memcpy(counter, nonce, AES_BLOCK_SIZE);
39 aes_encrypt(ctx, counter, buf);
41 len = (left < AES_BLOCK_SIZE) ? left : AES_BLOCK_SIZE;
42 for (j = 0; j < len; j++)
47 for (i = AES_BLOCK_SIZE - 1; i >= 0; i--) {
53 aes_encrypt_deinit(ctx);