aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/aesxx/include
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-07-24 12:03:01 +0200
committerEgor Tensin <egor@tensin.name>2026-07-24 12:08:42 +0200
commitbf65cb89410cdb2d831094980631ecf4ef8f2928 (patch)
tree7ffbd446e74eb82c7d67e41d71f2a919ff689f9a /aesxx/include
parentaes: add a few notes to ASM files (diff)
downloadaes-tools-bf65cb89410cdb2d831094980631ecf4ef8f2928.tar.gz
aes-tools-bf65cb89410cdb2d831094980631ecf4ef8f2928.zip
aesxx/utils: fix the --verbose option
Diffstat (limited to 'aesxx/include')
-rw-r--r--aesxx/include/aesxx/box.hpp62
1 files changed, 44 insertions, 18 deletions
diff --git a/aesxx/include/aesxx/box.hpp b/aesxx/include/aesxx/box.hpp
index 1a4eec1..2a9659a 100644
--- a/aesxx/include/aesxx/box.hpp
+++ b/aesxx/include/aesxx/box.hpp
@@ -24,22 +24,20 @@ class Box {
public:
using Key = AES_Key;
- /*
- static std::string format_key(const Key& src, Algorithm algorithm) {
- AES_KeyString str;
- aes_format_key(&str, algorithm, &src, ErrorDetailsThrowsInDestructor{});
- return reinterpret_cast<const char*>(&str);
- }
- */
-
static void parse_key(Key& dest, Algorithm algorithm, std::string_view src) {
aes_parse_key(algorithm, &dest, src.data(), ErrorDetailsThrowsInDestructor{});
}
- Box(Algorithm algorithm, const Key& key, Mode mode, const std::optional<Block>& iv) {
+ Box(Algorithm algorithm,
+ const Key& key,
+ Mode mode,
+ const std::optional<Block>& iv,
+ bool verbose = false)
+ : verbose{verbose} {
aes_box_init(
&impl, algorithm, &key, mode, iv ? iv->ptr() : NULL, ErrorDetailsThrowsInDestructor{}
);
+ dump_key(key);
}
Algorithm get_algorithm() const {
@@ -51,19 +49,21 @@ public:
}
void encrypt_block(const Block& plaintext, Block& ciphertext) {
- dump_block("Plaintext", plaintext);
+ dump_iv();
+ dump_plaintext(plaintext);
aes_box_encrypt_block(
&impl, plaintext.ptr(), ciphertext.ptr(), ErrorDetailsThrowsInDestructor{}
);
- dump_block("Ciphertext", ciphertext);
+ dump_ciphertext(ciphertext);
}
void decrypt_block(const Block& ciphertext, Block& plaintext) {
- dump_block("Ciphertext", ciphertext);
+ dump_iv();
+ dump_ciphertext(ciphertext);
aes_box_decrypt_block(
&impl, ciphertext.ptr(), plaintext.ptr(), ErrorDetailsThrowsInDestructor{}
);
- dump_block("Plaintext", plaintext);
+ dump_plaintext(plaintext);
}
std::vector<unsigned char> encrypt_buffer(const void* src_buf, std::size_t src_size) {
@@ -113,15 +113,41 @@ public:
}
private:
- void dump_block(std::string_view header, const Block& block) {
- if (verbose > 0)
+ static std::string format_key(const Key& src, Algorithm algorithm) {
+ AES_KeyString str;
+ aes_format_key(algorithm, &str, &src, ErrorDetailsThrowsInDestructor{});
+ return reinterpret_cast<const char*>(&str);
+ }
+
+ void dump_key(const Key& src) const {
+ if (verbose)
+ std::cout << std::format("Key : {}\n", format_key(src, get_algorithm()));
+ }
+
+ Block get_iv() const {
+ return Block{impl.iv};
+ }
+
+ void dump_iv() const {
+ if (verbose)
+ std::cout << std::format("Init vector : {}\n", get_iv().to_string());
+ }
+
+ void dump_block(std::string_view header, const Block& block) const {
+ if (verbose)
std::cout << std::format("{}: {}\n", header, block.to_string());
- if (verbose > 1)
- std::cout << std::format("{}\n", block.to_matrix_string());
+ }
+
+ void dump_plaintext(const Block& src) const {
+ dump_block("Plaintext ", src);
+ }
+
+ void dump_ciphertext(const Block& src) const {
+ dump_block("Ciphertext ", src);
}
AES_Box impl;
- int verbose = 0;
+ bool verbose = false;
};
} // namespace aes