wire: reduce stack usage sending replies
What changed, and why it matters
This commit changes how message context is passed between functions in the Blockstream Jade hardware wallet firmware. Instead of copying the entire message context structure on the stack, functions now receive a pointer to it. The stated goal is to reduce stack memory usage. There is no direct evidence in the commit that this fixes an exploitable vulnerability, but reducing stack pressure can help prevent stack overflow crashes or corruption in a security-critical embedded device.
Treat as a routine hardening/refactoring commit. Review the preceding commit to understand what increased stack usage and verify combined stack usage remains within safe margins. No urgent security action is indicated by this commit alone.
Security signals we found
Stack usage reduction in embedded firmware
Pointer passing instead of structure copying
No direct vulnerability described in commit message
No CVE, advisory, or security disclosure referenced
Defensive assertions added for null pointer
Evidence from the diff
The patch converts function signatures from passing cbor_msg_t by value to passing const cbor_msg_t* const ctx pointers. This affects reply and rejection helpers across many process files and in main/wire.c. The change avoids copying the cbor_msg_t structure onto the stack for each reply call, which the commit message says offsets increased stack usage from the prior commit. Assertions are added to validate the pointer is non-null. No buffer sizes, parsing logic, or cryptographic operations are changed.
Changed components
main/process.cmain/process.hmain/wire.cmain/process/dashboard.cmain/process/debug_scan_qr.cmain/process/get_bip85_entropy.cmain/process/get_bip85_pubkey.cmain/process/get_blinding_factor.cmain/process/get_blinding_key.cmain/process/get_commitments.cmain/process/get_identity_pubkey.cmain/process/get_identity_shared_key.cmain/process/get_master_blinding_key.cmain/process/get_otp_code.cmain/process/get_receive_address.cmain/process/get_registered_descriptor.cmain/process/get_registered_descriptors.cmain/process/get_registered_multisig.cmain/process/get_registered_multisigs.cmain/process/get_shared_nonce.cmain/process/get_xpubs.cmain/process/ota_util.cmain/process/pinclient.cmain/process/sign_attestation.cmain/process/sign_bip85_digest.cmain/process/sign_identity.cmain/process/sign_message.cmain/process/sign_psbt.cmain/process/sign_tx.cInspect captured patch +65 / −64
diff --git a/main/process.c b/main/process.c
index 1e87d27..e4aae1c 100644
--- a/main/process.c
+++ b/main/process.c
@@ -531,32 +531,31 @@ void cbor_result_uint64_cb(const void* ctx, CborEncoder* container)
}
void jade_process_reply_to_message_result(
- const cbor_msg_t ctx, uint8_t* output, size_t output_size, const void* cbctx, cbor_encoder_fn_t cb)
+ const cbor_msg_t* const ctx, uint8_t* output, size_t output_size, const void* cbctx, cbor_encoder_fn_t cb)
{
- JADE_ASSERT(cb);
- JADE_ASSERT(output);
- JADE_ASSERT(output_size);
+ JADE_ASSERT(ctx && cb);
+ JADE_ASSERT(output && output_size);
char id[MAXLEN_ID + 1];
size_t written = 0;
- rpc_get_id(&ctx.value, id, sizeof(id), &written);
+ rpc_get_id(&ctx->value, id, sizeof(id), &written);
JADE_ASSERT(written != 0);
- jade_process_reply_to_message_result_with_id(id, output, output_size, ctx.source, cbctx, cb);
+ jade_process_reply_to_message_result_with_id(id, output, output_size, ctx->source, cbctx, cb);
}
void jade_process_reply_to_message_ok(jade_process_t* process)
{
uint8_t buf[64];
const bool ok = true;
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), &ok, cbor_result_boolean_cb);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), &ok, cbor_result_boolean_cb);
}
void jade_process_reply_to_message_fail(jade_process_t* process)
{
uint8_t buf[64];
const bool ok = false;
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), &ok, cbor_result_boolean_cb);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), &ok, cbor_result_boolean_cb);
}
void jade_process_reject_message_with_id(const char* id, int code, const char* message, const uint8_t* data,
@@ -579,29 +578,30 @@ void jade_process_reject_message_with_id(const char* id, int code, const char* m
}
}
-void jade_process_reject_message_ex(const cbor_msg_t ctx, int code, const char* message, const uint8_t* data,
+void jade_process_reject_message_ex(const cbor_msg_t* const ctx, int code, const char* message, const uint8_t* data,
const size_t datalen, uint8_t* buffer, const size_t buffer_len)
{
char id[MAXLEN_ID + 1];
size_t written = 0;
- rpc_get_id(&ctx.value, id, sizeof(id), &written);
+ rpc_get_id(&ctx->value, id, sizeof(id), &written);
jade_process_reject_message_with_id(
- written > 0 ? id : "00", code, message, data, datalen, buffer, buffer_len, ctx.source);
+ written > 0 ? id : "00", code, message, data, datalen, buffer, buffer_len, ctx->source);
}
void jade_process_reject_message(jade_process_t* process, int code, const char* message)
{
if (HAS_CURRENT_MESSAGE(process)) {
uint8_t buf[JADE_MSG_REPLY_LEN];
- jade_process_reject_message_ex(process->ctx, code, message, NULL, 0, buf, sizeof(buf));
+ jade_process_reject_message_ex(&process->ctx, code, message, NULL, 0, buf, sizeof(buf));
} else {
JADE_LOGW("Ignoring attempt to reject 'no-message'");
}
}
-void jade_process_reply_to_message_bytes(const cbor_msg_t ctx, const uint8_t* data, const size_t datalen)
+void jade_process_reply_to_message_bytes(const cbor_msg_t* const ctx, const uint8_t* data, const size_t datalen)
{
// Avoid allocating for small replies
+ JADE_ASSERT(ctx);
uint8_t buf[JADE_MSG_REPLY_LEN];
uint8_t* buffer = buf;
size_t buflen = sizeof(buf);
@@ -622,14 +622,14 @@ void jade_process_reply_to_message_bytes(const cbor_msg_t ctx, const uint8_t* da
JADE_ASSERT(cberr == CborNoError);
const char* id = NULL;
size_t written = 0;
- rpc_get_id_ptr(&ctx.value, &id, &written);
+ rpc_get_id_ptr(&ctx->value, &id, &written);
JADE_ASSERT(written != 0);
rpc_init_cbor(&root_map_encoder, id, written);
cberr = cbor_encode_byte_string(&root_map_encoder, data, datalen);
JADE_ASSERT(cberr == CborNoError);
cberr = cbor_encoder_close_container(&root_encoder, &root_map_encoder);
JADE_ASSERT(cberr == CborNoError);
- jade_process_push_out_message(buffer, cbor_encoder_get_buffer_size(&root_encoder, buffer), ctx.source);
+ jade_process_push_out_message(buffer, cbor_encoder_get_buffer_size(&root_encoder, buffer), ctx->source);
if (buffer != buf) {
// Allocated buffer
@@ -637,9 +637,10 @@ void jade_process_reply_to_message_bytes(const cbor_msg_t ctx, const uint8_t* da
}
}
-void jade_process_reply_to_message_bytes_sequence(const cbor_msg_t ctx, const size_t seqnum, const size_t seqlen,
+void jade_process_reply_to_message_bytes_sequence(const cbor_msg_t* const ctx, const size_t seqnum, const size_t seqlen,
const uint8_t* data, const size_t datalen, uint8_t* buffer, const size_t buflen)
{
+ JADE_ASSERT(ctx);
CborEncoder root_encoder;
cbor_encoder_init(&root_encoder, buffer, buflen, 0);
@@ -651,13 +652,13 @@ void jade_process_reply_to_message_bytes_sequence(const cbor_msg_t ctx, const si
JADE_ASSERT(cberr == CborNoError);
const char* id = NULL;
size_t written = 0;
- rpc_get_id_ptr(&ctx.value, &id, &written);
+ rpc_get_id_ptr(&ctx->value, &id, &written);
JADE_ASSERT(written != 0);
rpc_init_cbor_with_sequence(&root_map_encoder, id, written, seqnum, seqlen);
cberr = cbor_encode_byte_string(&root_map_encoder, data, datalen);
JADE_ASSERT(cberr == CborNoError);
cberr = cbor_encoder_close_container(&root_encoder, &root_map_encoder);
JADE_ASSERT(cberr == CborNoError);
- jade_process_push_out_message(buffer, cbor_encoder_get_buffer_size(&root_encoder, buffer), ctx.source);
+ jade_process_push_out_message(buffer, cbor_encoder_get_buffer_size(&root_encoder, buffer), ctx->source);
}
#endif // AMALGAMATED_BUILD
diff --git a/main/process.h b/main/process.h
index 922849c..5aa1bca 100644
--- a/main/process.h
+++ b/main/process.h
@@ -90,15 +90,15 @@ void jade_process_push_out_message(const uint8_t* data, size_t length, jade_msg_
void jade_process_reply_to_message_result_with_id(const char* id, uint8_t* output, size_t output_size,
jade_msg_source_t source, const void* cbctx, cbor_encoder_fn_t cb);
void jade_process_reply_to_message_result(
- cbor_msg_t ctx, uint8_t* output, size_t output_size, const void* cbctx, cbor_encoder_fn_t cb);
+ const cbor_msg_t* const ctx, uint8_t* output, size_t output_size, const void* cbctx, cbor_encoder_fn_t cb);
void jade_process_reply_to_message_ok(jade_process_t* process);
void jade_process_reply_to_message_fail(jade_process_t* process);
void jade_process_reply_to_message_ex(jade_msg_source_t source, const uint8_t* reply_payload, size_t payload_len);
void jade_process_reject_message(jade_process_t* process, int code, const char* message);
void jade_process_reject_message_with_id(const char* id, int code, const char* message, const uint8_t* data,
size_t datalen, uint8_t* buffer, size_t buffer_len, jade_msg_source_t source);
-void jade_process_reject_message_ex(cbor_msg_t ctx, int code, const char* message, const uint8_t* data, size_t datalen,
- uint8_t* buffer, size_t buffer_len);
+void jade_process_reject_message_ex(const cbor_msg_t* const ctx, int code, const char* message, const uint8_t* data,
+ size_t datalen, uint8_t* buffer, size_t buffer_len);
// Get in/out messages from the queues/ring-buffers
void jade_process_get_in_message(void* ctx, inbound_message_reader_fn_t reader, bool blocking);
@@ -110,8 +110,8 @@ void cbor_result_string_cb(const void* ctx, CborEncoder* container);
void cbor_result_boolean_cb(const void* ctx, CborEncoder* container);
void cbor_result_uint64_cb(const void* ctx, CborEncoder* container);
-void jade_process_reply_to_message_bytes(cbor_msg_t ctx, const uint8_t* data, size_t datalen);
-void jade_process_reply_to_message_bytes_sequence(cbor_msg_t ctx, const size_t seqnum, const size_t seqlen,
+void jade_process_reply_to_message_bytes(const cbor_msg_t* const ctx, const uint8_t* data, size_t datalen);
+void jade_process_reply_to_message_bytes_sequence(const cbor_msg_t* const ctx, const size_t seqnum, const size_t seqlen,
const uint8_t* data, const size_t datalen, uint8_t* buffer, const size_t buflen);
#endif /* PROCESS_H_ */
diff --git a/main/process/dashboard.c b/main/process/dashboard.c
index f68964a..caf55f0 100644
--- a/main/process/dashboard.c
+++ b/main/process/dashboard.c
@@ -256,7 +256,7 @@ static void process_get_version_info_request(jade_process_t* process)
uint8_t buf[1024];
jade_process_reply_to_message_result(
- process->ctx, buf, sizeof(buf), &process->ctx.source, build_version_info_reply);
+ &process->ctx, buf, sizeof(buf), &process->ctx.source, build_version_info_reply);
}
// If the user has successfully authenticated over a given connection interface,
@@ -523,7 +523,7 @@ static void dispatch_message(jade_process_t* process)
uint8_t buf[64];
jade_process_reply_to_message_result(
- process->ctx, buf, sizeof(buf), &elapsed_time_ms, cbor_result_uint64_cb);
+ &process->ctx, buf, sizeof(buf), &elapsed_time_ms, cbor_result_uint64_cb);
} else {
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "ERROR");
}
diff --git a/main/process/debug_scan_qr.c b/main/process/debug_scan_qr.c
index ad2187b..83c7d72 100644
--- a/main/process/debug_scan_qr.c
+++ b/main/process/debug_scan_qr.c
@@ -94,7 +94,7 @@ static bool return_image_data(const size_t width, const size_t height, const uin
}
// All good, reply with the compressed image data
- jade_process_reply_to_message_bytes(info->process->ctx, compressed, compressed_len);
+ jade_process_reply_to_message_bytes(&info->process->ctx, compressed, compressed_len);
// Free the input message (to signal that we have been called and sent the reply)
jade_process_free_current_message(info->process);
@@ -177,7 +177,7 @@ void debug_scan_qr_process(void* process_ptr)
}
// Reply with the decoded data (empty if failed)
- jade_process_reply_to_message_bytes(process->ctx, qr_data.data, qr_data.len);
+ jade_process_reply_to_message_bytes(&process->ctx, qr_data.data, qr_data.len);
JADE_LOGI("Success");
cleanup:
diff --git a/main/process/get_bip85_entropy.c b/main/process/get_bip85_entropy.c
index 3c36c98..2f1d7e3 100644
--- a/main/process/get_bip85_entropy.c
+++ b/main/process/get_bip85_entropy.c
@@ -314,7 +314,7 @@ void get_bip85_bip39_entropy_process(void* process_ptr)
// Reply with the encrypted bip85 entropy reply
uint8_t buf[256];
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), &bip85_data, reply_bip85_data);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), &bip85_data, reply_bip85_data);
JADE_LOGI("Success");
cleanup:
@@ -341,7 +341,7 @@ void get_bip85_rsa_entropy_process(void* process_ptr)
// Reply with the encrypted bip85 entropy reply
uint8_t buf[256];
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), &bip85_data, reply_bip85_data);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), &bip85_data, reply_bip85_data);
JADE_LOGI("Success");
cleanup:
diff --git a/main/process/get_bip85_pubkey.c b/main/process/get_bip85_pubkey.c
index 0397dc7..133b73b 100644
--- a/main/process/get_bip85_pubkey.c
+++ b/main/process/get_bip85_pubkey.c
@@ -37,7 +37,7 @@ void get_bip85_pubkey_process(void* process_ptr)
// Reply with the pubkey pem
uint8_t buf[1024];
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), pubkey_pem, cbor_result_string_cb);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), pubkey_pem, cbor_result_string_cb);
JADE_LOGI("Success");
cleanup:
diff --git a/main/process/get_blinding_factor.c b/main/process/get_blinding_factor.c
index ac7b1b4..aa2d008 100644
--- a/main/process/get_blinding_factor.c
+++ b/main/process/get_blinding_factor.c
@@ -64,7 +64,7 @@ void get_blinding_factor_process(void* process_ptr)
goto cleanup;
}
- jade_process_reply_to_message_bytes(process->ctx, blinding_factor, bf_len);
+ jade_process_reply_to_message_bytes(&process->ctx, blinding_factor, bf_len);
JADE_LOGI("Success");
cleanup:
diff --git a/main/process/get_blinding_key.c b/main/process/get_blinding_key.c
index 8e10634..b42d027 100644
--- a/main/process/get_blinding_key.c
+++ b/main/process/get_blinding_key.c
@@ -40,7 +40,7 @@ void get_blinding_key_process(void* process_ptr)
goto cleanup;
}
- jade_process_reply_to_message_bytes(process->ctx, public_blinding_key, sizeof(public_blinding_key));
+ jade_process_reply_to_message_bytes(&process->ctx, public_blinding_key, sizeof(public_blinding_key));
JADE_LOGI("Success");
cleanup:
diff --git a/main/process/get_commitments.c b/main/process/get_commitments.c
index db35e69..1121d6e 100644
--- a/main/process/get_commitments.c
+++ b/main/process/get_commitments.c
@@ -123,7 +123,7 @@ void get_commitments_process(void* process_ptr)
}
uint8_t buf[320];
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), &ec, reply_commitments);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), &ec, reply_commitments);
JADE_LOGI("Success");
diff --git a/main/process/get_identity_pubkey.c b/main/process/get_identity_pubkey.c
index 99c0f7a..e5f2d27 100644
--- a/main/process/get_identity_pubkey.c
+++ b/main/process/get_identity_pubkey.c
@@ -59,7 +59,7 @@ void get_identity_pubkey_process(void* process_ptr)
}
// Return pubkey to caller
- jade_process_reply_to_message_bytes(process->ctx, pubkey, sizeof(pubkey));
+ jade_process_reply_to_message_bytes(&process->ctx, pubkey, sizeof(pubkey));
JADE_LOGI("Success");
diff --git a/main/process/get_identity_shared_key.c b/main/process/get_identity_shared_key.c
index 1a19e0c..3d9be33 100644
--- a/main/process/get_identity_shared_key.c
+++ b/main/process/get_identity_shared_key.c
@@ -58,7 +58,7 @@ void get_identity_shared_key_process(void* process_ptr)
}
// Return pubkey to caller
- jade_process_reply_to_message_bytes(process->ctx, shared_key, sizeof(shared_key));
+ jade_process_reply_to_message_bytes(&process->ctx, shared_key, sizeof(shared_key));
JADE_LOGI("Success");
diff --git a/main/process/get_master_blinding_key.c b/main/process/get_master_blinding_key.c
index 4e017c2..4a46252 100644
--- a/main/process/get_master_blinding_key.c
+++ b/main/process/get_master_blinding_key.c
@@ -44,7 +44,7 @@ void get_master_blinding_key_process(void* process_ptr)
JADE_STATIC_ASSERT(sizeof(keychain_get()->master_unblinding_key) == HMAC_SHA512_LEN);
jade_process_reply_to_message_bytes(
- process->ctx, keychain_get()->master_unblinding_key + HMAC_SHA512_LEN / 2, HMAC_SHA512_LEN / 2);
+ &process->ctx, keychain_get()->master_unblinding_key + HMAC_SHA512_LEN / 2, HMAC_SHA512_LEN / 2);
JADE_LOGI("Success");
cleanup:
diff --git a/main/process/get_otp_code.c b/main/process/get_otp_code.c
index 1bbae88..3f1abce 100644
--- a/main/process/get_otp_code.c
+++ b/main/process/get_otp_code.c
@@ -94,7 +94,7 @@ void get_otp_code_process(void* process_ptr)
JADE_LOGD("User pressed accept");
uint8_t buf[64];
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), token, cbor_result_string_cb);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), token, cbor_result_string_cb);
JADE_LOGI("Success");
diff --git a/main/process/get_receive_address.c b/main/process/get_receive_address.c
index 90056c2..2edf469 100644
--- a/main/process/get_receive_address.c
+++ b/main/process/get_receive_address.c
@@ -266,7 +266,7 @@ void get_receive_address_process(void* process_ptr)
// Reply with the address
uint8_t buf[256];
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), address, cbor_result_string_cb);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), address, cbor_result_string_cb);
JADE_LOGI("Success");
diff --git a/main/process/get_registered_descriptor.c b/main/process/get_registered_descriptor.c
index 16a8b05..f01d0c2 100644
--- a/main/process/get_registered_descriptor.c
+++ b/main/process/get_registered_descriptor.c
@@ -98,7 +98,7 @@ void get_registered_descriptor_process(void* process_ptr)
uint8_t* const buf = JADE_MALLOC(buflen);
const descriptor_details_t descriptor_details
= { .descriptor_name = descriptor_name, .descriptor_data = &descriptor_data };
- jade_process_reply_to_message_result(process->ctx, buf, buflen, &descriptor_details, reply_registered_descriptor);
+ jade_process_reply_to_message_result(&process->ctx, buf, buflen, &descriptor_details, reply_registered_descriptor);
free(buf);
JADE_LOGI("Success");
diff --git a/main/process/get_registered_descriptors.c b/main/process/get_registered_descriptors.c
index 498edfb..f4f6309 100644
--- a/main/process/get_registered_descriptors.c
+++ b/main/process/get_registered_descriptors.c
@@ -96,7 +96,7 @@ void get_registered_descriptors_process(void* process_ptr)
// Reply with this info
const size_t buflen = 256 + (64 * descriptions.num_descriptors);
uint8_t* const buf = JADE_MALLOC(buflen);
- jade_process_reply_to_message_result(process->ctx, buf, buflen, &descriptions, reply_registered_descriptors);
+ jade_process_reply_to_message_result(&process->ctx, buf, buflen, &descriptions, reply_registered_descriptors);
free(buf);
JADE_LOGI("Success");
diff --git a/main/process/get_registered_multisig.c b/main/process/get_registered_multisig.c
index 4844a93..d6dba54 100644
--- a/main/process/get_registered_multisig.c
+++ b/main/process/get_registered_multisig.c
@@ -179,7 +179,7 @@ void get_registered_multisig_process(void* process_ptr)
.multisig_export_file = export_file,
.multisig_data = &multisig_data,
.signer_details = signer_details };
- jade_process_reply_to_message_result(process->ctx, buf, buflen, &multisig_details, reply_registered_multisig);
+ jade_process_reply_to_message_result(&process->ctx, buf, buflen, &multisig_details, reply_registered_multisig);
free(buf);
JADE_LOGI("Success");
diff --git a/main/process/get_registered_multisigs.c b/main/process/get_registered_multisigs.c
index 3eb047b..bfa4a3b 100644
--- a/main/process/get_registered_multisigs.c
+++ b/main/process/get_registered_multisigs.c
@@ -122,7 +122,7 @@ void get_registered_multisigs_process(void* process_ptr)
// Reply with this info
const size_t buflen = 256 + (176 * descriptions.num_multisigs);
uint8_t* const buf = JADE_MALLOC(buflen);
- jade_process_reply_to_message_result(process->ctx, buf, buflen, &descriptions, reply_registered_multisigs);
+ jade_process_reply_to_message_result(&process->ctx, buf, buflen, &descriptions, reply_registered_multisigs);
free(buf);
JADE_LOGI("Success");
diff --git a/main/process/get_shared_nonce.c b/main/process/get_shared_nonce.c
index 4de56a6..a6a6a4e 100644
--- a/main/process/get_shared_nonce.c
+++ b/main/process/get_shared_nonce.c
@@ -104,10 +104,10 @@ void get_shared_nonce_process(void* process_ptr)
.shared_nonce_len = sizeof(shared_nonce),
.pubkey = p_blinding_pubkey,
.pubkey_len = blinding_pubkey_len };
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), &data, reply_nonce_and_pubkey);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), &data, reply_nonce_and_pubkey);
} else {
// Just shared blinding nonce alone (default/legacy behaviour)
- jade_process_reply_to_message_bytes(process->ctx, shared_nonce, sizeof(shared_nonce));
+ jade_process_reply_to_message_bytes(&process->ctx, shared_nonce, sizeof(shared_nonce));
}
JADE_LOGI("Success");
diff --git a/main/process/get_xpubs.c b/main/process/get_xpubs.c
index 1d6a3ea..865a9a7 100644
--- a/main/process/get_xpubs.c
+++ b/main/process/get_xpubs.c
@@ -37,7 +37,7 @@ void get_xpubs_process(void* process_ptr)
jade_process_wally_free_string_on_exit(process, output);
uint8_t buf[256];
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), output, cbor_result_string_cb);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), output, cbor_result_string_cb);
JADE_LOGI("Success");
diff --git a/main/process/ota_util.c b/main/process/ota_util.c
index 5eaa209..98b3c18 100644
--- a/main/process/ota_util.c
+++ b/main/process/ota_util.c
@@ -387,7 +387,7 @@ error:
} else {
// Send error response to the ota_complete message.
// If we didn't get an ota_complete, sets the reply id as "00".
- jade_process_reject_message_ex(process->ctx, errcode, "Error completing OTA", (const uint8_t*)status_text,
+ jade_process_reject_message_ex(&process->ctx, errcode, "Error completing OTA", (const uint8_t*)status_text,
strlen(status_text), buf, sizeof(buf));
}
diff --git a/main/process/pinclient.c b/main/process/pinclient.c
index 91d5bc9..ed49c92 100644
--- a/main/process/pinclient.c
+++ b/main/process/pinclient.c
@@ -122,7 +122,7 @@ static void send_http_request_reply(jade_process_t* process, const char* documen
// Send reply message
const size_t buflen = 1024 + cert_len;
uint8_t* const buf = JADE_MALLOC(buflen);
- jade_process_reply_to_message_result(process->ctx, buf, buflen, &pin_data, client_data_request_reply);
+ jade_process_reply_to_message_result(&process->ctx, buf, buflen, &pin_data, client_data_request_reply);
free(buf);
}
diff --git a/main/process/sign_attestation.c b/main/process/sign_attestation.c
index 823e29a..54a1b80 100644
--- a/main/process/sign_attestation.c
+++ b/main/process/sign_attestation.c
@@ -48,7 +48,7 @@ void sign_attestation_and_send_reply(jade_process_t* process, const uint8_t* cha
// Reply with pubkey and signatures
const size_t buflen = 2560;
uint8_t* const buf = JADE_MALLOC(buflen);
- jade_process_reply_to_message_result(process->ctx, buf, buflen, &output, reply_attestation);
+ jade_process_reply_to_message_result(&process->ctx, buf, buflen, &output, reply_attestation);
free(buf);
}
#endif // CONFIG_IDF_TARGET_ESP32S3
diff --git a/main/process/sign_bip85_digest.c b/main/process/sign_bip85_digest.c
index fa221d7..4d6dbc7 100644
--- a/main/process/sign_bip85_digest.c
+++ b/main/process/sign_bip85_digest.c
@@ -164,7 +164,7 @@ void sign_bip85_digests_process(void* process_ptr)
// Reply with signatures
uint8_t buf[2304];
const signatures_t result = { .signatures = signatures, .num_signatures = num_digests };
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), &result, reply_signatures);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), &result, reply_signatures);
JADE_LOGI("Success");
cleanup:
diff --git a/main/process/sign_identity.c b/main/process/sign_identity.c
index da24f3c..a5584aa 100644
--- a/main/process/sign_identity.c
+++ b/main/process/sign_identity.c
@@ -97,7 +97,7 @@ void sign_identity_process(void* process_ptr)
// Return pubkey and signature
uint8_t buf[256];
- jade_process_reply_to_message_result(process->ctx, buf, sizeof(buf), &output, reply_signature_and_pubkey);
+ jade_process_reply_to_message_result(&process->ctx, buf, sizeof(buf), &output, reply_signature_and_pubkey);
JADE_LOGI("Success");
diff --git a/main/process/sign_message.c b/main/process/sign_message.c
index a9621cb..cdd2ed6 100644
--- a/main/process/sign_message.c
+++ b/main/process/sign_message.c
@@ -183,7 +183,7 @@ void sign_message_process(void* process_ptr)
uint8_t buf[256];
jade_process_reply_to_message_result(
- process->ctx, buf, sizeof(buf), (const char*)signature, cbor_result_string_cb);
+ &process->ctx, buf, sizeof(buf), (const char*)signature, cbor_result_string_cb);
return;
}
@@ -272,7 +272,7 @@ void sign_message_process(void* process_ptr)
}
// Return signer commitment to caller
- jade_process_reply_to_message_bytes(process->ctx, ae_signer_commitment, sizeof(ae_signer_commitment));
+ jade_process_reply_to_message_bytes(&process->ctx, ae_signer_commitment, sizeof(ae_signer_commitment));
// Await 'get_signature' message containing host entropy
jade_process_load_in_message(process, true);
@@ -306,7 +306,7 @@ void sign_message_process(void* process_ptr)
uint8_t buf[256];
jade_process_reply_to_message_result(
- process->ctx, buf, sizeof(buf), (const char*)sig_output, cbor_result_string_cb);
+ &process->ctx, buf, sizeof(buf), (const char*)sig_output, cbor_result_string_cb);
JADE_LOGI("Success");
diff --git a/main/process/sign_psbt.c b/main/process/sign_psbt.c
index 56451f8..66b1697 100644
--- a/main/process/sign_psbt.c
+++ b/main/process/sign_psbt.c
@@ -1259,7 +1259,7 @@ void sign_psbt_process(void* process_ptr)
const size_t chunk_len = remaining < PSBT_OUT_CHUNK_SIZE ? remaining : PSBT_OUT_CHUNK_SIZE;
const size_t seqnum = imsg + 1;
jade_process_reply_to_message_bytes_sequence(
- process->ctx, seqnum, nmsgs, chunk, chunk_len, msgbuf, MAX_OUTPUT_MSG_SIZE);
+ &process->ctx, seqnum, nmsgs, chunk, chunk_len, msgbuf, MAX_OUTPUT_MSG_SIZE);
chunk += chunk_len;
if (seqnum < nmsgs) {
diff --git a/main/process/sign_tx.c b/main/process/sign_tx.c
index 3582f06..2e227ff 100644
--- a/main/process/sign_tx.c
+++ b/main/process/sign_tx.c
@@ -369,7 +369,7 @@ static void send_ae_signature_replies(const network_t network_id, jade_process_t
}
// Send signature reply - will be empty for any inputs we are not signing
- jade_process_reply_to_message_bytes(process->ctx, input_data->sig, input_data->sig_len);
+ jade_process_reply_to_message_bytes(&process->ctx, input_data->sig, input_data->sig_len);
}
cleanup:
(void)process; /* No-op for label */
@@ -790,7 +790,7 @@ static void sign_tx_impl(jade_process_t* process, const bool for_liquid)
// as this simplifies the code both here and in the client.
if (use_ae_signatures) {
const size_t commitment_len = made_ae_commitment ? sizeof(ae_signer_commitment) : 0;
- jade_process_reply_to_message_bytes(process->ctx, ae_signer_commitment, commitment_len);
+ jade_process_reply_to_message_bytes(&process->ctx, ae_signer_commitment, commitment_len);
}
}
diff --git a/main/wire.c b/main/wire.c
index b25b5d2..b318567 100644
--- a/main/wire.c
+++ b/main/wire.c
@@ -29,7 +29,7 @@ static const TickType_t TIMEOUT_TICKS = 3000 / portTICK_PERIOD_MS;
static const TickType_t TIMEOUT_TICKS = 2000 / portTICK_PERIOD_MS;
#endif
-static void reject_data(const cbor_msg_t ctx, const char* msg, size_t rejected_len)
+static void reject_data(const cbor_msg_t* const ctx, const char* msg, size_t rejected_len)
{
uint8_t len_str[16], out[112]; // sufficient
JADE_LOGW("%s, length %u", msg, rejected_len);
@@ -42,7 +42,7 @@ static void reject_data(const cbor_msg_t ctx, const char* msg, size_t rejected_l
static const char PING[] = { 'p', 'i', 'n', 'g' };
static const char VERINFO[] = { 'g', 'e', 't', '_', 'v', 'e', 'r', 's', 'i', 'o', 'n', '_', 'i', 'n', 'f', 'o' };
-static bool handleImmediateMessage(cbor_msg_t* ctx)
+static bool handle_immediate_message(const cbor_msg_t* const ctx)
{
JADE_ASSERT(ctx);
@@ -57,7 +57,7 @@ static bool handleImmediateMessage(cbor_msg_t* ctx)
uint8_t buf[64];
const uint64_t jade_task_current_action = main_thread_action;
jade_process_reply_to_message_result(
- *ctx, buf, sizeof(buf), &jade_task_current_action, cbor_result_uint64_cb);
+ ctx, buf, sizeof(buf), &jade_task_current_action, cbor_result_uint64_cb);
return true;
} else if (method_len == sizeof(VERINFO) && !strncmp(method, VERINFO, method_len)) {
// Version-info message - reply immediately if it contains the 'nonblocking' flag
@@ -67,7 +67,7 @@ static bool handleImmediateMessage(cbor_msg_t* ctx)
&& nonblocking) {
JADE_LOGI("VerInfoEx message, replying immediately");
uint8_t buf[1024];
- jade_process_reply_to_message_result(*ctx, buf, sizeof(buf), &ctx->source, build_version_info_reply);
+ jade_process_reply_to_message_result(ctx, buf, sizeof(buf), &ctx->source, build_version_info_reply);
return true;
}
}
@@ -112,14 +112,14 @@ static void handle_data_impl(uint8_t* full_data_in, size_t* read_ptr, bool rejec
// Not a complete/valid cbor message, and we are not allowed to await more, so reject what we have.
// Break to reset the read-ptr to the start and lose all the data.
- reject_data(ctx, "Invalid RPC Request message", read);
+ reject_data(&ctx, "Invalid RPC Request message", read);
break;
}
if (!rpc_request_valid(&ctx.value)) {
// bad message - expect all inputs to be cbor with a root map with an id and a method strings keys values
- reject_data(ctx, "Invalid RPC Request message (malformed)", msg_len);
- } else if (handleImmediateMessage(&ctx)) {
+ reject_data(&ctx, "Invalid RPC Request message (malformed)", msg_len);
+ } else if (handle_immediate_message(&ctx)) {
JADE_LOGI("Message handled, not passing to main task");
idletimer_register_activity(false);
} else {
@@ -129,7 +129,7 @@ static void handle_data_impl(uint8_t* full_data_in, size_t* read_ptr, bool rejec
// (but not as 'UI' activity - ie. keep jade on but do not stop the screen from turning off)
idletimer_register_activity(false);
} else {
- reject_data(ctx, "Input message too large", msg_len);
+ reject_data(&ctx, "Input message too large", msg_len);
}
}
Why this scored 25/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.