1 /* 2 * Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de> 3 * 4 * This file is part of FFmpeg. 5 * 6 * FFmpeg is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * FFmpeg 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 GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with FFmpeg; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 /** 22 * @file 23 * @ingroup lavu_murmur3 24 * Public header for MurmurHash3 hash function implementation. 25 */ 26 27 #ifndef AVUTIL_MURMUR3_H 28 #define AVUTIL_MURMUR3_H 29 30 #include <stdint.h> 31 32 #include "version.h" 33 34 /** 35 * @defgroup lavu_murmur3 Murmur3 36 * @ingroup lavu_hash 37 * MurmurHash3 hash function implementation. 38 * 39 * MurmurHash3 is a non-cryptographic hash function, of which three 40 * incompatible versions were created by its inventor Austin Appleby: 41 * 42 * - 32-bit output 43 * - 128-bit output for 32-bit platforms 44 * - 128-bit output for 64-bit platforms 45 * 46 * FFmpeg only implements the last variant: 128-bit output designed for 64-bit 47 * platforms. Even though the hash function was designed for 64-bit platforms, 48 * the function in reality works on 32-bit systems too, only with reduced 49 * performance. 50 * 51 * @anchor lavu_murmur3_seedinfo 52 * By design, MurmurHash3 requires a seed to operate. In response to this, 53 * libavutil provides two functions for hash initiation, one that requires a 54 * seed (av_murmur3_init_seeded()) and one that uses a fixed arbitrary integer 55 * as the seed, and therefore does not (av_murmur3_init()). 56 * 57 * To make hashes comparable, you should provide the same seed for all calls to 58 * this hash function -- if you are supplying one yourself, that is. 59 * 60 * @{ 61 */ 62 63 /** 64 * Allocate an AVMurMur3 hash context. 65 * 66 * @return Uninitialized hash context or `NULL` in case of error 67 */ 68 struct AVMurMur3 *av_murmur3_alloc(void); 69 70 /** 71 * Initialize or reinitialize an AVMurMur3 hash context with a seed. 72 * 73 * @param[out] c Hash context 74 * @param[in] seed Random seed 75 * 76 * @see av_murmur3_init() 77 * @see @ref lavu_murmur3_seedinfo "Detailed description" on a discussion of 78 * seeds for MurmurHash3. 79 */ 80 void av_murmur3_init_seeded(struct AVMurMur3 *c, uint64_t seed); 81 82 /** 83 * Initialize or reinitialize an AVMurMur3 hash context. 84 * 85 * Equivalent to av_murmur3_init_seeded() with a built-in seed. 86 * 87 * @param[out] c Hash context 88 * 89 * @see av_murmur3_init_seeded() 90 * @see @ref lavu_murmur3_seedinfo "Detailed description" on a discussion of 91 * seeds for MurmurHash3. 92 */ 93 void av_murmur3_init(struct AVMurMur3 *c); 94 95 /** 96 * Update hash context with new data. 97 * 98 * @param[out] c Hash context 99 * @param[in] src Input data to update hash with 100 * @param[in] len Number of bytes to read from `src` 101 */ 102 #if FF_API_CRYPTO_SIZE_T 103 void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, int len); 104 #else 105 void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, size_t len); 106 #endif 107 108 /** 109 * Finish hashing and output digest value. 110 * 111 * @param[in,out] c Hash context 112 * @param[out] dst Buffer where output digest value is stored 113 */ 114 void av_murmur3_final(struct AVMurMur3 *c, uint8_t dst[16]); 115 116 /** 117 * @} 118 */ 119 120 #endif /* AVUTIL_MURMUR3_H */ 121