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  * 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  */
90 void 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  */
97 void 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  */
105 void av_hash_final_b64(struct AVHashContext *ctx, uint8_t *dst, int size);
106 
107 /**
108  * Free hash context.
109  */
110 void av_hash_freep(struct AVHashContext **ctx);
111 
112 #endif /* AVUTIL_HASH_H */
void av_hash_final(struct AVHashContext *ctx, uint8_t *dst)
Finalize a hash context and compute the actual hash value.
Definition: hash.c:179
int av_hash_alloc(struct AVHashContext **ctx, const char *name)
Allocate a hash context for the algorithm specified by name.
Definition: hash.c:100
AVFormatContext * ctx
Definition: movenc-test.c:48
void av_hash_init(struct AVHashContext *ctx)
Initialize or reset a hash context.
Definition: hash.c:137
const char * av_hash_get_name(const struct AVHashContext *ctx)
Get the name of the algorithm corresponding to the given hash context.
uint8_t
void av_hash_freep(struct AVHashContext **ctx)
Free hash context.
Definition: hash.c:234
int av_hash_get_size(const struct AVHashContext *ctx)
Get the size of the resulting hash value in bytes.
ptrdiff_t size
Definition: opengl_enc.c:101
void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, int len)
Update a hash context with additional data.
Definition: hash.c:158
const char * av_hash_names(int i)
Get the names of available hash algorithms.
Definition: hash.c:84
void av_hash_final_bin(struct AVHashContext *ctx, uint8_t *dst, int size)
Finalize a hash context and compute the actual hash value.
Definition: hash.c:200
#define src
Definition: vp9dsp.c:530
void av_hash_final_hex(struct AVHashContext *ctx, uint8_t *dst, int size)
Finalize a hash context and compute the actual hash value as a hex string.
Definition: hash.c:211
int len
void av_hash_final_b64(struct AVHashContext *ctx, uint8_t *dst, int size)
Finalize a hash context and compute the actual hash value as a base64 string.
Definition: hash.c:221
const char * name
Definition: opengl_enc.c:103