avutil: Switch crypto APIs to size_t

Announced in e435beb1ea.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2021-03-06 21:56:20 +01:00 committed by James Almer
parent 6e30b35b85
commit a240097ecd
17 changed files with 40 additions and 103 deletions

View File

@ -41,12 +41,7 @@
#define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf); #define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);
#define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf); #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
#if FF_API_CRYPTO_SIZE_T
unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf,
unsigned int len)
#else
AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len) AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len)
#endif
{ {
unsigned long s1 = adler & 0xffff; unsigned long s1 = adler & 0xffff;
unsigned long s2 = adler >> 16; unsigned long s2 = adler >> 16;

View File

@ -30,7 +30,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "attributes.h" #include "attributes.h"
#include "version.h"
/** /**
* @defgroup lavu_adler32 Adler-32 * @defgroup lavu_adler32 Adler-32
@ -40,11 +39,7 @@
* @{ * @{
*/ */
#if FF_API_CRYPTO_SIZE_T
typedef unsigned long AVAdler;
#else
typedef uint32_t AVAdler; typedef uint32_t AVAdler;
#endif
/** /**
* Calculate the Adler32 checksum of a buffer. * Calculate the Adler32 checksum of a buffer.
@ -59,11 +54,7 @@ typedef uint32_t AVAdler;
* @return updated checksum * @return updated checksum
*/ */
AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf,
#if FF_API_CRYPTO_SIZE_T
unsigned int len) av_pure;
#else
size_t len) av_pure; size_t len) av_pure;
#endif
/** /**
* @} * @}

View File

@ -157,11 +157,7 @@ void av_hash_init(AVHashContext *ctx)
} }
} }
#if FF_API_CRYPTO_SIZE_T
void av_hash_update(AVHashContext *ctx, const uint8_t *src, int len)
#else
void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len) void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len)
#endif
{ {
switch (ctx->type) { switch (ctx->type) {
case MD5: av_md5_update(ctx->ctx, src, len); break; case MD5: av_md5_update(ctx->ctx, src, len); break;

View File

@ -182,11 +182,7 @@ void av_hash_init(struct AVHashContext *ctx);
* @param[in] src Data to be added to the hash context * @param[in] src Data to be added to the hash context
* @param[in] len Size of the additional data * @param[in] len Size of the additional data
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, int len);
#else
void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, size_t len); void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, size_t len);
#endif
/** /**
* Finalize a hash context and compute the actual hash value. * Finalize a hash context and compute the actual hash value.

View File

@ -34,11 +34,7 @@
#define MAX_BLOCKLEN 128 #define MAX_BLOCKLEN 128
typedef void (*hmac_final)(void *ctx, uint8_t *dst); typedef void (*hmac_final)(void *ctx, uint8_t *dst);
#if FF_API_CRYPTO_SIZE_T
typedef void (*hmac_update)(void *ctx, const uint8_t *src, int len);
#else
typedef void (*hmac_update)(void *ctx, const uint8_t *src, size_t len); typedef void (*hmac_update)(void *ctx, const uint8_t *src, size_t len);
#endif
typedef void (*hmac_init)(void *ctx); typedef void (*hmac_init)(void *ctx);
struct AVHMAC { struct AVHMAC {

View File

@ -98,14 +98,13 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
a = b + (a << t | a >> (32 - t)); \ a = b + (a << t | a >> (32 - t)); \
} while (0) } while (0)
static void body(uint32_t ABCD[4], const uint8_t *src, int nblocks) static void body(uint32_t ABCD[4], const uint8_t *src, size_t nblocks)
{ {
int i av_unused; int i av_unused;
int n;
const uint32_t *X; const uint32_t *X;
uint32_t a, b, c, d, t; uint32_t a, b, c, d, t;
for (n = 0; n < nblocks; n++) { for (size_t n = 0; n < nblocks; n++) {
a = ABCD[3]; a = ABCD[3];
b = ABCD[2]; b = ABCD[2];
c = ABCD[1]; c = ABCD[1];
@ -150,11 +149,7 @@ void av_md5_init(AVMD5 *ctx)
ctx->ABCD[3] = 0x67452301; ctx->ABCD[3] = 0x67452301;
} }
#if FF_API_CRYPTO_SIZE_T
void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
#else
void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len) void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len)
#endif
{ {
const uint8_t *end; const uint8_t *end;
int j; int j;
@ -180,7 +175,7 @@ void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len)
src += 64; src += 64;
} }
} else { } else {
int nblocks = len / 64; size_t nblocks = len / 64;
body(ctx->ABCD, src, nblocks); body(ctx->ABCD, src, nblocks);
src = end; src = end;
} }
@ -204,11 +199,7 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst)
AV_WL32(dst + 4 * i, ctx->ABCD[3 - i]); AV_WL32(dst + 4 * i, ctx->ABCD[3 - i]);
} }
#if FF_API_CRYPTO_SIZE_T
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
#else
void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len) void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len)
#endif
{ {
AVMD5 ctx; AVMD5 ctx;

View File

@ -64,11 +64,7 @@ void av_md5_init(struct AVMD5 *ctx);
* @param src input data to update hash with * @param src input data to update hash with
* @param len input data length * @param len input data length
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len);
#else
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, size_t len); void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.
@ -85,11 +81,7 @@ void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
* @param src The data to hash * @param src The data to hash
* @param len The length of the data, in bytes * @param len The length of the data, in bytes
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
#else
void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len); void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len);
#endif
/** /**
* @} * @}

View File

@ -91,11 +91,7 @@ static inline uint64_t update_h2(uint64_t k, uint64_t h1, uint64_t h2)
return k; return k;
} }
#if FF_API_CRYPTO_SIZE_T
void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, int len)
#else
void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, size_t len) void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, size_t len)
#endif
{ {
const uint8_t *end; const uint8_t *end;
uint64_t h1 = c->h1, h2 = c->h2; uint64_t h1 = c->h1, h2 = c->h2;

View File

@ -100,11 +100,7 @@ void av_murmur3_init(struct AVMurMur3 *c);
* @param[in] src Input data to update hash with * @param[in] src Input data to update hash with
* @param[in] len Number of bytes to read from `src` * @param[in] len Number of bytes to read from `src`
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, int len);
#else
void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, size_t len); void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.

View File

@ -511,13 +511,10 @@ av_cold int av_ripemd_init(AVRIPEMD *ctx, int bits)
return 0; return 0;
} }
#if FF_API_CRYPTO_SIZE_T
void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, unsigned int len)
#else
void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len) void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len)
#endif
{ {
unsigned int i, j; unsigned int j;
size_t i;
j = ctx->count & 63; j = ctx->count & 63;
ctx->count += len; ctx->count += len;
@ -530,15 +527,19 @@ void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len)
} }
} }
#else #else
if ((j + len) > 63) { if (len >= 64 - j) {
const uint8_t *end;
memcpy(&ctx->buffer[j], data, (i = 64 - j)); memcpy(&ctx->buffer[j], data, (i = 64 - j));
ctx->transform(ctx->state, ctx->buffer); ctx->transform(ctx->state, ctx->buffer);
for (; i + 63 < len; i += 64) data += i;
ctx->transform(ctx->state, &data[i]); len -= i;
end = data + (len & ~63);
len = len % 64;
for (; data < end; data += 64)
ctx->transform(ctx->state, data);
j = 0; j = 0;
} else }
i = 0; memcpy(&ctx->buffer[j], data, len);
memcpy(&ctx->buffer[j], &data[i], len - i);
#endif #endif
} }

View File

@ -67,11 +67,7 @@ int av_ripemd_init(struct AVRIPEMD* context, int bits);
* @param data input data to update hash with * @param data input data to update hash with
* @param len input data length * @param len input data length
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, unsigned int len);
#else
void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, size_t len); void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.

View File

@ -311,13 +311,10 @@ av_cold int av_sha_init(AVSHA *ctx, int bits)
return 0; return 0;
} }
#if FF_API_CRYPTO_SIZE_T
void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len)
#else
void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len) void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len)
#endif
{ {
unsigned int i, j; unsigned int j;
size_t i;
j = ctx->count & 63; j = ctx->count & 63;
ctx->count += len; ctx->count += len;
@ -330,15 +327,19 @@ void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len)
} }
} }
#else #else
if ((j + len) > 63) { if (len >= 64 - j) {
const uint8_t *end;
memcpy(&ctx->buffer[j], data, (i = 64 - j)); memcpy(&ctx->buffer[j], data, (i = 64 - j));
ctx->transform(ctx->state, ctx->buffer); ctx->transform(ctx->state, ctx->buffer);
for (; i + 63 < len; i += 64) data += i;
ctx->transform(ctx->state, &data[i]); len -= i;
end = data + (len & ~63);
len = len % 64;
for (; data < end; data += 64)
ctx->transform(ctx->state, data);
j = 0; j = 0;
} else }
i = 0; memcpy(&ctx->buffer[j], data, len);
memcpy(&ctx->buffer[j], &data[i], len - i);
#endif #endif
} }

View File

@ -74,11 +74,7 @@ int av_sha_init(struct AVSHA* context, int bits);
* @param data input data to update hash with * @param data input data to update hash with
* @param len input data length * @param len input data length
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len);
#else
void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len); void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.

View File

@ -239,13 +239,10 @@ av_cold int av_sha512_init(AVSHA512 *ctx, int bits)
return 0; return 0;
} }
#if FF_API_CRYPTO_SIZE_T
void av_sha512_update(AVSHA512* ctx, const uint8_t* data, unsigned int len)
#else
void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len) void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len)
#endif
{ {
unsigned int i, j; unsigned int j;
size_t i;
j = ctx->count & 127; j = ctx->count & 127;
ctx->count += len; ctx->count += len;
@ -258,15 +255,19 @@ void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len)
} }
} }
#else #else
if ((j + len) > 127) { if (len >= 128 - j) {
const uint8_t *end;
memcpy(&ctx->buffer[j], data, (i = 128 - j)); memcpy(&ctx->buffer[j], data, (i = 128 - j));
sha512_transform(ctx->state, ctx->buffer); sha512_transform(ctx->state, ctx->buffer);
for (; i + 127 < len; i += 128) data += i;
sha512_transform(ctx->state, &data[i]); len -= i;
end = data + (len & ~127);
len = len % 128;
for (; data < end; data += 128)
sha512_transform(ctx->state, data);
j = 0; j = 0;
} else }
i = 0; memcpy(&ctx->buffer[j], data, len);
memcpy(&ctx->buffer[j], &data[i], len - i);
#endif #endif
} }

View File

@ -76,11 +76,7 @@ int av_sha512_init(struct AVSHA512* context, int bits);
* @param data input data to update hash with * @param data input data to update hash with
* @param len input data length * @param len input data length
*/ */
#if FF_API_CRYPTO_SIZE_T
void av_sha512_update(struct AVSHA512* context, const uint8_t* data, unsigned int len);
#else
void av_sha512_update(struct AVSHA512* context, const uint8_t* data, size_t len); void av_sha512_update(struct AVSHA512* context, const uint8_t* data, size_t len);
#endif
/** /**
* Finish hashing and output digest value. * Finish hashing and output digest value.

View File

@ -105,9 +105,6 @@
* @{ * @{
*/ */
#ifndef FF_API_CRYPTO_SIZE_T
#define FF_API_CRYPTO_SIZE_T (LIBAVUTIL_VERSION_MAJOR < 57)
#endif
#ifndef FF_API_FRAME_GET_SET #ifndef FF_API_FRAME_GET_SET
#define FF_API_FRAME_GET_SET (LIBAVUTIL_VERSION_MAJOR < 57) #define FF_API_FRAME_GET_SET (LIBAVUTIL_VERSION_MAJOR < 57)
#endif #endif

View File

@ -153,7 +153,7 @@ static int video_decode_example(const char *input_filename)
av_frame_unref(fr); av_frame_unref(fr);
return number_of_written_bytes; return number_of_written_bytes;
} }
printf("%d, %s, %s, %8"PRId64", %8d, 0x%08lx\n", video_stream, printf("%d, %s, %s, %8"PRId64", %8d, 0x%08"PRIx32"\n", video_stream,
av_ts2str(fr->pts), av_ts2str(fr->pkt_dts), fr->pkt_duration, av_ts2str(fr->pts), av_ts2str(fr->pkt_dts), fr->pkt_duration,
number_of_written_bytes, av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes)); number_of_written_bytes, av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes));