diff --git a/.github/workflows/amd64-linux-main.yml b/.github/workflows/amd64-linux-main.yml index c447b537..406e5819 100644 --- a/.github/workflows/amd64-linux-main.yml +++ b/.github/workflows/amd64-linux-main.yml @@ -152,7 +152,7 @@ jobs: uses: actions/checkout@v3 - name: compile amd64 - run: JASMIN=$(which_jasminc) make -j$JOBS -C src/ CI=1 default + run: JASMIN=$(which_jasminc) make -j$JOBS -C src/ CI=1 compile-amd64 - name: dist amd64 run: JASMIN=$(which_jasminc) ./scripts/ci/releaser/jdist-src-v1 amd64 diff --git a/.github/workflows/armv7m-linux-main.yml b/.github/workflows/armv7m-linux-main.yml new file mode 100644 index 00000000..8158ac21 --- /dev/null +++ b/.github/workflows/armv7m-linux-main.yml @@ -0,0 +1,32 @@ +name: armv7m-linux-main + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + +jobs: + + test: + runs-on: [self-hosted, linux, X64, amd64-main] + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: compile and run + run: JASMIN=$(which_jasminc) make -f Makefile.armv7m -j$JOBS -C test/ CI=1 default + - name: print logs + run: JASMIN=$(which_jasminc) make -f Makefile.armv7m -C test/ CI=1 reporter + - name: return error if there are any errors + run: make -f Makefile.armv7m -C test/ CI=1 err + + - name: libjade-armv7m-logs-test.tar.gz - contains non-empty logs and errors + if: always() + uses: actions/upload-artifact@v3 + with: + name: libjade-armv7m-logs-test.tar.gz + path: test/libjade-armv7m-logs-test.tar.gz + + diff --git a/bench/Makefile b/bench/Makefile index b2b62308..f763bb03 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -13,6 +13,9 @@ # implementations being excluded from benchmarks: EXCLUDE ?= crypto_xof/shake256/amd64/spec/ +# -------------------------------------------------------------------- +ARCH ?= amd64 + # -------------------------------------------------------------------- AS ?= as CC ?= clang @@ -51,6 +54,8 @@ BIN ?= bin LOGS := libjade-logs-bench.tar.gz SRC := ../src +export SRC + COMMON := common EXT := ../ext @@ -59,8 +64,13 @@ RANDINC ?= $(EXT)/randombytes/ SSBD_DIR := $(EXT)/ssbd-tools FILTER ?= $(SRC)/crypto_% -JAZZ ?= $(filter $(FILTER), $(filter-out $(addprefix $(SRC)/,$(EXCLUDE)), $(sort $(dir $(shell find $(SRC) -name '*.jazz'))))) -BENCHDIR := $(subst $(SRC),$(BIN), $(JAZZ)) +export FILTER + +JAZZ_ARCH ?= $(filter $(FILTER), $(filter-out $(addprefix $(SRC)/,$(EXCLUDE)), $(sort $(dir $(shell find $(SRC) -path "*/$(ARCH)/*" -name '*.jazz'))))) + +BENCHDIR := $(subst $(SRC),$(BIN), $(JAZZ_ARCH)) + +# -------------------------------------------------------------------- EXEC := $(addsuffix bench, $(BENCHDIR)) OUT := $(addsuffix .out, $(EXEC)) diff --git a/scripts/ci/config/jasmin b/scripts/ci/config/jasmin index 6c8bf917..3cbe126f 100644 --- a/scripts/ci/config/jasmin +++ b/scripts/ci/config/jasmin @@ -1 +1 @@ -9e87718c35083acc3349bee84e2b3a12ce385032 +2c25aa576a0852bcf6ebe2d6a58adbe65bb497bb diff --git a/src/Makefile b/src/Makefile index 2881e82f..951bfe72 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,19 @@ -# -*- Makefile -*- +# -------------------------------------------------------------------- +# some commands frequently run during development sessions: +# +# - clean 'everything' and compile all assembly files (change -j12 accordingly): +# libjade/src$ make CI=1 distclean && make -j12 CI=1 compile && make CI=1 reporter +# +# - build libjade-amd64.a/h (note that there are no tests that use libjade-*.a +# directly -- only .s files -- feel free to open a PR/reach out); +# libjade/src$ make CI=1 distclean && make -j12 libjade-amd64.a libjade-amd64.h +# +# - build libjade-armv7m.a libjade-armv7m.h +# libjade/src$ make CI=1 distclean && make -j12 CI=1 ARCH=armv7m CC=arm-linux-gnueabi-gcc CFLAGS='-Wall -O3' AS=arm-linux-gnueabi-as AR=arm-linux-gnueabi-ar RANLIB=arm-linux-gnueabi-ranlib libjade-armv7m.a libjade-armv7m.h && make CI=1 reporter +# +# In particular for the last command, it is helpful to setup some sort of +# facilitator that sets the variables according to the system's configuration || * + # -------------------------------------------------------------------- AS ?= as @@ -6,6 +21,9 @@ CC ?= clang CFLAGS ?= -O3 -Wall -Wextra -Wpedantic -Wvla -Werror -std=c99 \ -Wundef -Wshadow -Wcast-align -Wpointer-arith -Wmissing-prototypes \ -fstrict-aliasing -fno-common -pipe +AR ?= ar +RANLIB ?= ranlib + JASMIN ?= jasminc # -------------------------------------------------------------------- @@ -14,19 +32,32 @@ export CI CICL ?= "1" # -------------------------------------------------------------------- -LOGS := libjade-logs-src.tar.gz +SRC ?= . +LOGS := $(SRC)/libjade-logs-src.tar.gz -EXCLUDE ?= -SRC := . +EXCLUDE ?= FILTER ?= $(SRC)/crypto_% -JAZZ ?= $(filter $(FILTER), $(filter-out $(addprefix ./,$(EXCLUDE)), $(sort $(dir $(shell find $(SRC) -name '*.jazz'))))) + +# JAZZ contains *all* directories where there is a '.jazz' file: it is expected +# that there is a Makefile in the same directory whose default rule produces .s +# file(s). + +JAZZ ?= $(filter $(FILTER), $(filter-out $(addprefix ./,$(EXCLUDE)), $(sort $(dir $(shell find $(SRC) -name '*.jazz'))))) SAFETY ?= $(addsuffix safety, $(JAZZ)) -SOURCES ?= $(filter-out ./, $(sort $(dir $(shell find $(SRC) -name 'Makefile')))) -ASM := $(shell find $(SRC) -name '*.s') -API := $(addsuffix include/api.h, $(dir $(ASM))) -OBJ := $(ASM:%.s=%.o) + +# OBJECTS contains all '.o' files we would like to build. This list is built +# from the existing .s files (default rule compiles everything to assembly; +# then, on a second/third call to this Makefile, we create individual libraries +# -- at the time of this writing, amd64 and armv7m. + +ARCH ?= amd64 + +JAZZ_ARCH ?= $(filter $(FILTER), $(filter-out $(addprefix ./,$(EXCLUDE)), $(sort $(dir $(shell find $(SRC) -path "*/$(ARCH)/*" -name '*.jazz'))))) +ASSEMBLY := $(shell find $(SRC) -path "*/$(ARCH)/*" -name '*.s') +OBJECTS := $(ASSEMBLY:%.s=%.o) +HEADERS := $(addsuffix include/api.h, $(dir $(ASSEMBLY))) # -------------------------------------------------------------------- ifeq ($(CI),1) @@ -39,26 +70,36 @@ backward_compatibility: endif # -------------------------------------------------------------------- -.PHONY: libjade.a libjade.h $(JAZZ) clean distclean $(LOGS) -.INTERMEDIATE: $(OBJ) +.PHONY: libjade-$(ARCH).a libjade-$(ARCH).h $(JAZZ) clean distclean $(LOGS) +.INTERMEDIATE: $(OBJECTS) -default: libjade.a libjade.h +default: compile -all: $(JAZZ) - -libjade.a: $(JAZZ) - $(MAKE) __libjade - -__libjade: $(OBJ) - ar -rc libjade.a $(OBJ) - ranlib libjade.a - echo "" | cat - $(API) > libjade.h +compile: $(JAZZ) $(JAZZ): $(MAKE) -C $@ || true # -------------------------------------------------------------------- +# two call building pattern: +# - compile as many .s as possible (from .jazz); +# - then archive + +libjade-$(ARCH).a: compile-$(ARCH) + $(MAKE) __libjade-$(ARCH).a + +__libjade-$(ARCH).a: $(OBJECTS) + $(AR) -rc libjade-$(ARCH).a $(OBJECTS) + $(RANLIB) libjade-$(ARCH).a + +libjade-$(ARCH).h: $(HEADERS) + echo "" | cat - $(HEADERS) > $@ + +compile-$(ARCH): $(JAZZ_ARCH) + +# -------------------------------------------------------------------- + SAFETY_TIMEOUT ?= 1440m export SAFETY_TIMEOUT @@ -105,8 +146,8 @@ endif # -------------------------------------------------------------------- clean: - rm -f libjade.a libjade.h $(LOGS) check.tar.gz + rm -f libjade-*.a libjade-*.h $(LOGS) check.tar.gz distclean: clean - for i in $(SOURCES); do $(MAKE) -C $$i clean; done + for i in $(JAZZ); do $(MAKE) -C $$i clean; done diff --git a/src/common/keccak/keccak1600/armv7m/ref/keccak1600.jinc b/src/common/keccak/keccak1600/armv7m/ref/keccak1600.jinc new file mode 100644 index 00000000..9f156f3d --- /dev/null +++ b/src/common/keccak/keccak1600/armv7m/ref/keccak1600.jinc @@ -0,0 +1,250 @@ +require "keccakf1600.jinc" + +inline fn __keccak_init_ref(reg ptr u32[25*2] state) -> reg ptr u32[25*2] +{ + reg u32 i t; + + i = 0; + t = 0; + while(i < 25*2) + { state[(int)i] = t; + i += 1; + } + + return state; +} + + +// obs: @pre: rate multiple of 4 +inline fn __add_full_block_ref( + reg ptr u32[25*2] state, + reg u32 in inlen, + reg u32 rate +) -> reg ptr u32[25*2], reg u32, reg u32 +{ + reg u32 i t0 t1 rate32; + + rate32 = rate; + rate32 >>= 2; + i = 0; + while( i < rate32) + { + t0 = [in + 4*i]; + t1 = state[(int)i]; + t0 ^= t1; + state[(int)i] = t0; + i+=1; + } + + in += rate; + inlen -= rate; + + return state, in, inlen; +} + + +// obs: @pre: inlen < rate_in_bytes +inline fn __add_final_block_ref( + reg ptr u32[25*2] state, + reg u32 in inlen, + reg u32 trail_byte, + reg u32 rate +) -> reg ptr u32[25*2] +{ + reg u32 i t0 t1 inlen4; + + inlen4 = inlen; + inlen4 >>= 2; + i = 0; + while ( i < inlen4 ) + { + t0 = [in + 4*i]; + t1 = state[(int)i]; + t0 ^= t1; + state[(int)i] = t0; + i += 1; + } + + i <<= 2; + while ( i < inlen ) + { + t0 = (32u)(u8)[in + i]; + t1 = (32u) state[u8 (int)i]; + t0 ^= t1; + state[u8 (int)i] = (8u) t0; + i += 1; + } + + t0 = (32u) state[u8 (int)i]; + t0 ^= trail_byte; + state[u8 (int)i] = (8u) t0; + + i = rate; + i -= 1; + + t0 = (32u) state[u8 (int)i]; + t1 = 0x80; + t0 ^= t1; + state[u8 (int)i] = (8u) t0; + + return state; +} + + +inline fn __absorb_ref( + reg ptr u32[25*2] state, + reg u32 in inlen, + stack u32 s_trail_byte, + reg u32 rate // rate already in bytes -- it is returned bc of spills +) -> reg ptr u32[25*2], reg u32 +{ + stack u32 s_in s_inlen s_rate; + reg u32 trail_byte t; + + // intermediate blocks + while ( inlen >= rate ) + { + state, in, inlen = __add_full_block_ref(state, in, inlen, rate); + + s_in = in; + s_inlen = inlen; + s_rate = rate; + + state = _keccakf1600_ref(state); + + in = s_in; + inlen = s_inlen; + rate = s_rate; + } + + // final block + trail_byte = s_trail_byte; + + state = __add_final_block_ref(state, in, inlen, trail_byte, rate); + + return state, rate; +} + + +inline fn __xtr_full_block_ref( + reg ptr u32[25*2] state, + reg u32 out outlen, + reg u32 rate +) -> reg u32, reg u32 +{ + reg u32 i t rate32; + + rate32 = rate; + rate32 >>= 2; + i = 0; + while ( i < rate32 ) + { + t = state[(int)i]; + [out + 4*i] = t; + i += 1; + } + + out += rate; + outlen -= rate; + + return out, outlen; +} + + +inline fn __xtr_bytes_ref( + reg ptr u32[25*2] state, + reg u32 out outlen +) -> reg u32 +{ + reg u32 i t outlen4; + + outlen4 = outlen; + outlen4 >>= 4; + i = 0; + while ( i < outlen4 ) + { + t = state[(int)i]; + [out + 4*i] = t; + i += 1; + } + + i <<= 2; + while ( i < outlen ) + { + t = (32u) state[u8 (int)i]; + (u8)[out + i] = (8u) t; + i += 1; + } + + out += outlen; + return out; +} + + +inline fn __squeeze_ref( + reg mut ptr u32[25*2] state, + stack u32 s_out, + reg u32 outlen, + reg u32 rate +) +{ + reg u32 out; + stack u32 s_outlen s_rate; + + // intermediate blocks + while ( outlen > rate ) + { + s_outlen = outlen; + s_rate = rate; + + state = _keccakf1600_ref(state); + + out = s_out; + outlen = s_outlen; + rate = s_rate; + + out, outlen = __xtr_full_block_ref(state, out, outlen, rate); + s_out = out; + } + + s_outlen = outlen; + + state = _keccakf1600_ref(state); + + out = s_out; + outlen = s_outlen; + + out = __xtr_bytes_ref(state, out, outlen); +} + + +inline fn __keccak1600_ref(reg u32 out outlen in inlen trail_byte rate) +{ + stack u32[25*2] _state; + reg ptr u32[25*2] state; + stack u32 s_out s_outlen; + stack u32 s_trail_byte; + + s_out = out; + s_outlen = outlen; + s_trail_byte = trail_byte; + + state = _state; + state = __keccak_init_ref(state); + + // absorb + state, rate = __absorb_ref(state, in, inlen, s_trail_byte, rate); + + // squeeze + outlen = s_outlen; + __squeeze_ref(state, s_out, outlen, rate); +} + + +#[returnaddress="stack"] +fn _keccak1600_ref(reg u32 out outlen in inlen trail_byte rate) +{ + __keccak1600_ref(out, outlen, in, inlen, trail_byte, rate); +} + + diff --git a/src/common/keccak/keccak1600/armv7m/ref/keccakf1600.jinc b/src/common/keccak/keccak1600/armv7m/ref/keccakf1600.jinc new file mode 100644 index 00000000..f35fc6a9 --- /dev/null +++ b/src/common/keccak/keccak1600/armv7m/ref/keccakf1600.jinc @@ -0,0 +1,370 @@ +param int KECCAK_ROUNDS=24; + +u32[24*2] KECCAK1600_RC = +{ + 0x00000001, 0x00000000, + 0x00008082, 0x00000000, + 0x0000808a, 0x80000000, + 0x80008000, 0x80000000, + 0x0000808b, 0x00000000, + 0x80000001, 0x00000000, + 0x80008081, 0x80000000, + 0x00008009, 0x80000000, + 0x0000008a, 0x00000000, + 0x00000088, 0x00000000, + 0x80008009, 0x00000000, + 0x8000000a, 0x00000000, + 0x8000808b, 0x00000000, + 0x0000008b, 0x80000000, + 0x00008089, 0x80000000, + 0x00008003, 0x80000000, + 0x00008002, 0x80000000, + 0x00000080, 0x80000000, + 0x0000800a, 0x00000000, + 0x8000000a, 0x80000000, + 0x80008081, 0x80000000, + 0x00008080, 0x80000000, + 0x80000001, 0x00000000, + 0x80008008, 0x80000000 +}; + +// disclaimer: this is a non-optimized implementation designed with the goal of +// being proven equivalent to the amd64 implementation; an optimized +// implementation (bit interleaving; lazy rotates; etc) is needed and it will +// be proven equivalent to this one. + +// ///////////////////////////////////////////////////////////////////////////// +// the following functions are the same for armv7-m and amd64; +// to do, think a bit more where to put them, maybe here is just fine + +inline fn __index_ref1(inline int x y) -> inline int +{ + inline int r; + r = (x % 5) + 5 * (y % 5); + return r; +} + + +inline fn __keccak_rho_offsets_ref1(inline int i) -> inline int +{ + inline int r x y z t; + + r = 0; + x = 1; + y = 0; + + for t = 0 to 24 { + if (i == x + 5 * y) { + r = ((t + 1) * (t + 2) / 2) % 64; + } + z = (2 * x + 3 * y) % 5; + x = y; + y = z; + } + + return r; +} + + +inline fn __rhotates_ref1(inline int x y) -> inline int +{ + inline int i r; + i = __index_ref1(x, y); + r = __keccak_rho_offsets_ref1(i); + return r; +} + + +// ///////////////////////////////////////////////////////////////////////////// + + +// r == 32 +inline fn __ROL_64_32(reg u32 h l) -> reg u32, reg u32 +{ + return l, h; +} + +// r < 32 +inline fn __ROL_64_L(reg u32 h l, inline int r) -> reg u32, reg u32 +{ + reg u32 x y; + + x = l; + y = h << r; + l = l << r; + l = l | (h >> (32-r)); + h = y | (x >> (32-r)); + + return h, l; +} + + +inline fn __ROL_64(reg u32 h l, inline int r) -> reg u32, reg u32 +{ + if(r == 32) + { + h, l = __ROL_64_32(h, l); + } + else if( r > 32 ) + { + h, l = __ROL_64_32(h, l); + h, l = __ROL_64_L(h, l, r-32); + } + else + { + h, l = __ROL_64_L(h, l, r); + } + return h, l; +} + + +// C[x] = A[x,0] ^ A[x,1] ^ A[x,2] ^ A[x,3] ^ A[x,4] +inline fn __theta_sum_ref(reg ptr u32[25*2] a) -> stack u32[5*2] +{ + inline int x y; + reg u32[5*2] c; + reg u32 t0 t1; + stack u32[5*2] cs; + + // C[x] = A[x, 0] + for x=0 to 5 + { c[2*x + 0] = a[2*x + 0]; + c[2*x + 1] = a[2*x + 1]; } + + // C[x] ^= A[x,1] ^ A[x,2] ^ A[x,3] ^ A[x,4] + for y=1 to 5 + { for x=0 to 5 + { t0 = a[2*(x + y*5)+0]; + t1 = a[2*(x + y*5)+1]; + + c[2*x+0] ^= t0; + c[2*x+1] ^= t1; + } + } + + cs = #copy(c); + + return cs; +} + + +// D[x] = C[x-1] ^ ROT(C[x+1], 1) +inline fn __theta_rol_ref(stack u32[5*2] c) -> stack u32[5*2] +{ + inline int x; + reg u32[5*2] d; + reg u32 t0 t1; + stack u32[5*2] ds; + + for x = 0 to 5 + { // D[x] = C[x + 1] : 1 2 3 4 0 + d[2*x+0] = c[2*((x + 1) % 5)+0]; + d[2*x+1] = c[2*((x + 1) % 5)+1]; + + // D[x] = ROT(D[x], 1) + d[2*x+1], d[2*x+0] = __ROL_64(d[2*x+1], d[2*x+0], 1); + + // D[x] ^= C[x-1] : 4 0 1 2 3 + t0 = c[2*((x - 1 + 5) % 5)+0]; + t1 = c[2*((x - 1 + 5) % 5)+1]; + + d[2*x+0] ^= t0; + d[2*x+1] ^= t1; + } + + ds = #copy(d); + + return ds; +} + + +// B[x] = ROT( (A[x',y'] ^ D[x']), r[x',y'] ) with (x',y') = M^-1 (x,y) +// +// M = (0 1) M^-1 = (1 3) x' = 1x + 3y +// (2 3) (1 0) y' = 1x + 0y +// +inline fn __rol_sum_ref( + reg ptr u32[25*2] a, + stack u32[5*2] d, + inline int y +) -> reg u32[5*2] +{ + inline int r x x_ y_; + reg u32[5*2] b; + reg u32 t0 t1; + + for x = 0 to 5 + { + x_ = (x + 3*y) % 5; + y_ = x; + r = __rhotates_ref1(x_, y_); + + // B[x] = A[x',y'] + b[2*x+0] = a[2*(x_ + y_*5)+0]; + b[2*x+1] = a[2*(x_ + y_*5)+1]; + + // B[x] ^= D[x']; + t0 = d[2*x_+0]; + t1 = d[2*x_+1]; + b[2*x+0] ^= t0; + b[2*x+1] ^= t1; + + // B[x] = ROT( B[x], r[x',y'] ); + if(r != 0) + { b[2*x+1], b[2*x+0] = __ROL_64(b[2*x+1], b[2*x+0], r); } + } + + return b; +} + + +// E[x, y] = B[x] ^ ( (!B[x+1]) & B[x+2] ) +// -- when x and y are 0: E[0,0] ^= RC[i]; +inline fn __set_row_ref( + stack ptr u32[25*2] e_s, + reg u32[5*2] b, + inline int y, + stack u32 rc0_s, + stack u32 rc1_s +) -> stack ptr u32[25*2] +{ + inline int x x1 x2; + reg u32 t0 t1 rc0 rc1; + reg ptr u32[24*2] RC; + reg ptr u32[25*2] e; + + for x=0 to 5 + { + x1 = (x + 1) % 5; + x2 = (x + 2) % 5; + + //t = !b[x1] & b[x2]; + t0 = #BIC(b[2*x2+0], b[2*x1+0]); + t1 = #BIC(b[2*x2+1], b[2*x1+1]); + + t0 ^= b[2*x+0]; + t1 ^= b[2*x+1]; + + if( x==0 && y==0 ) + { rc0 = rc0_s; t0 ^= rc0; + rc1 = rc1_s; t1 ^= rc1; + } + + e = e_s; + e[2*(x + y*5)+0] = t0; + e[2*(x + y*5)+1] = t1; + e_s = e; + } + + return e_s; +} + +inline fn __round_ref(reg ptr u32[25*2] e a, reg u32 rc0 rc1) -> reg ptr u32[25*2] +{ + stack ptr u32[25*2] e_s a_s; + stack u32 rc0_s rc1_s; + stack u32[5*2] c d; + inline int y; + reg u32[5*2] b; + + e_s = e; + rc0_s = rc0; + rc1_s = rc1; + + c = __theta_sum_ref(a); + d = __theta_rol_ref(c); + + for y = 0 to 5 + { b = __rol_sum_ref(a, d, y); + e_s = __set_row_ref(e_s, b, y, rc0_s, rc1_s); + } + + e = e_s; + + return e; +} + + +#[returnaddress=stack] +fn _round_ref(reg ptr u32[25*2] e a, reg u32 rc0 rc1) -> reg ptr u32[25*2] +{ + e = __round_ref(e, a, rc0, rc1); + return e; +} + + +inline fn __get_RC( + stack ptr u32[24*2] s_RC, + reg u32 c) + -> + reg u32, + reg u32, + reg u32 +{ + reg ptr u32[24*2] RC; + reg u32 rc0 rc1; + + RC = s_RC; + + rc0 = RC[(int) c]; + c += 1; + rc1 = RC[(int) c]; + c += 1; + + return rc1, rc0, c; +} + + +inline fn __keccakf1600_ref(reg ptr u32[25*2] a) -> reg ptr u32[25*2] +{ + reg ptr u32[24*2] RC; + stack ptr u32[24*2] RC_s; + stack ptr u32[25*2] a_s; + reg ptr u32[25*2] e; + stack u32[25*2] s_e; + reg u32 rc0 rc1 c; + stack u32 c_s; + + e = s_e; + RC = KECCAK1600_RC; + RC_s = RC; + + c = 0; + while (c < KECCAK_ROUNDS*2) + { + rc1, rc0, c = __get_RC(RC_s, c); c_s = c; + e = _round_ref(e, a, rc0, rc1); + + + a_s = a; s_e = e; // swap 'e' and 'a' (in practice this is just "pointer swapping", to do, improve) + a = a_s; e = s_e; + + c = c_s; + rc1, rc0, c = __get_RC(RC_s, c); c_s = c; + a = _round_ref(a, e, rc0, rc1); + + a_s = a; s_e = e; // swap again + a = a_s; e = s_e; + + c = c_s; + } + + return a; +} + + +#[returnaddress=stack] +fn _keccakf1600_ref(reg ptr u32[25*2] a) -> reg ptr u32[25*2] +{ + a = __keccakf1600_ref(a); + return a; +} + + +inline fn _keccakf1600_ref_(reg ptr u32[25*2] a) -> reg ptr u32[25*2] +{ + a = a; + a = _keccakf1600_ref(a); + a = a; + return a; +} diff --git a/src/crypto_hash/sha256/armv7m/ref/Makefile b/src/crypto_hash/sha256/armv7m/ref/Makefile new file mode 100644 index 00000000..586e8a2f --- /dev/null +++ b/src/crypto_hash/sha256/armv7m/ref/Makefile @@ -0,0 +1,3 @@ +override JFLAGS += -arch arm-m4 +SRCS := hash.jazz +include ../../../../Makefile.common diff --git a/src/crypto_hash/sha256/armv7m/ref/hash.jazz b/src/crypto_hash/sha256/armv7m/ref/hash.jazz new file mode 100644 index 00000000..07996721 --- /dev/null +++ b/src/crypto_hash/sha256/armv7m/ref/hash.jazz @@ -0,0 +1,10 @@ +require "sha256.jinc" + +export fn jade_hash_sha256_armv7m_ref(reg u32 hash input input_length) -> reg u32 +{ + reg u32 r; + __sha256_ref(hash, input, input_length); + r = 0; + return r; +} + diff --git a/src/crypto_hash/sha256/armv7m/ref/include/api.h b/src/crypto_hash/sha256/armv7m/ref/include/api.h new file mode 100644 index 00000000..ac5bca50 --- /dev/null +++ b/src/crypto_hash/sha256/armv7m/ref/include/api.h @@ -0,0 +1,18 @@ +#ifndef JADE_HASH_sha256_armv7m_ref_API_H +#define JADE_HASH_sha256_armv7m_ref_API_H + +#define JADE_HASH_sha256_armv7m_ref_BYTES 32 + +#define JADE_HASH_sha256_armv7m_ref_ALGNAME "SHA256" +#define JADE_HASH_sha256_armv7m_ref_ARCH "armv7m" +#define JADE_HASH_sha256_armv7m_ref_IMPL "ref" + +#include + +int jade_hash_sha256_armv7m_ref( + uint8_t *hash, + const uint8_t *input, + uint32_t input_length +); + +#endif diff --git a/src/crypto_hash/sha256/armv7m/ref/sha256.jinc b/src/crypto_hash/sha256/armv7m/ref/sha256.jinc new file mode 100644 index 00000000..0f9f86cf --- /dev/null +++ b/src/crypto_hash/sha256/armv7m/ref/sha256.jinc @@ -0,0 +1,399 @@ + +require "sha256_globals.jinc" + +inline fn __initH_ref(reg ptr u32[8] H) -> reg ptr u32[8] +{ + inline int i; + reg ptr u32[8] H0; + reg u32 t; + + H0 = SHA256_H0; + + for i=0 to 8 + { t = H0[i]; + H[i] = t; } + + return H; +} + +inline fn __load_H_ref(reg ptr u32[8] H) -> reg u32, reg u32, reg u32, reg u32, + reg u32, reg u32, reg u32, reg u32 +{ + reg u32 a b c d e f g h; + + a = H[0]; + b = H[1]; + c = H[2]; + d = H[3]; + e = H[4]; + f = H[5]; + g = H[6]; + h = H[7]; + + return a, b, c, d, e, f, g, h; +} + +inline fn __store_H_ref(reg ptr u32[8] H, reg u32 a b c d e f g h) -> reg ptr u32[8] +{ + H[0] = a; + H[1] = b; + H[2] = c; + H[3] = d; + H[4] = e; + H[5] = f; + H[6] = g; + H[7] = h; + + return H; +} + +inline fn __store_ref(reg u32 out, reg ptr u32[8] H) +{ + inline int i; + reg u32 v; + + for i=0 to 8 + { v = H[i]; + v = #REV(v); + (u32)[out + i*4] = v; + } +} + +inline fn __SHR_ref(reg u32 x, inline int c) -> reg u32 +{ + reg u32 r; + r = x; + r >>= c; + return r; +} + +inline fn __ROTR_ref(reg u32 x, inline int c) -> reg u32 +{ + reg u32 r; + r = x; + r = #ROR(r, c); + return r; +} + +//(x & y) ^ (!x & z) +inline fn __CH_ref(reg u32 x y z) -> reg u32 +{ + reg u32 r s; + + r = x; + r &= y; + s = x; + s = !s; + s &= z; + r ^= s; + + return r; +} + +//(x & y) ^ (x & z) ^ (y & z) +inline fn __MAJ_ref(reg u32 x y z) -> reg u32 +{ + reg u32 r s; + + r = x; + r &= y; + s = x; + s &= z; + r ^= s; + s = y; + s &= z; + r ^= s; + + return r; +} + +// (x >>> 2) ^ (x >>> 13) ^ (x >>> 22) +inline fn __BSIG0_ref(reg u32 x) -> reg u32 +{ + reg u32 r s; + + r = __ROTR_ref(x, 2); + s = __ROTR_ref(x,13); + r ^= s; + s = __ROTR_ref(x,22); + r ^= s; + + return r; +} + +// (x >>> 6) ^ (x >>> 11) ^ (x >>> 25) +inline fn __BSIG1_ref(reg u32 x) -> reg u32 +{ + reg u32 r s; + + r = __ROTR_ref(x, 6); + s = __ROTR_ref(x,11); + r ^= s; + s = __ROTR_ref(x,25); + r ^= s; + + return r; +} + +// (x >>> 7) ^ (x >>> 18) ^ (x >> 3) +inline fn __SSIG0_ref(reg u32 x) -> reg u32 +{ + reg u32 r s; + + r = __ROTR_ref(x, 7); + s = __ROTR_ref(x,18); + r ^= s; + s = __SHR_ref(x,3); + r ^= s; + + return r; +} + +// (x >>> 17) ^ (x >>> 19) ^ (x >> 10) +inline fn __SSIG1_ref(reg u32 x) -> reg u32 +{ + reg u32 r s; + + r = __ROTR_ref(x,17); + s = __ROTR_ref(x,19); + r ^= s; + s = __SHR_ref(x,10); + r ^= s; + + return r; +} + +// Wt = SSIG1(W(t-2)) + W(t-7) + SSIG0(t-15) + W(t-16) +inline fn __Wt_ref(reg ptr u32[64] W, reg u32 t) -> reg ptr u32[64] +{ + reg u32 wt wt2 wt7 wt16 wt15; + + t -= 2; + wt2 = W[(int)t]; // -2 + wt = __SSIG1_ref(wt2); t -= 5; + wt7 = W[(int)t]; // -7 + wt += wt7; t -= 8; + wt15 = W[(int)t]; // -15 + wt15 = __SSIG0_ref(wt15); + wt += wt15; t -= 1; + wt16 = W[(int)t]; // -16 + wt += wt16; + t += 16; + W[(int)t] = wt; + + return W; +} + +#[returnaddress="stack"] +fn _blocks_inner(reg ptr u32[64] W, reg ptr u32[8] H) -> reg ptr u32[64], reg ptr u32[8] +{ + reg u32 a b c d e f g h r T1 T2 Kt Wt i t; + stack u32 ts ds hs; + + reg ptr u32[64] K; + K = SHA256_K; + + i = 16; + while(i < 64) + { W = __Wt_ref(W, i); + i += 1; + } + + a, b, c, d, e, f, g, h = __load_H_ref(H); + ds = d; + hs = h; + + t = 0; + while(t < 64) + { + ts = t; + + //T1 = h + BSIG1(e) + CH(e,f,g) + Kt + Wt + r = __BSIG1_ref(e); + T1 = hs; + T1 += r; + r = __CH_ref(e,f,g); + T1 += r; + + Kt = K[(int)t]; + T1 += Kt; + + Wt = W[(int)t]; + T1 += Wt; + + //T2 = BSIG0(a) + MAJ(a,b,c) + T2 = __BSIG0_ref(a); + r = __MAJ_ref(a,b,c); + T2 += r; + + hs = g; + g = f; + f = e; + e = ds; + e += T1; + ds = c; + c = b; + b = a; + a = T1; + a += T2; + + t = ts; + t += 1; + } + + d = ds; + h = hs; + + t = H[0]; + a += t; t = H[1]; + b += t; t = H[2]; + c += t; t = H[3]; + d += t; t = H[4]; + e += t; t = H[5]; + f += t; t = H[6]; + g += t; t = H[7]; + h += t; + + H = __store_H_ref(H,a,b,c,d,e,f,g,h); + + return W, H; +} + +inline fn _blocks_0_ref(reg ptr u32[8] H, reg u32 in, reg u32 inlen) -> reg ptr u32[8], reg u32, reg u32 +{ + inline int t; + reg u32 v; + stack u32 in_s inlen_s; + stack u32[64] _W; + reg ptr u32[64] W K; + + W = _W; + + while(inlen >= 64) + { + for t=0 to 16 + { v = (u32)[in + t*4]; + v = #REV(v); + W[t] = v; + } + + in_s = in; + inlen_s = inlen; + + W, H = _blocks_inner(W, H); + + in = in_s; + inlen = inlen_s; + + in += 64; + inlen -= 64; + } + + return H, in, inlen; +} + +inline fn _blocks_1_ref(reg ptr u32[8] H, reg ptr u32[32] blocks, reg u32 nblocks) -> reg ptr u32[8] +{ + inline int t; + reg u32 i v oblocks; + stack u32 i_s nblocks_s; + stack u32[64] _W; + reg ptr u32[64] W K; + + W = _W; + + // nblocks can be 1 or 2 => the following loop executes at most 2 times + // - for the first loop execution: index for blocks is 0; for the second is 16 + // - hence, nblocks << 4 and i += 16 + i = 0; + nblocks <<= 4; + nblocks_s = nblocks; + + while(i < nblocks) + { + for t=0 to 16 + { v = blocks[(int)i]; + i += 1; + v = #REV(v); + W[t] = v; + } + i_s = i; + + W, H = _blocks_inner(W, H); + + i = i_s; + nblocks = nblocks_s; + } + + return H; +} + +inline fn __lastblocks_ref(reg ptr u32[32] blocks, reg u32 in inlen bits) -> stack u32[32], reg u32 +{ + reg u32 zero i v j nblocks; + + // Zero-fill the blocks array + zero = 0; + i = 0; + while(i < 32) + { blocks[(int)i] = zero; + i += 1; + } + + // copy in to blocks + i = 0; + while(i < inlen) + { v = (32u)(u8)[in + i]; + blocks[u8 (int)i] = (8u) v; + i += 1; + } + + // set first byte after input to 0x80 + v = 0x80; + blocks[u8 (int)i] = (8u) v; + + + // check if one or two blocks are needed + if(inlen < 56) // 448 / 8 = 56 + { j = (64-4); nblocks = 1; i = 63; } + else + { j = (128-4); nblocks = 2; i = 127; } + + while(i >= j) + { blocks[u8 (int)i] = (8u) bits; + bits >>= 8; + i -= 1; + } + + return blocks, nblocks; +} + +inline fn __sha256_ref(reg u32 out in, reg u32 inlen) +{ + stack u32 s_out s_inlen; + reg u32 bits nblocks; + + stack u32[8] _H; + reg ptr u32[8] H; + stack u32[32] _blocks; + reg ptr u32[32] blocks; + + H = _H; + + s_out = out; + s_inlen = inlen; + + H = __initH_ref(H); + H, in, inlen = _blocks_0_ref(H, in, inlen); + + blocks = _blocks; + bits = s_inlen; + bits <<= 3; + blocks, nblocks = __lastblocks_ref(blocks, in, inlen, bits); + + H = _blocks_1_ref(H, blocks, nblocks); + + out = s_out; + __store_ref(out, H); +} + diff --git a/src/crypto_hash/sha256/armv7m/ref/sha256_globals.jinc b/src/crypto_hash/sha256/armv7m/ref/sha256_globals.jinc new file mode 100644 index 00000000..b9d4ceec --- /dev/null +++ b/src/crypto_hash/sha256/armv7m/ref/sha256_globals.jinc @@ -0,0 +1,31 @@ + +u32[64] SHA256_K = { + 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5, + 0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, + 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3, + 0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174, + 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc, + 0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da, + 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7, + 0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967, + 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13, + 0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85, + 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3, + 0xd192e819,0xd6990624,0xf40e3585,0x106aa070, + 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5, + 0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3, + 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208, + 0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 +}; + +u32[8] SHA256_H0 = { + 0x6a09e667, + 0xbb67ae85, + 0x3c6ef372, + 0xa54ff53a, + 0x510e527f, + 0x9b05688c, + 0x1f83d9ab, + 0x5be0cd19 +}; + diff --git a/src/crypto_hash/sha3-224/armv7m/ref/Makefile b/src/crypto_hash/sha3-224/armv7m/ref/Makefile new file mode 100644 index 00000000..586e8a2f --- /dev/null +++ b/src/crypto_hash/sha3-224/armv7m/ref/Makefile @@ -0,0 +1,3 @@ +override JFLAGS += -arch arm-m4 +SRCS := hash.jazz +include ../../../../Makefile.common diff --git a/src/crypto_hash/sha3-224/armv7m/ref/hash.jazz b/src/crypto_hash/sha3-224/armv7m/ref/hash.jazz new file mode 100644 index 00000000..cda5fbea --- /dev/null +++ b/src/crypto_hash/sha3-224/armv7m/ref/hash.jazz @@ -0,0 +1,11 @@ +require "sha3-224.jinc" + +export fn jade_hash_sha3_224_armv7m_ref(reg u32 hash input input_length) -> reg u32 +{ + reg u32 r; + __sha3_224_ref(hash, input, input_length); + r = 0; + return r; +} + + diff --git a/src/crypto_hash/sha3-224/armv7m/ref/include/api.h b/src/crypto_hash/sha3-224/armv7m/ref/include/api.h new file mode 100644 index 00000000..27485bd7 --- /dev/null +++ b/src/crypto_hash/sha3-224/armv7m/ref/include/api.h @@ -0,0 +1,17 @@ +#ifndef JADE_HASH_sha3_224_armv7m_ref_API_H +#define JADE_HASH_sha3_224_armv7m_ref_API_H + +#define JADE_HASH_sha3_224_armv7m_ref_BYTES 28 +#define JADE_HASH_sha3_224_armv7m_ref_ALGNAME "SHA3-224" +#define JADE_HASH_sha3_224_armv7m_ref_ARCH "armv7m" +#define JADE_HASH_sha3_224_armv7m_ref_IMPL "ref" + +#include + +int jade_hash_sha3_224_armv7m_ref( + uint8_t *hash, + const uint8_t *input, + uint32_t input_length +); + +#endif diff --git a/src/crypto_hash/sha3-224/armv7m/ref/sha3-224.jinc b/src/crypto_hash/sha3-224/armv7m/ref/sha3-224.jinc new file mode 100644 index 00000000..8f5be299 --- /dev/null +++ b/src/crypto_hash/sha3-224/armv7m/ref/sha3-224.jinc @@ -0,0 +1,14 @@ +from Jade require "common/keccak/keccak1600/armv7m/ref/keccak1600.jinc" + +inline fn __sha3_224_ref(reg u32 out in inlen) +{ + reg u32 outlen rate trail_byte; + + outlen = (224/8); + trail_byte = 0x6; + rate = (1152/8); + + _keccak1600_ref(out, outlen, in, inlen, trail_byte, rate); +} + + diff --git a/src/crypto_hash/sha3-256/armv7m/ref/Makefile b/src/crypto_hash/sha3-256/armv7m/ref/Makefile new file mode 100644 index 00000000..586e8a2f --- /dev/null +++ b/src/crypto_hash/sha3-256/armv7m/ref/Makefile @@ -0,0 +1,3 @@ +override JFLAGS += -arch arm-m4 +SRCS := hash.jazz +include ../../../../Makefile.common diff --git a/src/crypto_hash/sha3-256/armv7m/ref/hash.jazz b/src/crypto_hash/sha3-256/armv7m/ref/hash.jazz new file mode 100644 index 00000000..8ef4726a --- /dev/null +++ b/src/crypto_hash/sha3-256/armv7m/ref/hash.jazz @@ -0,0 +1,11 @@ +require "sha3-256.jinc" + +export fn jade_hash_sha3_256_armv7m_ref(reg u32 hash input input_length) -> reg u32 +{ + reg u32 r; + __sha3_256_ref(hash, input, input_length); + r = 0; + return r; +} + + diff --git a/src/crypto_hash/sha3-256/armv7m/ref/include/api.h b/src/crypto_hash/sha3-256/armv7m/ref/include/api.h new file mode 100644 index 00000000..78185cae --- /dev/null +++ b/src/crypto_hash/sha3-256/armv7m/ref/include/api.h @@ -0,0 +1,18 @@ +#ifndef JADE_HASH_sha3_256_armv7m_ref_API_H +#define JADE_HASH_sha3_256_armv7m_ref_API_H + +#define JADE_HASH_sha3_256_armv7m_ref_BYTES 32 + +#define JADE_HASH_sha3_256_armv7m_ref_ALGNAME "SHA3-256" +#define JADE_HASH_sha3_256_armv7m_ref_ARCH "armv7m" +#define JADE_HASH_sha3_256_armv7m_ref_IMPL "ref" + +#include + +int jade_hash_sha3_256_armv7m_ref( + uint8_t *hash, + const uint8_t *input, + uint32_t input_length +); + +#endif diff --git a/src/crypto_hash/sha3-256/armv7m/ref/sha3-256.jinc b/src/crypto_hash/sha3-256/armv7m/ref/sha3-256.jinc new file mode 100644 index 00000000..b1b1c61d --- /dev/null +++ b/src/crypto_hash/sha3-256/armv7m/ref/sha3-256.jinc @@ -0,0 +1,14 @@ +from Jade require "common/keccak/keccak1600/armv7m/ref/keccak1600.jinc" + +inline fn __sha3_256_ref(reg u32 out in inlen) +{ + reg u32 outlen rate trail_byte; + + outlen = (256/8); + trail_byte = 0x6; + rate = (1088/8); + + _keccak1600_ref(out, outlen, in, inlen, trail_byte, rate); +} + + diff --git a/src/crypto_hash/sha3-384/armv7m/ref/Makefile b/src/crypto_hash/sha3-384/armv7m/ref/Makefile new file mode 100644 index 00000000..586e8a2f --- /dev/null +++ b/src/crypto_hash/sha3-384/armv7m/ref/Makefile @@ -0,0 +1,3 @@ +override JFLAGS += -arch arm-m4 +SRCS := hash.jazz +include ../../../../Makefile.common diff --git a/src/crypto_hash/sha3-384/armv7m/ref/hash.jazz b/src/crypto_hash/sha3-384/armv7m/ref/hash.jazz new file mode 100644 index 00000000..edf5cde7 --- /dev/null +++ b/src/crypto_hash/sha3-384/armv7m/ref/hash.jazz @@ -0,0 +1,11 @@ +require "sha3-384.jinc" + +export fn jade_hash_sha3_384_armv7m_ref(reg u32 hash input input_length) -> reg u32 +{ + reg u32 r; + __sha3_384_ref(hash, input, input_length); + r = 0; + return r; +} + + diff --git a/src/crypto_hash/sha3-384/armv7m/ref/include/api.h b/src/crypto_hash/sha3-384/armv7m/ref/include/api.h new file mode 100644 index 00000000..da5bb04d --- /dev/null +++ b/src/crypto_hash/sha3-384/armv7m/ref/include/api.h @@ -0,0 +1,18 @@ +#ifndef JADE_HASH_sha3_384_armv7m_ref_API_H +#define JADE_HASH_sha3_384_armv7m_ref_API_H + +#define JADE_HASH_sha3_384_armv7m_ref_BYTES 48 + +#define JADE_HASH_sha3_384_armv7m_ref_ALGNAME "SHA3-384" +#define JADE_HASH_sha3_384_armv7m_ref_ARCH "armv7m" +#define JADE_HASH_sha3_384_armv7m_ref_IMPL "ref" + +#include + +int jade_hash_sha3_384_armv7m_ref( + uint8_t *hash, + const uint8_t *input, + uint32_t input_length +); + +#endif diff --git a/src/crypto_hash/sha3-384/armv7m/ref/sha3-384.jinc b/src/crypto_hash/sha3-384/armv7m/ref/sha3-384.jinc new file mode 100644 index 00000000..47cf7a3f --- /dev/null +++ b/src/crypto_hash/sha3-384/armv7m/ref/sha3-384.jinc @@ -0,0 +1,14 @@ +from Jade require "common/keccak/keccak1600/armv7m/ref/keccak1600.jinc" + +inline fn __sha3_384_ref(reg u32 out in inlen) +{ + reg u32 outlen rate trail_byte; + + outlen = (384/8); + trail_byte = 0x6; + rate = (832/8); + + _keccak1600_ref(out, outlen, in, inlen, trail_byte, rate); +} + + diff --git a/src/crypto_hash/sha3-512/armv7m/ref/Makefile b/src/crypto_hash/sha3-512/armv7m/ref/Makefile new file mode 100644 index 00000000..586e8a2f --- /dev/null +++ b/src/crypto_hash/sha3-512/armv7m/ref/Makefile @@ -0,0 +1,3 @@ +override JFLAGS += -arch arm-m4 +SRCS := hash.jazz +include ../../../../Makefile.common diff --git a/src/crypto_hash/sha3-512/armv7m/ref/hash.jazz b/src/crypto_hash/sha3-512/armv7m/ref/hash.jazz new file mode 100644 index 00000000..59e5ea01 --- /dev/null +++ b/src/crypto_hash/sha3-512/armv7m/ref/hash.jazz @@ -0,0 +1,11 @@ +require "sha3-512.jinc" + +export fn jade_hash_sha3_512_armv7m_ref(reg u32 hash input input_length) -> reg u32 +{ + reg u32 r; + __sha3_512_ref(hash, input, input_length); + r = 0; + return r; +} + + diff --git a/src/crypto_hash/sha3-512/armv7m/ref/include/api.h b/src/crypto_hash/sha3-512/armv7m/ref/include/api.h new file mode 100644 index 00000000..556482a7 --- /dev/null +++ b/src/crypto_hash/sha3-512/armv7m/ref/include/api.h @@ -0,0 +1,18 @@ +#ifndef JADE_HASH_sha3_512_armv7m_ref_API_H +#define JADE_HASH_sha3_512_armv7m_ref_API_H + +#define JADE_HASH_sha3_512_armv7m_ref_BYTES 64 + +#define JADE_HASH_sha3_512_armv7m_ref_ALGNAME "SHA3-512" +#define JADE_HASH_sha3_512_armv7m_ref_ARCH "armv7m" +#define JADE_HASH_sha3_512_armv7m_ref_IMPL "ref" + +#include + +int jade_hash_sha3_512_armv7m_ref( + uint8_t *hash, + const uint8_t *input, + uint32_t input_length +); + +#endif diff --git a/src/crypto_hash/sha3-512/armv7m/ref/sha3-512.jinc b/src/crypto_hash/sha3-512/armv7m/ref/sha3-512.jinc new file mode 100644 index 00000000..102c5e51 --- /dev/null +++ b/src/crypto_hash/sha3-512/armv7m/ref/sha3-512.jinc @@ -0,0 +1,14 @@ +from Jade require "common/keccak/keccak1600/armv7m/ref/keccak1600.jinc" + +inline fn __sha3_512_ref(reg u32 out in inlen) +{ + reg u32 outlen rate trail_byte; + + outlen = (512/8); + trail_byte = 0x6; + rate = (576/8); + + _keccak1600_ref(out, outlen, in, inlen, trail_byte, rate); +} + + diff --git a/src/crypto_stream/chacha/chacha20/armv7m/ref/Makefile b/src/crypto_stream/chacha/chacha20/armv7m/ref/Makefile new file mode 100644 index 00000000..e7b9fa96 --- /dev/null +++ b/src/crypto_stream/chacha/chacha20/armv7m/ref/Makefile @@ -0,0 +1,8 @@ +default0: compile stream_temp.s + +override JFLAGS += -arch arm-m4 +SRCS := stream.jazz +include ../../../../../Makefile.common + +stream_temp.s: stream_temp.c + $(CC) $(CFLAGS) -S -o $@ $< diff --git a/src/crypto_stream/chacha/chacha20/armv7m/ref/include/api.h b/src/crypto_stream/chacha/chacha20/armv7m/ref/include/api.h new file mode 100644 index 00000000..ddcc0c6f --- /dev/null +++ b/src/crypto_stream/chacha/chacha20/armv7m/ref/include/api.h @@ -0,0 +1,28 @@ +#ifndef JADE_STREAM_chacha_chacha20_armv7m_ref_API_H +#define JADE_STREAM_chacha_chacha20_armv7m_ref_API_H + +#define JADE_STREAM_chacha_chacha20_armv7m_ref_KEYBYTES 32 +#define JADE_STREAM_chacha_chacha20_armv7m_ref_NONCEBYTES 8 + +#define JADE_STREAM_chacha_chacha20_armv7m_ref_ALGNAME "ChaCha20" +#define JADE_STREAM_chacha_chacha20_armv7m_ref_ARCH "ARMv7-M" +#define JADE_STREAM_chacha_chacha20_armv7m_ref_IMPL "ref" + +#include + +int jade_stream_chacha_chacha20_armv7m_ref_xor( + uint8_t *output, // output[output_length] + const uint8_t *input, // input[input_length] + uint32_t input_length, // + const uint8_t *nonce, // nonce[NONCEBYTES] + const uint8_t *key // key[KEYBYTES] +); + +int jade_stream_chacha_chacha20_armv7m_ref( + uint8_t *stream, // stream[stream_length] + uint32_t stream_length, + const uint8_t *nonce, // nonce[NONCEBYTES] + const uint8_t *key // key[KEYBYTES] +); + +#endif diff --git a/src/crypto_stream/chacha/chacha20/armv7m/ref/stream.jazz b/src/crypto_stream/chacha/chacha20/armv7m/ref/stream.jazz new file mode 100644 index 00000000..2cdecc9b --- /dev/null +++ b/src/crypto_stream/chacha/chacha20/armv7m/ref/stream.jazz @@ -0,0 +1,28 @@ +param int CHACHA_ROUNDS=20; + +from Jade require "crypto_stream/chacha/common/armv7m/ref/chacha.jinc" + +// TODO: nonce_key -> nonce, key when support from jasminc > 4 args +export fn jade_stream_chacha_chacha20_armv7m_ref_xor_temporary(reg u32 output input input_length nonce_key) -> reg u32 +{ + reg u32 r nonce key; + + nonce = (u32)[nonce_key + 0]; + key = (u32)[nonce_key + 4]; + + __chacha_xor_ref(output, input, input_length, nonce, key); + + r = 0; + return r; +} + +export fn jade_stream_chacha_chacha20_armv7m_ref(reg u32 stream stream_length nonce key) -> reg u32 +{ + reg u32 r; + + __chacha_ref(stream, stream_length, nonce, key); + + r = 0; + return r; +} + diff --git a/src/crypto_stream/chacha/chacha20/armv7m/ref/stream_temp.c b/src/crypto_stream/chacha/chacha20/armv7m/ref/stream_temp.c new file mode 100644 index 00000000..f5760d7a --- /dev/null +++ b/src/crypto_stream/chacha/chacha20/armv7m/ref/stream_temp.c @@ -0,0 +1,29 @@ +#include +#include + +extern int jade_stream_chacha_chacha20_armv7m_ref_xor_temporary( + uint8_t *output, // output[input_length] + const uint8_t *input, // input[input_length] + uint32_t input_length, // + uint8_t **nonce_key // nonce_key[0] == nonce[NONCEBYTES]; nonce_key[1] = key[KEYBYTES] +); + +int jade_stream_chacha_chacha20_armv7m_ref_xor( + uint8_t *output, // output[output_length] + uint8_t *input, // input[input_length] + uint32_t input_length, // + uint8_t *nonce, // nonce[NONCEBYTES] + uint8_t *key // key[KEYBYTES] +) +{ + int r; + uint8_t *nonce_key[2]; + + nonce_key[0] = nonce; + nonce_key[1] = key; + + r = jade_stream_chacha_chacha20_armv7m_ref_xor_temporary(output, input, input_length, nonce_key); + + return r; +} + diff --git a/src/crypto_stream/chacha/common/armv7m/ref/chacha.jinc b/src/crypto_stream/chacha/common/armv7m/ref/chacha.jinc new file mode 100644 index 00000000..8af2aae8 --- /dev/null +++ b/src/crypto_stream/chacha/common/armv7m/ref/chacha.jinc @@ -0,0 +1,3 @@ +require "chacha_state.jinc" +require "chacha_store.jinc" +require "chacha_core.jinc" diff --git a/src/crypto_stream/chacha/common/armv7m/ref/chacha_core.jinc b/src/crypto_stream/chacha/common/armv7m/ref/chacha_core.jinc new file mode 100644 index 00000000..a9cc77cc --- /dev/null +++ b/src/crypto_stream/chacha/common/armv7m/ref/chacha_core.jinc @@ -0,0 +1,160 @@ +// the following implementation requires: +// - (even) param int CHACHA_ROUNDS; +// - inline fn __init_ref(reg u64 nonce key) -> stack u32[16] (check chacha_state.jinc) +// - inline fn __increment_counter_ref(stack u32[16] state) -> stack u32[16] (check chacha_state.jinc) + +fn _copy_state_ref(reg ptr u32[16] k st) -> reg ptr u32[16] +{ + reg u32 i t; + + i = 0; + while(i < 16) + { t = st[(int)i]; + k[(int)i] = t; + i += 1; + } + + return k; +} + +inline fn __line_ref(reg ptr u32[16] k, inline int a b c r) -> reg ptr u32[16] +{ + reg u32 ka kb kc; + + ka = k[a]; + kb = k[b]; + kc = k[c]; + + ka += kb; + kc ^= ka; + kc = #ROR(kc, (32-r)); + + k[a] = ka; + k[c] = kc; + + return k; +} + +inline fn __quarter_round_ref(reg ptr u32[16] k, inline int a b c d) -> reg ptr u32[16] +{ + k = __line_ref(k, a, b, d, 16); + k = __line_ref(k, c, d, b, 12); + k = __line_ref(k, a, b, d, 8); + k = __line_ref(k, c, d, b, 7); + return k; +} + +inline fn __column_round_ref(reg ptr u32[16] k) -> reg ptr u32[16] +{ + k = __quarter_round_ref(k, 0, 4, 8, 12); + k = __quarter_round_ref(k, 1, 5, 9, 13); + k = __quarter_round_ref(k, 2, 6, 10, 14); + k = __quarter_round_ref(k, 3, 7, 11, 15); + return k; +} + +inline fn __diagonal_round_ref(reg ptr u32[16] k) -> reg ptr u32[16] +{ + k = __quarter_round_ref(k, 0, 5, 10, 15); + k = __quarter_round_ref(k, 1, 6, 11, 12); + k = __quarter_round_ref(k, 2, 7, 8, 13); + k = __quarter_round_ref(k, 3, 4, 9, 14); + return k; +} + +// TODO: write compact version of this: line_ref args from inline to reg +inline fn __double_round_ref(reg ptr u32[16] k) -> reg ptr u32[16] +{ + k = __column_round_ref(k); + k = __diagonal_round_ref(k); + return k; +} + +fn _rounds_ref(reg ptr u32[16] k) -> reg ptr u32[16] +{ + reg bool zf; + reg u32 c; + + c = (CHACHA_ROUNDS/2); + while + { k = __double_round_ref(k); + _, zf, _, _, c = #SUBS(c, 1); + } (!zf) + + return k; +} + +fn _sum_states_ref(reg ptr u32[16] k st) -> reg ptr u32[16] +{ + reg u32 i tk tst; + + i = 0; + while(i < 16) + { + tk = k[(int)i]; + tst = st[(int)i]; + tk += tst; + k[(int)i] = tk; + + i += 1; + } + + return k; +} + +inline fn __chacha_xor_ref(reg u32 output plain len nonce key) +{ + stack u32[16] k st; + reg ptr u32[16] kp stp; + + kp = k; + stp = st; + + nonce = nonce; // allow register swap + key = key; // same. + + stp = _init_ref(stp, nonce, key); + + while (len >= 64) + { kp = _copy_state_ref(kp, stp); + kp = _rounds_ref(kp); + output, plain, len = __sum_states_store_xor_ref(output, plain,len, kp, stp); + stp = __increment_counter_ref(stp); + } + + if(len > 0) + { kp = _copy_state_ref(kp, stp); + kp = _rounds_ref(kp); + kp = _sum_states_ref(kp, stp); + __store_xor_last_ref(output, plain, len, kp); + } +} + +inline fn __chacha_ref(reg u32 output len nonce key) +{ + stack u32[16] k st; + reg ptr u32[16] kp stp; + + kp = k; + stp = st; + + nonce = nonce; // allow register swap + key = key; // same. + + stp = _init_ref(stp, nonce, key); + + while (len >= 64) + { kp = _copy_state_ref(kp, stp); + kp = _rounds_ref(kp); + output, len = __sum_states_store_ref(output, len, kp, stp); + stp = __increment_counter_ref(stp); + } + + if(len > 0) + { kp = _copy_state_ref(kp, stp); + kp = _rounds_ref(kp); + kp = _sum_states_ref(kp, stp); + __store_last_ref(output, len, kp); + } +} + diff --git a/src/crypto_stream/chacha/common/armv7m/ref/chacha_state.jinc b/src/crypto_stream/chacha/common/armv7m/ref/chacha_state.jinc new file mode 100644 index 00000000..83fd6d74 --- /dev/null +++ b/src/crypto_stream/chacha/common/armv7m/ref/chacha_state.jinc @@ -0,0 +1,56 @@ + +u32[4] CHACHA_SIGMA = { 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 }; + +// nonce : 8 bytes +// key : 32 bytes +// counter : 8 bytes (starts at 0) +fn _init_ref(reg ptr u32[16] st, reg u32 nonce key) -> reg ptr u32[16] +{ + // TODO: compress this function + + reg ptr u32[4] sigma; + reg u32 t; + inline int i; + + sigma = CHACHA_SIGMA; + for i=0 to 4 + { t = sigma[i]; + st[i] = t; } + + // reads 8 u32 from pointer key + for i=0 to 8 + { t = (u32)[key + 4*i]; + st[4+i] = t; } + + // 64-bit counter + t = 0; + st[12] = t; + st[13] = t; + + // nonce + t = (u32)[nonce + 0]; + st[14] = t; + t = (u32)[nonce + 4]; + st[15] = t; + + return st; +} + +// TODO: double check here: 64 bit counter +// increments 64-bit counter +inline fn __increment_counter_ref(reg ptr u32[16] st) -> reg ptr u32[16] +{ + reg bool cf; + reg u32 l h; + + l = st[12]; + h = st[13]; + + _, _, cf, _, l = #ADDS(l, 1); + h = #ADDcc(h, 1, cf, h); + + st[12] = l; + st[13] = h; + + return st; +} diff --git a/src/crypto_stream/chacha/common/armv7m/ref/chacha_store.jinc b/src/crypto_stream/chacha/common/armv7m/ref/chacha_store.jinc new file mode 100644 index 00000000..39294c4d --- /dev/null +++ b/src/crypto_stream/chacha/common/armv7m/ref/chacha_store.jinc @@ -0,0 +1,96 @@ + +// store 'xor' //////////////////////////////////////////////////////////////// + +inline fn __update_ptr_xor_ref(reg u32 output plain len, inline int n) -> reg u32, reg u32, reg u32 +{ + output += n; + plain += n; + len -= n; + return output, plain, len; +} + +inline fn __sum_states_store_xor_ref( + reg u32 output plain len, + reg ptr u32[16] k st) + -> + reg u32, reg u32, reg u32 +{ + reg u32 i t s v; + + i = 0; + while(i < 16) + { t = k[(int)i]; + s = st[(int)i]; + v = (u32)[plain + 4*i]; + t += s; + t ^= v; + (u32)[output + 4*i] = t; + i += 1; + } + + output, plain, len = __update_ptr_xor_ref(output, plain, len, 64); + + return output, plain, len; +} + + +// len bytes +inline fn __store_xor_last_ref(reg u32 output plain len, reg ptr u32[16] k) +{ + reg u32 i t v; + + i = 0; + while(i < len) + { t = (32u)k[u8 (int)i]; + v = (32u)(u8)[plain + i]; + t ^= v; + (u8)[output + i] = t; + i += 1; + } +} + +// store ////////////////////////////////////////////////////////////////////// + +inline fn __update_ptr_ref(reg u32 output len, inline int n) -> reg u32, reg u32 +{ + output += n; + len -= n; + return output, len; +} + +inline fn __sum_states_store_ref( + reg u32 output len, + reg ptr u32[16] k st) + -> + reg u32, reg u32 +{ + reg u32 i t s; + + i = 0; + while(i < 16) + { t = k[(int)i]; + s = st[(int)i]; + t += s; + [output + 4*i] = t; + i += 1; + } + + output, len = __update_ptr_ref(output, len, 64); + + return output, len; +} + +// len bytes +inline fn __store_last_ref(reg u32 output len, reg ptr u32[16] k) +{ + reg u32 i t; + + i = 0; + while(i < len) + { t = (32u)k[u8 (int)i]; + (u8)[output + i] = t; + i += 1; + } +} + + diff --git a/src/crypto_xof/shake128/armv7m/ref/Makefile b/src/crypto_xof/shake128/armv7m/ref/Makefile new file mode 100644 index 00000000..72547a45 --- /dev/null +++ b/src/crypto_xof/shake128/armv7m/ref/Makefile @@ -0,0 +1,3 @@ +override JFLAGS += -arch arm-m4 +SRCS := xof.jazz +include ../../../../Makefile.common diff --git a/src/crypto_xof/shake128/armv7m/ref/include/api.h b/src/crypto_xof/shake128/armv7m/ref/include/api.h new file mode 100644 index 00000000..a826fc50 --- /dev/null +++ b/src/crypto_xof/shake128/armv7m/ref/include/api.h @@ -0,0 +1,17 @@ +#ifndef JADE_XOF_shake128_armv7m_ref_API_H +#define JADE_XOF_shake128_armv7m_ref_API_H + +#define JADE_XOF_shake128_armv7m_ref_ALGNAME "SHAKE128" +#define JADE_XOF_shake128_armv7m_ref_ARCH "armv7m" +#define JADE_XOF_shake128_armv7m_ref_IMPL "ref" + +#include + +int jade_xof_shake128_armv7m_ref( + uint8_t *output, + uint32_t output_length, + const uint8_t *input, + uint32_t input_length +); + +#endif diff --git a/src/crypto_xof/shake128/armv7m/ref/shake128.jinc b/src/crypto_xof/shake128/armv7m/ref/shake128.jinc new file mode 100644 index 00000000..80cab943 --- /dev/null +++ b/src/crypto_xof/shake128/armv7m/ref/shake128.jinc @@ -0,0 +1,13 @@ +from Jade require "common/keccak/keccak1600/armv7m/ref/keccak1600.jinc" + +inline fn __shake128_ref(reg u32 out outlen in inlen) +{ + reg u32 rate trail_byte; + + trail_byte = 0x1F; + rate = (1344/8); + + __keccak1600_ref(out, outlen, in, inlen, trail_byte, rate); +} + + diff --git a/src/crypto_xof/shake128/armv7m/ref/xof.jazz b/src/crypto_xof/shake128/armv7m/ref/xof.jazz new file mode 100644 index 00000000..3191b09b --- /dev/null +++ b/src/crypto_xof/shake128/armv7m/ref/xof.jazz @@ -0,0 +1,11 @@ +require "shake128.jinc" + +export fn jade_xof_shake128_armv7m_ref(reg u32 output output_length input input_length) -> reg u32 +{ + reg u32 r; + __shake128_ref(output, output_length, input, input_length); + r = 0; + return r; +} + + diff --git a/src/crypto_xof/shake256/armv7m/ref/Makefile b/src/crypto_xof/shake256/armv7m/ref/Makefile new file mode 100644 index 00000000..72547a45 --- /dev/null +++ b/src/crypto_xof/shake256/armv7m/ref/Makefile @@ -0,0 +1,3 @@ +override JFLAGS += -arch arm-m4 +SRCS := xof.jazz +include ../../../../Makefile.common diff --git a/src/crypto_xof/shake256/armv7m/ref/include/api.h b/src/crypto_xof/shake256/armv7m/ref/include/api.h new file mode 100644 index 00000000..44bb2fc4 --- /dev/null +++ b/src/crypto_xof/shake256/armv7m/ref/include/api.h @@ -0,0 +1,17 @@ +#ifndef JADE_XOF_shake256_armv7m_ref_API_H +#define JADE_XOF_shake256_armv7m_ref_API_H + +#define JADE_XOF_shake256_armv7m_ref_ALGNAME "SHAKE256" +#define JADE_XOF_shake256_armv7m_ref_ARCH "armv7m" +#define JADE_XOF_shake256_armv7m_ref_IMPL "ref" + +#include + +int jade_xof_shake256_armv7m_ref( + uint8_t *output, + uint32_t output_length, + const uint8_t *input, + uint32_t input_length +); + +#endif diff --git a/src/crypto_xof/shake256/armv7m/ref/shake256.jinc b/src/crypto_xof/shake256/armv7m/ref/shake256.jinc new file mode 100644 index 00000000..889c9782 --- /dev/null +++ b/src/crypto_xof/shake256/armv7m/ref/shake256.jinc @@ -0,0 +1,13 @@ +from Jade require "common/keccak/keccak1600/armv7m/ref/keccak1600.jinc" + +inline fn __shake256_ref(reg u32 out outlen in inlen) +{ + reg u32 rate trail_byte; + + trail_byte = 0x1F; + rate = (1088/8); + + __keccak1600_ref(out, outlen, in, inlen, trail_byte, rate); +} + + diff --git a/src/crypto_xof/shake256/armv7m/ref/xof.jazz b/src/crypto_xof/shake256/armv7m/ref/xof.jazz new file mode 100644 index 00000000..d5b91912 --- /dev/null +++ b/src/crypto_xof/shake256/armv7m/ref/xof.jazz @@ -0,0 +1,10 @@ +require "shake256.jinc" + +export fn jade_xof_shake256_armv7m_ref(reg u32 output output_length input input_length) -> reg u32 +{ + reg u32 r; + __shake256_ref(output, output_length, input, input_length); + r = 0; + return r; +} + diff --git a/test/Makefile b/test/Makefile index 33545b61..cc94b2a5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -21,8 +21,11 @@ # $ make -j2 CI=1 FILTER=../src/crypto_kem/kyber/% # $ make -j2 CI=1 reporter_checksums # + +# -------------------------------------------------------------------- +ARCH ?= amd64 + # -------------------------------------------------------------------- -AS ?= as CC ?= clang CFLAGS ?= -O3 -Wall -Wextra -Wpedantic -Wvla -Werror -std=c99 \ -Wundef -Wshadow -Wcast-align -Wpointer-arith -Wmissing-prototypes \ @@ -61,6 +64,8 @@ BIN ?= bin LOGS := libjade-logs-test.tar.gz SRC := ../src +export SRC + COMMON := common EXT := ../ext @@ -69,8 +74,10 @@ RANDSRC := $(COMMON)/notrandombytes.c FILTER ?= $(SRC)/crypto_% export FILTER -JAZZ ?= $(filter $(FILTER), $(filter-out $(addprefix $(SRC)/,$(EXCLUDE)), $(sort $(dir $(shell find $(SRC) -name '*.jazz'))))) -TESTDIR := $(subst $(SRC),$(BIN), $(JAZZ)) +JAZZ_ARCH ?= $(filter $(FILTER), $(filter-out $(addprefix $(SRC)/,$(EXCLUDE)), $(sort $(dir $(shell find $(SRC) -path "*/$(ARCH)/*" -name '*.jazz'))))) +TESTDIR := $(subst $(SRC),$(BIN), $(JAZZ_ARCH)) + +# -------------------------------------------------------------------- CHECKSUMSMALL := $(addsuffix checksumsmall, $(TESTDIR)) CHECKSUMBIG := $(addsuffix checksumbig, $(TESTDIR)) @@ -101,7 +108,15 @@ NAMESPACE = jade_$(OPERATION)_$(NAMESPACE0) NAMESPACE1 = JADE_$(OPERATION1)_$(NAMESPACE0) IDIR = $(subst $(BIN),$(SRC),$(@D)) -ASM = $(IDIR)/$(OPERATION).s + +# TODO: the following line (ASM =) is commented (and 'replaced' by the one after) as a temporary patch to allow C code in libjade's implementations: +# - when compiling (Jasmin) exported functions with more than 4 arguments the compilation fails since the ABI is not fully supported +# - for this reason, we need to write a (temporary) C wrapper to overcome this difficulty +# - this wrapper is temporary as we expect to support more than X arguments in the Jasmin compiler in the future +# - X is 5/6 in amd64 win/linux and 4 in armv7m + +#ASM = $(IDIR)/$(OPERATION).s +ASM = $(IDIR)/*.s DEFINE ?= DNAMESPACES = -DJADE_NAMESPACE=$(NAMESPACE1) -DJADE_NAMESPACE_LC=$(NAMESPACE) @@ -116,7 +131,7 @@ COMPILE_P = $(CC) $(CFLAGS) -o $@ $(DEFINE) $(DNAMESPACES) $(INCLUDES) crypto_ default: compile-and-run compile-and-run: - $(MAKE) CI=1 -C $(SRC) all + $(MAKE) CI=1 -C $(SRC) compile-$(ARCH) $(MAKE) CI=1 all reporter-and-err: @@ -158,21 +173,38 @@ include Makefile.partial_implementations # -------------------------------------------------------------------- $(OUT): - +ifeq ($(ARCH),amd64) %memory.out: %memory (valgrind --leak-check=full --error-exitcode=1 --log-file=$@ ./$*memory) $(CIL) || true +endif +## -- %.out +ifeq ($(ARCH),armv7m) +%.out: % + $(CIC) + (cd $(dir $*) && qemu-arm-static $(notdir $*) > $(notdir $*).out) $(CIL) || true +else %.out: % $(CIC) (cd $(dir $*) && ./$(notdir $*) > $(notdir $*).out) $(CIL) || true +endif $(STDOUT): +ifeq ($(ARCH),amd64) %memory.stdout: %memory (valgrind --leak-check=full --error-exitcode=1 ./$*memory) $(CIL) || true +endif +## -- %.stdout +ifeq ($(ARCH),armv7m) +%.stdout: % + $(CIC) + (cd $(dir $*) && qemu-arm-static $(notdir $*) && echo) $(CIL) || true +else %.stdout: % $(CIC) (cd $(dir $*) && ./$(notdir $*) && echo) $(CIL) || true +endif # -------------------------------------------------------------------- diff --git a/test/Makefile.armv7m b/test/Makefile.armv7m new file mode 100644 index 00000000..5ea5b254 --- /dev/null +++ b/test/Makefile.armv7m @@ -0,0 +1,14 @@ + +# some commands: +# make -f Makefile.armv7m CI=1 distclean && make -f Makefile.armv7m CI=1 default && make -f Makefile.armv7m CI=1 reporter + +ARCH := armv7m +CC := arm-linux-gnueabi-gcc +CFLAGS := -O3 -Wall -march=armv7 -z noexecstack -g -static + +export ARCH +export CC +export CFLAGS + +include Makefile + diff --git a/test/Makefile.partial_implementations b/test/Makefile.partial_implementations index 1d6c2831..ec5cf683 100644 --- a/test/Makefile.partial_implementations +++ b/test/Makefile.partial_implementations @@ -1,3 +1,6 @@ + +ifeq ($(ARCH),amd64) + EXTERNAL_PATH = $(subst $(BIN),external,$(@D)) EXTERNAL_LIB = $(EXTERNAL_PATH)/$(subst -,_,$(subst /,_,$(EXTERNAL_PATH))).a EXTERNAL_COMPILE = $(CC) $(CFLAGS) -o $@ $(DEFINE) $(DNAMESPACES) $(INCLUDES) crypto_$(OPERATION)/$(@F).c $(PRINT) $(ASM) $(RANDSRC) $(EXTERNAL_LIB) $(CIL) @@ -41,6 +44,9 @@ bin/crypto_sign/falcon/falcon512/amd64/avx2/memory: __phony | bin/crypto_sign/fa $(MAKE) -C $(EXTERNAL_PATH) $(EXTERNAL_COMPILE) || true +endif + #-- clean clean-external: $(MAKE) -C external/crypto_sign/falcon/falcon512/amd64/avx2 clean + diff --git a/test/common/notrandombytes.c b/test/common/notrandombytes.c index 89cf8586..cb2b11b5 100644 --- a/test/common/notrandombytes.c +++ b/test/common/notrandombytes.c @@ -112,10 +112,10 @@ static void chacha20_init(uint32_t x[16], const uint8_t n[8], const uint8_t k[32 } -static void chacha20(uint8_t *c, uint64_t clen, const uint8_t n[8], const uint8_t k[32]) +static void chacha20(uint8_t *c, size_t clen, const uint8_t n[8], const uint8_t k[32]) { uint32_t x[16], output[16]; - uint64_t i; + size_t i; chacha20_init(x,n,k); while(clen > 0) @@ -171,13 +171,13 @@ static uint8_t g1[KEYBYTES]; static uint8_t r0[OUTPUTBYTES]; static uint8_t r1[OUTPUTBYTES]; -static uint64_t pos0 = OUTPUTBYTES; -static uint64_t pos1 = OUTPUTBYTES; +static size_t pos0 = OUTPUTBYTES; +static size_t pos1 = OUTPUTBYTES; static void randombytes_internal( - uint8_t *x, uint64_t xlen, + uint8_t *x, size_t xlen, uint8_t *g, uint8_t *r, - uint64_t *pos + size_t *pos ) { while (xlen > 0) @@ -202,7 +202,7 @@ void resetrandombytes(void) memset(g0, 0, KEYBYTES); } -void randombytes(uint8_t* x, uint64_t xlen) +void randombytes(uint8_t* x, size_t xlen) { randombytes_internal(x,xlen,g0,r0,&pos0); } @@ -215,14 +215,14 @@ void resetrandombytes1(void) memset(g1, 0, KEYBYTES); } -void randombytes1(uint8_t* x, uint64_t xlen) +void randombytes1(uint8_t* x, size_t xlen) { randombytes_internal(x,xlen,g1,r1,&pos1); } // //////// -uint8_t* __jasmin_syscall_randombytes__(uint8_t* x, uint64_t xlen) +uint8_t* __jasmin_syscall_randombytes__(uint8_t* x, size_t xlen) { randombytes(x, xlen); return x; diff --git a/test/common/randombytes.h b/test/common/randombytes.h index c6a5e8cd..3e62da1f 100644 --- a/test/common/randombytes.h +++ b/test/common/randombytes.h @@ -2,16 +2,17 @@ #define NOTRANDOMBYTES_H #include +#include void resetrandombytes(void); -void randombytes(uint8_t* x, uint64_t xlen); +void randombytes(uint8_t* x, size_t xlen); void resetrandombytes1(void); -void randombytes1(uint8_t* x, uint64_t xlen); +void randombytes1(uint8_t* x, size_t xlen); // -uint8_t* __jasmin_syscall_randombytes__(uint8_t* _x, uint64_t xlen) __asm__("__jasmin_syscall_randombytes__"); +uint8_t* __jasmin_syscall_randombytes__(uint8_t* _x, size_t xlen) __asm__("__jasmin_syscall_randombytes__"); #endif diff --git a/test/common/try-anything.c b/test/common/try-anything.c index 311dd6a3..2448d168 100644 --- a/test/common/try-anything.c +++ b/test/common/try-anything.c @@ -65,11 +65,11 @@ static void core(uint8_t *out, const uint8_t *in, const uint8_t *k) FOR(i,16) st32(out + 4 * i,x[i] + y[i]); } -static void salsa20(uint8_t *c, uint64_t b, const uint8_t *n, const uint8_t *k) +static void salsa20(uint8_t *c, size_t b, const uint8_t *n, const uint8_t *k) { uint8_t z[16], x[64]; uint32_t u; - uint64_t i; + size_t i; if (!b) return; FOR(i,16) z[i] = 0; @@ -108,7 +108,7 @@ static void increment(uint8_t *n) // //////////////////////////////////////////////////////////////////////////// -static void testvector(unsigned char *x, uint64_t xlen) +static void testvector(unsigned char *x, size_t xlen) { static const unsigned char testvector_k[33] = "generate inputs for test vectors"; static unsigned char testvector_n[8]; // TODO REFACTOR @@ -134,7 +134,7 @@ unsigned long long myrandom(void) // //////////////////////////////////////////////////////////////////////////// -static void canary(uint8_t *x, uint64_t xlen) +static void canary(uint8_t *x, size_t xlen) { static const uint8_t canary_k[33] = "generate pad to catch overwrites"; static uint8_t canary_n[8]; // TODO REFACTOR @@ -142,7 +142,7 @@ static void canary(uint8_t *x, uint64_t xlen) increment(canary_n); } -void double_canary(uint8_t *x2, uint8_t *x, uint64_t xlen) +void double_canary(uint8_t *x2, uint8_t *x, size_t xlen) { canary(x - CANARY_LENGTH, CANARY_LENGTH); canary(x + xlen, CANARY_LENGTH); @@ -150,7 +150,7 @@ void double_canary(uint8_t *x2, uint8_t *x, uint64_t xlen) memcpy(x2 + xlen, x + xlen, CANARY_LENGTH); } -void input_prepare(uint8_t *x2, uint8_t *x, uint64_t xlen) +void input_prepare(uint8_t *x2, uint8_t *x, size_t xlen) { testvector(x, xlen); canary(x - CANARY_LENGTH, CANARY_LENGTH); @@ -158,7 +158,7 @@ void input_prepare(uint8_t *x2, uint8_t *x, uint64_t xlen) memcpy(x2 - CANARY_LENGTH, x - CANARY_LENGTH, xlen + (2*CANARY_LENGTH)); } -void input_compare(const uint8_t *x2, const uint8_t *x, uint64_t xlen, const char *fun) +void input_compare(const uint8_t *x2, const uint8_t *x, size_t xlen, const char *fun) { if (memcmp(x2 - CANARY_LENGTH, x - CANARY_LENGTH, xlen + (2*CANARY_LENGTH))) { fprintf(stderr,"%s overwrites input\n",fun); @@ -166,13 +166,13 @@ void input_compare(const uint8_t *x2, const uint8_t *x, uint64_t xlen, const cha } } -void output_prepare(uint8_t *x2, uint8_t *x, uint64_t xlen) +void output_prepare(uint8_t *x2, uint8_t *x, size_t xlen) { canary(x - CANARY_LENGTH, xlen + (2*CANARY_LENGTH)); memcpy(x2 - CANARY_LENGTH, x - CANARY_LENGTH, xlen + (2*CANARY_LENGTH)); } -void output_compare(const uint8_t *x2, const uint8_t *x, uint64_t xlen, const char *fun) +void output_compare(const uint8_t *x2, const uint8_t *x, size_t xlen, const char *fun) { if (memcmp(x2 - CANARY_LENGTH, x - CANARY_LENGTH, CANARY_LENGTH)) { fprintf(stderr,"%s writes before output\n",fun); @@ -186,10 +186,10 @@ void output_compare(const uint8_t *x2, const uint8_t *x, uint64_t xlen, const ch // //////////////////////////////////////////////////////////////////////////// -void checksum(uint8_t *checksum_state, uint8_t *x, uint64_t xlen) +void checksum(uint8_t *checksum_state, uint8_t *x, size_t xlen) { uint8_t block[16]; - uint64_t i; + size_t i; while (xlen >= 16) { core(checksum_state, x, checksum_state); @@ -227,10 +227,10 @@ void fail(const char *why) // //////////////////////////////////////////////////////////////////////////// -uint8_t* alignedcalloc(void** c, uint64_t len) +uint8_t* alignedcalloc(void** c, size_t len) { uint8_t *x; - uint64_t i; + size_t i; x = (uint8_t *) calloc(1,len + 256); if (!x) fail("out of memory"); diff --git a/test/common/try-anything.h b/test/common/try-anything.h index 57c2df91..e2549536 100644 --- a/test/common/try-anything.h +++ b/test/common/try-anything.h @@ -1,15 +1,15 @@ #ifndef TRY_ANYTHING #define TRY_ANYTHING -uint8_t* alignedcalloc(void**, uint64_t); +uint8_t* alignedcalloc(void**, size_t); unsigned long long myrandom(void); -void double_canary(uint8_t*, uint8_t*, uint64_t); -void input_prepare(uint8_t*, uint8_t*, uint64_t); -void output_prepare(uint8_t*, uint8_t*, uint64_t); -void output_compare(const uint8_t*, const uint8_t*, uint64_t, const char*); -void input_compare(const uint8_t*, const uint8_t*, uint64_t, const char *); +void double_canary(uint8_t*, uint8_t*, size_t); +void input_prepare(uint8_t*, uint8_t*, size_t); +void output_prepare(uint8_t*, uint8_t*, size_t); +void output_compare(const uint8_t*, const uint8_t*, size_t, const char*); +void input_compare(const uint8_t*, const uint8_t*, size_t, const char *); void fail(const char *); -void checksum(uint8_t*, uint8_t*, uint64_t); +void checksum(uint8_t*, uint8_t*, size_t); int try_anything_main(void); #endif diff --git a/test/crypto_hash/checksums.c b/test/crypto_hash/checksums.c index c8217a99..8d5abcb1 100644 --- a/test/crypto_hash/checksums.c +++ b/test/crypto_hash/checksums.c @@ -19,8 +19,8 @@ typedef struct state { uint8_t *m; uint8_t *h2; uint8_t *m2; - uint64_t hlen; - uint64_t mlen; + size_t hlen; + size_t mlen; void* free[4]; } state; @@ -55,7 +55,7 @@ state* preallocate(void) void allocate(state *s) { - uint64_t alloclen = 0; + size_t alloclen = 0; if (alloclen < TUNE_BYTES) alloclen = TUNE_BYTES; if (alloclen < MAXTEST_BYTES) alloclen = MAXTEST_BYTES; diff --git a/test/crypto_hash/memory.c b/test/crypto_hash/memory.c index a91a78db..08db016b 100644 --- a/test/crypto_hash/memory.c +++ b/test/crypto_hash/memory.c @@ -8,20 +8,11 @@ #include "jade_hash.h" #include "config.h" -/* -int jade_hash( - uint8_t *hash, - const uint8_t *input, - uint64_t input_length -); -*/ - - int main(void) { uint8_t *hash; uint8_t *input; - uint64_t input_length; + size_t input_length; hash = malloc(sizeof(uint8_t) * JADE_HASH_BYTES); diff --git a/test/crypto_hash/safetyparams.c b/test/crypto_hash/safetyparams.c index fb1e44da..765c8347 100644 --- a/test/crypto_hash/safetyparams.c +++ b/test/crypto_hash/safetyparams.c @@ -6,14 +6,6 @@ #include "api.h" #include "jade_hash.h" -/* -int jade_hash( - uint8_t *hash, - const uint8_t *input, - uint64_t input_length -); -*/ - int main(void) { char *functions[1] = {xstr(jade_hash,)}; diff --git a/test/crypto_kem/checksums.c b/test/crypto_kem/checksums.c index 0b8598a9..005a3b44 100644 --- a/test/crypto_kem/checksums.c +++ b/test/crypto_kem/checksums.c @@ -47,13 +47,13 @@ typedef struct state { uint8_t *_kc2; uint8_t *_ec2; - uint64_t plen; - uint64_t slen; - uint64_t klen; - uint64_t clen; - uint64_t tlen; - uint64_t kclen; - uint64_t eclen; + size_t plen; + size_t slen; + size_t klen; + size_t clen; + size_t tlen; + size_t kclen; + size_t eclen; void* free[24]; } state; @@ -89,7 +89,7 @@ state* preallocate(void) void allocate(state *s) { - unsigned long long alloclen = 0; + size_t alloclen = 0; if (alloclen < TUNE_BYTES) alloclen = TUNE_BYTES; if (alloclen < MAXTEST_BYTES) alloclen = MAXTEST_BYTES; diff --git a/test/crypto_kem/memory.c b/test/crypto_kem/memory.c index d9b74662..01e1a224 100644 --- a/test/crypto_kem/memory.c +++ b/test/crypto_kem/memory.c @@ -9,40 +9,6 @@ #include "randombytes.h" #include "config.h" -/* -int jade_kem_keypair( - uint8_t *public_key, - uint8_t *secret_key -); - -int jade_kem_enc( - uint8_t *ciphertext, - uint8_t *shared_secret, - const uint8_t *public_key -); - -int jade_kem_dec( - uint8_t *shared_secret, - const uint8_t *ciphertext, - const uint8_t *secret_key -); - -// - -int jade_kem_keypair_derand( - uint8_t *public_key, - uint8_t *secret_key, - const uint8_t *coins -); - -int jade_kem_enc_derand( - uint8_t *ciphertext, - uint8_t *shared_secret, - const uint8_t *public_key, - const uint8_t *coins -); -*/ - int main(void) { uint8_t *public_key; diff --git a/test/crypto_kem/safetyparams.c b/test/crypto_kem/safetyparams.c index f49a42f8..c884a4b4 100644 --- a/test/crypto_kem/safetyparams.c +++ b/test/crypto_kem/safetyparams.c @@ -6,42 +6,6 @@ #include "api.h" #include "jade_kem.h" -/* - -int jade_kem_keypair( - uint8_t *public_key, - uint8_t *secret_key -); - -int jade_kem_enc( - uint8_t *ciphertext, - uint8_t *shared_secret, - const uint8_t *public_key -); - -int jade_kem_dec( - uint8_t *shared_secret, - const uint8_t *ciphertext, - const uint8_t *secret_key -); - -// - -int jade_kem_keypair_derand( - uint8_t *public_key, - uint8_t *secret_key, - const uint8_t *coins -); - -int jade_kem_enc_derand( - uint8_t *ciphertext, - uint8_t *shared_secret, - const uint8_t *public_key, - const uint8_t *coins -); - -*/ - int main(void) { char *functions[5] diff --git a/test/crypto_onetimeauth/checksums.c b/test/crypto_onetimeauth/checksums.c index 7807264f..e26d39b8 100644 --- a/test/crypto_onetimeauth/checksums.c +++ b/test/crypto_onetimeauth/checksums.c @@ -21,9 +21,9 @@ typedef struct state { uint8_t *h2; uint8_t *m2; uint8_t *k2; - uint64_t hlen; - uint64_t mlen; - uint64_t klen; + size_t hlen; + size_t mlen; + size_t klen; void* free[6]; } state; @@ -58,7 +58,7 @@ state* preallocate(void) void allocate(state *s) { - uint64_t alloclen = 0; + size_t alloclen = 0; if (alloclen < TUNE_BYTES) alloclen = TUNE_BYTES; if (alloclen < MAXTEST_BYTES) alloclen = MAXTEST_BYTES; if (alloclen < JADE_ONETIMEAUTH_BYTES) alloclen = JADE_ONETIMEAUTH_BYTES; diff --git a/test/crypto_onetimeauth/memory.c b/test/crypto_onetimeauth/memory.c index 6dc398bb..d0091c63 100644 --- a/test/crypto_onetimeauth/memory.c +++ b/test/crypto_onetimeauth/memory.c @@ -10,28 +10,12 @@ #include "randombytes.h" #include "config.h" -/* -int jade_onetimeauth( - uint8_t *mac, - const uint8_t *input, - uint64_t input_length, - const uint8_t *key -); - -int jade_onetimeauth_verify( - const uint8_t *mac, - const uint8_t *input, - uint64_t input_length, - const uint8_t *key -); -*/ - int main(void) { int r; uint8_t *mac; uint8_t *input; - uint64_t input_length; + size_t input_length; uint8_t *key; mac = malloc(sizeof(uint8_t) * JADE_ONETIMEAUTH_BYTES); diff --git a/test/crypto_onetimeauth/safetyparams.c b/test/crypto_onetimeauth/safetyparams.c index 1bc3ddc9..29283edb 100644 --- a/test/crypto_onetimeauth/safetyparams.c +++ b/test/crypto_onetimeauth/safetyparams.c @@ -6,22 +6,6 @@ #include "api.h" #include "jade_onetimeauth.h" -/* -int jade_onetimeauth( - uint8_t *mac, - const uint8_t *input, - uint64_t input_length, - const uint8_t *key -); - -int jade_onetimeauth_verify( - const uint8_t *mac, - const uint8_t *input, - uint64_t input_length, - const uint8_t *key -); -*/ - int main(void) { char *functions[2] = {xstr(jade_onetimeauth,), xstr(jade_onetimeauth_verify,)}; diff --git a/test/crypto_scalarmult/checksums.c b/test/crypto_scalarmult/checksums.c index 7857caec..a9787529 100644 --- a/test/crypto_scalarmult/checksums.c +++ b/test/crypto_scalarmult/checksums.c @@ -27,12 +27,12 @@ typedef struct state { uint8_t *d2; uint8_t *e2; uint8_t *f2; - uint64_t alen; - uint64_t blen; - uint64_t clen; - uint64_t dlen; - uint64_t elen; - uint64_t flen; + size_t alen; + size_t blen; + size_t clen; + size_t dlen; + size_t elen; + size_t flen; void* free[12]; } state; @@ -63,7 +63,7 @@ state* preallocate(void) void allocate(state *s) { - unsigned long long alloclen = 0; + size_t alloclen = 0; if (alloclen < JADE_SCALARMULT_SCALARBYTES) alloclen = JADE_SCALARMULT_SCALARBYTES; if (alloclen < JADE_SCALARMULT_BYTES) alloclen = JADE_SCALARMULT_BYTES; s->a = alignedcalloc(&(s->free[0]), alloclen); diff --git a/test/crypto_scalarmult/memory.c b/test/crypto_scalarmult/memory.c index 6110e735..dcdca081 100644 --- a/test/crypto_scalarmult/memory.c +++ b/test/crypto_scalarmult/memory.c @@ -9,19 +9,6 @@ #include "randombytes.h" #include "config.h" -/* -int jade_scalarmult( - uint8_t *q, - const uint8_t *n, - const uint8_t *p -); - -int jade_scalarmult_base( - uint8_t *q, - const uint8_t *n -); -*/ - int main(void) { uint8_t *public_key = malloc(sizeof(uint8_t) * JADE_SCALARMULT_BYTES); diff --git a/test/crypto_scalarmult/safetyparams.c b/test/crypto_scalarmult/safetyparams.c index 2461a5b6..de81fb96 100644 --- a/test/crypto_scalarmult/safetyparams.c +++ b/test/crypto_scalarmult/safetyparams.c @@ -6,19 +6,6 @@ #include "api.h" #include "jade_scalarmult.h" -/* -int jade_scalarmult( - uint8_t *q, - const uint8_t *n, - const uint8_t *p -); - -int jade_scalarmult_base( - uint8_t *q, - const uint8_t *n -); -*/ - int main(void) { char *functions[] = {xstr(jade_scalarmult,), xstr(jade_scalarmult_base,)}; diff --git a/test/crypto_secretbox/checksums.c b/test/crypto_secretbox/checksums.c index 26977359..6e236a53 100644 --- a/test/crypto_secretbox/checksums.c +++ b/test/crypto_secretbox/checksums.c @@ -25,11 +25,11 @@ typedef struct state { uint8_t *m2; uint8_t *c2; uint8_t *t2; - uint64_t klen; - uint64_t nlen; - uint64_t mlen; - uint64_t clen; - uint64_t tlen; + size_t klen; + size_t nlen; + size_t mlen; + size_t clen; + size_t tlen; void* free[10]; } state; @@ -64,7 +64,7 @@ state* preallocate(void) void allocate(state *s) { - uint64_t alloclen = 0; + size_t alloclen = 0; if (alloclen < TUNE_BYTES) alloclen = TUNE_BYTES; if (alloclen < MAXTEST_BYTES) alloclen = MAXTEST_BYTES; if (alloclen < JADE_SECRETBOX_KEYBYTES) alloclen = JADE_SECRETBOX_KEYBYTES; diff --git a/test/crypto_secretbox/functest.c b/test/crypto_secretbox/functest.c index a3bc7125..1f9f07f7 100644 --- a/test/crypto_secretbox/functest.c +++ b/test/crypto_secretbox/functest.c @@ -19,7 +19,7 @@ int main(void) uint8_t ciphertext[JADE_SECRETBOX_ZEROBYTES + PLAINTEXT_LENGTH]; uint8_t plaintext_1[JADE_SECRETBOX_ZEROBYTES + PLAINTEXT_LENGTH]; uint8_t plaintext_2[JADE_SECRETBOX_ZEROBYTES + PLAINTEXT_LENGTH]; - uint64_t length = JADE_SECRETBOX_ZEROBYTES + PLAINTEXT_LENGTH; + size_t length = JADE_SECRETBOX_ZEROBYTES + PLAINTEXT_LENGTH; uint8_t _nonce[JADE_SECRETBOX_NONCEBYTES]; uint8_t _key[JADE_SECRETBOX_KEYBYTES]; uint8_t* nonce = _nonce; diff --git a/test/crypto_secretbox/memory.c b/test/crypto_secretbox/memory.c index cf327db4..4a4f2416 100644 --- a/test/crypto_secretbox/memory.c +++ b/test/crypto_secretbox/memory.c @@ -10,31 +10,13 @@ #include "randombytes.h" #include "config.h" -/* -int jade_secretbox( - uint8_t *ciphertext, - const uint8_t *plaintext, - uint64_t plaintext_length, - const uint8_t *nonce, - const uint8_t *key -); - -int jade_secretbox_open( - uint8_t *plaintext, - const uint8_t *ciphertext, - uint64_t ciphertext_length, - const uint8_t *nonce, - const uint8_t *key -); -*/ - int main(void) { int r; uint8_t *ciphertext; uint8_t *plaintext; - uint64_t plaintext_length; - uint64_t ciphertext_length; + size_t plaintext_length; + size_t ciphertext_length; uint8_t *nonce; uint8_t *key; diff --git a/test/crypto_secretbox/safetyparams.c b/test/crypto_secretbox/safetyparams.c index e9ac564e..98573ed3 100644 --- a/test/crypto_secretbox/safetyparams.c +++ b/test/crypto_secretbox/safetyparams.c @@ -6,24 +6,6 @@ #include "api.h" #include "jade_secretbox.h" -/* -int jade_secretbox( - uint8_t *ciphertext, - const uint8_t *plaintext, - uint64_t length, - const uint8_t *nonce, - const uint8_t *key -); - -int jade_secretbox_open( - uint8_t *plaintext, - const uint8_t *ciphertext, - uint64_t length, - const uint8_t *nonce, - const uint8_t *key -); -*/ - int main(void) { char *functions[] = {xstr(jade_secretbox,), xstr(jade_secretbox_open,)}; diff --git a/test/crypto_sign/checksums.c b/test/crypto_sign/checksums.c index 773448bf..625163e6 100644 --- a/test/crypto_sign/checksums.c +++ b/test/crypto_sign/checksums.c @@ -27,11 +27,11 @@ typedef struct state { uint8_t *m2; uint8_t *c2; uint8_t *t2; - uint64_t plen; - uint64_t slen; - uint64_t mlen; - uint64_t clen; - uint64_t tlen; + size_t plen; + size_t slen; + size_t mlen; + size_t clen; + size_t tlen; void* free[10]; } state; @@ -66,7 +66,7 @@ state* preallocate(void) void allocate(state *s) { - uint64_t alloclen = 0; + size_t alloclen = 0; if (alloclen < TUNE_BYTES) alloclen = TUNE_BYTES; if (alloclen < MAXTEST_BYTES + JADE_SIGN_BYTES) alloclen = MAXTEST_BYTES + JADE_SIGN_BYTES; if (alloclen < JADE_SIGN_PUBLICKEYBYTES) alloclen = JADE_SIGN_PUBLICKEYBYTES; diff --git a/test/crypto_sign/functest.c b/test/crypto_sign/functest.c index 8e296c6a..753868ce 100644 --- a/test/crypto_sign/functest.c +++ b/test/crypto_sign/functest.c @@ -18,10 +18,10 @@ int main(void) #define MESSAGE_LENGTH 3 uint8_t message_1[MESSAGE_LENGTH] = {0x61, 0x62, 0x63}; uint8_t message_2[MESSAGE_LENGTH]; - uint64_t message_length; + size_t message_length; uint8_t signed_message[JADE_SIGN_BYTES + MESSAGE_LENGTH]; - uint64_t signed_message_length; + size_t signed_message_length; // r = jade_sign_keypair(public_key, secret_key); diff --git a/test/crypto_sign/memory.c b/test/crypto_sign/memory.c index e6946ad0..30ebee2d 100644 --- a/test/crypto_sign/memory.c +++ b/test/crypto_sign/memory.c @@ -10,38 +10,15 @@ #include "randombytes.h" #include "config.h" -/* -int jade_sign_keypair( - uint8_t *public_key, - uint8_t *secret_key -); - -int jade_sign_ref( - uint8_t *signed_message, - uint64_t *signed_message_length, - const uint8_t *message, - uint64_t message_length, - const uint8_t *secret_key -); - -int jade_sign_open( - uint8_t *message, - uint64_t *message_length, - const uint8_t *signed_message, - uint64_t signed_message_length, - const uint8_t *public_key -); -*/ - int main(void) { int r; uint8_t *public_key; uint8_t *secret_key; uint8_t *signed_message; - uint64_t signed_message_length; + size_t signed_message_length; uint8_t *message; - uint64_t message_length; + size_t message_length; public_key = malloc(sizeof(uint8_t) * JADE_SIGN_PUBLICKEYBYTES); secret_key = malloc(sizeof(uint8_t) * JADE_SIGN_SECRETKEYBYTES); diff --git a/test/crypto_sign/safetyparams.c b/test/crypto_sign/safetyparams.c index 55d9243e..698ea746 100644 --- a/test/crypto_sign/safetyparams.c +++ b/test/crypto_sign/safetyparams.c @@ -6,29 +6,6 @@ #include "api.h" #include "jade_sign.h" -/* -int jade_sign_keypair( - uint8_t *public_key, - uint8_t *secret_key -); - -int jade_sign( - uint8_t *signed_message, - uint64_t *signed_message_length, - const uint8_t *message, - uint64_t message_length, - const uint8_t *secret_key -); - -int jade_sign_open( - uint8_t *message, - uint64_t *message_length, - const uint8_t *signed_message, - uint64_t signed_message_length, - const uint8_t *public_key -); -*/ - int main(void) { char *functions[3] = {xstr(jade_sign_keypair,), xstr(jade_sign,), xstr(jade_sign_open,)}; @@ -54,14 +31,14 @@ int main(void) fprintf(files[2],"-safetyparam \""); f_fprintf2(files[0], files[2], "%s>signed_message,signed_message_length,message,secret_key;%zu+message_length,%zu,message_length,%zu", - functions[1],(size_t)JADE_SIGN_BYTES,(size_t)(sizeof(uint64_t)),(size_t)JADE_SIGN_SECRETKEYBYTES); + functions[1],(size_t)JADE_SIGN_BYTES,(size_t)(sizeof(size_t)),(size_t)JADE_SIGN_SECRETKEYBYTES); fprintf(files[0],"|"); fprintf(files[2],"\""); fprintf(files[3],"-safetyparam \""); f_fprintf2(files[0],files[3], "%s>message,message_length,signed_message,public_key;signed_message_length-%zu,%zu,signed_message_length,%zu", - functions[2],(size_t)JADE_SIGN_BYTES,(size_t)(sizeof(uint64_t)),(size_t)JADE_SIGN_PUBLICKEYBYTES); + functions[2],(size_t)JADE_SIGN_BYTES,(size_t)(sizeof(size_t)),(size_t)JADE_SIGN_PUBLICKEYBYTES); f_fprintf2(files[0],files[3], "\""); diff --git a/test/crypto_stream/checksums.c b/test/crypto_stream/checksums.c index 07f617e2..bd71c659 100644 --- a/test/crypto_stream/checksums.c +++ b/test/crypto_stream/checksums.c @@ -25,11 +25,11 @@ typedef struct state { uint8_t *m2; uint8_t *c2; uint8_t *s2; - uint64_t klen; - uint64_t nlen; - uint64_t mlen; - uint64_t clen; - uint64_t slen; + size_t klen; + size_t nlen; + size_t mlen; + size_t clen; + size_t slen; void* free[10]; } state; @@ -64,7 +64,7 @@ state* preallocate(void) void allocate(state *s) { - uint64_t alloclen = 0; + size_t alloclen = 0; if (alloclen < TUNE_BYTES) alloclen = TUNE_BYTES; if (alloclen < MAXTEST_BYTES) alloclen = MAXTEST_BYTES; if (alloclen < JADE_STREAM_KEYBYTES) alloclen = JADE_STREAM_KEYBYTES; diff --git a/test/crypto_stream/functest.c b/test/crypto_stream/functest.c index bd16bffb..5d6d58cf 100644 --- a/test/crypto_stream/functest.c +++ b/test/crypto_stream/functest.c @@ -19,7 +19,7 @@ int main(void) uint8_t plaintext_2[PLAINTEXT_LENGTH]; uint8_t ciphertext[PLAINTEXT_LENGTH]; uint8_t stream[PLAINTEXT_LENGTH]; - uint64_t length = PLAINTEXT_LENGTH; + size_t length = PLAINTEXT_LENGTH; uint8_t _nonce[JADE_STREAM_NONCEBYTES]; uint8_t _key[JADE_STREAM_KEYBYTES]; uint8_t* nonce = _nonce; diff --git a/test/crypto_stream/memory.c b/test/crypto_stream/memory.c index b827f391..9b3fdf5e 100644 --- a/test/crypto_stream/memory.c +++ b/test/crypto_stream/memory.c @@ -9,28 +9,11 @@ #include "randombytes.h" #include "config.h" -/* -int jade_stream_xor( - uint8_t *output, - const uint8_t *input, - uint64_t input_length, - const uint8_t *nonce, - const uint8_t *key -); - -int jade_stream( - uint8_t *stream, - uint64_t stream_length, - const uint8_t *nonce, - const uint8_t *key -); -*/ - int main(void) { uint8_t *output; uint8_t *input; - uint64_t input_length; + size_t input_length; uint8_t *nonce; uint8_t *key; diff --git a/test/crypto_stream/safetyparams.c b/test/crypto_stream/safetyparams.c index ed799f93..60ca871d 100644 --- a/test/crypto_stream/safetyparams.c +++ b/test/crypto_stream/safetyparams.c @@ -6,23 +6,6 @@ #include "api.h" #include "jade_stream.h" -/* -int jade_stream( - uint8_t *stream, - uint64_t stream_length, - const uint8_t *nonce, - const uint8_t *key -); - -int jade_stream_xor( - uint8_t *output, - const uint8_t *input, - uint64_t input_length, - const uint8_t *nonce, - const uint8_t *key -); -*/ - int main(void) { char *functions[2] = {xstr(jade_stream,), xstr(jade_stream_xor,)}; diff --git a/test/crypto_xof/checksums.c b/test/crypto_xof/checksums.c index 31fec02f..bb19e2f1 100644 --- a/test/crypto_xof/checksums.c +++ b/test/crypto_xof/checksums.c @@ -19,8 +19,8 @@ typedef struct state { uint8_t *m; uint8_t *h2; uint8_t *m2; - uint64_t hlen; - uint64_t mlen; + size_t hlen; + size_t mlen; void* free[4]; } state; @@ -57,7 +57,7 @@ state* preallocate(void) void allocate(state *s) { - uint64_t alloclen = 0; + size_t alloclen = 0; if (alloclen < TUNE_BYTES) alloclen = TUNE_BYTES; if (alloclen < MAXTEST_BYTES) alloclen = MAXTEST_BYTES; diff --git a/test/crypto_xof/memory.c b/test/crypto_xof/memory.c index 61a08ae5..5755fe55 100644 --- a/test/crypto_xof/memory.c +++ b/test/crypto_xof/memory.c @@ -9,21 +9,12 @@ #include "randombytes.h" #include "config.h" -/* -int jade_xof( - uint8_t *output, - uint64_t output_length, - const uint8_t *input, - uint64_t input_length -); -*/ - int main(void) { uint8_t *output; - uint64_t output_length; + size_t output_length; uint8_t *input; - uint64_t input_length; + size_t input_length; for (output_length = MINOUTBYTES; output_length <= MAXOUTBYTES; output_length++) { diff --git a/test/crypto_xof/safetyparams.c b/test/crypto_xof/safetyparams.c index 365840dc..7b256e0e 100644 --- a/test/crypto_xof/safetyparams.c +++ b/test/crypto_xof/safetyparams.c @@ -5,15 +5,6 @@ #include "api.h" #include "jade_xof.h" -/* -int jade_xof( - uint8_t *output, - uint64_t output_length, - const uint8_t *input, - uint64_t input_length -); -*/ - int main(void) { char *functions[1] = {xstr(jade_xof,)};