Skip to content

Commit

Permalink
Merge pull request #142 from Zondax/dev
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
ftheirs authored Dec 12, 2023
2 parents f9814c2 + aab8f5c commit 9ba16aa
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 23 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/guidelines_enforcer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ jobs:
guidelines_enforcer:
name: Call Ledger guidelines_enforcer
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_guidelines_enforcer.yml@v1
with:
relative_app_directory: app
run_for_devices: '["nanos", "nanosp", "nanox"]'
1 change: 0 additions & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ endif

APP_LOAD_PARAMS = --curve secp256k1 $(COMMON_LOAD_PARAMS) --path $(APPPATH)

NANOS_STACK_SIZE := 1932
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices

$(info TARGET_NAME = [$(TARGET_NAME)])
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=0
# This is the minor version of this release
APPVERSION_N=23
# This is the patch version of this release
APPVERSION_P=9
APPVERSION_P=10
2 changes: 1 addition & 1 deletion app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ handleGetAddrEth(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx)
if (with_code != P2_CHAINCODE && with_code != P2_NO_CHAINCODE)
THROW(APDU_CODE_INVALIDP1P2);

chain_code = with_code;
fil_chain_code = with_code;

zxerr_t zxerr = app_fill_eth_address();
if (zxerr != zxerr_ok) {
Expand Down
1 change: 1 addition & 0 deletions app/src/common/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "coin.h"
#include "zxerror.h"
#include <stdbool.h>

// transaction initializer for the buffer and transaction type.
void tx_context_fil();
Expand Down
24 changes: 12 additions & 12 deletions app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ static zxerr_t crypto_extractPublicKey(uint8_t *pubKey, uint16_t pubKeyLen, uint
privateKeyData,
chainCode,
NULL,
0))
0));

CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey))
CATCH_CXERROR(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1, NULL, 0, &cx_publicKey))
CATCH_CXERROR(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1, &cx_publicKey, &cx_privateKey, 1))
CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey));
CATCH_CXERROR(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1, NULL, 0, &cx_publicKey));
CATCH_CXERROR(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1, &cx_publicKey, &cx_privateKey, 1));
memcpy(pubKey, cx_publicKey.W, SECP256K1_PK_LEN);
error = zxerr_ok;

Expand All @@ -69,7 +69,7 @@ __Z_INLINE zxerr_t keccak_hash(const unsigned char *in, unsigned int inLen,
// return actual size using value from signatureLength
cx_sha3_t keccak;
if (cx_keccak_init_no_throw(&keccak, outLen * 8) != CX_OK) return zxerr_unknown;
cx_hash_no_throw((cx_hash_t *)&keccak, CX_LAST, in, inLen, out, outLen);
CHECK_CX_OK(cx_hash_no_throw((cx_hash_t *)&keccak, CX_LAST, in, inLen, out, outLen));

return zxerr_ok;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ zxerr_t blake_hash(const uint8_t *in, uint16_t inLen, uint8_t *out, uint16_t out
}
cx_blake2b_t ctx;
if (cx_blake2b_init_no_throw(&ctx, outLen * 8) != CX_OK) return zxerr_unknown;
cx_hash_no_throw(&ctx.header, CX_LAST, in, inLen, out, outLen);
CHECK_CX_OK(cx_hash_no_throw(&ctx.header, CX_LAST, in, inLen, out, outLen));

return zxerr_ok;
}
Expand All @@ -131,8 +131,8 @@ zxerr_t blake_hash_cid(const unsigned char *in, unsigned int inLen,

cx_blake2b_t ctx;
if (cx_blake2b_init_no_throw(&ctx, outLen * 8) != CX_OK) return zxerr_unknown;
cx_hash_no_throw(&ctx.header, 0, prefix, sizeof(prefix), NULL, 0);
cx_hash_no_throw(&ctx.header, CX_LAST, in, inLen, out, outLen);
CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, prefix, sizeof(prefix), NULL, 0));
CHECK_CX_OK(cx_hash_no_throw(&ctx.header, CX_LAST, in, inLen, out, outLen));

return zxerr_ok;
}
Expand Down Expand Up @@ -170,16 +170,16 @@ zxerr_t _sign(uint8_t *output, uint16_t outputLen, const uint8_t *message, uint1
privateKeyData,
NULL,
NULL,
0))
0));

CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey))
CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey));
CATCH_CXERROR(cx_ecdsa_sign_no_throw(&cx_privateKey,
CX_RND_RFC6979 | CX_LAST,
CX_SHA256,
message,
messageLen,
signature->der_signature,
&signatureLength, &tmpInfo))
&signatureLength, &tmpInfo));

const err_convert_e err_c = convertDERtoRSV(signature->der_signature, tmpInfo, signature->r, signature->s, &signature->v);
if (err_c == no_error) {
Expand Down Expand Up @@ -316,7 +316,7 @@ zxerr_t crypto_fillEthAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *ad
MEMZERO(buffer, buffer_len);
answer_eth_t *const answer = (answer_eth_t *) buffer;

CHECK_ZXERR(crypto_extractPublicKey(&answer->publicKey[1], sizeof_field(answer_eth_t, publicKey) - 1, &chain_code))
CHECK_ZXERR(crypto_extractPublicKey(&answer->publicKey[1], sizeof_field(answer_eth_t, publicKey) - 1, &fil_chain_code))

answer->publicKey[0] = SECP256K1_PK_LEN;

Expand Down
2 changes: 1 addition & 1 deletion app/src/crypto_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

uint32_t hdPath[MAX_BIP32_PATH];
uint32_t hdPath_len;
uint8_t chain_code;
uint8_t fil_chain_code;

bool isTestnet() {
return hdPath[0] == HDPATH_0_TESTNET &&
Expand Down
2 changes: 1 addition & 1 deletion app/src/crypto_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {

extern uint32_t hdPath[MAX_BIP32_PATH];
extern uint32_t hdPath_len;
extern uint8_t chain_code;
extern uint8_t fil_chain_code;

#define ADDRESS_PROTOCOL_LEN 1

Expand Down
6 changes: 4 additions & 2 deletions app/src/crypto_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
// Implementation from methods that are needed for cpp_test
#if !defined(LEDGER_SPECIFIC)

#include <hexutils.h>
#include "zxerror.h"
#include "coin.h"
#include "crypto_helper.h"

// Implementation from methods that are needed for cpp_test
#if !defined (TARGET_NANOS) && !defined(TARGET_NANOS2) && !defined(TARGET_NANOX) && !defined(TARGET_STAX)
#include "blake2.h"
#include "zxmacros.h"

char *crypto_testPubKey;

Expand Down
7 changes: 7 additions & 0 deletions ledger_app.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[app]
build_directory = "./app/"
sdk = "C"
devices = ["nanos", "nanox", "nanos+"]

[tests]
unit_directory = "./tests/"
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9ba16aa

Please sign in to comment.