"Fossies" - the Fresh Open Source Software Archive

Member "ftwin-master/src/checksum.h" (15 Feb 2015, 1769 Bytes) of package /linux/privat/ftwin-master.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #ifndef CHECKSUM_H
    2 #define CHECKSUM_H
    3 
    4 #include <apr.h>        /* define apr_uint32_t */
    5 
    6 typedef unsigned char ub1;
    7 
    8 #define HASHSTATE 8
    9 
   10 /*
   11 --------------------------------------------------------------------
   12 hash() -- hash a variable-length key into a 256-bit value
   13   k     : the key (the unaligned variable-length array of bytes)
   14   len   : the length of the key, counting by bytes
   15   state : an array of HASHSTATE 4-byte values (256 bits)
   16 The state is the checksum.  Every bit of the key affects every bit of
   17 the state.  There are no funnels.  About 112+6.875len instructions.
   18 
   19 If you are hashing n strings (ub1 **)k, do it like this:
   20   for (i=0; i<8; ++i) state[i] = 0x9e3779b9;
   21   for (i=0, h=0; i<n; ++i) hash( k[i], len[i], state);
   22 
   23 (c) Bob Jenkins, 1996.  bob_jenkins@burtleburtle.net.  You may use this
   24 code any way you wish, private, educational, or commercial, as long
   25 as this whole comment accompanies it.
   26 
   27 See http://burtleburtle.net/bob/hash/evahash.html
   28 Use to detect changes between revisions of documents, assuming nobody
   29 is trying to cause collisions.  Do NOT use for cryptography.
   30 --------------------------------------------------------------------
   31 */
   32 void hash(register ub1 * k, register apr_uint32_t len, register apr_uint32_t *state);
   33 
   34 /*
   35 --------------------------------------------------------------------
   36  This works on all machines, is identical to hash() on little-endian 
   37  machines, and it is much faster than hash(), but it requires
   38  -- that buffers be aligned, that is, ASSERT(((apr_uint32_t)k)&3 == 0), and
   39  -- that all your machines have the same endianness.
   40 --------------------------------------------------------------------
   41 */
   42 void hash2(register ub1 * k, register apr_uint32_t len, register apr_uint32_t *state);
   43 
   44 #endif /* CHECKSUM_H */