Imported Debian version 2.4.3~trusty1
[deb_ffmpeg.git] / ffmpeg / libavutil / hash.h
CommitLineData
2ba45a60
DM
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
26struct 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 */
34int 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 */
44const char *av_hash_names(int i);
45
46/**
47 * Get the name of the algorithm corresponding to the given hash context.
48 */
49const 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 */
68int av_hash_get_size(const struct AVHashContext *ctx);
69
70/**
71 * Initialize or reset a hash context.
72 */
73void av_hash_init(struct AVHashContext *ctx);
74
75/**
76 * Update a hash context with additional data.
77 */
78void 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 */
83void av_hash_final(struct AVHashContext *ctx, uint8_t *dst);
84
85/**
86 * Finalize a hash context and compute the actual hash value.
87 * If size is smaller than the hash size, the hash is truncated;
88 * if size is larger, the buffer is padded with 0.
89 */
90void av_hash_final_bin(struct AVHashContext *ctx, uint8_t *dst, int size);
91
92/**
93 * Finalize a hash context and compute the actual hash value as a hex string.
94 * The string is always 0-terminated.
95 * If size is smaller than 2 * hash_size + 1, the hex string is truncated.
96 */
97void av_hash_final_hex(struct AVHashContext *ctx, uint8_t *dst, int size);
98
99/**
100 * Finalize a hash context and compute the actual hash value as a base64 string.
101 * The string is always 0-terminated.
102 * If size is smaller than AV_BASE64_SIZE(hash_size), the base64 string is
103 * truncated.
104 */
105void av_hash_final_b64(struct AVHashContext *ctx, uint8_t *dst, int size);
106
107/**
108 * Free hash context.
109 */
110void av_hash_freep(struct AVHashContext **ctx);
111
112#endif /* AVUTIL_HASH_H */