fix deserialize

This commit is contained in:
Lukas Bielesch
2026-02-11 10:48:52 +01:00
parent f207b548d4
commit f9a8781adc
5 changed files with 25 additions and 36 deletions

View File

@@ -3,3 +3,4 @@
#include "elligator2.h"
#include "hmac.h"
#include "sha2.h"
#include "bip32.h"

View File

@@ -71,8 +71,8 @@ def main():
print(f"Serialized ({len(request_data)} bytes): {request_data.hex()}")
# Load the app and get its hash
# app_path = Path(__file__).parent.parent / "target" / "debug" / "ethereum_rust"
app_path = Path(__file__).parent.parent / "target" / "release" / "ethereum_rust"
app_path = Path(__file__).parent.parent / "target" / "debug" / "ethereum_rust"
# app_path = Path(__file__).parent.parent / "target" / "release" / "ethereum_rust"
#app_path = Path(__file__).parent.parent / "target" / "thumbv7em-none-eabihf" / "debug" / "ethereum_rust.min"
# app_path = Path(__file__).parent.parent / "target" / "thumbv7em-none-eabihf" / "release" / "ethereum_rust.min"
print(f"\nLoading app from: {app_path}")

View File

@@ -212,12 +212,14 @@ pub fn system_exit_fatal(message: &str, file: &str, line: i32) -> ! {
core::intrinsics::abort();
}
unsafe extern "C" {
pub fn hdnode_deserialize_public(
str_: *const core::ffi::c_char,
version: u32,
curve: *const core::ffi::c_char,
node: *mut HDNode,
fingerprint: *mut u32,
) -> core::ffi::c_int;
pub fn hdnode_deserialize_public(
str_: *const core::ffi::c_char,
version: u32,
curve: *const core::ffi::c_char,
node: *mut HDNode,
fingerprint: *mut u32,
) -> core::ffi::c_int {
unsafe {
(get_crypto_or_die().hdnode_deserialize_public)(str_, version, curve, node, fingerprint)
}
}

View File

@@ -121,24 +121,12 @@ pub struct trezor_api_v1_t {
/// Trezor crypto v1 function pointers
#[repr(C)]
pub struct trezor_crypto_v1_t {
pub hdnode_from_xpub: unsafe extern "C" fn(
depth: u32,
child_num: u32,
chain_code: *const u8,
public_key: *const u8,
curve: *const core::ffi::c_char,
out: *mut HDNode,
) -> core::ffi::c_int,
pub hdnode_sign: unsafe extern "C" fn(
pub hdnode_deserialize_public: unsafe extern "C" fn(
str_: *const cty::c_char,
version: u32,
curve: *const cty::c_char,
node: *mut HDNode,
msg: *const u8,
msg_len: u32,
hasher_sign: HasherType,
sig: *mut u8,
pby: *mut u8,
is_canonical: ::core::option::Option<
unsafe extern "C" fn(by: u8, sig: *mut u8) -> core::ffi::c_int,
>,
fingerprint: *mut u32,
) -> core::ffi::c_int,
}

View File

@@ -103,15 +103,13 @@ pub fn hdnode_deserialize_public(serialized: &str, version: u32) -> Result<(HDNo
curve: &curve_info,
};
let mut fingerprint: u32 = 0;
let result = unsafe {
low_level_api::hdnode_deserialize_public(
serialized.as_ptr() as *const core::ffi::c_char,
version,
b"secp256k1\0".as_ptr() as *const core::ffi::c_char,
&mut node,
&mut fingerprint,
)
};
let result = low_level_api::hdnode_deserialize_public(
serialized.as_ptr() as *const core::ffi::c_char,
version,
b"secp256k1\0".as_ptr() as *const core::ffi::c_char,
&mut node,
&mut fingerprint,
);
if result == 0 {
Ok((node, fingerprint))
} else {