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
41#define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);41#define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);
42#define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);42#define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
43 43
44#if FF_API_CRYPTO_SIZE_T
45unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf,
46 unsigned int len)
47#else
48AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len)44AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len)
49#endif
50{45{
51 unsigned long s1 = adler & 0xffff;46 unsigned long s1 = adler & 0xffff;
52 unsigned long s2 = adler >> 16;47 unsigned long s2 = adler >> 16;
libavutil/adler32.h+0−9
@@ -30,7 +30,6 @@ · 29 unmodified lines
30#include <stddef.h>30#include <stddef.h>
31#include <stdint.h>31#include <stdint.h>
32#include "attributes.h"32#include "attributes.h"
33#include "version.h"
34 33
35/**34/**
36 * @defgroup lavu_adler32 Adler-3235 * @defgroup lavu_adler32 Adler-32
@@ -40,11 +39,7 @@ · 3 unmodified lines
40 * @{39 * @{
41 */40 */
42 41
43#if FF_API_CRYPTO_SIZE_T
44typedef unsigned long AVAdler;
45#else
46typedef uint32_t AVAdler;42typedef uint32_t AVAdler;
47#endif
48 43
49/**44/**
50 * Calculate the Adler32 checksum of a buffer.45 * Calculate the Adler32 checksum of a buffer.
@@ -59,11 +54,7 @@ typedef uint32_t AVAdler; · 8 unmodified lines
59 * @return updated checksum54 * @return updated checksum
60 */55 */
61AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf,56AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf,
62#if FF_API_CRYPTO_SIZE_T
63 unsigned int len) av_pure;
64#else
65 size_t len) av_pure;57 size_t len) av_pure;
66#endif
67 58
68/**59/**
69 * @}60 * @}
libavutil/hash.c+0−4
@@ -157,11 +157,7 @@ void av_hash_init(AVHashContext *ctx) · 156 unmodified lines
157 }157 }
158}158}
159 159
160#if FF_API_CRYPTO_SIZE_T
161void av_hash_update(AVHashContext *ctx, const uint8_t *src, int len)
162#else
163void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len)160void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len)
164#endif
165{161{
166 switch (ctx->type) {162 switch (ctx->type) {
167 case MD5: av_md5_update(ctx->ctx, src, len); break;163 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
182 * @param[in] src Data to be added to the hash context182 * @param[in] src Data to be added to the hash context
183 * @param[in] len Size of the additional data183 * @param[in] len Size of the additional data
184 */184 */
185#if FF_API_CRYPTO_SIZE_T
186void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, int len);
187#else
188void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, size_t len);185void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, size_t len);
189#endif
190 186
191/**187/**
192 * Finalize a hash context and compute the actual hash value.188 * Finalize a hash context and compute the actual hash value.
libavutil/hmac.c+0−4
@@ -34,11 +34,7 @@ · 33 unmodified lines
34#define MAX_BLOCKLEN 12834#define MAX_BLOCKLEN 128
35 35
36typedef void (*hmac_final)(void *ctx, uint8_t *dst);36typedef void (*hmac_final)(void *ctx, uint8_t *dst);
37#if FF_API_CRYPTO_SIZE_T
38typedef void (*hmac_update)(void *ctx, const uint8_t *src, int len);
39#else
40typedef void (*hmac_update)(void *ctx, const uint8_t *src, size_t len);37typedef void (*hmac_update)(void *ctx, const uint8_t *src, size_t len);
41#endif
42typedef void (*hmac_init)(void *ctx);38typedef void (*hmac_init)(void *ctx);
43 39
44struct AVHMAC {40struct 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
98 a = b + (a << t | a >> (32 - t)); \98 a = b + (a << t | a >> (32 - t)); \
99 } while (0)99 } while (0)
100 100
101static void body(uint32_t ABCD[4], const uint8_t *src, int nblocks)101static void body(uint32_t ABCD[4], const uint8_t *src, size_t nblocks)
102{102{
103 int i av_unused;103 int i av_unused;
104 int n;
105 const uint32_t *X;104 const uint32_t *X;
106 uint32_t a, b, c, d, t;105 uint32_t a, b, c, d, t;
107 106
108 for (n = 0; n < nblocks; n++) {107 for (size_t n = 0; n < nblocks; n++) {
109 a = ABCD[3];108 a = ABCD[3];
110 b = ABCD[2];109 b = ABCD[2];
111 c = ABCD[1];110 c = ABCD[1];
@@ -150,11 +149,7 @@ void av_md5_init(AVMD5 *ctx) · 38 unmodified lines
150 ctx->ABCD[3] = 0x67452301;149 ctx->ABCD[3] = 0x67452301;
151}150}
152 151
153#if FF_API_CRYPTO_SIZE_T
154void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
155#else
156void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len)152void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len)
157#endif
158{153{
159 const uint8_t *end;154 const uint8_t *end;
160 int j;155 int j;
@@ -180,7 +175,7 @@ void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len) · 19 unmodified lines
180 src += 64;175 src += 64;
181 }176 }
182 } else {177 } else {
183 int nblocks = len / 64;178 size_t nblocks = len / 64;
184 body(ctx->ABCD, src, nblocks);179 body(ctx->ABCD, src, nblocks);
185 src = end;180 src = end;
186 }181 }
@@ -204,11 +199,7 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst) · 17 unmodified lines
204 AV_WL32(dst + 4 * i, ctx->ABCD[3 - i]);199 AV_WL32(dst + 4 * i, ctx->ABCD[3 - i]);
205}200}
206 201
207#if FF_API_CRYPTO_SIZE_T
208void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
209#else
210void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len)202void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len)
211#endif
212{203{
213 AVMD5 ctx;204 AVMD5 ctx;
214 205
libavutil/md5.h+0−8
@@ -64,11 +64,7 @@ void av_md5_init(struct AVMD5 *ctx); · 63 unmodified lines
64 * @param src input data to update hash with64 * @param src input data to update hash with
65 * @param len input data length65 * @param len input data length
66 */66 */
67#if FF_API_CRYPTO_SIZE_T
68void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len);
69#else
70void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, size_t len);67void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, size_t len);
71#endif
72 68
73/**69/**
74 * Finish hashing and output digest value.70 * Finish hashing and output digest value.
@@ -85,11 +81,7 @@ void av_md5_final(struct AVMD5 *ctx, uint8_t *dst); · 10 unmodified lines
85 * @param src The data to hash81 * @param src The data to hash
86 * @param len The length of the data, in bytes82 * @param len The length of the data, in bytes
87 */83 */
88#if FF_API_CRYPTO_SIZE_T
89void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
90#else
91void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len);84void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len);
92#endif
93 85
94/**86/**
95 * @}87 * @}
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
91 return k;91 return k;
92}92}
93 93
94#if FF_API_CRYPTO_SIZE_T
95void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, int len)
96#else
97void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, size_t len)94void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, size_t len)
98#endif
99{95{
100 const uint8_t *end;96 const uint8_t *end;
101 uint64_t h1 = c->h1, h2 = c->h2;97 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
100 * @param[in] src Input data to update hash with100 * @param[in] src Input data to update hash with
101 * @param[in] len Number of bytes to read from `src`101 * @param[in] len Number of bytes to read from `src`
102 */102 */
103#if FF_API_CRYPTO_SIZE_T
104void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, int len);
105#else
106void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, size_t len);103void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, size_t len);
107#endif
108 104
109/**105/**
110 * Finish hashing and output digest value.106 * 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
511 return 0;511 return 0;
512}512}
513 513
514#if FF_API_CRYPTO_SIZE_T
515void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, unsigned int len)
516#else
517void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len)514void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len)
518#endif
519{515{
520 unsigned int i, j;516 unsigned int j;
517 size_t i;
521 518
522 j = ctx->count & 63;519 j = ctx->count & 63;
523 ctx->count += len;520 ctx->count += len;
@@ -530,15 +527,19 @@ void av_ripemd_update(AVRIPEMD* ctx, const uint8_t* data, size_t len) · 6 unmodified lines
530 }527 }
531 }528 }
532#else529#else
533 if ((j + len) > 63) {530 if (len >= 64 - j) {
531 const uint8_t *end;
534 memcpy(&ctx->buffer[j], data, (i = 64 - j));532 memcpy(&ctx->buffer[j], data, (i = 64 - j));
535 ctx->transform(ctx->state, ctx->buffer);533 ctx->transform(ctx->state, ctx->buffer);
536 for (; i + 63 < len; i += 64)534 data += i;
537 ctx->transform(ctx->state, &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);
538 j = 0;540 j = 0;
539 } else541 }
540 i = 0;542 memcpy(&ctx->buffer[j], data, len);
541 memcpy(&ctx->buffer[j], &data[i], len - i);
542#endif543#endif
543}544}
544 545
libavutil/ripemd.h+0−4
@@ -67,11 +67,7 @@ int av_ripemd_init(struct AVRIPEMD* context, int bits); · 66 unmodified lines
67 * @param data input data to update hash with67 * @param data input data to update hash with
68 * @param len input data length68 * @param len input data length
69 */69 */
70#if FF_API_CRYPTO_SIZE_T
71void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, unsigned int len);
72#else
73void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, size_t len);70void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, size_t len);
74#endif
75 71
76/**72/**
77 * Finish hashing and output digest value.73 * 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
311 return 0;311 return 0;
312}312}
313 313
314#if FF_API_CRYPTO_SIZE_T
315void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len)
316#else
317void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len)314void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len)
318#endif
319{315{
320 unsigned int i, j;316 unsigned int j;
317 size_t i;
321 318
322 j = ctx->count & 63;319 j = ctx->count & 63;
323 ctx->count += len;320 ctx->count += len;
@@ -330,15 +327,19 @@ void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len) · 6 unmodified lines
330 }327 }
331 }328 }
332#else329#else
333 if ((j + len) > 63) {330 if (len >= 64 - j) {
331 const uint8_t *end;
334 memcpy(&ctx->buffer[j], data, (i = 64 - j));332 memcpy(&ctx->buffer[j], data, (i = 64 - j));
335 ctx->transform(ctx->state, ctx->buffer);333 ctx->transform(ctx->state, ctx->buffer);
336 for (; i + 63 < len; i += 64)334 data += i;
337 ctx->transform(ctx->state, &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);
338 j = 0;340 j = 0;
339 } else341 }
340 i = 0;342 memcpy(&ctx->buffer[j], data, len);
341 memcpy(&ctx->buffer[j], &data[i], len - i);
342#endif343#endif
343}344}
344 345
libavutil/sha.h+0−4
@@ -74,11 +74,7 @@ int av_sha_init(struct AVSHA* context, int bits); · 73 unmodified lines
74 * @param data input data to update hash with74 * @param data input data to update hash with
75 * @param len input data length75 * @param len input data length
76 */76 */
77#if FF_API_CRYPTO_SIZE_T
78void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len);
79#else
80void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len);77void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len);
81#endif
82 78
83/**79/**
84 * Finish hashing and output digest value.80 * 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
239 return 0;239 return 0;
240}240}
241 241
242#if FF_API_CRYPTO_SIZE_T
243void av_sha512_update(AVSHA512* ctx, const uint8_t* data, unsigned int len)
244#else
245void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len)242void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len)
246#endif
247{243{
248 unsigned int i, j;244 unsigned int j;
245 size_t i;
249 246
250 j = ctx->count & 127;247 j = ctx->count & 127;
251 ctx->count += len;248 ctx->count += len;
@@ -258,15 +255,19 @@ void av_sha512_update(AVSHA512* ctx, const uint8_t* data, size_t len) · 6 unmodified lines
258 }255 }
259 }256 }
260#else257#else
261 if ((j + len) > 127) {258 if (len >= 128 - j) {
259 const uint8_t *end;
262 memcpy(&ctx->buffer[j], data, (i = 128 - j));260 memcpy(&ctx->buffer[j], data, (i = 128 - j));
263 sha512_transform(ctx->state, ctx->buffer);261 sha512_transform(ctx->state, ctx->buffer);
264 for (; i + 127 < len; i += 128)262 data += i;
265 sha512_transform(ctx->state, &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);
266 j = 0;268 j = 0;
267 } else269 }
268 i = 0;270 memcpy(&ctx->buffer[j], data, len);
269 memcpy(&ctx->buffer[j], &data[i], len - i);
270#endif271#endif
271}272}
272 273
libavutil/sha512.h+0−4
@@ -76,11 +76,7 @@ int av_sha512_init(struct AVSHA512* context, int bits); · 75 unmodified lines
76 * @param data input data to update hash with76 * @param data input data to update hash with
77 * @param len input data length77 * @param len input data length
78 */78 */
79#if FF_API_CRYPTO_SIZE_T
80void av_sha512_update(struct AVSHA512* context, const uint8_t* data, unsigned int len);
81#else
82void av_sha512_update(struct AVSHA512* context, const uint8_t* data, size_t len);79void av_sha512_update(struct AVSHA512* context, const uint8_t* data, size_t len);
83#endif
84 80
85/**81/**
86 * Finish hashing and output digest value.82 * Finish hashing and output digest value.
libavutil/version.h+0−3
@@ -105,9 +105,6 @@ · 104 unmodified lines
105 * @{105 * @{
106 */106 */
107 107
108#ifndef FF_API_CRYPTO_SIZE_T
109#define FF_API_CRYPTO_SIZE_T (LIBAVUTIL_VERSION_MAJOR < 57)
110#endif
111#ifndef FF_API_FRAME_GET_SET108#ifndef FF_API_FRAME_GET_SET
112#define FF_API_FRAME_GET_SET (LIBAVUTIL_VERSION_MAJOR < 57)109#define FF_API_FRAME_GET_SET (LIBAVUTIL_VERSION_MAJOR < 57)
113#endif110#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
153 av_frame_unref(fr);153 av_frame_unref(fr);
154 return number_of_written_bytes;154 return number_of_written_bytes;
155 }155 }
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,
157 av_ts2str(fr->pts), av_ts2str(fr->pkt_dts), fr->pkt_duration,157 av_ts2str(fr->pts), av_ts2str(fr->pkt_dts), fr->pkt_duration,
158 number_of_written_bytes, av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes));158 number_of_written_bytes, av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes));
159 159

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