libgpac
Documentation of the core library of GPAC
Hash and Compression

Data hashing, integrity and generic compression. More...

+ Collaboration diagram for Hash and Compression:

Macros

#define GF_SHA1_DIGEST_SIZE   20
 

Typedefs

typedef struct __sha1_context GF_SHA1Context
 

Functions

u32 gf_crc_32 (const u8 *data, u32 size)
 CRC32 compute. More...
 
GF_Err gf_gz_compress_payload (u8 **data, u32 data_len, u32 *out_size)
 
GF_Err gf_gz_compress_payload_ex (u8 **data, u32 data_len, u32 *out_size, u8 data_offset, Bool skip_if_larger, u8 **out_comp_data, Bool use_gz)
 
GF_Err gf_gz_decompress_payload (u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size)
 
GF_Err gf_gz_decompress_payload_ex (u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size, Bool use_gz)
 
GF_Err gf_lz_compress_payload (u8 **data, u32 data_len, u32 *out_size)
 
GF_Err gf_lz_decompress_payload (u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size)
 
u64 gf_gzseek (void *file, u64 offset, int whence)
 
u64 gf_gztell (void *file)
 
s64 gf_gzrewind (void *file)
 
int gf_gzeof (void *file)
 
int gf_gzclose (void *file)
 
const char * gf_gzerror (void *file, int *errnum)
 
void gf_gzclearerr (void *file)
 
void * gf_gzopen (const char *path, const char *mode)
 
int gf_gzread (void *file, void *buf, unsigned len)
 
int gf_gzdirect (void *file)
 
int gf_gzgetc (void *file)
 
char * gf_gzgets (void *file, char *buf, int len)
 
GF_SHA1Contextgf_sha1_starts ()
 
void gf_sha1_update (GF_SHA1Context *ctx, u8 *input, u32 length)
 
void gf_sha1_finish (GF_SHA1Context *ctx, u8 digest[GF_SHA1_DIGEST_SIZE])
 
GF_Err gf_sha1_file (const char *filename, u8 digest[GF_SHA1_DIGEST_SIZE])
 
GF_Err gf_sha1_file_ptr (FILE *file, u8 digest[GF_SHA1_DIGEST_SIZE])
 
void gf_sha1_csum (u8 *buf, u32 buflen, u8 digest[GF_SHA1_DIGEST_SIZE])
 

Detailed Description

This section documents misc data functions such as integrity and parsing such as SHA-1 hashing CRC checksum, 128 bit ID parsing...

Macro Definition Documentation

◆ GF_SHA1_DIGEST_SIZE

#define GF_SHA1_DIGEST_SIZE   20

SHA1 message size

Typedef Documentation

◆ GF_SHA1Context

typedef struct __sha1_context GF_SHA1Context

SHA1 context

Function Documentation

◆ gf_crc_32()

u32 gf_crc_32 ( const u8 data,
u32  size 
)

Computes the CRC32 value of a buffer.

Parameters
databuffer
sizebuffer size
Returns
computed CRC32

◆ gf_gz_compress_payload()

GF_Err gf_gz_compress_payload ( u8 **  data,
u32  data_len,
u32 out_size 
)

Compresses a data buffer in place using zlib/deflate. Buffer may be reallocated in the process.

Parameters
datapointer to the data buffer to be compressed
data_lenlength of the data buffer to be compressed
out_sizepointer for output buffer size
Returns
error if any

◆ gf_gz_compress_payload_ex()

GF_Err gf_gz_compress_payload_ex ( u8 **  data,
u32  data_len,
u32 out_size,
u8  data_offset,
Bool  skip_if_larger,
u8 **  out_comp_data,
Bool  use_gz 
)

Compresses a data buffer in place using zlib/deflate. Buffer may be reallocated in the process.

Parameters
datapointer to the data buffer to be compressed
data_lenlength of the data buffer to be compressed
out_sizepointer for output buffer size
data_offsetoffset in source buffer - the input payload size is data_len - data_offset
skip_if_largerif GF_TRUE, will not override source buffer if compressed version is larger than input data
out_comp_dataif not NULL, the compressed result is set in this pointer rather than doing inplace compression
use_gzif true, GZ header is present
Returns
error if any

◆ gf_gz_decompress_payload()

GF_Err gf_gz_decompress_payload ( u8 data,
u32  data_len,
u8 **  uncompressed_data,
u32 out_size 
)

Decompresses a data buffer using zlib/inflate.

Parameters
datadata buffer to be decompressed
data_lenlength of the data buffer to be decompressed
uncompressed_datapointer to the uncompressed data buffer. The resulting buffer is NULL-terminated. It is the responsibility of the caller to free this buffer.
out_sizesize of the uncompressed buffer
Returns
error if any

◆ gf_gz_decompress_payload_ex()

GF_Err gf_gz_decompress_payload_ex ( u8 data,
u32  data_len,
u8 **  uncompressed_data,
u32 out_size,
Bool  use_gz 
)

Decompresses a data buffer using zlib/inflate.

Parameters
datadata buffer to be decompressed
data_lenlength of the data buffer to be decompressed
uncompressed_datapointer to the uncompressed data buffer. The resulting buffer is NULL-terminated. It is the responsibility of the caller to free this buffer.
out_sizesize of the uncompressed buffer
use_gzif true, gz header is present
Returns
error if any

◆ gf_lz_compress_payload()

GF_Err gf_lz_compress_payload ( u8 **  data,
u32  data_len,
u32 out_size 
)

Compresses a data buffer in place using LZMA. Buffer may be reallocated in the process.

Parameters
datapointer to the data buffer to be compressed
data_lenlength of the data buffer to be compressed
out_sizepointer for output buffer size
Returns
error if any

◆ gf_lz_decompress_payload()

GF_Err gf_lz_decompress_payload ( u8 data,
u32  data_len,
u8 **  uncompressed_data,
u32 out_size 
)

Decompresses a data buffer using LZMA.

Parameters
datadata buffer to be decompressed
data_lenlength of the data buffer to be decompressed
uncompressed_datapointer to the uncompressed data buffer. It is the responsibility of the caller to free this buffer.
out_sizesize of the uncompressed buffer
Returns
error if any

◆ gf_gzseek()

u64 gf_gzseek ( void *  file,
u64  offset,
int  whence 
)

Wrapper around gzseek, same parameters

Parameters
filetarget gzfile
offsetoffset in file
whencesame as gzseek
Returns
same as gzseek

◆ gf_gztell()

u64 gf_gztell ( void *  file)

Wrapper around gf_gztell, same parameters

Parameters
filetarget gzfile
Returns
postion in file

◆ gf_gzrewind()

s64 gf_gzrewind ( void *  file)

Wrapper around gzrewind, same parameters

Parameters
filetarget gzfile
Returns
same as gzrewind

◆ gf_gzeof()

int gf_gzeof ( void *  file)

Wrapper around gzeof, same parameters

Parameters
filetarget gzfile
Returns
same as gzeof

◆ gf_gzclose()

int gf_gzclose ( void *  file)

Wrapper around gzclose, same parameters

Parameters
filetarget gzfile
Returns
same as gzclose

◆ gf_gzerror()

const char* gf_gzerror ( void *  file,
int *  errnum 
)

Wrapper around gzerror, same parameters

Parameters
filetarget gzfile
errnumsame as gzerror
Returns
same as gzerror

◆ gf_gzclearerr()

void gf_gzclearerr ( void *  file)

Wrapper around gzclearerr, same parameters

Parameters
filetarget gzfile

◆ gf_gzopen()

void* gf_gzopen ( const char *  path,
const char *  mode 
)

Wrapper around gzopen, same parameters

Parameters
paththe file name to open
modethe file open mode
Returns
open file

◆ gf_gzread()

int gf_gzread ( void *  file,
void *  buf,
unsigned  len 
)

Wrapper around gzread, same parameters

Parameters
filetarget gzfile
bufsame as gzread
lensame as gzread
Returns
same as gzread

◆ gf_gzdirect()

int gf_gzdirect ( void *  file)

Wrapper around gzdirect, same parameters

Parameters
filetarget gzfile
Returns
same as gzdirect

◆ gf_gzgetc()

int gf_gzgetc ( void *  file)

Wrapper around gzgetc, same parameters

Parameters
filetarget gzfile
Returns
same as gzgetc

◆ gf_gzgets()

char* gf_gzgets ( void *  file,
char *  buf,
int  len 
)

Wrapper around gzgets, same parameters

Parameters
filetarget gzfile
bufsame as gzread
lensame as gzread
Returns
same as gzgets

◆ gf_sha1_starts()

GF_SHA1Context* gf_sha1_starts ( )

create SHA-1 context

Returns
the SHA1 context

◆ gf_sha1_update()

void gf_sha1_update ( GF_SHA1Context ctx,
u8 input,
u32  length 
)

adds byte to the SHA-1 context

Parameters
ctxthe target SHA1 context
inputdata to hash
lengthsize of data in bytes

◆ gf_sha1_finish()

void gf_sha1_finish ( GF_SHA1Context ctx,
u8  digest[GF_SHA1_DIGEST_SIZE] 
)

generates SHA-1 of all bytes ingested

Parameters
ctxthe target SHA1 context
digestbuffer to store message digest

◆ gf_sha1_file()

GF_Err gf_sha1_file ( const char *  filename,
u8  digest[GF_SHA1_DIGEST_SIZE] 
)

gets SHA1 message digest of a file

Parameters
filenamename of file to hash
digestbuffer to store message digest
Returns
error if any

◆ gf_sha1_file_ptr()

GF_Err gf_sha1_file_ptr ( FILE *  file,
u8  digest[GF_SHA1_DIGEST_SIZE] 
)

gets SHA1 message digest of a opened file

Parameters
filehandle to open file
digestbuffer to store message digest
Returns
error if any

◆ gf_sha1_csum()

void gf_sha1_csum ( u8 buf,
u32  buflen,
u8  digest[GF_SHA1_DIGEST_SIZE] 
)

gets SHA-1 of input buffer

Parameters
bufinput buffer to hash
buflensize of input buffer in bytes
digestbuffer to store message digest