From 070f97038a36f1c8e5401f0701f1313ea33148cc Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 18 Dec 2010 16:03:54 +0200 Subject: [PATCH] =?utf8?q?=D0=A3=20=D0=BA=D0=BB=D0=B0=D1=81=D1=96=20=D0=BF?= =?utf8?q?=D1=96=D0=B4=D1=82=D1=80=D0=B8=D0=BC=D0=BA=D0=B8=20=D0=BF=D1=80?= =?utf8?q?=D0=BE=D1=82=D0=BE=D0=BA=D0=BE=D0=BB=D1=83=20=D1=81=D0=B5=D1=80?= =?utf8?q?=D0=B2=D0=B5=D1=80=D0=B0=20rscriptd=20=D0=BC=D0=B5=D1=82=D0=BE?= =?utf8?q?=D0=B4=D0=B8=20=D1=88=D0=B8=D1=84=D1=80=D1=83=D0=B2=D0=B0=D0=BD?= =?utf8?q?=D0=BD=D1=8F=20=D0=B2=D0=B8=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=96?= =?utf8?q?=20=D1=8F=D0=BA=20=D0=B7=D0=B2=D0=B8=D1=87=D0=B0=D0=B9=D0=BD?= =?utf8?q?=D1=96=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D1=96=D1=97.=20=D0=A2?= =?utf8?q?=D0=B0=D0=BA=D0=BE=D0=B6=20=D0=B4=D0=BE=D0=B4=D0=B0=D0=BD=D1=96?= =?utf8?q?=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=B0=D0=B4=D0=BD=D0=B0=20?= =?utf8?q?=D0=B7=D0=B0=D0=B3=D0=BE=D0=BB=D0=BE=D0=B2=D0=BE=D1=87=D0=BD?= =?utf8?q?=D1=96=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/rscriptd/listener.cpp | 42 +++++++++++++++++++--------------- projects/rscriptd/listener.h | 3 --- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index 87a85ebb..8737b3b8 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,9 @@ #include "stg_locker.h" #include "common.h" +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); +void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); + //----------------------------------------------------------------------------- LISTENER::LISTENER() : WriteServLog(GetStgLogger()), @@ -52,7 +56,7 @@ version = "rscriptd listener v.1.2"; pthread_mutex_init(&mutex, NULL); } //----------------------------------------------------------------------------- -void LISTENER::SetPassword(const string & p) +void LISTENER::SetPassword(const std::string & p) { password = p; printfd(__FILE__, "Encryption initiated with password \'%s\'\n", password.c_str()); @@ -439,23 +443,6 @@ else return false; } //----------------------------------------------------------------------------- -void LISTENER::InitEncrypt(BLOWFISH_CTX * ctx, const string & password) -{ -unsigned char keyL[PASSWD_LEN]; -memset(keyL, 0, PASSWD_LEN); -strncpy((char *)keyL, password.c_str(), PASSWD_LEN); -Blowfish_Init(ctx, keyL, PASSWD_LEN); -} -//----------------------------------------------------------------------------- -void LISTENER::Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) -{ -if (dst != src) - memcpy(dst, src, len8 * 8); - -for (int i = 0; i < len8; i++) - Blowfish_Decrypt(ctx, (uint32_t *)(dst + i * 8), (uint32_t *)(dst + i * 8 + 4)); -} -//----------------------------------------------------------------------------- bool LISTENER::CheckHeader(const RS_PACKET_HEADER & header) const { if (strncmp((char *)header.magic, RS_ID, RS_MAGIC_LEN)) @@ -497,3 +484,22 @@ if (res == 0) // Timeout return true; } //----------------------------------------------------------------------------- +inline +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) +{ +unsigned char keyL[PASSWD_LEN]; +memset(keyL, 0, PASSWD_LEN); +strncpy((char *)keyL, password.c_str(), PASSWD_LEN); +Blowfish_Init(ctx, keyL, PASSWD_LEN); +} +//----------------------------------------------------------------------------- +inline +void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) +{ +if (dst != src) + memcpy(dst, src, len8 * 8); + +for (int i = 0; i < len8; i++) + Blowfish_Decrypt(ctx, (uint32_t *)(dst + i * 8), (uint32_t *)(dst + i * 8 + 4)); +} +//----------------------------------------------------------------------------- diff --git a/projects/rscriptd/listener.h b/projects/rscriptd/listener.h index 4a012c77..abc03f6f 100644 --- a/projects/rscriptd/listener.h +++ b/projects/rscriptd/listener.h @@ -104,9 +104,6 @@ private: void ProcessTimeouts(); bool Disconnect(const UserData & data) const; bool Connect(const UserData & data) const; - // Decryption stuff - void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); - void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); BLOWFISH_CTX ctxS; STG_LOGGER & WriteServLog; -- 2.43.2