1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 00:28:10 +00:00
trezor-firmware/tools/xpubaddrgen.c
Saleem Rashid c70e440128 hasher: Replace hasher_Double with HASHER_*D
This allows us to finely control when to use a single hash or a double hash in
various places. For example, Bitcoin signatures use double SHA256, but Decred
signatures use a single BLAKE256. However, both use double hashes for Base58.
2018-04-03 18:28:06 +02:00

48 lines
1.2 KiB
C

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include "bip32.h"
#include "curves.h"
#include "ecdsa.h"
#define VERSION_PUBLIC 0x0488b21e
#define VERSION_PRIVATE 0x0488ade4
void process_job(uint32_t jobid, const char *xpub, uint32_t change, uint32_t from, uint32_t to)
{
HDNode node, child;
if (change > 1 || to <= from || hdnode_deserialize(xpub, VERSION_PUBLIC, VERSION_PRIVATE, SECP256K1_NAME, &node, NULL) != 0) {
printf("%d error\n", jobid);
return;
}
hdnode_public_ckd(&node, change);
uint32_t i;
char address[36];
for (i = from; i < to; i++) {
memcpy(&child, &node, sizeof(HDNode));
hdnode_public_ckd(&child, i);
ecdsa_get_address(child.public_key, 0, HASHER_SHA2, HASHER_SHA2D, address, sizeof(address));
printf("%d %d %s\n", jobid, i, address);
}
}
int main(void)
{
char line[1024], xpub[1024];
uint32_t jobid, change, from, to;
int r;
for (;;) {
if (!fgets(line, sizeof(line), stdin)) break;
r = sscanf(line, "%u %s %u %u %u\n", &jobid, xpub, &change, &from, &to);
if (r < 1) {
printf("error\n");
} else if (r != 5) {
printf("%d error\n", jobid);
} else {
process_job(jobid, xpub, change, from, to);
}
}
return 0;
}