mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
Merge pull request #11 from dllaurence/cmake-tests
Make CMakeLists.txt build tests
This commit is contained in:
commit
24beac2cc0
@ -3,3 +3,13 @@ if(MSVC)
|
|||||||
set_source_files_properties(${SOURCES} PROPERTIES LANGUAGE CXX)
|
set_source_files_properties(${SOURCES} PROPERTIES LANGUAGE CXX)
|
||||||
endif(MSVC)
|
endif(MSVC)
|
||||||
add_library(TrezorCrypto STATIC ${SOURCES})
|
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)
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#include "ecdsa.h"
|
#include "ecdsa.h"
|
||||||
#include "rand.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;
|
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;
|
uint32_t i, j, msg_len;
|
||||||
@ -41,7 +41,14 @@ int main(void)
|
|||||||
init_rand();
|
init_rand();
|
||||||
ecgroup = EC_GROUP_new_by_curve_name(NID_secp256k1);
|
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
|
// random message len between 1 and 256
|
||||||
msg_len = (random32() & 0xFF) + 1;
|
msg_len = (random32() & 0xFF) + 1;
|
||||||
// create random message
|
// create random message
|
||||||
@ -113,6 +120,7 @@ int main(void)
|
|||||||
EC_KEY_free(eckey);
|
EC_KEY_free(eckey);
|
||||||
cnt++;
|
cnt++;
|
||||||
if ((cnt % 100) == 0) printf("Passed ... %d\n", cnt);
|
if ((cnt % 100) == 0) printf("Passed ... %d\n", cnt);
|
||||||
|
++iterations;
|
||||||
}
|
}
|
||||||
EC_GROUP_free(ecgroup);
|
EC_GROUP_free(ecgroup);
|
||||||
return 0;
|
return 0;
|
||||||
|
2
tests.c
2
tests.c
@ -54,7 +54,7 @@ uint8_t *fromhex(const char *str)
|
|||||||
return buf;
|
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);
|
char *buf = (char *)malloc(l * 2 + 1);
|
||||||
static char digits[] = "0123456789abcdef";
|
static char digits[] = "0123456789abcdef";
|
||||||
|
Loading…
Reference in New Issue
Block a user