1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

fsm: use const where applicable, document where it isn't and why

This commit is contained in:
Pavol Rusnak 2018-09-14 14:40:29 +02:00
parent a4058e1061
commit 7b4f027445
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
17 changed files with 182 additions and 311 deletions

View File

@ -584,7 +584,7 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node)
} }
} }
void ethereum_signing_txack(EthereumTxAck *tx) void ethereum_signing_txack(const EthereumTxAck *tx)
{ {
if (!ethereum_signing) { if (!ethereum_signing) {
fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Not in Ethereum signing mode")); fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Not in Ethereum signing mode"));
@ -644,7 +644,7 @@ static void ethereum_message_hash(const uint8_t *message, size_t message_len, ui
keccak_Final(&ctx, hash); keccak_Final(&ctx, hash);
} }
void ethereum_message_sign(EthereumSignMessage *msg, const HDNode *node, EthereumMessageSignature *resp) void ethereum_message_sign(const EthereumSignMessage *msg, const HDNode *node, EthereumMessageSignature *resp)
{ {
uint8_t hash[32]; uint8_t hash[32];
@ -667,7 +667,7 @@ void ethereum_message_sign(EthereumSignMessage *msg, const HDNode *node, Ethereu
msg_write(MessageType_MessageType_EthereumMessageSignature, resp); msg_write(MessageType_MessageType_EthereumMessageSignature, resp);
} }
int ethereum_message_verify(EthereumVerifyMessage *msg) int ethereum_message_verify(const EthereumVerifyMessage *msg)
{ {
if (msg->signature.size != 65 || msg->address.size != 20) { if (msg->signature.size != 65 || msg->address.size != 20) {
fsm_sendFailure(FailureType_Failure_DataError, _("Malformed data")); fsm_sendFailure(FailureType_Failure_DataError, _("Malformed data"));

View File

@ -27,9 +27,9 @@
void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node); void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node);
void ethereum_signing_abort(void); void ethereum_signing_abort(void);
void ethereum_signing_txack(EthereumTxAck *msg); void ethereum_signing_txack(const EthereumTxAck *msg);
void ethereum_message_sign(EthereumSignMessage *msg, const HDNode *node, EthereumMessageSignature *resp); void ethereum_message_sign(const EthereumSignMessage *msg, const HDNode *node, EthereumMessageSignature *resp);
int ethereum_message_verify(EthereumVerifyMessage *msg); int ethereum_message_verify(const EthereumVerifyMessage *msg);
#endif #endif

View File

@ -41,82 +41,86 @@ void fsm_sendFailureDebug(FailureType code, const char *text, const char *source
void fsm_sendFailure(FailureType code, const char *text); void fsm_sendFailure(FailureType code, const char *text);
#endif #endif
void fsm_msgInitialize(Initialize *msg); // void fsm_msgPinMatrixAck(const PinMatrixAck *msg); // tiny
void fsm_msgGetFeatures(GetFeatures *msg); // void fsm_msgButtonAck(const ButtonAck *msg); // tiny
void fsm_msgPing(Ping *msg); // void fsm_msgPassphraseAck(const PassphraseAck *msg); // tiny
void fsm_msgChangePin(ChangePin *msg);
void fsm_msgWipeDevice(WipeDevice *msg);
void fsm_msgGetEntropy(GetEntropy *msg);
void fsm_msgGetPublicKey(GetPublicKey *msg);
void fsm_msgLoadDevice(LoadDevice *msg);
void fsm_msgResetDevice(ResetDevice *msg);
void fsm_msgBackupDevice(BackupDevice *msg);
void fsm_msgSignTx(SignTx *msg);
//void fsm_msgPinMatrixAck(PinMatrixAck *msg);
void fsm_msgCancel(Cancel *msg);
void fsm_msgTxAck(TxAck *msg);
void fsm_msgCipherKeyValue(CipherKeyValue *msg);
void fsm_msgClearSession(ClearSession *msg);
void fsm_msgApplySettings(ApplySettings *msg);
void fsm_msgApplyFlags(ApplyFlags *msg);
//void fsm_msgButtonAck(ButtonAck *msg);
void fsm_msgGetAddress(GetAddress *msg);
void fsm_msgEntropyAck(EntropyAck *msg);
void fsm_msgSignMessage(SignMessage *msg);
void fsm_msgVerifyMessage(VerifyMessage *msg);
void fsm_msgSignIdentity(SignIdentity *msg);
void fsm_msgGetECDHSessionKey(GetECDHSessionKey *msg);
/* ECIES disabled
void fsm_msgEncryptMessage(EncryptMessage *msg);
void fsm_msgDecryptMessage(DecryptMessage *msg);
*/
//void fsm_msgPassphraseAck(PassphraseAck *msg);
void fsm_msgRecoveryDevice(RecoveryDevice *msg);
void fsm_msgWordAck(WordAck *msg);
void fsm_msgSetU2FCounter(SetU2FCounter *msg);
void fsm_msgEthereumGetAddress(EthereumGetAddress *msg);
void fsm_msgEthereumSignTx(EthereumSignTx *msg);
void fsm_msgEthereumTxAck(EthereumTxAck *msg);
void fsm_msgEthereumSignMessage(EthereumSignMessage *msg);
void fsm_msgEthereumVerifyMessage(EthereumVerifyMessage *msg);
void fsm_msgNEMGetAddress(NEMGetAddress *msg); // common
void fsm_msgNEMSignTx(NEMSignTx *msg); void fsm_msgInitialize(const Initialize *msg);
void fsm_msgNEMDecryptMessage(NEMDecryptMessage *msg); void fsm_msgGetFeatures(const GetFeatures *msg);
void fsm_msgPing(const Ping *msg);
void fsm_msgChangePin(const ChangePin *msg);
void fsm_msgWipeDevice(const WipeDevice *msg);
void fsm_msgGetEntropy(const GetEntropy *msg);
void fsm_msgLoadDevice(const LoadDevice *msg);
void fsm_msgResetDevice(const ResetDevice *msg);
void fsm_msgEntropyAck(const EntropyAck *msg);
void fsm_msgBackupDevice(const BackupDevice *msg);
void fsm_msgCancel(const Cancel *msg);
void fsm_msgClearSession(const ClearSession *msg);
void fsm_msgApplySettings(const ApplySettings *msg);
void fsm_msgApplyFlags(const ApplyFlags *msg);
void fsm_msgRecoveryDevice(const RecoveryDevice *msg);
void fsm_msgWordAck(const WordAck *msg);
void fsm_msgSetU2FCounter(const SetU2FCounter *msg);
void fsm_msgCosiCommit(CosiCommit *msg); // coin
void fsm_msgCosiSign(CosiSign *msg); void fsm_msgGetPublicKey(const GetPublicKey *msg);
void fsm_msgSignTx(const SignTx *msg);
void fsm_msgTxAck(TxAck *msg); // not const because we mutate input/output scripts
void fsm_msgGetAddress(const GetAddress *msg);
void fsm_msgSignMessage(const SignMessage *msg);
void fsm_msgVerifyMessage(const VerifyMessage *msg);
// Stellar // crypto
void fsm_msgStellarGetAddress(StellarGetAddress *msg); void fsm_msgCipherKeyValue(CipherKeyValue *msg); // not const because we mutate msg->iv
void fsm_msgStellarSignTx(StellarSignTx *msg); void fsm_msgSignIdentity(const SignIdentity *msg);
void fsm_msgStellarPaymentOp(StellarPaymentOp *msg); void fsm_msgGetECDHSessionKey(const GetECDHSessionKey *msg);
void fsm_msgStellarCreateAccountOp(StellarCreateAccountOp *msg); void fsm_msgCosiCommit(const CosiCommit *msg);
void fsm_msgStellarPathPaymentOp(StellarPathPaymentOp *msg); void fsm_msgCosiSign(const CosiSign *msg);
void fsm_msgStellarManageOfferOp(StellarManageOfferOp *msg);
void fsm_msgStellarCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg);
void fsm_msgStellarSetOptionsOp(StellarSetOptionsOp *msg);
void fsm_msgStellarChangeTrustOp(StellarChangeTrustOp *msg);
void fsm_msgStellarAllowTrustOp(StellarAllowTrustOp *msg);
void fsm_msgStellarAccountMergeOp(StellarAccountMergeOp *msg);
void fsm_msgStellarManageDataOp(StellarManageDataOp *msg);
void fsm_msgStellarBumpSequenceOp(StellarBumpSequenceOp *msg);
// Lisk // debug
void fsm_msgLiskGetAddress(LiskGetAddress *msg);
void fsm_msgLiskGetPublicKey(LiskGetPublicKey *msg);
void fsm_msgLiskSignMessage(LiskSignMessage *msg);
void fsm_msgLiskVerifyMessage(LiskVerifyMessage *msg);
void fsm_msgLiskSignTx(LiskSignTx *msg);
// debug message functions
#if DEBUG_LINK #if DEBUG_LINK
//void fsm_msgDebugLinkDecision(DebugLinkDecision *msg); // void fsm_msgDebugLinkDecision(const DebugLinkDecision *msg); // tiny
void fsm_msgDebugLinkGetState(DebugLinkGetState *msg); void fsm_msgDebugLinkGetState(const DebugLinkGetState *msg);
void fsm_msgDebugLinkStop(DebugLinkStop *msg); void fsm_msgDebugLinkStop(const DebugLinkStop *msg);
void fsm_msgDebugLinkMemoryWrite(DebugLinkMemoryWrite *msg); void fsm_msgDebugLinkMemoryWrite(const DebugLinkMemoryWrite *msg);
void fsm_msgDebugLinkMemoryRead(DebugLinkMemoryRead *msg); void fsm_msgDebugLinkMemoryRead(const DebugLinkMemoryRead *msg);
void fsm_msgDebugLinkFlashErase(DebugLinkFlashErase *msg); void fsm_msgDebugLinkFlashErase(const DebugLinkFlashErase *msg);
#endif #endif
// ethereum
void fsm_msgEthereumGetAddress(const EthereumGetAddress *msg);
void fsm_msgEthereumSignTx(EthereumSignTx *msg); // not const because we mutate transaction
void fsm_msgEthereumTxAck(const EthereumTxAck *msg);
void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg);
void fsm_msgEthereumVerifyMessage(const EthereumVerifyMessage *msg);
// lisk
void fsm_msgLiskGetAddress(const LiskGetAddress *msg);
void fsm_msgLiskGetPublicKey(const LiskGetPublicKey *msg);
void fsm_msgLiskSignMessage(const LiskSignMessage *msg);
void fsm_msgLiskVerifyMessage(const LiskVerifyMessage *msg);
void fsm_msgLiskSignTx(LiskSignTx *msg); // // not const because we mutate transaction
// nem
void fsm_msgNEMGetAddress(NEMGetAddress *msg); // not const because we mutate msg->network
void fsm_msgNEMSignTx(NEMSignTx *msg); // not const because we mutate msg->network
void fsm_msgNEMDecryptMessage(NEMDecryptMessage *msg); // not const because we mutate msg->payload
// stellar
void fsm_msgStellarGetAddress(const StellarGetAddress *msg);
void fsm_msgStellarSignTx(const StellarSignTx *msg);
void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg);
void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg);
void fsm_msgStellarPathPaymentOp(const StellarPathPaymentOp *msg);
void fsm_msgStellarManageOfferOp(const StellarManageOfferOp *msg);
void fsm_msgStellarCreatePassiveOfferOp(const StellarCreatePassiveOfferOp *msg);
void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg);
void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg);
void fsm_msgStellarAllowTrustOp(const StellarAllowTrustOp *msg);
void fsm_msgStellarAccountMergeOp(const StellarAccountMergeOp *msg);
void fsm_msgStellarManageDataOp(const StellarManageDataOp *msg);
void fsm_msgStellarBumpSequenceOp(const StellarBumpSequenceOp *msg);
#endif #endif

View File

@ -17,7 +17,7 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>. * along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
void fsm_msgGetPublicKey(GetPublicKey *msg) void fsm_msgGetPublicKey(const GetPublicKey *msg)
{ {
RESP_INIT(PublicKey); RESP_INIT(PublicKey);
@ -81,7 +81,7 @@ void fsm_msgGetPublicKey(GetPublicKey *msg)
layoutHome(); layoutHome();
} }
void fsm_msgSignTx(SignTx *msg) void fsm_msgSignTx(const SignTx *msg)
{ {
CHECK_INITIALIZED CHECK_INITIALIZED
@ -181,7 +181,7 @@ static bool path_mismatched(const CoinInfo *coin, const GetAddress *msg)
return false; return false;
} }
void fsm_msgGetAddress(GetAddress *msg) void fsm_msgGetAddress(const GetAddress *msg)
{ {
RESP_INIT(Address); RESP_INIT(Address);
@ -242,7 +242,7 @@ void fsm_msgGetAddress(GetAddress *msg)
layoutHome(); layoutHome();
} }
void fsm_msgSignMessage(SignMessage *msg) void fsm_msgSignMessage(const SignMessage *msg)
{ {
// CHECK_PARAM(is_ascii_only(msg->message.bytes, msg->message.size), _("Cannot sign non-ASCII strings")); // CHECK_PARAM(is_ascii_only(msg->message.bytes, msg->message.size), _("Cannot sign non-ASCII strings"));
@ -282,7 +282,7 @@ void fsm_msgSignMessage(SignMessage *msg)
layoutHome(); layoutHome();
} }
void fsm_msgVerifyMessage(VerifyMessage *msg) void fsm_msgVerifyMessage(const VerifyMessage *msg)
{ {
CHECK_PARAM(msg->has_address, _("No address provided")); CHECK_PARAM(msg->has_address, _("No address provided"));
CHECK_PARAM(msg->has_message, _("No message provided")); CHECK_PARAM(msg->has_message, _("No message provided"));

View File

@ -17,7 +17,7 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>. * along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
void fsm_msgInitialize(Initialize *msg) void fsm_msgInitialize(const Initialize *msg)
{ {
recovery_abort(); recovery_abort();
signing_abort(); signing_abort();
@ -37,7 +37,7 @@ void fsm_msgInitialize(Initialize *msg)
fsm_msgGetFeatures(0); fsm_msgGetFeatures(0);
} }
void fsm_msgGetFeatures(GetFeatures *msg) void fsm_msgGetFeatures(const GetFeatures *msg)
{ {
(void)msg; (void)msg;
RESP_INIT(Features); RESP_INIT(Features);
@ -74,7 +74,7 @@ void fsm_msgGetFeatures(GetFeatures *msg)
msg_write(MessageType_MessageType_Features, resp); msg_write(MessageType_MessageType_Features, resp);
} }
void fsm_msgPing(Ping *msg) void fsm_msgPing(const Ping *msg)
{ {
RESP_INIT(Success); RESP_INIT(Success);
@ -106,7 +106,7 @@ void fsm_msgPing(Ping *msg)
layoutHome(); layoutHome();
} }
void fsm_msgChangePin(ChangePin *msg) void fsm_msgChangePin(const ChangePin *msg)
{ {
bool removal = msg->has_remove && msg->remove; bool removal = msg->has_remove && msg->remove;
if (removal) { if (removal) {
@ -145,7 +145,7 @@ void fsm_msgChangePin(ChangePin *msg)
layoutHome(); layoutHome();
} }
void fsm_msgWipeDevice(WipeDevice *msg) void fsm_msgWipeDevice(const WipeDevice *msg)
{ {
(void)msg; (void)msg;
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you really want to"), _("wipe the device?"), NULL, _("All data will be lost."), NULL, NULL); layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you really want to"), _("wipe the device?"), NULL, _("All data will be lost."), NULL, NULL);
@ -161,7 +161,7 @@ void fsm_msgWipeDevice(WipeDevice *msg)
layoutHome(); layoutHome();
} }
void fsm_msgGetEntropy(GetEntropy *msg) void fsm_msgGetEntropy(const GetEntropy *msg)
{ {
#if !DEBUG_RNG #if !DEBUG_RNG
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you really want to"), _("send entropy?"), NULL, NULL, NULL, NULL); layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you really want to"), _("send entropy?"), NULL, NULL, NULL, NULL);
@ -182,7 +182,7 @@ void fsm_msgGetEntropy(GetEntropy *msg)
layoutHome(); layoutHome();
} }
void fsm_msgLoadDevice(LoadDevice *msg) void fsm_msgLoadDevice(const LoadDevice *msg)
{ {
CHECK_NOT_INITIALIZED CHECK_NOT_INITIALIZED
@ -206,7 +206,7 @@ void fsm_msgLoadDevice(LoadDevice *msg)
layoutHome(); layoutHome();
} }
void fsm_msgResetDevice(ResetDevice *msg) void fsm_msgResetDevice(const ResetDevice *msg)
{ {
CHECK_NOT_INITIALIZED CHECK_NOT_INITIALIZED
@ -224,7 +224,7 @@ void fsm_msgResetDevice(ResetDevice *msg)
); );
} }
void fsm_msgEntropyAck(EntropyAck *msg) void fsm_msgEntropyAck(const EntropyAck *msg)
{ {
if (msg->has_entropy) { if (msg->has_entropy) {
reset_entropy(msg->entropy.bytes, msg->entropy.size); reset_entropy(msg->entropy.bytes, msg->entropy.size);
@ -233,7 +233,7 @@ void fsm_msgEntropyAck(EntropyAck *msg)
} }
} }
void fsm_msgBackupDevice(BackupDevice *msg) void fsm_msgBackupDevice(const BackupDevice *msg)
{ {
CHECK_INITIALIZED CHECK_INITIALIZED
@ -243,7 +243,7 @@ void fsm_msgBackupDevice(BackupDevice *msg)
reset_backup(true); reset_backup(true);
} }
void fsm_msgCancel(Cancel *msg) void fsm_msgCancel(const Cancel *msg)
{ {
(void)msg; (void)msg;
recovery_abort(); recovery_abort();
@ -252,7 +252,7 @@ void fsm_msgCancel(Cancel *msg)
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
} }
void fsm_msgClearSession(ClearSession *msg) void fsm_msgClearSession(const ClearSession *msg)
{ {
(void)msg; (void)msg;
session_clear(true); // clear PIN as well session_clear(true); // clear PIN as well
@ -260,7 +260,7 @@ void fsm_msgClearSession(ClearSession *msg)
fsm_sendSuccess(_("Session cleared")); fsm_sendSuccess(_("Session cleared"));
} }
void fsm_msgApplySettings(ApplySettings *msg) void fsm_msgApplySettings(const ApplySettings *msg)
{ {
CHECK_PARAM(msg->has_label || msg->has_language || msg->has_use_passphrase || msg->has_homescreen || msg->has_auto_lock_delay_ms, CHECK_PARAM(msg->has_label || msg->has_language || msg->has_use_passphrase || msg->has_homescreen || msg->has_auto_lock_delay_ms,
_("No setting provided")); _("No setting provided"));
@ -329,7 +329,7 @@ void fsm_msgApplySettings(ApplySettings *msg)
layoutHome(); layoutHome();
} }
void fsm_msgApplyFlags(ApplyFlags *msg) void fsm_msgApplyFlags(const ApplyFlags *msg)
{ {
if (msg->has_flags) { if (msg->has_flags) {
storage_applyFlags(msg->flags); storage_applyFlags(msg->flags);
@ -337,7 +337,7 @@ void fsm_msgApplyFlags(ApplyFlags *msg)
fsm_sendSuccess(_("Flags applied")); fsm_sendSuccess(_("Flags applied"));
} }
void fsm_msgRecoveryDevice(RecoveryDevice *msg) void fsm_msgRecoveryDevice(const RecoveryDevice *msg)
{ {
const bool dry_run = msg->has_dry_run ? msg->dry_run : false; const bool dry_run = msg->has_dry_run ? msg->dry_run : false;
if (dry_run) { if (dry_run) {
@ -370,12 +370,12 @@ void fsm_msgRecoveryDevice(RecoveryDevice *msg)
); );
} }
void fsm_msgWordAck(WordAck *msg) void fsm_msgWordAck(const WordAck *msg)
{ {
recovery_word(msg->word); recovery_word(msg->word);
} }
void fsm_msgSetU2FCounter(SetU2FCounter *msg) void fsm_msgSetU2FCounter(const SetU2FCounter *msg)
{ {
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you want to set"), _("the U2F counter?"), NULL, NULL, NULL, NULL); layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you want to set"), _("the U2F counter?"), NULL, NULL, NULL, NULL);
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {

View File

@ -65,7 +65,7 @@ void fsm_msgCipherKeyValue(CipherKeyValue *msg)
layoutHome(); layoutHome();
} }
void fsm_msgSignIdentity(SignIdentity *msg) void fsm_msgSignIdentity(const SignIdentity *msg)
{ {
RESP_INIT(SignedIdentity); RESP_INIT(SignedIdentity);
@ -141,7 +141,7 @@ void fsm_msgSignIdentity(SignIdentity *msg)
layoutHome(); layoutHome();
} }
void fsm_msgGetECDHSessionKey(GetECDHSessionKey *msg) void fsm_msgGetECDHSessionKey(const GetECDHSessionKey *msg)
{ {
RESP_INIT(ECDHSessionKey); RESP_INIT(ECDHSessionKey);
@ -189,98 +189,7 @@ void fsm_msgGetECDHSessionKey(GetECDHSessionKey *msg)
layoutHome(); layoutHome();
} }
/* ECIES disabled void fsm_msgCosiCommit(const CosiCommit *msg)
void fsm_msgEncryptMessage(EncryptMessage *msg)
{
CHECK_INITIALIZED
CHECK_PARAM(msg->has_pubkey, _("No public key provided"));
CHECK_PARAM(msg->has_message, _("No message provided"));
CHECK_PARAM(msg->pubkey.size == 33, _("Invalid public key provided"));
curve_point pubkey;
CHECK_PARAM(ecdsa_read_pubkey(&secp256k1, msg->pubkey.bytes, &pubkey) == 1, _("Invalid public key provided"));
bool display_only = msg->has_display_only && msg->display_only;
bool signing = msg->address_n_count > 0;
RESP_INIT(EncryptedMessage);
const HDNode *node = 0;
uint8_t address_raw[MAX_ADDR_RAW_SIZE];
if (signing) {
const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name);
if (!coin) return;
CHECK_PIN
node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL);
if (!node) return;
hdnode_get_address_raw(node, coin->address_type, address_raw);
}
layoutEncryptMessage(msg->message.bytes, msg->message.size, signing);
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
layoutHome();
return;
}
layoutProgressSwipe(_("Encrypting"), 0);
if (cryptoMessageEncrypt(&pubkey, msg->message.bytes, msg->message.size, display_only, resp->nonce.bytes, &(resp->nonce.size), resp->message.bytes, &(resp->message.size), resp->hmac.bytes, &(resp->hmac.size), signing ? node->private_key : 0, signing ? address_raw : 0) != 0) {
fsm_sendFailure(FailureType_Failure_ProcessError, _("Error encrypting message"));
layoutHome();
return;
}
resp->has_nonce = true;
resp->has_message = true;
resp->has_hmac = true;
msg_write(MessageType_MessageType_EncryptedMessage, resp);
layoutHome();
}
void fsm_msgDecryptMessage(DecryptMessage *msg)
{
CHECK_INITIALIZED
CHECK_PARAM(msg->has_nonce, _("No nonce provided"));
CHECK_PARAM(msg->has_message, _("No message provided"));
CHECK_PARAM(msg->has_hmac, _("No message hmac provided"));
CHECK_PARAM(msg->nonce.size == 33, _("Invalid nonce key provided"));
curve_point nonce_pubkey;
CHECK_PARAM(ecdsa_read_pubkey(&secp256k1, msg->nonce.bytes, &nonce_pubkey) == 1, _("Invalid nonce provided"));
CHECK_PIN
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL);
if (!node) return;
layoutProgressSwipe(_("Decrypting"), 0);
RESP_INIT(DecryptedMessage);
bool display_only = false;
bool signing = false;
uint8_t address_raw[MAX_ADDR_RAW_SIZE];
if (cryptoMessageDecrypt(&nonce_pubkey, msg->message.bytes, msg->message.size, msg->hmac.bytes, msg->hmac.size, node->private_key, resp->message.bytes, &(resp->message.size), &display_only, &signing, address_raw) != 0) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
layoutHome();
return;
}
if (signing) {
base58_encode_check(address_raw, 21, resp->address, sizeof(resp->address));
}
layoutDecryptMessage(resp->message.bytes, resp->message.size, signing ? resp->address : 0);
protectButton(ButtonRequestType_ButtonRequest_Other, true);
if (display_only) {
resp->has_address = false;
resp->has_message = false;
memset(resp->address, 0, sizeof(resp->address));
memset(&(resp->message), 0, sizeof(resp->message));
} else {
resp->has_address = signing;
resp->has_message = true;
}
msg_write(MessageType_MessageType_DecryptedMessage, resp);
layoutHome();
}
*/
void fsm_msgCosiCommit(CosiCommit *msg)
{ {
RESP_INIT(CosiCommitment); RESP_INIT(CosiCommitment);
@ -318,7 +227,7 @@ void fsm_msgCosiCommit(CosiCommit *msg)
layoutHome(); layoutHome();
} }
void fsm_msgCosiSign(CosiSign *msg) void fsm_msgCosiSign(const CosiSign *msg)
{ {
RESP_INIT(CosiSignature); RESP_INIT(CosiSignature);

View File

@ -19,7 +19,7 @@
#if DEBUG_LINK #if DEBUG_LINK
void fsm_msgDebugLinkGetState(DebugLinkGetState *msg) void fsm_msgDebugLinkGetState(const DebugLinkGetState *msg)
{ {
(void)msg; (void)msg;
@ -68,12 +68,12 @@ void fsm_msgDebugLinkGetState(DebugLinkGetState *msg)
msg_debug_write(MessageType_MessageType_DebugLinkState, &resp); msg_debug_write(MessageType_MessageType_DebugLinkState, &resp);
} }
void fsm_msgDebugLinkStop(DebugLinkStop *msg) void fsm_msgDebugLinkStop(const DebugLinkStop *msg)
{ {
(void)msg; (void)msg;
} }
void fsm_msgDebugLinkMemoryRead(DebugLinkMemoryRead *msg) void fsm_msgDebugLinkMemoryRead(const DebugLinkMemoryRead *msg)
{ {
RESP_INIT(DebugLinkMemory); RESP_INIT(DebugLinkMemory);
@ -86,7 +86,7 @@ void fsm_msgDebugLinkMemoryRead(DebugLinkMemoryRead *msg)
msg_debug_write(MessageType_MessageType_DebugLinkMemory, resp); msg_debug_write(MessageType_MessageType_DebugLinkMemory, resp);
} }
void fsm_msgDebugLinkMemoryWrite(DebugLinkMemoryWrite *msg) void fsm_msgDebugLinkMemoryWrite(const DebugLinkMemoryWrite *msg)
{ {
uint32_t length = msg->memory.size; uint32_t length = msg->memory.size;
if (msg->flash) { if (msg->flash) {
@ -106,7 +106,7 @@ void fsm_msgDebugLinkMemoryWrite(DebugLinkMemoryWrite *msg)
} }
} }
void fsm_msgDebugLinkFlashErase(DebugLinkFlashErase *msg) void fsm_msgDebugLinkFlashErase(const DebugLinkFlashErase *msg)
{ {
svc_flash_unlock(); svc_flash_unlock();
svc_flash_erase_sector(msg->sector); svc_flash_erase_sector(msg->sector);

View File

@ -29,12 +29,12 @@ void fsm_msgEthereumSignTx(EthereumSignTx *msg)
ethereum_signing_init(msg, node); ethereum_signing_init(msg, node);
} }
void fsm_msgEthereumTxAck(EthereumTxAck *msg) void fsm_msgEthereumTxAck(const EthereumTxAck *msg)
{ {
ethereum_signing_txack(msg); ethereum_signing_txack(msg);
} }
void fsm_msgEthereumGetAddress(EthereumGetAddress *msg) void fsm_msgEthereumGetAddress(const EthereumGetAddress *msg)
{ {
RESP_INIT(EthereumAddress); RESP_INIT(EthereumAddress);
@ -75,7 +75,7 @@ void fsm_msgEthereumGetAddress(EthereumGetAddress *msg)
layoutHome(); layoutHome();
} }
void fsm_msgEthereumSignMessage(EthereumSignMessage *msg) void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg)
{ {
RESP_INIT(EthereumMessageSignature); RESP_INIT(EthereumMessageSignature);
@ -97,7 +97,7 @@ void fsm_msgEthereumSignMessage(EthereumSignMessage *msg)
layoutHome(); layoutHome();
} }
void fsm_msgEthereumVerifyMessage(EthereumVerifyMessage *msg) void fsm_msgEthereumVerifyMessage(const EthereumVerifyMessage *msg)
{ {
CHECK_PARAM(msg->has_address, _("No address provided")); CHECK_PARAM(msg->has_address, _("No address provided"));
CHECK_PARAM(msg->has_message, _("No message provided")); CHECK_PARAM(msg->has_message, _("No message provided"));

View File

@ -17,7 +17,7 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>. * along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
void fsm_msgLiskGetAddress(LiskGetAddress *msg) void fsm_msgLiskGetAddress(const LiskGetAddress *msg)
{ {
CHECK_INITIALIZED CHECK_INITIALIZED
@ -43,7 +43,7 @@ void fsm_msgLiskGetAddress(LiskGetAddress *msg)
layoutHome(); layoutHome();
} }
void fsm_msgLiskGetPublicKey(LiskGetPublicKey *msg) void fsm_msgLiskGetPublicKey(const LiskGetPublicKey *msg)
{ {
CHECK_INITIALIZED CHECK_INITIALIZED
@ -75,7 +75,7 @@ void fsm_msgLiskGetPublicKey(LiskGetPublicKey *msg)
layoutHome(); layoutHome();
} }
void fsm_msgLiskSignMessage(LiskSignMessage *msg) void fsm_msgLiskSignMessage(const LiskSignMessage *msg)
{ {
CHECK_INITIALIZED CHECK_INITIALIZED
@ -95,7 +95,7 @@ void fsm_msgLiskSignMessage(LiskSignMessage *msg)
layoutHome(); layoutHome();
} }
void fsm_msgLiskVerifyMessage(LiskVerifyMessage *msg) void fsm_msgLiskVerifyMessage(const LiskVerifyMessage *msg)
{ {
if (lisk_verify_message(msg)) { if (lisk_verify_message(msg)) {
char address[MAX_LISK_ADDRESS_SIZE]; char address[MAX_LISK_ADDRESS_SIZE];

View File

@ -17,7 +17,7 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>. * along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
void fsm_msgStellarGetAddress(StellarGetAddress *msg) void fsm_msgStellarGetAddress(const StellarGetAddress *msg)
{ {
RESP_INIT(StellarAddress); RESP_INIT(StellarAddress);
@ -55,49 +55,7 @@ void fsm_msgStellarGetAddress(StellarGetAddress *msg)
layoutHome(); layoutHome();
} }
// void fsm_msgStellarGetPublicKey(StellarGetPublicKey *msg) void fsm_msgStellarSignTx(const StellarSignTx *msg)
// {
// RESP_INIT(StellarPublicKey);
// CHECK_INITIALIZED
// CHECK_PIN
// HDNode *node = stellar_deriveNode(msg->address_n, msg->address_n_count);
// if (!node) {
// fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to derive private key"));
// return;
// }
// if (msg->has_show_display && msg->show_display) {
// char hex[32 * 2 + 1];
// data2hex(node->public_key + 1, 32, hex);
// const char **str_pubkey_rows = split_message((const uint8_t *)hex, 32 * 2, 16);
// layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), _("Share public account ID?"),
// str_pubkey_rows[0],
// str_pubkey_rows[1],
// str_pubkey_rows[2],
// str_pubkey_rows[3],
// NULL, NULL
// );
// if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
// fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
// layoutHome();
// return;
// }
// }
// // Read public key and write it to the response
// resp->has_public_key = true;
// resp->public_key.size = 32;
// memcpy(resp->public_key.bytes, node->public_key + 1, 32);
// msg_write(MessageType_MessageType_StellarPublicKey, resp);
// layoutHome();
// }
void fsm_msgStellarSignTx(StellarSignTx *msg)
{ {
CHECK_INITIALIZED CHECK_INITIALIZED
CHECK_PIN CHECK_PIN
@ -113,7 +71,7 @@ void fsm_msgStellarSignTx(StellarSignTx *msg)
msg_write(MessageType_MessageType_StellarTxOpRequest, resp); msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
} }
void fsm_msgStellarCreateAccountOp(StellarCreateAccountOp *msg) void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg)
{ {
if (!stellar_confirmCreateAccountOp(msg)) return; if (!stellar_confirmCreateAccountOp(msg)) return;
@ -132,7 +90,7 @@ void fsm_msgStellarCreateAccountOp(StellarCreateAccountOp *msg)
} }
} }
void fsm_msgStellarPaymentOp(StellarPaymentOp *msg) void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg)
{ {
// This will display additional dialogs to the user // This will display additional dialogs to the user
if (!stellar_confirmPaymentOp(msg)) return; if (!stellar_confirmPaymentOp(msg)) return;
@ -153,7 +111,7 @@ void fsm_msgStellarPaymentOp(StellarPaymentOp *msg)
} }
} }
void fsm_msgStellarPathPaymentOp(StellarPathPaymentOp *msg) void fsm_msgStellarPathPaymentOp(const StellarPathPaymentOp *msg)
{ {
if (!stellar_confirmPathPaymentOp(msg)) return; if (!stellar_confirmPathPaymentOp(msg)) return;
@ -172,7 +130,7 @@ void fsm_msgStellarPathPaymentOp(StellarPathPaymentOp *msg)
} }
} }
void fsm_msgStellarManageOfferOp(StellarManageOfferOp *msg) void fsm_msgStellarManageOfferOp(const StellarManageOfferOp *msg)
{ {
if (!stellar_confirmManageOfferOp(msg)) return; if (!stellar_confirmManageOfferOp(msg)) return;
@ -191,7 +149,7 @@ void fsm_msgStellarManageOfferOp(StellarManageOfferOp *msg)
} }
} }
void fsm_msgStellarCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg) void fsm_msgStellarCreatePassiveOfferOp(const StellarCreatePassiveOfferOp *msg)
{ {
if (!stellar_confirmCreatePassiveOfferOp(msg)) return; if (!stellar_confirmCreatePassiveOfferOp(msg)) return;
@ -210,7 +168,7 @@ void fsm_msgStellarCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg)
} }
} }
void fsm_msgStellarSetOptionsOp(StellarSetOptionsOp *msg) void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg)
{ {
if (!stellar_confirmSetOptionsOp(msg)) return; if (!stellar_confirmSetOptionsOp(msg)) return;
@ -229,7 +187,7 @@ void fsm_msgStellarSetOptionsOp(StellarSetOptionsOp *msg)
} }
} }
void fsm_msgStellarChangeTrustOp(StellarChangeTrustOp *msg) void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg)
{ {
if (!stellar_confirmChangeTrustOp(msg)) return; if (!stellar_confirmChangeTrustOp(msg)) return;
@ -248,7 +206,7 @@ void fsm_msgStellarChangeTrustOp(StellarChangeTrustOp *msg)
} }
} }
void fsm_msgStellarAllowTrustOp(StellarAllowTrustOp *msg) void fsm_msgStellarAllowTrustOp(const StellarAllowTrustOp *msg)
{ {
if (!stellar_confirmAllowTrustOp(msg)) return; if (!stellar_confirmAllowTrustOp(msg)) return;
@ -267,7 +225,7 @@ void fsm_msgStellarAllowTrustOp(StellarAllowTrustOp *msg)
} }
} }
void fsm_msgStellarAccountMergeOp(StellarAccountMergeOp *msg) void fsm_msgStellarAccountMergeOp(const StellarAccountMergeOp *msg)
{ {
if (!stellar_confirmAccountMergeOp(msg)) return; if (!stellar_confirmAccountMergeOp(msg)) return;
@ -286,7 +244,7 @@ void fsm_msgStellarAccountMergeOp(StellarAccountMergeOp *msg)
} }
} }
void fsm_msgStellarManageDataOp(StellarManageDataOp *msg) void fsm_msgStellarManageDataOp(const StellarManageDataOp *msg)
{ {
if (!stellar_confirmManageDataOp(msg)) return; if (!stellar_confirmManageDataOp(msg)) return;
@ -305,7 +263,7 @@ void fsm_msgStellarManageDataOp(StellarManageDataOp *msg)
} }
} }
void fsm_msgStellarBumpSequenceOp(StellarBumpSequenceOp *msg) void fsm_msgStellarBumpSequenceOp(const StellarBumpSequenceOp *msg)
{ {
if (!stellar_confirmBumpSequenceOp(msg)) return; if (!stellar_confirmBumpSequenceOp(msg)) return;

View File

@ -46,7 +46,7 @@ void lisk_message_hash(const uint8_t *message, size_t message_len, uint8_t hash[
sha256_Raw(hash, 32, hash); sha256_Raw(hash, 32, hash);
} }
void lisk_sign_message(const HDNode *node, LiskSignMessage *msg, LiskMessageSignature *resp) void lisk_sign_message(const HDNode *node, const LiskSignMessage *msg, LiskMessageSignature *resp)
{ {
layoutSignMessage(msg->message.bytes, msg->message.size); layoutSignMessage(msg->message.bytes, msg->message.size);
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
@ -72,7 +72,7 @@ void lisk_sign_message(const HDNode *node, LiskSignMessage *msg, LiskMessageSign
resp->public_key.size = 32; resp->public_key.size = 32;
} }
bool lisk_verify_message(LiskVerifyMessage *msg) bool lisk_verify_message(const LiskVerifyMessage *msg)
{ {
uint8_t hash[32]; uint8_t hash[32];
lisk_message_hash(msg->message.bytes, msg->message.size, hash); lisk_message_hash(msg->message.bytes, msg->message.size, hash);

View File

@ -26,8 +26,8 @@
#define MAX_LISK_ADDRESS_SIZE 23 #define MAX_LISK_ADDRESS_SIZE 23
void lisk_sign_message(const HDNode *node, LiskSignMessage *msg, LiskMessageSignature *resp); void lisk_sign_message(const HDNode *node, const LiskSignMessage *msg, LiskMessageSignature *resp);
bool lisk_verify_message(LiskVerifyMessage *msg); bool lisk_verify_message(const LiskVerifyMessage *msg);
void lisk_sign_tx(const HDNode *node, LiskSignTx *msg, LiskSignedTx *resp); void lisk_sign_tx(const HDNode *node, LiskSignTx *msg, LiskSignedTx *resp);
// Helpers // Helpers

View File

@ -544,7 +544,7 @@ void signing_init(const SignTx *msg, const CoinInfo *_coin, const HDNode *_root)
#define MIN(a,b) (((a)<(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b))
static bool signing_check_input(TxInputType *txinput) { static bool signing_check_input(const TxInputType *txinput) {
/* compute multisig fingerprint */ /* compute multisig fingerprint */
/* (if all input share the same fingerprint, outputs having the same fingerprint will be considered as change outputs) */ /* (if all input share the same fingerprint, outputs having the same fingerprint will be considered as change outputs) */
if (txinput->has_multisig && !multisig_fp_mismatch) { if (txinput->has_multisig && !multisig_fp_mismatch) {

View File

@ -52,7 +52,7 @@ static StellarTransaction stellar_activeTx;
/* /*
* Starts the signing process and parses the transaction header * Starts the signing process and parses the transaction header
*/ */
void stellar_signingInit(StellarSignTx *msg) void stellar_signingInit(const StellarSignTx *msg)
{ {
memset(&stellar_activeTx, 0, sizeof(StellarTransaction)); memset(&stellar_activeTx, 0, sizeof(StellarTransaction));
stellar_signing = true; stellar_signing = true;
@ -155,7 +155,7 @@ void stellar_signingInit(StellarSignTx *msg)
} }
} }
bool stellar_confirmSourceAccount(bool has_source_account, char *str_account) bool stellar_confirmSourceAccount(bool has_source_account, const char *str_account)
{ {
if (!has_source_account) { if (!has_source_account) {
stellar_hashupdate_bool(false); stellar_hashupdate_bool(false);
@ -188,7 +188,7 @@ bool stellar_confirmSourceAccount(bool has_source_account, char *str_account)
return true; return true;
} }
bool stellar_confirmCreateAccountOp(StellarCreateAccountOp *msg) bool stellar_confirmCreateAccountOp(const StellarCreateAccountOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -239,7 +239,7 @@ bool stellar_confirmCreateAccountOp(StellarCreateAccountOp *msg)
return true; return true;
} }
bool stellar_confirmPaymentOp(StellarPaymentOp *msg) bool stellar_confirmPaymentOp(const StellarPaymentOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -300,7 +300,7 @@ bool stellar_confirmPaymentOp(StellarPaymentOp *msg)
return true; return true;
} }
bool stellar_confirmPathPaymentOp(StellarPathPaymentOp *msg) bool stellar_confirmPathPaymentOp(const StellarPathPaymentOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -400,7 +400,7 @@ bool stellar_confirmPathPaymentOp(StellarPathPaymentOp *msg)
return true; return true;
} }
bool stellar_confirmManageOfferOp(StellarManageOfferOp *msg) bool stellar_confirmManageOfferOp(const StellarManageOfferOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -490,7 +490,7 @@ bool stellar_confirmManageOfferOp(StellarManageOfferOp *msg)
return true; return true;
} }
bool stellar_confirmCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg) bool stellar_confirmCreatePassiveOfferOp(const StellarCreatePassiveOfferOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -568,7 +568,7 @@ bool stellar_confirmCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg)
return true; return true;
} }
bool stellar_confirmSetOptionsOp(StellarSetOptionsOp *msg) bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -892,7 +892,7 @@ bool stellar_confirmSetOptionsOp(StellarSetOptionsOp *msg)
return true; return true;
} }
bool stellar_confirmChangeTrustOp(StellarChangeTrustOp *msg) bool stellar_confirmChangeTrustOp(const StellarChangeTrustOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -960,7 +960,7 @@ bool stellar_confirmChangeTrustOp(StellarChangeTrustOp *msg)
return true; return true;
} }
bool stellar_confirmAllowTrustOp(StellarAllowTrustOp *msg) bool stellar_confirmAllowTrustOp(const StellarAllowTrustOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -1036,7 +1036,7 @@ bool stellar_confirmAllowTrustOp(StellarAllowTrustOp *msg)
return true; return true;
} }
bool stellar_confirmAccountMergeOp(StellarAccountMergeOp *msg) bool stellar_confirmAccountMergeOp(const StellarAccountMergeOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -1077,7 +1077,7 @@ bool stellar_confirmAccountMergeOp(StellarAccountMergeOp *msg)
return true; return true;
} }
bool stellar_confirmManageDataOp(StellarManageDataOp *msg) bool stellar_confirmManageDataOp(const StellarManageDataOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -1151,7 +1151,7 @@ bool stellar_confirmManageDataOp(StellarManageDataOp *msg)
return true; return true;
} }
bool stellar_confirmBumpSequenceOp(StellarBumpSequenceOp *msg) bool stellar_confirmBumpSequenceOp(const StellarBumpSequenceOp *msg)
{ {
if (!stellar_signing) return false; if (!stellar_signing) return false;
@ -1312,7 +1312,7 @@ void stellar_format_uint64(uint64_t number, char *out, size_t outlen)
* Breaks a 56 character address into 3 lines of lengths 16, 20, 20 * Breaks a 56 character address into 3 lines of lengths 16, 20, 20
* This is to allow a small label to be prepended to the first line * This is to allow a small label to be prepended to the first line
*/ */
const char **stellar_lineBreakAddress(uint8_t *addrbytes) const char **stellar_lineBreakAddress(const uint8_t *addrbytes)
{ {
char str_fulladdr[56+1]; char str_fulladdr[56+1];
static char rows[3][20+1]; static char rows[3][20+1];
@ -1339,7 +1339,7 @@ const char **stellar_lineBreakAddress(uint8_t *addrbytes)
* MOBI (G123456789000) * MOBI (G123456789000)
* ALPHA12EXAMP (G0987) * ALPHA12EXAMP (G0987)
*/ */
void stellar_format_asset(StellarAssetType *asset, char *str_formatted, size_t len) void stellar_format_asset(const StellarAssetType *asset, char *str_formatted, size_t len)
{ {
char str_asset_code[12 + 1]; char str_asset_code[12 + 1];
// truncated asset issuer, final length depends on length of asset code // truncated asset issuer, final length depends on length of asset code
@ -1383,7 +1383,7 @@ void stellar_format_asset(StellarAssetType *asset, char *str_formatted, size_t l
} }
} }
size_t stellar_publicAddressAsStr(uint8_t *bytes, char *out, size_t outlen) size_t stellar_publicAddressAsStr(const uint8_t *bytes, char *out, size_t outlen)
{ {
// version + key bytes + checksum // version + key bytes + checksum
uint8_t keylen = 1 + 32 + 2; uint8_t keylen = 1 + 32 + 2;
@ -1446,7 +1446,7 @@ bool stellar_validateAddress(const char *str_address)
/** /**
* Converts a string address (G...) to the 32-byte raw address * Converts a string address (G...) to the 32-byte raw address
*/ */
bool stellar_getAddressBytes(char* str_address, uint8_t *out_bytes) bool stellar_getAddressBytes(const char* str_address, uint8_t *out_bytes)
{ {
uint8_t decoded[STELLAR_ADDRESS_SIZE_RAW]; uint8_t decoded[STELLAR_ADDRESS_SIZE_RAW];
@ -1497,7 +1497,7 @@ uint16_t stellar_crc16(uint8_t *bytes, uint32_t length)
* *
* All paths must be hardened * All paths must be hardened
*/ */
HDNode *stellar_deriveNode(uint32_t *address_n, size_t address_n_count) HDNode *stellar_deriveNode(const uint32_t *address_n, size_t address_n_count)
{ {
static CONFIDENTIAL HDNode node; static CONFIDENTIAL HDNode node;
const char *curve = "ed25519"; const char *curve = "ed25519";
@ -1597,7 +1597,7 @@ void stellar_hashupdate_address(uint8_t *address_bytes)
* so if "TEST" is the asset code then the hashed value needs to be 4 bytes and not include the null * so if "TEST" is the asset code then the hashed value needs to be 4 bytes and not include the null
* at the end of the string * at the end of the string
*/ */
void stellar_hashupdate_asset(StellarAssetType *asset) void stellar_hashupdate_asset(const StellarAssetType *asset)
{ {
stellar_hashupdate_uint32(asset->type); stellar_hashupdate_uint32(asset->type);
@ -1629,7 +1629,7 @@ void stellar_hashupdate_asset(StellarAssetType *asset)
} }
} }
void stellar_hashupdate_bytes(uint8_t *data, size_t len) void stellar_hashupdate_bytes(const uint8_t *data, size_t len)
{ {
sha256_Update(&(stellar_activeTx.sha256_ctx), data, len); sha256_Update(&(stellar_activeTx.sha256_ctx), data, len);
} }
@ -1637,7 +1637,7 @@ void stellar_hashupdate_bytes(uint8_t *data, size_t len)
/* /*
* Displays a summary of the overall transaction * Displays a summary of the overall transaction
*/ */
void stellar_layoutTransactionSummary(StellarSignTx *msg) void stellar_layoutTransactionSummary(const StellarSignTx *msg)
{ {
char str_lines[5][32]; char str_lines[5][32];
memset(str_lines, 0, sizeof(str_lines)); memset(str_lines, 0, sizeof(str_lines));

View File

@ -53,39 +53,39 @@ typedef struct {
} StellarTransaction; } StellarTransaction;
// Signing process // Signing process
void stellar_signingInit(StellarSignTx *tx); void stellar_signingInit(const StellarSignTx *tx);
void stellar_signingAbort(const char *reason); void stellar_signingAbort(const char *reason);
bool stellar_confirmSourceAccount(bool has_source_account, char *str_account); bool stellar_confirmSourceAccount(bool has_source_account, const char *str_account);
bool stellar_confirmCreateAccountOp(StellarCreateAccountOp *msg); bool stellar_confirmCreateAccountOp(const StellarCreateAccountOp *msg);
bool stellar_confirmPaymentOp(StellarPaymentOp *msg); bool stellar_confirmPaymentOp(const StellarPaymentOp *msg);
bool stellar_confirmPathPaymentOp(StellarPathPaymentOp *msg); bool stellar_confirmPathPaymentOp(const StellarPathPaymentOp *msg);
bool stellar_confirmManageOfferOp(StellarManageOfferOp *msg); bool stellar_confirmManageOfferOp(const StellarManageOfferOp *msg);
bool stellar_confirmCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg); bool stellar_confirmCreatePassiveOfferOp(const StellarCreatePassiveOfferOp *msg);
bool stellar_confirmSetOptionsOp(StellarSetOptionsOp *msg); bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg);
bool stellar_confirmChangeTrustOp(StellarChangeTrustOp *msg); bool stellar_confirmChangeTrustOp(const StellarChangeTrustOp *msg);
bool stellar_confirmAllowTrustOp(StellarAllowTrustOp *msg); bool stellar_confirmAllowTrustOp(const StellarAllowTrustOp *msg);
bool stellar_confirmAccountMergeOp(StellarAccountMergeOp *msg); bool stellar_confirmAccountMergeOp(const StellarAccountMergeOp *msg);
bool stellar_confirmManageDataOp(StellarManageDataOp *msg); bool stellar_confirmManageDataOp(const StellarManageDataOp *msg);
bool stellar_confirmBumpSequenceOp(StellarBumpSequenceOp *msg); bool stellar_confirmBumpSequenceOp(const StellarBumpSequenceOp *msg);
// Layout // Layout
void stellar_layoutTransactionDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5); void stellar_layoutTransactionDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5);
void stellar_layoutTransactionSummary(StellarSignTx *msg); void stellar_layoutTransactionSummary(const StellarSignTx *msg);
void stellar_layoutSigningDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, uint32_t *address_n, size_t address_n_count, const char *warning, bool is_final_step); void stellar_layoutSigningDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, uint32_t *address_n, size_t address_n_count, const char *warning, bool is_final_step);
// Helpers // Helpers
HDNode *stellar_deriveNode(uint32_t *address_n, size_t address_n_count); HDNode *stellar_deriveNode(const uint32_t *address_n, size_t address_n_count);
size_t stellar_publicAddressAsStr(uint8_t *bytes, char *out, size_t outlen); size_t stellar_publicAddressAsStr(const uint8_t *bytes, char *out, size_t outlen);
const char **stellar_lineBreakAddress(uint8_t *addrbytes); const char **stellar_lineBreakAddress(const uint8_t *addrbytes);
void stellar_hashupdate_uint32(uint32_t value); void stellar_hashupdate_uint32(uint32_t value);
void stellar_hashupdate_uint64(uint64_t value); void stellar_hashupdate_uint64(uint64_t value);
void stellar_hashupdate_bool(bool value); void stellar_hashupdate_bool(bool value);
void stellar_hashupdate_string(uint8_t *data, size_t len); void stellar_hashupdate_string(uint8_t *data, size_t len);
void stellar_hashupdate_address(uint8_t *address_bytes); void stellar_hashupdate_address(uint8_t *address_bytes);
void stellar_hashupdate_asset(StellarAssetType *asset); void stellar_hashupdate_asset(const StellarAssetType *asset);
void stellar_hashupdate_bytes(uint8_t *data, size_t len); void stellar_hashupdate_bytes(const uint8_t *data, size_t len);
void stellar_fillSignedTx(StellarSignedTx *resp); void stellar_fillSignedTx(StellarSignedTx *resp);
bool stellar_allOperationsConfirmed(void); bool stellar_allOperationsConfirmed(void);
@ -94,11 +94,11 @@ void stellar_getSignatureForActiveTx(uint8_t *out_signature);
void stellar_format_uint32(uint32_t number, char *out, size_t outlen); void stellar_format_uint32(uint32_t number, char *out, size_t outlen);
void stellar_format_uint64(uint64_t number, char *out, size_t outlen); void stellar_format_uint64(uint64_t number, char *out, size_t outlen);
void stellar_format_stroops(uint64_t number, char *out, size_t outlen); void stellar_format_stroops(uint64_t number, char *out, size_t outlen);
void stellar_format_asset(StellarAssetType *asset, char *str_formatted, size_t len); void stellar_format_asset(const StellarAssetType *asset, char *str_formatted, size_t len);
void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out, size_t outlen); void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out, size_t outlen);
bool stellar_validateAddress(const char *str_address); bool stellar_validateAddress(const char *str_address);
bool stellar_getAddressBytes(char* str_address, uint8_t *out_bytes); bool stellar_getAddressBytes(const char* str_address, uint8_t *out_bytes);
uint16_t stellar_crc16(uint8_t *bytes, uint32_t length); uint16_t stellar_crc16(uint8_t *bytes, uint32_t length);
#endif #endif

View File

@ -422,7 +422,7 @@ void storage_dumpNode(HDNodeType *node) {
} }
#endif #endif
void storage_loadDevice(LoadDevice *msg) void storage_loadDevice(const LoadDevice *msg)
{ {
session_clear(true); session_clear(true);

View File

@ -83,7 +83,7 @@ void storage_clear_update(void);
void storage_update(void); void storage_update(void);
void session_clear(bool clear_pin); void session_clear(bool clear_pin);
void storage_loadDevice(LoadDevice *msg); void storage_loadDevice(const LoadDevice *msg);
const uint8_t *storage_getSeed(bool usePassphrase); const uint8_t *storage_getSeed(bool usePassphrase);