diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-02-14 23:17:13 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-02-14 23:18:16 +0300 |
commit | a8dad2e0664da2e0e95eedb8d83462e2bd52cc7e (patch) | |
tree | 06308ac93c963b846083deca9f364d194d136763 /protocols | |
parent | 5bb58bd24e6be45c6812713795d2e58e5ac18989 (diff) |
protocols:
jabber:
omemo:
added hmac_sha256 callbacks to libsignal-c initialization
Diffstat (limited to 'protocols')
-rwxr-xr-x | protocols/JabberG/src/jabber.cpp | 6 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_omemo.cpp | 87 |
2 files changed, 75 insertions, 18 deletions
diff --git a/protocols/JabberG/src/jabber.cpp b/protocols/JabberG/src/jabber.cpp index 469e89c4cd..184a5651d6 100755 --- a/protocols/JabberG/src/jabber.cpp +++ b/protocols/JabberG/src/jabber.cpp @@ -179,7 +179,9 @@ static int jabberProtoUninit(CJabberProto *ppro) return 0;
}
-int init_omemo();
+namespace omemo {
+ int init_omemo();
+};
extern "C" int __declspec(dllexport) Load()
{
@@ -223,7 +225,7 @@ extern "C" int __declspec(dllexport) Load() g_MenuInit();
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
JabberUserInfoInit();
- init_omemo();
+ omemo::init_omemo();
return 0;
}
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index 825ed9428e..1d137feebc 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -26,25 +26,80 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
#include <signal_protocol.h>
-//TODO: create mutex
+namespace omemo {
-void lock(void * /*user_data*/)
-{
+ int random_func(uint8_t *data, size_t len, void * /*user_data*/)
+ {
+ Utils_GetRandom(data, len);
+ return 0;
+ }
-}
+ struct hmac_sha256_ctx {
+ uint8_t *key, *data;
+ size_t key_len, data_len;
+ };
-void unlock(void * /*user_data*/)
-{
+ int hmac_sha256_init_func(void **hmac_context, const uint8_t *key, size_t key_len, void * /*user_data*/)
+ {
+ hmac_sha256_ctx *ctx = (hmac_sha256_ctx*)mir_alloc(sizeof(hmac_sha256_ctx));
+ ctx->key = (uint8_t*)mir_alloc(key_len);
+ memcpy(ctx->key, key, key_len);
+ ctx->key_len = key_len;
+ *hmac_context = ctx;
+ return 0;
+ }
+ int hmac_sha256_update_func(void *hmac_context, const uint8_t *data, size_t data_len, void * /*user_data*/)
+ {
+ hmac_sha256_ctx *ctx = (hmac_sha256_ctx*)hmac_context;
+ ctx->data = (uint8_t*)mir_alloc(data_len);
+ memcpy(ctx->data, data, data_len);
+ ctx->data_len = data_len;
+ return 0;
+ }
+ int hmac_sha256_final_func(void *hmac_context, signal_buffer **output, void * /*user_data*/)
+ {
+ hmac_sha256_ctx *ctx = (hmac_sha256_ctx*)hmac_context;
+ BYTE hashout[MIR_SHA256_HASH_SIZE];
+ mir_hmac_sha256(hashout, ctx->key, ctx->key_len, ctx->data, ctx->data_len);
+ signal_buffer *output_buffer = signal_buffer_create(hashout, MIR_SHA256_HASH_SIZE);
+ *output = output_buffer;
+ return 0;
+ }
+ void hmac_sha256_cleanup_func(void * hmac_context, void * /*user_data*/)
+ {
+ hmac_sha256_ctx *ctx = (hmac_sha256_ctx*)hmac_context;
+ mir_free(ctx->key);
+ mir_free(ctx->data);
+ }
-}
+ CRITICAL_SECTION _signal_cs;
+ mir_cslockfull signal_mutex(_signal_cs);
-int init_omemo()
-{
- signal_context *global_context;
- signal_crypto_provider provider;
- signal_context_create(&global_context, NULL);
- signal_context_set_crypto_provider(global_context, &provider);
- signal_context_set_locking_functions(global_context, &lock, &unlock);
+ void lock(void * /*user_data*/)
+ {
+ signal_mutex.lock();
+ }
- return 0;
-}
\ No newline at end of file + void unlock(void * /*user_data*/)
+ {
+ signal_mutex.unlock();
+ }
+
+ int init_omemo()
+ {
+ signal_mutex.unlock(); //fuck...
+ signal_context *global_context;
+ signal_context_create(&global_context, NULL);
+ signal_crypto_provider provider;
+ provider.random_func = &random_func;
+ provider.hmac_sha256_init_func = &hmac_sha256_init_func;
+ provider.hmac_sha256_update_func = &hmac_sha256_update_func;
+ provider.hmac_sha256_final_func = &hmac_sha256_final_func;
+ provider.hmac_sha256_cleanup_func = &hmac_sha256_cleanup_func;
+ signal_context_set_crypto_provider(global_context, &provider);
+ signal_context_set_locking_functions(global_context, &lock, &unlock);
+
+ return 0;
+ }
+
+};
|