Skip to content

Commit

Permalink
have hex2blf print approx fp rate
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancdotorg committed Nov 4, 2015
1 parent bdcf7bd commit 0c9c9a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ blfchk: blfchk.o hex.o bloom.o mmapf.o hsearchf.o
$(COMPILE) -static $^ $(LIBS) -o $@

hex2blf: hex2blf.o hex.o bloom.o mmapf.o
$(COMPILE) -static $^ $(LIBS) -o $@
$(COMPILE) -static $^ $(LIBS) -lm -o $@

ecmtabgen: ecmtabgen.o mmapf.o ec_pubkey_fast.o
$(COMPILE) -static $^ $(LIBS) -o $@
Expand Down
13 changes: 12 additions & 1 deletion hex2blf.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@

#include <arpa/inet.h> /* for ntohl/htonl */

#include <math.h> /* pow/exp */

#include "hex.h"
#include "bloom.h"
#include "hash160.h"

const double k_hashes = 20;
const double m_bits = 4294967296;

int main(int argc, char **argv) {
hash160_t hash;
int i;
double pct;
struct stat sb;
unsigned char *bloom, *hashfile, *bloomfile;
FILE *f, *b;
size_t line_sz = 1024;
size_t line_sz = 1024, line_ct = 0;
char *line;

double err_rate;

if (argc != 3) {
fprintf(stderr, "[!] Usage: %s hashfile.hex bloomfile.blf\n", argv[0]);
exit(1);
Expand Down Expand Up @@ -79,6 +86,7 @@ int main(int argc, char **argv) {
stat(hashfile, &sb);
fprintf(stderr, "[*] Loading hash160s from '%s' \033[s 0.0%%", hashfile);
while (getline(&line, &line_sz, f) > 0) {
++line_ct;
unhex(line, strlen(line), hash.uc, sizeof(hash.uc));
bloom_set_hash160(bloom, hash.ul);

Expand All @@ -90,6 +98,9 @@ int main(int argc, char **argv) {
}
fprintf(stderr, "\033[u 100.0%%\n");

err_rate = pow(1 - exp(-k_hashes * line_ct / m_bits), k_hashes);
fprintf(stderr, "[*] Loaded %zu hashes, false positive rate: ~%.3e (1 in ~%.3e)\n", line_ct, err_rate, 1/err_rate);

fprintf(stderr, "[*] Writing bloom filter to '%s'...\n", bloomfile);
if ((fwrite(bloom, BLOOM_SIZE, 1, b)) != 1) {
fprintf(stderr, "[!] Failed to write bloom filter file '%s'\n", bloomfile);
Expand Down

0 comments on commit 0c9c9a0

Please sign in to comment.