1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

feat(legacy): Support no_script_type option in SignMessage.

This commit is contained in:
Andrew Kozlik 2021-11-05 18:01:46 +01:00 committed by Andrew Kozlik
parent bc4a56b2c0
commit 4146ab7f9e
5 changed files with 28 additions and 20 deletions

View File

@ -0,0 +1 @@
Support no_script_type option in SignMessage.

View File

@ -146,28 +146,33 @@ static void cryptoMessageHash(const CoinInfo *coin, const uint8_t *message,
}
int cryptoMessageSign(const CoinInfo *coin, HDNode *node,
InputScriptType script_type, const uint8_t *message,
size_t message_len, uint8_t *signature) {
InputScriptType script_type, bool no_script_type,
const uint8_t *message, size_t message_len,
uint8_t *signature) {
uint8_t hash[HASHER_DIGEST_LENGTH] = {0};
cryptoMessageHash(coin, message, message_len, hash);
uint8_t pby = 0;
int result = hdnode_sign_digest(node, hash, signature + 1, &pby, NULL);
if (result == 0) {
switch (script_type) {
case InputScriptType_SPENDP2SHWITNESS:
// segwit-in-p2sh
signature[0] = 35 + pby;
break;
case InputScriptType_SPENDWITNESS:
// segwit
signature[0] = 39 + pby;
break;
default:
// p2pkh
signature[0] = 31 + pby;
break;
uint8_t script_type_info = 0;
if (!no_script_type) {
switch (script_type) {
case InputScriptType_SPENDP2SHWITNESS:
// segwit-in-p2sh
script_type_info = 4;
break;
case InputScriptType_SPENDWITNESS:
// segwit
script_type_info = 8;
break;
default:
// p2pkh
script_type_info = 0;
break;
}
}
signature[0] = 31 + pby + script_type_info;
}
return result;
}

View File

@ -54,8 +54,9 @@ int signifyMessageSign(HDNode *node, const uint8_t *message, size_t message_len,
uint8_t *signature);
int cryptoMessageSign(const CoinInfo *coin, HDNode *node,
InputScriptType script_type, const uint8_t *message,
size_t message_len, uint8_t *signature);
InputScriptType script_type, bool no_script_type,
const uint8_t *message, size_t message_len,
uint8_t *signature);
int cryptoMessageVerify(const CoinInfo *coin, const uint8_t *message,
size_t message_len, const char *address,

View File

@ -272,8 +272,9 @@ void fsm_msgSignMessage(const SignMessage *msg) {
if (!node) return;
layoutProgressSwipe(_("Signing"), 0);
if (cryptoMessageSign(coin, node, msg->script_type, msg->message.bytes,
msg->message.size, resp->signature.bytes) == 0) {
if (cryptoMessageSign(coin, node, msg->script_type, msg->no_script_type,
msg->message.bytes, msg->message.size,
resp->signature.bytes) == 0) {
if (hdnode_fill_public_key(node) != 0) {
fsm_sendFailure(FailureType_Failure_ProcessError,
_("Failed to derive public key"));

View File

@ -135,7 +135,7 @@ void fsm_msgSignIdentity(const SignIdentity *msg) {
sha256_Raw((const uint8_t *)msg->challenge_visual,
strlen(msg->challenge_visual), digest + 32);
result = cryptoMessageSign(&(coins[0]), node, InputScriptType_SPENDADDRESS,
digest, 64, resp->signature.bytes);
false, digest, 64, resp->signature.bytes);
}
if (result == 0) {