aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/des.c
diff options
context:
space:
mode:
authorDiego Biurrun <diego@biurrun.de>2016-03-17 19:13:17 +0100
committerDiego Biurrun <diego@biurrun.de>2016-04-07 16:14:42 +0200
commitd12b5b2f135aade4099f4b26b0fe678656158c13 (patch)
treed5b44fd428a1c68213fe51aca21b5819bce3d33a /libavutil/des.c
parent330177b508420a553083df94f22cbd5142de0f4a (diff)
downloadffmpeg-d12b5b2f135aade4099f4b26b0fe678656158c13.tar.gz
build: Split test programs off into separate files
This avoids spurious library rebuilds when only the test program code is changed and simplifies the build system.
Diffstat (limited to 'libavutil/des.c')
-rw-r--r--libavutil/des.c111
1 files changed, 1 insertions, 110 deletions
diff --git a/libavutil/des.c b/libavutil/des.c
index 7d9458c81f..1dbedd92cd 100644
--- a/libavutil/des.c
+++ b/libavutil/des.c
@@ -111,7 +111,7 @@ static const uint8_t S_boxes[8][32] = {
#else
/**
* This table contains the results of applying both the S-box and P-shuffle.
- * It can be regenerated by compiling this file with -DCONFIG_SMALL -DTEST -DGENTABLES
+ * It can be regenerated by compiling des-test.c with "-DCONFIG_SMALL -DGENTABLES".
*/
static const uint32_t S_boxes_P_shuffle[8][64] = {
{ 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
@@ -337,112 +337,3 @@ void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count)
{
av_des_crypt_mac(d, dst, src, count, (uint8_t[8]) { 0 }, 0, 1);
}
-
-#ifdef TEST
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "time.h"
-
-static uint64_t rand64(void)
-{
- uint64_t r = rand();
- r = (r << 32) | rand();
- return r;
-}
-
-static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
-static const DECLARE_ALIGNED(8, uint8_t, plain)[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
-static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = { 0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18 };
-static DECLARE_ALIGNED(8, uint8_t, tmp)[8];
-static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8];
-static const uint8_t cbc_key[] = {
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
- 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
-};
-
-static int run_test(int cbc, int decrypt)
-{
- AVDES d;
- int delay = cbc && !decrypt ? 2 : 1;
- uint64_t res;
- AV_WB64(large_buffer[0], 0x4e6f772069732074ULL);
- AV_WB64(large_buffer[1], 0x1234567890abcdefULL);
- AV_WB64(tmp, 0x1234567890abcdefULL);
- av_des_init(&d, cbc_key, 192, decrypt);
- av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt);
- res = AV_RB64(large_buffer[9999 + delay]);
- if (cbc) {
- if (decrypt)
- return res == 0xc5cecf63ecec514cULL;
- else
- return res == 0xcb191f85d1ed8439ULL;
- } else {
- if (decrypt)
- return res == 0x8325397644091a0aULL;
- else
- return res == 0xdd17e8b8b437d232ULL;
- }
-}
-
-int main(void)
-{
- AVDES d;
- int i;
- uint64_t key[3];
- uint64_t data;
- uint64_t ct;
- uint64_t roundkeys[16];
- srand(av_gettime());
- key[0] = AV_RB64(test_key);
- data = AV_RB64(plain);
- gen_roundkeys(roundkeys, key[0]);
- if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) {
- printf("Test 1 failed\n");
- return 1;
- }
- av_des_init(&d, test_key, 64, 0);
- av_des_crypt(&d, tmp, plain, 1, NULL, 0);
- if (memcmp(tmp, crypt, sizeof(crypt))) {
- printf("Public API decryption failed\n");
- return 1;
- }
- if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) {
- printf("Partial Monte-Carlo test failed\n");
- return 1;
- }
- for (i = 0; i < 1000; i++) {
- key[0] = rand64();
- key[1] = rand64();
- key[2] = rand64();
- data = rand64();
- av_des_init(&d, key, 192, 0);
- av_des_crypt(&d, &ct, &data, 1, NULL, 0);
- av_des_init(&d, key, 192, 1);
- av_des_crypt(&d, &ct, &ct, 1, NULL, 1);
- if (ct != data) {
- printf("Test 2 failed\n");
- return 1;
- }
- }
-#ifdef GENTABLES
- printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n");
- for (i = 0; i < 8; i++) {
- int j;
- printf(" {");
- for (j = 0; j < 64; j++) {
- uint32_t v = S_boxes[i][j >> 1];
- v = j & 1 ? v >> 4 : v & 0xf;
- v <<= 28 - 4 * i;
- v = shuffle(v, P_shuffle, sizeof(P_shuffle));
- printf((j & 7) == 0 ? "\n " : " ");
- printf("0x%08X,", v);
- }
- printf("\n },\n");
- }
- printf("};\n");
-#endif
- return 0;
-}
-#endif