diff options
author | Janne Grunau <janne-vlc@jannau.net> | 2019-02-27 21:30:18 +0300 |
---|---|---|
committer | Jean-Baptiste Kempf <jb@videolan.org> | 2019-03-14 13:23:47 +0300 |
commit | d9a911a4fbddcb7a28f64851503521ca6b00d291 (patch) | |
tree | a29e2c5434f13088de88fe42994ad55400b6d47e | |
parent | dc769f5d44b697a6a8c1fdd975bbab6cd2864574 (diff) |
tools/dav1d: make the md5 muxer endian-aware
Fixes tests on big endian architectures.
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | tools/output/md5.c | 25 |
2 files changed, 25 insertions, 2 deletions
diff --git a/meson.build b/meson.build index 1258f89..96b7b1f 100644 --- a/meson.build +++ b/meson.build @@ -214,6 +214,8 @@ endif stackalign_flag = [] stackrealign_flag = [] +cdata.set10('ENDIANNESS_BIG', host_machine.endian() == 'big') + if host_machine.cpu_family().startswith('x86') if get_option('stack_alignment') > 0 stack_alignment = get_option('stack_alignment') diff --git a/tools/output/md5.c b/tools/output/md5.c index 812a280..8382640 100644 --- a/tools/output/md5.c +++ b/tools/output/md5.c @@ -63,6 +63,27 @@ static const unsigned k[] = { 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, }; + +#if ENDIANNESS_BIG +#define NE2LE_32(x) (((x & 0x00ff) << 24) |\ + ((x & 0xff00) << 8) |\ + ((x >> 8) & 0xff00) |\ + ((x >> 24) & 0x00ff)) + +#define NE2LE_64(x) (((x & 0x000000ff) << 56) |\ + ((x & 0x0000ff00) << 40) |\ + ((x & 0x00ff0000) << 24) |\ + ((x & 0xff000000) << 8) |\ + ((x >> 8) & 0xff000000) |\ + ((x >> 24) & 0x00ff0000) |\ + ((x >> 40) & 0x0000ff00) |\ + ((x >> 56) & 0x000000ff)) + +#else +#define NE2LE_32(x) (x) +#define NE2LE_64(x) (x) +#endif + typedef struct MuxerPriv { unsigned abcd[4]; uint8_t data[64]; @@ -123,7 +144,7 @@ static void md5_body(MD5Context *md5, const uint8_t *const _data) { tmp = d; d = c; c = b; - b += leftrotate(a + f + k[i] + data[g], s[i >> 4][i & 3]); + b += leftrotate(a + f + k[i] + NE2LE_32(data[g]), s[i >> 4][i & 3]); a = tmp; } @@ -193,7 +214,7 @@ static int md5_write(MD5Context *const md5, Dav1dPicture *const p) { static void md5_finish(MD5Context *const md5) { static const uint8_t bit[2] = { 0x80, 0x00 }; - uint64_t len = md5->len << 3; + uint64_t len = NE2LE_64(md5->len << 3); md5_update(md5, &bit[0], 1); while ((md5->len & 63) != 56) |