Skip to content

Commit 9ddef39

Browse files
committed
Replace openssl/sha2 with the sha256 implementation in tree
1 parent 80c5cce commit 9ddef39

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
ITERATE_OBJS := iterate.o parse.o blockfiles.o io.o dump.o
1+
ITERATE_OBJS := iterate.o parse.o blockfiles.o io.o dump.o sha256.o
22
#CCAN_OBJS := ccan-asort.o ccan-breakpoint.o ccan-tal.o ccan-tal-path.o ccan-tal-str.o ccan-take.o ccan-list.o ccan-str.o ccan-opt-helpers.o ccan-opt.o ccan-opt-parse.o ccan-opt-usage.o ccan-htable.o ccan-rbuf.o
33
CCAN_OBJS := ccan-tal.o ccan-tal-path.o ccan-tal-str.o ccan-take.o ccan-list.o ccan-str.o ccan-opt-helpers.o ccan-opt.o ccan-opt-parse.o ccan-opt-usage.o ccan-htable.o ccan-rbuf.o ccan-hex.o ccan-tal-grab-file.o ccan-noerr.o
44
CCANDIR=ccan/
55
CFLAGS = -O3 -flto -ggdb -I $(CCANDIR) -Wall
66
LDFLAGS = -O3 -flto
77
#CFLAGS = -ggdb -I $(CCANDIR) -Wall
8-
LDLIBS := -lcrypto
8+
LDLIBS :=
99
BIN_DIR := /usr/local/bin
1010

1111
all: bitcoin-iterate doc/bitcoin-iterate.1

parse.c

+17-17
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ static void read_output(struct space *space, struct file *f, off_t *poff,
104104
pull_bytes(f, poff, output->script, output->script_length);
105105
}
106106

107-
static void sha_add(SHA256_CTX *sha256, struct file *f, off_t start, off_t len)
107+
static void sha_add(sha256_context *sha256, struct file *f, off_t start, off_t len)
108108
{
109109
if (likely(f->mmap)) {
110-
SHA256_Update(sha256, f->mmap + start, len);
110+
sha256_write(sha256, f->mmap + start, len);
111111
} else {
112112
u8 *buf = tal_arr(NULL, u8, len);
113113
file_read(f, start, len, buf);
114-
SHA256_Update(sha256, buf, len);
114+
sha256_write(sha256, buf, len);
115115
tal_free(buf);
116116
}
117117
}
@@ -156,10 +156,10 @@ void read_bitcoin_transaction(struct space *space,
156156
size_t i;
157157
const off_t start = *poff;
158158
off_t hash_start = *poff;
159-
SHA256_CTX sha256;
159+
sha256_context sha256;
160160
bool segwit = false;
161161

162-
SHA256_Init(&sha256);
162+
sha256_initialize(&sha256);
163163

164164
trans->version = pull_u32(f, poff);
165165
sha_add(&sha256, f, start, *poff - start);
@@ -211,10 +211,10 @@ void read_bitcoin_transaction(struct space *space,
211211
len += *poff - hash_start;
212212

213213
/* Bitcoin uses double sha (it's not quite known why...) */
214-
SHA256_Final(trans->sha256, &sha256);
215-
SHA256_Init(&sha256);
216-
SHA256_Update(&sha256, trans->sha256, sizeof(trans->sha256));
217-
SHA256_Final(trans->sha256, &sha256);
214+
sha256_finalize(&sha256, trans->sha256);
215+
sha256_initialize(&sha256);
216+
sha256_write(&sha256, trans->sha256, sizeof(trans->sha256));
217+
sha256_finalize(&sha256, trans->sha256);
218218

219219
trans->non_swlen = len;
220220
trans->total_len = *poff - start;
@@ -243,7 +243,7 @@ read_bitcoin_block_header(struct bitcoin_block *block,
243243
u8 block_md[SHA256_DIGEST_LENGTH],
244244
const u32 marker)
245245
{
246-
SHA256_CTX sha256;
246+
sha256_context sha256;
247247
off_t start;
248248

249249
block->D9B4BEF9 = pull_u32(f, off);
@@ -260,20 +260,20 @@ read_bitcoin_block_header(struct bitcoin_block *block,
260260
block->nonce = pull_u32(f, off);
261261

262262
/* Bitcoin uses double sha (it's not quite known why...) */
263-
SHA256_Init(&sha256);
263+
sha256_initialize(&sha256);
264264
if (likely(f->mmap)) {
265-
SHA256_Update(&sha256, f->mmap + start, *off - start);
265+
sha256_write(&sha256, f->mmap + start, *off - start);
266266
} else {
267267
u8 *buf = tal_arr(NULL, u8, *off - start);
268268
file_read(f, start, *off - start, buf);
269-
SHA256_Update(&sha256, buf, *off - start);
269+
sha256_write(&sha256, buf, *off - start);
270270
tal_free(buf);
271271
}
272-
SHA256_Final(block_md, &sha256);
272+
sha256_finalize(&sha256, block_md);
273273

274-
SHA256_Init(&sha256);
275-
SHA256_Update(&sha256, block_md, SHA256_DIGEST_LENGTH);
276-
SHA256_Final(block_md, &sha256);
274+
sha256_initialize(&sha256);
275+
sha256_write(&sha256, block_md, SHA256_DIGEST_LENGTH);
276+
sha256_finalize(&sha256, block_md);
277277

278278
block->transaction_count = pull_varint(f, off);
279279

types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef BITCOIN_PARSE_TYPES_H
22
#define BITCOIN_PARSE_TYPES_H
33
#include <ccan/short_types/short_types.h>
4-
#include <openssl/sha.h>
4+
#include "sha256.h"
55

66
/* We unpack varints for our in-memory representation */
77
#define varint_t u64

0 commit comments

Comments
 (0)