1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 20:19:23 +00:00
trezor-firmware/crypto/tools/xpubaddrgen.c

49 lines
1.3 KiB
C
Raw Permalink Normal View History

#include <inttypes.h>
#include <stdint.h>
2014-12-24 00:26:39 +00:00
#include <stdio.h>
#include <string.h>
2016-04-25 15:15:02 +00:00
#include "bip32.h"
2017-12-10 12:35:02 +00:00
#include "curves.h"
2016-04-25 15:15:02 +00:00
#include "ecdsa.h"
2014-12-24 00:26:39 +00:00
#define VERSION_PUBLIC 0x0488b21e
2017-04-21 11:53:10 +00:00
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_public(xpub, VERSION_PUBLIC, 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);
}
2014-12-24 00:26:39 +00:00
}
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;
2014-12-24 00:26:39 +00:00
}