aboutsummaryrefslogtreecommitdiff
path: root/tests/test_axolotl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_axolotl.cpp')
-rw-r--r--tests/test_axolotl.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test_axolotl.cpp b/tests/test_axolotl.cpp
new file mode 100644
index 0000000..1c605ea
--- /dev/null
+++ b/tests/test_axolotl.cpp
@@ -0,0 +1,63 @@
+#include "axolotl/axolotl.hh"
+#include "unittest.hh"
+
+
+int main() {
+
+{ /* Loopback test case */
+TestCase test_case("Axolotl Loopback 1");
+
+std::uint8_t root_info[] = "Axolotl";
+std::uint8_t ratchet_info[] = "AxolotlRatchet";
+std::uint8_t message_info[] = "AxolotlMessageKeys";
+
+axolotl::KdfInfo kdf_info = {
+ root_info, sizeof(root_info) - 1,
+ ratchet_info, sizeof(ratchet_info - 1),
+ message_info, sizeof(ratchet_info - 1)
+};
+
+axolotl::Session alice(kdf_info);
+axolotl::Session bob(kdf_info);
+
+std::uint8_t random_bytes[] = "0123456789ABDEF0123456789ABCDEF";
+axolotl::Curve25519KeyPair bob_key;
+axolotl::generate_key(random_bytes, bob_key);
+
+std::uint8_t shared_secret[] = "A secret";
+
+alice.initialise_as_bob(shared_secret, sizeof(shared_secret) - 1, bob_key);
+bob.initialise_as_alice(shared_secret, sizeof(shared_secret) - 1, bob_key);
+
+std::uint8_t plaintext[] = "Message";
+std::size_t plaintext_length = sizeof(plaintext) - 1;
+
+std::size_t message_length, random_length, actual_length;
+std::size_t encrypt_length, decrypt_length;
+
+message_length = bob.encrypt_max_output_length(plaintext_length);
+random_length = bob.encrypt_random_length();
+assert_equals(std::size_t(0), random_length);
+actual_length = alice.decrypt_max_plaintext_length(message_length);
+{
+ std::uint8_t message[message_length];
+ std::uint8_t actual[actual_length];
+
+ encrypt_length = bob.encrypt(
+ plaintext, plaintext_length,
+ NULL, 0,
+ message, message_length
+ );
+ assert_equals(message_length, encrypt_length);
+
+ decrypt_length = alice.decrypt(
+ message, message_length,
+ actual, actual_length
+ );
+ assert_equals(plaintext_length, decrypt_length);
+ assert_equals(plaintext, actual, decrypt_length);
+}
+
+} /* Loopback test case */
+
+}