History

avutil: Switch crypto APIs to size_t

Announced in e435beb1ea5380a90774dbf51fdc8c941e486551.

Andreas Rheinhardt committed 5 years ago

Commit a2400971 parent 6e30b3517 files · +40 −103Browse files

Unified · Split

17 files
  1. libavutil/adler32.c +0 −5
  2. libavutil/adler32.h +0 −9
  3. libavutil/hash.c +0 −4
  4. libavutil/hash.h +0 −4
  5. libavutil/hmac.c +0 −4
  6. libavutil/md5.c +3 −12
  7. libavutil/md5.h +0 −8
  8. libavutil/murmur3.c +0 −4
  9. libavutil/murmur3.h +0 −4
  10. libavutil/ripemd.c +12 −11
  11. libavutil/ripemd.h +0 −4
  12. libavutil/sha.c +12 −11
  13. libavutil/sha.h +0 −4
  14. libavutil/sha512.c +12 −11
  15. libavutil/sha512.h +0 −4
  16. libavutil/version.h +0 −3
  17. tests/api/api-h264-test.c +1 −1
libavutil/adler32.c+0−5
@@ -41,12 +41,7 @@ · 40 unmodified lines
4141 #define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);
4242 #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
4343
44−#if FF_API_CRYPTO_SIZE_T
45−unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf,
46− unsigned int len)
47−#else
4844 AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len)
49−#endif
5045 {
5146 unsigned long s1 = adler & 0xffff;
5247 unsigned long s2 = adler >> 16;
libavutil/adler32.h+0−9
@@ -30,7 +30,6 @@ · 29 unmodified lines
3030 #include <stddef.h>
3131 #include <stdint.h>
3232 #include "attributes.h"
33−#include "version.h"
3433
3534 /**
3635 * @defgroup lavu_adler32 Adler-32
@@ -40,11 +39,7 @@ · 3 unmodified lines
4039 * @{
4140 */
4241
43−#if FF_API_CRYPTO_SIZE_T
44−typedef unsigned long AVAdler;
45−#else
4642 typedef uint32_t AVAdler;
47−#endif
4843
4944 /**
5045 * Calculate the Adler32 checksum of a buffer.
@@ -59,11 +54,7 @@ typedef uint32_t AVAdler; · 8 unmodified lines
5954 * @return updated checksum
6055 */
6156 AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf,
62−#if FF_API_CRYPTO_SIZE_T
63− unsigned int len) av_pure;
64−#else
6557 size_t len) av_pure;
66−#endif
6758
6859 /**
6960 * @}
libavutil/hash.c+0−4
@@ -157,11 +157,7 @@ void av_hash_init(AVHashContext *ctx) · 156 unmodified lines
157157 }
158158 }
159159
160−#if FF_API_CRYPTO_SIZE_T
161−void av_hash_update(AVHashContext *ctx, const uint8_t *src, int len)
162−#else
163160 void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len)
164−#endif
165161 {
166162 switch (ctx->type) {
167163 case MD5: av_md5_update(ctx->ctx, src, len); break;
libavutil/hash.h+0−4
@@ -182,11 +182,7 @@ void av_hash_init(struct AVHashContext *ctx); · 181 unmodified lines
182182 * @param[in] src Data to be added to the hash context
183183 * @param[in] len Size of the additional data
184184 */
185−#if FF_API_CRYPTO_SIZE_T
186−void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, int len);
187−#else
188185 void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, size_t len);
189−#endif
190186
191187 /**
192188 * Finalize a hash context and compute the actual hash value.
libavutil/hmac.c+0−4
@@ -34,11 +34,7 @@ · 33 unmodified lines
3434 #define MAX_BLOCKLEN 128
3535
3636 typedef void (*hmac_final)(void *ctx, uint8_t *dst);
37−#if FF_API_CRYPTO_SIZE_T
38−typedef void (*hmac_update)(void *ctx, const uint8_t *src, int len);
39−#else
4037 typedef void (*hmac_update)(void *ctx, const uint8_t *src, size_t len);
41−#endif
4238 typedef void (*hmac_init)(void *ctx);
4339
4440 struct AVHMAC {
libavutil/md5.c+3−12
@@ -98,14 +98,13 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32) · 97 unmodified lines
9898 a = b + (a << t | a >> (32 - t)); \
9999 } while (0)
100100
101−static void body(uint32_t ABCD[4], const uint8_t *src, int nblocks)
101+static void body(uint32_t ABCD[4], const uint8_t *src, size_t nblocks)
102102 {
103103 int i av_unused;
104− int n;
105104 const uint32_t *X;
106105 uint32_t a, b, c, d, t;
107106
108− for (n = 0; n < nblocks; n++) {
107+ for (size_t n = 0; n < nblocks; n++) {
109108 a = ABCD[3];
110109 b = ABCD[2];
111110 c = ABCD[1];
@@ -150,11 +149,7 @@ void av_md5_init(AVMD5 *ctx) · 38 unmodified lines
150149 ctx->ABCD[3] = 0x67452301;
151150 }
152151
153−#if FF_API_CRYPTO_SIZE_T
154−void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
155−#else
156152 void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len)
157−#endif
158153 {
159154 const uint8_t *end;
160155 int j;
@@ -180,7 +175,7 @@ void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len) · 19 unmodified lines
180175 src += 64;
181176 }
182177 } else {
183− int nblocks = len / 64;
178+ size_t nblocks = len / 64;
184179 body(ctx->ABCD, src, nblocks);
185180 src = end;
186181 }
@@ -204,11 +199,7 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst) · 17 unmodified lines
204199 AV_WL32(dst + 4 * i, ctx->ABCD[3 - i]);
205200 }
206201
207−#if FF_API_CRYPTO_SIZE_T
208−void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
209−#else
210202 void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len)
211−#endif
212203 {
213204 AVMD5 ctx;
214205
libavutil/md5.h+0−8
@@ -64,11 +64,7 @@ void av_md5_init(struct AVMD5 *ctx); · 63 unmodified lines
6464 * @param src input data to update hash with
6565 * @param len input data length
6666 */
67−#if FF_API_CRYPTO_SIZE_T
68−void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len);
69−#else
7067 void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, size_t len);
71−#endif
7268
7369 /**
7470 * Finish hashing and output digest value.
@@ -85,11 +81,7 @@ void av_md5_final(struct AVMD5 *ctx, uint8_t *dst); · 10 unmodified lines
8581 * @param src The data to hash
8682 * @param len The length of the data, in bytes
8783 */
88−#if FF_API_CRYPTO_SIZE_T
89−void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
90−#else
9184 void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len);
92−#endif
9385
9486 /**
9587 * @}
libavutil/murmur3.c+0−4
@@ -91,11 +91,7 @@ static inline uint64_t update_h2(uint64_t k, uint64_t h1, uint64_t h2) · 90 unmodified lines
9191 return k;
9292 }
9393
94−#if FF_API_CRYPTO_SIZE_T
95−void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, int len)
96−#else
9794 void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, size_t len)
98−#endif
9995 {
10096 const uint8_t *end;
10197 uint64_t h1 = c->h1, h2 = c->h2;
libavutil/murmur3.h+0−4
@@ -100,11 +100,7 @@ void av_murmur3_init(struct AVMurMur3 *c); · 99 unmodified lines
100100 * @param[in] src Input data to update hash with
101101 * @param[in] len Number of bytes to read from `src`
102102 */
103−#if FF_API_CRYPTO_SIZE_T
104−void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, int len);
105−#else
106103 void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, size_t len);
107−#endif
108104
109105 /**
110106 * Finish hashing and output digest value.
libavutil/ripemd.c+12−11
@@ -511,13 +511,10 @@ av_cold int av_ripemd_init(AVRIPEMD *ctx, int bits) · 510 unmodified lines
511511 return 0;
512512 }
513513
514−#if FF_API_CRYPTO_SIZE_T
515−void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, unsigned int len)
516−#else
517514 void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len)
518−#endif
519515 {
520− unsigned int i, j;
516+ unsigned int j;
517+ size_t i;
521518
522519 j = ctx->count & 63;
523520 ctx->count += len;
@@ -530,15 +527,19 @@ void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len) · 6 unmodified lines
530527 }
531528 }
532529 #else
533− if ((j + len) > 63) {
530+ if (len >= 64 - j) {
531+ const uint8_t *end;
534532 memcpy(&ctx->buffer[j], data, (i = 64 - j));
535533 ctx->transform(ctx->state, ctx->buffer);
536− for (; i + 63 < len; i += 64)
537− ctx->transform(ctx->state, &data[i]);
534+ data += i;
535+ len -= i;
536+ end = data + (len & ~63);
537+ len = len % 64;
538+ for (; data < end; data += 64)
539+ ctx->transform(ctx->state, data);
538540 j = 0;
539− } else
540− i = 0;
541− memcpy(&ctx->buffer[j], &data[i], len - i);
541+ }
542+ memcpy(&ctx->buffer[j], data, len);
542543 #endif
543544 }
544545
libavutil/ripemd.h+0−4
@@ -67,11 +67,7 @@ int av_ripemd_init(struct AVRIPEMD* context, int bits); · 66 unmodified lines
6767 * @param data input data to update hash with
6868 * @param len input data length
6969 */
70−#if FF_API_CRYPTO_SIZE_T
71−void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, unsigned int len);
72−#else
7370 void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, size_t len);
74−#endif
7571
7672 /**
7773 * Finish hashing and output digest value.
libavutil/sha.c+12−11
@@ -311,13 +311,10 @@ av_cold int av_sha_init(AVSHA *ctx, int bits) · 310 unmodified lines
311311 return 0;
312312 }
313313
314−#if FF_API_CRYPTO_SIZE_T
315−void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len)
316−#else
317314 void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len)
318−#endif
319315 {
320− unsigned int i, j;
316+ unsigned int j;
317+ size_t i;
321318
322319 j = ctx->count & 63;
323320 ctx->count += len;
@@ -330,15 +327,19 @@ void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len) · 6 unmodified lines
330327 }
331328 }
332329 #else
333− if ((j + len) > 63) {
330+ if (len >= 64 - j) {
331+ const uint8_t *end;
334332 memcpy(&ctx->buffer[j], data, (i = 64 - j));
335333 ctx->transform(ctx->state, ctx->buffer);
336− for (; i + 63 < len; i += 64)
337− ctx->transform(ctx->state, &data[i]);
334+ data += i;
335+ len -= i;
336+ end = data + (len & ~63);
337+ len = len % 64;
338+ for (; data < end; data += 64)
339+ ctx->transform(ctx->state, data);
338340 j = 0;
339− } else
340− i = 0;
341− memcpy(&ctx->buffer[j], &data[i], len - i);
341+ }
342+ memcpy(&ctx->buffer[j], data, len);
342343 #endif
343344 }
344345
libavutil/sha.h+0−4
@@ -74,11 +74,7 @@ int av_sha_init(struct AVSHA* context, int bits); · 73 unmodified lines
7474 * @param data input data to update hash with
7575 * @param len input data length
7676 */
77−#if FF_API_CRYPTO_SIZE_T
78−void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len);
79−#else
8077 void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len);
81−#endif
8278
8379 /**
8480 * Finish hashing and output digest value.
libavutil/sha512.c+12−11
@@ -239,13 +239,10 @@ av_cold int av_sha512_init(AVSHA512 *ctx, int bits) · 238 unmodified lines
239239 return 0;
240240 }
241241
242−#if FF_API_CRYPTO_SIZE_T
243−void av_sha512_update(AVSHA512* ctx, const uint8_t* data, unsigned int len)
244−#else
245242 void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len)
246−#endif
247243 {
248− unsigned int i, j;
244+ unsigned int j;
245+ size_t i;
249246
250247 j = ctx->count & 127;
251248 ctx->count += len;
@@ -258,15 +255,19 @@ void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len) · 6 unmodified lines
258255 }
259256 }
260257 #else
261− if ((j + len) > 127) {
258+ if (len >= 128 - j) {
259+ const uint8_t *end;
262260 memcpy(&ctx->buffer[j], data, (i = 128 - j));
263261 sha512_transform(ctx->state, ctx->buffer);
264− for (; i + 127 < len; i += 128)
265− sha512_transform(ctx->state, &data[i]);
262+ data += i;
263+ len -= i;
264+ end = data + (len & ~127);
265+ len = len % 128;
266+ for (; data < end; data += 128)
267+ sha512_transform(ctx->state, data);
266268 j = 0;
267− } else
268− i = 0;
269− memcpy(&ctx->buffer[j], &data[i], len - i);
269+ }
270+ memcpy(&ctx->buffer[j], data, len);
270271 #endif
271272 }
272273
libavutil/sha512.h+0−4
@@ -76,11 +76,7 @@ int av_sha512_init(struct AVSHA512* context, int bits); · 75 unmodified lines
7676 * @param data input data to update hash with
7777 * @param len input data length
7878 */
79−#if FF_API_CRYPTO_SIZE_T
80−void av_sha512_update(struct AVSHA512* context, const uint8_t* data, unsigned int len);
81−#else
8279 void av_sha512_update(struct AVSHA512* context, const uint8_t* data, size_t len);
83−#endif
8480
8581 /**
8682 * Finish hashing and output digest value.
libavutil/version.h+0−3
@@ -105,9 +105,6 @@ · 104 unmodified lines
105105 * @{
106106 */
107107
108−#ifndef FF_API_CRYPTO_SIZE_T
109−#define FF_API_CRYPTO_SIZE_T (LIBAVUTIL_VERSION_MAJOR < 57)
110−#endif
111108 #ifndef FF_API_FRAME_GET_SET
112109 #define FF_API_FRAME_GET_SET (LIBAVUTIL_VERSION_MAJOR < 57)
113110 #endif
tests/api/api-h264-test.c+1−1
@@ -153,7 +153,7 @@ static int video_decode_example(const char *input_filename) · 152 unmodified lines
153153 av_frame_unref(fr);
154154 return number_of_written_bytes;
155155 }
156− printf("%d, %s, %s, %8"PRId64", %8d, 0x%08lx\n", video_stream,
156+ printf("%d, %s, %s, %8"PRId64", %8d, 0x%08"PRIx32"\n", video_stream,
157157 av_ts2str(fr->pts), av_ts2str(fr->pkt_dts), fr->pkt_duration,
158158 number_of_written_bytes, av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes));
159159

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