Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double aesrand_getword() performance by using full 128 bits #801

Merged
merged 1 commit into from Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/aesrand.c
Expand Up @@ -8,6 +8,7 @@

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>

Expand All @@ -28,6 +29,7 @@ struct aesrand {
uint32_t input[AES_BLOCK_WORDS];
uint32_t sched[(AES_ROUNDS + 1) * 4];
uint8_t output[OUTPUT_BYTES];
bool remaining;
};

static aesrand_t *_aesrand_init(uint8_t *key)
Expand All @@ -38,6 +40,7 @@ static aesrand_t *_aesrand_init(uint8_t *key)
log_fatal("aesrand", "could not initialize AES key");
}
memset(aes->output, 0, OUTPUT_BYTES);
aes->remaining = false;
return aes;
}

Expand All @@ -62,10 +65,18 @@ aesrand_t *aesrand_init_from_random(void)

uint64_t aesrand_getword(aesrand_t *aes)
{
uint64_t retval;

if (aes->remaining) {
memcpy(&retval, &aes->output[sizeof(retval)], sizeof(retval));
aes->remaining = false;
return retval;
}

memcpy(aes->input, aes->output, sizeof(aes->input));
rijndaelEncrypt(aes->sched, AES_ROUNDS, (uint8_t *)aes->input,
aes->output);
uint64_t retval;
memcpy(&retval, aes->output, sizeof(retval));
aes->remaining = true;
return retval;
}