mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Implement bright_ambassador
This commit is contained in:
parent
35c320d53d
commit
1162b26759
7 changed files with 155 additions and 4 deletions
|
@ -6,7 +6,8 @@ set(HEADER_FILES
|
||||||
include/chiaki/base64.h
|
include/chiaki/base64.h
|
||||||
include/chiaki/http.h
|
include/chiaki/http.h
|
||||||
include/chiaki/log.h
|
include/chiaki/log.h
|
||||||
include/chiaki/ctrl.h)
|
include/chiaki/ctrl.h
|
||||||
|
include/chiaki/rpcrypt.h)
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
src/common.c
|
src/common.c
|
||||||
|
@ -15,7 +16,9 @@ set(SOURCE_FILES
|
||||||
src/base64.c
|
src/base64.c
|
||||||
src/http.c
|
src/http.c
|
||||||
src/log.c
|
src/log.c
|
||||||
src/ctrl.c)
|
src/ctrl.c
|
||||||
|
src/rpcrypt.c)
|
||||||
|
|
||||||
|
|
||||||
add_library(chiaki-lib ${HEADER_FILES} ${SOURCE_FILES})
|
add_library(chiaki-lib ${HEADER_FILES} ${SOURCE_FILES})
|
||||||
set_target_properties(chiaki-lib PROPERTIES OUTPUT_NAME chiaki)
|
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)
|
find_package(Threads)
|
||||||
target_link_libraries(chiaki-lib Threads::Threads)
|
target_link_libraries(chiaki-lib Threads::Threads)
|
||||||
|
|
||||||
|
find_package(OpenSSL REQUIRED)
|
||||||
|
target_link_libraries(chiaki-lib OpenSSL::Crypto)
|
42
lib/include/chiaki/rpcrypt.h
Normal file
42
lib/include/chiaki/rpcrypt.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CHIAKI_RPCRYPT_H
|
||||||
|
#define CHIAKI_RPCRYPT_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#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
|
|
@ -22,6 +22,7 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "ctrl.h"
|
#include "ctrl.h"
|
||||||
|
#include "rpcrypt.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
@ -70,7 +71,6 @@ typedef struct chiaki_event_t
|
||||||
typedef void (*ChiakiEventCallback)(ChiakiEvent *event, void *user);
|
typedef void (*ChiakiEventCallback)(ChiakiEvent *event, void *user);
|
||||||
|
|
||||||
|
|
||||||
#define CHIAKI_KEY_BYTES 0x10
|
|
||||||
|
|
||||||
typedef struct chiaki_session_t
|
typedef struct chiaki_session_t
|
||||||
{
|
{
|
||||||
|
|
45
lib/src/rpcrypt.c
Normal file
45
lib/src/rpcrypt.c
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <chiaki/rpcrypt.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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<CHIAKI_KEY_BYTES; i++)
|
||||||
|
{
|
||||||
|
uint8_t v = nonce[i];
|
||||||
|
v -= i;
|
||||||
|
v -= 0x27;
|
||||||
|
v ^= echo_a[i];
|
||||||
|
ambassador[i] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(uint8_t i=0; i<CHIAKI_KEY_BYTES; i++)
|
||||||
|
{
|
||||||
|
uint8_t v = morning[i];
|
||||||
|
v -= i;
|
||||||
|
v += 0x34;
|
||||||
|
v ^= echo_b[i];
|
||||||
|
v ^= nonce[i];
|
||||||
|
bright[i] = v;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,8 @@ target_include_directories(munit PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/munit")
|
||||||
|
|
||||||
add_executable(chiaki-unit
|
add_executable(chiaki-unit
|
||||||
main.c
|
main.c
|
||||||
http.c)
|
http.c
|
||||||
|
rpcrypt.c)
|
||||||
|
|
||||||
target_link_libraries(chiaki-unit chiaki-lib munit)
|
target_link_libraries(chiaki-unit chiaki-lib munit)
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <munit.h>
|
#include <munit.h>
|
||||||
|
|
||||||
extern MunitTest tests_http[];
|
extern MunitTest tests_http[];
|
||||||
|
extern MunitTest tests_rpcrypt[];
|
||||||
|
|
||||||
static MunitSuite suites[] = {
|
static MunitSuite suites[] = {
|
||||||
{
|
{
|
||||||
|
@ -27,6 +28,13 @@ static MunitSuite suites[] = {
|
||||||
1,
|
1,
|
||||||
MUNIT_SUITE_OPTION_NONE
|
MUNIT_SUITE_OPTION_NONE
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"/rpcrypt",
|
||||||
|
tests_rpcrypt,
|
||||||
|
NULL,
|
||||||
|
1,
|
||||||
|
MUNIT_SUITE_OPTION_NONE
|
||||||
|
},
|
||||||
{ NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE }
|
{ NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
49
test/rpcrypt.c
Normal file
49
test/rpcrypt.c
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <munit.h>
|
||||||
|
|
||||||
|
#include <chiaki/rpcrypt.h>
|
||||||
|
|
||||||
|
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 }
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue