Commit 24c65eb2 authored by Reimar Döffinger's avatar Reimar Döffinger

md5: avoid unnecessary copying.

Where necessary use memcpy instead.
Thanks to Giorgio Vazzana [mywing81 gmail] for
spotting this loop as the cause for the bad
performance.
Signed-off-by: 's avatarReimar Döffinger <Reimar.Doeffinger@gmx.de>
parent 47ac3449
...@@ -139,20 +139,40 @@ void av_md5_init(AVMD5 *ctx) ...@@ -139,20 +139,40 @@ void av_md5_init(AVMD5 *ctx)
ctx->ABCD[3] = 0x67452301; ctx->ABCD[3] = 0x67452301;
} }
void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len) void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
{ {
int i, j; const uint8_t *end;
int j;
j = ctx->len & 63; j = ctx->len & 63;
ctx->len += len; ctx->len += len;
for (i = 0; i < len; i++) { if (j) {
ctx->block[j++] = src[i]; int cnt = FFMIN(len, 64 - j);
if (j == 64) { memcpy(ctx->block + j, src, cnt);
body(ctx->ABCD, (uint32_t *) ctx->block); src += cnt;
j = 0; len -= cnt;
if (j + cnt < 64)
return;
body(ctx->ABCD, (uint32_t *)ctx->block);
}
end = src + (len & ~63);
if (HAVE_BIGENDIAN || (!HAVE_FAST_UNALIGNED && ((intptr_t)src & 3))) {
while (src < end) {
memcpy(ctx->block, src, 64);
body(ctx->ABCD, (uint32_t *) ctx->block);
src += 64;
}
} else {
while (src < end) {
body(ctx->ABCD, (uint32_t *)src);
src += 64;
} }
} }
len &= 63;
if (len > 0)
memcpy(ctx->block, src, len);
} }
void av_md5_final(AVMD5 *ctx, uint8_t *dst) void av_md5_final(AVMD5 *ctx, uint8_t *dst)
......
...@@ -38,7 +38,7 @@ struct AVMD5; ...@@ -38,7 +38,7 @@ struct AVMD5;
struct AVMD5 *av_md5_alloc(void); struct AVMD5 *av_md5_alloc(void);
void av_md5_init(struct AVMD5 *ctx); void av_md5_init(struct AVMD5 *ctx);
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len); void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len);
void av_md5_final(struct AVMD5 *ctx, uint8_t *dst); void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len); void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment