summaryrefslogtreecommitdiff
path: root/src/modules/common/swcipher.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:49 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:49 -0400
commit8c8aa6b07e595cfac56838b5964ab3e96051f1b2 (patch)
treeda38e2c1979148dbd3b0c7b87f930746f5ba7f44 /src/modules/common/swcipher.cpp
parent8d3fc864d094eeadc721f8e93436b37a5fab173e (diff)
Imported Upstream version 1.5.7
Diffstat (limited to 'src/modules/common/swcipher.cpp')
-rw-r--r--src/modules/common/swcipher.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/modules/common/swcipher.cpp b/src/modules/common/swcipher.cpp
index d221b8b..bd4d551 100644
--- a/src/modules/common/swcipher.cpp
+++ b/src/modules/common/swcipher.cpp
@@ -3,10 +3,11 @@
* cipher utilities.
*/
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <swcipher.h>
+SWORD_NAMESPACE_START
/******************************************************************************
* SWCipher Constructor - Initializes data for instance of SWCipher
@@ -30,7 +31,7 @@ SWCipher::~SWCipher()
}
-char *SWCipher::Buf(const char *ibuf, unsigned int ilen)
+char *SWCipher::Buf(const char *ibuf, unsigned long ilen)
{
if (ibuf) {
@@ -54,14 +55,14 @@ char *SWCipher::Buf(const char *ibuf, unsigned int ilen)
}
-char *SWCipher::cipherBuf(unsigned int *ilen, const char *ibuf)
+char *SWCipher::cipherBuf(unsigned long *ilen, const char *ibuf)
{
if (ibuf) {
if (buf)
free(buf);
- buf = (char *) malloc(*ilen);
+ buf = (char *) malloc(*ilen+1);
memcpy(buf, ibuf, *ilen);
len = *ilen;
cipher = true;
@@ -69,7 +70,7 @@ char *SWCipher::cipherBuf(unsigned int *ilen, const char *ibuf)
Encode();
- *ilen = (short)len;
+ *ilen = len;
return buf;
}
@@ -86,7 +87,7 @@ void SWCipher::Encode(void)
{
if (!cipher) {
work = master;
- for (int i = 0; i < len; i++)
+ for (unsigned long i = 0; i < len; i++)
buf[i] = work.encrypt(buf[i]);
cipher = true;
}
@@ -105,8 +106,10 @@ void SWCipher::Decode(void)
{
if (cipher) {
work = master;
- for (int i = 0; i < len; i++)
+ unsigned long i;
+ for (i = 0; i < len; i++)
buf[i] = work.decrypt(buf[i]);
+ buf[i] = 0;
cipher = false;
}
}
@@ -121,3 +124,5 @@ void SWCipher::setCipherKey(const char *ikey) {
unsigned char *key = (unsigned char *)ikey;
master.initialize(key, strlen((char *)key));
}
+
+SWORD_NAMESPACE_END