1 /**************************************************************************** 2 * 3 * Copyright (C) 2003-2009 Sourcefire, Inc. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License Version 2 as 7 * published by the Free Software Foundation. You may not use, modify or 8 * distribute this program under any other version of the GNU General 9 * Public License. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 * 20 ****************************************************************************/ 21 22 /* 23 sfhashfcn.h 24 */ 25 #ifndef SFHASHFCN_INCLUDE 26 #define SFHASHFCN_INCLUDE 27 28 #include <stdlib.h> 29 #include <string.h> 30 #include <stdio.h> 31 #include <time.h> 32 33 #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) 34 35 #define mix(a,b,c) \ 36 { \ 37 a -= c; a ^= rot(c, 4); c += b; \ 38 b -= a; b ^= rot(a, 6); a += c; \ 39 c -= b; c ^= rot(b, 8); b += a; \ 40 a -= c; a ^= rot(c,16); c += b; \ 41 b -= a; b ^= rot(a,19); a += c; \ 42 c -= b; c ^= rot(b, 4); b += a; \ 43 } 44 45 #define final(a,b,c) \ 46 { \ 47 c ^= b; c -= rot(b,14); \ 48 a ^= c; a -= rot(c,11); \ 49 b ^= a; b -= rot(a,25); \ 50 c ^= b; c -= rot(b,16); \ 51 a ^= c; a -= rot(c,4); \ 52 b ^= a; b -= rot(a,14); \ 53 c ^= b; c -= rot(b,24); \ 54 } 55 56 typedef struct _SFHASHFCN { 57 58 unsigned seed; 59 unsigned scale; 60 unsigned hardener; 61 unsigned (*hash_fcn)(struct _SFHASHFCN * p, 62 unsigned char *d, 63 int n ); 64 int (*keycmp_fcn)( const void *s1, 65 const void *s2, 66 size_t n); 67 } SFHASHFCN; 68 69 SFHASHFCN * sfhashfcn_new( int nrows ); 70 void sfhashfcn_free( SFHASHFCN * p ); 71 void sfhashfcn_static( SFHASHFCN * p ); 72 73 unsigned sfhashfcn_hash( SFHASHFCN * p, unsigned char *d, int n ); 74 75 int sfhashfcn_set_keyops( SFHASHFCN * p, 76 unsigned (*hash_fcn)( SFHASHFCN * p, 77 unsigned char *d, 78 int n), 79 int (*keycmp_fcn)( const void *s1, 80 const void *s2, 81 size_t n)); 82 83 84 85 #endif 86