mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-22 13:21:03 +00:00
start implementing EncryptMessage/DecryptMessage
This commit is contained in:
parent
5765fccc0d
commit
8f1c40a933
@ -554,6 +554,61 @@ void fsm_msgVerifyMessage(VerifyMessage *msg)
|
|||||||
layoutHome();
|
layoutHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fsm_msgEncryptMessage(EncryptMessage *msg)
|
||||||
|
{
|
||||||
|
if (!msg->has_pubkey) {
|
||||||
|
fsm_sendFailure(FailureType_Failure_SyntaxError, "No public key provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!msg->has_message) {
|
||||||
|
fsm_sendFailure(FailureType_Failure_SyntaxError, "No message provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
curve_point pubkey;
|
||||||
|
if ((msg->pubkey.size != 33 && msg->pubkey.size != 65) || ecdsa_read_pubkey(msg->pubkey.bytes, &pubkey) == 0) {
|
||||||
|
fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid public key provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg->address_n_count) {
|
||||||
|
if (!protectPin(true)) {
|
||||||
|
layoutHome();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HDNode *node = fsm_getRootNode();
|
||||||
|
if (!node) return;
|
||||||
|
fsm_deriveKey(node, msg->address_n, msg->address_n_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
layoutHome();
|
||||||
|
}
|
||||||
|
|
||||||
|
void fsm_msgDecryptMessage(DecryptMessage *msg)
|
||||||
|
{
|
||||||
|
if (!msg->has_message) {
|
||||||
|
fsm_sendFailure(FailureType_Failure_SyntaxError, "No message provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (msg->message.size % 16) {
|
||||||
|
fsm_sendFailure(FailureType_Failure_SyntaxError, "Message length must be a multiple of 16");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!protectPin(true)) {
|
||||||
|
layoutHome();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HDNode *node = fsm_getRootNode();
|
||||||
|
if (!node) return;
|
||||||
|
fsm_deriveKey(node, msg->address_n, msg->address_n_count);
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
layoutHome();
|
||||||
|
}
|
||||||
|
|
||||||
void fsm_msgEstimateTxSize(EstimateTxSize *msg)
|
void fsm_msgEstimateTxSize(EstimateTxSize *msg)
|
||||||
{
|
{
|
||||||
RESP_INIT(TxSize);
|
RESP_INIT(TxSize);
|
||||||
|
@ -49,6 +49,8 @@ void fsm_msgGetAddress(GetAddress *msg);
|
|||||||
void fsm_msgEntropyAck(EntropyAck *msg);
|
void fsm_msgEntropyAck(EntropyAck *msg);
|
||||||
void fsm_msgSignMessage(SignMessage *msg);
|
void fsm_msgSignMessage(SignMessage *msg);
|
||||||
void fsm_msgVerifyMessage(VerifyMessage *msg);
|
void fsm_msgVerifyMessage(VerifyMessage *msg);
|
||||||
|
void fsm_msgEncryptMessage(EncryptMessage *msg);
|
||||||
|
void fsm_msgDecryptMessage(DecryptMessage *msg);
|
||||||
//void fsm_msgPassphraseAck(PassphraseAck *msg);
|
//void fsm_msgPassphraseAck(PassphraseAck *msg);
|
||||||
void fsm_msgEstimateTxSize(EstimateTxSize *msg);
|
void fsm_msgEstimateTxSize(EstimateTxSize *msg);
|
||||||
void fsm_msgRecoveryDevice(RecoveryDevice *msg);
|
void fsm_msgRecoveryDevice(RecoveryDevice *msg);
|
||||||
|
@ -61,6 +61,8 @@ static const struct MessagesMap_t MessagesMap[] = {
|
|||||||
{'n', 'i', MessageType_MessageType_EntropyAck, EntropyAck_fields, (void (*)(void *))fsm_msgEntropyAck},
|
{'n', 'i', MessageType_MessageType_EntropyAck, EntropyAck_fields, (void (*)(void *))fsm_msgEntropyAck},
|
||||||
{'n', 'i', MessageType_MessageType_SignMessage, SignMessage_fields, (void (*)(void *))fsm_msgSignMessage},
|
{'n', 'i', MessageType_MessageType_SignMessage, SignMessage_fields, (void (*)(void *))fsm_msgSignMessage},
|
||||||
{'n', 'i', MessageType_MessageType_VerifyMessage, VerifyMessage_fields, (void (*)(void *))fsm_msgVerifyMessage},
|
{'n', 'i', MessageType_MessageType_VerifyMessage, VerifyMessage_fields, (void (*)(void *))fsm_msgVerifyMessage},
|
||||||
|
{'n', 'i', MessageType_MessageType_EncryptMessage, EncryptMessage_fields, (void (*)(void *))fsm_msgEncryptMessage},
|
||||||
|
{'n', 'i', MessageType_MessageType_DecryptMessage, DecryptMessage_fields, (void (*)(void *))fsm_msgDecryptMessage},
|
||||||
// {'n', 'i', MessageType_MessageType_PassphraseAck, PassphraseAck_fields, (void (*)(void *))fsm_msgPassphraseAck},
|
// {'n', 'i', MessageType_MessageType_PassphraseAck, PassphraseAck_fields, (void (*)(void *))fsm_msgPassphraseAck},
|
||||||
{'n', 'i', MessageType_MessageType_EstimateTxSize, EstimateTxSize_fields, (void (*)(void *))fsm_msgEstimateTxSize},
|
{'n', 'i', MessageType_MessageType_EstimateTxSize, EstimateTxSize_fields, (void (*)(void *))fsm_msgEstimateTxSize},
|
||||||
{'n', 'i', MessageType_MessageType_RecoveryDevice, RecoveryDevice_fields, (void (*)(void *))fsm_msgRecoveryDevice},
|
{'n', 'i', MessageType_MessageType_RecoveryDevice, RecoveryDevice_fields, (void (*)(void *))fsm_msgRecoveryDevice},
|
||||||
|
@ -59,6 +59,13 @@ VerifyMessage.message max_size:256
|
|||||||
MessageSignature.address max_size:35
|
MessageSignature.address max_size:35
|
||||||
MessageSignature.signature max_size:65
|
MessageSignature.signature max_size:65
|
||||||
|
|
||||||
|
EncryptMessage.pubkey max_size:65
|
||||||
|
EncryptMessage.message max_size:1024
|
||||||
|
EncryptMessage.address_n max_count:8
|
||||||
|
|
||||||
|
DecryptMessage.address_n max_count:8
|
||||||
|
DecryptMessage.message max_size:1024
|
||||||
|
|
||||||
CipherKeyValue.address_n max_count:8
|
CipherKeyValue.address_n max_count:8
|
||||||
CipherKeyValue.key max_size:256
|
CipherKeyValue.key max_size:256
|
||||||
CipherKeyValue.value max_size:1024
|
CipherKeyValue.value max_size:1024
|
||||||
|
@ -211,16 +211,17 @@ const pb_field_t MessageSignature_fields[3] = {
|
|||||||
PB_LAST_FIELD
|
PB_LAST_FIELD
|
||||||
};
|
};
|
||||||
|
|
||||||
const pb_field_t EncryptMessage_fields[4] = {
|
const pb_field_t EncryptMessage_fields[5] = {
|
||||||
PB_FIELD2( 1, BYTES , OPTIONAL, CALLBACK, FIRST, EncryptMessage, pubkey, pubkey, 0),
|
PB_FIELD2( 1, BYTES , OPTIONAL, STATIC , FIRST, EncryptMessage, pubkey, pubkey, 0),
|
||||||
PB_FIELD2( 2, BYTES , OPTIONAL, CALLBACK, OTHER, EncryptMessage, message, pubkey, 0),
|
PB_FIELD2( 2, BYTES , OPTIONAL, STATIC , OTHER, EncryptMessage, message, pubkey, 0),
|
||||||
PB_FIELD2( 3, BOOL , OPTIONAL, STATIC , OTHER, EncryptMessage, display_only, message, 0),
|
PB_FIELD2( 3, BOOL , OPTIONAL, STATIC , OTHER, EncryptMessage, display_only, message, 0),
|
||||||
|
PB_FIELD2( 4, UINT32 , REPEATED, STATIC , OTHER, EncryptMessage, address_n, display_only, 0),
|
||||||
PB_LAST_FIELD
|
PB_LAST_FIELD
|
||||||
};
|
};
|
||||||
|
|
||||||
const pb_field_t DecryptMessage_fields[3] = {
|
const pb_field_t DecryptMessage_fields[3] = {
|
||||||
PB_FIELD2( 1, UINT32 , REPEATED, CALLBACK, FIRST, DecryptMessage, address_n, address_n, 0),
|
PB_FIELD2( 1, UINT32 , REPEATED, STATIC , FIRST, DecryptMessage, address_n, address_n, 0),
|
||||||
PB_FIELD2( 2, BYTES , OPTIONAL, CALLBACK, OTHER, DecryptMessage, message, address_n, 0),
|
PB_FIELD2( 2, BYTES , OPTIONAL, STATIC , OTHER, DecryptMessage, message, address_n, 0),
|
||||||
PB_LAST_FIELD
|
PB_LAST_FIELD
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -196,16 +196,37 @@ typedef struct _DebugLinkState {
|
|||||||
uint32_t recovery_word_pos;
|
uint32_t recovery_word_pos;
|
||||||
} DebugLinkState;
|
} DebugLinkState;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
size_t size;
|
||||||
|
uint8_t bytes[1024];
|
||||||
|
} DecryptMessage_message_t;
|
||||||
|
|
||||||
typedef struct _DecryptMessage {
|
typedef struct _DecryptMessage {
|
||||||
pb_callback_t address_n;
|
size_t address_n_count;
|
||||||
pb_callback_t message;
|
uint32_t address_n[8];
|
||||||
|
bool has_message;
|
||||||
|
DecryptMessage_message_t message;
|
||||||
} DecryptMessage;
|
} DecryptMessage;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
size_t size;
|
||||||
|
uint8_t bytes[65];
|
||||||
|
} EncryptMessage_pubkey_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
size_t size;
|
||||||
|
uint8_t bytes[1024];
|
||||||
|
} EncryptMessage_message_t;
|
||||||
|
|
||||||
typedef struct _EncryptMessage {
|
typedef struct _EncryptMessage {
|
||||||
pb_callback_t pubkey;
|
bool has_pubkey;
|
||||||
pb_callback_t message;
|
EncryptMessage_pubkey_t pubkey;
|
||||||
|
bool has_message;
|
||||||
|
EncryptMessage_message_t message;
|
||||||
bool has_display_only;
|
bool has_display_only;
|
||||||
bool display_only;
|
bool display_only;
|
||||||
|
size_t address_n_count;
|
||||||
|
uint32_t address_n[8];
|
||||||
} EncryptMessage;
|
} EncryptMessage;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -528,6 +549,7 @@ extern const char SimpleSignTx_coin_name_default[17];
|
|||||||
#define EncryptMessage_pubkey_tag 1
|
#define EncryptMessage_pubkey_tag 1
|
||||||
#define EncryptMessage_message_tag 2
|
#define EncryptMessage_message_tag 2
|
||||||
#define EncryptMessage_display_only_tag 3
|
#define EncryptMessage_display_only_tag 3
|
||||||
|
#define EncryptMessage_address_n_tag 4
|
||||||
#define Entropy_entropy_tag 1
|
#define Entropy_entropy_tag 1
|
||||||
#define EntropyAck_entropy_tag 1
|
#define EntropyAck_entropy_tag 1
|
||||||
#define EstimateTxSize_outputs_count_tag 1
|
#define EstimateTxSize_outputs_count_tag 1
|
||||||
@ -641,7 +663,7 @@ extern const pb_field_t WordAck_fields[2];
|
|||||||
extern const pb_field_t SignMessage_fields[4];
|
extern const pb_field_t SignMessage_fields[4];
|
||||||
extern const pb_field_t VerifyMessage_fields[4];
|
extern const pb_field_t VerifyMessage_fields[4];
|
||||||
extern const pb_field_t MessageSignature_fields[3];
|
extern const pb_field_t MessageSignature_fields[3];
|
||||||
extern const pb_field_t EncryptMessage_fields[4];
|
extern const pb_field_t EncryptMessage_fields[5];
|
||||||
extern const pb_field_t DecryptMessage_fields[3];
|
extern const pb_field_t DecryptMessage_fields[3];
|
||||||
extern const pb_field_t CipherKeyValue_fields[7];
|
extern const pb_field_t CipherKeyValue_fields[7];
|
||||||
extern const pb_field_t EstimateTxSize_fields[4];
|
extern const pb_field_t EstimateTxSize_fields[4];
|
||||||
@ -691,6 +713,8 @@ extern const pb_field_t DebugLinkLog_fields[4];
|
|||||||
#define SignMessage_size 326
|
#define SignMessage_size 326
|
||||||
#define VerifyMessage_size 363
|
#define VerifyMessage_size 363
|
||||||
#define MessageSignature_size 104
|
#define MessageSignature_size 104
|
||||||
|
#define EncryptMessage_size 1144
|
||||||
|
#define DecryptMessage_size 1075
|
||||||
#define CipherKeyValue_size 1340
|
#define CipherKeyValue_size 1340
|
||||||
#define EstimateTxSize_size 31
|
#define EstimateTxSize_size 31
|
||||||
#define TxSize_size 6
|
#define TxSize_size 6
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 5bbe684c1068bd9cb6d24b12da5e216feb74351d
|
Subproject commit e2dab40398da63becf0e815c9fece141d2043d2e
|
@ -1 +1 @@
|
|||||||
Subproject commit ffd2d69dd658bad0e78cad853f8b81f2cd3e4b05
|
Subproject commit ad8e618ed28f4dca108461a9afdbbaadeb26746c
|
@ -1 +1 @@
|
|||||||
Subproject commit dfcfd702be6d0c1bc3f035001fba20f5336f308b
|
Subproject commit f12996741ca0a73b09e324306c7e79755a84202c
|
Loading…
Reference in New Issue
Block a user