diff options
Diffstat (limited to 'src/common/md5calc.cpp')
-rw-r--r-- | src/common/md5calc.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp index b0f8e5f..1625912 100644 --- a/src/common/md5calc.cpp +++ b/src/common/md5calc.cpp @@ -1,6 +1,10 @@ #include "md5calc.hpp" -#include <string.h> -#include "mt_rand.hpp" + +#include <cstring> + +#include "random.hpp" + +#include "../poison.hpp" // auxilary data /* @@ -9,7 +13,8 @@ sin() constant table echo 'scale=40; obase=16; for (i=1;i<=64;i++) print 2^32 * sin(i), "\n"' | bc | sed 's/^-//;s/^/0x/;s/\..*$/,/' */ -static const uint32_t T[64] = +static +const uint32_t T[64] = { // used by round 1 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0 @@ -35,29 +40,35 @@ static const uint32_t T[64] = // auxilary functions // note - the RFC defines these by non-CS conventions: or=v, and=(empty) -static inline uint32_t rotate_left(uint32_t val, unsigned shift) +static +uint32_t rotate_left(uint32_t val, unsigned shift) { return val << shift | val >> (32-shift); } -static inline uint32_t F(uint32_t X, uint32_t Y, uint32_t Z) +static +uint32_t F(uint32_t X, uint32_t Y, uint32_t Z) { return (X & Y) | (~X & Z); } -static inline uint32_t G(uint32_t X, uint32_t Y, uint32_t Z) +static +uint32_t G(uint32_t X, uint32_t Y, uint32_t Z) { return (X & Z) | (Y & ~Z); } -static inline uint32_t H(uint32_t X, uint32_t Y, uint32_t Z) +static +uint32_t H(uint32_t X, uint32_t Y, uint32_t Z) { return X ^ Y ^ Z; } -static inline uint32_t I(uint32_t X, uint32_t Y, uint32_t Z) +static +uint32_t I(uint32_t X, uint32_t Y, uint32_t Z) { return Y ^ (X | ~Z); } -static const struct +static +const struct { uint8_t k : 4; uint8_t : 0; @@ -165,7 +176,8 @@ void MD5_to_bin(MD5_state state, uint8_t out[0x10]) out[i] = state.val[i/4] >> 8*(i%4); } -static const char hex[] = "0123456789abcdef"; +static +const char hex[] = "0123456789abcdef"; void MD5_to_str(MD5_state state, char out[0x21]) { @@ -193,7 +205,7 @@ MD5_state MD5_from_string(const char* msg, const size_t msglen) } // now pad 1-512 bits + the 64-bit length - may be two blocks uint8_t buf[0x40] = {}; - memcpy (buf, msg, rem); + memcpy(buf, msg, rem); buf[rem] = 0x80; // a single one bit if (64 - rem > 8) { @@ -293,8 +305,9 @@ const char *MD5_saltcrypt(const char *key, const char *salt) const char *make_salt(void) { static char salt[6]; - for (int i=0; i<5; i++) - salt[i] = MPRAND(48, 78); + for (int i = 0; i < 5; i++) + // 126 would probably actually be okay + salt[i] = random_::in(48, 125); return salt; } |