From ab494c1e3eafc27c84c8cf0eb5e5ad8ef37389bc Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 27 Jul 2011 16:16:24 +0300 Subject: [PATCH 1/1] crypto.lib is now a plain C library --- stglibs/crypto.lib/Makefile | 4 +-- stglibs/crypto.lib/{ag_md5.cpp => ag_md5.c} | 0 stglibs/crypto.lib/ag_md5.h | 13 ++++++-- .../crypto.lib/{blowfish.cpp => blowfish.c} | 30 +++++-------------- stglibs/crypto.lib/blowfish.h | 8 +++++ 5 files changed, 28 insertions(+), 27 deletions(-) rename stglibs/crypto.lib/{ag_md5.cpp => ag_md5.c} (100%) rename stglibs/crypto.lib/{blowfish.cpp => blowfish.c} (96%) diff --git a/stglibs/crypto.lib/Makefile b/stglibs/crypto.lib/Makefile index 7d19fcec..6e83e01e 100644 --- a/stglibs/crypto.lib/Makefile +++ b/stglibs/crypto.lib/Makefile @@ -4,8 +4,8 @@ LIB_NAME = stgcrypto -SRCS = ag_md5.cpp \ - blowfish.cpp +SRCS = ag_md5.c \ + blowfish.c INCS = ag_md5.h \ blowfish.h diff --git a/stglibs/crypto.lib/ag_md5.cpp b/stglibs/crypto.lib/ag_md5.c similarity index 100% rename from stglibs/crypto.lib/ag_md5.cpp rename to stglibs/crypto.lib/ag_md5.c diff --git a/stglibs/crypto.lib/ag_md5.h b/stglibs/crypto.lib/ag_md5.h index 9a8b16a0..b278f97b 100644 --- a/stglibs/crypto.lib/ag_md5.h +++ b/stglibs/crypto.lib/ag_md5.h @@ -1,10 +1,14 @@ #ifndef _MD5_H #define _MD5_H -#include +#include #include "stg/os_int.h" +#ifdef __cplusplus +extern "C" { +#endif + struct MD5Context { uint32_t buf[4]; uint32_t bits[2]; @@ -19,7 +23,6 @@ void MD5Init(struct MD5Context *ctx); void MD5Update(struct MD5Context*, char const*, unsigned); void MD5Final(unsigned char digest[16], struct MD5Context *ctx); void MD5Transform(uint32_t buf[4], uint32_t const in[16]); -/* static void to64(char*, unsigned long, int); */ char *libshadow_md5_crypt(const char*, const char*); char *pw_encrypt(const char*, const char*); @@ -27,4 +30,8 @@ char *pw_encrypt(const char*, const char*); char *make_ag_hash(time_t salt, const char *clear); int check_ag_hash(time_t salt, const char *clear, const char *hash); -#endif /* _MD5_H */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stglibs/crypto.lib/blowfish.cpp b/stglibs/crypto.lib/blowfish.c similarity index 96% rename from stglibs/crypto.lib/blowfish.cpp rename to stglibs/crypto.lib/blowfish.c index ad482b79..e11bb1a2 100644 --- a/stglibs/crypto.lib/blowfish.cpp +++ b/stglibs/crypto.lib/blowfish.c @@ -5,20 +5,10 @@ * Description: C implementation of the Blowfish algorithm. */ -#include +#include -#include "blowfish.h" #include "stg/const.h" - -/*typedef struct _BCoptions - { - unsigned char remove; - unsigned char standardout; - unsigned char compression; - unsigned char type; - uint32_t origsize; - unsigned char securedelete; - } BCoptions;*/ +#include "blowfish.h" #define ENCRYPT 0 #define DECRYPT 1 @@ -445,28 +435,24 @@ for (i = 0; i < 4; ++i) } } //----------------------------------------------------------------------------- -void EnDecodeInit(const char * passwd, int, BLOWFISH_CTX *ctx) +void EnDecodeInit(const char * passwd, int length, BLOWFISH_CTX *ctx) { -unsigned char * keyL = NULL;//[PASSWD_LEN]; // ðÁÒÏÌØ ÄÌÑ ÛÉÆÒÏ×ËÉ - -keyL = new unsigned char[PASSWD_LEN]; +unsigned char keyL[PASSWD_LEN]; memset(keyL, 0, PASSWD_LEN); strncpy((char *)keyL, passwd, PASSWD_LEN); Blowfish_Init(ctx, keyL, PASSWD_LEN); - -delete[] keyL; } //----------------------------------------------------------------------------- // Note: swap bytes order for compatibility with OpenSSL uint32_t bytes2block(const char * c) { - uint32_t t = static_cast(*c++); - t += static_cast(*c++) << 8; - t += static_cast(*c++) << 16; - t += static_cast(*c) << 24; + uint32_t t = (unsigned char)(*c++); + t += (unsigned char)(*c++) << 8; + t += (unsigned char)(*c++) << 16; + t += (unsigned char)(*c) << 24; return t; } //----------------------------------------------------------------------------- diff --git a/stglibs/crypto.lib/blowfish.h b/stglibs/crypto.lib/blowfish.h index 45d92110..20f2fff7 100644 --- a/stglibs/crypto.lib/blowfish.h +++ b/stglibs/crypto.lib/blowfish.h @@ -12,6 +12,10 @@ #define MAXKEYBYTES 56 /* 448 bits */ +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { uint32_t P[16 + 2]; uint32_t S[4][256]; @@ -25,5 +29,9 @@ void EnDecodeInit(const char * key, int passwdLen, BLOWFISH_CTX *ctx); void DecodeString(char * d, const char * s, BLOWFISH_CTX *ctx); void EncodeString(char * d, const char * s, BLOWFISH_CTX *ctx); +#ifdef __cplusplus +} +#endif + #endif -- 2.44.2