mirror of https://git.ffmpeg.org/ffmpeg.git
Use pointer to hash transform function to make adding SHA-2 support easier.
Originally committed as revision 19388 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
3a7c65077d
commit
2c6361e009
|
@ -29,6 +29,8 @@ typedef struct AVSHA1 {
|
||||||
uint64_t count; ///< number of bytes in buffer
|
uint64_t count; ///< number of bytes in buffer
|
||||||
uint8_t buffer[64]; ///< 512-bit buffer of input values used in hash updating
|
uint8_t buffer[64]; ///< 512-bit buffer of input values used in hash updating
|
||||||
uint32_t state[8]; ///< current hash value
|
uint32_t state[8]; ///< current hash value
|
||||||
|
/** function used to update hash for 512-bit input block */
|
||||||
|
void (*transform)(uint32_t *state, const uint8_t buffer[64]);
|
||||||
} AVSHA1;
|
} AVSHA1;
|
||||||
|
|
||||||
const int av_sha1_size = sizeof(AVSHA1);
|
const int av_sha1_size = sizeof(AVSHA1);
|
||||||
|
@ -132,6 +134,7 @@ void av_sha1_init(AVSHA1* ctx)
|
||||||
ctx->state[2] = 0x98BADCFE;
|
ctx->state[2] = 0x98BADCFE;
|
||||||
ctx->state[3] = 0x10325476;
|
ctx->state[3] = 0x10325476;
|
||||||
ctx->state[4] = 0xC3D2E1F0;
|
ctx->state[4] = 0xC3D2E1F0;
|
||||||
|
ctx->transform = transform;
|
||||||
ctx->count = 0;
|
ctx->count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,16 +148,16 @@ void av_sha1_update(AVSHA1* ctx, const uint8_t* data, unsigned int len)
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
ctx->buffer[j++] = data[i];
|
ctx->buffer[j++] = data[i];
|
||||||
if (64 == j) {
|
if (64 == j) {
|
||||||
transform(ctx->state, ctx->buffer);
|
ctx->transform(ctx->state, ctx->buffer);
|
||||||
j = 0;
|
j = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if ((j + len) > 63) {
|
if ((j + len) > 63) {
|
||||||
memcpy(&ctx->buffer[j], data, (i = 64 - j));
|
memcpy(&ctx->buffer[j], data, (i = 64 - j));
|
||||||
transform(ctx->state, ctx->buffer);
|
ctx->transform(ctx->state, ctx->buffer);
|
||||||
for (; i + 63 < len; i += 64)
|
for (; i + 63 < len; i += 64)
|
||||||
transform(ctx->state, &data[i]);
|
ctx->transform(ctx->state, &data[i]);
|
||||||
j = 0;
|
j = 0;
|
||||||
} else
|
} else
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
Loading…
Reference in New Issue