Skip to content

Commit

Permalink
Add lots of repetitions to small host operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jpzg committed Aug 20, 2020
1 parent d217625 commit a0b0a4b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 41 deletions.
64 changes: 34 additions & 30 deletions host/aesni_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,51 @@ int aesni_AES_ecb(void *in, void *out, unsigned long length,
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC_RAW, &start);

// OpenSSL only accepts an integer length, so we reject lengths any longer
// than that
if (length > INT_MAX) {
return EINVAL;
}
int nr_repetitions = (GIGABYTE(1) + length - 1) / length;

if (operation == OP_ENCRYPT) {
operation = 1;
} else if (operation == OP_DECRYPT) {
operation = 0;
} else {
return EINVAL;
}
for (int i = 0; i < nr_repetitions; i++) {
// OpenSSL only accepts an integer length, so we reject lengths any longer
// than that
if (length > INT_MAX) {
return EINVAL;
}

EVP_CIPHER_CTX *ctx;
if (operation == OP_ENCRYPT) {
operation = 1;
} else if (operation == OP_DECRYPT) {
operation = 0;
} else {
return EINVAL;
}

if (!(ctx = EVP_CIPHER_CTX_new())) {
handleErrors();
}
EVP_CIPHER_CTX *ctx;

if (1 != EVP_CipherInit_ex(ctx, EVP_aes_128_ecb(), NULL, key_ptr, NULL,
operation)) {
handleErrors();
}
if (!(ctx = EVP_CIPHER_CTX_new())) {
handleErrors();
}

int outl;
if (1 != EVP_CipherInit_ex(ctx, EVP_aes_128_ecb(), NULL, key_ptr, NULL,
operation)) {
handleErrors();
}

if (1 != EVP_CipherUpdate(ctx, out, &outl, in, length)) {
handleErrors();
}
int outl;

if (1 != EVP_CipherUpdate(ctx, out, &outl, in, length)) {
handleErrors();
}

if (length != (unsigned int)outl) {
ERROR("Error: OpenSSL did not encrypt all data\n");
EVP_CIPHER_CTX_free(ctx);
return -1;
}

if (length != (unsigned int)outl) {
ERROR("Error: OpenSSL did not encrypt all data\n");
EVP_CIPHER_CTX_free(ctx);
return -1;
}

EVP_CIPHER_CTX_free(ctx);

clock_gettime(CLOCK_MONOTONIC_RAW, &end);
double execution_time = TIME_DIFFERENCE(start, end);
double execution_time = TIME_DIFFERENCE(start, end) / nr_repetitions;

// TODO: add a cycle count
// Operation, Data size, Execution time
Expand Down
28 changes: 17 additions & 11 deletions host/host_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@ int host_AES_ecb(void *in, void *out, unsigned long length, const void *key_ptr,

clock_gettime(CLOCK_MONOTONIC_RAW, &start);

switch (operation) {
case OP_ENCRYPT:
host_AES_ecb_encrypt(in, out, length, key_ptr);
break;
case OP_DECRYPT:
host_AES_ecb_decrypt(in, out, length, key_ptr);
break;
default:
return 1;
}
int nr_repetitions = (MEGABYTE(256) + length - 1) /
length; // This aims to have each execution take at least
// 1s, with more repetitions for smaller numbers
// that tend to have less precision

for (int i = 0; i < nr_repetitions; i++) {
switch (operation) {
case OP_ENCRYPT:
host_AES_ecb_encrypt(in, out, length, key_ptr);
break;
case OP_DECRYPT:
host_AES_ecb_decrypt(in, out, length, key_ptr);
break;
default:
return 1;
}
}
clock_gettime(CLOCK_MONOTONIC_RAW, &end);

double execution_time = TIME_DIFFERENCE(start, end);
double execution_time = TIME_DIFFERENCE(start, end) / nr_repetitions;

// TODO: add a cycle count
// Operation, Data size, Execution time
Expand Down

0 comments on commit a0b0a4b

Please sign in to comment.