From: Maxim Mamontov <faust.madf@gmail.com>
Date: Wed, 27 Jul 2011 14:08:09 +0000 (+0300)
Subject: Fixed interface in stgcrypto
X-Git-Tag: 2.408-alpha~61
X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/87b537b8e3e393c865cfa5bcb199ab6223a20134?ds=sidebyside

Fixed interface in stgcrypto
---

diff --git a/stglibs/crypto.lib/blowfish.c b/stglibs/crypto.lib/blowfish.c
index e11bb1a2..69c467bd 100644
--- a/stglibs/crypto.lib/blowfish.c
+++ b/stglibs/crypto.lib/blowfish.c
@@ -16,6 +16,8 @@
 #define endianBig ((unsigned char) 0x45)
 #define endianLittle ((unsigned char) 0x54)
 
+#define MIN(a,b) ((a) < (b) ? a : b)
+
 #ifdef WIN32 /* Win32 doesn't have random() or lstat */
     #define random() rand()
     #define initstate(x,y,z) srand(x)
@@ -27,7 +29,7 @@
 #endif
 
 
-#define N               16
+#define N 16
 
 static uint32_t F(BLOWFISH_CTX *ctx, uint32_t x);
 static const uint32_t ORIG_P[16 + 2] = {
@@ -435,13 +437,13 @@ for (i = 0; i < 4; ++i)
     }
 }
 //-----------------------------------------------------------------------------
-void EnDecodeInit(const char * passwd, int length, BLOWFISH_CTX *ctx)
+void EnDecodeInit(const char * passwd, size_t length, BLOWFISH_CTX *ctx)
 {
 unsigned char keyL[PASSWD_LEN];
 
 memset(keyL, 0, PASSWD_LEN);
 
-strncpy((char *)keyL, passwd, PASSWD_LEN);
+strncpy((char *)keyL, passwd, MIN(length, PASSWD_LEN));
 
 Blowfish_Init(ctx, keyL, PASSWD_LEN);
 }
diff --git a/stglibs/crypto.lib/blowfish.h b/stglibs/crypto.lib/blowfish.h
index 20f2fff7..a8800d75 100644
--- a/stglibs/crypto.lib/blowfish.h
+++ b/stglibs/crypto.lib/blowfish.h
@@ -25,7 +25,7 @@ void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen);
 void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr);
 void Blowfish_Decrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr);
 
-void EnDecodeInit(const char * key, int passwdLen, BLOWFISH_CTX *ctx);
+void EnDecodeInit(const char * key, size_t length, BLOWFISH_CTX *ctx);
 void DecodeString(char * d, const char * s, BLOWFISH_CTX *ctx);
 void EncodeString(char * d, const char * s, BLOWFISH_CTX *ctx);