mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 12:28:09 +00:00
feat(legacy): Support no_script_type option in SignMessage.
This commit is contained in:
parent
bc4a56b2c0
commit
4146ab7f9e
1
legacy/firmware/.changelog.d/1586.added
Normal file
1
legacy/firmware/.changelog.d/1586.added
Normal file
@ -0,0 +1 @@
|
|||||||
|
Support no_script_type option in SignMessage.
|
@ -146,29 +146,34 @@ static void cryptoMessageHash(const CoinInfo *coin, const uint8_t *message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int cryptoMessageSign(const CoinInfo *coin, HDNode *node,
|
int cryptoMessageSign(const CoinInfo *coin, HDNode *node,
|
||||||
InputScriptType script_type, const uint8_t *message,
|
InputScriptType script_type, bool no_script_type,
|
||||||
size_t message_len, uint8_t *signature) {
|
const uint8_t *message, size_t message_len,
|
||||||
|
uint8_t *signature) {
|
||||||
uint8_t hash[HASHER_DIGEST_LENGTH] = {0};
|
uint8_t hash[HASHER_DIGEST_LENGTH] = {0};
|
||||||
cryptoMessageHash(coin, message, message_len, hash);
|
cryptoMessageHash(coin, message, message_len, hash);
|
||||||
|
|
||||||
uint8_t pby = 0;
|
uint8_t pby = 0;
|
||||||
int result = hdnode_sign_digest(node, hash, signature + 1, &pby, NULL);
|
int result = hdnode_sign_digest(node, hash, signature + 1, &pby, NULL);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
|
uint8_t script_type_info = 0;
|
||||||
|
if (!no_script_type) {
|
||||||
switch (script_type) {
|
switch (script_type) {
|
||||||
case InputScriptType_SPENDP2SHWITNESS:
|
case InputScriptType_SPENDP2SHWITNESS:
|
||||||
// segwit-in-p2sh
|
// segwit-in-p2sh
|
||||||
signature[0] = 35 + pby;
|
script_type_info = 4;
|
||||||
break;
|
break;
|
||||||
case InputScriptType_SPENDWITNESS:
|
case InputScriptType_SPENDWITNESS:
|
||||||
// segwit
|
// segwit
|
||||||
signature[0] = 39 + pby;
|
script_type_info = 8;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// p2pkh
|
// p2pkh
|
||||||
signature[0] = 31 + pby;
|
script_type_info = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
signature[0] = 31 + pby + script_type_info;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,9 @@ int signifyMessageSign(HDNode *node, const uint8_t *message, size_t message_len,
|
|||||||
uint8_t *signature);
|
uint8_t *signature);
|
||||||
|
|
||||||
int cryptoMessageSign(const CoinInfo *coin, HDNode *node,
|
int cryptoMessageSign(const CoinInfo *coin, HDNode *node,
|
||||||
InputScriptType script_type, const uint8_t *message,
|
InputScriptType script_type, bool no_script_type,
|
||||||
size_t message_len, uint8_t *signature);
|
const uint8_t *message, size_t message_len,
|
||||||
|
uint8_t *signature);
|
||||||
|
|
||||||
int cryptoMessageVerify(const CoinInfo *coin, const uint8_t *message,
|
int cryptoMessageVerify(const CoinInfo *coin, const uint8_t *message,
|
||||||
size_t message_len, const char *address,
|
size_t message_len, const char *address,
|
||||||
|
@ -272,8 +272,9 @@ void fsm_msgSignMessage(const SignMessage *msg) {
|
|||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
layoutProgressSwipe(_("Signing"), 0);
|
layoutProgressSwipe(_("Signing"), 0);
|
||||||
if (cryptoMessageSign(coin, node, msg->script_type, msg->message.bytes,
|
if (cryptoMessageSign(coin, node, msg->script_type, msg->no_script_type,
|
||||||
msg->message.size, resp->signature.bytes) == 0) {
|
msg->message.bytes, msg->message.size,
|
||||||
|
resp->signature.bytes) == 0) {
|
||||||
if (hdnode_fill_public_key(node) != 0) {
|
if (hdnode_fill_public_key(node) != 0) {
|
||||||
fsm_sendFailure(FailureType_Failure_ProcessError,
|
fsm_sendFailure(FailureType_Failure_ProcessError,
|
||||||
_("Failed to derive public key"));
|
_("Failed to derive public key"));
|
||||||
|
@ -135,7 +135,7 @@ void fsm_msgSignIdentity(const SignIdentity *msg) {
|
|||||||
sha256_Raw((const uint8_t *)msg->challenge_visual,
|
sha256_Raw((const uint8_t *)msg->challenge_visual,
|
||||||
strlen(msg->challenge_visual), digest + 32);
|
strlen(msg->challenge_visual), digest + 32);
|
||||||
result = cryptoMessageSign(&(coins[0]), node, InputScriptType_SPENDADDRESS,
|
result = cryptoMessageSign(&(coins[0]), node, InputScriptType_SPENDADDRESS,
|
||||||
digest, 64, resp->signature.bytes);
|
false, digest, 64, resp->signature.bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user