From 1162b26759c343741b29d8ec8bcd6e2f82dc44e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sat, 17 Nov 2018 11:43:36 +0100 Subject: [PATCH] Implement bright_ambassador --- lib/CMakeLists.txt | 10 ++++++-- lib/include/chiaki/rpcrypt.h | 42 +++++++++++++++++++++++++++++++ lib/include/chiaki/session.h | 2 +- lib/src/rpcrypt.c | 45 +++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 3 ++- test/main.c | 8 ++++++ test/rpcrypt.c | 49 ++++++++++++++++++++++++++++++++++++ 7 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 lib/include/chiaki/rpcrypt.h create mode 100644 lib/src/rpcrypt.c create mode 100644 test/rpcrypt.c diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 8037f67..52c7bac 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -6,7 +6,8 @@ set(HEADER_FILES include/chiaki/base64.h include/chiaki/http.h include/chiaki/log.h - include/chiaki/ctrl.h) + include/chiaki/ctrl.h + include/chiaki/rpcrypt.h) set(SOURCE_FILES src/common.c @@ -15,7 +16,9 @@ set(SOURCE_FILES src/base64.c src/http.c src/log.c - src/ctrl.c) + src/ctrl.c + src/rpcrypt.c) + add_library(chiaki-lib ${HEADER_FILES} ${SOURCE_FILES}) set_target_properties(chiaki-lib PROPERTIES OUTPUT_NAME chiaki) @@ -24,3 +27,6 @@ target_include_directories(chiaki-lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/includ find_package(Threads) target_link_libraries(chiaki-lib Threads::Threads) + +find_package(OpenSSL REQUIRED) +target_link_libraries(chiaki-lib OpenSSL::Crypto) \ No newline at end of file diff --git a/lib/include/chiaki/rpcrypt.h b/lib/include/chiaki/rpcrypt.h new file mode 100644 index 0000000..0d0e72a --- /dev/null +++ b/lib/include/chiaki/rpcrypt.h @@ -0,0 +1,42 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +#ifndef CHIAKI_RPCRYPT_H +#define CHIAKI_RPCRYPT_H + +#include "common.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define CHIAKI_KEY_BYTES 0x10 + +typedef struct chiaki_rpcrypt_t +{ + +} ChiakiRPCrypt; + +CHIAKI_EXPORT void chiaki_rpcrypt_bright_ambassador(uint8_t *bright, uint8_t *ambassador, const uint8_t *nonce, const uint8_t *morning); + +#ifdef __cplusplus +} +#endif + +#endif // CHIAKI_RPCRYPT_H diff --git a/lib/include/chiaki/session.h b/lib/include/chiaki/session.h index 804cc41..7793f75 100644 --- a/lib/include/chiaki/session.h +++ b/lib/include/chiaki/session.h @@ -22,6 +22,7 @@ #include "thread.h" #include "log.h" #include "ctrl.h" +#include "rpcrypt.h" #include #include @@ -70,7 +71,6 @@ typedef struct chiaki_event_t typedef void (*ChiakiEventCallback)(ChiakiEvent *event, void *user); -#define CHIAKI_KEY_BYTES 0x10 typedef struct chiaki_session_t { diff --git a/lib/src/rpcrypt.c b/lib/src/rpcrypt.c new file mode 100644 index 0000000..e838251 --- /dev/null +++ b/lib/src/rpcrypt.c @@ -0,0 +1,45 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +#include + + + +CHIAKI_EXPORT void chiaki_rpcrypt_bright_ambassador(uint8_t *bright, uint8_t *ambassador, const uint8_t *nonce, const uint8_t *morning) +{ + static const uint8_t echo_a[] = { 0x01, 0x49, 0x87, 0x9b, 0x65, 0x39, 0x8b, 0x39, 0x4b, 0x3a, 0x8d, 0x48, 0xc3, 0x0a, 0xef, 0x51 }; + static const uint8_t echo_b[] = { 0xe1, 0xec, 0x9c, 0x3a, 0xdd, 0xbd, 0x08, 0x85, 0xfc, 0x0e, 0x1d, 0x78, 0x90, 0x32, 0xc0, 0x04 }; + + for(uint8_t i=0; i extern MunitTest tests_http[]; +extern MunitTest tests_rpcrypt[]; static MunitSuite suites[] = { { @@ -27,6 +28,13 @@ static MunitSuite suites[] = { 1, MUNIT_SUITE_OPTION_NONE }, + { + "/rpcrypt", + tests_rpcrypt, + NULL, + 1, + MUNIT_SUITE_OPTION_NONE + }, { NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE } }; diff --git a/test/rpcrypt.c b/test/rpcrypt.c new file mode 100644 index 0000000..d02ee93 --- /dev/null +++ b/test/rpcrypt.c @@ -0,0 +1,49 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +#include + +#include + +static MunitResult test_bright_ambassador(const MunitParameter params[], void *user) +{ + static const uint8_t nonce[] = { 0x43, 0x9, 0x67, 0xae, 0x36, 0x4b, 0x1c, 0x45, 0x26, 0x62, 0x37, 0x7a, 0xbf, 0x3f, 0xe9, 0x39 }; + static const uint8_t morning[] = { 0xd2, 0x78, 0x9f, 0x51, 0x85, 0xa7, 0x99, 0xa2, 0x44, 0x52, 0x77, 0x9c, 0x2b, 0x83, 0xcf, 0x7 }; + static const uint8_t bright_expected[] = { 0xa4, 0x4e, 0x2a, 0x16, 0x5e, 0x20, 0xd3, 0xf, 0xaa, 0x11, 0x8b, 0xc7, 0x7c, 0xa7, 0xdc, 0x11 }; + static const uint8_t ambassador_expected[] = { 0x1d, 0xa8, 0xb9, 0x1f, 0x6e, 0x26, 0x64, 0x2e, 0xbc, 0x8, 0x8b, 0x0, 0x4f, 0x1, 0x5b, 0x52 }; + + uint8_t bright[CHIAKI_KEY_BYTES]; + uint8_t ambassador[CHIAKI_KEY_BYTES]; + chiaki_rpcrypt_bright_ambassador(bright, ambassador, nonce, morning); + + munit_assert_memory_equal(CHIAKI_KEY_BYTES, bright, bright_expected); + munit_assert_memory_equal(CHIAKI_KEY_BYTES, ambassador, ambassador_expected); + + return MUNIT_OK; +} + +MunitTest tests_rpcrypt[] = { + { + "/bright_ambassador", + test_bright_ambassador, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL + }, + { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } +}; \ No newline at end of file