Skip to content

Commit

Permalink
fix: change all deprecated functions calls with recommanded functions
Browse files Browse the repository at this point in the history
  • Loading branch information
keiff3r committed Mar 15, 2024
1 parent 2c3e39a commit c6e7b83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void handleGetWalletId(volatile unsigned int *tx) {
CX_THROW(os_derive_bip32_no_throw(CX_CURVE_256K1, U_os_perso_seed_cookie, 2, t, NULL));
// priv key => pubkey
CX_THROW(cx_ecdsa_init_private_key(CX_CURVE_256K1, t, 32, &priv));
cx_ecfp_generate_pair(CX_CURVE_256K1, &pub, &priv, 1);
CX_THROW(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1, &pub, &priv, 1));
// pubkey -> sha512
cx_hash_sha512(pub.W, sizeof(pub.W), t, sizeof(t));
// ! cookie !
Expand Down Expand Up @@ -210,9 +210,9 @@ void handleGetPublicKey(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t da
privateKeyData,
(tmpCtx.publicKeyContext.getChaincode ? tmpCtx.publicKeyContext.chainCode : NULL)));

cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
CX_THROW(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &privateKey));
io_seproxyhal_io_heartbeat();
cx_ecfp_generate_pair(CX_CURVE_256K1, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1);
CX_THROW(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1));
explicit_bzero(&privateKey, sizeof(privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData));
io_seproxyhal_io_heartbeat();
Expand Down Expand Up @@ -278,8 +278,8 @@ void handleProvideErc20TokenInformation(uint8_t p1, uint8_t p2, uint8_t *workBuf
// Skip chainId
offset += 4;
dataLength -= 4;
cx_ecfp_init_public_key(CX_CURVE_256K1, TOKEN_SIGNATURE_PUBLIC_KEY, sizeof(TOKEN_SIGNATURE_PUBLIC_KEY), &tokenKey);
if (!cx_ecdsa_verify(&tokenKey, CX_LAST, CX_SHA256, hash, 32, workBuffer + offset, dataLength)) {
CX_THROW(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1, TOKEN_SIGNATURE_PUBLIC_KEY, sizeof(TOKEN_SIGNATURE_PUBLIC_KEY), &tokenKey));
if (!cx_ecdsa_verify_no_throw(&tokenKey, hash, 32, workBuffer + offset, dataLength)) {
PRINTF("Invalid token signature\n");
THROW(0x6A80);
}
Expand Down
16 changes: 9 additions & 7 deletions src/ui_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ unsigned int io_seproxyhal_touch_tx_ok(void) {
CX_THROW(os_derive_bip32_no_throw(CX_CURVE_256K1, tmpCtx.transactionContext.derivationPath.path,
tmpCtx.transactionContext.derivationPath.len,
privateKeyData, NULL));
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32,
&privateKey);
CX_THROW(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32,
&privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData));
unsigned int info = 0;
size_t sig_len = sizeof(signature);
io_seproxyhal_io_heartbeat();
cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256,
CX_THROW(cx_ecdsa_sign_no_throw(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256,
tmpCtx.transactionContext.hash,
sizeof(tmpCtx.transactionContext.hash), signature, sizeof(signature), &info);
sizeof(tmpCtx.transactionContext.hash), signature, &sig_len, &info));
explicit_bzero(&privateKey, sizeof(privateKey));
// Parity is present in the sequence tag in the legacy API
if (tmpContent.txContent.vLength == 0) {
Expand Down Expand Up @@ -158,13 +159,14 @@ unsigned int io_seproxyhal_touch_signMessage_ok(void) {
tmpCtx.messageSigningContext.derivationPath.len, privateKeyData, NULL));

io_seproxyhal_io_heartbeat();
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
CX_THROW(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData));
unsigned int info = 0;
size_t sig_len = sizeof(signature);
io_seproxyhal_io_heartbeat();
cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256,
CX_THROW(cx_ecdsa_sign_no_throw(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256,
tmpCtx.messageSigningContext.hash,
sizeof(tmpCtx.messageSigningContext.hash), signature, sizeof(signature), &info);
sizeof(tmpCtx.messageSigningContext.hash), signature, &sig_len, &info));
explicit_bzero(&privateKey, sizeof(privateKey));
G_io_apdu_buffer[0] = 27;
if (info & CX_ECCINFO_PARITY_ODD) {
Expand Down

0 comments on commit c6e7b83

Please sign in to comment.