mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
bip32: Add hdnode_nem_get_shared_key
This commit is contained in:
parent
e1a511092a
commit
abda0f6504
20
bip32.c
20
bip32.c
@ -456,6 +456,26 @@ int hdnode_get_nem_address(HDNode *node, uint8_t version, char *address) {
|
|||||||
hdnode_fill_public_key(node);
|
hdnode_fill_public_key(node);
|
||||||
return nem_get_address(&node->public_key[1], version, address);
|
return nem_get_address(&node->public_key[1], version, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int hdnode_get_nem_shared_key(const HDNode *node, const ed25519_public_key peer_public_key, const uint8_t *salt, ed25519_public_key mul, uint8_t *shared_key) {
|
||||||
|
if (node->curve != &ed25519_keccak_info) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sizeof(ed25519_public_key) == SHA3_256_DIGEST_LENGTH
|
||||||
|
if (mul == NULL) mul = shared_key;
|
||||||
|
|
||||||
|
if (ed25519_scalarmult_keccak(mul, node->private_key, peer_public_key)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 32; i++) {
|
||||||
|
shared_key[i] = mul[i] ^ salt[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
keccak_256(shared_key, 32, shared_key);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// msg is a data to be signed
|
// msg is a data to be signed
|
||||||
|
2
bip32.h
2
bip32.h
@ -28,6 +28,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "ecdsa.h"
|
#include "ecdsa.h"
|
||||||
|
#include "ed25519.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -74,6 +75,7 @@ int hdnode_get_ethereum_pubkeyhash(const HDNode *node, uint8_t *pubkeyhash);
|
|||||||
|
|
||||||
#if USE_NEM
|
#if USE_NEM
|
||||||
int hdnode_get_nem_address(HDNode *node, uint8_t version, char *address);
|
int hdnode_get_nem_address(HDNode *node, uint8_t version, char *address);
|
||||||
|
int hdnode_get_nem_shared_key(const HDNode *node, const ed25519_public_key peer_public_key, const uint8_t *salt, ed25519_public_key mul, uint8_t *shared_key);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int hdnode_sign(HDNode *node, const uint8_t *msg, uint32_t msg_len, uint8_t *sig, uint8_t *pby, int (*is_canonical)(uint8_t by, uint8_t sig[64]));
|
int hdnode_sign(HDNode *node, const uint8_t *msg, uint32_t msg_len, uint8_t *sig, uint8_t *pby, int (*is_canonical)(uint8_t by, uint8_t sig[64]));
|
||||||
|
Loading…
Reference in New Issue
Block a user