Fix crypt

--HG--
branch : sha512-auth
This commit is contained in:
kaetemi 2014-10-07 03:00:34 +02:00
parent e6c0c70fc9
commit 025d7b6260
3 changed files with 11 additions and 11 deletions

View file

@ -18,16 +18,15 @@
#include "crypt.h" #include "crypt.h"
char * rz_crypt(register const char *key, register const char *setting); char * rz_crypt(register const char *key, register const char *setting, char *buf);
char *__crypt_sha512(const char *key, const char *setting, char *output); char *__crypt_sha512(const char *key, const char *setting, char *output);
// Crypts password using salt // Crypts password using salt
std::string CCrypt::crypt(const std::string& password, const std::string& salt) std::string CCrypt::crypt(const std::string& password, const std::string& salt)
{ {
std::string result = ::rz_crypt(password.c_str(), salt.c_str()); char buf[128];
return ::rz_crypt(password.c_str(), salt.c_str(), buf);
return result;
} }
@ -506,7 +505,7 @@ static char cryptresult[1+4+4+11+1]; /* encrypted result */
* Return a pointer to static data consisting of the "setting" * Return a pointer to static data consisting of the "setting"
* followed by an encryption produced by the "key" and "setting". * followed by an encryption produced by the "key" and "setting".
*/ */
char * rz_crypt(register const char *key, register const char *setting) { char * rz_crypt(register const char *key, register const char *setting, char *buf) {
register char *encp; register char *encp;
register long i; register long i;
register int t; register int t;
@ -521,8 +520,7 @@ char * rz_crypt(register const char *key, register const char *setting) {
return buff; return buff;
#endif #endif
static char buf[128]; if (setting[0] == '$' && setting[1] == '6') {
if (key[0] == '$' && key[1] == '6') {
return __crypt_sha512(key, setting, buf); return __crypt_sha512(key, setting, buf);
} }

View file

@ -365,9 +365,11 @@ char *__crypt_sha512(const char *key, const char *setting, char *output)
char *p, *q; char *p, *q;
p = sha512crypt(key, setting, output); p = sha512crypt(key, setting, output);
/* self test and stack cleanup */ /* self test and stack cleanup */
q = sha512crypt(testkey, testsetting, testbuf); q = sha512crypt(testkey, testsetting, testbuf);
if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash)) if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof(testhash)))
return "*"; return "*";
return p; return p;
} }