diff --git a/.clang-format b/.clang-format index a9d6f7a..570f635 100644 --- a/.clang-format +++ b/.clang-format @@ -6,6 +6,7 @@ Language: Cpp ColumnLimit: 100 PointerAlignment: Right AlignAfterOpenBracket: Align +AllowShortFunctionsOnASingleLine: None AlignConsecutiveMacros: true AllowAllParametersOfDeclarationOnNextLine: false SortIncludes: false diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml index e369dfd..627c486 100644 --- a/.github/workflows/ci-workflow.yml +++ b/.github/workflows/ci-workflow.yml @@ -32,6 +32,26 @@ jobs: name: monero-app-debug path: bin + scan-build: + name: Clang Static Analyzer + runs-on: ubuntu-latest + + container: + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest + + steps: + - uses: actions/checkout@v2 + + - name: Build with Clang Static Analyzer + run: | + make clean + scan-build --use-cc=clang -analyze-headers -enable-checker security -enable-checker unix -enable-checker valist -o scan-build --status-bugs make default + - uses: actions/upload-artifact@v2 + if: failure() + with: + name: scan-build + path: scan-build + job_test: name: Test needs: job_build_debug diff --git a/.github/workflows/codeql-workflow.yml b/.github/workflows/codeql-workflow.yml new file mode 100644 index 0000000..cc08e94 --- /dev/null +++ b/.github/workflows/codeql-workflow.yml @@ -0,0 +1,43 @@ +name: "CodeQL" +on: + workflow_dispatch: + push: + branches: + - master + - develop + pull_request: + branches: + - master + - develop + +jobs: + analyse: + name: Analyse + strategy: + matrix: + sdk: [ "$NANOS_SDK", "$NANOX_SDK", "$NANOSP_SDK" ] + language: [ 'cpp', 'python' ] + runs-on: ubuntu-latest + + container: + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest + + steps: + - name: Clone + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: security-and-quality + + - name: Build Nano + run: | + make clean + make BOLOS_SDK=${{ matrix.sdk }} + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/Makefile b/Makefile index b2eca0e..a97ca37 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ endif APPVERSION_M=1 APPVERSION_N=8 -APPVERSION_P=0 +APPVERSION_P=1 APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) SPECVERSION="1.0" diff --git a/doc/developer/blue-app-commands.pdf b/doc/developer/blue-app-commands.pdf index 72a9b60..37d5471 100644 Binary files a/doc/developer/blue-app-commands.pdf and b/doc/developer/blue-app-commands.pdf differ diff --git a/doc/developer/blue-app-commands.rst b/doc/developer/blue-app-commands.rst index ee6fd81..db46f4a 100644 --- a/doc/developer/blue-app-commands.rst +++ b/doc/developer/blue-app-commands.rst @@ -104,8 +104,8 @@ .. |eDRVout| replace:: :math:`\widetilde{\mathfrak{D}_\mathrm{out}}` .. |AKout| replace:: :math:`\mathcal{AK}_\mathrm{amount}` .. |eAKout| replace:: :math:`\widetilde{\mathcal{AK}_\mathrm{amount}}` -.. |vtf| replace:: :math:`\mathit{view_tag_full}` -.. |vt| replace:: :math:`\mathit{view_tag}` +.. |vtf| replace:: :math:`\mathit{view\_tag\_full}` +.. |vt| replace:: :math:`\mathit{view\_tag}` .. |ctH| replace:: :math:`\mathcal{H}_\mathrm{commitment}` diff --git a/src/monero_api.h b/src/monero_api.h index 0ce728d..ffeba31 100644 --- a/src/monero_api.h +++ b/src/monero_api.h @@ -19,9 +19,11 @@ #ifndef MONERO_API_H #define MONERO_API_H +#include "monero_vars.h" + int monero_apdu_reset(void); int monero_apdu_lock(void); -void monero_lock_and_throw(int sw); +void monero_lock_and_throw(int sw) __attribute__((noreturn)); void monero_install(unsigned char netId); void monero_init(void); @@ -34,7 +36,7 @@ int monero_dispatch(void); int monero_apdu_put_key(void); int monero_apdu_get_key(void); int monero_apdu_display_address(void); -int monero_apdu_manage_seedwords(); +int monero_apdu_manage_seedwords(void); int monero_apdu_verify_key(void); int monero_apdu_get_chacha8_prekey(void); int monero_apdu_sc_add(void); @@ -75,8 +77,8 @@ int monero_apdu_clsag_sign(void); int monero_apu_generate_txout_keys(void); -int monero_apdu_prefix_hash_init(); -int monero_apdu_prefix_hash_update(); +int monero_apdu_prefix_hash_init(void); +int monero_apdu_prefix_hash_update(void); int monero_apdu_mlsag_prepare(void); int monero_apdu_mlsag_hash(void); @@ -116,7 +118,7 @@ int monero_amount2str(uint64_t xmr, char *str, unsigned int str_len); /** uint64 amount to str */ void monero_uint642str(uint64_t val, char *str, unsigned int str_len); -int monero_abort_tx(); +int monero_abort_tx(void); int monero_unblind(unsigned char *v, unsigned char *k, unsigned char *AKout, unsigned int short_amount); void ui_menu_validation_display(unsigned int value); @@ -170,7 +172,8 @@ void monero_derive_public_key(unsigned char *x, unsigned char *drv_data, unsigne unsigned char *ec_pub); void monero_secret_key_to_public_key(unsigned char *ec_pub, unsigned char *ec_priv); void monero_generate_key_image(unsigned char *img, unsigned char *P, unsigned char *x); -void monero_derive_view_tag(unsigned char *view_tag, unsigned char *drv_data, unsigned int out_idx); +void monero_derive_view_tag(unsigned char *view_tag, const unsigned char drv_data[static 32], + unsigned int out_idx); void monero_derive_subaddress_public_key(unsigned char *x, unsigned char *pub, unsigned char *drv_data, unsigned int index); @@ -178,7 +181,7 @@ void monero_get_subaddress_spend_public_key(unsigned char *x, unsigned char *ind void monero_get_subaddress(unsigned char *C, unsigned char *D, unsigned char *index); void monero_get_subaddress_secret_key(unsigned char *sub_s, unsigned char *s, unsigned char *index); -void monero_clear_words(); +void monero_clear_words(void); /* ----------------------------------------------------------------------- */ /* --- CRYPTO ---- */ /* ----------------------------------------------------------------------- */ @@ -190,39 +193,67 @@ void monero_aes_generate(cx_aes_key_t *sk); /* Compute Monero-Hash of data*/ void monero_hash_init_keccak(cx_hash_t *hasher); void monero_hash_init_sha256(cx_hash_t *hasher); -void monero_hash_update(cx_hash_t *hasher, unsigned char *buf, unsigned int len); +void 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, 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); -#define monero_keccak_init_F() monero_hash_init_keccak((cx_hash_t *)&G_monero_vstate.keccakF) -#define monero_keccak_update_F(buf, len) \ - monero_hash_update((cx_hash_t *)&G_monero_vstate.keccakF, (buf), (len)) -#define monero_keccak_final_F(out) monero_hash_final((cx_hash_t *)&G_monero_vstate.keccakF, (out)) -#define monero_keccak_F(buf, len, out) \ - monero_hash(CX_KECCAK, (cx_hash_t *)&G_monero_vstate.keccakF, (buf), (len), (out)) - -#define monero_keccak_init_H() monero_hash_init_keccak((cx_hash_t *)&G_monero_vstate.keccakH) -#define monero_keccak_update_H(buf, len) \ - monero_hash_update((cx_hash_t *)&G_monero_vstate.keccakH, (buf), (len)) -#define monero_keccak_final_H(out) monero_hash_final((cx_hash_t *)&G_monero_vstate.keccakH, (out)) -#define monero_keccak_H(buf, len, out) \ - monero_hash(CX_KECCAK, (cx_hash_t *)&G_monero_vstate.keccakH, (buf), (len), (out)) - -#define monero_sha256_commitment_init() \ - monero_hash_init_sha256((cx_hash_t *)&G_monero_vstate.sha256_commitment) -#define monero_sha256_commitment_update(buf, len) \ - monero_hash_update((cx_hash_t *)&G_monero_vstate.sha256_commitment, (buf), (len)) -#define monero_sha256_commitment_final(out) \ - monero_hash_final((cx_hash_t *)&G_monero_vstate.sha256_commitment, \ - (out) ? (out) : G_monero_vstate.C) - -#define monero_sha256_outkeys_init() \ - monero_hash_init_sha256((cx_hash_t *)&G_monero_vstate.sha256_out_keys) -#define monero_sha256_outkeys_update(buf, len) \ - monero_hash_update((cx_hash_t *)&G_monero_vstate.sha256_out_keys, (buf), (len)) -#define monero_sha256_outkeys_final(out) \ - monero_hash_final((cx_hash_t *)&G_monero_vstate.sha256_out_keys, (out)) +static inline void monero_keccak_init_F(void) { + monero_hash_init_keccak((cx_hash_t *)&G_monero_vstate.keccakF); +} + +static inline void monero_keccak_update_F(const unsigned char *buf, size_t len) { + monero_hash_update((cx_hash_t *)&G_monero_vstate.keccakF, buf, len); +} + +static inline int monero_keccak_final_F(unsigned char *out) { + return monero_hash_final((cx_hash_t *)&G_monero_vstate.keccakF, 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); +} + +static inline void monero_keccak_init_H(void) { + monero_hash_init_keccak((cx_hash_t *)&G_monero_vstate.keccakH); +} + +static inline void monero_keccak_update_H(const unsigned char *buf, size_t len) { + 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); +} + +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); +} + +static inline void monero_sha256_commitment_init(void) { + monero_hash_init_sha256((cx_hash_t *)&G_monero_vstate.sha256_commitment); +} + +static inline void monero_sha256_commitment_update(const unsigned char *buf, size_t len) { + 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); +} + +static inline void monero_sha256_outkeys_init(void) { + monero_hash_init_sha256((cx_hash_t *)&G_monero_vstate.sha256_out_keys); +} + +static inline void monero_sha256_outkeys_update(const unsigned char *buf, size_t len) { + 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); +} /* * check 10 --- */ /* ----------------------------------------------------------------------- */ -unsigned int monero_decode_varint(unsigned char *varint, unsigned int max_len, uint64_t *value) { +unsigned int monero_decode_varint(const unsigned char *varint, size_t max_len, uint64_t *value) { uint64_t v; - int len; + size_t len; v = 0; len = 0; while ((varint[len]) & 0x80) { @@ -135,14 +135,18 @@ void monero_reverse32(unsigned char *rscal, unsigned char *scal) { /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -void monero_hash_init_sha256(cx_hash_t *hasher) { cx_sha256_init((cx_sha256_t *)hasher); } +void monero_hash_init_sha256(cx_hash_t *hasher) { + cx_sha256_init((cx_sha256_t *)hasher); +} -void monero_hash_init_keccak(cx_hash_t *hasher) { cx_keccak_init((cx_sha3_t *)hasher, 256); } +void monero_hash_init_keccak(cx_hash_t *hasher) { + cx_keccak_init((cx_sha3_t *)hasher, 256); +} /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -void monero_hash_update(cx_hash_t *hasher, unsigned char *buf, unsigned int len) { +void monero_hash_update(cx_hash_t *hasher, const unsigned char *buf, unsigned int len) { cx_hash(hasher, 0, buf, len, NULL, 0); } @@ -156,7 +160,7 @@ int monero_hash_final(cx_hash_t *hasher, unsigned char *out) { /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_hash(unsigned int algo, cx_hash_t *hasher, 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) { if (algo == CX_SHA256) { cx_sha256_init((cx_sha256_t *)hasher); @@ -304,8 +308,6 @@ void monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes) { #define rY (G_monero_vstate.io_buffer + 7 * 32) #define rZ (G_monero_vstate.io_buffer + 8 * 32) - //#define uv7 (G_monero_vstate.io_buffer+9*32) - //#define v3 (G_monero_vstate.io_buffer+10*32) union { unsigned char _Pxy[65]; struct { @@ -335,7 +337,7 @@ void monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes) { cx_math_multm(v, u, u, MOD); /* 2 * u^2 */ cx_math_addm(v, v, v, MOD); - os_memset(w, 0, 32); + memset(w, 0, 32); w[31] = 1; /* w = 1 */ cx_math_addm(w, v, w, MOD); /* w = 2 * u^2 + 1 */ cx_math_multm(x, w, w, MOD); /* w^2 */ @@ -359,7 +361,7 @@ void monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes) { cx_math_multm(y, rX, rX, MOD); cx_math_multm(x, y, x, MOD); cx_math_subm(y, w, x, MOD); - os_memmove(z, C_fe_ma, 32); + memcpy(z, C_fe_ma, 32); if (!cx_math_is_zero(y, 32)) { cx_math_addm(y, w, x, MOD); @@ -392,7 +394,6 @@ void monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes) { setsign: if (fe_isnegative(rX) != sign) { - // fe_neg(r->X, r->X); cx_math_sub(rX, (unsigned char *)C_ED25519_FIELD, rX, 32); } cx_math_addm(rZ, z, w, MOD); @@ -404,8 +405,8 @@ void monero_ge_fromfe_frombytes(unsigned char *ge, unsigned char *bytes) { Pxy[0] = 0x04; cx_math_multm(&Pxy[1], rX, u, MOD); cx_math_multm(&Pxy[1 + 32], rY, u, MOD); - cx_edward_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); - os_memmove(ge, &Pxy[1], 32); + cx_edwards_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(ge, &Pxy[1], 32); #undef u #undef v @@ -468,7 +469,7 @@ void monero_derivation_to_scalar(unsigned char *scalar, unsigned char *drv_data, unsigned char varint[32 + 8]; unsigned int len_varint; - os_memmove(varint, drv_data, 32); + memcpy(varint, drv_data, 32); len_varint = monero_encode_varint(varint + 32, 8, out_idx); len_varint += 32; monero_keccak_F(varint, len_varint, varint); @@ -522,17 +523,17 @@ void monero_generate_key_image(unsigned char *img, unsigned char *P, unsigned ch /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -void monero_derive_view_tag(unsigned char *view_tag, unsigned char *drv_data, +void 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; - os_memmove(varint, "view_tag", 8); - os_memmove(varint + 8, drv_data, 32); + memcpy(varint, "view_tag", 8); + memcpy(varint + 8, drv_data, 32); len_varint = monero_encode_varint(varint + 8 + 32, 8, out_idx); len_varint += 8 + 32; monero_keccak_F(varint, len_varint, varint); - os_memmove(view_tag, varint, 1); + *view_tag = varint[0]; } /* ======================================================================= */ @@ -582,9 +583,9 @@ void monero_get_subaddress_secret_key(unsigned char *sub_s, unsigned char *s, unsigned char *index) { unsigned char in[sizeof(C_sub_address_prefix) + 32 + 8]; - os_memmove(in, C_sub_address_prefix, sizeof(C_sub_address_prefix)), - os_memmove(in + sizeof(C_sub_address_prefix), s, 32); - os_memmove(in + sizeof(C_sub_address_prefix) + 32, index, 8); + memcpy(in, C_sub_address_prefix, sizeof(C_sub_address_prefix)); + memcpy(in + sizeof(C_sub_address_prefix), s, 32); + memcpy(in + sizeof(C_sub_address_prefix) + 32, index, 8); // hash_to_scalar with more that 32bytes: monero_keccak_F(in, sizeof(in), sub_s); monero_reduce(sub_s, sub_s); @@ -620,10 +621,10 @@ void monero_ecmul_G(unsigned char *W, unsigned char *scalar32) { unsigned char Pxy[65]; unsigned char s[32]; monero_reverse32(s, scalar32); - os_memmove(Pxy, C_ED25519_G, 65); + memcpy(Pxy, C_ED25519_G, 65); cx_ecfp_scalar_mult(CX_CURVE_Ed25519, Pxy, sizeof(Pxy), s, 32); - cx_edward_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); - os_memmove(W, &Pxy[1], 32); + cx_edwards_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(W, &Pxy[1], 32); } /* ----------------------------------------------------------------------- */ @@ -636,13 +637,13 @@ void monero_ecmul_H(unsigned char *W, unsigned char *scalar32) { monero_reverse32(s, scalar32); Pxy[0] = 0x02; - os_memmove(&Pxy[1], C_ED25519_Hy, 32); - cx_edward_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(&Pxy[1], C_ED25519_Hy, 32); + cx_edwards_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); cx_ecfp_scalar_mult(CX_CURVE_Ed25519, Pxy, sizeof(Pxy), s, 32); - cx_edward_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + cx_edwards_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); - os_memmove(W, &Pxy[1], 32); + memcpy(W, &Pxy[1], 32); } /* ----------------------------------------------------------------------- */ @@ -655,13 +656,13 @@ void monero_ecmul_k(unsigned char *W, unsigned char *P, unsigned char *scalar32) monero_reverse32(s, scalar32); Pxy[0] = 0x02; - os_memmove(&Pxy[1], P, 32); - cx_edward_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(&Pxy[1], P, 32); + cx_edwards_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); cx_ecfp_scalar_mult(CX_CURVE_Ed25519, Pxy, sizeof(Pxy), s, 32); - cx_edward_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + cx_edwards_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); - os_memmove(W, &Pxy[1], 32); + memcpy(W, &Pxy[1], 32); } /* ----------------------------------------------------------------------- */ @@ -680,13 +681,13 @@ void monero_ecmul_8(unsigned char *W, unsigned char *P) { unsigned char Pxy[65]; Pxy[0] = 0x02; - os_memmove(&Pxy[1], P, 32); - cx_edward_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(&Pxy[1], P, 32); + cx_edwards_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); cx_ecfp_add_point(CX_CURVE_Ed25519, Pxy, Pxy, Pxy, sizeof(Pxy)); cx_ecfp_add_point(CX_CURVE_Ed25519, Pxy, Pxy, Pxy, sizeof(Pxy)); cx_ecfp_add_point(CX_CURVE_Ed25519, Pxy, Pxy, Pxy, sizeof(Pxy)); - cx_edward_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); - os_memmove(W, &Pxy[1], 32); + cx_edwards_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(W, &Pxy[1], 32); } /* ----------------------------------------------------------------------- */ @@ -697,17 +698,17 @@ void monero_ecadd(unsigned char *W, unsigned char *P, unsigned char *Q) { unsigned char Qxy[65]; Pxy[0] = 0x02; - os_memmove(&Pxy[1], P, 32); - cx_edward_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(&Pxy[1], P, 32); + cx_edwards_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); Qxy[0] = 0x02; - os_memmove(&Qxy[1], Q, 32); - cx_edward_decompress_point(CX_CURVE_Ed25519, Qxy, sizeof(Qxy)); + memcpy(&Qxy[1], Q, 32); + cx_edwards_decompress_point(CX_CURVE_Ed25519, Qxy, sizeof(Qxy)); cx_ecfp_add_point(CX_CURVE_Ed25519, Pxy, Pxy, Qxy, sizeof(Pxy)); - cx_edward_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); - os_memmove(W, &Pxy[1], 32); + cx_edwards_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(W, &Pxy[1], 32); } /* ----------------------------------------------------------------------- */ @@ -718,18 +719,18 @@ void monero_ecsub(unsigned char *W, unsigned char *P, unsigned char *Q) { unsigned char Qxy[65]; Pxy[0] = 0x02; - os_memmove(&Pxy[1], P, 32); - cx_edward_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(&Pxy[1], P, 32); + cx_edwards_decompress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); Qxy[0] = 0x02; - os_memmove(&Qxy[1], Q, 32); - cx_edward_decompress_point(CX_CURVE_Ed25519, Qxy, sizeof(Qxy)); + memcpy(&Qxy[1], Q, 32); + cx_edwards_decompress_point(CX_CURVE_Ed25519, Qxy, sizeof(Qxy)); cx_math_sub(Qxy + 1, (unsigned char *)C_ED25519_FIELD, Qxy + 1, 32); cx_ecfp_add_point(CX_CURVE_Ed25519, Pxy, Pxy, Qxy, sizeof(Pxy)); - cx_edward_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); - os_memmove(W, &Pxy[1], 32); + cx_edwards_compress_point(CX_CURVE_Ed25519, Pxy, sizeof(Pxy)); + memcpy(W, &Pxy[1], 32); } /* ----------------------------------------------------------------------- */ @@ -748,8 +749,8 @@ void monero_ecsub(unsigned char *W, unsigned char *P, unsigned char *Q) { */ void monero_ecdhHash(unsigned char *x, unsigned char *k) { unsigned char data[38]; - os_memmove(data, "amount", 6); - os_memmove(data + 6, k, 32); + memcpy(data, "amount", 6); + memcpy(data + 6, k, 32); monero_keccak_F(data, 38, x); } @@ -769,8 +770,8 @@ void monero_ecdhHash(unsigned char *x, unsigned char *k) { */ void monero_genCommitmentMask(unsigned char *c, unsigned char *sk) { unsigned char data[15 + 32]; - os_memmove(data, "commitment_mask", 15); - os_memmove(data + 15, sk, 32); + memcpy(data, "commitment_mask", 15); + memcpy(data + 15, sk, 32); monero_hash_to_scalar(c, data, 15 + 32); } @@ -820,7 +821,7 @@ void monero_multm_8(unsigned char *r, unsigned char *a) { unsigned char rb[32]; monero_reverse32(ra, a); - os_memset(rb, 0, 32); + memset(rb, 0, 32); rb[31] = 8; cx_math_multm(r, ra, rb, (unsigned char *)C_ED25519_ORDER, 32); monero_reverse32(r, r); @@ -854,7 +855,7 @@ void monero_uint642str(uint64_t val, char *str, unsigned int str_len) { char stramount[22]; unsigned int offset, len; - os_memset(str, 0, str_len); + memset(str, 0, str_len); offset = 22; while (val) { @@ -866,7 +867,7 @@ void monero_uint642str(uint64_t val, char *str, unsigned int str_len) { if (len > str_len) { THROW(SW_WRONG_DATA_RANGE); } - os_memmove(str, stramount + offset, len); + memcpy(str, stramount + offset, len); } /* ----------------------------------------------------------------------- */ @@ -878,9 +879,9 @@ int monero_amount2str(uint64_t xmr, char *str, unsigned int str_len) { char stramount[22]; unsigned int offset, len, ov; - os_memset(str, 0, str_len); + memset(str, 0, str_len); - os_memset(stramount, '0', sizeof(stramount)); + memset(stramount, '0', sizeof(stramount)); stramount[21] = 0; // special case if (xmr == 0) { @@ -902,7 +903,7 @@ int monero_amount2str(uint64_t xmr, char *str, unsigned int str_len) { // offset: 0-7 | 8 | 9-20 |21 // ---------------------- // value: xmr | . | units| 0 - os_memmove(stramount, stramount + 1, 8); + memmove(stramount, stramount + 1, 8); stramount[8] = '.'; offset = 0; while ((stramount[offset] == '0') && (stramount[offset] != '.')) { @@ -921,7 +922,7 @@ int monero_amount2str(uint64_t xmr, char *str, unsigned int str_len) { len = str_len - 1; ov = 1; } - os_memmove(str, stramount + offset, len); + memcpy(str, stramount + offset, len); return ov; } @@ -949,7 +950,6 @@ int monero_bamount2str(unsigned char *binary, char *str, unsigned int str_len) { /* --- --- */ /* ----------------------------------------------------------------------- */ int monero_vamount2str(unsigned char *binary, char *str, unsigned int str_len) { - // return monero_amount2str(monero_vamount2uint64(binary), str,str_len); uint64_t amount; monero_decode_varint(binary, 8, &amount); return monero_amount2str(amount, str, str_len); diff --git a/src/monero_dispatch.c b/src/monero_dispatch.c index b11ff4e..be29f84 100644 --- a/src/monero_dispatch.c +++ b/src/monero_dispatch.c @@ -434,7 +434,7 @@ int monero_dispatch() { // 1. state machine check if ((G_monero_vstate.tx_state_ins != INS_VALIDATE) && // (G_monero_vstate.tx_state_ins != INS_MLSAG) && // - ((G_monero_vstate.protocol != 3) || (G_monero_vstate.protocol != 4))) { + (G_monero_vstate.protocol != 3 && G_monero_vstate.protocol != 4)) { THROW(SW_COMMAND_NOT_ALLOWED); } if (G_monero_vstate.tx_state_ins == INS_VALIDATE) { diff --git a/src/monero_init.c b/src/monero_init.c index bf2dd34..bfc9e27 100644 --- a/src/monero_init.c +++ b/src/monero_init.c @@ -38,10 +38,10 @@ const unsigned char C_FAKE_SEC_SPEND_KEY[32] = { /* --- Boot --- */ /* ----------------------------------------------------------------------- */ void monero_init() { - os_memset(&G_monero_vstate, 0, sizeof(monero_v_state_t)); + memset(&G_monero_vstate, 0, sizeof(monero_v_state_t)); // first init ? - if (os_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 @@ -64,11 +64,11 @@ void monero_init() { /* --- init private keys --- */ /* ----------------------------------------------------------------------- */ void monero_wipe_private_key() { - os_memset(G_monero_vstate.a, 0, 32); - os_memset(G_monero_vstate.b, 0, 32); - os_memset(G_monero_vstate.A, 0, 32); - os_memset(G_monero_vstate.B, 0, 32); - os_memset(&G_monero_vstate.spk, 0, sizeof(G_monero_vstate.spk)); + memset(G_monero_vstate.a, 0, 32); + memset(G_monero_vstate.b, 0, 32); + memset(G_monero_vstate.A, 0, 32); + memset(G_monero_vstate.B, 0, 32); + memset(&G_monero_vstate.spk, 0, sizeof(G_monero_vstate.spk)); G_monero_vstate.key_set = 0; } @@ -98,8 +98,8 @@ void monero_init_private_key() { break; case KEY_MODE_EXTERNAL: - os_memmove(G_monero_vstate.a, (void*)N_monero_pstate->a, 32); - os_memmove(G_monero_vstate.b, (void*)N_monero_pstate->b, 32); + memcpy(G_monero_vstate.a, (void*)N_monero_pstate->a, 32); + memcpy(G_monero_vstate.b, (void*)N_monero_pstate->b, 32); break; default: @@ -121,24 +121,24 @@ void monero_init_private_key() { void monero_init_ux() { monero_base58_public_key(G_monero_vstate.ux_address, G_monero_vstate.A, G_monero_vstate.B, 0, NULL); - os_memset(G_monero_vstate.ux_wallet_public_short_address, '.', - sizeof(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)); #ifdef HAVE_UX_FLOW #ifdef UI_NANO_X snprintf(G_monero_vstate.ux_wallet_account_name, sizeof(G_monero_vstate.ux_wallet_account_name), "XMR / %d", N_monero_pstate->account_id); - os_memmove(G_monero_vstate.ux_wallet_public_short_address, G_monero_vstate.ux_address, 5); - os_memmove(G_monero_vstate.ux_wallet_public_short_address + 7, - G_monero_vstate.ux_address + 95 - 5, 5); + 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, + 5); G_monero_vstate.ux_wallet_public_short_address[12] = 0; #else snprintf(G_monero_vstate.ux_wallet_account_name, sizeof(G_monero_vstate.ux_wallet_account_name), " XMR / %d", N_monero_pstate->account_id); - os_memmove(G_monero_vstate.ux_wallet_public_short_address, G_monero_vstate.ux_address, 4); - os_memmove(G_monero_vstate.ux_wallet_public_short_address + 6, - G_monero_vstate.ux_address + 95 - 4, 4); + memcpy(G_monero_vstate.ux_wallet_public_short_address, G_monero_vstate.ux_address, 4); + memcpy(G_monero_vstate.ux_wallet_public_short_address + 6, G_monero_vstate.ux_address + 95 - 4, + 4); G_monero_vstate.ux_wallet_public_short_address[10] = 0; #endif @@ -146,9 +146,9 @@ void monero_init_ux() { snprintf(G_monero_vstate.ux_wallet_account_name, sizeof(G_monero_vstate.ux_wallet_account_name), "XMR / %d", N_monero_pstate->account_id); - os_memmove(G_monero_vstate.ux_wallet_public_short_address, G_monero_vstate.ux_address, 5); - os_memmove(G_monero_vstate.ux_wallet_public_short_address + 7, - G_monero_vstate.ux_address + 95 - 5, 5); + 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, + 5); G_monero_vstate.ux_wallet_public_short_address[12] = 0; #endif diff --git a/src/monero_io.c b/src/monero_io.c index 65c9b5a..0f350bb 100644 --- a/src/monero_io.c +++ b/src/monero_io.c @@ -50,7 +50,9 @@ void monero_io_set_offset(unsigned int offset) { } } -void monero_io_mark() { G_monero_vstate.io_mark = G_monero_vstate.io_offset; } +void monero_io_mark() { + G_monero_vstate.io_mark = G_monero_vstate.io_offset; +} void monero_io_inserted(unsigned int len) { G_monero_vstate.io_offset += len; @@ -66,7 +68,9 @@ void monero_io_discard(int clear) { } } -void monero_io_clear() { os_memset(G_monero_vstate.io_buffer, 0, MONERO_IO_BUFFER_LENGTH); } +void monero_io_clear() { + memset(G_monero_vstate.io_buffer, 0, MONERO_IO_BUFFER_LENGTH); +} /* ----------------------------------------------------------------------- */ /* INSERT data to be sent */ @@ -76,15 +80,15 @@ void monero_io_hole(unsigned int sz) { if ((G_monero_vstate.io_length + sz) > MONERO_IO_BUFFER_LENGTH) { THROW(ERROR_IO_FULL); } - os_memmove(G_monero_vstate.io_buffer + G_monero_vstate.io_offset + sz, - G_monero_vstate.io_buffer + G_monero_vstate.io_offset, - G_monero_vstate.io_length - G_monero_vstate.io_offset); + memmove(G_monero_vstate.io_buffer + G_monero_vstate.io_offset + sz, + G_monero_vstate.io_buffer + G_monero_vstate.io_offset, + G_monero_vstate.io_length - G_monero_vstate.io_offset); G_monero_vstate.io_length += sz; } void monero_io_insert(unsigned char const* buff, unsigned int len) { monero_io_hole(len); - os_memmove(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, buff, len); + memcpy(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, buff, len); G_monero_vstate.io_offset += len; } @@ -96,7 +100,7 @@ void monero_io_insert_hmac_for(unsigned char* buffer, int len, int type) { unsigned char hmac[32 + 1 + 4]; - os_memmove(hmac, buffer, 32); + memcpy(hmac, buffer, 32); hmac[32] = type; if (type == TYPE_ALPHA) { hmac[33] = (G_monero_vstate.tx_sign_cnt >> 0) & 0xFF; @@ -126,7 +130,7 @@ void monero_io_insert_encrypt(unsigned char* buffer, int len, int type) { G_monero_vstate.io_buffer[G_monero_vstate.io_offset + i] = buffer[i] ^ 0x55; } #elif defined(IONOCRYPT) - os_memmove(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, buffer, len); + memcpy(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, buffer, len); #else cx_aes(&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); @@ -196,7 +200,9 @@ void monero_io_insert_tlv(unsigned int T, unsigned int L, unsigned char const* V /* ----------------------------------------------------------------------- */ /* FECTH data from received buffer */ /* ----------------------------------------------------------------------- */ -int monero_io_fetch_available() { return G_monero_vstate.io_length - G_monero_vstate.io_offset; } +int monero_io_fetch_available(void) { + return G_monero_vstate.io_length - G_monero_vstate.io_offset; +} void monero_io_assert_available(int sz) { if ((G_monero_vstate.io_length - G_monero_vstate.io_offset) < sz) { THROW(SW_WRONG_LENGTH + (sz & 0xFF)); @@ -206,7 +212,7 @@ void monero_io_assert_available(int sz) { int monero_io_fetch(unsigned char* buffer, int len) { monero_io_assert_available(len); if (buffer) { - os_memmove(buffer, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, len); + memcpy(buffer, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, len); } G_monero_vstate.io_offset += len; return len; @@ -220,7 +226,7 @@ static void monero_io_verify_hmac_for(const unsigned char* buffer, int len, } unsigned char hmac[37]; - os_memmove(hmac, buffer, 32); + memcpy(hmac, buffer, 32); hmac[32] = type; if (type == TYPE_ALPHA) { hmac[33] = (G_monero_vstate.tx_sign_cnt >> 0) & 0xFF; @@ -234,7 +240,7 @@ static void monero_io_verify_hmac_for(const unsigned char* buffer, int len, hmac[36] = 0; } cx_hmac_sha256(G_monero_vstate.hmac_key, 32, hmac, 37, hmac, 32); - if (os_memcmp(hmac, expected_hmac, 32)) { + if (memcmp(hmac, expected_hmac, 32) != 0) { monero_lock_and_throw(SW_SECURITY_HMAC); } } @@ -260,7 +266,7 @@ int monero_io_fetch_decrypt(unsigned char* buffer, int len, int type) { buffer[i] = G_monero_vstate.io_buffer[G_monero_vstate.io_offset + i] ^ 0x55; } #elif defined(IONOCRYPT) - os_memmove(buffer, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, len); + memcpy(buffer, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, len); #else // IOCRYPT cx_aes(&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); @@ -293,7 +299,7 @@ int monero_io_fetch_decrypt_key(unsigned char* buffer) { k = G_monero_vstate.io_buffer + G_monero_vstate.io_offset; // view? - if (os_memcmp(k, C_FAKE_SEC_VIEW_KEY, 32) == 0) { + if (memcmp(k, C_FAKE_SEC_VIEW_KEY, 32) == 0) { G_monero_vstate.io_offset += 32; if (G_monero_vstate.tx_in_progress) { monero_io_assert_available(32); @@ -302,11 +308,11 @@ int monero_io_fetch_decrypt_key(unsigned char* buffer) { TYPE_SCALAR); G_monero_vstate.io_offset += 32; } - os_memmove(buffer, G_monero_vstate.a, 32); + memcpy(buffer, G_monero_vstate.a, 32); return 32; } // spend? - else if (os_memcmp(k, C_FAKE_SEC_SPEND_KEY, 32) == 0) { + else if (memcmp(k, C_FAKE_SEC_SPEND_KEY, 32) == 0) { switch (G_monero_vstate.io_ins) { case INS_VERIFY_KEY: case INS_DERIVE_SECRET_KEY: @@ -322,7 +328,7 @@ int monero_io_fetch_decrypt_key(unsigned char* buffer) { G_monero_vstate.io_buffer + G_monero_vstate.io_offset, TYPE_SCALAR); } - os_memmove(buffer, G_monero_vstate.b, 32); + memcpy(buffer, G_monero_vstate.b, 32); return 32; } // else @@ -432,8 +438,8 @@ int monero_io_do(unsigned int io_flags) { if (G_monero_vstate.io_length > MAX_OUT) { THROW(SW_IO_FULL); } - os_memmove(G_io_apdu_buffer, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, - G_monero_vstate.io_length); + 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) { monero_io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, G_monero_vstate.io_length); @@ -453,7 +459,7 @@ int monero_io_do(unsigned int io_flags) { G_monero_vstate.io_lc = 0; G_monero_vstate.io_le = 0; G_monero_vstate.io_lc = G_io_apdu_buffer[4]; - os_memmove(G_monero_vstate.io_buffer, G_io_apdu_buffer + 5, G_monero_vstate.io_lc); + memcpy(G_monero_vstate.io_buffer, G_io_apdu_buffer + 5, G_monero_vstate.io_lc); G_monero_vstate.io_length = G_monero_vstate.io_lc; return 0; diff --git a/src/monero_key.c b/src/monero_key.c index 0f552db..828607a 100644 --- a/src/monero_key.c +++ b/src/monero_key.c @@ -73,7 +73,7 @@ static unsigned long monero_crc32(unsigned long inCrc32, const void *buf, size_t return (crc32 ^ 0xFFFFFFFF); } -void monero_clear_words() { +void monero_clear_words(void) { monero_nvm_write((void *)N_monero_pstate->words_list, NULL, sizeof(N_monero_pstate->words_list)); } @@ -109,7 +109,7 @@ static void monero_set_word(unsigned int n, unsigned int idx, unsigned int w_sta #define word_list_length 1626 #define seed G_monero_vstate.b -int monero_apdu_manage_seedwords() { +int monero_apdu_manage_seedwords(void) { unsigned int w_start, w_end; unsigned short wc[4]; @@ -156,10 +156,10 @@ int monero_apdu_manage_seedwords() { w_start = 0; for (int i = 0; i < 24; i++) { w_end = N_monero_pstate->words[i][0]; - os_memmove(word, &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(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; } #endif @@ -215,8 +215,8 @@ int monero_apdu_display_address() { if (minor | major) { monero_get_subaddress(C, D, index); } else { - os_memmove(C, G_monero_vstate.A, 32); - os_memmove(D, G_monero_vstate.B, 32); + memcpy(C, G_monero_vstate.A, 32); + memcpy(D, G_monero_vstate.B, 32); } // prepare UI @@ -241,9 +241,13 @@ int monero_apdu_display_address() { /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int is_fake_view_key(unsigned char *s) { return os_memcmp(s, C_FAKE_SEC_VIEW_KEY, 32) == 0; } +int is_fake_view_key(unsigned char *s) { + return memcmp(s, C_FAKE_SEC_VIEW_KEY, 32) == 0; +} -int is_fake_spend_key(unsigned char *s) { return os_memcmp(s, C_FAKE_SEC_SPEND_KEY, 32) == 0; } +int is_fake_spend_key(unsigned char *s) { + return memcmp(s, C_FAKE_SEC_SPEND_KEY, 32) == 0; +} /* ----------------------------------------------------------------------- */ /* --- --- */ @@ -263,7 +267,7 @@ int monero_apdu_put_key() { monero_io_fetch(sec, 32); monero_io_fetch(pub, 32); monero_ecmul_G(raw, sec); - if (os_memcmp(pub, raw, 32)) { + if (memcmp(pub, raw, 32) != 0) { THROW(SW_WRONG_DATA); return SW_WRONG_DATA; } @@ -273,7 +277,7 @@ int monero_apdu_put_key() { monero_io_fetch(sec, 32); monero_io_fetch(pub, 32); monero_ecmul_G(raw, sec); - if (os_memcmp(pub, raw, 32)) { + if (memcmp(pub, raw, 32) != 0) { THROW(SW_WRONG_DATA); return SW_WRONG_DATA; } @@ -368,15 +372,15 @@ int monero_apdu_verify_key() { monero_secret_key_to_public_key(computed_pub, priv); break; case 1: - os_memmove(computed_pub, G_monero_vstate.A, 32); + memcpy(computed_pub, G_monero_vstate.A, 32); break; case 2: - os_memmove(computed_pub, G_monero_vstate.B, 32); + memcpy(computed_pub, G_monero_vstate.B, 32); break; default: THROW(SW_WRONG_P1P2); } - if (os_memcmp(computed_pub, pub, 32) == 0) { + if (memcmp(computed_pub, pub, 32) == 0) { verified = 1; } @@ -394,8 +398,8 @@ int monero_apdu_get_chacha8_prekey(/*char *prekey*/) { unsigned char pre[32]; monero_io_discard(0); - os_memmove(abt, G_monero_vstate.a, 32); - os_memmove(abt + 32, G_monero_vstate.b, 32); + memcpy(abt, G_monero_vstate.a, 32); + memcpy(abt + 32, G_monero_vstate.b, 32); abt[64] = CHACHA8_KEY_TAIL; monero_keccak_F(abt, 65, pre); monero_io_insert((unsigned char *)G_monero_vstate.keccakF.acc, 200); @@ -420,8 +424,8 @@ int monero_apdu_sc_add(/*unsigned char *r, unsigned char *s1, unsigned char *s2* // https://github.com/monero-project/monero/blob/v0.15.0.5/src/cryptonote_basic/cryptonote_format_utils.cpp#L331 // // hwdev.sc_secret_add(scalar_step2, scalar_step1,subaddr_sk); - if ((os_memcmp(s1, G_monero_vstate.last_derive_secret_key, 32) != 0) || - (os_memcmp(s2, G_monero_vstate.last_get_subaddress_secret_key, 32) != 0)) { + if ((memcmp(s1, G_monero_vstate.last_derive_secret_key, 32) != 0) || + (memcmp(s2, G_monero_vstate.last_get_subaddress_secret_key, 32) != 0)) { monero_lock_and_throw(SW_WRONG_DATA); } } @@ -577,7 +581,7 @@ int monero_apdu_derive_secret_key(/*const crypto::key_derivation &derivation, co monero_derive_secret_key(drvsec, derivation, output_index, sec); // sec key - os_memmove(G_monero_vstate.last_derive_secret_key, drvsec, 32); + memcpy(G_monero_vstate.last_derive_secret_key, drvsec, 32); monero_io_insert_encrypt(drvsec, 32, TYPE_SCALAR); return SW_OK; } @@ -704,7 +708,7 @@ int monero_apdu_get_subaddress_secret_key(/*const crypto::secret_key& sec, const monero_get_subaddress_secret_key(sub_sec, sec, index); - os_memmove(G_monero_vstate.last_get_subaddress_secret_key, sub_sec, 32); + memcpy(G_monero_vstate.last_get_subaddress_secret_key, sub_sec, 32); monero_io_insert_encrypt(sub_sec, 32, TYPE_SCALAR); return SW_OK; } @@ -715,7 +719,6 @@ int monero_apdu_get_subaddress_secret_key(/*const crypto::secret_key& sec, const int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_sec, crypto::public_key Aout, crypto::public_key Bout, size_t output_index, bool is_change, bool is_subaddress, bool need_additional_key, bool use_view_tags*/) { // IN - unsigned int tx_version; unsigned char tx_key[32]; unsigned char *txkey_pub; unsigned char *Aout; @@ -734,7 +737,7 @@ int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_se // TMP unsigned char derivation[32]; - tx_version = monero_io_fetch_u32(); + monero_io_fetch_u32(); // skip tx_version monero_io_fetch_decrypt_key(tx_key); txkey_pub = G_monero_vstate.io_buffer + G_monero_vstate.io_offset; monero_io_fetch(NULL, 32); @@ -770,7 +773,7 @@ int monero_apu_generate_txout_keys(/*size_t tx_version, crypto::secret_key tx_se monero_ecmul_G(additional_txkey_pub, additional_txkey_sec); } } else { - os_memset(additional_txkey_pub, 0, 32); + memset(additional_txkey_pub, 0, 32); } // derivation diff --git a/src/monero_main.c b/src/monero_main.c index 9360f7e..e82f812 100644 --- a/src/monero_main.c +++ b/src/monero_main.c @@ -51,7 +51,6 @@ void monero_main(void) { sw = 0; cont = 0; monero_io_discard(1); - // THROW(EXCEPTION_IO_RESET); } CATCH_OTHER(e) { monero_reset_tx(1); @@ -80,7 +79,7 @@ void monero_main(void) { } } -unsigned char io_event(unsigned char channel) { +unsigned char io_event(unsigned char channel __attribute__((unused))) { unsigned int s_before; unsigned int s_after; @@ -164,8 +163,11 @@ unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) { void app_exit(void) { BEGIN_TRY_L(exit) { - TRY_L(exit) { os_sched_exit(-1); } - FINALLY_L(exit) {} + TRY_L(exit) { + os_sched_exit(-1); + } + FINALLY_L(exit) { + } } END_TRY_L(exit); } @@ -216,8 +218,11 @@ __attribute__((section(".boot"))) int main(void) { // reset IO and UX ; } - CATCH_OTHER(e) { cont = 0; } - FINALLY {} + CATCH_OTHER(e) { + cont = 0; + } + FINALLY { + } } END_TRY; } diff --git a/src/monero_mlsag.c b/src/monero_mlsag.c index 415cc93..7c255d5 100644 --- a/src/monero_mlsag.c +++ b/src/monero_mlsag.c @@ -79,7 +79,7 @@ int monero_apdu_mlsag_hash() { unsigned char c[32]; if (G_monero_vstate.io_p2 == 1) { monero_keccak_init_H(); - os_memmove(msg, G_monero_vstate.mlsagH, 32); + memcpy(msg, G_monero_vstate.mlsagH, 32); } else { monero_io_fetch(msg, 32); } @@ -90,7 +90,7 @@ int monero_apdu_mlsag_hash() { monero_keccak_final_H(c); monero_reduce(c, c); monero_io_insert(c, 32); - os_memmove(G_monero_vstate.c, c, 32); + memcpy(G_monero_vstate.c, c, 32); } return SW_OK; } diff --git a/src/monero_monero.c b/src/monero_monero.c index 783f21b..91a9681 100644 --- a/src/monero_monero.c +++ b/src/monero_monero.c @@ -116,7 +116,6 @@ int monero_base58_public_key(char* str_b58, unsigned char* view, unsigned char* unsigned int offset; unsigned int prefix; - // data[0] = N_monero_pstate->network_id; switch (N_monero_pstate->network_id) { case TESTNET: if (paymanetID) { @@ -147,18 +146,21 @@ int monero_base58_public_key(char* str_b58, unsigned char* view, unsigned char* } break; #endif + default: + str_b58[0] = 0; + return 0; } offset = monero_encode_varint(data, 8, prefix); - os_memmove(data + offset, spend, 32); - os_memmove(data + offset + 32, view, 32); + memcpy(data + offset, spend, 32); + memcpy(data + offset + 32, view, 32); offset += 64; if (paymanetID) { - os_memmove(data + offset, paymanetID, 8); + memcpy(data + offset, paymanetID, 8); offset += 8; } monero_keccak_F(data, offset, G_monero_vstate.mlsagH); - os_memmove(data + offset, G_monero_vstate.mlsagH, 4); + memcpy(data + offset, G_monero_vstate.mlsagH, 4); offset += 4; unsigned int full_block_count = (offset) / FULL_BLOCK_SIZE; diff --git a/src/monero_open_tx.c b/src/monero_open_tx.c index 093eec0..618b901 100644 --- a/src/monero_open_tx.c +++ b/src/monero_open_tx.c @@ -26,8 +26,8 @@ /* --- --- */ /* ----------------------------------------------------------------------- */ void monero_reset_tx(int reset_tx_cnt) { - os_memset(G_monero_vstate.r, 0, 32); - os_memset(G_monero_vstate.R, 0, 32); + memset(G_monero_vstate.r, 0, 32); + memset(G_monero_vstate.R, 0, 32); cx_rng(G_monero_vstate.hmac_key, 32); monero_keccak_init_H(); @@ -47,18 +47,13 @@ void monero_reset_tx(int reset_tx_cnt) { * HD wallet not yet supported : account is assumed to be zero */ int monero_apdu_open_tx() { - unsigned int account; - - account = monero_io_fetch_u32(); + monero_io_fetch_u32(); // skip account monero_io_discard(1); monero_reset_tx(0); G_monero_vstate.tx_cnt++; ui_menu_opentx_display(0); - if (G_monero_vstate.tx_sig_mode == TRANSACTION_CREATE_REAL) { - // return 0; - } return monero_apdu_open_tx_cont(); } @@ -66,7 +61,7 @@ int monero_apdu_open_tx_cont() { G_monero_vstate.tx_in_progress = 1; #ifdef DEBUG_HWDEVICE - os_memset(G_monero_vstate.hmac_key, 0xab, 32); + memset(G_monero_vstate.hmac_key, 0xab, 32); #else cx_rng(G_monero_vstate.hmac_key, 32); #endif diff --git a/src/monero_prefix.c b/src/monero_prefix.c index dac5e50..c08c4e7 100644 --- a/src/monero_prefix.c +++ b/src/monero_prefix.c @@ -29,7 +29,7 @@ /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_apdu_prefix_hash_init() { +int monero_apdu_prefix_hash_init(void) { uint64_t timelock; monero_keccak_update_H(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, @@ -59,7 +59,7 @@ int monero_apdu_prefix_hash_init() { /* ----------------------------------------------------------------------- */ /* --- --- */ /* ----------------------------------------------------------------------- */ -int monero_apdu_prefix_hash_update() { +int monero_apdu_prefix_hash_update(void) { monero_keccak_update_H(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, G_monero_vstate.io_length - G_monero_vstate.io_offset); monero_io_discard(0); diff --git a/src/monero_prehash.c b/src/monero_prehash.c index 7e3cb96..f016981 100644 --- a/src/monero_prehash.c +++ b/src/monero_prehash.c @@ -119,9 +119,9 @@ int monero_apdu_mlsag_prehash_update() { monero_ecmul_H(aH, v); monero_ecadd(aH, kG, aH); } else { - os_memmove(aH, kG, 32); + memcpy(aH, kG, 32); } - if (os_memcmp(C, aH, 32)) { + if (memcmp(C, aH, 32) != 0) { monero_lock_and_throw(SW_SECURITY_COMMITMENT_CONTROL); } // update commitment hash control @@ -131,7 +131,7 @@ int monero_apdu_mlsag_prehash_update() { if (G_monero_vstate.io_protocol_version >= 2) { // finalize and check destination hash_control monero_sha256_outkeys_final(k); - if (os_memcmp(k, G_monero_vstate.OUTK, 32)) { + if (memcmp(k, G_monero_vstate.OUTK, 32) != 0) { monero_lock_and_throw(SW_SECURITY_OUTKEYS_CHAIN_CONTROL); } } @@ -176,7 +176,7 @@ int monero_apdu_mlsag_prehash_finalize() { // Finalize and check commitment hash control if (G_monero_vstate.tx_sig_mode == TRANSACTION_CREATE_REAL) { monero_sha256_commitment_final(H); - if (os_memcmp(H, G_monero_vstate.C, 32)) { + if (memcmp(H, G_monero_vstate.C, 32) != 0) { monero_lock_and_throw(SW_SECURITY_COMMITMENT_CHAIN_CONTROL); } } @@ -188,7 +188,7 @@ int monero_apdu_mlsag_prehash_finalize() { monero_io_discard(1); monero_keccak_init_H(); if (G_monero_vstate.io_protocol_version >= 3) { - if (os_memcmp(message, G_monero_vstate.prefixH, 32) != 0) { + if (memcmp(message, G_monero_vstate.prefixH, 32) != 0) { monero_lock_and_throw(SW_SECURITY_PREFIX_HASH); } } diff --git a/src/monero_proof.c b/src/monero_proof.c index 9708e47..ca4b265 100644 --- a/src/monero_proof.c +++ b/src/monero_proof.c @@ -55,9 +55,9 @@ int monero_apdu_get_tx_proof() { // Generate random k monero_rng_mod_order(k); // tmp = msg - os_memmove(G_monero_vstate.tmp + 32 * 0, msg, 32); + memcpy(G_monero_vstate.tmp + 32 * 0, msg, 32); // tmp = msg || D - os_memmove(G_monero_vstate.tmp + 32 * 1, D, 32); + memcpy(G_monero_vstate.tmp + 32 * 1, D, 32); if (G_monero_vstate.options & 1) { // X = kB @@ -67,21 +67,21 @@ int monero_apdu_get_tx_proof() { monero_ecmul_G(XY, k); } // tmp = msg || D || X - os_memmove(G_monero_vstate.tmp + 32 * 2, XY, 32); + memcpy(G_monero_vstate.tmp + 32 * 2, XY, 32); // Y = kA monero_ecmul_k(XY, A, k); // tmp = msg || D || X || Y - os_memmove(G_monero_vstate.tmp + 32 * 3, XY, 32); + memcpy(G_monero_vstate.tmp + 32 * 3, XY, 32); monero_keccak_H((unsigned char *)"TXPROOF_V2", 10, sep); // tmp = msg || D || X || Y || sep - os_memmove(G_monero_vstate.tmp + 32 * 4, sep, 32); + memcpy(G_monero_vstate.tmp + 32 * 4, sep, 32); // tmp = msg || D || X || Y || sep || R - os_memmove(G_monero_vstate.tmp + 32 * 5, R, 32); + memcpy(G_monero_vstate.tmp + 32 * 5, R, 32); // tmp = msg || D || X || Y || sep || R || A - os_memmove(G_monero_vstate.tmp + 32 * 6, A, 32); + memcpy(G_monero_vstate.tmp + 32 * 6, A, 32); // tmp = msg || D || X || Y || sep || R || B or [0] - os_memmove(G_monero_vstate.tmp + 32 * 7, B, 32); + memcpy(G_monero_vstate.tmp + 32 * 7, B, 32); // sig_c = H_n(tmp) monero_hash_to_scalar(sig_c, &G_monero_vstate.tmp[0], 32 * 8); diff --git a/src/monero_ux_nano.c b/src/monero_ux_nano.c index efb1194..1893f52 100644 --- a/src/monero_ux_nano.c +++ b/src/monero_ux_nano.c @@ -85,16 +85,22 @@ UX_STEP_CB(ux_menu_words_3_step, pb, ui_menu_words_back(0), {&C_icon_back, "back UX_FLOW(ux_flow_words, &ux_menu_words_1_step, &ux_menu_words_2_step, &ux_menu_words_3_step); -void ui_menu_words_clear(unsigned int value) { +void ui_menu_words_clear(unsigned int value __attribute__((unused))) { monero_clear_words(); ui_menu_main_display(0); } -void ui_menu_words_back(unsigned int value) { ui_menu_main_display(1); } +void ui_menu_words_back(unsigned int value __attribute__((unused))) { + ui_menu_main_display(1); +} -void ui_menu_words_display(unsigned int value) { ux_flow_init(0, ux_flow_words, NULL); } +void ui_menu_words_display(unsigned int value __attribute__((unused))) { + ux_flow_init(0, ux_flow_words, NULL); +} -void settings_show_25_words(void) { ui_menu_words_display(0); } +void settings_show_25_words(void) { + ui_menu_words_display(0); +} /* -------------------------------- INFO UX --------------------------------- */ unsigned int ui_menu_info_action(unsigned int value); @@ -106,7 +112,7 @@ UX_STEP_CB(ux_menu_info_1_step, nn, ui_menu_info_action(0), UX_FLOW(ux_flow_info, &ux_menu_info_1_step); -unsigned int ui_menu_info_action(unsigned int value) { +unsigned int ui_menu_info_action(unsigned int value __attribute__((unused))) { if (G_monero_vstate.protocol_barrier == PROTOCOL_LOCKED) { ui_menu_pinlock_display(); } else { @@ -115,13 +121,15 @@ unsigned int ui_menu_info_action(unsigned int value) { return 0; } -void ui_menu_info_display2(unsigned int value, char* line1, char* line2) { +void ui_menu_info_display2(unsigned int value __attribute__((unused)), char* line1, 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); ux_flow_init(0, ux_flow_info, NULL); } -void ui_menu_info_display(unsigned int value) { ux_flow_init(0, ux_flow_info, NULL); } +void ui_menu_info_display(unsigned int value __attribute__((unused))) { + ux_flow_init(0, ux_flow_info, NULL); +} /* -------------------------------- OPEN TX UX --------------------------------- */ unsigned int ui_menu_opentx_action(unsigned int value); @@ -135,18 +143,17 @@ UX_STEP_CB(ux_menu_opentx_3_step, pb, ui_menu_opentx_action(REJECT), {&C_icon_cr UX_FLOW(ux_flow_opentx, &ux_menu_opentx_1_step, &ux_menu_opentx_2_step, &ux_menu_opentx_3_step); unsigned int ui_menu_opentx_action(unsigned int value) { - unsigned int sw; + unsigned int sw = SW_OK; unsigned char x[32]; monero_io_discard(0); - os_memset(x, 0, 32); - sw = SW_OK; + memset(x, 0, 32); if (value == ACCEPT) { sw = monero_apdu_open_tx_cont(); ui_menu_info_display2(0, "Processing TX", "..."); } else { - monero_abort_tx(0); + monero_abort_tx(); sw = SW_DENY; ui_menu_info_display2(0, "Transaction", "aborted"); } @@ -166,7 +173,7 @@ void ui_menu_opentx_display(unsigned int value) { } } #else -void ui_menu_opentx_display(unsigned int value) { +void ui_menu_opentx_display(unsigned int value __attribute__((unused))) { uint32_t i; if (G_monero_vstate.tx_sig_mode == TRANSACTION_CREATE_REAL) { snprintf(G_monero_vstate.ux_info1, sizeof(G_monero_vstate.ux_info1), "Processing TX"); @@ -229,7 +236,7 @@ void ui_menu_amount_validation_action(unsigned int value) { if (value == ACCEPT) { sw = SW_OK; } else { - monero_abort_tx(0); + monero_abort_tx(); sw = SW_DENY; } monero_io_insert_u16(sw); @@ -237,13 +244,15 @@ void ui_menu_amount_validation_action(unsigned int value) { ui_menu_info_display2(0, "Processing TX", "..."); } -void ui_menu_fee_validation_display(unsigned int value) { ux_flow_init(0, ux_flow_fee, NULL); } +void ui_menu_fee_validation_display(unsigned int value __attribute__((unused))) { + ux_flow_init(0, ux_flow_fee, NULL); +} -void ui_menu_change_validation_display(unsigned int value) { +void ui_menu_change_validation_display(unsigned int value __attribute__((unused))) { ux_flow_init(0, ux_flow_change, NULL); } -void ui_menu_timelock_validation_display(unsigned int value) { +void ui_menu_timelock_validation_display(unsigned int value __attribute__((unused))) { ux_flow_init(0, ux_flow_timelock, NULL); } /* ----------------------------- USER DEST/AMOUNT VALIDATION ----------------------------- */ @@ -268,14 +277,16 @@ UX_STEP_CB(ux_menu_validation_4_step, pb, ui_menu_validation_action(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); -void ui_menu_validation_display(unsigned int value) { ux_flow_init(0, ux_flow_validation, NULL); } +void ui_menu_validation_display(unsigned int value __attribute__((unused))) { + ux_flow_init(0, ux_flow_validation, NULL); +} void ui_menu_validation_action(unsigned int value) { unsigned short sw; if (value == ACCEPT) { sw = SW_OK; } else { - monero_abort_tx(0); + monero_abort_tx(); sw = SW_DENY; } monero_io_insert_u16(sw); @@ -297,7 +308,7 @@ UX_STEP_CB(ux_menu_export_viewkey_3_step, pb, ui_menu_export_viewkey_action(REJE 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) { +void ui_export_viewkey_display(unsigned int value __attribute__((unused))) { ux_flow_init(0, ux_flow_export_viewkey, NULL); } @@ -306,7 +317,7 @@ unsigned int ui_menu_export_viewkey_action(unsigned int value) { unsigned char x[32]; monero_io_discard(0); - os_memset(x, 0, 32); + memset(x, 0, 32); sw = SW_OK; if (value == ACCEPT) { @@ -340,7 +351,9 @@ const char* account_submenu_getter(unsigned int idx) { } } -void account_back(void) { ui_menu_main_display(0); } +void account_back(void) { + ui_menu_main_display(0); +} void account_submenu_selector(unsigned int idx) { if (idx <= 9) { @@ -350,11 +363,13 @@ void account_submenu_selector(unsigned int idx) { ui_menu_main_display(0); } -void ui_menu_account_display(unsigned int value) { +void ui_menu_account_display(void) { ux_menulist_init(G_ux.stack_count - 1, account_submenu_getter, account_submenu_selector); } -void settings_change_account(void) { ui_menu_account_display(0); } +void settings_change_account(void) { + ui_menu_account_display(); +} /* -------------------------------- NETWORK UX --------------------------------- */ @@ -403,7 +418,9 @@ const char* network_submenu_getter(unsigned int idx) { } } -void network_back(void) { ui_menu_main_display(0); } +void network_back(void) { + ui_menu_main_display(0); +} static void network_set_net(unsigned int network) { monero_install(network); @@ -429,13 +446,15 @@ void network_submenu_selector(unsigned int idx) { ui_menu_main_display(0); } -void ui_menu_network_display(unsigned int value) { +void ui_menu_network_display(void) { ux_menulist_init(G_ux.stack_count - 1, network_submenu_getter, network_submenu_selector); } -void settings_change_network(void) { ui_menu_network_display(0); } +void settings_change_network(void) { + ui_menu_network_display(); +} /* -------------------------------- RESET UX --------------------------------- */ -void ui_menu_reset_display(unsigned int value); +void ui_menu_reset_display(void); void ui_menu_reset_action(unsigned int value); UX_STEP_NOCB(ux_menu_reset_1_step, nn, @@ -458,9 +477,13 @@ UX_STEP_CB(ux_menu_reset_3_step, pb, ui_menu_reset_action(ACCEPT), UX_FLOW(ux_flow_reset, &ux_menu_reset_1_step, &ux_menu_reset_2_step, &ux_menu_reset_3_step); -void ui_menu_reset_display(unsigned int value) { ux_flow_init(0, ux_flow_reset, 0); } +void ui_menu_reset_display(void) { + ux_flow_init(0, ux_flow_reset, 0); +} -void settings_reset(void) { ui_menu_reset_display(0); } +void settings_reset(void) { + ui_menu_reset_display(); +} void ui_menu_reset_action(unsigned int value) { if (value == ACCEPT) { @@ -487,7 +510,9 @@ const char* settings_submenu_getter(unsigned int idx) { return NULL; } -void settings_back(void) { ui_menu_main_display(0); } +void settings_back(void) { + ui_menu_main_display(0); +} void settings_submenu_selector(unsigned int idx) { switch (idx) { @@ -549,7 +574,9 @@ UX_FLOW(ux_flow_about, #endif &ux_menu_about_2_step); -void ui_menu_about_display(unsigned int value) { ux_flow_init(0, ux_flow_about, NULL); } +void ui_menu_about_display(void) { + ux_flow_init(0, ux_flow_about, NULL); +} #undef STR #undef XSTR @@ -583,7 +610,7 @@ UX_STEP_CB(ux_menu_pubaddr_2_step, pb, ui_menu_pubaddr_action(0), {&C_icon_back, 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) { +void ui_menu_pubaddr_action(unsigned int value __attribute__((unused))) { if (G_monero_vstate.disp_addr_mode) { monero_io_insert_u16(SW_OK); monero_io_do(IO_RETURN_AFTER_TX); @@ -595,29 +622,29 @@ void ui_menu_pubaddr_action(unsigned int value) { /** * */ -void 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_any_pubaddr_display(unsigned int value __attribute__((unused)), + unsigned char* pub_view, unsigned char* pub_spend, + unsigned char is_subbadress, unsigned char* paymanetID) { memset(G_monero_vstate.ux_address, 0, sizeof(G_monero_vstate.ux_address)); switch (G_monero_vstate.disp_addr_mode) { case 0: case DISP_MAIN: - os_memmove(ADDR_TYPE, "Main", 4); - os_memmove(ADDR_MAJOR, "Major: 0", 8); - os_memmove(ADDR_MINOR, "minor: 0", 8); + memcpy(ADDR_TYPE, "Main", 4); + memcpy(ADDR_MAJOR, "Major: 0", 8); + memcpy(ADDR_MINOR, "minor: 0", 8); break; case DISP_SUB: - os_memmove(ADDR_TYPE, "Sub", 3); + memcpy(ADDR_TYPE, "Sub", 3); snprintf(ADDR_MAJOR, 16, "Major: %d", G_monero_vstate.disp_addr_M); snprintf(ADDR_MINOR, 16, "minor: %d", G_monero_vstate.disp_addr_m); break; case DISP_INTEGRATED: - os_memmove(ADDR_TYPE, "Integrated", 10); - os_memmove(ADDR_IDSTR, "Payment ID", 10); - os_memmove(ADDR_ID, G_monero_vstate.payment_id, 16); + memcpy(ADDR_TYPE, "Integrated", 10); + memcpy(ADDR_IDSTR, "Payment ID", 10); + memcpy(ADDR_ID, G_monero_vstate.payment_id, 16); break; } @@ -651,14 +678,14 @@ UX_STEP_CB(ux_menu_main_2_step, pb, settings_submenu_selector), {&C_icon_coggle, "Settings"}); -UX_STEP_CB(ux_menu_main_3_step, pb, ui_menu_about_display(0), {&C_icon_certificate, "About"}); +UX_STEP_CB(ux_menu_main_3_step, pb, ui_menu_about_display(), {&C_icon_certificate, "About"}); UX_STEP_CB(ux_menu_main_4_step, pb, os_sched_exit(0), {&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_menu_main_4_step); -void ui_menu_main_display(unsigned int value) { +void ui_menu_main_display(unsigned int value __attribute__((unused))) { // reserve a display stack slot if none yet if (G_ux.stack_count == 0) { ux_stack_push(); @@ -667,7 +694,9 @@ void ui_menu_main_display(unsigned int value) { } /* --- INIT --- */ -void ui_init(void) { ui_menu_main_display(0); } +void ui_init(void) { + ui_menu_main_display(0); +} void io_seproxyhal_display(const bagl_element_t* element) { io_seproxyhal_display_default((bagl_element_t*)element); diff --git a/src/monero_ux_nanos.c b/src/monero_ux_nanos.c index d047d6b..4517c01 100644 --- a/src/monero_ux_nanos.c +++ b/src/monero_ux_nanos.c @@ -91,7 +91,7 @@ const ux_menu_entry_t ui_menu_words[] = { const bagl_element_t* ui_menu_words_preprocessor(const ux_menu_entry_t* entry, bagl_element_t* element) { - if ((entry->userid >= 0) && (entry->userid < 25)) { + if (entry->userid < 25) { if (element->component.userid == 0x21) { element->text = N_monero_pstate->words[entry->userid]; } @@ -104,16 +104,18 @@ const bagl_element_t* ui_menu_words_preprocessor(const ux_menu_entry_t* entry, return element; } -void ui_menu_words_display(unsigned int value) { +void ui_menu_words_display(unsigned int value __attribute__((unused))) { UX_MENU_DISPLAY(0, ui_menu_words, ui_menu_words_preprocessor); } -void ui_menu_words_clear(unsigned int value) { +void ui_menu_words_clear(unsigned int value __attribute__((unused))) { monero_clear_words(); ui_menu_main_display(0); } -void ui_menu_words_back(unsigned int value) { ui_menu_settings_display(1); } +void ui_menu_words_back(unsigned int value __attribute__((unused))) { + ui_menu_settings_display(1); +} /* -------------------------------- INFO UX --------------------------------- */ unsigned int ui_menu_info_button(unsigned int button_mask, unsigned int button_mask_counter); @@ -132,7 +134,8 @@ const bagl_element_t ui_menu_info[] = { G_monero_vstate.ux_info2}, }; -unsigned int ui_menu_info_button(unsigned int button_mask, unsigned int button_mask_counter) { +unsigned int ui_menu_info_button(unsigned int button_mask, + unsigned int button_mask_counter __attribute__((unused))) { switch (button_mask) { case BUTTON_EVT_RELEASED | BUTTON_RIGHT: case BUTTON_EVT_RELEASED | BUTTON_LEFT: @@ -149,13 +152,15 @@ unsigned int ui_menu_info_button(unsigned int button_mask, unsigned int button_m return 0; } -void ui_menu_info_display2(unsigned int value, char* line1, char* line2) { +void ui_menu_info_display2(unsigned int value __attribute__((unused)), char* line1, 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); UX_DISPLAY(ui_menu_info, NULL); } -void ui_menu_info_display(unsigned int value) { UX_DISPLAY(ui_menu_info, NULL); } +void ui_menu_info_display(unsigned int value __attribute__((unused))) { + UX_DISPLAY(ui_menu_info, NULL); +} /* -------------------------------- OPEN TX UX --------------------------------- */ @@ -180,13 +185,13 @@ const bagl_element_t ui_menu_opentx[] = { }; -unsigned int ui_menu_opentx_button(unsigned int button_mask, unsigned int button_mask_counter) { - unsigned int sw; +unsigned int ui_menu_opentx_button(unsigned int button_mask, + unsigned int button_mask_counter __attribute__((unused))) { + unsigned int sw = SW_OK; unsigned char x[32]; monero_io_discard(0); - os_memset(x, 0, 32); - sw = SW_OK; + memset(x, 0, 32); switch (button_mask) { case BUTTON_EVT_RELEASED | BUTTON_LEFT: // CANCEL @@ -221,7 +226,7 @@ void ui_menu_opentx_display(unsigned int value) { } } #else -void ui_menu_opentx_display(unsigned int value) { +void ui_menu_opentx_display(unsigned int value __attribute__((unused))) { uint32_t i; if (G_monero_vstate.tx_sig_mode == TRANSACTION_CREATE_REAL) { snprintf(G_monero_vstate.ux_info1, sizeof(G_monero_vstate.ux_info1), "Processing TX"); @@ -283,13 +288,13 @@ void ui_menu_amount_validation_action(unsigned int value) { ui_menu_info_display2(0, "Processing TX", "..."); } -void ui_menu_fee_validation_display(unsigned int value) { +void ui_menu_fee_validation_display(unsigned int value __attribute__((unused))) { UX_MENU_DISPLAY(0, ui_menu_fee_validation, ui_menu_amount_validation_preprocessor); } -void ui_menu_change_validation_display(unsigned int value) { +void ui_menu_change_validation_display(unsigned int value __attribute__((unused))) { UX_MENU_DISPLAY(0, ui_menu_change_validation, ui_menu_amount_validation_preprocessor); } -void ui_menu_timelock_validation_display(unsigned int value) { +void ui_menu_timelock_validation_display(unsigned int value __attribute__((unused))) { UX_MENU_DISPLAY(0, ui_menu_timelock_validation, ui_menu_amount_validation_preprocessor); } @@ -319,48 +324,48 @@ const bagl_element_t* ui_menu_validation_preprocessor(const ux_menu_entry_t* ent /* --- Destination --- */ if (entry == &ui_menu_validation[1]) { if (element->component.userid == 0x22) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 0, 11); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 0, 11); element->text = G_monero_vstate.ux_menu; } } if (entry == &ui_menu_validation[2]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 1, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 1, 11); } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 2, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 2, 11); } element->text = G_monero_vstate.ux_menu; } if (entry == &ui_menu_validation[3]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 3, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 3, 11); } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 4, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 4, 11); } element->text = G_monero_vstate.ux_menu; } if (entry == &ui_menu_validation[4]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 5, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 5, 11); } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 6, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 6, 11); } element->text = G_monero_vstate.ux_menu; } if (entry == &ui_menu_validation[5]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 7, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 7, 11); } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 8, 7); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 8, 7); } element->text = G_monero_vstate.ux_menu; } @@ -368,7 +373,7 @@ const bagl_element_t* ui_menu_validation_preprocessor(const ux_menu_entry_t* ent return element; } -void ui_menu_validation_display(unsigned int value) { +void ui_menu_validation_display(unsigned int value __attribute__((unused))) { UX_MENU_DISPLAY(0, ui_menu_validation, ui_menu_validation_preprocessor); } @@ -407,7 +412,7 @@ const bagl_element_t ui_export_viewkey[] = { G_monero_vstate.ux_menu}, }; -void ui_export_viewkey_display(unsigned int value) { +void ui_export_viewkey_display(unsigned int value __attribute__((unused))) { UX_DISPLAY(ui_export_viewkey, (void*)ui_export_viewkey_prepro); } @@ -424,12 +429,13 @@ unsigned int ui_export_viewkey_prepro(const bagl_element_t* element) { return 1; } -unsigned int ui_export_viewkey_button(unsigned int button_mask, unsigned int button_mask_counter) { +unsigned int ui_export_viewkey_button(unsigned int button_mask, + unsigned int button_mask_counter __attribute__((unused))) { unsigned int sw; unsigned char x[32]; monero_io_discard(0); - os_memset(x, 0, 32); + memset(x, 0, 32); sw = SW_OK; switch (button_mask) { @@ -472,7 +478,7 @@ const ux_menu_entry_t ui_menu_account[] = { const bagl_element_t* ui_menu_account_preprocessor(const ux_menu_entry_t* entry, bagl_element_t* element) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); for (unsigned int i = 2; i < 12; i++) { if ((entry == &ui_menu_account[i]) && (element->component.userid == 0x20) && (N_monero_pstate->account_id == (i - 2))) { @@ -509,23 +515,23 @@ const ux_menu_entry_t ui_menu_network[] = { const bagl_element_t* ui_menu_network_preprocessor(const ux_menu_entry_t* entry, bagl_element_t* element) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if ((entry == &ui_menu_network[2]) && (element->component.userid == 0x20) && (N_monero_pstate->network_id == TESTNET)) { - os_memmove(G_monero_vstate.ux_menu, "Test Network ", 14); + memcpy(G_monero_vstate.ux_menu, "Test Network ", 14); G_monero_vstate.ux_menu[13] = '+'; element->text = G_monero_vstate.ux_menu; } if ((entry == &ui_menu_network[3]) && (element->component.userid == 0x20) && (N_monero_pstate->network_id == STAGENET)) { - os_memmove(G_monero_vstate.ux_menu, "Stage Network ", 14); + memcpy(G_monero_vstate.ux_menu, "Stage Network ", 14); G_monero_vstate.ux_menu[13] = '+'; element->text = G_monero_vstate.ux_menu; } #ifndef MONERO_ALPHA if ((entry == &ui_menu_network[4]) && (element->component.userid == 0x20) && (N_monero_pstate->network_id == MAINNET)) { - os_memmove(G_monero_vstate.ux_menu, "Main Network ", 14); + memcpy(G_monero_vstate.ux_menu, "Main Network ", 14); G_monero_vstate.ux_menu[13] = '+'; element->text = G_monero_vstate.ux_menu; } @@ -551,7 +557,7 @@ const ux_menu_entry_t ui_menu_reset[] = { {NULL, ui_menu_reset_action, 0, NULL, "Yes", NULL, 0, 0}, UX_MENU_END}; -void ui_menu_reset_action(unsigned int value) { +void ui_menu_reset_action(unsigned int value __attribute__((unused))) { unsigned char magic[4]; magic[0] = 0; magic[1] = 0; @@ -613,30 +619,30 @@ const bagl_element_t* ui_menu_pubaddr_preprocessor(const ux_menu_entry_t* entry, bagl_element_t* element) { /* --- address --- */ if (entry == &ui_menu_pubaddr[0]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { switch (G_monero_vstate.disp_addr_mode) { case 0: case DISP_MAIN: - os_memmove(G_monero_vstate.ux_menu, "Main", 4); + memcpy(G_monero_vstate.ux_menu, "Main", 4); break; case DISP_SUB: - os_memmove(G_monero_vstate.ux_menu, "Sub", 3); + memcpy(G_monero_vstate.ux_menu, "Sub", 3); break; case DISP_INTEGRATED: - os_memmove(G_monero_vstate.ux_menu, "Integrated", 10); + memcpy(G_monero_vstate.ux_menu, "Integrated", 10); break; } element->text = G_monero_vstate.ux_menu; } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, "Address", 7); + memcpy(G_monero_vstate.ux_menu, "Address", 7); element->text = G_monero_vstate.ux_menu; } } if (entry == &ui_menu_pubaddr[1]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { switch (G_monero_vstate.disp_addr_mode) { case 0: @@ -646,7 +652,7 @@ const bagl_element_t* ui_menu_pubaddr_preprocessor(const ux_menu_entry_t* entry, G_monero_vstate.disp_addr_M); break; case DISP_INTEGRATED: - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.payment_id, 8); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.payment_id, 8); break; } element->text = G_monero_vstate.ux_menu; @@ -660,7 +666,7 @@ const bagl_element_t* ui_menu_pubaddr_preprocessor(const ux_menu_entry_t* entry, G_monero_vstate.disp_addr_m); break; case DISP_INTEGRATED: - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.payment_id + 8, 8); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.payment_id + 8, 8); break; } element->text = G_monero_vstate.ux_menu; @@ -669,58 +675,58 @@ const bagl_element_t* ui_menu_pubaddr_preprocessor(const ux_menu_entry_t* entry, } if (entry == &ui_menu_pubaddr[2]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 0, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 0, 11); } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 1, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 1, 11); } element->text = G_monero_vstate.ux_menu; } if (entry == &ui_menu_pubaddr[3]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 2, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 2, 11); } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 3, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 3, 11); } element->text = G_monero_vstate.ux_menu; } if (entry == &ui_menu_pubaddr[4]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 4, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 4, 11); } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 5, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 5, 11); } element->text = G_monero_vstate.ux_menu; } if (entry == &ui_menu_pubaddr[5]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 6, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 6, 11); } if (element->component.userid == 0x22) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 7, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 7, 11); } element->text = G_monero_vstate.ux_menu; } if (entry == &ui_menu_pubaddr[6]) { - os_memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); + memset(G_monero_vstate.ux_menu, 0, sizeof(G_monero_vstate.ux_menu)); if (element->component.userid == 0x21) { if (G_monero_vstate.disp_addr_mode == DISP_INTEGRATED) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 8, 11); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 8, 11); } else { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 8, 7); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 8, 7); } } if (element->component.userid == 0x22) { if (G_monero_vstate.disp_addr_mode == DISP_INTEGRATED) { - os_memmove(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 9, 7); + memcpy(G_monero_vstate.ux_menu, G_monero_vstate.ux_address + 11 * 9, 7); } } element->text = G_monero_vstate.ux_menu; @@ -729,7 +735,7 @@ const bagl_element_t* ui_menu_pubaddr_preprocessor(const ux_menu_entry_t* entry, return element; } -void ui_menu_pubaddr_action(unsigned int value) { +void ui_menu_pubaddr_action(unsigned int value __attribute__((unused))) { if (G_monero_vstate.disp_addr_mode) { monero_io_insert_u16(SW_OK); monero_io_do(IO_RETURN_AFTER_TX); @@ -767,7 +773,9 @@ const ux_menu_entry_t ui_menu_main[] = { {NULL, (void*)os_sched_exit, 0, &C_icon_dashboard, "Quit app", NULL, 50, 29}, UX_MENU_END}; -void ui_menu_main_display(unsigned int value) { UX_MENU_DISPLAY(value, ui_menu_main, NULL); } +void ui_menu_main_display(unsigned int value) { + UX_MENU_DISPLAY(value, ui_menu_main, NULL); +} void ui_init(void) { ui_menu_main_display(0);