2017-12-24 17:26:47 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 2017 Merlok
|
|
|
|
//
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Crypto algorithms testing
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "cryptotest.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "ui.h"
|
|
|
|
|
2018-11-08 00:05:02 +08:00
|
|
|
#include "mbedtls/bignum.h"
|
|
|
|
#include "mbedtls/aes.h"
|
|
|
|
#include "mbedtls/cmac.h"
|
|
|
|
#include "mbedtls/des.h"
|
|
|
|
#include "mbedtls/ecp.h"
|
|
|
|
#include "mbedtls/rsa.h"
|
|
|
|
#include "mbedtls/sha1.h"
|
|
|
|
#include "mbedtls/md5.h"
|
|
|
|
#include "mbedtls/x509.h"
|
|
|
|
#include "mbedtls/base64.h"
|
|
|
|
#include "mbedtls/ctr_drbg.h"
|
|
|
|
#include "mbedtls/entropy.h"
|
|
|
|
#include "mbedtls/timing.h"
|
2017-12-24 17:26:47 +08:00
|
|
|
|
|
|
|
#include "crypto_test.h"
|
|
|
|
#include "sda_test.h"
|
|
|
|
#include "dda_test.h"
|
|
|
|
#include "cda_test.h"
|
2018-11-08 00:05:02 +08:00
|
|
|
#include "crypto/libpcrypto.h"
|
2018-12-29 02:33:38 +08:00
|
|
|
#include "emv/emv_roca.h"
|
2017-12-24 17:26:47 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
int ExecuteCryptoTests(bool verbose) {
|
2019-03-10 06:35:06 +08:00
|
|
|
int res;
|
|
|
|
bool TestFail = false;
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_mpi_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_aes_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2018-11-08 00:05:02 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_des_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_sha1_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2018-11-08 00:05:02 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_md5_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_rsa_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_entropy_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2018-11-08 00:05:02 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_timing_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2018-11-08 00:05:02 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_ctr_drbg_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_base64_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2018-11-08 00:05:02 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_cmac_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2018-11-08 00:05:02 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = ecdsa_nist_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2018-11-08 00:05:02 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_ecp_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2018-11-08 00:05:02 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = mbedtls_x509_self_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = exec_sda_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2017-12-24 17:26:47 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = exec_dda_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = exec_cda_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2017-12-24 17:26:47 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = exec_crypto_test(verbose);
|
|
|
|
if (res) TestFail = true;
|
2017-12-24 17:26:47 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
res = roca_self_test();
|
|
|
|
if (res) TestFail = true;
|
2018-12-29 02:33:38 +08:00
|
|
|
|
2019-04-08 00:12:58 +08:00
|
|
|
PrintAndLogEx(NORMAL, "\n--------------------------");
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
if (TestFail)
|
2019-03-10 07:56:00 +08:00
|
|
|
PrintAndLogEx(FAILED, "\tTest(s) [ %s ]", _RED_("FAIL"));
|
2019-03-10 06:35:06 +08:00
|
|
|
else
|
2019-03-10 07:56:00 +08:00
|
|
|
PrintAndLogEx(SUCCESS, "\tTest(s) [ %s ]", _GREEN_("OK"));
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
return TestFail;
|
2017-12-24 17:26:47 +08:00
|
|
|
}
|
|
|
|
|