Skip to content

Commit cfb7cb4

Browse files
committed
optimize shake
1 parent 8c1d734 commit cfb7cb4

File tree

10 files changed

+2774
-250
lines changed

10 files changed

+2774
-250
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
TARGET :=
21
TARGET := riscv64-unknown-linux-gnu-
32
CC := $(TARGET)gcc
43
LD := $(TARGET)gcc
@@ -46,8 +45,9 @@ HEADERS = \
4645
SOURCES += \
4746
c/$(SOURCES_DIR)/fips202.c \
4847
c/$(SOURCES_DIR)/hash_shake.c \
49-
c/$(SOURCES_DIR)/thash_shake_robust.c\
50-
c/$(SOURCES_DIR)/thash_shake_simple.c
48+
c/$(SOURCES_DIR)/thash_shake_robust.c \
49+
c/$(SOURCES_DIR)/thash_shake_simple.c \
50+
c/$(SOURCES_DIR)/fips202_asm_bin.S
5151
HEADERS += \
5252
c/$(SOURCES_DIR)/fips202.h
5353

@@ -69,7 +69,7 @@ SOURCES += \
6969
HEADERS += \
7070
c/$(SOURCES_DIR)/haraka.h
7171

72-
# CFLAGS := $(CFLAGS) -g -DCKB_C_STDLIB_PRINTF
72+
CFLAGS := $(CFLAGS) -g -DCKB_C_STDLIB_PRINTF
7373

7474
# docker pull nervos/ckb-riscv-gnu-toolchain:gnu-bionic-20191012
7575
BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:aae8a3f79705f67d505d1f1d5ddc694a4fd537ed1c7e9622420a470d59ba2ec3
@@ -79,7 +79,10 @@ all: build/sphincsplus_lock
7979
all-via-docker:
8080
docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make"
8181

82-
build/sphincsplus_lock: c/ckb-sphincsplus-lock.c $(SOURCES) $(HEADERS)
82+
build/convert_asm: c/ref/fips202_asm.S
83+
riscv-naive-assembler -i c/ref/fips202_asm.S > c/ref/fips202_asm_bin.S
84+
85+
build/sphincsplus_lock: c/ckb-sphincsplus-lock.c $(SOURCES) $(HEADERS) build/convert_asm
8386
mkdir -p build
8487
$(CC) $(CFLAGS) -o $@ $(SOURCES) $<
8588

c/ref/fips202.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#define NROUNDS 24
1414
#define ROL(a, offset) (((a) << (offset)) ^ ((a) >> (64 - (offset))))
1515

16+
#ifdef CKB_VM
17+
void riscv_keccak_f1600(uint64_t *state, uint64_t *rc);
18+
#endif
19+
1620
/*************************************************
1721
* Name: load64
1822
*
@@ -63,6 +67,13 @@ static const uint64_t KeccakF_RoundConstants[NROUNDS] = {
6367
*
6468
* Arguments: - uint64_t *state: pointer to input/output Keccak state
6569
**************************************************/
70+
#ifdef CKB_VM
71+
72+
static void KeccakF1600_StatePermute(uint64_t *state) {
73+
riscv_keccak_f1600(state, (uint64_t *)KeccakF_RoundConstants);
74+
}
75+
76+
#else // CKB_VM
6677
static void KeccakF1600_StatePermute(uint64_t *state) {
6778
int round;
6879

@@ -325,6 +336,7 @@ static void KeccakF1600_StatePermute(uint64_t *state) {
325336
state[23] = Aso;
326337
state[24] = Asu;
327338
}
339+
#endif // CKB_VM
328340

329341
/*************************************************
330342
* Name: keccak_absorb

0 commit comments

Comments
 (0)