Skip to content

Commit

Permalink
added noexcept specifier for some aes methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdcvlsc committed Aug 31, 2023
1 parent a0bf642 commit d656c7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions AES.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ namespace Cipher {
{11, 13, 9, 14},
};

void sub_bytes(unsigned char state[AES_BLOCK]) {
void sub_bytes(unsigned char state[AES_BLOCK]) noexcept {
for (size_t i = 0; i < AES_BLOCK; i += 4) {
state[i] = sbox[state[i]];
state[i + 1] = sbox[state[i + 1]];
Expand All @@ -419,7 +419,7 @@ namespace Cipher {
}
}

void inverse_sub_bytes(unsigned char state[AES_BLOCK]) {
void inverse_sub_bytes(unsigned char state[AES_BLOCK]) noexcept {
for (size_t i = 0; i < AES_BLOCK; i += 4) {
state[i] = inverse_sbox[state[i]];
state[i + 1] = inverse_sbox[state[i + 1]];
Expand All @@ -428,7 +428,7 @@ namespace Cipher {
}
}

void shift_rows(unsigned char state[AES_BLOCK]) {
void shift_rows(unsigned char state[AES_BLOCK]) noexcept {
unsigned char temp = state[4];

state[4] = state[5];
Expand All @@ -450,7 +450,7 @@ namespace Cipher {
state[13] = temp;
}

void inverse_shift_rows(unsigned char state[AES_BLOCK]) {
void inverse_shift_rows(unsigned char state[AES_BLOCK]) noexcept {
unsigned char temp = state[4];

state[4] = state[7];
Expand All @@ -472,7 +472,7 @@ namespace Cipher {
state[15] = temp;
}

void mix_columns(unsigned char state[AES_BLOCK]) {
void mix_columns(unsigned char state[AES_BLOCK]) noexcept {
unsigned char gf_product[AES_BLOCK] = {};

// TODO: analyse in the future if this loop can speed up by branchless programming.
Expand All @@ -493,7 +493,7 @@ namespace Cipher {
}
}

void inverse_mix_columns(unsigned char state[AES_BLOCK]) {
void inverse_mix_columns(unsigned char state[AES_BLOCK]) noexcept {
unsigned char gf_product[AES_BLOCK] = {};

for (size_t i = 0; i < 4; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions microbench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main() {
auto enc_end = std::chrono::high_resolution_clock::now();
auto enc_dur = std::chrono::duration_cast<std::chrono::milliseconds>(enc_end - enc_start);

std::cout << "| Encryption | " << KEY_BIT_SIZE << " | " << enc_dur.count() << "ms | " << (MB / 1024) / 1024 << "\n";
std::cout << "| Encryption | " << KEY_BIT_SIZE << " | " << enc_dur.count() << "ms | " << (MB / 1024) / 1024 << "|\n";

auto dec_start = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < MB; i += 16) {
Expand All @@ -53,7 +53,7 @@ int main() {
auto dec_end = std::chrono::high_resolution_clock::now();
auto dec_dur = std::chrono::duration_cast<std::chrono::milliseconds>(dec_end - dec_start);

std::cout << "| Decryption | " << KEY_BIT_SIZE << " | " << dec_dur.count() << "ms | " << (MB / 1024) / 1024 << "\n";
std::cout << "| Decryption | " << KEY_BIT_SIZE << " | " << dec_dur.count() << "ms | " << (MB / 1024) / 1024 << "|\n";

int result = std::memcmp(data, save, MB);
// std::cout << "\n\nresult = " << result << "\n\n";
Expand Down

0 comments on commit d656c7a

Please sign in to comment.