Skip to content

Commit

Permalink
aes: [CBC] add ISAL_ prefix to definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Cornu <marcel.d.cornu@intel.com>
  • Loading branch information
mdcornu authored and tkanteck committed May 20, 2024
1 parent 42a5133 commit e4a8493
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 88 deletions.
2 changes: 1 addition & 1 deletion aes/aarch64/cbc_dec_aes.S
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
void _aes_cbc_dec_128(
void *in, //!< Input cipher text
uint8_t *IV, //!< Must be 16 bytes aligned to a 16 byte boundary
uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key rounds or dec_keys of cbc_key_data
uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key rounds or dec_keys of isal_cbc_key_data
void *out, //!< Output plain text
uint64_t len_bytes //!< Must be a multiple of 16 bytes
);
Expand Down
2 changes: 1 addition & 1 deletion aes/aarch64/cbc_enc_aes.S
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
void _aes_cbc_dec_128(
void *in, //!< Input cipher text
uint8_t *IV, //!< Must be 16 bytes aligned to a 16 byte boundary
uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key rounds or dec_keys of cbc_key_data
uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key rounds or dec_keys of isal_cbc_key_data
void *out, //!< Output plain text
uint64_t len_bytes //!< Must be a multiple of 16 bytes
);
Expand Down
12 changes: 6 additions & 6 deletions aes/aes_param_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ struct test_func {
static int
test_aes_keyexp_api(aes_keyexp_func aes_keyexp_func_ptr, const char *name)
{
uint8_t key[CBC_ROUND_KEY_LEN] = { 0 };
uint8_t enc_keys[CBC_MAX_KEYS_SIZE] = { 0 };
uint8_t dec_keys[CBC_MAX_KEYS_SIZE] = { 0 };
uint8_t key[ISAL_CBC_ROUND_KEY_LEN] = { 0 };
uint8_t enc_keys[ISAL_CBC_MAX_KEYS_SIZE] = { 0 };
uint8_t dec_keys[ISAL_CBC_MAX_KEYS_SIZE] = { 0 };

// test null key
CHECK_RETURN(aes_keyexp_func_ptr(NULL, enc_keys, dec_keys), ISAL_CRYPTO_ERR_NULL_KEY, name);
Expand All @@ -103,7 +103,7 @@ test_aes_keyexp_api(aes_keyexp_func aes_keyexp_func_ptr, const char *name)
static int
test_aes_cbc_api(aes_cbc_func aes_cbc_func_ptr, const char *name)
{
uint8_t exp_keys[CBC_MAX_KEYS_SIZE] = { 0 };
uint8_t exp_keys[ISAL_CBC_MAX_KEYS_SIZE] = { 0 };
uint8_t buf[16] = { 0 };
uint8_t iv[16] = { 0 };

Expand Down Expand Up @@ -132,9 +132,9 @@ static int
test_aes_xts_api(aes_xts_func aes_xts_func_ptr, const char *name, const int expanded_key)
{
uint8_t key1[32] = { 0 };
uint8_t exp_keys1[CBC_MAX_KEYS_SIZE] = { 0 };
uint8_t exp_keys1[ISAL_CBC_MAX_KEYS_SIZE] = { 0 };
uint8_t key2[32];
uint8_t exp_keys2[CBC_MAX_KEYS_SIZE];
uint8_t exp_keys2[ISAL_CBC_MAX_KEYS_SIZE];
uint8_t buf[16] = { 0 };
uint8_t tweak[16] = { 0 };

Expand Down
20 changes: 10 additions & 10 deletions aes/cbc_ossl_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static unsigned char *ciphertext = NULL;
static unsigned char *ossl_plaintext = NULL;
static unsigned char *ossl_ciphertext = NULL;

static uint8_t test_key[CBC_256_BITS];
static uint8_t test_key[ISAL_CBC_256_BITS];

void
mk_rand_data(uint8_t *data, uint32_t size)
Expand All @@ -83,9 +83,9 @@ aes_128_perf(uint8_t *key)

/* Initialize our cipher context, which can use same input vectors */
uint8_t *iv = NULL;
struct cbc_key_data *key_data = NULL;
struct isal_cbc_key_data *key_data = NULL;

ret = posix_memalign((void **) &iv, 16, (CBC_IV_DATA_LEN));
ret = posix_memalign((void **) &iv, 16, (ISAL_CBC_IV_DATA_LEN));
if (ret) {
printf("alloc error: Fail");
return 1;
Expand All @@ -97,7 +97,7 @@ aes_128_perf(uint8_t *key)
goto exit;
}

memcpy(iv, ic, CBC_IV_DATA_LEN);
memcpy(iv, ic, ISAL_CBC_IV_DATA_LEN);

isal_aes_keyexp_128(key, key_data->enc_keys, key_data->dec_keys);
isal_aes_cbc_enc_128(plaintext, iv, key_data->enc_keys, ciphertext, TEST_LEN);
Expand Down Expand Up @@ -169,9 +169,9 @@ aes_192_perf(uint8_t *key)
{
int i, ret;
uint8_t *iv = NULL;
struct cbc_key_data *key_data = NULL;
struct isal_cbc_key_data *key_data = NULL;

ret = posix_memalign((void **) &iv, 16, (CBC_IV_DATA_LEN));
ret = posix_memalign((void **) &iv, 16, (ISAL_CBC_IV_DATA_LEN));
if (ret) {
printf("alloc error: Fail");
return 1;
Expand All @@ -183,7 +183,7 @@ aes_192_perf(uint8_t *key)
goto exit;
}

memcpy(iv, ic, CBC_IV_DATA_LEN);
memcpy(iv, ic, ISAL_CBC_IV_DATA_LEN);
isal_aes_keyexp_192(key, key_data->enc_keys, key_data->dec_keys);
isal_aes_cbc_enc_192(plaintext, iv, key_data->enc_keys, ciphertext, TEST_LEN);
openssl_aes_192_cbc_enc(key, iv, TEST_LEN, plaintext, ossl_ciphertext);
Expand Down Expand Up @@ -254,9 +254,9 @@ aes_256_perf(uint8_t *key)
{
int i, ret;
uint8_t *iv = NULL;
struct cbc_key_data *key_data = NULL;
struct isal_cbc_key_data *key_data = NULL;

ret = posix_memalign((void **) &iv, 16, (CBC_IV_DATA_LEN));
ret = posix_memalign((void **) &iv, 16, (ISAL_CBC_IV_DATA_LEN));
if (ret) {
printf("alloc error: Fail");
return 1;
Expand All @@ -269,7 +269,7 @@ aes_256_perf(uint8_t *key)
}

isal_aes_keyexp_256(key, key_data->enc_keys, key_data->dec_keys);
memcpy(iv, ic, CBC_IV_DATA_LEN);
memcpy(iv, ic, ISAL_CBC_IV_DATA_LEN);
isal_aes_cbc_enc_256(plaintext, iv, key_data->enc_keys, ciphertext, TEST_LEN);
openssl_aes_256_cbc_enc(key, iv, TEST_LEN, plaintext, ossl_ciphertext);

Expand Down
8 changes: 4 additions & 4 deletions aes/cbc_pre.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
#include "aes_keyexp_internal.h"

int
aes_cbc_precomp(uint8_t *key, int key_size, struct cbc_key_data *keys_blk)
aes_cbc_precomp(uint8_t *key, int key_size, struct isal_cbc_key_data *keys_blk)
{
if (CBC_128_BITS == key_size) {
if (ISAL_CBC_128_BITS == key_size) {
_aes_keyexp_128(key, keys_blk->enc_keys, keys_blk->dec_keys);
} else if (CBC_192_BITS == key_size) {
} else if (ISAL_CBC_192_BITS == key_size) {
_aes_keyexp_192(key, keys_blk->enc_keys, keys_blk->dec_keys);
} else if (CBC_256_BITS == key_size) {
} else if (ISAL_CBC_256_BITS == key_size) {
_aes_keyexp_256(key, keys_blk->enc_keys, keys_blk->dec_keys);
} else {
// Invalid key length
Expand Down
12 changes: 6 additions & 6 deletions aes/cbc_std_vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@

// struct to hold pointers to the cbc data vectors
struct cbc_vector {
uint8_t *K; // AES Key
cbc_key_size K_LEN; // length of key in bits
uint8_t *IV; // initial value used by GCM
uint64_t P_LEN; // length of our plaintext
uint8_t *P; // Plain text
uint8_t *K; // AES Key
isal_cbc_key_size K_LEN; // length of key in bits
uint8_t *IV; // initial value used by GCM
uint64_t P_LEN; // length of our plaintext
uint8_t *P; // Plain text
// outputs of encryption
uint8_t *EXP_C; // same length as P
// used in vector checks, not populated in std vector array
uint8_t *C;
struct cbc_key_data *KEYS;
struct isal_cbc_key_data *KEYS;
};

///////////////////////////////////////////
Expand Down
44 changes: 23 additions & 21 deletions aes/cbc_std_vectors_random_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,26 @@
#define MAX_UNALINED (16)
#endif

static cbc_key_size const Ksize[] = { CBC_128_BITS, CBC_192_BITS, CBC_256_BITS };
static isal_cbc_key_size const Ksize[] = { ISAL_CBC_128_BITS, ISAL_CBC_192_BITS,
ISAL_CBC_256_BITS };

typedef void (*aes_cbc_generic)(uint8_t *in, uint8_t *IV, uint8_t *keys, uint8_t *out,
uint64_t len_bytes);

int
OpenSslEnc(uint8_t k_len, uint8_t *key, uint8_t *in, uint8_t *iv, uint8_t *out, uint64_t len_bytes)
{
if (CBC_128_BITS == k_len) {
if (ISAL_CBC_128_BITS == k_len) {
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" OpenSSL128 ");
#endif
openssl_aes_128_cbc_enc(key, (uint8_t *) iv, len_bytes, in, out);
} else if (CBC_192_BITS == k_len) {
} else if (ISAL_CBC_192_BITS == k_len) {
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" OpenSSL192 ");
#endif
openssl_aes_192_cbc_enc(key, (uint8_t *) iv, len_bytes, in, out);
} else if (CBC_256_BITS == k_len) {
} else if (ISAL_CBC_256_BITS == k_len) {
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" OpenSSL256 ");
fflush(0);
Expand All @@ -90,17 +91,17 @@ OpenSslEnc(uint8_t k_len, uint8_t *key, uint8_t *in, uint8_t *iv, uint8_t *out,
int
OpenSslDec(uint8_t k_len, uint8_t *key, uint8_t *in, uint8_t *iv, uint8_t *out, uint64_t len_bytes)
{
if (CBC_128_BITS == k_len) {
if (ISAL_CBC_128_BITS == k_len) {
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" OpenSSL128 ");
#endif
openssl_aes_128_cbc_dec(key, (uint8_t *) iv, len_bytes, in, out);
} else if (CBC_192_BITS == k_len) {
} else if (ISAL_CBC_192_BITS == k_len) {
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" OpenSSL192 ");
#endif
openssl_aes_192_cbc_dec(key, (uint8_t *) iv, len_bytes, in, out);
} else if (CBC_256_BITS == k_len) {
} else if (ISAL_CBC_256_BITS == k_len) {
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" OpenSSL256 ");
#endif
Expand Down Expand Up @@ -165,21 +166,21 @@ check_vector(struct cbc_vector *vector)
printf(".");
#endif

if (CBC_128_BITS == vector->K_LEN) {
if (ISAL_CBC_128_BITS == vector->K_LEN) {
enc = (aes_cbc_generic) &isal_aes_cbc_enc_128;
dec = (aes_cbc_generic) &isal_aes_cbc_dec_128;
isal_aes_keyexp_128(vector->K, vector->KEYS->enc_keys, vector->KEYS->dec_keys);
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" CBC128 ");
#endif
} else if (CBC_192_BITS == vector->K_LEN) {
} else if (ISAL_CBC_192_BITS == vector->K_LEN) {
enc = (aes_cbc_generic) &isal_aes_cbc_enc_192;
dec = (aes_cbc_generic) &isal_aes_cbc_dec_192;
isal_aes_keyexp_192(vector->K, vector->KEYS->enc_keys, vector->KEYS->dec_keys);
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" CBC192 ");
#endif
} else if (CBC_256_BITS == vector->K_LEN) {
} else if (ISAL_CBC_256_BITS == vector->K_LEN) {
enc = (aes_cbc_generic) &isal_aes_cbc_enc_256;
dec = (aes_cbc_generic) &isal_aes_cbc_dec_256;
isal_aes_keyexp_256(vector->K, vector->KEYS->enc_keys, vector->KEYS->dec_keys);
Expand Down Expand Up @@ -259,7 +260,7 @@ test_std_combinations(void)
#ifdef CBC_VECTORS_VERBOSE
printf("\n");
#endif
ret = posix_memalign((void **) &iv, 16, (CBC_IV_DATA_LEN));
ret = posix_memalign((void **) &iv, 16, (ISAL_CBC_IV_DATA_LEN));
if ((0 != ret) || (NULL == iv))
return 1;

Expand All @@ -273,7 +274,7 @@ test_std_combinations(void)
}
// IV data must be aligned to 16 byte boundary so move data in aligned buffer and
// change out the pointer
memcpy(iv, vect.IV, CBC_IV_DATA_LEN);
memcpy(iv, vect.IV, ISAL_CBC_IV_DATA_LEN);
vect.IV = iv;
vect.C = NULL;
vect.C = malloc(vect.P_LEN);
Expand Down Expand Up @@ -317,7 +318,7 @@ test_random_combinations(void)
fflush(0);
#endif
test.IV = NULL;
ret = posix_memalign((void **) &test.IV, 16, (CBC_IV_DATA_LEN));
ret = posix_memalign((void **) &test.IV, 16, (ISAL_CBC_IV_DATA_LEN));
if ((0 != ret) || (NULL == test.IV))
return 1;
test.KEYS = NULL;
Expand Down Expand Up @@ -362,7 +363,7 @@ test_random_combinations(void)

mk_rand_data(test.P, test.P_LEN);
mk_rand_data(test.K, test.K_LEN);
mk_rand_data(test.IV, CBC_IV_DATA_LEN);
mk_rand_data(test.IV, ISAL_CBC_IV_DATA_LEN);

#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" Offset:0x%x ", offset);
Expand Down Expand Up @@ -428,18 +429,19 @@ test_efence_combinations(void)
test.P = P + PAGE_LEN - test.P_LEN - offset;
test.C = C + PAGE_LEN - test.P_LEN - offset;
test.K = K + PAGE_LEN - test.K_LEN - offset;
test.IV = IV + PAGE_LEN - CBC_IV_DATA_LEN - offset;
test.IV = IV + PAGE_LEN - ISAL_CBC_IV_DATA_LEN - offset;
test.IV =
test.IV - ((uint64_t) test.IV & 0xff); // align to 16 byte boundary
test.KEYS = (struct cbc_key_data *) (key_data + PAGE_LEN -
sizeof(*test.KEYS) - offset);
test.KEYS = (struct cbc_key_data *) ((uint8_t *) test.KEYS -
((uint64_t) test.KEYS &
0xff)); // align to 16 byte boundary
test.KEYS = (struct isal_cbc_key_data *) (key_data + PAGE_LEN -
sizeof(*test.KEYS) - offset);
test.KEYS =
(struct isal_cbc_key_data *) ((uint8_t *) test.KEYS -
((uint64_t) test.KEYS &
0xff)); // align to 16 byte boundary

mk_rand_data(test.P, test.P_LEN);
mk_rand_data(test.K, test.K_LEN);
mk_rand_data(test.IV, CBC_IV_DATA_LEN);
mk_rand_data(test.IV, ISAL_CBC_IV_DATA_LEN);
#ifdef CBC_VECTORS_EXTRA_VERBOSE
printf(" Offset:0x%x ", offset);
#endif
Expand Down
10 changes: 5 additions & 5 deletions aes/cbc_std_vectors_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ check_vector(struct cbc_vector *vector)
printf(".");

switch (vector->K_LEN) {
case CBC_128_BITS:
case ISAL_CBC_128_BITS:
enc = (aes_cbc_generic) &isal_aes_cbc_enc_128;
dec = (aes_cbc_generic) &isal_aes_cbc_dec_128;
isal_aes_keyexp_128(vector->K, vector->KEYS->enc_keys, vector->KEYS->dec_keys);
DEBUG_PRINT((" CBC128 "));
break;
case CBC_192_BITS:
case ISAL_CBC_192_BITS:
enc = (aes_cbc_generic) &isal_aes_cbc_enc_192;
dec = (aes_cbc_generic) &isal_aes_cbc_dec_192;
isal_aes_keyexp_192(vector->K, vector->KEYS->enc_keys, vector->KEYS->dec_keys);
DEBUG_PRINT((" CBC192 "));
break;
case CBC_256_BITS:
case ISAL_CBC_256_BITS:
enc = (aes_cbc_generic) &isal_aes_cbc_enc_256;
dec = (aes_cbc_generic) &isal_aes_cbc_dec_256;
isal_aes_keyexp_256(vector->K, vector->KEYS->enc_keys, vector->KEYS->dec_keys);
Expand Down Expand Up @@ -162,7 +162,7 @@ test_std_combinations(void)

printf("AES CBC standard test vectors: ");

ret = posix_memalign((void **) &iv, 16, (CBC_IV_DATA_LEN));
ret = posix_memalign((void **) &iv, 16, (ISAL_CBC_IV_DATA_LEN));
if ((0 != ret) || (NULL == iv))
return 1;

Expand All @@ -176,7 +176,7 @@ test_std_combinations(void)
}
// IV data must be aligned to 16 byte boundary so move data in
// aligned buffer and change out the pointer
memcpy(iv, vect.IV, CBC_IV_DATA_LEN);
memcpy(iv, vect.IV, ISAL_CBC_IV_DATA_LEN);
vect.IV = iv;
vect.C = malloc(vect.P_LEN);
if (NULL == vect.C) {
Expand Down
8 changes: 4 additions & 4 deletions examples/saturation_test/aes_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ mk_rand_data(uint8_t *data, uint32_t size)
struct cbc_context {
struct aes_context base;
uint8_t *iv;
uint8_t key[CBC_256_BITS];
struct cbc_key_data *key_data;
uint8_t key[ISAL_CBC_256_BITS];
struct isal_cbc_key_data *key_data;
};

static int
Expand All @@ -130,14 +130,14 @@ cbc_dec_pre(struct aes_context *p)
struct cbc_context *pCtx = (struct cbc_context *) p;
int ret;

ret = posix_memalign((void **) &pCtx->iv, 16, (CBC_IV_DATA_LEN));
ret = posix_memalign((void **) &pCtx->iv, 16, (ISAL_CBC_IV_DATA_LEN));
ret |= posix_memalign((void **) &pCtx->key_data, 16, (sizeof(*pCtx->key_data)));

if ((0 != ret) || (NULL == pCtx->iv) || (NULL == pCtx->key_data))
return 1;

mk_rand_data(pCtx->key, sizeof(pCtx->key));
memcpy(pCtx->iv, ic, CBC_IV_DATA_LEN);
memcpy(pCtx->iv, ic, ISAL_CBC_IV_DATA_LEN);
switch (pCtx->base.bits) {
case 128:
isal_aes_keyexp_128(pCtx->key, pCtx->key_data->enc_keys, pCtx->key_data->dec_keys);
Expand Down
Loading

0 comments on commit e4a8493

Please sign in to comment.