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,28 +146,33 @@ 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) {
|
||||||
switch (script_type) {
|
uint8_t script_type_info = 0;
|
||||||
case InputScriptType_SPENDP2SHWITNESS:
|
if (!no_script_type) {
|
||||||
// segwit-in-p2sh
|
switch (script_type) {
|
||||||
signature[0] = 35 + pby;
|
case InputScriptType_SPENDP2SHWITNESS:
|
||||||
break;
|
// segwit-in-p2sh
|
||||||
case InputScriptType_SPENDWITNESS:
|
script_type_info = 4;
|
||||||
// segwit
|
break;
|
||||||
signature[0] = 39 + pby;
|
case InputScriptType_SPENDWITNESS:
|
||||||
break;
|
// segwit
|
||||||
default:
|
script_type_info = 8;
|
||||||
// p2pkh
|
break;
|
||||||
signature[0] = 31 + pby;
|
default:
|
||||||
break;
|
// p2pkh
|
||||||
|
script_type_info = 0;
|
||||||
|
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