Skip to content

Commit f46bb46

Browse files
committed
Linting
1 parent 8c39083 commit f46bb46

File tree

4 files changed

+99
-90
lines changed

4 files changed

+99
-90
lines changed

src/handler/sign_psbt.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,14 +1527,13 @@ static bool __attribute__((noinline)) yield_signature(dispatcher_context_t *dc,
15271527
return true;
15281528
}
15291529

1530-
bool __attribute__((noinline))
1531-
sign_sighash_ecdsa_and_yield(dispatcher_context_t *dc,
1532-
sign_psbt_state_t *st,
1533-
unsigned int input_index,
1534-
const uint32_t sign_path[],
1535-
size_t sign_path_len,
1536-
uint8_t sighash_byte,
1537-
uint8_t sighash[static 32]) {
1530+
bool __attribute__((noinline)) sign_sighash_ecdsa_and_yield(dispatcher_context_t *dc,
1531+
sign_psbt_state_t *st,
1532+
unsigned int input_index,
1533+
const uint32_t sign_path[],
1534+
size_t sign_path_len,
1535+
uint8_t sighash_byte,
1536+
uint8_t sighash[static 32]) {
15381537
LOG_PROCESSOR(__FILE__, __LINE__, __func__);
15391538

15401539
uint8_t sig[MAX_DER_SIG_LEN + 1]; // extra byte for the appended sighash-type
@@ -1717,7 +1716,8 @@ static bool __attribute__((noinline)) sign_transaction_input(dispatcher_context_
17171716
return false;
17181717
}
17191718

1720-
uint8_t sighash_byte = input->has_sighash_type ? (uint8_t)input->sighash_type : SIGHASH_ALL;
1719+
uint8_t sighash_byte =
1720+
input->has_sighash_type ? (uint8_t) input->sighash_type : SIGHASH_ALL;
17211721

17221722
uint8_t sighash[32];
17231723
if (!compute_sighash_legacy(dc,
@@ -1799,7 +1799,8 @@ static bool __attribute__((noinline)) sign_transaction_input(dispatcher_context_
17991799
LEDGER_ASSERT(keyexpr_info->key_expression_ptr->type == KEY_EXPRESSION_NORMAL,
18001800
"Only plain key expressions are valid for SegwitV0 inputs");
18011801
// segwitv0 inputs default to SIGHASH_ALL
1802-
uint8_t sighash_byte = input->has_sighash_type ? (uint8_t)input->sighash_type : SIGHASH_ALL;
1802+
uint8_t sighash_byte =
1803+
input->has_sighash_type ? (uint8_t) input->sighash_type : SIGHASH_ALL;
18031804

18041805
if (!compute_sighash_segwitv0(dc,
18051806
st,
@@ -1822,7 +1823,8 @@ static bool __attribute__((noinline)) sign_transaction_input(dispatcher_context_
18221823
return false;
18231824
} else if (segwit_version == 1) {
18241825
// segwitv1 inputs default to SIGHASH_DEFAULT
1825-
uint8_t sighash_byte = input->has_sighash_type ? (uint8_t)input->sighash_type : SIGHASH_DEFAULT;
1826+
uint8_t sighash_byte =
1827+
input->has_sighash_type ? (uint8_t) input->sighash_type : SIGHASH_DEFAULT;
18261828

18271829
if (!compute_sighash_segwitv1(
18281830
dc,

src/handler/sign_psbt.h

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ typedef struct {
151151

152152
} sign_psbt_state_t;
153153

154-
155154
/**
156155
* Signs a legacy or SegwitV0 sighash using the ECDSA algorithm, and yields the necessary
157156
* info for the partial signature.
@@ -163,47 +162,51 @@ typedef struct {
163162
* @param[in] sign_path_len The number of derivation steps of the BIP32 path
164163
* @param[in] sighash_byte The sighash type byte
165164
* @param[out] sighash Pointer to a 32-byte array that will receive the computed sighash
166-
* @return true if the computation is successful, false otherwise. On failure, an error status word is already sent.
165+
* @return true if the computation is successful, false otherwise. On failure, an error status word
166+
* is already sent.
167167
*/
168-
bool __attribute__((noinline))
169-
sign_sighash_ecdsa_and_yield(dispatcher_context_t *dc,
170-
sign_psbt_state_t *st,
171-
unsigned int input_index,
172-
const uint32_t sign_path[],
173-
size_t sign_path_len,
174-
uint8_t sighash_byte,
175-
uint8_t sighash[static 32]);
168+
bool __attribute__((noinline)) sign_sighash_ecdsa_and_yield(dispatcher_context_t *dc,
169+
sign_psbt_state_t *st,
170+
unsigned int input_index,
171+
const uint32_t sign_path[],
172+
size_t sign_path_len,
173+
uint8_t sighash_byte,
174+
uint8_t sighash[static 32]);
176175

177176
/**
178177
* Signs a legacy or SegwitV0 sighash using the ECDSA algorithm, and yields the necessary
179178
* info for the partial signature.
180179
*
181-
* This function allows to select the tweak_data to be used after the BIP-32 derivation. This should be:
180+
* This function allows to select the tweak_data to be used after the BIP-32 derivation. This should
181+
* be:
182182
* - a zero-length array for key conforming to BIP-86 and BIP-386.abort
183183
* - a 32-byte array containing the taproot Merkle tree root for taproot Script path spends.
184-
* Passing NULL allows to sign with an untweaked key, for example in case this is used for a protocol using the
185-
* `rawtr()` expression.
184+
* Passing NULL allows to sign with an untweaked key, for example in case this is used for a
185+
* protocol using the `rawtr()` expression.
186186
*
187187
* @param[in] dc The dispatcher context
188188
* @param[in] st The signing state
189189
* @param[in] input_index The index of the input whose sighash is being signed
190190
* @param[in] sign_path The BIP32 path of the key being used to sign
191191
* @param[in] sign_path_len The number of derivation steps of the BIP32 path
192-
* @param[in] tweak_data If the key used to sign has to be tweaked, a pointer to an array containing the tweak data. NULL otherwise.
193-
* @param[in] tweak_data_len The length of the `tweak_data` array. If `tweak_data` is NULL, this should be 0.
194-
* @param[in] tapleaf_hash NULL if the sighash was signed using the keypath spend, or the tapleaf hash if the sighash was signed using a script path spend.
192+
* @param[in] tweak_data If the key used to sign has to be tweaked, a pointer to an array containing
193+
* the tweak data. NULL otherwise.
194+
* @param[in] tweak_data_len The length of the `tweak_data` array. If `tweak_data` is NULL, this
195+
* should be 0.
196+
* @param[in] tapleaf_hash NULL if the sighash was signed using the keypath spend, or the tapleaf
197+
* hash if the sighash was signed using a script path spend.
195198
* @param[in] sighash_byte The sighash type byte
196199
* @param[in] sighash Pointer to a 32-byte array containing the sighash to sign
197-
* @return true if the computation is successful, false otherwise. On failure, an error status word is already sent.
200+
* @return true if the computation is successful, false otherwise. On failure, an error status word
201+
* is already sent.
198202
*/
199-
bool __attribute__((noinline))
200-
sign_sighash_schnorr_and_yield(dispatcher_context_t *dc,
201-
sign_psbt_state_t *st,
202-
unsigned int input_index,
203-
const uint32_t sign_path[],
204-
size_t sign_path_len,
205-
const uint8_t *tweak_data,
206-
size_t tweak_data_len,
207-
const uint8_t *tapleaf_hash,
208-
uint8_t sighash_byte,
209-
const uint8_t sighash[static 32]);
203+
bool __attribute__((noinline)) sign_sighash_schnorr_and_yield(dispatcher_context_t *dc,
204+
sign_psbt_state_t *st,
205+
unsigned int input_index,
206+
const uint32_t sign_path[],
207+
size_t sign_path_len,
208+
const uint8_t *tweak_data,
209+
size_t tweak_data_len,
210+
const uint8_t *tapleaf_hash,
211+
uint8_t sighash_byte,
212+
const uint8_t sighash[static 32]);

src/handler/sign_psbt/txhashes.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,14 @@ bool __attribute__((noinline)) compute_sighash_legacy(dispatcher_context_t *dc,
316316
} else {
317317
if (!has_redeemScript) {
318318
if (scriptPubKey == NULL) {
319-
SEND_SW(dc, SW_BAD_STATE); // we should never reach here
319+
SEND_SW(dc, SW_BAD_STATE); // we should never reach here
320320
return false;
321321
}
322322

323-
// P2PKH, the script_code is the prevout's scriptPubKey, and is provided by the caller
323+
// P2PKH, the script_code is the prevout's scriptPubKey, and is provided by the
324+
// caller
324325
crypto_hash_update_varint(&sighash_context.header, scriptPubKey_len);
325-
crypto_hash_update(&sighash_context.header,
326-
scriptPubKey,
327-
scriptPubKey_len);
326+
crypto_hash_update(&sighash_context.header, scriptPubKey, scriptPubKey_len);
328327
} else {
329328
// P2SH, the script_code is the redeemScript; we read it from the psbt
330329

@@ -371,7 +370,7 @@ bool __attribute__((noinline)) compute_sighash_legacy(dispatcher_context_t *dc,
371370
crypto_hash_update(&sighash_context.header, tmp, 4);
372371

373372
// hash type
374-
write_u32_le(tmp, 0, (uint32_t)sighash_byte);
373+
write_u32_le(tmp, 0, (uint32_t) sighash_byte);
375374
crypto_hash_update(&sighash_context.header, tmp, 4);
376375

377376
// compute sighash
@@ -381,15 +380,16 @@ bool __attribute__((noinline)) compute_sighash_legacy(dispatcher_context_t *dc,
381380
return true;
382381
}
383382

384-
bool __attribute__((noinline)) compute_sighash_segwitv0(dispatcher_context_t *dc,
385-
const sign_psbt_state_t *st,
386-
const tx_hashes_t *hashes,
387-
const merkleized_map_commitment_t *input_map,
388-
unsigned int input_index,
389-
const uint8_t *script,
390-
size_t script_len,
391-
uint8_t sighash_byte,
392-
uint8_t sighash[static 32]) {
383+
bool __attribute__((noinline))
384+
compute_sighash_segwitv0(dispatcher_context_t *dc,
385+
const sign_psbt_state_t *st,
386+
const tx_hashes_t *hashes,
387+
const merkleized_map_commitment_t *input_map,
388+
unsigned int input_index,
389+
const uint8_t *script,
390+
size_t script_len,
391+
uint8_t sighash_byte,
392+
uint8_t sighash[static 32]) {
393393
LOG_PROCESSOR(__FILE__, __LINE__, __func__);
394394

395395
cx_sha256_t sighash_context;
@@ -568,16 +568,17 @@ bool __attribute__((noinline)) compute_sighash_segwitv0(dispatcher_context_t *dc
568568
return true;
569569
}
570570

571-
bool __attribute__((noinline)) compute_sighash_segwitv1(dispatcher_context_t *dc,
572-
const sign_psbt_state_t *st,
573-
const tx_hashes_t *hashes,
574-
const merkleized_map_commitment_t *input_map,
575-
unsigned int input_index,
576-
const uint8_t *scriptPubKey,
577-
size_t scriptPubKey_len,
578-
const uint8_t *tapleaf_hash,
579-
uint8_t sighash_byte,
580-
uint8_t sighash[static 32]) {
571+
bool __attribute__((noinline))
572+
compute_sighash_segwitv1(dispatcher_context_t *dc,
573+
const sign_psbt_state_t *st,
574+
const tx_hashes_t *hashes,
575+
const merkleized_map_commitment_t *input_map,
576+
unsigned int input_index,
577+
const uint8_t *scriptPubKey,
578+
size_t scriptPubKey_len,
579+
const uint8_t *tapleaf_hash,
580+
uint8_t sighash_byte,
581+
uint8_t sighash[static 32]) {
581582
LOG_PROCESSOR(__FILE__, __LINE__, __func__);
582583

583584
cx_sha256_t sighash_context;
@@ -656,9 +657,7 @@ bool __attribute__((noinline)) compute_sighash_segwitv1(dispatcher_context_t *dc
656657

657658
// scriptPubKey
658659
crypto_hash_update_varint(&sighash_context.header, scriptPubKey_len);
659-
crypto_hash_update(&sighash_context.header,
660-
scriptPubKey,
661-
scriptPubKey_len);
660+
crypto_hash_update(&sighash_context.header, scriptPubKey, scriptPubKey_len);
662661

663662
// nSequence
664663
if (4 != call_get_merkleized_map_value(dc,

src/handler/sign_psbt/txhashes.h

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ compute_tx_hashes(dispatcher_context_t *dc, sign_psbt_state_t *st, tx_hashes_t *
2222
* @param[in] input_map Pointer to the map commitment of the input being signed for.
2323
* @param[in] input_index Index of the input for which the sighash is being computed.
2424
* @param[in] has_redeemScript Whether the input has a redeemScript.
25-
* @param[in] scriptPubKey Pointer to the scriptPubKey of the input being signed for (which should be obtained from the non-witness UTXO)
25+
* @param[in] scriptPubKey Pointer to the scriptPubKey of the input being signed for (which should
26+
* be obtained from the non-witness UTXO)
2627
* @param[in] scriptPubKey_len Length of the scriptPubKey.
2728
* @param[in] sighash_byte The sighash type byte.
2829
* @param[out] sighash Array where the computed sighash will be stored (must be at least 32 bytes).
@@ -46,22 +47,24 @@ bool __attribute__((noinline)) compute_sighash_legacy(dispatcher_context_t *dc,
4647
* @param[in] hashes Pointer to the structure containing the precomputed transaction hashes.
4748
* @param[in] input_map Pointer to the map commitment of the input being signed for.
4849
* @param[in] input_index Index of the input for which the sighash is being computed.
49-
* @param[in] script Pointer to the script used for signing. It is the redeemScript if this input has one; otherwise
50-
* it is the scriptPubKey of the input being signed for (which should be obtained from the witness UTXO).
50+
* @param[in] script Pointer to the script used for signing. It is the redeemScript if this input
51+
* has one; otherwise it is the scriptPubKey of the input being signed for (which should be obtained
52+
* from the witness UTXO).
5153
* @param[in] script_len Length of the script.
5254
* @param[in] sighash_byte The sighash type byte.
5355
* @param[out] sighash Array where the computed sighash will be stored (must be at least 32 bytes).
5456
* @return true if the computation is successful, false otherwise.
5557
*/
56-
bool __attribute__((noinline)) compute_sighash_segwitv0(dispatcher_context_t *dc,
57-
const sign_psbt_state_t *st,
58-
const tx_hashes_t *hashes,
59-
const merkleized_map_commitment_t *input_map,
60-
unsigned int input_index,
61-
const uint8_t *script,
62-
size_t script_len,
63-
uint8_t sighash_byte,
64-
uint8_t sighash[static 32]);
58+
bool __attribute__((noinline))
59+
compute_sighash_segwitv0(dispatcher_context_t *dc,
60+
const sign_psbt_state_t *st,
61+
const tx_hashes_t *hashes,
62+
const merkleized_map_commitment_t *input_map,
63+
unsigned int input_index,
64+
const uint8_t *script,
65+
size_t script_len,
66+
uint8_t sighash_byte,
67+
uint8_t sighash[static 32]);
6568

6669
/**
6770
* Computes the SegWit v1 (Taproot) sighash for a given input.
@@ -71,21 +74,23 @@ bool __attribute__((noinline)) compute_sighash_segwitv0(dispatcher_context_t *dc
7174
* @param[in] hashes Pointer to the structure containing the precomputed transaction hashes.
7275
* @param[in] input_map Pointer to the map commitment of the input being signed for.
7376
* @param[in] input_index Index of the input for which the sighash is being computed.
74-
* @param[in] scriptPubKey Pointer to the scriptPubKey of the input being signed for (which should be obtained from the non-witness UTXO)
77+
* @param[in] scriptPubKey Pointer to the scriptPubKey of the input being signed for (which should
78+
* be obtained from the non-witness UTXO)
7579
* @param[in] scriptPubKey_len Length of the scriptPubKey.
7680
* @param[in] tapleaf_hash Array containing the Taproot leaf hash. It must be NULL if spending using
7781
* the key path; otherwise, it is a pointer to a 32-byte array.
7882
* @param[in] sighash_byte The sighash type byte.
7983
* @param[out] sighash Array where the computed sighash will be stored (must be at least 32 bytes).
8084
* @return true if the computation is successful, false otherwise.
8185
*/
82-
bool __attribute__((noinline)) compute_sighash_segwitv1(dispatcher_context_t *dc,
83-
const sign_psbt_state_t *st,
84-
const tx_hashes_t *hashes,
85-
const merkleized_map_commitment_t *input_map,
86-
unsigned int input_index,
87-
const uint8_t *scriptPubKey,
88-
size_t scriptPubKey_len,
89-
const uint8_t *tapleaf_hash,
90-
uint8_t sighash_byte,
91-
uint8_t sighash[static 32]);
86+
bool __attribute__((noinline))
87+
compute_sighash_segwitv1(dispatcher_context_t *dc,
88+
const sign_psbt_state_t *st,
89+
const tx_hashes_t *hashes,
90+
const merkleized_map_commitment_t *input_map,
91+
unsigned int input_index,
92+
const uint8_t *scriptPubKey,
93+
size_t scriptPubKey_len,
94+
const uint8_t *tapleaf_hash,
95+
uint8_t sighash_byte,
96+
uint8_t sighash[static 32]);

0 commit comments

Comments
 (0)