Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit 02581be

Browse files
committed
Use HMACs for keeping track of valid back pages, instead of Merkle Tree
1 parent b1c89cd commit 02581be

File tree

15 files changed

+601
-919
lines changed

15 files changed

+601
-919
lines changed

bench/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ BENCH_FLAGS := -DUSE_FREEMEM -DUSE_PAGING -DUSE_PAGE_HASH -DUSE_PAGE_CRYPTO -D__
44

55
.PHONY: benches clean
66

7-
benches: merkle crypto
7+
benches: hmac crypto
88

9-
MODULES := merkle.o sha256.o aes.o bench/bencher.o bench/crypto.o bench/merkle.o
9+
MODULES := hmac.o sha256.o aes.o bench/bencher.o bench/crypto.o bench/hmac.o
1010
OBJ_PREFIX := objs/
1111

1212
$(addprefix $(OBJ_PREFIX),$(MODULES)) :: $(OBJ_PREFIX)%.o : ../%.c
1313
mkdir -p $(shell dirname $@)
1414
$(CC) $(CFLAGS) $(BENCH_FLAGS) -c -o $@ $^
1515

16-
MERKLE_MODULES := merkle.o sha256.o bench/bencher.o bench/merkle.o
17-
merkle: $(addprefix $(OBJ_PREFIX),$(MERKLE_MODULES))
16+
HMAC_MODULES := hmac.o sha256.o bench/bencher.o bench/hmac.o
17+
hmac: $(addprefix $(OBJ_PREFIX),$(HMAC_MODULES))
1818
$(CC) $(CFLAGS) $(BENCH_FLAGS) $^ $(LDFLAGS) -o $@
1919

2020
CRYPTO_MODULES := sha256.o aes.o bench/bencher.o bench/crypto.o
2121
crypto: $(addprefix $(OBJ_PREFIX),$(CRYPTO_MODULES))
2222
$(CC) $(CFLAGS) $(BENCH_FLAGS) $^ $(LDFLAGS) -o $@
2323

2424
clean:
25-
rm -rf merkle crypto objs/
25+
rm -rf hmac crypto objs/

bench/hmac.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#define _GNU_SOURCE
2+
3+
#include <../hmac.h>
4+
#include <assert.h>
5+
#include <bencher.h>
6+
#include <stdint.h>
7+
#include <stdlib.h>
8+
#include <string.h>
9+
#include <sys/mman.h>
10+
#include <time.h>
11+
12+
#define RAND_BOOK_LEN (4 * 1024 * 1024)
13+
14+
typedef struct bench_ctx {
15+
int* rand_book;
16+
uint8_t* key;
17+
uint8_t* page;
18+
} bench_ctx_t;
19+
20+
void
21+
bench_ctx__init(bench_ctx_t* ctx) {
22+
ctx->rand_book = (int*)malloc(sizeof(int) * RAND_BOOK_LEN);
23+
for (int i = 0; i < RAND_BOOK_LEN; i++) {
24+
ctx->rand_book[i] = rand();
25+
}
26+
}
27+
28+
int
29+
hmac_page__init(void* _ctx) {
30+
bench_ctx_t* ctx = (bench_ctx_t*)_ctx;
31+
ctx->key = (uint8_t*)ctx->rand_book + rand() % (RAND_BOOK_LEN - 32);
32+
ctx->page = (uint8_t*)ctx->rand_book + rand() % (RAND_BOOK_LEN - 4096);
33+
return 0;
34+
}
35+
36+
int
37+
hmac_page__destroy(void* _ctx) {
38+
(void)_ctx;
39+
return 0;
40+
}
41+
42+
int
43+
hmac_page(void* _ctx) {
44+
bench_ctx_t* ctx = (bench_ctx_t*)_ctx;
45+
uint8_t hash[32];
46+
int err = hmac(ctx->page, 4096, ctx->key, 32, hash);
47+
__asm__ __volatile__("" ::"r"(hash));
48+
return err;
49+
}
50+
51+
int
52+
main(int argc, char** argv) {
53+
srand(time(NULL));
54+
bench_ctx_t ctx = {};
55+
bench_ctx__init(&ctx);
56+
57+
struct bench benches[] = {
58+
{.name = "hmac page",
59+
.init = hmac_page__init,
60+
.deinit = hmac_page__destroy,
61+
.iter = hmac_page},
62+
};
63+
struct bench_opts opts = bench_argp(argc, argv);
64+
run_benches(&opts, benches, sizeof(benches) / sizeof(struct bench), &ctx);
65+
}

bench/merkle.c

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)