aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/examples
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-06-17 23:25:52 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-06-17 23:25:52 +0300
commit44d58e0a10c7dfdb33899fa98c0eea790e0b90ce (patch)
tree646541b156ffdd88bbaa4f1fa860aed465dfce60 /examples
parentrefactoring (diff)
downloadaes-tools-44d58e0a10c7dfdb33899fa98c0eea790e0b90ce.tar.gz
aes-tools-44d58e0a10c7dfdb33899fa98c0eea790e0b90ce.zip
factoring out AES-specific stuff
Diffstat (limited to 'examples')
-rw-r--r--examples/aes128cbc.cpp16
-rw-r--r--examples/aes128cfb.cpp12
-rw-r--r--examples/aes128ctr.cpp10
-rw-r--r--examples/aes128ecb.cpp10
-rw-r--r--examples/aes128ofb.cpp12
-rw-r--r--examples/aes192cbc.cpp12
-rw-r--r--examples/aes192cfb.cpp10
-rw-r--r--examples/aes192ctr.cpp8
-rw-r--r--examples/aes192ecb.cpp8
-rw-r--r--examples/aes192ofb.cpp10
-rw-r--r--examples/aes256cbc.cpp12
-rw-r--r--examples/aes256cfb.cpp10
-rw-r--r--examples/aes256ctr.cpp8
-rw-r--r--examples/aes256ecb.cpp8
-rw-r--r--examples/aes256ofb.cpp10
-rw-r--r--examples/common.hpp41
16 files changed, 98 insertions, 99 deletions
diff --git a/examples/aes128cbc.cpp b/examples/aes128cbc.cpp
index 5bb8c67..b6253e6 100644
--- a/examples/aes128cbc.cpp
+++ b/examples/aes128cbc.cpp
@@ -19,29 +19,29 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block128 key;
+ aesni::aes::Key128 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule128 encryption_schedule;
- aesni_aes128_expand_key(key, &encryption_schedule);
+ aesni::aes::RoundKeys128 encryption_schedule;
+ aesni_aes128_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes128_encrypt_block_cbc(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
- aesni::KeySchedule128 decryption_schedule;
+ aesni::aes::RoundKeys128 decryption_schedule;
aesni_aes128_derive_decryption_keys(&encryption_schedule, &decryption_schedule);
dump_decryption_schedule(decryption_schedule);
- aesni::Block128 decrypted = aesni_aes128_decrypt_block_cbc(ciphertext, &decryption_schedule, iv, &next_iv);
+ aesni::aes::Block decrypted = aesni_aes128_decrypt_block_cbc(ciphertext, &decryption_schedule, iv, &next_iv);
dump_decrypted(decrypted);
dump_next_iv(next_iv);
diff --git a/examples/aes128cfb.cpp b/examples/aes128cfb.cpp
index b5f78a7..472b0c3 100644
--- a/examples/aes128cfb.cpp
+++ b/examples/aes128cfb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block128 key;
+ aesni::aes::Key128 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule128 encryption_schedule;
- aesni_aes128_expand_key(key, &encryption_schedule);
+ aesni::aes::RoundKeys128 encryption_schedule;
+ aesni_aes128_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes128_encrypt_block_cfb(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
diff --git a/examples/aes128ctr.cpp b/examples/aes128ctr.cpp
index 0515336..3f64173 100644
--- a/examples/aes128ctr.cpp
+++ b/examples/aes128ctr.cpp
@@ -19,17 +19,17 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block128 key;
+ aesni::aes::Key128 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule128 encryption_schedule;
- aesni_aes128_expand_key(key, &encryption_schedule);
+ aesni::aes::RoundKeys128 encryption_schedule;
+ aesni_aes128_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
const auto ciphertext = aesni_aes128_encrypt_block_ctr(plaintext, &encryption_schedule, iv, 0);
diff --git a/examples/aes128ecb.cpp b/examples/aes128ecb.cpp
index b33c00a..cf0d033 100644
--- a/examples/aes128ecb.cpp
+++ b/examples/aes128ecb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block128 key;
+ aesni::aes::Key128 key;
make_default_key(key);
- aesni::KeySchedule128 encryption_schedule;
- aesni_aes128_expand_key(key, &encryption_schedule);
+ aesni::aes::RoundKeys128 encryption_schedule;
+ aesni_aes128_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
const auto ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, &encryption_schedule);
dump_ciphertext(ciphertext);
- aesni::KeySchedule128 decryption_schedule;
+ aesni::aes::RoundKeys128 decryption_schedule;
aesni_aes128_derive_decryption_keys(&encryption_schedule, &decryption_schedule);
dump_decryption_schedule(decryption_schedule);
diff --git a/examples/aes128ofb.cpp b/examples/aes128ofb.cpp
index da3d750..d6a5c87 100644
--- a/examples/aes128ofb.cpp
+++ b/examples/aes128ofb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block128 key;
+ aesni::aes::Key128 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule128 encryption_schedule;
- aesni_aes128_expand_key(key, &encryption_schedule);
+ aesni::aes::RoundKeys128 encryption_schedule;
+ aesni_aes128_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes128_encrypt_block_ofb(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
diff --git a/examples/aes192cbc.cpp b/examples/aes192cbc.cpp
index 6d7ff74..2c18d34 100644
--- a/examples/aes192cbc.cpp
+++ b/examples/aes192cbc.cpp
@@ -19,25 +19,25 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block192 key;
+ aesni::aes::Key192 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule192 encryption_schedule;
+ aesni::aes::RoundKeys192 encryption_schedule;
aesni_aes192_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes192_encrypt_block_cbc(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
- aesni::KeySchedule192 decryption_schedule;
+ aesni::aes::RoundKeys192 decryption_schedule;
aesni_aes192_derive_decryption_keys(&encryption_schedule, &decryption_schedule);
dump_decryption_schedule(decryption_schedule);
diff --git a/examples/aes192cfb.cpp b/examples/aes192cfb.cpp
index a8662ca..4deaf1c 100644
--- a/examples/aes192cfb.cpp
+++ b/examples/aes192cfb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block192 key;
+ aesni::aes::Key192 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule192 encryption_schedule;
+ aesni::aes::RoundKeys192 encryption_schedule;
aesni_aes192_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes192_encrypt_block_cfb(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
diff --git a/examples/aes192ctr.cpp b/examples/aes192ctr.cpp
index ef4dde6..022bc33 100644
--- a/examples/aes192ctr.cpp
+++ b/examples/aes192ctr.cpp
@@ -19,16 +19,16 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block192 key;
+ aesni::aes::Key192 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule192 encryption_schedule;
+ aesni::aes::RoundKeys192 encryption_schedule;
aesni_aes192_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
diff --git a/examples/aes192ecb.cpp b/examples/aes192ecb.cpp
index 6faf96f..6de3e16 100644
--- a/examples/aes192ecb.cpp
+++ b/examples/aes192ecb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block192 key;
+ aesni::aes::Key192 key;
make_default_key(key);
- aesni::KeySchedule192 encryption_schedule;
+ aesni::aes::RoundKeys192 encryption_schedule;
aesni_aes192_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
const auto ciphertext = aesni_aes192_encrypt_block_ecb(plaintext, &encryption_schedule);
dump_ciphertext(ciphertext);
- aesni::KeySchedule192 decryption_schedule;
+ aesni::aes::RoundKeys192 decryption_schedule;
aesni_aes192_derive_decryption_keys(&encryption_schedule, &decryption_schedule);
dump_decryption_schedule(decryption_schedule);
diff --git a/examples/aes192ofb.cpp b/examples/aes192ofb.cpp
index e7de746..df907cd 100644
--- a/examples/aes192ofb.cpp
+++ b/examples/aes192ofb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block192 key;
+ aesni::aes::Key192 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule192 encryption_schedule;
+ aesni::aes::RoundKeys192 encryption_schedule;
aesni_aes192_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes192_encrypt_block_ofb(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
diff --git a/examples/aes256cbc.cpp b/examples/aes256cbc.cpp
index 66f7c38..9123c9b 100644
--- a/examples/aes256cbc.cpp
+++ b/examples/aes256cbc.cpp
@@ -19,25 +19,25 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block256 key;
+ aesni::aes::Key256 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule256 encryption_schedule;
+ aesni::aes::RoundKeys256 encryption_schedule;
aesni_aes256_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes256_encrypt_block_cbc(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
- aesni::KeySchedule256 decryption_schedule;
+ aesni::aes::RoundKeys256 decryption_schedule;
aesni_aes256_derive_decryption_keys(&encryption_schedule, &decryption_schedule);
dump_decryption_schedule(decryption_schedule);
diff --git a/examples/aes256cfb.cpp b/examples/aes256cfb.cpp
index 8a23146..a6e8ba7 100644
--- a/examples/aes256cfb.cpp
+++ b/examples/aes256cfb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block256 key;
+ aesni::aes::Key256 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule256 encryption_schedule;
+ aesni::aes::RoundKeys256 encryption_schedule;
aesni_aes256_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes256_encrypt_block_cfb(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
diff --git a/examples/aes256ctr.cpp b/examples/aes256ctr.cpp
index b5e2ae7..3360c76 100644
--- a/examples/aes256ctr.cpp
+++ b/examples/aes256ctr.cpp
@@ -19,16 +19,16 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block256 key;
+ aesni::aes::Key256 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule256 encryption_schedule;
+ aesni::aes::RoundKeys256 encryption_schedule;
aesni_aes256_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
diff --git a/examples/aes256ecb.cpp b/examples/aes256ecb.cpp
index aebd14b..d11aaa6 100644
--- a/examples/aes256ecb.cpp
+++ b/examples/aes256ecb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block256 key;
+ aesni::aes::Key256 key;
make_default_key(key);
- aesni::KeySchedule256 encryption_schedule;
+ aesni::aes::RoundKeys256 encryption_schedule;
aesni_aes256_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
const auto ciphertext = aesni_aes256_encrypt_block_ecb(plaintext, &encryption_schedule);
dump_ciphertext(ciphertext);
- aesni::KeySchedule256 decryption_schedule;
+ aesni::aes::RoundKeys256 decryption_schedule;
aesni_aes256_derive_decryption_keys(&encryption_schedule, &decryption_schedule);
dump_decryption_schedule(decryption_schedule);
diff --git a/examples/aes256ofb.cpp b/examples/aes256ofb.cpp
index cf1f1a0..b4f9a1f 100644
--- a/examples/aes256ofb.cpp
+++ b/examples/aes256ofb.cpp
@@ -19,20 +19,20 @@ int main()
{
try
{
- aesni::Block128 plaintext;
+ aesni::aes::Block plaintext;
make_default_plaintext(plaintext);
- aesni::Block256 key;
+ aesni::aes::Key256 key;
make_default_key(key);
- aesni::Block128 iv;
+ aesni::aes::Block iv;
make_default_iv(iv);
- aesni::KeySchedule256 encryption_schedule;
+ aesni::aes::RoundKeys256 encryption_schedule;
aesni_aes256_expand_key(&key, &encryption_schedule);
dump_encryption_schedule(encryption_schedule);
- aesni::Block128 next_iv;
+ aesni::aes::Block next_iv;
const auto ciphertext = aesni_aes256_encrypt_block_ofb(plaintext, &encryption_schedule, iv, &next_iv);
dump_ciphertext(ciphertext);
dump_next_iv(next_iv);
diff --git a/examples/common.hpp b/examples/common.hpp
index 0188352..d7b3394 100644
--- a/examples/common.hpp
+++ b/examples/common.hpp
@@ -16,68 +16,67 @@
namespace
{
- template <typename BlockT>
- void dump_block(const char* name, const BlockT& block)
+ void dump_block(const char* name, const aesni::aes::Block& block)
{
- std::cout << name << ": " << block << "\n" << aesni::to_matrix_string(block) << "\n";
+ std::cout << name << ": " << aesni::aes::to_string(block) << "\n" << aesni::aes::to_matrix_string(block) << "\n";
}
- void dump_plaintext(const aesni::Block128& block)
+ void dump_plaintext(const aesni::aes::Block& block)
{
dump_block("Plaintext", block);
}
- template <typename BlockT>
- void dump_key(const BlockT& key)
+ template <typename KeyT>
+ void dump_key(const KeyT& key)
{
- dump_block("Key", key);
+ std::cout << "Key: " << aesni::aes::to_string(key) << "\n";
}
- void dump_ciphertext(const aesni::Block128& ciphertext)
+ void dump_ciphertext(const aesni::aes::Block& ciphertext)
{
dump_block("Ciphertext", ciphertext);
}
- void dump_iv(const aesni::Block128& iv)
+ void dump_iv(const aesni::aes::Block& iv)
{
dump_block("Initialization vector", iv);
}
- void dump_next_iv(const aesni::Block128& next_iv)
+ void dump_next_iv(const aesni::aes::Block& next_iv)
{
dump_block("Next initialization vector", next_iv);
}
- void dump_decrypted(const aesni::Block128& decrypted)
+ void dump_decrypted(const aesni::aes::Block& decrypted)
{
dump_block("Decrypted", decrypted);
}
- void make_default_plaintext(aesni::Block128& plaintext)
+ void make_default_plaintext(aesni::aes::Block& plaintext)
{
aesni::make_block(plaintext, 0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
dump_plaintext(plaintext);
}
- void make_default_key(aesni::Block128& key)
+ void make_default_key(aesni::aes::Key128& key)
{
- aesni::make_block(key, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
+ aesni::aes::make_key(key, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
dump_key(key);
}
- void make_default_key(aesni::Block192& key)
+ void make_default_key(aesni::aes::Key192& key)
{
- aesni::make_block(key, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
+ aesni::aes::make_key(key, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
dump_key(key);
}
- void make_default_key(aesni::Block256& key)
+ void make_default_key(aesni::aes::Key256& key)
{
- aesni::make_block(key, 0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
+ aesni::aes::make_key(key, 0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
dump_key(key);
}
- void make_default_iv(aesni::Block128& iv)
+ void make_default_iv(aesni::aes::Block& iv)
{
aesni::make_block(iv, 0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
dump_iv(iv);
@@ -87,8 +86,8 @@ namespace
void dump_schedule(const char* name, const KeyScheduleT& schedule)
{
std::cout << name << ":\n";
- for (std::size_t i = 0; i < aesni::get_number_of_keys(schedule); ++i)
- std::cout << "\t[" << i << "]: " << schedule.keys[i] << "\n";
+ for (std::size_t i = 0; i < aesni::aes::get_number_of_keys(schedule); ++i)
+ std::cout << "\t[" << i << "]: " << aesni::aes::to_string(schedule.keys[i]) << "\n";
std::cout << "\n";
}