split slow tests

This commit is contained in:
Philippe Teuwen 2019-09-21 18:32:07 +02:00
commit 782feb934a
9 changed files with 43 additions and 17 deletions

View file

@ -229,10 +229,11 @@ static int usage_hf_iclass_sniff(void) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int usage_hf_iclass_loclass(void) { static int usage_hf_iclass_loclass(void) {
PrintAndLogEx(NORMAL, "Usage: hf iclass loclass [options]"); PrintAndLogEx(NORMAL, "Usage: hf iclass loclass [h] [t [l]] [f <filename>]");
PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h Show this help"); PrintAndLogEx(NORMAL, " h Show this help");
PrintAndLogEx(NORMAL, " t Perform self-test"); PrintAndLogEx(NORMAL, " t Perform self-test");
PrintAndLogEx(NORMAL, " t l Perform self-test, including long ones");
PrintAndLogEx(NORMAL, " f <filename> Bruteforce iclass dumpfile"); PrintAndLogEx(NORMAL, " f <filename> Bruteforce iclass dumpfile");
PrintAndLogEx(NORMAL, " An iclass dumpfile is assumed to consist of an arbitrary number of"); PrintAndLogEx(NORMAL, " An iclass dumpfile is assumed to consist of an arbitrary number of");
PrintAndLogEx(NORMAL, " malicious CSNs, and their protocol responses"); PrintAndLogEx(NORMAL, " malicious CSNs, and their protocol responses");
@ -1831,10 +1832,11 @@ static int CmdHFiClass_loclass(const char *Cmd) {
return PM3_EFILE; return PM3_EFILE;
} }
} else if (opt == 't') { } else if (opt == 't') {
char opt2 = tolower(param_getchar(Cmd, 1));
int errors = testCipherUtils(); int errors = testCipherUtils();
errors += testMAC(); errors += testMAC();
errors += doKeyTests(0); errors += doKeyTests(0);
errors += testElite(); errors += testElite(opt2=='l');
if (errors) PrintAndLogEx(ERR, "There were errors!!!"); if (errors) PrintAndLogEx(ERR, "There were errors!!!");
return PM3_ESOFT; return PM3_ESOFT;
} }

View file

@ -1716,19 +1716,21 @@ static int CmdEMVList(const char *Cmd) {
static int CmdEMVTest(const char *Cmd) { static int CmdEMVTest(const char *Cmd) {
CLIParserInit("emv test", CLIParserInit("emv test",
"Executes tests\n", "Executes tests\n",
"Usage:\n\temv test\n"); "Usage:\n\temv test [l]\n");
void *argtable[] = { void *argtable[] = {
arg_param_begin, arg_param_begin,
arg_lit0("iI", "ignore", "ignore timing tests for VM"), arg_lit0("iI", "ignore", "ignore timing tests for VM"),
arg_lit0("lL", "long", "run long tests too"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(Cmd, argtable, true); CLIExecWithReturn(Cmd, argtable, true);
bool ignoreTimeTest = arg_get_lit(1); bool ignoreTimeTest = arg_get_lit(1);
bool runSlowTests = arg_get_lit(2);
CLIParserFree(); CLIParserFree();
return ExecuteCryptoTests(true, ignoreTimeTest); return ExecuteCryptoTests(true, ignoreTimeTest, runSlowTests);
} }
static int CmdEMVRoca(const char *Cmd) { static int CmdEMVRoca(const char *Cmd) {

View file

@ -301,8 +301,9 @@ close_pub:
return ret; return ret;
} }
int exec_crypto_test(bool verbose) { int exec_crypto_test(bool verbose, bool include_slow_tests) {
unsigned int keylengths[] = {1024, 1152, 1408, 1984, 2048, 3072, 4096}; unsigned int keylengths[] = {1024, 2048};
unsigned int extra_keylengths[] = {1152, 1408, 1984, 3072, 4096};
int i; int i;
int ret; int ret;
fprintf(stdout, "\n"); fprintf(stdout, "\n");
@ -322,6 +323,15 @@ int exec_crypto_test(bool verbose) {
return ret; return ret;
} }
} }
if (include_slow_tests) {
for (i = 0; i < ARRAYLEN(extra_keylengths); i++) {
unsigned int kl = extra_keylengths[i];
ret = test_genkey(kl, message, kl / 8, verbose);
if (ret) {
fprintf(stderr, "Crypto generate key[%u] test: failed\n", kl);
return ret;
}
}
}
return 0; return 0;
} }

View file

@ -17,5 +17,5 @@
#define __CRYPTO_TEST_H #define __CRYPTO_TEST_H
#include <stdbool.h> #include <stdbool.h>
int exec_crypto_test(bool verbose); int exec_crypto_test(bool verbose, bool include_slow_tests);
#endif #endif

View file

@ -33,7 +33,7 @@
#include "crypto/libpcrypto.h" #include "crypto/libpcrypto.h"
#include "emv/emv_roca.h" #include "emv/emv_roca.h"
int ExecuteCryptoTests(bool verbose, bool ignore_time) { int ExecuteCryptoTests(bool verbose, bool ignore_time, bool include_slow_tests) {
int res; int res;
bool TestFail = false; bool TestFail = false;
@ -94,7 +94,7 @@ int ExecuteCryptoTests(bool verbose, bool ignore_time) {
res = exec_cda_test(verbose); res = exec_cda_test(verbose);
if (res) TestFail = true; if (res) TestFail = true;
res = exec_crypto_test(verbose); res = exec_crypto_test(verbose, include_slow_tests);
if (res) TestFail = true; if (res) TestFail = true;
res = roca_self_test(); res = roca_self_test();

View file

@ -12,5 +12,5 @@
#define __CRYPTOTEST_H #define __CRYPTOTEST_H
#include <stdbool.h> #include <stdbool.h>
int ExecuteCryptoTests(bool verbose, bool ignore_time); int ExecuteCryptoTests(bool verbose, bool ignore_time, bool include_slow_tests);
#endif #endif

View file

@ -637,7 +637,7 @@ static int _testHash1() {
return 0; return 0;
} }
int testElite() { int testElite(bool slowtests) {
PrintAndLogEx(INFO, "Testing iClass Elite functinality..."); PrintAndLogEx(INFO, "Testing iClass Elite functinality...");
PrintAndLogEx(INFO, "Testing hash2"); PrintAndLogEx(INFO, "Testing hash2");
uint8_t k_cus[8] = {0x5B, 0x7C, 0x62, 0xC4, 0x91, 0xC1, 0x1B, 0x39}; uint8_t k_cus[8] = {0x5B, 0x7C, 0x62, 0xC4, 0x91, 0xC1, 0x1B, 0x39};
@ -669,6 +669,7 @@ int testElite() {
errors += _testHash1(); errors += _testHash1();
PrintAndLogEx(INFO, "Testing key diversification ..."); PrintAndLogEx(INFO, "Testing key diversification ...");
errors += _test_iclass_key_permutation(); errors += _test_iclass_key_permutation();
errors += _testBruteforce(); if (slowtests)
errors += _testBruteforce();
return errors; return errors;
} }

View file

@ -124,7 +124,7 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[]);
* @brief Test function * @brief Test function
* @return * @return
*/ */
int testElite(void); int testElite(bool slowtests);
/** /**
Here are some pretty optimal values that can be used to recover necessary data in only Here are some pretty optimal values that can be used to recover necessary data in only

View file

@ -3,6 +3,12 @@
PM3PATH=$(dirname "$0") PM3PATH=$(dirname "$0")
cd "$PM3PATH" || exit 1 cd "$PM3PATH" || exit 1
if [ "$1" == "long" ]; then
SLOWTESTS=true
else
SLOWTESTS=false
fi
C_RED='\033[0;31m' C_RED='\033[0;31m'
C_GREEN='\033[0;32m' C_GREEN='\033[0;32m'
C_YELLOW='\033[0;33m' C_YELLOW='\033[0;33m'
@ -95,9 +101,14 @@ while true; do
printf "\n${C_BLUE}Testing HF:${C_NC}\n" printf "\n${C_BLUE}Testing HF:${C_NC}\n"
if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi
if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi if $SLOWTESTS; then
if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "verified ok"; then break; fi if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi
if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t l'" "verified ok"; then break; fi
if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test -l'" "Test(s) \[ OK"; then break; fi
else
if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "OK!"; then break; fi
if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi
fi
printf "\n${C_BLUE}Testing tools:${C_NC}\n" printf "\n${C_BLUE}Testing tools:${C_NC}\n"
# Need a decent example for mfkey32... # Need a decent example for mfkey32...