diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-10-04 12:30:25 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-10-04 12:30:25 +0200 |
commit | 741f5b021a0494676de0dab543f8a9591ec2e01e (patch) | |
tree | 51b8243f64192e37c61bf03d18a25f40fd4c0d6d /libavutil/xtea.c | |
parent | 047dcfabc7e8932490836be94ef3b2ecc8289ab0 (diff) | |
parent | 29abb04e73b0580ebe38703cadb988d26df6a76a (diff) | |
download | ffmpeg-741f5b021a0494676de0dab543f8a9591ec2e01e.tar.gz |
Merge commit '29abb04e73b0580ebe38703cadb988d26df6a76a'
* commit '29abb04e73b0580ebe38703cadb988d26df6a76a':
libspeexdec: If the channel count is not valid, decode as stereo.
libspeexdec: improve setting of Speex mode and sample rate
libspeex: Add a private option for enabling VAD
xtea: Test inplace decryption
xtea: Fix CBC decryption when src==dst
xtea: Factorize testing into a separate function
configure: Refactor HAVE_ options available on the command line
avconv/avprobe: Add missing 'void' to exit_program() definition
Allow use of strncpy()
blowfish: Add more tests
blowfish: Fix CBC decryption with dst==src
blowfish: Factorize testing into a separate function
Conflicts:
configure
libavcodec/libspeexdec.c
libavutil/xtea.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/xtea.c')
-rw-r--r-- | libavutil/xtea.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/libavutil/xtea.c b/libavutil/xtea.c index 1c2bd04639..9c41f140fa 100644 --- a/libavutil/xtea.c +++ b/libavutil/xtea.c @@ -96,8 +96,8 @@ static void xtea_crypt_ecb(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, DSTEP(0x9E3779B9U, k3, k0); #endif if (iv) { - v0 ^= AV_RB32(iv ); - v1 ^= AV_RB32(iv+4); + v0 ^= AV_RB32(iv); + v1 ^= AV_RB32(iv + 4); memcpy(iv, src, 8); } } else { @@ -220,27 +220,39 @@ static const uint8_t xtea_test_ct[XTEA_NUM_TESTS][8] = { { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 } }; +#undef exit +static void test_xtea(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, + const uint8_t *ref, int len, uint8_t *iv, int dir, + const char *test) +{ + av_xtea_crypt(ctx, dst, src, len, iv, dir); + if (memcmp(dst, ref, 8*len)) { + int i; + printf("%s failed\ngot ", test); + for (i = 0; i < 8*len; i++) + printf("%02x ", dst[i]); + printf("\nexpected "); + for (i = 0; i < 8*len; i++) + printf("%02x ", ref[i]); + printf("\n"); + exit(1); + } +} + int main(void) { AVXTEA ctx; uint8_t buf[8], iv[8]; int i; const uint8_t src[32] = "HelloWorldHelloWorldHelloWorld"; - uint8_t ct[32]; - uint8_t pl[32]; - -#define CHECK(dst, src, ref, len, iv, dir, error) \ - av_xtea_crypt(&ctx, dst, src, len, iv, dir);\ - if (memcmp(dst, ref, 8*len)) {\ - printf(error);\ - return 1;\ - } + uint8_t ct[32]; + uint8_t pl[32]; for (i = 0; i < XTEA_NUM_TESTS; i++) { av_xtea_init(&ctx, xtea_test_key[i]); - CHECK(buf, xtea_test_pt[i], xtea_test_ct[i], 1, NULL, 0, "Test encryption failed.\n"); - CHECK(buf, xtea_test_ct[i], xtea_test_pt[i], 1, NULL, 1, "Test decryption failed.\n"); + test_xtea(&ctx, buf, xtea_test_pt[i], xtea_test_ct[i], 1, NULL, 0, "encryption"); + test_xtea(&ctx, buf, xtea_test_ct[i], xtea_test_pt[i], 1, NULL, 1, "decryption"); /* encrypt */ memcpy(iv, "HALLO123", 8); @@ -248,10 +260,10 @@ int main(void) /* decrypt into pl */ memcpy(iv, "HALLO123", 8); - CHECK(pl, ct, src, 4, iv, 1, "Test IV decryption failed.\n"); + test_xtea(&ctx, pl, ct, src, 4, iv, 1, "CBC decryption"); memcpy(iv, "HALLO123", 8); - CHECK(ct, ct, src, 4, iv, 1, "Test IV inplace decryption failed.\n"); + test_xtea(&ctx, ct, ct, src, 4, iv, 1, "CBC inplace decryption"); } printf("Test encryption/decryption success.\n"); |