diff --git a/CHANGELOG.md b/CHANGELOG.md index 15a61af..d85b45f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +### Changed + +- TROPIC01 hw wallet example updated - compiles for 32 and 64 bit system \ No newline at end of file diff --git a/examples/hw_wallet/hw_wallet.c b/examples/hw_wallet/TROPIC01_hw_wallet.c similarity index 96% rename from examples/hw_wallet/hw_wallet.c rename to examples/hw_wallet/TROPIC01_hw_wallet.c index 9e37084..c74c802 100644 --- a/examples/hw_wallet/hw_wallet.c +++ b/examples/hw_wallet/TROPIC01_hw_wallet.c @@ -4,7 +4,7 @@ #include "libtropic.h" #include "libtropic_common.h" -#include "hw_wallet.h" +#include "TROPIC01_hw_wallet.h" /* [Note] We recommend reading TROPIC01's datasheet before diving into this example! @@ -24,6 +24,27 @@ during the device's lifecycle. */ +#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(_WIN32)) + #if defined(_M_X64) + #define BITNESS 64 + #define LONG_SIZE 4 + #else + #define BITNESS 32 + #define LONG_SIZE 4 + #endif +#elif defined(__clang__) || defined(__INTEL_COMPILER) || defined(__GNUC__) + #if defined(__x86_64) + #define BITNESS 64 + #else + #define BITNESS 32 + #endif + #if __LONG_MAX__ == 2147483647L + #define LONG_SIZE 4 + #else + #define LONG_SIZE 8 + #endif +#endif + // Default factory pairing keys uint8_t pkey_index_0 = PAIRING_KEY_SLOT_INDEX_0; uint8_t sh0priv[] = {0xf0,0xc4,0xaa,0x04,0x8f,0x00,0x13,0xa0,0x96,0x84,0xdf,0x05,0xe8,0xa2,0x2e,0xf7,0x21,0x38,0x98,0x28,0x2b,0xa9,0x43,0x12,0xf3,0x13,0xdf,0x2d,0xce,0x8d,0x41,0x64}; @@ -164,7 +185,11 @@ static lt_ret_t read_whole_I_config(lt_handle_t *h) if(ret != LT_OK) { return ret; } - printf("\t\t%s %08X\r\n", config_description[i].desc, check); +#if(BITNESS == 64) + printf("\t\t%s %08X\r\n", config_description[i].desc, check); +#else + printf("\t\t%s %08lX\r\n", config_description[i].desc, check); +#endif } printf("\r\n"); @@ -188,7 +213,11 @@ static lt_ret_t read_whole_R_config(lt_handle_t *h) if(ret != LT_OK) { return ret; } - printf("\t\t%s %08X\r\n", config_description[i].desc, check); +#if(BITNESS == 64) + printf("\t\t%s %08X\r\n", config_description[i].desc, check); +#else + printf("\t\t%s %08lX\r\n", config_description[i].desc, check); +#endif } printf("\r\n"); @@ -423,7 +452,6 @@ static lt_ret_t write_whole_R_config(lt_handle_t *h) * @return 0 if success, otherwise -1 */ static int session_initial(lt_handle_t *h) { - lt_ret_t ret; // Establish secure handshake with default H0 pairing keys LOG_OUT_SESSION("%s", "Creating session with initial factory keys H0"); @@ -463,7 +491,6 @@ static int session_initial(lt_handle_t *h) { * @return 0 if success, otherwise -1 */ static int session_H0(lt_handle_t *h) { - lt_ret_t ret; /* Establish secure handshake with default H0 pairing keys should fail, because this H0 key was invalidated at the end of initial session */ LOG_OUT_SESSION("%s", "Establish session with H0 must fail"); @@ -479,7 +506,6 @@ static int session_H0(lt_handle_t *h) { * @return 0 if success, otherwise -1 */ static int session_H1(lt_handle_t *h) { - lt_ret_t ret; /* Establish secure handshake with default H0 pairing keys */ LOG_OUT_SESSION("%s", "Creating session with H1 keys"); @@ -522,7 +548,6 @@ static int session_H1(lt_handle_t *h) { * @return 0 if success, otherwise -1 */ static int session_H2(lt_handle_t *h) { - lt_ret_t ret; LOG_OUT_SESSION("%s", "Creating session with H2 keys"); LT_ASSERT(LT_OK, verify_chip_and_start_secure_session(h, sh2priv, sh2pub, pkey_index_2)); @@ -564,7 +589,6 @@ static int session_H2(lt_handle_t *h) { * @return 0 if success, otherwise -1 */ static int session_H3(lt_handle_t *h) { - lt_ret_t ret; LOG_OUT_SESSION("%s", "Creating session with H3 keys"); LT_ASSERT(LT_OK, verify_chip_and_start_secure_session(h, sh3priv, sh3pub, pkey_index_3)); diff --git a/examples/hw_wallet/hw_wallet.h b/examples/hw_wallet/TROPIC01_hw_wallet.h similarity index 95% rename from examples/hw_wallet/hw_wallet.h rename to examples/hw_wallet/TROPIC01_hw_wallet.h index 1cd51a2..88c5115 100644 --- a/examples/hw_wallet/hw_wallet.h +++ b/examples/hw_wallet/TROPIC01_hw_wallet.h @@ -13,7 +13,6 @@ #define LOG_OUT_SESSION(f_, ...) printf("\t\t- "f_, ##__VA_ARGS__) #define LT_ASSERT(func, expected) \ - ret = (func); \ if(func!=expected) \ { \ printf("\t\t\tERROR\r\n"); return -1; \ diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 6c37e46..7e713f7 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -36,7 +36,7 @@ project(libtropic_unix_example add_executable(integration_tests main.c ${CMAKE_CURRENT_SOURCE_DIR}/${PATH_LIBTROPIC}hal/port/unix/lt_port_unix.c - ${CMAKE_CURRENT_SOURCE_DIR}/${PATH_LIBTROPIC}examples/hw_wallet/hw_wallet.c + ${CMAKE_CURRENT_SOURCE_DIR}/${PATH_LIBTROPIC}examples/hw_wallet/TROPIC01_hw_wallet.c ) target_include_directories(integration_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${PATH_LIBTROPIC}examples/hw_wallet/) diff --git a/tests/integration/main.c b/tests/integration/main.c index 031cf64..496f118 100644 --- a/tests/integration/main.c +++ b/tests/integration/main.c @@ -3,9 +3,9 @@ #include #include "string.h" -#include "hw_wallet.h" +#include "TROPIC01_hw_wallet.h" -// Code can be found in examples/hw/wallet/ +// Code can be found in examples/hw_wallet/ int main(void) { int x = tropic01_hw_wallet_example();