mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
Implement ecdsa_get_ethereum_pubkeyhash()
This commit is contained in:
parent
7d68a6ee17
commit
1b8e3d557f
24
ecdsa.c
24
ecdsa.c
@ -36,6 +36,9 @@
|
||||
#include "base58.h"
|
||||
#include "macros.h"
|
||||
#include "secp256k1.h"
|
||||
#if USE_ETHEREUM
|
||||
#include "sha3.h"
|
||||
#endif
|
||||
|
||||
// Set cp2 = cp1
|
||||
void point_copy(const curve_point *cp1, curve_point *cp2)
|
||||
@ -850,6 +853,27 @@ void ecdsa_get_pubkeyhash(const uint8_t *pub_key, uint8_t *pubkeyhash)
|
||||
MEMSET_BZERO(h, sizeof(h));
|
||||
}
|
||||
|
||||
#if USE_ETHEREUM
|
||||
int ecdsa_get_ethereum_pubkeyhash(const uint8_t *pub_key, uint8_t *pubkeyhash)
|
||||
{
|
||||
uint8_t h[65];
|
||||
SHA3_CTX ctx;
|
||||
|
||||
if (!ecdsa_uncompress_pubkey(&secp256k1, pub_key, h)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sha3_256_Init(&ctx);
|
||||
sha3_Update(&ctx, h + 1, 64);
|
||||
keccak_Final(&ctx, h);
|
||||
|
||||
// least significant 160 bits
|
||||
memcpy(pubkeyhash, h + 12, 20);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ecdsa_get_address_raw(const uint8_t *pub_key, uint8_t version, uint8_t *addr_raw)
|
||||
{
|
||||
addr_raw[0] = version;
|
||||
|
1
ecdsa.h
1
ecdsa.h
@ -66,6 +66,7 @@ int ecdsa_sign_digest(const ecdsa_curve *curve, const uint8_t *priv_key, const u
|
||||
void ecdsa_get_public_key33(const ecdsa_curve *curve, const uint8_t *priv_key, uint8_t *pub_key);
|
||||
void ecdsa_get_public_key65(const ecdsa_curve *curve, const uint8_t *priv_key, uint8_t *pub_key);
|
||||
void ecdsa_get_pubkeyhash(const uint8_t *pub_key, uint8_t *pubkeyhash);
|
||||
int ecdsa_get_ethereum_pubkeyhash(const uint8_t *pub_key, uint8_t *pubkeyhash);
|
||||
void ecdsa_get_address_raw(const uint8_t *pub_key, uint8_t version, uint8_t *addr_raw);
|
||||
void ecdsa_get_address(const uint8_t *pub_key, uint8_t version, char *addr, int addrsize);
|
||||
void ecdsa_get_wif(const uint8_t *priv_key, uint8_t version, char *wif, int wifsize);
|
||||
|
Loading…
Reference in New Issue
Block a user