History

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).

Martin Storsjö committed 14 years ago

Commit 9a92aea1 parent fb32f3110 files · +78 −5Browse files

Unified · Split

10 files
  1. doc/APIchanges +4 −0
  2. libavutil/aes.c +7 −0
  3. libavutil/aes.h +11 −1
  4. libavutil/md5.c +8 −0
  5. libavutil/md5.h +7 −1
  6. libavutil/sha.c +8 −0
  7. libavutil/sha.h +11 −1
  8. libavutil/tree.c +7 −0
  9. libavutil/tree.h +11 −1
  10. libavutil/version.h +4 −1
doc/APIchanges+4−0
@@ -13,6 +13,10 @@ libavutil: 2011-04-18 · 12 unmodified lines
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
162012-10-xx - xxxxxxx - lavu 51.43.0 - aes.h, md5.h, sha.h, tree.h
17 Add functions for allocating the opaque contexts for the algorithms,
18 deprecate the context size variables.
19
162012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h202012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h
17 Add avio_closep to complement avio_close.21 Add avio_closep to complement avio_close.
18 22
libavutil/aes.c+7−0
@@ -39,7 +39,14 @@ typedef struct AVAES { · 38 unmodified lines
39 int rounds;39 int rounds;
40} AVAES;40} AVAES;
41 41
42#if FF_API_CONTEXT_SIZE
42const int av_aes_size= sizeof(AVAES);43const int av_aes_size= sizeof(AVAES);
44#endif
45
46struct AVAES *av_aes_alloc(void)
47{
48 return av_mallocz(sizeof(struct AVAES));
49}
43 50
44static const uint8_t rcon[10] = {51static const uint8_t rcon[10] = {
45 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x3652 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
libavutil/aes.h+11−1
@@ -23,16 +23,26 @@ · 22 unmodified lines
23 23
24#include <stdint.h>24#include <stdint.h>
25 25
26#include "attributes.h"
27#include "version.h"
28
26/**29/**
27 * @defgroup lavu_aes AES30 * @defgroup lavu_aes AES
28 * @ingroup lavu_crypto31 * @ingroup lavu_crypto
29 * @{32 * @{
30 */33 */
31 34
32extern const int av_aes_size;35#if FF_API_CONTEXT_SIZE
36extern attribute_deprecated const int av_aes_size;
37#endif
33 38
34struct AVAES;39struct AVAES;
35 40
41/**
42 * Allocate an AVAES context.
43 */
44struct AVAES *av_aes_alloc(void);
45
36/**46/**
37 * Initialize an AVAES context.47 * Initialize an AVAES context.
38 * @param key_bits 128, 192 or 25648 * @param key_bits 128, 192 or 256
libavutil/md5.c+8−0
@@ -34,6 +34,7 @@ · 33 unmodified lines
34#include "bswap.h"34#include "bswap.h"
35#include "intreadwrite.h"35#include "intreadwrite.h"
36#include "md5.h"36#include "md5.h"
37#include "mem.h"
37 38
38typedef struct AVMD5{39typedef struct AVMD5{
39 uint64_t len;40 uint64_t len;
@@ -41,7 +42,14 @@ typedef struct AVMD5{ · 1 unmodified line
41 uint32_t ABCD[4];42 uint32_t ABCD[4];
42} AVMD5;43} AVMD5;
43 44
45#if FF_API_CONTEXT_SIZE
44const int av_md5_size = sizeof(AVMD5);46const int av_md5_size = sizeof(AVMD5);
47#endif
48
49struct AVMD5 *av_md5_alloc(void)
50{
51 return av_mallocz(sizeof(struct AVMD5));
52}
45 53
46static const uint8_t S[4][4] = {54static const uint8_t S[4][4] = {
47 { 7, 12, 17, 22 }, /* round 1 */55 { 7, 12, 17, 22 }, /* round 1 */
libavutil/md5.h+7−1
@@ -23,16 +23,22 @@ · 22 unmodified lines
23 23
24#include <stdint.h>24#include <stdint.h>
25 25
26#include "attributes.h"
27#include "version.h"
28
26/**29/**
27 * @defgroup lavu_md5 MD530 * @defgroup lavu_md5 MD5
28 * @ingroup lavu_crypto31 * @ingroup lavu_crypto
29 * @{32 * @{
30 */33 */
31 34
32extern const int av_md5_size;35#if FF_API_CONTEXT_SIZE
36extern attribute_deprecated const int av_md5_size;
37#endif
33 38
34struct AVMD5;39struct AVMD5;
35 40
41struct AVMD5 *av_md5_alloc(void);
36void av_md5_init(struct AVMD5 *ctx);42void av_md5_init(struct AVMD5 *ctx);
37void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len);43void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len);
38void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);44void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
libavutil/sha.c+8−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
26#include "bswap.h"26#include "bswap.h"
27#include "sha.h"27#include "sha.h"
28#include "intreadwrite.h"28#include "intreadwrite.h"
29#include "mem.h"
29 30
30/** hash context */31/** hash context */
31typedef struct AVSHA {32typedef struct AVSHA {
@@ -37,7 +38,14 @@ typedef struct AVSHA { · 5 unmodified lines
37 void (*transform)(uint32_t *state, const uint8_t buffer[64]);38 void (*transform)(uint32_t *state, const uint8_t buffer[64]);
38} AVSHA;39} AVSHA;
39 40
41#if FF_API_CONTEXT_SIZE
40const int av_sha_size = sizeof(AVSHA);42const int av_sha_size = sizeof(AVSHA);
43#endif
44
45struct AVSHA *av_sha_alloc(void)
46{
47 return av_mallocz(sizeof(struct AVSHA));
48}
41 49
42#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))50#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
43 51
libavutil/sha.h+11−1
@@ -23,16 +23,26 @@ · 22 unmodified lines
23 23
24#include <stdint.h>24#include <stdint.h>
25 25
26#include "attributes.h"
27#include "version.h"
28
26/**29/**
27 * @defgroup lavu_sha SHA30 * @defgroup lavu_sha SHA
28 * @ingroup lavu_crypto31 * @ingroup lavu_crypto
29 * @{32 * @{
30 */33 */
31 34
32extern const int av_sha_size;35#if FF_API_CONTEXT_SIZE
36extern attribute_deprecated const int av_sha_size;
37#endif
33 38
34struct AVSHA;39struct AVSHA;
35 40
41/**
42 * Allocate an AVSHA context.
43 */
44struct AVSHA *av_sha_alloc(void);
45
36/**46/**
37 * Initialize SHA-1 or SHA-2 hashing.47 * Initialize SHA-1 or SHA-2 hashing.
38 *48 *
libavutil/tree.c+7−0
@@ -28,7 +28,14 @@ typedef struct AVTreeNode { · 27 unmodified lines
28 int state;28 int state;
29} AVTreeNode;29} AVTreeNode;
30 30
31#if FF_API_CONTEXT_SIZE
31const int av_tree_node_size = sizeof(AVTreeNode);32const int av_tree_node_size = sizeof(AVTreeNode);
33#endif
34
35struct AVTreeNode *av_tree_node_alloc(void)
36{
37 return av_mallocz(sizeof(struct AVTreeNode));
38}
32 39
33void *av_tree_find(const AVTreeNode *t, void *key,40void *av_tree_find(const AVTreeNode *t, void *key,
34 int (*cmp)(void *key, const void *b), void *next[2])41 int (*cmp)(void *key, const void *b), void *next[2])
libavutil/tree.h+11−1
@@ -27,6 +27,9 @@ · 26 unmodified lines
27#ifndef AVUTIL_TREE_H27#ifndef AVUTIL_TREE_H
28#define AVUTIL_TREE_H28#define AVUTIL_TREE_H
29 29
30#include "attributes.h"
31#include "version.h"
32
30/**33/**
31 * @addtogroup lavu_tree AVTree34 * @addtogroup lavu_tree AVTree
32 * @ingroup lavu_data35 * @ingroup lavu_data
@@ -40,7 +43,14 @@ · 7 unmodified lines
40 43
41 44
42struct AVTreeNode;45struct AVTreeNode;
43extern const int av_tree_node_size;46#if FF_API_CONTEXT_SIZE
47extern attribute_deprecated const int av_tree_node_size;
48#endif
49
50/**
51 * Allocate an AVTreeNode.
52 */
53struct AVTreeNode *av_tree_node_alloc(void);
44 54
45/**55/**
46 * Find an element.56 * Find an element.
libavutil/version.h+4−1
@@ -37,7 +37,7 @@ · 36 unmodified lines
37 */37 */
38 38
39#define LIBAVUTIL_VERSION_MAJOR 5139#define LIBAVUTIL_VERSION_MAJOR 51
40#define LIBAVUTIL_VERSION_MINOR 4240#define LIBAVUTIL_VERSION_MINOR 43
41#define LIBAVUTIL_VERSION_MICRO 041#define LIBAVUTIL_VERSION_MICRO 0
42 42
43#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \43#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@@ -76,6 +76,9 @@ · 32 unmodified lines
76#ifndef FF_API_PIX_FMT76#ifndef FF_API_PIX_FMT
77#define FF_API_PIX_FMT (LIBAVUTIL_VERSION_MAJOR < 52)77#define FF_API_PIX_FMT (LIBAVUTIL_VERSION_MAJOR < 52)
78#endif78#endif
79#ifndef FF_API_CONTEXT_SIZE
80#define FF_API_CONTEXT_SIZE (LIBAVUTIL_VERSION_MAJOR < 52)
81#endif
79 82
80/**83/**
81 * @}84 * @}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t