mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
avutil: Add functions for allocating opaque contexts for algorithms
The current API where the plain size is exposed is not of much use - in most cases it is allocated dynamically anyway. If allocated e.g. on the stack via an uint8_t array, there's no guarantee that the struct's members are aligned properly (unless the array is overallocated and the opaque pointer within it manually aligned to some unspecified alignment). Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
fb32f31af7
commit
9a92aea27b
@ -13,6 +13,10 @@ libavutil: 2011-04-18
|
||||
|
||||
API changes, most recent first:
|
||||
|
||||
2012-10-xx - xxxxxxx - lavu 51.43.0 - aes.h, md5.h, sha.h, tree.h
|
||||
Add functions for allocating the opaque contexts for the algorithms,
|
||||
deprecate the context size variables.
|
||||
|
||||
2012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h
|
||||
Add avio_closep to complement avio_close.
|
||||
|
||||
|
@ -39,7 +39,14 @@ typedef struct AVAES {
|
||||
int rounds;
|
||||
} AVAES;
|
||||
|
||||
#if FF_API_CONTEXT_SIZE
|
||||
const int av_aes_size= sizeof(AVAES);
|
||||
#endif
|
||||
|
||||
struct AVAES *av_aes_alloc(void)
|
||||
{
|
||||
return av_mallocz(sizeof(struct AVAES));
|
||||
}
|
||||
|
||||
static const uint8_t rcon[10] = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
|
||||
|
@ -23,16 +23,26 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "version.h"
|
||||
|
||||
/**
|
||||
* @defgroup lavu_aes AES
|
||||
* @ingroup lavu_crypto
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern const int av_aes_size;
|
||||
#if FF_API_CONTEXT_SIZE
|
||||
extern attribute_deprecated const int av_aes_size;
|
||||
#endif
|
||||
|
||||
struct AVAES;
|
||||
|
||||
/**
|
||||
* Allocate an AVAES context.
|
||||
*/
|
||||
struct AVAES *av_aes_alloc(void);
|
||||
|
||||
/**
|
||||
* Initialize an AVAES context.
|
||||
* @param key_bits 128, 192 or 256
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "bswap.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "md5.h"
|
||||
#include "mem.h"
|
||||
|
||||
typedef struct AVMD5{
|
||||
uint64_t len;
|
||||
@ -41,7 +42,14 @@ typedef struct AVMD5{
|
||||
uint32_t ABCD[4];
|
||||
} AVMD5;
|
||||
|
||||
#if FF_API_CONTEXT_SIZE
|
||||
const int av_md5_size = sizeof(AVMD5);
|
||||
#endif
|
||||
|
||||
struct AVMD5 *av_md5_alloc(void)
|
||||
{
|
||||
return av_mallocz(sizeof(struct AVMD5));
|
||||
}
|
||||
|
||||
static const uint8_t S[4][4] = {
|
||||
{ 7, 12, 17, 22 }, /* round 1 */
|
||||
|
@ -23,16 +23,22 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "version.h"
|
||||
|
||||
/**
|
||||
* @defgroup lavu_md5 MD5
|
||||
* @ingroup lavu_crypto
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern const int av_md5_size;
|
||||
#if FF_API_CONTEXT_SIZE
|
||||
extern attribute_deprecated const int av_md5_size;
|
||||
#endif
|
||||
|
||||
struct AVMD5;
|
||||
|
||||
struct AVMD5 *av_md5_alloc(void);
|
||||
void av_md5_init(struct AVMD5 *ctx);
|
||||
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len);
|
||||
void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "bswap.h"
|
||||
#include "sha.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "mem.h"
|
||||
|
||||
/** hash context */
|
||||
typedef struct AVSHA {
|
||||
@ -37,7 +38,14 @@ typedef struct AVSHA {
|
||||
void (*transform)(uint32_t *state, const uint8_t buffer[64]);
|
||||
} AVSHA;
|
||||
|
||||
#if FF_API_CONTEXT_SIZE
|
||||
const int av_sha_size = sizeof(AVSHA);
|
||||
#endif
|
||||
|
||||
struct AVSHA *av_sha_alloc(void)
|
||||
{
|
||||
return av_mallocz(sizeof(struct AVSHA));
|
||||
}
|
||||
|
||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||
|
||||
|
@ -23,16 +23,26 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "version.h"
|
||||
|
||||
/**
|
||||
* @defgroup lavu_sha SHA
|
||||
* @ingroup lavu_crypto
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern const int av_sha_size;
|
||||
#if FF_API_CONTEXT_SIZE
|
||||
extern attribute_deprecated const int av_sha_size;
|
||||
#endif
|
||||
|
||||
struct AVSHA;
|
||||
|
||||
/**
|
||||
* Allocate an AVSHA context.
|
||||
*/
|
||||
struct AVSHA *av_sha_alloc(void);
|
||||
|
||||
/**
|
||||
* Initialize SHA-1 or SHA-2 hashing.
|
||||
*
|
||||
|
@ -28,7 +28,14 @@ typedef struct AVTreeNode {
|
||||
int state;
|
||||
} AVTreeNode;
|
||||
|
||||
#if FF_API_CONTEXT_SIZE
|
||||
const int av_tree_node_size = sizeof(AVTreeNode);
|
||||
#endif
|
||||
|
||||
struct AVTreeNode *av_tree_node_alloc(void)
|
||||
{
|
||||
return av_mallocz(sizeof(struct AVTreeNode));
|
||||
}
|
||||
|
||||
void *av_tree_find(const AVTreeNode *t, void *key,
|
||||
int (*cmp)(void *key, const void *b), void *next[2])
|
||||
|
@ -27,6 +27,9 @@
|
||||
#ifndef AVUTIL_TREE_H
|
||||
#define AVUTIL_TREE_H
|
||||
|
||||
#include "attributes.h"
|
||||
#include "version.h"
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_tree AVTree
|
||||
* @ingroup lavu_data
|
||||
@ -40,7 +43,14 @@
|
||||
|
||||
|
||||
struct AVTreeNode;
|
||||
extern const int av_tree_node_size;
|
||||
#if FF_API_CONTEXT_SIZE
|
||||
extern attribute_deprecated const int av_tree_node_size;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Allocate an AVTreeNode.
|
||||
*/
|
||||
struct AVTreeNode *av_tree_node_alloc(void);
|
||||
|
||||
/**
|
||||
* Find an element.
|
||||
|
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#define LIBAVUTIL_VERSION_MAJOR 51
|
||||
#define LIBAVUTIL_VERSION_MINOR 42
|
||||
#define LIBAVUTIL_VERSION_MINOR 43
|
||||
#define LIBAVUTIL_VERSION_MICRO 0
|
||||
|
||||
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
|
||||
@ -76,6 +76,9 @@
|
||||
#ifndef FF_API_PIX_FMT
|
||||
#define FF_API_PIX_FMT (LIBAVUTIL_VERSION_MAJOR < 52)
|
||||
#endif
|
||||
#ifndef FF_API_CONTEXT_SIZE
|
||||
#define FF_API_CONTEXT_SIZE (LIBAVUTIL_VERSION_MAJOR < 52)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
Loading…
x
Reference in New Issue
Block a user