Skip to content

Commit

Permalink
Merge branch 'develop' of ssh://tropic-gitlab.corp.sldev.cz:7999/inte…
Browse files Browse the repository at this point in the history
…rnal/sw-design/libtropic into develop
  • Loading branch information
Jan Medek committed Oct 2, 2024
2 parents 9e4315a + 9ed9ca6 commit 17a4981
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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};
Expand Down Expand Up @@ -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");

Expand All @@ -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");

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <stdio.h>
#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();
Expand Down

0 comments on commit 17a4981

Please sign in to comment.