Changeset 675


Ignore:
Timestamp:
01/30/12 22:26:32 (16 months ago)
Author:
literalka
Message:

remove md5 dependency, use sam's hash instead

Location:
trollforge/lastmeasure/server
Files:
2 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trollforge/lastmeasure/server/lmutil.h

    r673 r675  
    1111#include <time.h> /* localtime_r() */ 
    1212 
    13 #include "md5.h" 
     13//#include "md5.h" 
    1414#include "lmkeywords.h" 
     15 
     16/* Jacked from http://lol.zoy.org/blog/2011/12/20/cpp-constant-string-hash */ 
     17/* max heartiez to sam */ 
     18#define H1(s,i,x)   (x*65599u+(uint8_t)s[(i)<strlen(s)?strlen(s)-1-(i):strlen(s)]) 
     19#define H4(s,i,x)   H1(s,i,H1(s,i+1,H1(s,i+2,H1(s,i+3,x)))) 
     20#define H16(s,i,x)  H4(s,i,H4(s,i+4,H4(s,i+8,H4(s,i+12,x)))) 
     21#define H64(s,i,x)  H16(s,i,H16(s,i+16,H16(s,i+32,H16(s,i+48,x)))) 
     22#define H256(s,i,x) H64(s,i,H64(s,i+64,H64(s,i+128,H64(s,i+192,x)))) 
     23 
     24#define HASH(s)    ((uint32_t)(H256(s,0,0)^(H256(s,0,0)>>16))) 
    1525 
    1626class Random 
     
    129139        char buffer[16]; 
    130140        char iphash[37]; 
    131         char hash[8]; 
     141        unsigned int hash; 
    132142 
    133143        sprintf(iphash,"%s%d",client_ip,rand()%32767); 
    134144 
    135         md5((unsigned char*)iphash,8,(unsigned char*)hash); 
     145        hash = HASH(iphash); 
    136146 
    137147        sprintf(buffer, "%lx", (0xffffffff - t)); 
    138         strcat(buffer,hash); 
     148        strcat(buffer,(char const *)hash); 
    139149 
    140150        return buffer; 
Note: See TracChangeset for help on using the changeset viewer.