summaryrefslogtreecommitdiff
path: root/libavutil/xtea.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2012-10-03 19:19:37 +0300
committerMartin Storsjö <martin@martin.st>2012-10-03 19:19:37 +0300
commitca074cc3134cb81c086f54b441f0bbde4d4249e7 (patch)
treee52512f5da14e70ba31af81c9956f27d8aaae0a0 /libavutil/xtea.c
parentfd712a5584f13f8f89b2cd486d5a65a47634ed2a (diff)
xtea: Factorize testing into a separate function
Based on a patch by Michael Niedermayer. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavutil/xtea.c')
-rw-r--r--libavutil/xtea.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/libavutil/xtea.c b/libavutil/xtea.c
index 7c3a14c2be..11ae2664bb 100644
--- a/libavutil/xtea.c
+++ b/libavutil/xtea.c
@@ -139,6 +139,25 @@ 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;
@@ -148,17 +167,8 @@ int main(void)
for (i = 0; i < XTEA_NUM_TESTS; i++) {
av_xtea_init(&ctx, xtea_test_key[i]);
- av_xtea_crypt(&ctx, buf, xtea_test_pt[i], 1, NULL, 0);
- if (memcmp(buf, xtea_test_ct[i], 8)) {
- printf("Test encryption failed.\n");
- return 1;
- }
-
- av_xtea_crypt(&ctx, buf, xtea_test_ct[i], 1, NULL, 1);
- if (memcmp(buf, xtea_test_pt[i], 8)) {
- printf("Test decryption failed.\n");
- return 1;
- }
+ 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");
}
printf("Test encryption/decryption success.\n");