aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2021-03-06 21:56:20 +0100
committerJames Almer <jamrial@gmail.com>2021-04-27 10:43:13 -0300
commita240097ecd4fb1639db99e7becb888ae478405cd (patch)
tree26a70d86c81463ced96d1123bb0d06621668dffd
parent6e30b35b85b81c802e52a1078ec7a3097e353c6d (diff)
downloadffmpeg-a240097ecd4fb1639db99e7becb888ae478405cd.tar.gz
avutil: Switch crypto APIs to size_t
Announced in e435beb1ea5380a90774dbf51fdc8c941e486551. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--libavutil/adler32.c5
-rw-r--r--libavutil/adler32.h9
-rw-r--r--libavutil/hash.c4
-rw-r--r--libavutil/hash.h4
-rw-r--r--libavutil/hmac.c4
-rw-r--r--libavutil/md5.c15
-rw-r--r--libavutil/md5.h8
-rw-r--r--libavutil/murmur3.c4
-rw-r--r--libavutil/murmur3.h4
-rw-r--r--libavutil/ripemd.c23
-rw-r--r--libavutil/ripemd.h4
-rw-r--r--libavutil/sha.c23
-rw-r--r--libavutil/sha.h4
-rw-r--r--libavutil/sha512.c23
-rw-r--r--libavutil/sha512.h4
-rw-r--r--libavutil/version.h3
-rw-r--r--tests/api/api-h264-test.c2
17 files changed, 40 insertions, 103 deletions
diff --git a/libavutil/adler32.c b/libavutil/adler32.c
index 5ed5ff55a3..f7d3062265 100644
--- a/libavutil/adler32.c
+++ b/libavutil/adler32.c
@@ -41,12 +41,7 @@
#define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(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)
-#endif
{
unsigned long s1 = adler & 0xffff;
unsigned long s2 = adler >> 16;
diff --git a/libavutil/adler32.h b/libavutil/adler32.h
index e7a8f83729..232d07f5fe 100644
--- a/libavutil/adler32.h
+++ b/libavutil/adler32.h
@@ -30,7 +30,6 @@
#include <stddef.h>
#include <stdint.h>
#include "attributes.h"
-#include "version.h"
/**
* @defgroup lavu_adler32 Adler-32
@@ -40,11 +39,7 @@
* @{
*/
-#if FF_API_CRYPTO_SIZE_T
-typedef unsigned long AVAdler;
-#else
typedef uint32_t AVAdler;
-#endif
/**
* Calculate the Adler32 checksum of a buffer.
@@ -59,11 +54,7 @@ typedef uint32_t AVAdler;
* @return updated checksum
*/
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;
-#endif
/**
* @}
diff --git a/libavutil/hash.c b/libavutil/hash.c
index d626c31181..9a49748189 100644
--- a/libavutil/hash.c
+++ b/libavutil/hash.c
@@ -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)
-#endif
{
switch (ctx->type) {
case MD5: av_md5_update(ctx->ctx, src, len); break;
diff --git a/libavutil/hash.h b/libavutil/hash.h
index af4719e423..930d2d6cde 100644
--- a/libavutil/hash.h
+++ b/libavutil/hash.h
@@ -182,11 +182,7 @@ void av_hash_init(struct AVHashContext *ctx);
* @param[in] src Data to be added to the hash context
* @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);
-#endif
/**
* Finalize a hash context and compute the actual hash value.
diff --git a/libavutil/hmac.c b/libavutil/hmac.c
index d064a105f4..e277fd7701 100644
--- a/libavutil/hmac.c
+++ b/libavutil/hmac.c
@@ -34,11 +34,7 @@
#define MAX_BLOCKLEN 128
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);
-#endif
typedef void (*hmac_init)(void *ctx);
struct AVHMAC {
diff --git a/libavutil/md5.c b/libavutil/md5.c
index 31e69925ae..88596203c1 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -98,14 +98,13 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
a = b + (a << t | a >> (32 - t)); \
} 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 n;
const uint32_t *X;
uint32_t a, b, c, d, t;
- for (n = 0; n < nblocks; n++) {
+ for (size_t n = 0; n < nblocks; n++) {
a = ABCD[3];
b = ABCD[2];
c = ABCD[1];
@@ -150,11 +149,7 @@ void av_md5_init(AVMD5 *ctx)
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)
-#endif
{
const uint8_t *end;
int j;
@@ -180,7 +175,7 @@ void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len)
src += 64;
}
} else {
- int nblocks = len / 64;
+ size_t nblocks = len / 64;
body(ctx->ABCD, src, nblocks);
src = end;
}
@@ -204,11 +199,7 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst)
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)
-#endif
{
AVMD5 ctx;
diff --git a/libavutil/md5.h b/libavutil/md5.h
index ca72ccbf83..eee6af44df 100644
--- a/libavutil/md5.h
+++ b/libavutil/md5.h
@@ -64,11 +64,7 @@ void av_md5_init(struct AVMD5 *ctx);
* @param src input data to update hash with
* @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);
-#endif
/**
* 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 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);
-#endif
/**
* @}
diff --git a/libavutil/murmur3.c b/libavutil/murmur3.c
index 3e85c3c94f..f2e2a9ea6c 100644
--- a/libavutil/murmur3.c
+++ b/libavutil/murmur3.c
@@ -91,11 +91,7 @@ static inline uint64_t update_h2(uint64_t k, uint64_t h1, uint64_t h2)
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)
-#endif
{
const uint8_t *end;
uint64_t h1 = c->h1, h2 = c->h2;
diff --git a/libavutil/murmur3.h b/libavutil/murmur3.h
index b3b3a07de2..c5cd7e49e0 100644
--- a/libavutil/murmur3.h
+++ b/libavutil/murmur3.h
@@ -100,11 +100,7 @@ void av_murmur3_init(struct AVMurMur3 *c);
* @param[in] src Input data to update hash with
* @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);
-#endif
/**
* Finish hashing and output digest value.
diff --git a/libavutil/ripemd.c b/libavutil/ripemd.c
index 89d69cc23d..b8e9761a24 100644
--- a/libavutil/ripemd.c
+++ b/libavutil/ripemd.c
@@ -511,13 +511,10 @@ av_cold int av_ripemd_init(AVRIPEMD *ctx, int bits)
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)
-#endif
{
- unsigned int i, j;
+ unsigned int j;
+ size_t i;
j = ctx->count & 63;
ctx->count += len;
@@ -530,15 +527,19 @@ void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len)
}
}
#else
- if ((j + len) > 63) {
+ if (len >= 64 - j) {
+ const uint8_t *end;
memcpy(&ctx->buffer[j], data, (i = 64 - j));
ctx->transform(ctx->state, ctx->buffer);
- for (; i + 63 < len; i += 64)
- ctx->transform(ctx->state, &data[i]);
+ data += i;
+ len -= i;
+ end = data + (len & ~63);
+ len = len % 64;
+ for (; data < end; data += 64)
+ ctx->transform(ctx->state, data);
j = 0;
- } else
- i = 0;
- memcpy(&ctx->buffer[j], &data[i], len - i);
+ }
+ memcpy(&ctx->buffer[j], data, len);
#endif
}
diff --git a/libavutil/ripemd.h b/libavutil/ripemd.h
index 921aa66684..8c24b72855 100644
--- a/libavutil/ripemd.h
+++ b/libavutil/ripemd.h
@@ -67,11 +67,7 @@ int av_ripemd_init(struct AVRIPEMD* context, int bits);
* @param data input data to update hash with
* @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);
-#endif
/**
* Finish hashing and output digest value.
diff --git a/libavutil/sha.c b/libavutil/sha.c
index ef6fa44227..ab42869c7b 100644
--- a/libavutil/sha.c
+++ b/libavutil/sha.c
@@ -311,13 +311,10 @@ av_cold int av_sha_init(AVSHA *ctx, int bits)
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)
-#endif
{
- unsigned int i, j;
+ unsigned int j;
+ size_t i;
j = ctx->count & 63;
ctx->count += len;
@@ -330,15 +327,19 @@ void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len)
}
}
#else
- if ((j + len) > 63) {
+ if (len >= 64 - j) {
+ const uint8_t *end;
memcpy(&ctx->buffer[j], data, (i = 64 - j));
ctx->transform(ctx->state, ctx->buffer);
- for (; i + 63 < len; i += 64)
- ctx->transform(ctx->state, &data[i]);
+ data += i;
+ len -= i;
+ end = data + (len & ~63);
+ len = len % 64;
+ for (; data < end; data += 64)
+ ctx->transform(ctx->state, data);
j = 0;
- } else
- i = 0;
- memcpy(&ctx->buffer[j], &data[i], len - i);
+ }
+ memcpy(&ctx->buffer[j], data, len);
#endif
}
diff --git a/libavutil/sha.h b/libavutil/sha.h
index c0180e5729..85356218b9 100644
--- a/libavutil/sha.h
+++ b/libavutil/sha.h
@@ -74,11 +74,7 @@ int av_sha_init(struct AVSHA* context, int bits);
* @param data input data to update hash with
* @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);
-#endif
/**
* Finish hashing and output digest value.
diff --git a/libavutil/sha512.c b/libavutil/sha512.c
index 6d092a7c5c..97aaaa865c 100644
--- a/libavutil/sha512.c
+++ b/libavutil/sha512.c
@@ -239,13 +239,10 @@ av_cold int av_sha512_init(AVSHA512 *ctx, int bits)
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)
-#endif
{
- unsigned int i, j;
+ unsigned int j;
+ size_t i;
j = ctx->count & 127;
ctx->count += len;
@@ -258,15 +255,19 @@ void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len)
}
}
#else
- if ((j + len) > 127) {
+ if (len >= 128 - j) {
+ const uint8_t *end;
memcpy(&ctx->buffer[j], data, (i = 128 - j));
sha512_transform(ctx->state, ctx->buffer);
- for (; i + 127 < len; i += 128)
- sha512_transform(ctx->state, &data[i]);
+ data += i;
+ len -= i;
+ end = data + (len & ~127);
+ len = len % 128;
+ for (; data < end; data += 128)
+ sha512_transform(ctx->state, data);
j = 0;
- } else
- i = 0;
- memcpy(&ctx->buffer[j], &data[i], len - i);
+ }
+ memcpy(&ctx->buffer[j], data, len);
#endif
}
diff --git a/libavutil/sha512.h b/libavutil/sha512.h
index bef714b41c..30dd8744f8 100644
--- a/libavutil/sha512.h
+++ b/libavutil/sha512.h
@@ -76,11 +76,7 @@ int av_sha512_init(struct AVSHA512* context, int bits);
* @param data input data to update hash with
* @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);
-#endif
/**
* Finish hashing and output digest value.
diff --git a/libavutil/version.h b/libavutil/version.h
index 0235074d8c..c447a51d0f 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -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
#define FF_API_FRAME_GET_SET (LIBAVUTIL_VERSION_MAJOR < 57)
#endif
diff --git a/tests/api/api-h264-test.c b/tests/api/api-h264-test.c
index 04bdfbc9d2..6f13e773f9 100644
--- a/tests/api/api-h264-test.c
+++ b/tests/api/api-h264-test.c
@@ -153,7 +153,7 @@ static int video_decode_example(const char *input_filename)
av_frame_unref(fr);
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,
number_of_written_bytes, av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes));