FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Enumerations | Functions | Variables
hash.c File Reference
#include <stdint.h>
#include "hash.h"
#include "adler32.h"
#include "crc.h"
#include "md5.h"
#include "murmur3.h"
#include "ripemd.h"
#include "sha.h"
#include "sha512.h"
#include "avstring.h"
#include "base64.h"
#include "error.h"
#include "intreadwrite.h"
#include "mem.h"

Go to the source code of this file.

Data Structures

struct  AVHashContext
 

Enumerations

enum  hashtype {
  MD5, MURMUR3, RIPEMD128, RIPEMD160,
  RIPEMD256, RIPEMD320, SHA160, SHA224,
  SHA256, SHA512_224, SHA512_256, SHA384,
  SHA512, CRC32, ADLER32, NUM_HASHES
}
 

Functions

const char * av_hash_names (int i)
 Get the names of available hash algorithms.
 
const char * av_hash_get_name (const AVHashContext *ctx)
 
int av_hash_get_size (const AVHashContext *ctx)
 
int av_hash_alloc (AVHashContext **ctx, const char *name)
 Allocate a hash context for the algorithm specified by name.
 
void av_hash_init (AVHashContext *ctx)
 Initialize or reset a hash context.
 
void av_hash_update (AVHashContext *ctx, const uint8_t *src, int len)
 Update a hash context with additional data.
 
void av_hash_final (AVHashContext *ctx, uint8_t *dst)
 Finalize a hash context and compute the actual hash value.
 
void av_hash_final_bin (struct AVHashContext *ctx, uint8_t *dst, int size)
 Finalize a hash context and compute the actual hash value.
 
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.
 
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.
 
void av_hash_freep (AVHashContext **ctx)
 Free hash context.
 

Variables

struct {
   const char *   name
 
   int   size
 
hashdesc []
 

Enumeration Type Documentation

enum hashtype
Enumerator:
MD5 
MURMUR3 
RIPEMD128 
RIPEMD160 
RIPEMD256 
RIPEMD320 
SHA160 
SHA224 
SHA256 
SHA512_224 
SHA512_256 
SHA384 
SHA512 
CRC32 
ADLER32 
NUM_HASHES 

Definition at line 37 of file hash.c.

Function Documentation

const char* av_hash_names ( int  i)

Get the names of available hash algorithms.

This function can be used to enumerate the algorithms.

Parameters
iindex of the hash algorithm, starting from 0
Returns
a pointer to a static string or NULL if i is out of range

Definition at line 84 of file hash.c.

Referenced by main(), and usage().

const char* av_hash_get_name ( const AVHashContext ctx)

Definition at line 90 of file hash.c.

Referenced by check(), finish(), and writer_print_data_hash().

int av_hash_get_size ( const AVHashContext ctx)

Definition at line 95 of file hash.c.

Referenced by av_hash_final_b64(), av_hash_final_bin(), av_hash_final_hex(), and md5_finish().

int av_hash_alloc ( struct AVHashContext **  ctx,
const char *  name 
)

Allocate a hash context for the algorithm specified by name.

Returns
>= 0 for success, a negative error code for failure
Note
The context is not initialized, you must call av_hash_init().

Definition at line 100 of file hash.c.

Referenced by main().

void av_hash_init ( AVHashContext ctx)

Initialize or reset a hash context.

Definition at line 137 of file hash.c.

Referenced by check(), and writer_print_data_hash().

void av_hash_update ( AVHashContext ctx,
const uint8_t src,
int  len 
)

Update a hash context with additional data.

Definition at line 158 of file hash.c.

Referenced by check(), and writer_print_data_hash().

void av_hash_final ( AVHashContext ctx,
uint8_t dst 
)

Finalize a hash context and compute the actual hash value.

Definition at line 179 of file hash.c.

Referenced by av_hash_final_b64(), av_hash_final_bin(), av_hash_final_hex(), and md5_finish().

void av_hash_final_bin ( struct AVHashContext ctx,
uint8_t dst,
int  size 
)

Finalize a hash context and compute the actual hash value.

If size is smaller than the hash size, the hash is truncated; if size is larger, the buffer is padded with 0.

Definition at line 200 of file hash.c.

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.

The string is always 0-terminated. If size is smaller than 2 * hash_size + 1, the hex string is truncated.

Definition at line 211 of file hash.c.

Referenced by finish(), and writer_print_data_hash().

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.

The string is always 0-terminated. If size is smaller than AV_BASE64_SIZE(hash_size), the base64 string is truncated.

Definition at line 221 of file hash.c.

Referenced by finish().

void av_hash_freep ( AVHashContext **  ctx)

Free hash context.

Definition at line 234 of file hash.c.

Referenced by main().

Variable Documentation

const char* name

Definition at line 64 of file hash.c.

int size

Definition at line 65 of file hash.c.

struct { ... } hashdesc[]
Initial value:
= {
[MD5] = {"MD5", 16},
[MURMUR3] = {"murmur3", 16},
[RIPEMD128] = {"RIPEMD128", 16},
[RIPEMD160] = {"RIPEMD160", 20},
[RIPEMD256] = {"RIPEMD256", 32},
[RIPEMD320] = {"RIPEMD320", 40},
[SHA160] = {"SHA160", 20},
[SHA224] = {"SHA224", 28},
[SHA256] = {"SHA256", 32},
[SHA512_224] = {"SHA512/224", 28},
[SHA512_256] = {"SHA512/256", 32},
[SHA384] = {"SHA384", 48},
[SHA512] = {"SHA512", 64},
[CRC32] = {"CRC32", 4},
[ADLER32] = {"adler32", 4},
}

Referenced by av_hash_alloc(), av_hash_get_name(), av_hash_get_size(), and av_hash_names().