/* -*-c-*-
*
- * $Id: unihash.h,v 1.1 2003/10/12 14:43:24 mdw Exp $
+ * $Id: unihash.h,v 1.4 2004/04/08 01:36:13 mdw Exp $
*
* Simple and efficient universal hashing for hashtables
*
* (c) 2003 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of the mLib utilities library.
*
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
- *
+ *
* mLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Library General Public
* License along with mLib; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: unihash.h,v $
- * Revision 1.1 2003/10/12 14:43:24 mdw
- * Universal hashing.
- *
- */
-
#ifndef MLIB_UNIHASH_H
#define MLIB_UNIHASH_H
* $m_{n-1}, m_{n-2}, \ldots, m_2, m_1, m_0$% in %$\gf{q}%.
* Then we compute
*
- * %$H_k(M) = k^{n+1} \sum_{0\le i<n} m_i k^{i+1}.$%
+ * %$H_k(M) = k^{n+1} + \sum_{0\le i<n} m_i k^{i+1}.$%
*
* Note that %$H_0(M) = 0$% for all messages %$M$%.
*
* computationally unbounded adversaries. Simply XOR the hash with a random
* string indexed from a large random pad by some nonce sent with the
* message. The probability of a forgery attempt being successful is then
- * %$(\ell + 1)/2^t$%, where %$t$% is the tag length and %$n$% is the longest
- * message permitted.
+ * %$(\ell + 1)/2^t$%, where %$t$% is the tag length and %$\ell$% is the
+ * longest message permitted.
*/
/*----- Practicalities ----------------------------------------------------*
*
* We work in %$\gf{2^32}$%, represented as a field of polynomials modulo
- * %$\{104c11db7}_x$% (this is the standard CRC-32 polynomial). Our blocks
- * are bytes. We append a big-endian byte length.
+ * %$\texttt{104c11db7}_x$% (this is the standard CRC-32 polynomial). Our
+ * blocks are bytes.
*
* The choice of a 32-bit hash is made for pragmatic reasons: we're never
* likely to actually want all 32 bits for a real hashtable anyway. The
uint32 s[UNIHASH_NBATCH][4][256]; /* S-tables as described */
} unihash_info;
+/*----- A global hash-info table ------------------------------------------*/
+
+extern unihash_info unihash_global; /* Key this if you like */
+
/*----- Functions provided ------------------------------------------------*/
/* --- @unihash_setkey@ --- *
* @const void *p@ = pointer to data to hash
* @size_t sz@ = size of the data
*
- * Returns: ---
+ * Returns: Hash of data so far.
*
- * Use: Hashes data. Call this as many times as needed.
+ * Use: Hashes data. Call this as many times as needed.
*/
#define UNIHASH_INIT(i) ((i)->s[0][0][1]) /* %$k$% */
* Returns: The hash value computed.
*
* Use: All-in-one hashing function. No faster than using the
- * separate calls, but more convenient.
+ * separate calls, but more convenient.
*/
#define UNIHASH(i, p, sz) (unihash_hash((i), UNIHASH_INIT((i)), (p), (sz)))