Skip to content

Commit

Permalink
aes: remove unused AES-CTR mode implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinas committed Jul 11, 2023
1 parent 4a18336 commit 69f0ad9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 58 deletions.
33 changes: 0 additions & 33 deletions aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,39 +294,6 @@ int rijndael256_encrypt_block(const aes_round_keys_t* key, const uint8_t* plaint
return ret;
}

void aes128_ctr_encrypt(const aes_round_keys_t* key, const uint8_t* iv, const uint8_t* plaintext,
uint8_t* ciphertext) {
aes_block_t state;
load_state(state, iv, AES_BLOCK_WORDS);
aes_encrypt(key, state, AES_BLOCK_WORDS, ROUNDS_128);

for (unsigned int i = 0; i < 16; ++i) {
ciphertext[i] = plaintext[i] ^ state[i / 4][i % 4];
}
}

void aes192_ctr_encrypt(const aes_round_keys_t* key, const uint8_t* iv, const uint8_t* plaintext,
uint8_t* ciphertext) {
aes_block_t state;
load_state(state, iv, AES_BLOCK_WORDS);
aes_encrypt(key, state, AES_BLOCK_WORDS, ROUNDS_192);

for (unsigned int i = 0; i < 16; ++i) {
ciphertext[i] = plaintext[i] ^ state[i / 4][i % 4];
}
}

void aes256_ctr_encrypt(const aes_round_keys_t* key, const uint8_t* iv, const uint8_t* plaintext,
uint8_t* ciphertext) {
aes_block_t state;
load_state(state, iv, AES_BLOCK_WORDS);
aes_encrypt(key, state, AES_BLOCK_WORDS, ROUNDS_256);

for (unsigned int i = 0; i < 16; ++i) {
ciphertext[i] = plaintext[i] ^ state[i / 4][i % 4];
}
}

void prg(const uint8_t* key, const uint8_t* iv, uint8_t* out, unsigned int seclvl, size_t outlen) {
#if !defined(HAVE_OPENSSL)
uint8_t internal_iv[16];
Expand Down
7 changes: 0 additions & 7 deletions aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ int rijndael192_encrypt_block(const aes_round_keys_t* key, const uint8_t* plaint
int rijndael256_encrypt_block(const aes_round_keys_t* key, const uint8_t* plaintext,
uint8_t* ciphertext);

void aes128_ctr_encrypt(const aes_round_keys_t* key, const uint8_t* iv, const uint8_t* plaintext,
uint8_t* ciphertext);
void aes192_ctr_encrypt(const aes_round_keys_t* key, const uint8_t* iv, const uint8_t* plaintext,
uint8_t* ciphertext);
void aes256_ctr_encrypt(const aes_round_keys_t* key, const uint8_t* iv, const uint8_t* plaintext,
uint8_t* ciphertext);

void aes_increment_iv(uint8_t* iv);

uint8_t* aes_extend_witness(const uint8_t* key, const uint8_t* in, const faest_paramset_t* params);
Expand Down
24 changes: 6 additions & 18 deletions tests/aes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,20 @@ BOOST_AUTO_TEST_CASE(test_aes128) {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
};
constexpr uint8_t iv_128[16] = {
constexpr uint8_t plaintext_128[16] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
};
constexpr block_t expected_128 = {
0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30,
0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a,
};
constexpr uint8_t plaintext_128[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

aes_round_keys_t ctx;
aes128_init_round_keys(&ctx, key_128);

block_t output_128;
aes128_ctr_encrypt(&ctx, iv_128, plaintext_128, output_128.data());
aes128_encrypt_block(&ctx, plaintext_128, output_128.data());

BOOST_TEST(output_128 == expected_128);
}
Expand All @@ -290,24 +286,20 @@ BOOST_AUTO_TEST_CASE(test_aes192) {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
};
constexpr uint8_t iv_192[16] = {
constexpr uint8_t plaintext_192[16] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
};
constexpr block_t expected_192 = {
0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0,
0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91,
};
constexpr uint8_t plaintext_192[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

aes_round_keys_t ctx;
aes192_init_round_keys(&ctx, key_192);

block_t output_192;
aes192_ctr_encrypt(&ctx, iv_192, plaintext_192, output_192.data());
aes192_encrypt_block(&ctx, plaintext_192, output_192.data());

BOOST_TEST(output_192 == expected_192);
}
Expand All @@ -318,24 +310,20 @@ BOOST_AUTO_TEST_CASE(test_aes256) {
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
};
constexpr uint8_t iv_256[16] = {
constexpr uint8_t plaintext_256[16] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
};
constexpr block_t expected_256 = {
0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf,
0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89,
};
constexpr uint8_t plaintext_256[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

aes_round_keys_t ctx;
aes256_init_round_keys(&ctx, key_256);

block_t output_256;
aes256_ctr_encrypt(&ctx, iv_256, plaintext_256, output_256.data());
aes256_encrypt_block(&ctx, plaintext_256, output_256.data());

BOOST_TEST(output_256 == expected_256);
}
Expand Down

0 comments on commit 69f0ad9

Please sign in to comment.