#include "includes.h"
#include "common.h"
-#include "aes_i.h"
+#include "aes.h"
/**
* aes_128_cbc_encrypt - AES-128 CBC encryption
int aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
{
void *ctx;
- u8 cbc[BLOCK_SIZE];
+ 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, BLOCK_SIZE);
+ os_memcpy(cbc, iv, AES_BLOCK_SIZE);
- blocks = data_len / BLOCK_SIZE;
+ blocks = data_len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
- for (j = 0; j < BLOCK_SIZE; j++)
+ for (j = 0; j < AES_BLOCK_SIZE; j++)
cbc[j] ^= pos[j];
aes_encrypt(ctx, cbc, cbc);
- os_memcpy(pos, cbc, BLOCK_SIZE);
- pos += BLOCK_SIZE;
+ os_memcpy(pos, cbc, AES_BLOCK_SIZE);
+ pos += AES_BLOCK_SIZE;
}
aes_encrypt_deinit(ctx);
return 0;
int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
{
void *ctx;
- u8 cbc[BLOCK_SIZE], tmp[BLOCK_SIZE];
+ u8 cbc[AES_BLOCK_SIZE], tmp[AES_BLOCK_SIZE];
u8 *pos = data;
int i, j, blocks;
ctx = aes_decrypt_init(key, 16);
if (ctx == NULL)
return -1;
- os_memcpy(cbc, iv, BLOCK_SIZE);
+ os_memcpy(cbc, iv, AES_BLOCK_SIZE);
- blocks = data_len / BLOCK_SIZE;
+ blocks = data_len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
- os_memcpy(tmp, pos, BLOCK_SIZE);
+ os_memcpy(tmp, pos, AES_BLOCK_SIZE);
aes_decrypt(ctx, pos, pos);
- for (j = 0; j < BLOCK_SIZE; j++)
+ for (j = 0; j < AES_BLOCK_SIZE; j++)
pos[j] ^= cbc[j];
- os_memcpy(cbc, tmp, BLOCK_SIZE);
- pos += BLOCK_SIZE;
+ os_memcpy(cbc, tmp, AES_BLOCK_SIZE);
+ pos += AES_BLOCK_SIZE;
}
aes_decrypt_deinit(ctx);
return 0;
#include "includes.h"
#include "common.h"
-#include "aes_i.h"
+#include "aes.h"
/**
* aes_128_ctr_encrypt - AES-128 CTR mode encryption
size_t j, len, left = data_len;
int i;
u8 *pos = data;
- u8 counter[BLOCK_SIZE], buf[BLOCK_SIZE];
+ u8 counter[AES_BLOCK_SIZE], buf[AES_BLOCK_SIZE];
ctx = aes_encrypt_init(key, 16);
if (ctx == NULL)
return -1;
- os_memcpy(counter, nonce, BLOCK_SIZE);
+ os_memcpy(counter, nonce, AES_BLOCK_SIZE);
while (left > 0) {
aes_encrypt(ctx, counter, buf);
- len = (left < BLOCK_SIZE) ? left : BLOCK_SIZE;
+ len = (left < AES_BLOCK_SIZE) ? left : AES_BLOCK_SIZE;
for (j = 0; j < len; j++)
pos[j] ^= buf[j];
pos += len;
left -= len;
- for (i = BLOCK_SIZE - 1; i >= 0; i--) {
+ for (i = AES_BLOCK_SIZE - 1; i >= 0; i--) {
counter[i]++;
if (counter[i])
break;
#include "includes.h"
#include "common.h"
-#include "aes_i.h"
+#include "aes.h"
#include "aes_wrap.h"
/**
{
u8 *buf;
size_t buf_len;
- u8 nonce_mac[BLOCK_SIZE], hdr_mac[BLOCK_SIZE], data_mac[BLOCK_SIZE];
+ u8 nonce_mac[AES_BLOCK_SIZE], hdr_mac[AES_BLOCK_SIZE],
+ data_mac[AES_BLOCK_SIZE];
int i, ret = -1;
if (nonce_len > data_len)
if (omac1_aes_128(key, buf, 16 + data_len, data_mac))
goto fail;
- for (i = 0; i < BLOCK_SIZE; i++)
+ for (i = 0; i < AES_BLOCK_SIZE; i++)
tag[i] = nonce_mac[i] ^ data_mac[i] ^ hdr_mac[i];
ret = 0;
{
u8 *buf;
size_t buf_len;
- u8 nonce_mac[BLOCK_SIZE], hdr_mac[BLOCK_SIZE], data_mac[BLOCK_SIZE];
+ u8 nonce_mac[AES_BLOCK_SIZE], hdr_mac[AES_BLOCK_SIZE],
+ data_mac[AES_BLOCK_SIZE];
int i;
if (nonce_len > data_len)
os_free(buf);
- for (i = 0; i < BLOCK_SIZE; i++) {
+ for (i = 0; i < AES_BLOCK_SIZE; i++) {
if (tag[i] != (nonce_mac[i] ^ data_mac[i] ^ hdr_mac[i]))
return -2;
}
#include "includes.h"
#include "common.h"
-#include "aes_i.h"
+#include "aes.h"
/**
* aes_128_encrypt_block - Perform one AES 128-bit block operation
#include "includes.h"
#include "common.h"
-#include "aes_i.h"
+#include "aes.h"
static void gf_mulx(u8 *pad)
{
int i, carry;
carry = pad[0] & 0x80;
- for (i = 0; i < BLOCK_SIZE - 1; i++)
+ for (i = 0; i < AES_BLOCK_SIZE - 1; i++)
pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7);
- pad[BLOCK_SIZE - 1] <<= 1;
+ pad[AES_BLOCK_SIZE - 1] <<= 1;
if (carry)
- pad[BLOCK_SIZE - 1] ^= 0x87;
+ pad[AES_BLOCK_SIZE - 1] ^= 0x87;
}
const u8 *addr[], const size_t *len, u8 *mac)
{
void *ctx;
- u8 cbc[BLOCK_SIZE], pad[BLOCK_SIZE];
+ u8 cbc[AES_BLOCK_SIZE], pad[AES_BLOCK_SIZE];
const u8 *pos, *end;
size_t i, e, left, total_len;
ctx = aes_encrypt_init(key, 16);
if (ctx == NULL)
return -1;
- os_memset(cbc, 0, BLOCK_SIZE);
+ os_memset(cbc, 0, AES_BLOCK_SIZE);
total_len = 0;
for (e = 0; e < num_elem; e++)
pos = addr[0];
end = pos + len[0];
- while (left >= BLOCK_SIZE) {
- for (i = 0; i < BLOCK_SIZE; i++) {
+ while (left >= AES_BLOCK_SIZE) {
+ for (i = 0; i < AES_BLOCK_SIZE; i++) {
cbc[i] ^= *pos++;
if (pos >= end) {
e++;
end = pos + len[e];
}
}
- if (left > BLOCK_SIZE)
+ if (left > AES_BLOCK_SIZE)
aes_encrypt(ctx, cbc, cbc);
- left -= BLOCK_SIZE;
+ left -= AES_BLOCK_SIZE;
}
- os_memset(pad, 0, BLOCK_SIZE);
+ os_memset(pad, 0, AES_BLOCK_SIZE);
aes_encrypt(ctx, pad, pad);
gf_mulx(pad);
gf_mulx(pad);
}
- for (i = 0; i < BLOCK_SIZE; i++)
+ for (i = 0; i < AES_BLOCK_SIZE; i++)
pad[i] ^= cbc[i];
aes_encrypt(ctx, pad, mac);
aes_encrypt_deinit(ctx);
#include "includes.h"
#include "common.h"
-#include "aes_i.h"
+#include "aes.h"
/**
* aes_unwrap - Unwrap key with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
#include "includes.h"
#include "common.h"
-#include "aes_i.h"
+#include "aes.h"
/**
* aes_wrap - Wrap keys with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
#ifndef AES_H
#define AES_H
+#define AES_BLOCK_SIZE 16
+
void * aes_encrypt_init(const u8 *key, size_t len);
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
void aes_encrypt_deinit(void *ctx);
#include "aes.h"
-#define BLOCK_SIZE 16
-
/* #define FULL_UNROLL */
#define AES_SMALL_TABLES