1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

Merge pull request #11 from dllaurence/cmake-tests

Make CMakeLists.txt build tests
This commit is contained in:
Pavol Rusnak 2014-07-17 16:38:39 +02:00
commit 24beac2cc0
3 changed files with 21 additions and 3 deletions

View File

@ -3,3 +3,13 @@ if(MSVC)
set_source_files_properties(${SOURCES} PROPERTIES LANGUAGE CXX)
endif(MSVC)
add_library(TrezorCrypto STATIC ${SOURCES})
# disable sequence point warning because of AES code
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sequence-point")
add_executable(tests tests.c aescrypt.c aeskey.c aestab.c aes_modes.c)
target_link_libraries(tests TrezorCrypto check rt pthread m crypto)
add_test(NAME trezor-crypto COMMAND tests)
add_executable(test-openssl test-openssl.c)
target_link_libraries(test-openssl TrezorCrypto check rt pthread m crypto)
add_test(NAME trezor-crypto-openssl COMMAND test-openssl 100)

View File

@ -30,7 +30,7 @@
#include "ecdsa.h"
#include "rand.h"
int main(void)
int main(int argc, char *argv[])
{
uint8_t sig[64], pub_key33[33], pub_key65[65], priv_key[32], msg[256], buffer[1000], hash[32], *p;
uint32_t i, j, msg_len;
@ -41,7 +41,14 @@ int main(void)
init_rand();
ecgroup = EC_GROUP_new_by_curve_name(NID_secp256k1);
for (;;) {
unsigned long max_iterations = -1;
if (argc == 2) {
sscanf(argv[1], "%lu", &max_iterations);
} else if (argc > 2) {
puts("Zero or one command-line arguments only, exiting....");
}
unsigned long iterations = 0;
while (argc == 1 || iterations < max_iterations) {
// random message len between 1 and 256
msg_len = (random32() & 0xFF) + 1;
// create random message
@ -113,6 +120,7 @@ int main(void)
EC_KEY_free(eckey);
cnt++;
if ((cnt % 100) == 0) printf("Passed ... %d\n", cnt);
++iterations;
}
EC_GROUP_free(ecgroup);
return 0;

View File

@ -54,7 +54,7 @@ uint8_t *fromhex(const char *str)
return buf;
}
inline char *tohex(const uint8_t *bin, size_t l)
char *tohex(const uint8_t *bin, size_t l)
{
char *buf = (char *)malloc(l * 2 + 1);
static char digits[] = "0123456789abcdef";