From 36b3e05fed4971eac765ba05d449bf2d3bb50098 Mon Sep 17 00:00:00 2001 From: Jun Luo <4catcode@gmail.com> Date: Sat, 18 May 2024 07:26:03 +0800 Subject: [PATCH] Update docs. --- .clang-format | 3 ++- .clusterfuzzlite/project.yaml | 2 +- docs/COMMANDS.md | 16 ++++++++-------- src/apdu/dispatcher.c | 6 +++--- src/constants.h | 4 ++-- src/handler/get_app_configuration.c | 8 ++++---- src/handler/sign_auth.c | 8 ++++---- src/handler/sign_tx.c | 10 +++++----- src/sw.h | 13 ++++++------- src/types.h | 6 +++--- 10 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.clang-format b/.clang-format index a3aaac99..12369a4e 100644 --- a/.clang-format +++ b/.clang-format @@ -7,13 +7,14 @@ ColumnLimit: 100 PointerAlignment: Right AlignAfterOpenBracket: Align AlignConsecutiveMacros: true +AllowAllParametersOfDeclarationOnNextLine: false SortIncludes: false SpaceAfterCStyleCast: true AllowShortCaseLabelsOnASingleLine: false AllowAllArgumentsOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: Never AllowShortFunctionsOnASingleLine: None BinPackArguments: false BinPackParameters: false --- + diff --git a/.clusterfuzzlite/project.yaml b/.clusterfuzzlite/project.yaml index e196c5cc..7f563eb7 100644 --- a/.clusterfuzzlite/project.yaml +++ b/.clusterfuzzlite/project.yaml @@ -1 +1 @@ -language: c \ No newline at end of file +language: c++ \ No newline at end of file diff --git a/docs/COMMANDS.md b/docs/COMMANDS.md index d6fc607d..e986833d 100644 --- a/docs/COMMANDS.md +++ b/docs/COMMANDS.md @@ -8,7 +8,7 @@ | `SIGN_TX` | 0x04 | Sign the raw transaction | | `GET_APP_CONFIGURATION` | 0x06 | Get application configuration information | | `SIGN_HASH` | 0x08 | Sign the hash | -| `INS_SIGN_SOROBAN_AUTHORATION` | 0x0A | Sign the Soroban Authoration | +| `SIGN_SOROBAN_AUTHORATION` | 0x0A | Sign the Soroban Authoration | ## GET_PUBLIC_KEY @@ -50,7 +50,7 @@ | Response length (bytes) | SW | RData | | ----------------------- | ------ | ---------------------------------------------------------------------------- | -| 4 | 0x9000 | `HASH_SIGNING_ENABLED (1)` \|\| `MAJOR (1)` \|\| `MINOR (1)` \|\| `PATCH (1)` \|\| `RAW_TX_MAX_SIZE (2)` | +| 4 | 0x9000 | `HASH_SIGNING_ENABLED (1)` \|\| `MAJOR (1)` \|\| `MINOR (1)` \|\| `PATCH (1)` \|\| `RAW_DATA_MAX_SIZE (2)` | ## SIGN_HASH @@ -66,7 +66,7 @@ | ----------------------- | ------ | ---------------- | | 64 | 0x9000 | `signature (64)` | -## INS_SIGN_SOROBAN_AUTHORATION +## SIGN_SOROBAN_AUTHORATION ### Command @@ -85,7 +85,7 @@ | SW | SW name | Description | | ------ | ------------------------------------- | ------------------------------------------------------- | -| 0x6125 | `SW_TX_FORMATTING_FAIL` | Failed to format transaction data | +| 0x6125 | `SW_FORMATTING_FAIL` | Failed to format the data | | 0x6985 | `SW_DENY` | Rejected by user | | 0x6A87 | `SW_WRONG_DATA_LENGTH` | `Lc` or minimum APDU lenght is incorrect | | 0x6B00 | `SW_WRONG_P1P2` | Either `P1` or `P2` is incorrect | @@ -94,10 +94,10 @@ | 0x6E00 | `SW_CLA_NOT_SUPPORTED` | Bad `CLA` used for this application | | 0xB002 | `SW_DISPLAY_ADDRESS_FAIL` | Failed to display address | | 0xB003 | `SW_DISPLAY_TRANSACTION_HASH_FAIL` | Failed to display transaction hash | -| 0xB004 | `SW_WRONG_TX_LENGTH` | Wrong raw transaction length | -| 0xB005 | `SW_TX_PARSING_FAIL` | Failed to parse raw transaction | -| 0xB006 | `SW_TX_HASH_FAIL` | Failed to compute hash digest of raw transaction | +| 0xB004 | `SW_DATA_TOO_LARGE` | The data is too large to be processed | +| 0xB005 | `SW_DATA_PARSING_FAIL` | Failed to parse raw data | +| 0xB006 | `SW_DATA_HASH_FAIL` | Failed to compute hash digest of raw data | | 0xB007 | `SW_BAD_STATE` | Security issue with bad state | -| 0xB008 | `SW_SIGNATURE_FAIL` | Signature of raw transaction or transaction hash failed | +| 0xB008 | `SW_SIGNATURE_FAIL` | Generating signature failed | | 0xB009 | `SW_SWAP_CHECKING_FAIL` | Failed to check swap params (maybe the data is invalid) | | 0x9000 | `SW_OK` | Success | diff --git a/src/apdu/dispatcher.c b/src/apdu/dispatcher.c index e28580c9..e824fbb2 100644 --- a/src/apdu/dispatcher.c +++ b/src/apdu/dispatcher.c @@ -40,7 +40,7 @@ int apdu_dispatcher(const command_t *cmd) { } if (G_called_from_swap) { - if (cmd->ins != GET_PUBLIC_KEY && cmd->ins != SIGN_TX) { + if (cmd->ins != INS_GET_PUBLIC_KEY && cmd->ins != INS_SIGN_TX) { PRINTF("Only GET_PUBLIC_KEY and SIGN_TX can be called during swap\n"); return io_send_sw(SW_INS_NOT_SUPPORTED); } @@ -54,7 +54,7 @@ int apdu_dispatcher(const command_t *cmd) { return io_send_sw(SW_WRONG_P1P2); } return handler_get_app_configuration(); - case GET_PUBLIC_KEY: + case INS_GET_PUBLIC_KEY: if (cmd->p1 != 0 || cmd->p2 > 1) { return io_send_sw(SW_WRONG_P1P2); } @@ -81,7 +81,7 @@ int apdu_dispatcher(const command_t *cmd) { buf.size = cmd->lc; buf.offset = 0; return handler_sign_hash(&buf); - case SIGN_TX: + case INS_SIGN_TX: if ((cmd->p1 != P1_FIRST && cmd->p1 != P1_MORE) || (cmd->p2 != P2_LAST && cmd->p2 != P2_MORE)) { return io_send_sw(SW_WRONG_P1P2); diff --git a/src/constants.h b/src/constants.h index cf537db2..0b837230 100644 --- a/src/constants.h +++ b/src/constants.h @@ -32,7 +32,7 @@ #define DETAIL_VALUE_MAX_LENGTH 105 #ifdef TARGET_NANOS -#define RAW_TX_MAX_SIZE 1536 +#define RAW_DATA_MAX_SIZE 1536 #else -#define RAW_TX_MAX_SIZE 10240 +#define RAW_DATA_MAX_SIZE 10240 #endif diff --git a/src/handler/get_app_configuration.c b/src/handler/get_app_configuration.c index c5a8252e..720b0d07 100644 --- a/src/handler/get_app_configuration.c +++ b/src/handler/get_app_configuration.c @@ -40,15 +40,15 @@ int handler_get_app_configuration() { "MINOR version must be between 0 and 255!"); _Static_assert(PATCH_VERSION >= 0 && PATCH_VERSION <= UINT8_MAX, "PATCH version must be between 0 and 255!"); - _Static_assert(RAW_TX_MAX_SIZE >= 0 && RAW_TX_MAX_SIZE <= UINT16_MAX, - "RAW_TX_MAX_SIZE must be between 0 and 65535!"); + _Static_assert(RAW_DATA_MAX_SIZE >= 0 && RAW_DATA_MAX_SIZE <= UINT16_MAX, + "RAW_DATA_MAX_SIZE must be between 0 and 65535!"); uint8_t config[] = {HAS_SETTING(S_HASH_SIGNING_ENABLED), MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, - RAW_TX_MAX_SIZE >> 8, - RAW_TX_MAX_SIZE & 0xFF}; + RAW_DATA_MAX_SIZE >> 8, + RAW_DATA_MAX_SIZE & 0xFF}; return io_send_response_pointer(config, sizeof(config), SW_OK); } diff --git a/src/handler/sign_auth.c b/src/handler/sign_auth.c index c2e6492c..82028f1b 100644 --- a/src/handler/sign_auth.c +++ b/src/handler/sign_auth.c @@ -40,8 +40,8 @@ int handler_sign_auth(buffer_t *cdata, bool is_first_chunk, bool more) { explicit_bzero(&G_context, sizeof(G_context)); } - if (G_context.raw_size + cdata->size > RAW_TX_MAX_SIZE) { - return io_send_sw(SW_WRONG_TX_LENGTH); + if (G_context.raw_size + cdata->size > RAW_DATA_MAX_SIZE) { + return io_send_sw(SW_DATA_TOO_LARGE); } if (is_first_chunk) { @@ -74,7 +74,7 @@ int handler_sign_auth(buffer_t *cdata, bool is_first_chunk, bool more) { if (!parse_soroban_authorization_envelope(G_context.raw, G_context.raw_size, &G_context.envelope)) { - return io_send_sw(SW_TX_PARSING_FAIL); + return io_send_sw(SW_DATA_PARSING_FAIL); } G_context.state = STATE_PARSED; @@ -89,7 +89,7 @@ int handler_sign_auth(buffer_t *cdata, bool is_first_chunk, bool more) { } if (cx_hash_sha256(G_context.raw, G_context.raw_size, G_context.hash, HASH_SIZE) != HASH_SIZE) { - return io_send_sw(SW_TX_HASH_FAIL); + return io_send_sw(SW_DATA_HASH_FAIL); } return ui_display_auth(); diff --git a/src/handler/sign_tx.c b/src/handler/sign_tx.c index 41e7fd7e..7b63714f 100644 --- a/src/handler/sign_tx.c +++ b/src/handler/sign_tx.c @@ -40,8 +40,8 @@ int handler_sign_tx(buffer_t *cdata, bool is_first_chunk, bool more) { explicit_bzero(&G_context, sizeof(G_context)); } - if (G_context.raw_size + cdata->size > RAW_TX_MAX_SIZE) { - return io_send_sw(SW_WRONG_TX_LENGTH); + if (G_context.raw_size + cdata->size > RAW_DATA_MAX_SIZE) { + return io_send_sw(SW_DATA_TOO_LARGE); } if (is_first_chunk) { @@ -72,7 +72,7 @@ int handler_sign_tx(buffer_t *cdata, bool is_first_chunk, bool more) { } if (!parse_transaction_envelope(G_context.raw, G_context.raw_size, &G_context.envelope)) { - return io_send_sw(SW_TX_PARSING_FAIL); + return io_send_sw(SW_DATA_PARSING_FAIL); } G_context.state = STATE_PARSED; @@ -97,7 +97,7 @@ int handler_sign_tx(buffer_t *cdata, bool is_first_chunk, bool more) { if (cx_hash_sha256(G_context.raw, G_context.raw_size, G_context.hash, HASH_SIZE) != HASH_SIZE) { - return io_send_sw(SW_TX_HASH_FAIL); + return io_send_sw(SW_DATA_HASH_FAIL); } if (crypto_sign_message(G_context.hash, @@ -124,7 +124,7 @@ int handler_sign_tx(buffer_t *cdata, bool is_first_chunk, bool more) { if (cx_hash_sha256(G_context.raw, G_context.raw_size, G_context.hash, HASH_SIZE) != HASH_SIZE) { - return io_send_sw(SW_TX_HASH_FAIL); + return io_send_sw(SW_DATA_HASH_FAIL); } return ui_display_transaction(); } diff --git a/src/sw.h b/src/sw.h index 5c895b55..60bdedf9 100644 --- a/src/sw.h +++ b/src/sw.h @@ -41,18 +41,17 @@ */ #define SW_DISPLAY_TRANSACTION_HASH_FAIL 0xB003 /** - * Status word for wrong transaction length. - * When the data requested by the user is too large, this exception will be thrown. + * Status word for the data is too large to be processed. */ -#define SW_WRONG_TX_LENGTH 0xB004 +#define SW_DATA_TOO_LARGE 0xB004 /** - * Status word for fail of transaction parsing. + * Status word for fail of data parsing. */ -#define SW_TX_PARSING_FAIL 0xB005 +#define SW_DATA_PARSING_FAIL 0xB005 /** - * Status word for fail of transaction hash. + * Status word for fail of data hash. */ -#define SW_TX_HASH_FAIL 0xB006 +#define SW_DATA_HASH_FAIL 0xB006 /** * Status word for bad state. */ diff --git a/src/types.h b/src/types.h index a0ce687b..f782258f 100644 --- a/src/types.h +++ b/src/types.h @@ -12,8 +12,8 @@ * Enumeration with expected INS of APDU commands. */ typedef enum { - GET_PUBLIC_KEY = 0x02, // public key of corresponding BIP32 path - SIGN_TX = 0x04, // sign transaction with BIP32 path + INS_GET_PUBLIC_KEY = 0x02, // public key of corresponding BIP32 path + INS_SIGN_TX = 0x04, // sign transaction with BIP32 path INS_GET_APP_CONFIGURATION = 0x06, // app configuration of the application INS_SIGN_HASH = 0x08, // sign transaction in hash mode INS_SIGN_SOROBAN_AUTHORATION = 0x0a, // sign soroban authoration @@ -48,7 +48,7 @@ enum e_state { */ typedef struct { envelope_t envelope; - uint8_t raw[RAW_TX_MAX_SIZE]; + uint8_t raw[RAW_DATA_MAX_SIZE]; uint32_t raw_size; uint8_t raw_public_key[RAW_ED25519_PUBLIC_KEY_SIZE]; // BIP32 path public key uint8_t hash[HASH_SIZE]; // tx hash