Skip to content

Commit f242b08

Browse files
committed
naming cleanup, expose bip32_fingerprint()
1 parent becc652 commit f242b08

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

bip32.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int bip32_from_seed(bip32_key *key, const unsigned char *seed, size_t seed_len)
6868
return retcode;
6969
}
7070

71-
int pubkey_from_privkey(unsigned char* out, const unsigned char* privkey_in) {
71+
int bip32_pubkey_from_privkey(unsigned char* out, const unsigned char* privkey_in) {
7272
int retcode = 1;
7373
secp256k1_context* ctx = NULL;
7474
get_secp_ctx(&ctx);
@@ -89,11 +89,11 @@ int pubkey_from_privkey(unsigned char* out, const unsigned char* privkey_in) {
8989
return retcode;
9090
}
9191

92-
int get_fingerprint(const bip32_key* key, uint32_t* out) {
92+
int bip32_fingerprint(const bip32_key* key, uint32_t* out) {
9393
unsigned char pubkey_bytes[BIP32_PUBKEY_SIZE];
9494

9595
if (key->is_private) {
96-
pubkey_from_privkey(pubkey_bytes, key->key.privkey);
96+
bip32_pubkey_from_privkey(pubkey_bytes, key->key.privkey);
9797
} else {
9898
memcpy(pubkey_bytes, key->key.pubkey, BIP32_PUBKEY_SIZE);
9999
}
@@ -114,7 +114,7 @@ int bip32_index_derive(bip32_key *target, const bip32_key *source, uint32_t inde
114114
int retcode = 1;
115115
const size_t hmac_msg_len = BIP32_PUBKEY_SIZE + sizeof(uint32_t);
116116
unsigned char hmac_msg[hmac_msg_len];
117-
unsigned char output[SHA512_SIZE];
117+
unsigned char output[crypto_hash_sha512_BYTES];
118118
bool is_hardened = index >= HARDENED_INDEX;
119119

120120
if (is_hardened && !source->is_private) {
@@ -211,7 +211,7 @@ int bip32_index_derive(bip32_key *target, const bip32_key *source, uint32_t inde
211211
retcode = 0; goto exit;
212212
}
213213

214-
get_fingerprint(source, &target->parent_fingerprint);
214+
bip32_fingerprint(source, &target->parent_fingerprint);
215215

216216
exit:
217217
secp256k1_context_destroy(ctx);
@@ -337,7 +337,7 @@ int bip32_deserialize(bip32_key *key, const char *str, const size_t str_len) {
337337
}
338338

339339
// Verify checksum
340-
unsigned char hash[SHA256_SIZE];
340+
unsigned char hash[crypto_hash_sha512_BYTES];
341341
sha256_double(hash, data, 78);
342342
if (memcmp(hash, data + 78, 4) != 0) {
343343
return 0;
@@ -421,7 +421,7 @@ int bip32_get_public(bip32_key *target, const bip32_key *source) {
421421
target->is_testnet = source->is_testnet;
422422
target->is_private = 0;
423423

424-
pubkey_from_privkey(target->key.pubkey, source->key.privkey);
424+
bip32_pubkey_from_privkey(target->key.pubkey, source->key.privkey);
425425
return 1;
426426
}
427427

bip32.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
#define BIP32_CHAINCODE_SIZE 32
88
#define BIP32_PRIVKEY_SIZE 32
99
#define BIP32_PUBKEY_SIZE 33
10-
#define RIPEMD160_SIZE 20
11-
#define SHA256_SIZE 32
12-
#define SHA512_SIZE 64
1310

1411
#ifdef __cplusplus
1512
extern "C" {
1613
#endif
1714

18-
// Version bytes
1915
#define VERSION_XPUB 0x0488B21E
2016
#define VERSION_XPRIV 0x0488ADE4
2117
#define VERSION_TPUB 0x043587CF
@@ -60,12 +56,17 @@ int bip32_get_public(bip32_key *target, const bip32_key *source);
6056

6157
int bip32_index_derive(bip32_key *target, const bip32_key *source, uint32_t index);
6258

63-
/**
64-
* Given a private key, set `out`'s bytes to the corresponding compressed pubkey.
59+
/** Given a private key, set `out`'s bytes to the corresponding compressed pubkey.
6560
*
6661
* Returns 1 if successful.
6762
*/
68-
int pubkey_from_privkey(unsigned char* out, const unsigned char* privkey_in);
63+
int bip32_pubkey_from_privkey(unsigned char* out, const unsigned char* privkey_in);
64+
65+
/** Get a key's fingerpint.
66+
*
67+
* Returns 1 always.
68+
*/
69+
int bip32_fingerprint(const bip32_key* key, uint32_t* out);
6970

7071
void sha256_double(uint8_t *hash, const uint8_t *data, size_t len);
7172

0 commit comments

Comments
 (0)