From 4f1bb49d20ff7e9583a764b5d7d6d6cd9dc26870 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 17 May 2016 12:13:57 +0100 Subject: Rename olm.hh to olm.h --- tests/test_olm.cpp | 2 +- tests/test_olm_decrypt.cpp | 2 +- tests/test_olm_sha256.cpp | 2 +- tests/test_olm_signature.cpp | 2 +- tests/test_olm_using_malloc.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test_olm.cpp b/tests/test_olm.cpp index fbc14cf..de7e236 100644 --- a/tests/test_olm.cpp +++ b/tests/test_olm.cpp @@ -1,4 +1,4 @@ -#include "olm/olm.hh" +#include "olm/olm.h" #include "unittest.hh" #include diff --git a/tests/test_olm_decrypt.cpp b/tests/test_olm_decrypt.cpp index 4ec873c..95cb18e 100644 --- a/tests/test_olm_decrypt.cpp +++ b/tests/test_olm_decrypt.cpp @@ -1,4 +1,4 @@ -#include "olm/olm.hh" +#include "olm/olm.h" #include "unittest.hh" const char * test_cases[] = { diff --git a/tests/test_olm_sha256.cpp b/tests/test_olm_sha256.cpp index fe5bf42..c6d0242 100644 --- a/tests/test_olm_sha256.cpp +++ b/tests/test_olm_sha256.cpp @@ -1,4 +1,4 @@ -#include "olm/olm.hh" +#include "olm/olm.h" #include "unittest.hh" int main() { diff --git a/tests/test_olm_signature.cpp b/tests/test_olm_signature.cpp index a7cce63..d7259de 100644 --- a/tests/test_olm_signature.cpp +++ b/tests/test_olm_signature.cpp @@ -1,4 +1,4 @@ -#include "olm/olm.hh" +#include "olm/olm.h" #include "unittest.hh" #include diff --git a/tests/test_olm_using_malloc.cpp b/tests/test_olm_using_malloc.cpp index 84fbbd7..fff3ea2 100644 --- a/tests/test_olm_using_malloc.cpp +++ b/tests/test_olm_using_malloc.cpp @@ -1,4 +1,4 @@ -#include "olm/olm.hh" +#include "olm/olm.h" #include "unittest.hh" #include -- cgit v1.2.3 From e533b0dc8ef606aa808b38d2f49d9baf438dae47 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 13 May 2016 12:56:23 +0100 Subject: Give SHA256 functions C bindings --- tests/test_crypto.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_crypto.cpp b/tests/test_crypto.cpp index 4606c52..e86f3ab 100644 --- a/tests/test_crypto.cpp +++ b/tests/test_crypto.cpp @@ -186,7 +186,7 @@ std::uint8_t expected[32] = { std::uint8_t actual[32]; -olm::sha256(input, sizeof(input), actual); +crypto_sha256(input, sizeof(input), actual); assert_equals(expected, actual, 32); @@ -207,7 +207,7 @@ std::uint8_t expected[32] = { std::uint8_t actual[32]; -olm::hmac_sha256(input, sizeof(input), input, sizeof(input), actual); +crypto_hmac_sha256(input, sizeof(input), input, sizeof(input), actual); assert_equals(expected, actual, 32); @@ -242,7 +242,7 @@ std::uint8_t hmac_expected_output[32] = { std::uint8_t hmac_actual_output[32] = {}; -olm::hmac_sha256( +crypto_hmac_sha256( salt, sizeof(salt), input, sizeof(input), hmac_actual_output @@ -261,7 +261,7 @@ std::uint8_t hkdf_expected_output[42] = { std::uint8_t hkdf_actual_output[42] = {}; -olm::hkdf_sha256( +crypto_hkdf_sha256( input, sizeof(input), salt, sizeof(salt), info, sizeof(info), -- cgit v1.2.3 From 294cf482ea49f690ac9eaad52f2574a90b2e51e6 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 16 May 2016 16:25:09 +0100 Subject: Convert cipher.hh to plain C --- tests/test_ratchet.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_ratchet.cpp b/tests/test_ratchet.cpp index 8f89048..2c8bc1b 100644 --- a/tests/test_ratchet.cpp +++ b/tests/test_ratchet.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ #include "olm/ratchet.hh" -#include "olm/cipher.hh" +#include "olm/cipher.h" #include "unittest.hh" @@ -28,8 +28,9 @@ olm::KdfInfo kdf_info = { ratchet_info, sizeof(ratchet_info) - 1 }; -olm::CipherAesSha256 cipher( - message_info, sizeof(message_info) - 1 +olm_cipher_aes_sha_256 cipher0; +olm_cipher *cipher = olm_cipher_aes_sha_256_init( + &cipher0, message_info, sizeof(message_info) - 1 ); std::uint8_t random_bytes[] = "0123456789ABDEF0123456789ABCDEF"; -- cgit v1.2.3 From c57b2b71c5a1314e79a0ee110ed9e1168a70b921 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 18 May 2016 17:13:39 +0100 Subject: C bindings for base64 functions --- tests/test_base64.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_base64.cpp b/tests/test_base64.cpp index 5bae2f9..a1efe17 100644 --- a/tests/test_base64.cpp +++ b/tests/test_base64.cpp @@ -1,10 +1,11 @@ #include "olm/base64.hh" +#include "olm/base64.h" #include "unittest.hh" int main() { { /* Base64 encode test */ -TestCase test_case("Base64 encode test"); +TestCase test_case("Base64 C++ binding encode test"); std::uint8_t input[] = "Hello World"; std::uint8_t expected_output[] = "SGVsbG8gV29ybGQ"; @@ -18,8 +19,24 @@ olm::encode_base64(input, input_length, output); assert_equals(expected_output, output, output_length); } +{ +TestCase test_case("Base64 C binding encode test"); + +std::uint8_t input[] = "Hello World"; +std::uint8_t expected_output[] = "SGVsbG8gV29ybGQ"; +std::size_t input_length = sizeof(input) - 1; + +std::size_t output_length = ::olm_encode_base64_length(input_length); +assert_equals(std::size_t(15), output_length); + +std::uint8_t output[output_length]; +output_length = ::olm_encode_base64(input, input_length, output); +assert_equals(std::size_t(15), output_length); +assert_equals(expected_output, output, output_length); +} + { /* Base64 decode test */ -TestCase test_case("Base64 decode test"); +TestCase test_case("Base64 C++ binding decode test"); std::uint8_t input[] = "SGVsbG8gV29ybGQ"; std::uint8_t expected_output[] = "Hello World"; @@ -33,4 +50,21 @@ olm::decode_base64(input, input_length, output); assert_equals(expected_output, output, output_length); } +{ +TestCase test_case("Base64 C binding decode test"); + +std::uint8_t input[] = "SGVsbG8gV29ybGQ"; +std::uint8_t expected_output[] = "Hello World"; +std::size_t input_length = sizeof(input) - 1; + +std::size_t output_length = ::olm_decode_base64_length(input_length); +assert_equals(std::size_t(11), output_length); + +std::uint8_t output[output_length]; +output_length = ::olm_decode_base64(input, input_length, output); +assert_equals(std::size_t(11), output_length); +assert_equals(expected_output, output, output_length); +} + + } -- cgit v1.2.3 From 444ef1f70687c340ba1b0b2a22d6e63c734d5f9e Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 20 May 2016 11:59:31 +0100 Subject: Prefix for internal symbols Give a load of internal symbols "_olm_" prefixes. This better delineates the public and private interfaces in the module, and helps avoid internal symbols leaking out and possibly being abused. --- tests/test_base64.cpp | 8 ++++---- tests/test_crypto.cpp | 8 ++++---- tests/test_ratchet.cpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/test_base64.cpp b/tests/test_base64.cpp index a1efe17..c95e3c9 100644 --- a/tests/test_base64.cpp +++ b/tests/test_base64.cpp @@ -26,11 +26,11 @@ std::uint8_t input[] = "Hello World"; std::uint8_t expected_output[] = "SGVsbG8gV29ybGQ"; std::size_t input_length = sizeof(input) - 1; -std::size_t output_length = ::olm_encode_base64_length(input_length); +std::size_t output_length = ::_olm_encode_base64_length(input_length); assert_equals(std::size_t(15), output_length); std::uint8_t output[output_length]; -output_length = ::olm_encode_base64(input, input_length, output); +output_length = ::_olm_encode_base64(input, input_length, output); assert_equals(std::size_t(15), output_length); assert_equals(expected_output, output, output_length); } @@ -57,11 +57,11 @@ std::uint8_t input[] = "SGVsbG8gV29ybGQ"; std::uint8_t expected_output[] = "Hello World"; std::size_t input_length = sizeof(input) - 1; -std::size_t output_length = ::olm_decode_base64_length(input_length); +std::size_t output_length = ::_olm_decode_base64_length(input_length); assert_equals(std::size_t(11), output_length); std::uint8_t output[output_length]; -output_length = ::olm_decode_base64(input, input_length, output); +output_length = ::_olm_decode_base64(input, input_length, output); assert_equals(std::size_t(11), output_length); assert_equals(expected_output, output, output_length); } diff --git a/tests/test_crypto.cpp b/tests/test_crypto.cpp index e86f3ab..1041538 100644 --- a/tests/test_crypto.cpp +++ b/tests/test_crypto.cpp @@ -186,7 +186,7 @@ std::uint8_t expected[32] = { std::uint8_t actual[32]; -crypto_sha256(input, sizeof(input), actual); +_olm_crypto_sha256(input, sizeof(input), actual); assert_equals(expected, actual, 32); @@ -207,7 +207,7 @@ std::uint8_t expected[32] = { std::uint8_t actual[32]; -crypto_hmac_sha256(input, sizeof(input), input, sizeof(input), actual); +_olm_crypto_hmac_sha256(input, sizeof(input), input, sizeof(input), actual); assert_equals(expected, actual, 32); @@ -242,7 +242,7 @@ std::uint8_t hmac_expected_output[32] = { std::uint8_t hmac_actual_output[32] = {}; -crypto_hmac_sha256( +_olm_crypto_hmac_sha256( salt, sizeof(salt), input, sizeof(input), hmac_actual_output @@ -261,7 +261,7 @@ std::uint8_t hkdf_expected_output[42] = { std::uint8_t hkdf_actual_output[42] = {}; -crypto_hkdf_sha256( +_olm_crypto_hkdf_sha256( input, sizeof(input), salt, sizeof(salt), info, sizeof(info), diff --git a/tests/test_ratchet.cpp b/tests/test_ratchet.cpp index 2c8bc1b..3997eb3 100644 --- a/tests/test_ratchet.cpp +++ b/tests/test_ratchet.cpp @@ -28,8 +28,8 @@ olm::KdfInfo kdf_info = { ratchet_info, sizeof(ratchet_info) - 1 }; -olm_cipher_aes_sha_256 cipher0; -olm_cipher *cipher = olm_cipher_aes_sha_256_init( +_olm_cipher_aes_sha_256 cipher0; +_olm_cipher *cipher = _olm_cipher_aes_sha_256_init( &cipher0, message_info, sizeof(message_info) - 1 ); -- cgit v1.2.3 From 2fd28a66824bda7b86c08b065736009c39761987 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 24 May 2016 12:06:47 +0100 Subject: Rewrite _olm_cipher_aes_sha_256 initialisation Replace the init-static-var dance with some preprocessor macros --- tests/test_ratchet.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_ratchet.cpp b/tests/test_ratchet.cpp index 3997eb3..2f8412e 100644 --- a/tests/test_ratchet.cpp +++ b/tests/test_ratchet.cpp @@ -28,10 +28,8 @@ olm::KdfInfo kdf_info = { ratchet_info, sizeof(ratchet_info) - 1 }; -_olm_cipher_aes_sha_256 cipher0; -_olm_cipher *cipher = _olm_cipher_aes_sha_256_init( - &cipher0, message_info, sizeof(message_info) - 1 -); +_olm_cipher_aes_sha_256 cipher0 = OLM_CIPHER_INIT_AES_SHA_256(message_info); +_olm_cipher *cipher = OLM_CIPHER_BASE(&cipher0); std::uint8_t random_bytes[] = "0123456789ABDEF0123456789ABCDEF"; olm::Curve25519KeyPair alice_key; -- cgit v1.2.3