diff --git a/.clang-format b/.clang-format index 570f6354..c76e9fc2 100644 --- a/.clang-format +++ b/.clang-format @@ -6,8 +6,14 @@ Language: Cpp ColumnLimit: 100 PointerAlignment: Right AlignAfterOpenBracket: Align -AllowShortFunctionsOnASingleLine: None AlignConsecutiveMacros: true AllowAllParametersOfDeclarationOnNextLine: false SortIncludes: false +SpaceAfterCStyleCast: true +AllowShortCaseLabelsOnASingleLine: false +AllowAllArgumentsOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: None +BinPackArguments: false +BinPackParameters: false --- diff --git a/.github/workflows/lint-workflow.yml b/.github/workflows/lint-workflow.yml index 3a64caff..9b8eff43 100644 --- a/.github/workflows/lint-workflow.yml +++ b/.github/workflows/lint-workflow.yml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@v2 - name: Lint - uses: DoozyX/clang-format-lint-action@v0.5 + uses: DoozyX/clang-format-lint-action@v0.18 with: source: './src' extensions: 'h,c' diff --git a/src/monero_api.h b/src/monero_api.h index 2238d803..affd5255 100644 --- a/src/monero_api.h +++ b/src/monero_api.h @@ -89,8 +89,10 @@ void ui_menu_main_display(void); void ui_menu_show_security_error(void); void ui_menu_show_tx_aborted(void); void ui_export_viewkey_display(unsigned int value); -int ui_menu_any_pubaddr_display(unsigned int value, unsigned char *pub_view, - unsigned char *pub_spend, unsigned char is_subbadress, +int ui_menu_any_pubaddr_display(unsigned int value, + unsigned char *pub_view, + unsigned char *pub_spend, + unsigned char is_subbadress, unsigned char *paymanetID); void ui_menu_pubaddr_display(unsigned int value); @@ -99,10 +101,13 @@ unsigned int ui_menu_transaction_signed(void); /* ----------------------------------------------------------------------- */ /* --- MISC ---- */ /* ----------------------------------------------------------------------- */ -#define OFFSETOF(type, field) ((unsigned int)&(((type *)NULL)->field)) +#define OFFSETOF(type, field) ((unsigned int) &(((type *) NULL)->field)) -int monero_base58_public_key(char *str_b58, unsigned char *view, unsigned char *spend, - unsigned char is_subbadress, unsigned char *paymanetID); +int monero_base58_public_key(char *str_b58, + unsigned char *view, + unsigned char *spend, + unsigned char is_subbadress, + unsigned char *paymanetID); /** unsigned varint amount to uint64 */ uint64_t monero_vamount2uint64(unsigned char *binary); @@ -119,8 +124,13 @@ unsigned int monero_amount2str(uint64_t xmr, char *str, unsigned int str_len); unsigned int monero_uint642str(uint64_t val, char *str, unsigned int str_len); int monero_abort_tx(void); -int monero_unblind(unsigned char *v, unsigned char *k, unsigned char *AKout, - unsigned int short_amount, size_t v_len, size_t k_len, size_t AKout_len); +int monero_unblind(unsigned char *v, + unsigned char *k, + unsigned char *AKout, + unsigned int short_amount, + size_t v_len, + size_t k_len, + size_t AKout_len); void ui_menu_validation_display(unsigned int value); void ui_menu_validation_display_last(unsigned int value); void ui_menu_fee_validation_display(unsigned int value); @@ -140,13 +150,19 @@ extern const unsigned char C_FAKE_SEC_SPEND_KEY[KEY_SIZE]; int is_fake_view_key(unsigned char *s); int is_fake_spend_key(unsigned char *s); -int monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes, size_t ge_len, +int monero_ge_fromfe_frombytes(unsigned char *ge, + unsigned char *bytes, + size_t ge_len, size_t bytes_len); void monero_sc_add(unsigned char *r, unsigned char *s1, unsigned char *s2); -int monero_hash_to_scalar(unsigned char *scalar, unsigned char *raw, size_t scalar_len, +int monero_hash_to_scalar(unsigned char *scalar, + unsigned char *raw, + size_t scalar_len, unsigned int len); int monero_hash_to_ec(unsigned char *ec, unsigned char *ec_pub, size_t ec_len); -int monero_generate_keypair(unsigned char *ec_pub, unsigned char *ec_priv, size_t ec_pub_len, +int monero_generate_keypair(unsigned char *ec_pub, + unsigned char *ec_priv, + size_t ec_pub_len, size_t ec_priv_len); /* * compute s = 8 * (k*P) @@ -155,10 +171,17 @@ int monero_generate_keypair(unsigned char *ec_pub, unsigned char *ec_priv, size_ * P [in] point in 02 y or 04 x y format * k [in] 32 bytes scalar */ -int monero_generate_key_derivation(unsigned char *drv_data, unsigned char *P, unsigned char *scalar, - size_t drv_data_len, size_t P_len, size_t scalar_len); -int monero_derivation_to_scalar(unsigned char *scalar, unsigned char *drv_data, - unsigned int out_idx, size_t scalar_len, size_t drv_data_len); +int monero_generate_key_derivation(unsigned char *drv_data, + unsigned char *P, + unsigned char *scalar, + size_t drv_data_len, + size_t P_len, + size_t scalar_len); +int monero_derivation_to_scalar(unsigned char *scalar, + unsigned char *drv_data, + unsigned int out_idx, + size_t scalar_len, + size_t drv_data_len); /* * compute x = Hps(drv_data,out_idx) + ec_pv * @@ -166,8 +189,12 @@ int monero_derivation_to_scalar(unsigned char *scalar, unsigned char *drv_data, * drv_data [in] 32 bytes derivation data (point) * ec_pv [in] 32 bytes private key */ -int monero_derive_secret_key(unsigned char *x, unsigned char *drv_data, unsigned int out_idx, - unsigned char *ec_priv, size_t x_len, size_t drv_data_len, +int monero_derive_secret_key(unsigned char *x, + unsigned char *drv_data, + unsigned int out_idx, + unsigned char *ec_priv, + size_t x_len, + size_t drv_data_len, size_t ec_priv_len); /* * compute x = Hps(drv_data,out_idx)*G + ec_pub @@ -176,25 +203,49 @@ int monero_derive_secret_key(unsigned char *x, unsigned char *drv_data, unsigned * drv_data [in] 32 bytes derivation data (point) * ec_pub [in] 32 bytes public key */ -int monero_derive_public_key(unsigned char *x, unsigned char *drv_data, unsigned int out_idx, - unsigned char *ec_pub, size_t x_len, size_t drv_data_len, +int monero_derive_public_key(unsigned char *x, + unsigned char *drv_data, + unsigned int out_idx, + unsigned char *ec_pub, + size_t x_len, + size_t drv_data_len, size_t ec_pub_len); -int monero_secret_key_to_public_key(unsigned char *ec_pub, unsigned char *ec_priv, - size_t ec_pub_len, size_t ec_priv_len); -int monero_generate_key_image(unsigned char *img, unsigned char *P, unsigned char *x, - size_t img_len, size_t x_len); -int monero_derive_view_tag(unsigned char *view_tag, const unsigned char drv_data[static 32], +int monero_secret_key_to_public_key(unsigned char *ec_pub, + unsigned char *ec_priv, + size_t ec_pub_len, + size_t ec_priv_len); +int monero_generate_key_image(unsigned char *img, + unsigned char *P, + unsigned char *x, + size_t img_len, + size_t x_len); +int monero_derive_view_tag(unsigned char *view_tag, + const unsigned char drv_data[static 32], unsigned int out_idx); -int monero_derive_subaddress_public_key(unsigned char *x, unsigned char *pub, - unsigned char *drv_data, unsigned int index, size_t x_len, - size_t pub_len, size_t drv_data_len); -int monero_get_subaddress_spend_public_key(unsigned char *x, unsigned char *index, size_t x_len, +int monero_derive_subaddress_public_key(unsigned char *x, + unsigned char *pub, + unsigned char *drv_data, + unsigned int index, + size_t x_len, + size_t pub_len, + size_t drv_data_len); +int monero_get_subaddress_spend_public_key(unsigned char *x, + unsigned char *index, + size_t x_len, size_t index_len); -int monero_get_subaddress(unsigned char *C, unsigned char *D, unsigned char *index, size_t C_len, - size_t D_len, size_t index_len); -int monero_get_subaddress_secret_key(unsigned char *sub_s, unsigned char *s, unsigned char *index, - size_t sub_s_len, size_t s_len, size_t index_len); +int monero_get_subaddress(unsigned char *C, + unsigned char *D, + unsigned char *index, + size_t C_len, + size_t D_len, + size_t index_len); +int monero_get_subaddress_secret_key(unsigned char *sub_s, + unsigned char *s, + unsigned char *index, + size_t sub_s_len, + size_t s_len, + size_t index_len); void monero_clear_words(void); /* ----------------------------------------------------------------------- */ @@ -210,52 +261,55 @@ int monero_hash_init_keccak(cx_hash_t *hasher); void monero_hash_init_sha256(cx_hash_t *hasher); int monero_hash_update(cx_hash_t *hasher, const unsigned char *buf, unsigned int len); int monero_hash_final(cx_hash_t *hasher, unsigned char *out); -int monero_hash(unsigned int algo, cx_hash_t *hasher, const unsigned char *buf, unsigned int len, +int monero_hash(unsigned int algo, + cx_hash_t *hasher, + const unsigned char *buf, + unsigned int len, unsigned char *out); static inline int monero_keccak_F(unsigned char *buf, size_t len, unsigned char *out) { - return monero_hash(CX_KECCAK, (cx_hash_t *)&G_monero_vstate.keccakF, buf, len, out); + return monero_hash(CX_KECCAK, (cx_hash_t *) &G_monero_vstate.keccakF, buf, len, out); } static inline int monero_keccak_init_H(void) { - return monero_hash_init_keccak((cx_hash_t *)&G_monero_vstate.keccakH); + return monero_hash_init_keccak((cx_hash_t *) &G_monero_vstate.keccakH); } static inline int monero_keccak_update_H(const unsigned char *buf, size_t len) { - return monero_hash_update((cx_hash_t *)&G_monero_vstate.keccakH, buf, len); + return monero_hash_update((cx_hash_t *) &G_monero_vstate.keccakH, buf, len); } static inline int monero_keccak_final_H(unsigned char *out) { - return monero_hash_final((cx_hash_t *)&G_monero_vstate.keccakH, out); + return monero_hash_final((cx_hash_t *) &G_monero_vstate.keccakH, out); } static inline int monero_keccak_H(const unsigned char *buf, size_t len, unsigned char *out) { - return monero_hash(CX_KECCAK, (cx_hash_t *)&G_monero_vstate.keccakH, buf, len, out); + return monero_hash(CX_KECCAK, (cx_hash_t *) &G_monero_vstate.keccakH, buf, len, out); } static inline void monero_sha256_commitment_init(void) { - monero_hash_init_sha256((cx_hash_t *)&G_monero_vstate.sha256_commitment); + monero_hash_init_sha256((cx_hash_t *) &G_monero_vstate.sha256_commitment); } static inline int monero_sha256_commitment_update(const unsigned char *buf, size_t len) { - return monero_hash_update((cx_hash_t *)&G_monero_vstate.sha256_commitment, buf, len); + return monero_hash_update((cx_hash_t *) &G_monero_vstate.sha256_commitment, buf, len); } static inline int monero_sha256_commitment_final(unsigned char *out) { unsigned char *digest = out ? out : G_monero_vstate.C; - return monero_hash_final((cx_hash_t *)&G_monero_vstate.sha256_commitment, digest); + return monero_hash_final((cx_hash_t *) &G_monero_vstate.sha256_commitment, digest); } static inline void monero_sha256_outkeys_init(void) { - monero_hash_init_sha256((cx_hash_t *)&G_monero_vstate.sha256_out_keys); + monero_hash_init_sha256((cx_hash_t *) &G_monero_vstate.sha256_out_keys); } static inline int monero_sha256_outkeys_update(const unsigned char *buf, size_t len) { - return monero_hash_update((cx_hash_t *)&G_monero_vstate.sha256_out_keys, buf, len); + return monero_hash_update((cx_hash_t *) &G_monero_vstate.sha256_out_keys, buf, len); } static inline int monero_sha256_outkeys_final(unsigned char *out) { - return monero_hash_final((cx_hash_t *)&G_monero_vstate.sha256_out_keys, out); + return monero_hash_final((cx_hash_t *) &G_monero_vstate.sha256_out_keys, out); } /* @@ -271,13 +325,17 @@ unsigned int monero_check_scalar_not_null(unsigned char *s); /** * LE-7-bits encoding. High bit set says one more byte to decode. */ -unsigned int monero_encode_varint(unsigned char *varint, unsigned int max_len, uint64_t v, +unsigned int monero_encode_varint(unsigned char *varint, + unsigned int max_len, + uint64_t v, unsigned int *out_len); /** * LE-7-bits decoding. High bit set says one more byte to decode. */ -unsigned int monero_decode_varint(const unsigned char *varint, size_t max_len, uint64_t *value, +unsigned int monero_decode_varint(const unsigned char *varint, + size_t max_len, + uint64_t *value, unsigned int *out_len); /** */ @@ -286,19 +344,30 @@ int monero_reverse32(unsigned char *rscal, unsigned char *scal, size_t rscal_len /** * Hps: keccak(drv_data|varint(out_idx)) */ -int monero_derivation_to_scalar(unsigned char *scalar, unsigned char *drv_data, - unsigned int out_idx, size_t scalar_len, size_t drv_data_len); +int monero_derivation_to_scalar(unsigned char *scalar, + unsigned char *drv_data, + unsigned int out_idx, + size_t scalar_len, + size_t drv_data_len); /* * W = k.P */ -int monero_ecmul_k(unsigned char *W, unsigned char *P, unsigned char *scalar32, size_t W_len, - size_t P_len, size_t scalar32_len); +int monero_ecmul_k(unsigned char *W, + unsigned char *P, + unsigned char *scalar32, + size_t W_len, + size_t P_len, + size_t scalar32_len); /* * W = 8k.P */ -int monero_ecmul_8k(unsigned char *W, unsigned char *P, unsigned char *scalar32, size_t W_len, - size_t P_len, size_t scalar32_len); +int monero_ecmul_8k(unsigned char *W, + unsigned char *P, + unsigned char *scalar32, + size_t W_len, + size_t P_len, + size_t scalar32_len); /* * W = 8.P @@ -328,24 +397,44 @@ int monero_genCommitmentMask(unsigned char *c, unsigned char *sk, size_t c_len, /* * W = P+Q */ -int monero_ecadd(unsigned char *W, unsigned char *P, unsigned char *Q, size_t W_len, size_t P_len, +int monero_ecadd(unsigned char *W, + unsigned char *P, + unsigned char *Q, + size_t W_len, + size_t P_len, size_t Q_len); /* * W = P-Q */ -int monero_ecsub(unsigned char *W, unsigned char *P, unsigned char *Q, size_t W_len, size_t P_len, +int monero_ecsub(unsigned char *W, + unsigned char *P, + unsigned char *Q, + size_t W_len, + size_t P_len, size_t Q_len); /* r = (a+b) %order */ -int monero_addm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_len, size_t a_len, +int monero_addm(unsigned char *r, + unsigned char *a, + unsigned char *b, + size_t r_len, + size_t a_len, size_t b_len); /* r = (a-b) %order */ -int monero_subm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_len, size_t a_len, +int monero_subm(unsigned char *r, + unsigned char *a, + unsigned char *b, + size_t r_len, + size_t a_len, size_t b_len); /* r = (a*b) %order */ -int monero_multm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_len, size_t a_len, +int monero_multm(unsigned char *r, + unsigned char *a, + unsigned char *b, + size_t r_len, + size_t a_len, size_t b_len); /* r = (a*8) %order */ diff --git a/src/monero_blind.c b/src/monero_blind.c index 47b15aa5..97a65fa7 100644 --- a/src/monero_blind.c +++ b/src/monero_blind.c @@ -83,8 +83,13 @@ int monero_apdu_blind() { /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_unblind(unsigned char *v, unsigned char *k, unsigned char *AKout, - unsigned int short_amount, size_t v_len, size_t k_len, size_t AKout_len) { +int monero_unblind(unsigned char *v, + unsigned char *k, + unsigned char *AKout, + unsigned int short_amount, + size_t v_len, + size_t k_len, + size_t AKout_len) { int error; if (short_amount == 2) { error = monero_genCommitmentMask(k, AKout, k_len, AKout_len); @@ -144,7 +149,12 @@ int monero_apdu_unblind() { monero_io_discard(1); - err = monero_unblind(v, k, AKout, G_monero_vstate.options & 0x03, sizeof(v), sizeof(k), + err = monero_unblind(v, + k, + AKout, + G_monero_vstate.options & 0x03, + sizeof(v), + sizeof(k), sizeof(AKout)); if (err) { return err; diff --git a/src/monero_clsag.c b/src/monero_clsag.c index f81c2277..dd9877fe 100644 --- a/src/monero_clsag.c +++ b/src/monero_clsag.c @@ -238,7 +238,9 @@ int monero_apdu_clsag_sign() { return err; } - err = monero_reduce(G_monero_vstate.c, G_monero_vstate.c, sizeof(G_monero_vstate.c), + err = monero_reduce(G_monero_vstate.c, + G_monero_vstate.c, + sizeof(G_monero_vstate.c), sizeof(G_monero_vstate.c)); if (err) { return err; @@ -266,7 +268,11 @@ int monero_apdu_clsag_sign() { return err; } // mu_P = c * (p*mu_P + mu_C*z) - err = monero_multm(mu_P, G_monero_vstate.c, s, sizeof(mu_P), sizeof(G_monero_vstate.c), + err = monero_multm(mu_P, + G_monero_vstate.c, + s, + sizeof(mu_P), + sizeof(G_monero_vstate.c), sizeof(s)); if (err) { return err; diff --git a/src/monero_crypto.c b/src/monero_crypto.c index 713f2330..d19a7c21 100644 --- a/src/monero_crypto.c +++ b/src/monero_crypto.c @@ -31,11 +31,71 @@ static unsigned char const WIDE C_ED25519_G[] = { // uncompressed 0x04, // x - 0x21, 0x69, 0x36, 0xd3, 0xcd, 0x6e, 0x53, 0xfe, 0xc0, 0xa4, 0xe2, 0x31, 0xfd, 0xd6, 0xdc, 0x5c, - 0x69, 0x2c, 0xc7, 0x60, 0x95, 0x25, 0xa7, 0xb2, 0xc9, 0x56, 0x2d, 0x60, 0x8f, 0x25, 0xd5, 0x1a, + 0x21, + 0x69, + 0x36, + 0xd3, + 0xcd, + 0x6e, + 0x53, + 0xfe, + 0xc0, + 0xa4, + 0xe2, + 0x31, + 0xfd, + 0xd6, + 0xdc, + 0x5c, + 0x69, + 0x2c, + 0xc7, + 0x60, + 0x95, + 0x25, + 0xa7, + 0xb2, + 0xc9, + 0x56, + 0x2d, + 0x60, + 0x8f, + 0x25, + 0xd5, + 0x1a, // y - 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x58}; + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x66, + 0x58}; static unsigned char const WIDE C_ED25519_Hy[] = { 0x8b, 0x65, 0x59, 0x70, 0x15, 0x37, 0x99, 0xaf, 0x2a, 0xea, 0xdc, 0x9f, 0xf1, 0xad, 0xd0, 0xea, @@ -102,7 +162,9 @@ int monero_aes_derive(cx_aes_key_t *sk, unsigned char *seed32, unsigned char *a, /* ----------------------------------------------------------------------- */ /* --- assert: max_len>0 --- */ /* ----------------------------------------------------------------------- */ -unsigned int monero_encode_varint(unsigned char *varint, unsigned int max_len, uint64_t value, +unsigned int monero_encode_varint(unsigned char *varint, + unsigned int max_len, + uint64_t value, unsigned int *out_len) { if (!varint || !out_len) { PRINTF("Buffer Error: %s:%d \n", __LINE__); @@ -126,7 +188,9 @@ unsigned int monero_encode_varint(unsigned char *varint, unsigned int max_len, u /* ----------------------------------------------------------------------- */ /* --- assert: max_len>0 --- */ /* ----------------------------------------------------------------------- */ -unsigned int monero_decode_varint(const unsigned char *varint, size_t max_len, uint64_t *value, +unsigned int monero_decode_varint(const unsigned char *varint, + size_t max_len, + uint64_t *value, unsigned int *out_len) { uint64_t v; size_t len; @@ -140,11 +204,11 @@ unsigned int monero_decode_varint(const unsigned char *varint, size_t max_len, u if (len == (max_len - 1)) { return SW_WRONG_DATA_RANGE; } - v = v + ((uint64_t)((varint[len]) & 0x7f) << (len * 7)); + v = v + ((uint64_t) ((varint[len]) & 0x7f) << (len * 7)); len++; } - v = v + ((uint64_t)((varint[len]) & 0x7f) << (len * 7)); + v = v + ((uint64_t) ((varint[len]) & 0x7f) << (len * 7)); *value = v; *out_len = len + 1; return 0; @@ -176,11 +240,11 @@ int monero_reverse32(unsigned char *rscal, unsigned char *scal, size_t rscal_len /* --- --- */ /* ----------------------------------------------------------------------- */ void monero_hash_init_sha256(cx_hash_t *hasher) { - cx_sha256_init((cx_sha256_t *)hasher); + cx_sha256_init((cx_sha256_t *) hasher); } int monero_hash_init_keccak(cx_hash_t *hasher) { - int error = cx_keccak_init_no_throw((cx_sha3_t *)hasher, 256); + int error = cx_keccak_init_no_throw((cx_sha3_t *) hasher, 256); if (error) { return SW_SECURITY_INTERNAL; } @@ -212,13 +276,16 @@ int monero_hash_final(cx_hash_t *hasher, unsigned char *out) { /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_hash(unsigned int algo, cx_hash_t *hasher, const unsigned char *buf, unsigned int len, +int monero_hash(unsigned int algo, + cx_hash_t *hasher, + const unsigned char *buf, + unsigned int len, unsigned char *out) { int err = 0; if (algo == CX_SHA256) { - cx_sha256_init((cx_sha256_t *)hasher); + cx_sha256_init((cx_sha256_t *) hasher); } else { - err = cx_keccak_init_no_throw((cx_sha3_t *)hasher, 256); + err = cx_keccak_init_no_throw((cx_sha3_t *) hasher, 256); if (err) { return SW_SECURITY_INTERNAL; } @@ -338,10 +405,12 @@ const unsigned char C_fe_qm5div8[] = { 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd}; -int monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes, size_t ge_len, +int monero_ge_fromfe_frombytes(unsigned char *ge, + unsigned char *bytes, + size_t ge_len, size_t bytes_len) { int error = 0; -#define MOD (unsigned char *)C_ED25519_FIELD, 32 +#define MOD (unsigned char *) C_ED25519_FIELD, 32 #define fe_isnegative(f) (f[31] & 1) #define u (G_monero_vstate.io_buffer + 0 * 32) #define v (G_monero_vstate.io_buffer + 1 * 32) @@ -383,17 +452,17 @@ int monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes, size_t g } // cx works in BE error |= monero_reverse32(u, bytes, 32, bytes_len); - error |= cx_math_modm_no_throw(u, 32, (unsigned char *)C_ED25519_FIELD, 32); + error |= cx_math_modm_no_throw(u, 32, (unsigned char *) C_ED25519_FIELD, 32); // go on error |= cx_math_multm_no_throw(v, u, u, MOD); /* 2 * u^2 */ error |= cx_math_addm_no_throw(v, v, v, MOD); explicit_bzero(w, 32); - w[31] = 1; /* w = 1 */ - error |= cx_math_addm_no_throw(w, v, w, MOD); /* w = 2 * u^2 + 1 */ - error |= cx_math_multm_no_throw(x, w, w, MOD); /* w^2 */ - error |= cx_math_multm_no_throw(y, (unsigned char *)C_fe_ma2, v, MOD); /* -2 * A^2 * u^2 */ + w[31] = 1; /* w = 1 */ + error |= cx_math_addm_no_throw(w, v, w, MOD); /* w = 2 * u^2 + 1 */ + error |= cx_math_multm_no_throw(x, w, w, MOD); /* w^2 */ + error |= cx_math_multm_no_throw(y, (unsigned char *) C_fe_ma2, v, MOD); /* -2 * A^2 * u^2 */ error |= cx_math_addm_no_throw(x, x, y, MOD); /* x = w^2 - 2 * A^2 * u^2 */ // inline fe_divpowm1(r->X, w, x); // (w / x)^(m + 1) => fe_divpowm1(r,u,v) @@ -404,7 +473,10 @@ int monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes, size_t g error |= cx_math_multm_no_throw(uv7, v3, v3, MOD); error |= cx_math_multm_no_throw(uv7, uv7, _v, MOD); error |= cx_math_multm_no_throw(uv7, uv7, _u, MOD); /* uv7 = uv^7 */ - error |= cx_math_powm_no_throw(uv7, uv7, (unsigned char *)C_fe_qm5div8, 32, + error |= cx_math_powm_no_throw(uv7, + uv7, + (unsigned char *) C_fe_qm5div8, + 32, MOD); /* (uv^7)^((q-5)/8)*/ error |= cx_math_multm_no_throw(uv7, uv7, v3, MOD); error |= cx_math_multm_no_throw(rX, uv7, w, MOD); /* u^(m+1)v^(-(m+1)) */ @@ -421,10 +493,10 @@ int monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes, size_t g if (!cx_math_is_zero(y, 32)) { goto negative; } else { - error |= cx_math_multm_no_throw(rX, rX, (unsigned char *)C_fe_fffb1, MOD); + error |= cx_math_multm_no_throw(rX, rX, (unsigned char *) C_fe_fffb1, MOD); } } else { - error |= cx_math_multm_no_throw(rX, rX, (unsigned char *)C_fe_fffb2, MOD); + error |= cx_math_multm_no_throw(rX, rX, (unsigned char *) C_fe_fffb2, MOD); } error |= cx_math_multm_no_throw(rX, rX, u, MOD); // u * sqrt(2 * A * (A + 2) * w / x) error |= cx_math_multm_no_throw(z, z, v, MOD); // -2 * A * u^2 @@ -433,13 +505,13 @@ int monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes, size_t g goto setsign; negative: - error |= cx_math_multm_no_throw(x, x, (unsigned char *)C_fe_sqrtm1, MOD); + error |= cx_math_multm_no_throw(x, x, (unsigned char *) C_fe_sqrtm1, MOD); error |= cx_math_subm_no_throw(y, w, x, MOD); if (!cx_math_is_zero(y, 32)) { error |= cx_math_addm_no_throw(y, w, x, MOD); - error |= cx_math_multm_no_throw(rX, rX, (unsigned char *)C_fe_fffb3, MOD); + error |= cx_math_multm_no_throw(rX, rX, (unsigned char *) C_fe_fffb3, MOD); } else { - error |= cx_math_multm_no_throw(rX, rX, (unsigned char *)C_fe_fffb4, MOD); + error |= cx_math_multm_no_throw(rX, rX, (unsigned char *) C_fe_fffb4, MOD); } // r->X = sqrt(A * (A + 2) * w / x) // z = -A @@ -447,7 +519,7 @@ int monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes, size_t g setsign: if (fe_isnegative(rX) != sign) { - error |= cx_math_sub(rX, (unsigned char *)C_ED25519_FIELD, rX, 32); + error |= cx_math_sub(rX, (unsigned char *) C_ED25519_FIELD, rX, 32); } error |= cx_math_addm_no_throw(rZ, z, w, MOD); error |= cx_math_subm_no_throw(rY, z, w, MOD); @@ -489,7 +561,9 @@ int monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes, size_t g /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_hash_to_scalar(unsigned char *scalar, unsigned char *raw, size_t scalar_len, +int monero_hash_to_scalar(unsigned char *scalar, + unsigned char *raw, + size_t scalar_len, unsigned int raw_len) { int error; @@ -530,7 +604,9 @@ int monero_hash_to_ec(unsigned char *ec, unsigned char *ec_pub, size_t ec_len) { /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_generate_keypair(unsigned char *ec_pub, unsigned char *ec_priv, size_t ec_pub_len, +int monero_generate_keypair(unsigned char *ec_pub, + unsigned char *ec_priv, + size_t ec_pub_len, size_t ec_priv_len) { int error; error = monero_rng_mod_order(ec_priv, ec_priv_len); @@ -548,16 +624,23 @@ int monero_generate_keypair(unsigned char *ec_pub, unsigned char *ec_priv, size_ /* ----------------------------------------------------------------------- */ /* --- ok --- */ /* ----------------------------------------------------------------------- */ -int monero_generate_key_derivation(unsigned char *drv_data, unsigned char *P, unsigned char *scalar, - size_t drv_data_len, size_t P_len, size_t scalar_len) { +int monero_generate_key_derivation(unsigned char *drv_data, + unsigned char *P, + unsigned char *scalar, + size_t drv_data_len, + size_t P_len, + size_t scalar_len) { return monero_ecmul_8k(drv_data, P, scalar, drv_data_len, P_len, scalar_len); } /* ----------------------------------------------------------------------- */ /* --- ok --- */ /* ----------------------------------------------------------------------- */ -int monero_derivation_to_scalar(unsigned char *scalar, unsigned char *drv_data, - unsigned int out_idx, size_t scalar_len, size_t drv_data_len) { +int monero_derivation_to_scalar(unsigned char *scalar, + unsigned char *drv_data, + unsigned int out_idx, + size_t scalar_len, + size_t drv_data_len) { unsigned char varint[32 + 8]; unsigned int len_varint; int error = 0; @@ -589,8 +672,12 @@ int monero_derivation_to_scalar(unsigned char *scalar, unsigned char *drv_data, /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_derive_secret_key(unsigned char *x, unsigned char *drv_data, unsigned int out_idx, - unsigned char *ec_priv, size_t x_len, size_t drv_data_len, +int monero_derive_secret_key(unsigned char *x, + unsigned char *drv_data, + unsigned int out_idx, + unsigned char *ec_priv, + size_t x_len, + size_t drv_data_len, size_t ec_priv_len) { unsigned char tmp[32]; int error; @@ -612,8 +699,12 @@ int monero_derive_secret_key(unsigned char *x, unsigned char *drv_data, unsigned /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_derive_public_key(unsigned char *x, unsigned char *drv_data, unsigned int out_idx, - unsigned char *ec_pub, size_t x_len, size_t drv_data_len, +int monero_derive_public_key(unsigned char *x, + unsigned char *drv_data, + unsigned int out_idx, + unsigned char *ec_pub, + size_t x_len, + size_t drv_data_len, size_t ec_pub_len) { unsigned char tmp[32]; @@ -638,16 +729,21 @@ int monero_derive_public_key(unsigned char *x, unsigned char *drv_data, unsigned /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_secret_key_to_public_key(unsigned char *ec_pub, unsigned char *ec_priv, - size_t ec_pub_len, size_t ec_priv_len) { +int monero_secret_key_to_public_key(unsigned char *ec_pub, + unsigned char *ec_priv, + size_t ec_pub_len, + size_t ec_priv_len) { return monero_ecmul_G(ec_pub, ec_priv, ec_pub_len, ec_priv_len); } /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_generate_key_image(unsigned char *img, unsigned char *P, unsigned char *x, - size_t img_len, size_t x_len) { +int monero_generate_key_image(unsigned char *img, + unsigned char *P, + unsigned char *x, + size_t img_len, + size_t x_len) { unsigned char I[32]; int error; error = monero_hash_to_ec(I, P, sizeof(I)); @@ -665,7 +761,8 @@ int monero_generate_key_image(unsigned char *img, unsigned char *P, unsigned cha /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_derive_view_tag(unsigned char *view_tag, const unsigned char drv_data[static 32], +int monero_derive_view_tag(unsigned char *view_tag, + const unsigned char drv_data[static 32], unsigned int out_idx) { unsigned char varint[8 + 32 + 8]; unsigned int len_varint; @@ -695,9 +792,13 @@ int monero_derive_view_tag(unsigned char *view_tag, const unsigned char drv_data /* ----------------------------------------------------------------------- */ /* --- ok --- */ /* ----------------------------------------------------------------------- */ -int monero_derive_subaddress_public_key(unsigned char *x, unsigned char *pub, - unsigned char *drv_data, unsigned int index, size_t x_len, - size_t pub_len, size_t drv_data_len) { +int monero_derive_subaddress_public_key(unsigned char *x, + unsigned char *pub, + unsigned char *drv_data, + unsigned int index, + size_t x_len, + size_t pub_len, + size_t drv_data_len) { unsigned char scalarG[32]; int error; @@ -719,12 +820,18 @@ int monero_derive_subaddress_public_key(unsigned char *x, unsigned char *pub, /* ----------------------------------------------------------------------- */ /* --- ok --- */ /* ----------------------------------------------------------------------- */ -int monero_get_subaddress_spend_public_key(unsigned char *x, unsigned char *index, size_t x_len, +int monero_get_subaddress_spend_public_key(unsigned char *x, + unsigned char *index, + size_t x_len, size_t index_len) { int error; // m = Hs(a || index_major || index_minor) - error = monero_get_subaddress_secret_key(x, G_monero_vstate.a, index, x_len, - sizeof(G_monero_vstate.a), index_len); + error = monero_get_subaddress_secret_key(x, + G_monero_vstate.a, + index, + x_len, + sizeof(G_monero_vstate.a), + index_len); if (error) { return error; } @@ -746,8 +853,12 @@ int monero_get_subaddress_spend_public_key(unsigned char *x, unsigned char *inde /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_get_subaddress(unsigned char *C, unsigned char *D, unsigned char *index, size_t C_len, - size_t D_len, size_t index_len) { +int monero_get_subaddress(unsigned char *C, + unsigned char *D, + unsigned char *index, + size_t C_len, + size_t D_len, + size_t index_len) { // retrieve D int error = monero_get_subaddress_spend_public_key(D, index, D_len, index_len); if (error) { @@ -766,8 +877,12 @@ int monero_get_subaddress(unsigned char *C, unsigned char *D, unsigned char *ind /* ----------------------------------------------------------------------- */ static const char C_sub_address_prefix[] = {'S', 'u', 'b', 'A', 'd', 'd', 'r', 0}; -int monero_get_subaddress_secret_key(unsigned char *sub_s, unsigned char *s, unsigned char *index, - size_t sub_s_len, size_t s_len, size_t index_len) { +int monero_get_subaddress_secret_key(unsigned char *sub_s, + unsigned char *s, + unsigned char *index, + size_t sub_s_len, + size_t s_len, + size_t index_len) { unsigned char in[sizeof(C_sub_address_prefix) + 32 + 8]; int error; @@ -897,8 +1012,12 @@ int monero_ecmul_H(unsigned char *W, unsigned char *scalar32, size_t W_len, size /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_ecmul_k(unsigned char *W, unsigned char *P, unsigned char *scalar32, size_t W_len, - size_t P_len, size_t scalar32_len) { +int monero_ecmul_k(unsigned char *W, + unsigned char *P, + unsigned char *scalar32, + size_t W_len, + size_t P_len, + size_t scalar32_len) { unsigned char Pxy[PXY_SIZE]; unsigned char s[32]; int error = 0; @@ -934,8 +1053,12 @@ int monero_ecmul_k(unsigned char *W, unsigned char *P, unsigned char *scalar32, /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_ecmul_8k(unsigned char *W, unsigned char *P, unsigned char *scalar32, size_t W_len, - size_t P_len, size_t scalar32_len) { +int monero_ecmul_8k(unsigned char *W, + unsigned char *P, + unsigned char *scalar32, + size_t W_len, + size_t P_len, + size_t scalar32_len) { unsigned char s[32]; int error = 0; error = monero_multm_8(s, scalar32, sizeof(s), scalar32_len); @@ -984,7 +1107,11 @@ int monero_ecmul_8(unsigned char *W, unsigned char *P, size_t W_len, size_t P_le /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_ecadd(unsigned char *W, unsigned char *P, unsigned char *Q, size_t W_len, size_t P_len, +int monero_ecadd(unsigned char *W, + unsigned char *P, + unsigned char *Q, + size_t W_len, + size_t P_len, size_t Q_len) { unsigned char Pxy[PXY_SIZE]; unsigned char Qxy[PXY_SIZE]; @@ -1027,7 +1154,11 @@ int monero_ecadd(unsigned char *W, unsigned char *P, unsigned char *Q, size_t W_ /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_ecsub(unsigned char *W, unsigned char *P, unsigned char *Q, size_t W_len, size_t P_len, +int monero_ecsub(unsigned char *W, + unsigned char *P, + unsigned char *Q, + size_t W_len, + size_t P_len, size_t Q_len) { unsigned char Pxy[PXY_SIZE]; unsigned char Qxy[PXY_SIZE]; @@ -1056,7 +1187,7 @@ int monero_ecsub(unsigned char *W, unsigned char *P, unsigned char *Q, size_t W_ memcpy(&Qxy[1], Q, 32); error |= cx_edwards_decompress_point_no_throw(CX_CURVE_Ed25519, Qxy, sizeof(Qxy)); - error |= cx_math_sub(Qxy + 1, (unsigned char *)C_ED25519_FIELD, Qxy + 1, 32); + error |= cx_math_sub(Qxy + 1, (unsigned char *) C_ED25519_FIELD, Qxy + 1, 32); error |= cx_ecfp_add_point_no_throw(CX_CURVE_Ed25519, Pxy, Pxy, Qxy); error |= cx_edwards_compress_point_no_throw(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); @@ -1132,7 +1263,11 @@ int monero_genCommitmentMask(unsigned char *c, unsigned char *sk, size_t c_len, /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_addm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_len, size_t a_len, +int monero_addm(unsigned char *r, + unsigned char *a, + unsigned char *b, + size_t r_len, + size_t a_len, size_t b_len) { unsigned char ra[32]; unsigned char rb[32]; @@ -1146,7 +1281,7 @@ int monero_addm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_l if (error) { return error; } - error = cx_math_addm_no_throw(r, ra, rb, (unsigned char *)C_ED25519_ORDER, 32); + error = cx_math_addm_no_throw(r, ra, rb, (unsigned char *) C_ED25519_ORDER, 32); if (error) { return SW_SECURITY_INTERNAL; } @@ -1162,7 +1297,11 @@ int monero_addm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_l /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_subm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_len, size_t a_len, +int monero_subm(unsigned char *r, + unsigned char *a, + unsigned char *b, + size_t r_len, + size_t a_len, size_t b_len) { unsigned char ra[32]; unsigned char rb[32]; @@ -1176,7 +1315,7 @@ int monero_subm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_l if (error) { return error; } - error = cx_math_subm_no_throw(r, ra, rb, (unsigned char *)C_ED25519_ORDER, 32); + error = cx_math_subm_no_throw(r, ra, rb, (unsigned char *) C_ED25519_ORDER, 32); if (error) { return SW_SECURITY_INTERNAL; } @@ -1190,7 +1329,11 @@ int monero_subm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_l /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_multm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_len, size_t a_len, +int monero_multm(unsigned char *r, + unsigned char *a, + unsigned char *b, + size_t r_len, + size_t a_len, size_t b_len) { unsigned char ra[32]; unsigned char rb[32]; @@ -1204,7 +1347,7 @@ int monero_multm(unsigned char *r, unsigned char *a, unsigned char *b, size_t r_ if (error) { return error; } - error = cx_math_multm_no_throw(r, ra, rb, (unsigned char *)C_ED25519_ORDER, 32); + error = cx_math_multm_no_throw(r, ra, rb, (unsigned char *) C_ED25519_ORDER, 32); if (error) { return SW_SECURITY_INTERNAL; } @@ -1230,7 +1373,7 @@ int monero_multm_8(unsigned char *r, unsigned char *a, size_t r_len, size_t a_le } explicit_bzero(rb, 32); rb[31] = 8; - error = cx_math_multm_no_throw(r, ra, rb, (unsigned char *)C_ED25519_ORDER, 32); + error = cx_math_multm_no_throw(r, ra, rb, (unsigned char *) C_ED25519_ORDER, 32); if (error) { return SW_SECURITY_INTERNAL; } @@ -1252,7 +1395,7 @@ int monero_reduce(unsigned char *r, unsigned char *a, size_t r_len, size_t a_len if (error) { return error; } - error = cx_math_modm_no_throw(ra, 32, (unsigned char *)C_ED25519_ORDER, 32); + error = cx_math_modm_no_throw(ra, 32, (unsigned char *) C_ED25519_ORDER, 32); if (error) { return SW_SECURITY_INTERNAL; } @@ -1272,7 +1415,7 @@ int monero_rng_mod_order(unsigned char *r, size_t r_len) { cx_rng(rnd, 32 + 8); /* To uncomment in order to freeze the secret for test purposes */ /* memset(rnd, 0xBB, 32 + 8); */ - error = cx_math_modm_no_throw(rnd, 32 + 8, (unsigned char *)C_ED25519_ORDER, 32); + error = cx_math_modm_no_throw(rnd, 32 + 8, (unsigned char *) C_ED25519_ORDER, 32); if (error) { return SW_SECURITY_INTERNAL; } diff --git a/src/monero_init.c b/src/monero_init.c index f2316602..65e4111b 100644 --- a/src/monero_init.c +++ b/src/monero_init.c @@ -41,7 +41,7 @@ unsigned int monero_init() { explicit_bzero(&G_monero_vstate, sizeof(monero_v_state_t)); // first init ? - if (memcmp((void*)N_monero_pstate->magic, (void*)C_MAGIC, sizeof(C_MAGIC)) != 0) { + if (memcmp((void*) N_monero_pstate->magic, (void*) C_MAGIC, sizeof(C_MAGIC)) != 0) { #if defined(MONERO_ALPHA) || defined(MONERO_BETA) monero_install(STAGENET); #else @@ -96,7 +96,9 @@ int monero_init_private_key(void) { return error; } - error = monero_reduce(G_monero_vstate.b, G_monero_vstate.b, sizeof(G_monero_vstate.b), + error = monero_reduce(G_monero_vstate.b, + G_monero_vstate.b, + sizeof(G_monero_vstate.b), sizeof(G_monero_vstate.b)); if (error) { return error; @@ -107,7 +109,9 @@ int monero_init_private_key(void) { return error; } - error = monero_reduce(G_monero_vstate.a, G_monero_vstate.a, sizeof(G_monero_vstate.a), + error = monero_reduce(G_monero_vstate.a, + G_monero_vstate.a, + sizeof(G_monero_vstate.a), sizeof(G_monero_vstate.a)); if (error) { return error; @@ -115,19 +119,23 @@ int monero_init_private_key(void) { break; case KEY_MODE_EXTERNAL: - memcpy(G_monero_vstate.a, (void*)N_monero_pstate->a, KEY_SIZE); - memcpy(G_monero_vstate.b, (void*)N_monero_pstate->b, KEY_SIZE); + memcpy(G_monero_vstate.a, (void*) N_monero_pstate->a, KEY_SIZE); + memcpy(G_monero_vstate.b, (void*) N_monero_pstate->b, KEY_SIZE); break; default: return SW_SECURITY_LOAD_KEY; } - error = monero_ecmul_G(G_monero_vstate.A, G_monero_vstate.a, sizeof(G_monero_vstate.A), + error = monero_ecmul_G(G_monero_vstate.A, + G_monero_vstate.a, + sizeof(G_monero_vstate.A), sizeof(G_monero_vstate.a)); if (error) { return error; } - error = monero_ecmul_G(G_monero_vstate.B, G_monero_vstate.b, sizeof(G_monero_vstate.B), + error = monero_ecmul_G(G_monero_vstate.B, + G_monero_vstate.b, + sizeof(G_monero_vstate.B), sizeof(G_monero_vstate.b)); if (error) { return error; @@ -147,19 +155,26 @@ int monero_init_private_key(void) { /* --- Set up ui/ux --- */ /* ----------------------------------------------------------------------- */ int monero_init_ux() { - int error = monero_base58_public_key(G_monero_vstate.ux_address, G_monero_vstate.A, - G_monero_vstate.B, 0, NULL); + int error = monero_base58_public_key(G_monero_vstate.ux_address, + G_monero_vstate.A, + G_monero_vstate.B, + 0, + NULL); if (error) { return error; } - memset(G_monero_vstate.ux_wallet_public_short_address, '.', + memset(G_monero_vstate.ux_wallet_public_short_address, + '.', sizeof(G_monero_vstate.ux_wallet_public_short_address)); - snprintf(G_monero_vstate.ux_wallet_account_name, sizeof(G_monero_vstate.ux_wallet_account_name), - "XMR / %d", N_monero_pstate->account_id); + snprintf(G_monero_vstate.ux_wallet_account_name, + sizeof(G_monero_vstate.ux_wallet_account_name), + "XMR / %d", + N_monero_pstate->account_id); memcpy(G_monero_vstate.ux_wallet_public_short_address, G_monero_vstate.ux_address, 5); - memcpy(G_monero_vstate.ux_wallet_public_short_address + 7, G_monero_vstate.ux_address + 95 - 5, + memcpy(G_monero_vstate.ux_wallet_public_short_address + 7, + G_monero_vstate.ux_address + 95 - 5, 5); G_monero_vstate.ux_wallet_public_short_address[12] = 0; @@ -173,17 +188,17 @@ void monero_install(unsigned char netId) { unsigned char c; // full reset data - monero_nvm_write((void*)N_monero_pstate, NULL, sizeof(monero_nv_state_t)); + monero_nvm_write((void*) N_monero_pstate, NULL, sizeof(monero_nv_state_t)); // set mode key c = KEY_MODE_SEED; - nvm_write((void*)&N_monero_pstate->key_mode, &c, 1); + nvm_write((void*) &N_monero_pstate->key_mode, &c, 1); // set net id - monero_nvm_write((void*)&N_monero_pstate->network_id, &netId, 1); + monero_nvm_write((void*) &N_monero_pstate->network_id, &netId, 1); // write magic - monero_nvm_write((void*)N_monero_pstate->magic, (void*)C_MAGIC, sizeof(C_MAGIC)); + monero_nvm_write((void*) N_monero_pstate->magic, (void*) C_MAGIC, sizeof(C_MAGIC)); } /* ----------------------------------------------------------------------- */ @@ -223,7 +238,7 @@ int monero_apdu_reset() { if (client_version_len > 14) { return SW_CLIENT_NOT_SUPPORTED + 1; } - monero_io_fetch((unsigned char*)&client_version[0], client_version_len); + monero_io_fetch((unsigned char*) &client_version[0], client_version_len); // Add '.' suffix to avoid 'X.1' prefixing 'X.10' client_version[client_version_len] = '.'; diff --git a/src/monero_io.c b/src/monero_io.c index de06eb3d..cba1ba5d 100644 --- a/src/monero_io.c +++ b/src/monero_io.c @@ -132,14 +132,19 @@ void monero_io_insert_encrypt(unsigned char* buffer, size_t len, int type) { #elif defined(IONOCRYPT) memcpy(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, buffer, len); #else - if (cx_aes_no_throw(&G_monero_vstate.spk, CX_ENCRYPT | CX_CHAIN_CBC | CX_LAST | CX_PAD_NONE, - buffer, len, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, &len)) { + if (cx_aes_no_throw(&G_monero_vstate.spk, + CX_ENCRYPT | CX_CHAIN_CBC | CX_LAST | CX_PAD_NONE, + buffer, + len, + G_monero_vstate.io_buffer + G_monero_vstate.io_offset, + &len)) { send_error_and_kill_app(SW_SECURITY_INTERNAL); } #endif G_monero_vstate.io_offset += len; if (G_monero_vstate.tx_in_progress) { - monero_io_insert_hmac_for(G_monero_vstate.io_buffer + G_monero_vstate.io_offset - len, len, + monero_io_insert_hmac_for(G_monero_vstate.io_buffer + G_monero_vstate.io_offset - len, + len, type); } } @@ -214,8 +219,10 @@ int monero_io_fetch(unsigned char* buffer, int len) { return len; } -static int monero_io_verify_hmac_for(const unsigned char* buffer, int len, - unsigned char* expected_hmac, int type) { +static int monero_io_verify_hmac_for(const unsigned char* buffer, + int len, + unsigned char* expected_hmac, + int type) { if (!buffer || !expected_hmac) { return SW_WRONG_DATA; } @@ -254,9 +261,11 @@ int monero_io_fetch_decrypt(unsigned char* buffer, size_t len, int type) { if (G_monero_vstate.tx_in_progress) { monero_io_assert_available(len + 32); - error = monero_io_verify_hmac_for( - G_monero_vstate.io_buffer + G_monero_vstate.io_offset, len, - G_monero_vstate.io_buffer + G_monero_vstate.io_offset + len, type); + error = + monero_io_verify_hmac_for(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, + len, + G_monero_vstate.io_buffer + G_monero_vstate.io_offset + len, + type); if (error) { return error; } @@ -272,9 +281,12 @@ int monero_io_fetch_decrypt(unsigned char* buffer, size_t len, int type) { #elif defined(IONOCRYPT) memcpy(buffer, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, len); #else // IOCRYPT - error = cx_aes_no_throw( - &G_monero_vstate.spk, CX_DECRYPT | CX_CHAIN_CBC | CX_LAST | CX_PAD_NONE, - G_monero_vstate.io_buffer + G_monero_vstate.io_offset, len, buffer, &len); + error = cx_aes_no_throw(&G_monero_vstate.spk, + CX_DECRYPT | CX_CHAIN_CBC | CX_LAST | CX_PAD_NONE, + G_monero_vstate.io_buffer + G_monero_vstate.io_offset, + len, + buffer, + &len); #endif } G_monero_vstate.io_offset += len; @@ -313,7 +325,8 @@ int monero_io_fetch_decrypt_key(unsigned char* buffer, size_t buffer_size) { G_monero_vstate.io_offset += 32; if (G_monero_vstate.tx_in_progress) { monero_io_assert_available(32); - error = monero_io_verify_hmac_for(C_FAKE_SEC_VIEW_KEY, 32, + error = monero_io_verify_hmac_for(C_FAKE_SEC_VIEW_KEY, + 32, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, TYPE_SCALAR); if (error) { @@ -337,7 +350,8 @@ int monero_io_fetch_decrypt_key(unsigned char* buffer, size_t buffer_size) { G_monero_vstate.io_offset += 32; if (G_monero_vstate.tx_in_progress) { monero_io_assert_available(32); - error = monero_io_verify_hmac_for(C_FAKE_SEC_SPEND_KEY, 32, + error = monero_io_verify_hmac_for(C_FAKE_SEC_SPEND_KEY, + 32, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, TYPE_SCALAR); if (error) { @@ -358,9 +372,11 @@ int monero_io_fetch_varint(uint64_t* out_v64) { return SW_WRONG_DATA; } unsigned int out_len = 0; - unsigned int error = monero_decode_varint( - G_monero_vstate.io_buffer + G_monero_vstate.io_offset, - MIN(8, G_monero_vstate.io_length - G_monero_vstate.io_offset), out_v64, &out_len); + unsigned int error = + monero_decode_varint(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, + MIN(8, G_monero_vstate.io_length - G_monero_vstate.io_offset), + out_v64, + &out_len); G_monero_vstate.io_offset += out_len; return error; } @@ -444,7 +460,8 @@ int monero_io_do(unsigned int io_flags) { if (G_monero_vstate.io_length > MAX_OUT) { return SW_IO_FULL; } - memcpy(G_io_apdu_buffer, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, + memcpy(G_io_apdu_buffer, + G_monero_vstate.io_buffer + G_monero_vstate.io_offset, G_monero_vstate.io_length); if (io_flags & IO_RETURN_AFTER_TX) { diff --git a/src/monero_key.c b/src/monero_key.c index e9104565..849e7937 100644 --- a/src/monero_key.c +++ b/src/monero_key.c @@ -66,7 +66,7 @@ static unsigned long monero_crc32(unsigned long inCrc32, const void *buf, size_t /** accumulate crc32 for buffer **/ crc32 = inCrc32 ^ 0xFFFFFFFF; - byteBuf = (unsigned char *)buf; + byteBuf = (unsigned char *) buf; for (i = 0; i < bufLen; i++) { crc32 = (crc32 >> 8) ^ crcTable[(crc32 ^ byteBuf[i]) & 0xFF]; } @@ -74,7 +74,8 @@ static unsigned long monero_crc32(unsigned long inCrc32, const void *buf, size_t } void monero_clear_words(void) { - monero_nvm_write((void *)N_monero_pstate->words_list, NULL, + monero_nvm_write((void *) N_monero_pstate->words_list, + NULL, sizeof(N_monero_pstate->words_list)); } @@ -85,8 +86,11 @@ void monero_clear_words(void) { * word_list * len : word_list length */ -static int monero_set_word(unsigned int n, unsigned int idx, unsigned int w_start, - unsigned char *word_list, int len) { +static int monero_set_word(unsigned int n, + unsigned int idx, + unsigned int w_start, + unsigned char *word_list, + int len) { while (w_start < idx) { len -= 1 + word_list[0]; if (len < 0) { @@ -103,7 +107,7 @@ static int monero_set_word(unsigned int n, unsigned int idx, unsigned int w_star } len = word_list[0]; word_list++; - monero_nvm_write((void *)N_monero_pstate->words[n], word_list, len); + monero_nvm_write((void *) N_monero_pstate->words[n], word_list, len); return 0; } @@ -132,7 +136,9 @@ int monero_apdu_manage_seedwords(void) { for (int wi = 0; wi < 3; wi++) { if ((wc[wi] >= w_start) && (wc[wi] < w_end)) { - err = monero_set_word(i * 3 + wi, wc[wi], w_start, + err = monero_set_word(i * 3 + wi, + wc[wi], + w_start, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, MONERO_IO_BUFFER_LENGTH - G_monero_vstate.io_offset); if (err) { @@ -152,18 +158,19 @@ int monero_apdu_manage_seedwords(void) { } w_start = monero_crc32(0, G_monero_vstate.io_buffer, G_monero_vstate.io_p2 * 24) % 24; - monero_nvm_write((void *)N_monero_pstate->words[24], - (void *)N_monero_pstate->words[w_start], WORDS_MAX_LENGTH); + monero_nvm_write((void *) N_monero_pstate->words[24], + (void *) N_monero_pstate->words[w_start], + WORDS_MAX_LENGTH); // transform to list ready to display unsigned char word[21]; w_start = 0; for (int i = 0; i < 24; i++) { w_end = N_monero_pstate->words[i][0]; - memcpy(word, (char *)&N_monero_pstate->words[i][1], w_end); + memcpy(word, (char *) &N_monero_pstate->words[i][1], w_end); word[w_end] = (i == 23) ? 0 : ' '; w_end++; - monero_nvm_write((char *)N_monero_pstate->words_list + w_start, word, w_end); + monero_nvm_write((char *) N_monero_pstate->words_list + w_start, word, w_end); w_start += w_end; } } @@ -240,7 +247,10 @@ int monero_apdu_display_address() { } } - error = ui_menu_any_pubaddr_display(0, C, D, (minor | major) ? 1 : 0, + error = ui_menu_any_pubaddr_display(0, + C, + D, + (minor | major) ? 1 : 0, (G_monero_vstate.io_p1 == 1) ? payment_id : NULL); return error; } @@ -281,7 +291,7 @@ int monero_apdu_put_key() { if (memcmp(pub, raw, KEY_SIZE) != 0) { return SW_WRONG_DATA; } - nvm_write((void *)N_monero_pstate->a, sec, KEY_SIZE); + nvm_write((void *) N_monero_pstate->a, sec, KEY_SIZE); // spend key monero_io_fetch(sec, KEY_SIZE); @@ -294,11 +304,11 @@ int monero_apdu_put_key() { if (memcmp(pub, raw, KEY_SIZE) != 0) { return SW_WRONG_DATA; } - nvm_write((void *)N_monero_pstate->b, sec, KEY_SIZE); + nvm_write((void *) N_monero_pstate->b, sec, KEY_SIZE); // change mode unsigned char key_mode = KEY_MODE_EXTERNAL; - nvm_write((void *)&N_monero_pstate->key_mode, &key_mode, 1); + nvm_write((void *) &N_monero_pstate->key_mode, &key_mode, 1); monero_io_discard(1); @@ -319,8 +329,11 @@ int monero_apdu_get_key() { monero_io_insert(G_monero_vstate.B, KEY_SIZE); // public base address int error = monero_base58_public_key( - (char *)G_monero_vstate.io_buffer + G_monero_vstate.io_offset, G_monero_vstate.A, - G_monero_vstate.B, 0, NULL); + (char *) G_monero_vstate.io_buffer + G_monero_vstate.io_offset, + G_monero_vstate.A, + G_monero_vstate.B, + 0, + NULL); if (error) { return 0; } @@ -388,7 +401,9 @@ int monero_apdu_verify_key() { return err; } - err = monero_secret_key_to_public_key(computed_pub, priv, sizeof(computed_pub), + err = monero_secret_key_to_public_key(computed_pub, + priv, + sizeof(computed_pub), sizeof(priv)); explicit_bzero(priv, sizeof(priv)); @@ -436,7 +451,7 @@ int monero_apdu_get_chacha8_prekey(/*char *prekey*/) { if (error) { return error; } - monero_io_insert((unsigned char *)G_monero_vstate.keccakF.acc, 200); + monero_io_insert((unsigned char *) G_monero_vstate.keccakF.acc, 200); return SW_OK; } #undef CHACHA8_KEY_TAIL @@ -676,8 +691,13 @@ int monero_apdu_derive_public_key(/*const crypto::key_derivation &derivation, co monero_io_discard(0); // pub - int error = monero_derive_public_key(drvpub, derivation, output_index, pub, sizeof(drvpub), - sizeof(derivation), sizeof(pub)); + int error = monero_derive_public_key(drvpub, + derivation, + output_index, + pub, + sizeof(drvpub), + sizeof(derivation), + sizeof(pub)); if (error) { explicit_bzero(derivation, sizeof(derivation)); return error; @@ -715,8 +735,13 @@ int monero_apdu_derive_secret_key(/*const crypto::key_derivation &derivation, co monero_io_discard(0); // pub - err = monero_derive_secret_key(drvsec, derivation, output_index, sec, sizeof(drvsec), - sizeof(derivation), sizeof(sec)); + err = monero_derive_secret_key(drvsec, + derivation, + output_index, + sec, + sizeof(drvsec), + sizeof(derivation), + sizeof(sec)); if (err) { explicit_bzero(derivation, sizeof(derivation)); explicit_bzero(sec, sizeof(sec)); @@ -816,8 +841,13 @@ int monero_apdu_derive_subaddress_public_key(/*const crypto::public_key &pub, co monero_io_discard(0); // pub - err = monero_derive_subaddress_public_key(sub_pub, pub, derivation, output_index, - sizeof(sub_pub), sizeof(pub), sizeof(derivation)); + err = monero_derive_subaddress_public_key(sub_pub, + pub, + derivation, + output_index, + sizeof(sub_pub), + sizeof(pub), + sizeof(derivation)); if (err) { explicit_bzero(derivation, sizeof(derivation)); return err; @@ -894,7 +924,11 @@ int monero_apdu_get_subaddress_secret_key(/*const crypto::secret_key& sec, const monero_io_fetch(index, 8); monero_io_discard(0); - err = monero_get_subaddress_secret_key(sub_sec, sec, index, sizeof(sub_sec), sizeof(sec), + err = monero_get_subaddress_secret_key(sub_sec, + sec, + index, + sizeof(sub_sec), + sizeof(sec), sizeof(index)); if (err) { explicit_bzero(sec, sizeof(sec)); @@ -989,8 +1023,11 @@ int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_se // make additional tx pubkey if necessary if (need_additional_txkeys) { if (is_subaddress) { - err = monero_ecmul_k(additional_txkey_pub, Bout, additional_txkey_sec, - sizeof(additional_txkey_pub), KEY_SIZE, + err = monero_ecmul_k(additional_txkey_pub, + Bout, + additional_txkey_sec, + sizeof(additional_txkey_pub), + KEY_SIZE, sizeof(additional_txkey_sec)); if (err) { explicit_bzero(tx_key, sizeof(tx_key)); @@ -998,8 +1035,10 @@ int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_se return err; } } else { - err = monero_ecmul_G(additional_txkey_pub, additional_txkey_sec, - sizeof(additional_txkey_pub), sizeof(additional_txkey_sec)); + err = monero_ecmul_G(additional_txkey_pub, + additional_txkey_sec, + sizeof(additional_txkey_pub), + sizeof(additional_txkey_sec)); if (err) { explicit_bzero(tx_key, sizeof(tx_key)); explicit_bzero(additional_txkey_sec, sizeof(additional_txkey_sec)); @@ -1012,9 +1051,12 @@ int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_se // derivation if (is_change) { - err = - monero_generate_key_derivation(derivation, txkey_pub, G_monero_vstate.a, - sizeof(derivation), KEY_SIZE, sizeof(G_monero_vstate.a)); + err = monero_generate_key_derivation(derivation, + txkey_pub, + G_monero_vstate.a, + sizeof(derivation), + KEY_SIZE, + sizeof(G_monero_vstate.a)); if (err) { explicit_bzero(tx_key, sizeof(tx_key)); explicit_bzero(additional_txkey_sec, sizeof(additional_txkey_sec)); @@ -1022,9 +1064,12 @@ int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_se } } else { err = monero_generate_key_derivation( - derivation, Aout, + derivation, + Aout, (is_subaddress && need_additional_txkeys) ? additional_txkey_sec : tx_key, - sizeof(derivation), KEY_SIZE, KEY_SIZE); + sizeof(derivation), + KEY_SIZE, + KEY_SIZE); if (err) { explicit_bzero(tx_key, sizeof(tx_key)); explicit_bzero(additional_txkey_sec, sizeof(additional_txkey_sec)); @@ -1033,7 +1078,10 @@ int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_se } // compute amount key AKout (scalar1), version is always greater than 1 - err = monero_derivation_to_scalar(amount_key, derivation, output_index, sizeof(amount_key), + err = monero_derivation_to_scalar(amount_key, + derivation, + output_index, + sizeof(amount_key), sizeof(derivation)); if (err) { explicit_bzero(tx_key, sizeof(tx_key)); @@ -1054,8 +1102,13 @@ int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_se } // compute ephemeral output key - err = monero_derive_public_key(out_eph_public_key, derivation, output_index, Bout, - sizeof(out_eph_public_key), sizeof(derivation), KEY_SIZE); + err = monero_derive_public_key(out_eph_public_key, + derivation, + output_index, + Bout, + sizeof(out_eph_public_key), + sizeof(derivation), + KEY_SIZE); if (err) { explicit_bzero(tx_key, sizeof(tx_key)); explicit_bzero(additional_txkey_sec, sizeof(additional_txkey_sec)); diff --git a/src/monero_monero.c b/src/monero_monero.c index a6b585de..de152a68 100644 --- a/src/monero_monero.c +++ b/src/monero_monero.c @@ -23,13 +23,55 @@ #include "monero_vars.h" #ifndef MONERO_ALPHA -const unsigned char C_MAINNET_NETWORK_ID[] = {0x12, 0x30, 0xF1, 0x71, 0x61, 0x04, 0x41, 0x61, - 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10}; +const unsigned char C_MAINNET_NETWORK_ID[] = {0x12, + 0x30, + 0xF1, + 0x71, + 0x61, + 0x04, + 0x41, + 0x61, + 0x17, + 0x31, + 0x00, + 0x82, + 0x16, + 0xA1, + 0xA1, + 0x10}; #endif -const unsigned char C_TESTNET_NETWORK_ID[] = {0x12, 0x30, 0xF1, 0x71, 0x61, 0x04, 0x41, 0x61, - 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x11}; -const unsigned char C_STAGENET_NETWORK_ID[] = {0x12, 0x30, 0xF1, 0x71, 0x61, 0x04, 0x41, 0x61, - 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x12}; +const unsigned char C_TESTNET_NETWORK_ID[] = {0x12, + 0x30, + 0xF1, + 0x71, + 0x61, + 0x04, + 0x41, + 0x61, + 0x17, + 0x31, + 0x00, + 0x82, + 0x16, + 0xA1, + 0xA1, + 0x11}; +const unsigned char C_STAGENET_NETWORK_ID[] = {0x12, + 0x30, + 0xF1, + 0x71, + 0x61, + 0x04, + 0x41, + 0x61, + 0x17, + 0x31, + 0x00, + 0x82, + 0x16, + 0xA1, + 0xA1, + 0x12}; // Copyright (c) 2014-2017, The Monero Project // @@ -117,8 +159,11 @@ static void encode_block(const unsigned char* block, unsigned int size, char* re } } -int monero_base58_public_key(char* str_b58, unsigned char* view, unsigned char* spend, - unsigned char is_subbadress, unsigned char* paymanetID) { +int monero_base58_public_key(char* str_b58, + unsigned char* view, + unsigned char* spend, + unsigned char is_subbadress, + unsigned char* paymanetID) { unsigned char data[72 + 8]; unsigned int offset; unsigned int prefix; @@ -180,12 +225,14 @@ int monero_base58_public_key(char* str_b58, unsigned char* view, unsigned char* unsigned int full_block_count = (offset) / FULL_BLOCK_SIZE; unsigned int last_block_size = (offset) % FULL_BLOCK_SIZE; for (size_t i = 0; i < full_block_count; ++i) { - encode_block(data + i * FULL_BLOCK_SIZE, FULL_BLOCK_SIZE, + encode_block(data + i * FULL_BLOCK_SIZE, + FULL_BLOCK_SIZE, &str_b58[i * FULL_ENCODED_BLOCK_SIZE]); } if (0 < last_block_size) { - encode_block(data + full_block_count * FULL_BLOCK_SIZE, last_block_size, + encode_block(data + full_block_count * FULL_BLOCK_SIZE, + last_block_size, &str_b58[full_block_count * FULL_ENCODED_BLOCK_SIZE]); } diff --git a/src/monero_open_tx.c b/src/monero_open_tx.c index 97afc80e..1d69d09a 100644 --- a/src/monero_open_tx.c +++ b/src/monero_open_tx.c @@ -81,7 +81,9 @@ int monero_apdu_open_tx_cont() { return error; } - error = monero_ecmul_G(G_monero_vstate.R, G_monero_vstate.r, sizeof(G_monero_vstate.R), + error = monero_ecmul_G(G_monero_vstate.R, + G_monero_vstate.r, + sizeof(G_monero_vstate.R), sizeof(G_monero_vstate.r)); if (error) { return error; @@ -90,9 +92,9 @@ int monero_apdu_open_tx_cont() { monero_io_insert(G_monero_vstate.R, KEY_SIZE); monero_io_insert_encrypt(G_monero_vstate.r, KEY_SIZE, TYPE_SCALAR); monero_io_insert(C_FAKE_SEC_VIEW_KEY, KEY_SIZE); - monero_io_insert_hmac_for((void*)C_FAKE_SEC_VIEW_KEY, KEY_SIZE, TYPE_SCALAR); + monero_io_insert_hmac_for((void *) C_FAKE_SEC_VIEW_KEY, KEY_SIZE, TYPE_SCALAR); monero_io_insert(C_FAKE_SEC_SPEND_KEY, KEY_SIZE); - monero_io_insert_hmac_for((void*)C_FAKE_SEC_SPEND_KEY, KEY_SIZE, TYPE_SCALAR); + monero_io_insert_hmac_for((void *) C_FAKE_SEC_SPEND_KEY, KEY_SIZE, TYPE_SCALAR); return SW_OK; } diff --git a/src/monero_prehash.c b/src/monero_prehash.c index 747de4a0..8292b441 100644 --- a/src/monero_prehash.c +++ b/src/monero_prehash.c @@ -55,10 +55,12 @@ int monero_apdu_mlsag_prehash_init() { monero_io_fetch_u8(); // fee str monero_vamount2str(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, - G_monero_vstate.ux_amount, 15); + G_monero_vstate.ux_amount, + 15); snprintf(G_monero_vstate.ux_amount + strlen(G_monero_vstate.ux_amount), - sizeof(G_monero_vstate.ux_amount) - strlen(G_monero_vstate.ux_amount), " XMR"); + sizeof(G_monero_vstate.ux_amount) - strlen(G_monero_vstate.ux_amount), + " XMR"); // ask user monero_io_discard(1); ui_menu_fee_validation_display(0); @@ -129,8 +131,11 @@ int monero_apdu_mlsag_prehash_update() { if (G_monero_vstate.tx_sig_mode == TRANSACTION_CREATE_REAL) { if (is_change == 0) { // encode dest adress - err = monero_base58_public_key(&G_monero_vstate.ux_address[0], Aout, Bout, - is_subaddress, NULL); + err = monero_base58_public_key(&G_monero_vstate.ux_address[0], + Aout, + Bout, + is_subaddress, + NULL); if (err) { return err; } @@ -156,7 +161,12 @@ int monero_apdu_mlsag_prehash_update() { } // check C = aH+kG - err = monero_unblind(v, k, AKout, G_monero_vstate.options & 0x03, sizeof(v), sizeof(k), + err = monero_unblind(v, + k, + AKout, + G_monero_vstate.options & 0x03, + sizeof(v), + sizeof(k), sizeof(AKout)); if (err) { return err; @@ -222,7 +232,8 @@ int monero_apdu_mlsag_prehash_update() { monero_amount2str(amount, G_monero_vstate.ux_amount, 15); snprintf(G_monero_vstate.ux_amount + strlen(G_monero_vstate.ux_amount), - sizeof(G_monero_vstate.ux_amount) - strlen(G_monero_vstate.ux_amount), " XMR"); + sizeof(G_monero_vstate.ux_amount) - strlen(G_monero_vstate.ux_amount), + " XMR"); if ((G_monero_vstate.options & IN_OPTION_MORE_COMMAND) == 0) { if (!is_change) { diff --git a/src/monero_proof.c b/src/monero_proof.c index 0c89b31a..bbb830ab 100644 --- a/src/monero_proof.c +++ b/src/monero_proof.c @@ -96,7 +96,7 @@ int monero_apdu_get_tx_proof() { } // tmp = msg || D || X || Y memcpy(G_monero_vstate.tmp + 32 * 3, XY, 32); - err = monero_keccak_H((unsigned char *)"TXPROOF_V2", 10, sep); + err = monero_keccak_H((unsigned char *) "TXPROOF_V2", 10, sep); if (err) { explicit_bzero(r, sizeof(r)); return err; diff --git a/src/monero_types.h b/src/monero_types.h index 4b35b342..41b07af8 100644 --- a/src/monero_types.h +++ b/src/monero_types.h @@ -218,8 +218,8 @@ typedef struct monero_v_state_s monero_v_state_t; #define TYPE_ALPHA 4 /* --- ... --- */ -#define IO_OFFSET_END (unsigned int)-1 -#define IO_OFFSET_MARK (unsigned int)-2 +#define IO_OFFSET_END (unsigned int) -1 +#define IO_OFFSET_MARK (unsigned int) -2 #define ENCRYPTED_PAYMENT_ID_TAIL 0x8d diff --git a/src/monero_ux_nano.c b/src/monero_ux_nano.c index 1a21e406..f66a05fe 100644 --- a/src/monero_ux_nano.c +++ b/src/monero_ux_nano.c @@ -43,13 +43,16 @@ void ui_menu_words_display(unsigned int value); void ui_menu_words_clear(unsigned int value); void ui_menu_words_back(unsigned int value); -UX_STEP_NOCB(ux_menu_words_1_step, bnnn_paging, +UX_STEP_NOCB(ux_menu_words_1_step, + bnnn_paging, { .title = "Electrum Seed", .text = "NOTSET", }); -UX_STEP_CB(ux_menu_words_2_step, bn, ui_menu_words_clear(0), +UX_STEP_CB(ux_menu_words_2_step, + bn, + ui_menu_words_clear(0), {"CLEAR WORDS", "(Do not wipe the wallet)"}); UX_STEP_CB(ux_menu_words_3_step, pb, ui_menu_words_back(0), {&C_icon_back, "back"}); @@ -73,7 +76,9 @@ void settings_show_25_words(void) { ui_menu_words_display(0); } /* -------------------------------- INFO UX --------------------------------- */ -UX_STEP_CB(ux_menu_info_1_step, nn, (void)ui_menu_main_display(), +UX_STEP_CB(ux_menu_info_1_step, + nn, + (void) ui_menu_main_display(), { G_monero_vstate.ux_info1, G_monero_vstate.ux_info2, @@ -81,7 +86,8 @@ UX_STEP_CB(ux_menu_info_1_step, nn, (void)ui_menu_main_display(), UX_FLOW(ux_flow_info, &ux_menu_info_1_step); -static void ui_menu_info_display2(unsigned int value __attribute__((unused)), const char* line1, +static void ui_menu_info_display2(unsigned int value __attribute__((unused)), + const char* line1, const char* line2) { snprintf(G_monero_vstate.ux_info1, sizeof(G_monero_vstate.ux_info1), "%s", line1); snprintf(G_monero_vstate.ux_info2, sizeof(G_monero_vstate.ux_info2), "%s", line2); @@ -155,43 +161,56 @@ void ui_menu_opentx_display(unsigned int value __attribute__((unused))) { void ui_menu_amount_validation_action(unsigned int value); -UX_STEP_NOCB(ux_menu_validation_fee_1_step, bn, +UX_STEP_NOCB(ux_menu_validation_fee_1_step, + bn, { "Fee", G_monero_vstate.ux_amount, }); -UX_STEP_NOCB(ux_menu_validation_change_1_step, bn, +UX_STEP_NOCB(ux_menu_validation_change_1_step, + bn, { "Change", G_monero_vstate.ux_amount, }); -UX_STEP_NOCB(ux_menu_validation_timelock_1_step, bn, +UX_STEP_NOCB(ux_menu_validation_timelock_1_step, + bn, { "Timelock", G_monero_vstate.ux_amount, }); -UX_STEP_CB(ux_menu_validation_cf_2_step, pb, ui_menu_amount_validation_action(ACCEPT), +UX_STEP_CB(ux_menu_validation_cf_2_step, + pb, + ui_menu_amount_validation_action(ACCEPT), { &C_icon_validate_14, "Sign transaction", }); -UX_STEP_CB(ux_menu_validation_cf_3_step, pb, ui_menu_amount_validation_action(REJECT), +UX_STEP_CB(ux_menu_validation_cf_3_step, + pb, + ui_menu_amount_validation_action(REJECT), { &C_icon_crossmark, "Reject", }); -UX_FLOW(ux_flow_fee, &ux_menu_validation_fee_1_step, &ux_menu_validation_cf_2_step, +UX_FLOW(ux_flow_fee, + &ux_menu_validation_fee_1_step, + &ux_menu_validation_cf_2_step, &ux_menu_validation_cf_3_step); -UX_FLOW(ux_flow_change, &ux_menu_validation_change_1_step, &ux_menu_validation_cf_2_step, +UX_FLOW(ux_flow_change, + &ux_menu_validation_change_1_step, + &ux_menu_validation_cf_2_step, &ux_menu_validation_cf_3_step); -UX_FLOW(ux_flow_timelock, &ux_menu_validation_timelock_1_step, &ux_menu_validation_cf_2_step, +UX_FLOW(ux_flow_timelock, + &ux_menu_validation_timelock_1_step, + &ux_menu_validation_cf_2_step, &ux_menu_validation_cf_3_step); void ui_menu_amount_validation_action(unsigned int value) { @@ -229,14 +248,21 @@ UX_STEP_NOCB(ux_menu_validation_1_step, bn, {"Amount", G_monero_vstate.ux_amount UX_STEP_NOCB(ux_menu_validation_2_step, bnnn_paging, {"Destination", G_monero_vstate.ux_address}); -UX_STEP_CB(ux_menu_validation_3_step, pb, ui_menu_validation_action(ACCEPT), +UX_STEP_CB(ux_menu_validation_3_step, + pb, + ui_menu_validation_action(ACCEPT), {&C_icon_validate_14, "Sign transaction"}); -UX_STEP_CB(ux_menu_validation_4_step, pb, ui_menu_validation_action(REJECT), +UX_STEP_CB(ux_menu_validation_4_step, + pb, + ui_menu_validation_action(REJECT), {&C_icon_crossmark, "Reject"}); -UX_FLOW(ux_flow_validation, &ux_menu_validation_1_step, &ux_menu_validation_2_step, - &ux_menu_validation_3_step, &ux_menu_validation_4_step); +UX_FLOW(ux_flow_validation, + &ux_menu_validation_1_step, + &ux_menu_validation_2_step, + &ux_menu_validation_3_step, + &ux_menu_validation_4_step); void ui_menu_validation_display(unsigned int value __attribute__((unused))) { ux_flow_init(0, ux_flow_validation, NULL); @@ -264,13 +290,19 @@ unsigned int ui_menu_export_viewkey_action(unsigned int value); UX_STEP_NOCB(ux_menu_export_viewkey_1_step, nn, {"Export", "View Key"}); -UX_STEP_CB(ux_menu_export_viewkey_2_step, pb, ui_menu_export_viewkey_action(ACCEPT), +UX_STEP_CB(ux_menu_export_viewkey_2_step, + pb, + ui_menu_export_viewkey_action(ACCEPT), {&C_icon_validate_14, "Accept"}); -UX_STEP_CB(ux_menu_export_viewkey_3_step, pb, ui_menu_export_viewkey_action(REJECT), +UX_STEP_CB(ux_menu_export_viewkey_3_step, + pb, + ui_menu_export_viewkey_action(REJECT), {&C_icon_crossmark, "Reject"}); -UX_FLOW(ux_flow_export_viewkey, &ux_menu_export_viewkey_1_step, &ux_menu_export_viewkey_2_step, +UX_FLOW(ux_flow_export_viewkey, + &ux_menu_export_viewkey_1_step, + &ux_menu_export_viewkey_2_step, &ux_menu_export_viewkey_3_step); void ui_export_viewkey_display(unsigned int value __attribute__((unused))) { @@ -295,10 +327,10 @@ unsigned int ui_menu_export_viewkey_action(unsigned int value) { /* -------------------------------- ACCOUNT UX --------------------------------- */ -const char* const account_submenu_getter_values[] = {"0", "1", "2", "3", "4", "5", - "6", "7", "8", "9", "Abort"}; -const char* const account_submenu_getter_values_selected[] = { - "0 +", "1 +", "2 +", "3 +", "4 +", "5 +", "6 +", "7 +", "8 +", "9 +", "Abort"}; +const char* const account_submenu_getter_values[] = + {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "Abort"}; +const char* const account_submenu_getter_values_selected[] = + {"0 +", "1 +", "2 +", "3 +", "4 +", "5 +", "6 +", "7 +", "8 +", "9 +", "Abort"}; const char* account_submenu_getter(unsigned int idx) { if (idx >= ARRAYLEN(account_submenu_getter_values)) { @@ -317,7 +349,7 @@ void account_back(void) { void account_submenu_selector(unsigned int idx) { if (idx <= 9) { - monero_nvm_write((void*)&N_monero_pstate->account_id, &idx, sizeof(unsigned int)); + monero_nvm_write((void*) &N_monero_pstate->account_id, &idx, sizeof(unsigned int)); monero_init(); } ui_menu_main_display(); @@ -339,14 +371,18 @@ const char* const network_submenu_getter_values[] = { #else "Main Network", #endif - "Stage Network", "Test Network", "Abort"}; + "Stage Network", + "Test Network", + "Abort"}; const char* const network_submenu_getter_values_selected[] = { #ifdef MONERO_ALPHA "Unavailable", #else "Main Network +", #endif - "Stage Network +", "Test Network +", "Abort"}; + "Stage Network +", + "Test Network +", + "Abort"}; const char* network_submenu_getter(unsigned int idx) { if (idx >= ARRAYLEN(network_submenu_getter_values)) { @@ -417,19 +453,24 @@ void settings_change_network(void) { void ui_menu_reset_display(void); void ui_menu_reset_action(unsigned int value); -UX_STEP_NOCB(ux_menu_reset_1_step, nn, +UX_STEP_NOCB(ux_menu_reset_1_step, + nn, { "", "Really Reset?", }); -UX_STEP_CB(ux_menu_reset_2_step, pb, ui_menu_reset_action(REJECT), +UX_STEP_CB(ux_menu_reset_2_step, + pb, + ui_menu_reset_action(REJECT), { &C_icon_crossmark, "No", }); -UX_STEP_CB(ux_menu_reset_3_step, pb, ui_menu_reset_action(ACCEPT), +UX_STEP_CB(ux_menu_reset_3_step, + pb, + ui_menu_reset_action(ACCEPT), { &C_icon_validate_14, "Yes", @@ -452,7 +493,7 @@ void ui_menu_reset_action(unsigned int value) { magic[1] = 0; magic[2] = 0; magic[3] = 0; - monero_nvm_write((void*)N_monero_pstate->magic, magic, 4); + monero_nvm_write((void*) N_monero_pstate->magic, magic, 4); monero_init(); } ui_menu_main_display(); @@ -460,7 +501,11 @@ void ui_menu_reset_action(unsigned int value) { /* ------------------------------- SETTINGS UX ------------------------------- */ const char* const settings_submenu_getter_values[] = { - "Select Account", "Select Network", "Show 25 words", "Reset", "Back", + "Select Account", + "Select Network", + "Show 25 words", + "Reset", + "Back", }; const char* settings_submenu_getter(unsigned int idx) { @@ -497,7 +542,8 @@ void settings_submenu_selector(unsigned int idx) { #define STR(x) #x #define XSTR(x) STR(x) -UX_STEP_NOCB(ux_menu_about_1_step, bnnn, +UX_STEP_NOCB(ux_menu_about_1_step, + bnnn, { "Monero", "(c) Ledger SAS", @@ -505,7 +551,9 @@ UX_STEP_NOCB(ux_menu_about_1_step, bnnn, "App " XSTR(MONERO_VERSION), }); -UX_STEP_CB(ux_menu_about_2_step, pb, ui_menu_main_display(), +UX_STEP_CB(ux_menu_about_2_step, + pb, + ui_menu_main_display(), { &C_icon_back, "Back", @@ -529,25 +577,31 @@ void ui_menu_pubaddr_action(unsigned int value); #define ADDR_IDSTR G_monero_vstate.ux_address + 124 #define ADDR_ID G_monero_vstate.ux_address + 140 -UX_STEP_NOCB(ux_menu_pubaddr_01_step, nn, +UX_STEP_NOCB(ux_menu_pubaddr_01_step, + nn, { ADDR_TYPE, "Address", }); -UX_STEP_NOCB(ux_menu_pubaddr_02_step, nn, +UX_STEP_NOCB(ux_menu_pubaddr_02_step, + nn, { ADDR_MAJOR, ADDR_MINOR, }); -UX_STEP_NOCB(ux_menu_pubaddr_1_step, bnnn_paging, +UX_STEP_NOCB(ux_menu_pubaddr_1_step, + bnnn_paging, {.title = "Address", .text = G_monero_vstate.ux_address}); UX_STEP_CB(ux_menu_pubaddr_2_step, pb, ui_menu_pubaddr_action(0), {&C_icon_back, "Ok"}); -UX_FLOW(ux_flow_pubaddr, &ux_menu_pubaddr_01_step, &ux_menu_pubaddr_02_step, - &ux_menu_pubaddr_1_step, &ux_menu_pubaddr_2_step); +UX_FLOW(ux_flow_pubaddr, + &ux_menu_pubaddr_01_step, + &ux_menu_pubaddr_02_step, + &ux_menu_pubaddr_1_step, + &ux_menu_pubaddr_2_step); void ui_menu_pubaddr_action(unsigned int value __attribute__((unused))) { if (G_monero_vstate.disp_addr_mode) { @@ -561,8 +615,10 @@ void ui_menu_pubaddr_action(unsigned int value __attribute__((unused))) { /** * */ -int ui_menu_any_pubaddr_display(unsigned int value __attribute__((unused)), unsigned char* pub_view, - unsigned char* pub_spend, unsigned char is_subbadress, +int ui_menu_any_pubaddr_display(unsigned int value __attribute__((unused)), + unsigned char* pub_view, + unsigned char* pub_spend, + unsigned char is_subbadress, unsigned char* paymanetID) { explicit_bzero(G_monero_vstate.ux_address, sizeof(G_monero_vstate.ux_address)); @@ -587,8 +643,11 @@ int ui_menu_any_pubaddr_display(unsigned int value __attribute__((unused)), unsi break; } - int error = monero_base58_public_key(G_monero_vstate.ux_address, pub_view, pub_spend, - is_subbadress, paymanetID); + int error = monero_base58_public_key(G_monero_vstate.ux_address, + pub_view, + pub_spend, + is_subbadress, + paymanetID); if (error) { return error; } @@ -615,12 +674,17 @@ void ui_menu_pubaddr_display(unsigned int value) { /* --------------------------------- MAIN UX --------------------------------- */ -UX_STEP_CB(ux_menu_main_1_step, pbb, ui_menu_pubaddr_display(0), - {&C_icon_monero, G_monero_vstate.ux_wallet_account_name, +UX_STEP_CB(ux_menu_main_1_step, + pbb, + ui_menu_pubaddr_display(0), + {&C_icon_monero, + G_monero_vstate.ux_wallet_account_name, G_monero_vstate.ux_wallet_public_short_address}); -UX_STEP_CB(ux_menu_main_2_step, pb, - ux_menulist_init(G_ux.stack_count - 1, settings_submenu_getter, +UX_STEP_CB(ux_menu_main_2_step, + pb, + ux_menulist_init(G_ux.stack_count - 1, + settings_submenu_getter, settings_submenu_selector), {&C_icon_coggle, "Settings"}); @@ -628,7 +692,10 @@ UX_STEP_CB(ux_menu_main_3_step, pb, ui_menu_about_display(), {&C_icon_certificat UX_STEP_CB(ux_menu_main_4_step, pb, app_exit(), {&C_icon_dashboard_x, "Quit app"}); -UX_FLOW(ux_flow_main, &ux_menu_main_1_step, &ux_menu_main_2_step, &ux_menu_main_3_step, +UX_FLOW(ux_flow_main, + &ux_menu_main_1_step, + &ux_menu_main_2_step, + &ux_menu_main_3_step, &ux_menu_main_4_step); void ui_menu_main_display(void) { @@ -645,7 +712,7 @@ void ui_init(void) { } void io_seproxyhal_display(const bagl_element_t* element) { - io_seproxyhal_display_default((bagl_element_t*)element); + io_seproxyhal_display_default((bagl_element_t*) element); } #endif diff --git a/src/monero_ux_nbgl.c b/src/monero_ux_nbgl.c index 8c4877e9..3d3ea59c 100644 --- a/src/monero_ux_nbgl.c +++ b/src/monero_ux_nbgl.c @@ -97,7 +97,8 @@ static void add_amount(const char* title, bool forcePageStart) { } strncpy(transactionContext.amountBuffer[transactionContext.amountNum], - G_monero_vstate.ux_amount, MAX_AMOUNT_LENGTH); + G_monero_vstate.ux_amount, + MAX_AMOUNT_LENGTH); transactionContext.tagValuePair[nbPairs].item = title; transactionContext.tagValuePair[nbPairs].value = @@ -118,7 +119,8 @@ static void add_address(void) { return; } - strncpy(transactionContext.dstBuffer[transactionContext.addrNum], G_monero_vstate.ux_address, + strncpy(transactionContext.dstBuffer[transactionContext.addrNum], + G_monero_vstate.ux_address, MAX_ADDR_LENGTH); transactionContext.tagValuePair[nbPairs].item = dstTitle; @@ -160,8 +162,12 @@ void ui_menu_show_tx_aborted(void) { /* --------------------- FEE/CHANGE/TIMELOCK VALIDATION --------------------- */ static void start_signature(void) { - nbgl_useCaseReview(TYPE_TRANSACTION, &transactionContext.tagValueList, &ICON_APP_MAIN, - "Review Transaction\nto send Monero", NULL, "Sign transaction?", + nbgl_useCaseReview(TYPE_TRANSACTION, + &transactionContext.tagValueList, + &ICON_APP_MAIN, + "Review Transaction\nto send Monero", + NULL, + "Sign transaction?", ui_menu_validation_action); } @@ -273,18 +279,26 @@ void display_account(void) { transactionContext.tagValueList.pairs = transactionContext.tagValuePair; - nbgl_useCaseAddressReview(G_monero_vstate.ux_address, &transactionContext.tagValueList, - &ICON_APP_MAIN, "Verify Monero\naddress", NULL, + nbgl_useCaseAddressReview(G_monero_vstate.ux_address, + &transactionContext.tagValueList, + &ICON_APP_MAIN, + "Verify Monero\naddress", + NULL, ui_menu_pubaddr_action); } -int ui_menu_any_pubaddr_display(unsigned int value __attribute__((unused)), unsigned char* pub_view, - unsigned char* pub_spend, unsigned char is_subbadress, +int ui_menu_any_pubaddr_display(unsigned int value __attribute__((unused)), + unsigned char* pub_view, + unsigned char* pub_spend, + unsigned char is_subbadress, unsigned char* paymanetID) { int error; explicit_bzero(G_monero_vstate.ux_address, sizeof(G_monero_vstate.ux_address)); - error = monero_base58_public_key(G_monero_vstate.ux_address, pub_view, pub_spend, is_subbadress, + error = monero_base58_public_key(G_monero_vstate.ux_address, + pub_view, + pub_spend, + is_subbadress, paymanetID); if (error) { return error; @@ -321,7 +335,11 @@ static void ui_menu_export_viewkey_action(bool value) { } void ui_export_viewkey_display(unsigned int value __attribute__((unused))) { - nbgl_useCaseChoice(&ICON_APP_MAIN, "Export\nview key", "", "Accept", "Reject if not sure", + nbgl_useCaseChoice(&ICON_APP_MAIN, + "Export\nview key", + "", + "Accept", + "Reject if not sure", ui_menu_export_viewkey_action); } diff --git a/src/monero_ux_nbgl_menu.c b/src/monero_ux_nbgl_menu.c index b6ea36c5..c75a7b5d 100644 --- a/src/monero_ux_nbgl_menu.c +++ b/src/monero_ux_nbgl_menu.c @@ -64,7 +64,9 @@ enum { MAIN_NET, STAGE_NET, TEST_NET, MAX_NET }; #define SETTING_INFO_NB 4 static const char* const infoTypes[] = {"Spec", "Version", "Developer", "Copyright"}; -static const char* const infoContents[] = {XSTR(SPEC_VERSION), APPVERSION, "Ledger", +static const char* const infoContents[] = {XSTR(SPEC_VERSION), + APPVERSION, + "Ledger", "(c) 2024 Ledger"}; static const char* const barTexts[] = {"Select Account", "Select Network", "Reset"}; @@ -146,7 +148,7 @@ static void resetCallback(void) { magic[1] = 0; magic[2] = 0; magic[3] = 0; - monero_nvm_write((void*)N_monero_pstate->magic, magic, 4); + monero_nvm_write((void*) N_monero_pstate->magic, magic, 4); monero_init(); nbgl_useCaseStatus("ACCOUNT INFOS\nRESETTED", true, ui_menu_main_display); } @@ -158,7 +160,7 @@ static void account_settings_control_cb(int token, uint8_t index) { case ACCOUNT_CHOICE: index = (token - ACCOUNT_CHOICE) * 4 + index; if (index <= 9) { - monero_nvm_write((void*)&N_monero_pstate->account_id, &index, sizeof(uint8_t)); + monero_nvm_write((void*) &N_monero_pstate->account_id, &index, sizeof(uint8_t)); monero_init(); } display_settings_menu(); @@ -201,17 +203,26 @@ static void settings_control_cb(int token, uint8_t index, int page) { UNUSED(page); switch (token) { case ACCOUNT_TOKEN: - nbgl_useCaseNavigableContent("Select account", 0, 3, display_settings_menu, + nbgl_useCaseNavigableContent("Select account", + 0, + 3, + display_settings_menu, account_settings_navigation_cb, account_settings_control_cb); break; case NETWORK_TOKEN: - nbgl_useCaseNavigableContent("Select network", 0, 2, display_settings_menu, + nbgl_useCaseNavigableContent("Select network", + 0, + 2, + display_settings_menu, network_settings_navigation_cb, network_settings_control_cb); break; case RESET_TOKEN: - nbgl_useCaseConfirm("Reset account\ninformations ?", "", "Yes, Reset", "Go back", + nbgl_useCaseConfirm("Reset account\ninformations ?", + "", + "Yes, Reset", + "Go back", resetCallback); break; @@ -248,18 +259,29 @@ static void display_home_and_settings(bool displayHome) { explicit_bzero(G_monero_vstate.ux_address, sizeof(G_monero_vstate.ux_address)); - snprintf(transactionContext.buffer, sizeof(transactionContext.buffer), "Show %s", + snprintf(transactionContext.buffer, + sizeof(transactionContext.buffer), + "Show %s", G_monero_vstate.ux_wallet_account_name); - monero_base58_public_key(G_monero_vstate.ux_address, G_monero_vstate.A, G_monero_vstate.B, 0, + monero_base58_public_key(G_monero_vstate.ux_address, + G_monero_vstate.A, + G_monero_vstate.B, + 0, NULL); homeAction.callback = display_account; homeAction.icon = NULL; homeAction.text = transactionContext.buffer; - nbgl_useCaseHomeAndSettings(APPNAME, &ICON_APP_MAIN, NULL, displayHome ? INIT_HOME_PAGE : 0, - &settingContents, &infoList, &homeAction, app_exit); + nbgl_useCaseHomeAndSettings(APPNAME, + &ICON_APP_MAIN, + NULL, + displayHome ? INIT_HOME_PAGE : 0, + &settingContents, + &infoList, + &homeAction, + app_exit); } static void display_settings_menu(void) { diff --git a/src/monero_vars.h b/src/monero_vars.h index e190b79d..a37a5e95 100644 --- a/src/monero_vars.h +++ b/src/monero_vars.h @@ -28,7 +28,7 @@ extern monero_v_state_t G_monero_vstate; extern const monero_nv_state_t N_state_pic; -#define N_monero_pstate ((volatile monero_nv_state_t *)PIC(&N_state_pic)) +#define N_monero_pstate ((volatile monero_nv_state_t *) PIC(&N_state_pic)) #ifdef MONERO_DEBUG_MAIN extern int apdu_n;