FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hash.h
Go to the documentation of this file.
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 #ifndef AVUTIL_HASH_H
22 #define AVUTIL_HASH_H
23 
24 #include <stdint.h>
25 
26 struct AVHashContext;
27 
28 /**
29  * Allocate a hash context for the algorithm specified by name.
30  *
31  * @return >= 0 for success, a negative error code for failure
32  * @note The context is not initialized, you must call av_hash_init().
33  */
34 int av_hash_alloc(struct AVHashContext **ctx, const char *name);
35 
36 /**
37  * Get the names of available hash algorithms.
38  *
39  * This function can be used to enumerate the algorithms.
40  *
41  * @param i index of the hash algorithm, starting from 0
42  * @return a pointer to a static string or NULL if i is out of range
43  */
44 const char *av_hash_names(int i);
45 
46 /**
47  * Get the name of the algorithm corresponding to the given hash context.
48  */
49 const char *av_hash_get_name(const struct AVHashContext *ctx);
50 
51 /**
52  * Maximum value that av_hash_get_size will currently return.
53  *
54  * You can use this if you absolutely want or need to use static allocation
55  * and are fine with not supporting hashes newly added to libavutil without
56  * recompilation.
57  * Note that you still need to check against av_hash_get_size, adding new hashes
58  * with larger sizes will not be considered an ABI change and should not cause
59  * your code to overflow a buffer.
60  */
61 #define AV_HASH_MAX_SIZE 64
62 
63 /**
64  * Get the size of the resulting hash value in bytes.
65  *
66  * The pointer passed to av_hash_final have space for at least this many bytes.
67  */
68 int av_hash_get_size(const struct AVHashContext *ctx);
69 
70 /**
71  * Initialize or reset a hash context.
72  */
73 void av_hash_init(struct AVHashContext *ctx);
74 
75 /**
76  * Update a hash context with additional data.
77  */
78 void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, int len);
79 
80 /**
81  * Finalize a hash context and compute the actual hash value.
82  */
83 void av_hash_final(struct AVHashContext *ctx, uint8_t *dst);
84 
85 /**
86  * Free hash context.
87  */
88 void av_hash_freep(struct AVHashContext **ctx);
89 
90 #endif /* AVUTIL_HASH_H */