?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "mhmt-types.h"
  5. #include "mhmt-hash.h"
  6.  
  7. // allocate mem for hash (length) and build it from data
  8. // length must be at least 3 bytes, since hash[0] and hash[1] are not valid hashes
  9. UBYTE * build_hash(UBYTE * data, ULONG length, ULONG prebin_len)
  10. {
  11.         UBYTE * hash;
  12.  
  13.         ULONG i; UBYTE *src,*dst;
  14.         UBYTE curr,prev,prev2;
  15.  
  16.         if( !length )
  17.                 return NULL;
  18.  
  19.         hash=(UBYTE *)malloc( length+prebin_len );
  20.         if( !hash )
  21.                 return NULL;
  22.  
  23.  
  24.         prev=curr=0;
  25.         i=length+prebin_len;
  26.         src = data-prebin_len;
  27.         dst = hash;
  28.  
  29.         do
  30.         {
  31.                 prev2 = (UBYTE)( (prev>>1) | (prev<<7) );
  32.                 prev  = (UBYTE)( (curr>>1) | (curr<<7) );
  33.                 curr  = *(src++);
  34.  
  35.                 *(dst++) = curr^prev^prev2;
  36.  
  37.         } while( --i );
  38.  
  39.  
  40.  
  41.         return hash+prebin_len; // negative indices must be used to access prebin hashes
  42. }
  43.  
  44.  
  45.  
  46. // free hash
  47. void destroy_hash(UBYTE * hash, ULONG prebin_len)
  48. {
  49.         if( hash ) free(hash-prebin_len);
  50. }
  51.  
  52.