2 * Copyright (C) 2007 Thomas Vander Stichele <thomas at apestaart dot org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
28 /* This file implements FNV-1 hashing used in the Ogg payload encoders
29 * to generate the 24-bit ident value based on the header pages.
30 * See http://isthe.com/chongo/tech/comp/fnv/
33 #define MASK_24 (((guint32) 1 << 24) -1)
35 #define FNV1_HASH_32_INIT ((guint32) 0x811C9DC5L)
37 #define FNV1_HASH_32_PRIME 16777619
40 fnv1_hash_32_new (void)
42 return FNV1_HASH_32_INIT;
46 fnv1_hash_32_update (guint32 hash, const guchar * data, guint length)
49 const guchar *p = data;
51 for (i = 0; i < length; ++i, ++p) {
52 hash *= FNV1_HASH_32_PRIME;
60 fnv1_hash_32_to_24 (guint32 hash)
62 return (hash >> 24) ^ (hash & MASK_24);