diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2013-09-08 19:43:28 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2013-09-09 19:29:31 -0700 |
commit | a5861a4c81bb616b7fba2028cf9ee31f890357c5 (patch) | |
tree | 0a7aedad97d70b6194eb57a7de39857d015685a3 /src/common/md5calc.cpp | |
parent | 367e76ba89bde0e3fb6c4ae0e64cd3927e0db2f2 (diff) | |
download | tmwa-a5861a4c81bb616b7fba2028cf9ee31f890357c5.tar.gz tmwa-a5861a4c81bb616b7fba2028cf9ee31f890357c5.tar.bz2 tmwa-a5861a4c81bb616b7fba2028cf9ee31f890357c5.tar.xz tmwa-a5861a4c81bb616b7fba2028cf9ee31f890357c5.zip |
Use IP4 classes and rename conf variables
Diffstat (limited to 'src/common/md5calc.cpp')
-rw-r--r-- | src/common/md5calc.cpp | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp index ae134b7..1c48a24 100644 --- a/src/common/md5calc.cpp +++ b/src/common/md5calc.cpp @@ -327,26 +327,21 @@ bool pass_ok(AccountPass password, AccountCrypt crypted) // [M|h]ashes up an IP address and a secret key // to return a hopefully unique masked IP. -struct in_addr MD5_ip(struct in_addr ip) +IP4Address MD5_ip(IP4Address ip) { static SaltString secret = make_salt(); - union - { - uint8_t bytes[4]; - struct in_addr ip; - } conv; // MD5sum a secret + the IP address VString<31> ipbuf; - SNPRINTF(ipbuf, 32, "%u%s", ip.s_addr, secret); + SNPRINTF(ipbuf, 32, "%s %s", ip, secret); md5_binary obuf; MD5_to_bin(MD5_from_string(ipbuf), obuf); // Fold the md5sum to 32 bits, pack the bytes to an in_addr - conv.bytes[0] = obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]; - conv.bytes[1] = obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11]; - conv.bytes[2] = obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13]; - conv.bytes[3] = obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15]; - - return conv.ip; + return IP4Address({ + static_cast<uint8_t>(obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]), + static_cast<uint8_t>(obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11]), + static_cast<uint8_t>(obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13]), + static_cast<uint8_t>(obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15]), + }); } |