From 5de67d7ef664fe6ac0ae6879d878ebb89ab07883 Mon Sep 17 00:00:00 2001 From: BTChip github Date: Mon, 12 Mar 2018 11:04:02 +0100 Subject: [PATCH] Compatibility with Nano S SDK 1.4 --- src_genericwallet/main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src_genericwallet/main.c b/src_genericwallet/main.c index ccc5695..0d11101 100644 --- a/src_genericwallet/main.c +++ b/src_genericwallet/main.c @@ -1876,10 +1876,21 @@ unsigned int io_seproxyhal_touch_tx_ok(const bagl_element_t *e) { tmpCtx.transactionContext.pathLength, privateKeyData, NULL); cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey); os_memset(privateKeyData, 0, sizeof(privateKeyData)); +#if CX_APILEVEL >= 8 + unsigned int info = 0; + signatureLength = + cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256, + tmpCtx.transactionContext.hash, + sizeof(tmpCtx.transactionContext.hash), signature, &info); + if (info & CX_ECCINFO_PARITY_ODD) { + signature[0] |= 0x01; + } +#else signatureLength = cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256, tmpCtx.transactionContext.hash, sizeof(tmpCtx.transactionContext.hash), signature); +#endif os_memset(&privateKey, 0, sizeof(privateKey)); // Parity is present in the sequence tag in the legacy API if (tmpContent.txContent.vLength == 0) { @@ -1952,10 +1963,22 @@ unsigned int io_seproxyhal_touch_signMessage_ok(const bagl_element_t *e) { tmpCtx.messageSigningContext.pathLength, privateKeyData, NULL); cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey); os_memset(privateKeyData, 0, sizeof(privateKeyData)); + +#if CX_APILEVEL >= 8 + unsigned int info = 0; + signatureLength = cx_ecdsa_sign( + &privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256, + tmpCtx.messageSigningContext.hash, + sizeof(tmpCtx.messageSigningContext.hash), signature, &info); + if (info & CX_ECCINFO_PARITY_ODD) { + signature[0] |= 0x01; + } +#else signatureLength = cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256, tmpCtx.messageSigningContext.hash, sizeof(tmpCtx.messageSigningContext.hash), signature); +#endif os_memset(&privateKey, 0, sizeof(privateKey)); G_io_apdu_buffer[0] = 27 + (signature[0] & 0x01); rLength = signature[3];