]> git.sesse.net Git - ffmpeg/commitdiff
avutil: Switch crypto APIs to size_t
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 6 Mar 2021 20:56:20 +0000 (21:56 +0100)
committerJames Almer <jamrial@gmail.com>
Tue, 27 Apr 2021 13:43:13 +0000 (10:43 -0300)
Announced in e435beb1ea5380a90774dbf51fdc8c941e486551.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
17 files changed:
libavutil/adler32.c
libavutil/adler32.h
libavutil/hash.c
libavutil/hash.h
libavutil/hmac.c
libavutil/md5.c
libavutil/md5.h
libavutil/murmur3.c
libavutil/murmur3.h
libavutil/ripemd.c
libavutil/ripemd.h
libavutil/sha.c
libavutil/sha.h
libavutil/sha512.c
libavutil/sha512.h
libavutil/version.h
tests/api/api-h264-test.c

index 5ed5ff55a382724d31c84f327d805db8ee846616..f7d3062265a878b188658f6881ca8ee90566e06b 100644 (file)
 #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;
index e7a8f83729e3473469eee42207f686dfeea27b4b..232d07f5fe8220cd8ed80d9df3fa3a69b5ad7f90 100644 (file)
@@ -30,7 +30,6 @@
 #include <stddef.h>
 #include <stdint.h>
 #include "attributes.h"
-#include "version.h"
 
 /**
  * @defgroup lavu_adler32 Adler-32
  * @{
  */
 
-#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
 
 /**
  * @}
index d626c31181923b888592644bbe4160685da4c826..9a49748189c958052076c9581d809c6cedefdd4a 100644 (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)
-#endif
 {
     switch (ctx->type) {
     case MD5:     av_md5_update(ctx->ctx, src, len); break;
index af4719e4231713749daa19686bb4e24f20dc62e0..930d2d6cde4e95a8771a04054f11e6e4d2e56715 100644 (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]     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.
index d064a105f420f95c14ea9c4149b566a252c65353..e277fd7701d90861f7d462f2f3c709008cb5f08b 100644 (file)
 #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 {
index 31e69925aed5c3db942bca0fb41907f20c2239d4..88596203c11af6645927128583da04a3d5295d6e 100644 (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));                               \
     } 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;
 
index ca72ccbf8371145a33c51886ad7af99a83405492..eee6af44dfe1d4162dc5bc4f46cecf702db46319 100644 (file)
@@ -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
 
 /**
  * @}
index 3e85c3c94fe5a9d2bc97d8567cae0df00d315927..f2e2a9ea6c9e2ff63703b77ae589757520686227 100644 (file)
@@ -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;
index b3b3a07de29b706bfdbe32f4d2c00f4550b89f4b..c5cd7e49e0cbf5aa7f8e6d1062e1b86a87f2cecf 100644 (file)
@@ -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.
index 89d69cc23da8ffbedf30add5905497e2cd7c586d..b8e9761a242c07a314f87f2c1f35202ff6d6fd8b 100644 (file)
@@ -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
 }
 
index 921aa66684d53e58823547785aaa6ed061724f61..8c24b72855ac5144a5463468a6f734d01a747c42 100644 (file)
@@ -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.
index ef6fa4422740735606e88e9b61e98b49212e38ea..ab42869c7bd26347966837b9b6be92f4151889d9 100644 (file)
@@ -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
 }
 
index c0180e5729a2e9232bdbf387b9b74d6acc25e943..85356218b99b50e172de61d74a732f0ebc758bb2 100644 (file)
@@ -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.
index 6d092a7c5c0e3ab523ca3599901884f88067649f..97aaaa865c3c9d3967163a6b596b6d08914144b9 100644 (file)
@@ -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
 }
 
index bef714b41cf720918ef28f7c484a7d93018fc37a..30dd8744f81a2309a7e8239aa2a9d3a432b0206c 100644 (file)
@@ -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.
index 0235074d8c5456be523d21785d5df1ae6ba3d80a..c447a51d0fc1be4d081b021918cba5868d78dd1f 100644 (file)
  * @{
  */
 
-#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
index 04bdfbc9d2328249d2ddcea75a0527d9633ba214..6f13e773f9b464a60fe7bf50a017b2332e607d55 100644 (file)
@@ -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));