validate gen thraed safe
#define AES_KEY_BYTES 16
static int inited = 0;
-static uint32_t aes_input[AES_BLOCK_WORDS];
static uint32_t aes_sched[(AES_ROUNDS + 1) * 4];
void validate_init()
{
- for (int i = 0; i < AES_BLOCK_WORDS; i++) {
- aes_input[i] = 0;
- }
uint8_t key[AES_KEY_BYTES];
if (!random_bytes(key, AES_KEY_BYTES)) {
log_fatal("validate", "couldn't get random bytes");
}
- if (rijndaelKeySetupEnc(aes_sched, key, AES_KEY_BYTES * 8) !=
- AES_ROUNDS) {
+ if (rijndaelKeySetupEnc(aes_sched, key, AES_KEY_BYTES * 8) != AES_ROUNDS) {
log_fatal("validate", "couldn't initialize AES key");
}
inited = 1;
@@ -41,7 +36,11 @@ void validate_gen(const uint32_t src, const uint32_t dst,
uint8_t output[VALIDATE_BYTES])
{
assert(inited);
+
+ uint32_t aes_input[AES_BLOCK_WORDS];
aes_input[0] = src;
aes_input[1] = dst;
+ aes_input[2] = 0;
+ aes_input[3] = 0;
rijndaelEncrypt(aes_sched, AES_ROUNDS, (uint8_t *)aes_input, output);
}
