From 9a92aea27bad2f5603ca85e0d0716c679a6b686c Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Thu, 11 Oct 2012 15:08:04 +0300 Subject: avutil: Add functions for allocating opaque contexts for algorithms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ö --- libavutil/sha.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libavutil/sha.c') diff --git a/libavutil/sha.c b/libavutil/sha.c index cbe1608a26..d5831915c4 100644 --- a/libavutil/sha.c +++ b/libavutil/sha.c @@ -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)))) -- cgit v1.2.3