diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4370ba..2825211 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,19 +17,22 @@ jobs: - name: install clang run: sudo apt install clang - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - name: get updated submodules + run: git submodule update --init --recursive - name: build and compile the static library. - run: make -f staticlib CC=clang++ + run: make -f staticlib CXX=clang++ - name: run the tests for the static library. - run: make -f staticlib static_test CC=clang++ + run: make -f staticlib static_test CXX=clang++ - name: clean test executables run: make clean - name: install the static library. - run: sudo make -f staticlib install CC=clang++ + run: sudo make -f staticlib install CXX=clang++ - name: compile the static sample program for the library. run: clang++ static-build.cpp -o static-build.out -lchacha20 -fsanitize=address @@ -48,7 +51,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - name: get updated submodules + run: git submodule update --init --recursive - name: build and compile the static library. run: make -f staticlib diff --git a/.github/workflows/clang.yml b/.github/workflows/clang.yml index 12c792c..9e656d6 100644 --- a/.github/workflows/clang.yml +++ b/.github/workflows/clang.yml @@ -16,7 +16,10 @@ jobs: - name: install clang run: sudo apt install clang - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - name: get updated submodules + run: git submodule update --init --recursive - name: compile and run tests in header mode - run: make header_test CC=clang++ \ No newline at end of file + run: make header_test CXX=clang++ \ No newline at end of file diff --git a/.github/workflows/gcc-gnu.yml b/.github/workflows/gcc-gnu.yml index e042012..da98fb0 100644 --- a/.github/workflows/gcc-gnu.yml +++ b/.github/workflows/gcc-gnu.yml @@ -12,6 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - name: get updated submodules + run: git submodule update --init --recursive + - name: compile and run tests in header mode run: make header_test \ No newline at end of file diff --git a/.github/workflows/mingw64.yml b/.github/workflows/mingw64.yml index adc8315..9b094d5 100644 --- a/.github/workflows/mingw64.yml +++ b/.github/workflows/mingw64.yml @@ -12,8 +12,13 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - name: get updated submodules + run: git submodule update --init --recursive + - name: compiler architecture run: gcc -dumpmachine + - name: compile and run tests in header mode run: make header_test diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml index 3fd8863..7af0434 100644 --- a/.github/workflows/msvc.yml +++ b/.github/workflows/msvc.yml @@ -23,6 +23,9 @@ jobs: steps: - uses: actions/checkout@v3 + + - name: get updated submodules + run: git submodule update --init --recursive - name: Configure test executables run: cmake -S tests -B tests ${{matrix.platform.flags}} diff --git a/ChaCha20-Poly1305.cpp b/ChaCha20-Poly1305.cpp index eb49cb4..f03dd65 100644 --- a/ChaCha20-Poly1305.cpp +++ b/ChaCha20-Poly1305.cpp @@ -1,9 +1,10 @@ #ifndef CHACHA20_CPP_mrdcvlsc #define CHACHA20_CPP_mrdcvlsc -#include "extended-precision-integers/include/epi/epi.hpp" #include #include +#include "extended-precision-integers/include/epi/epi.hpp" + #ifdef _MAKE_LIB #include "ChaCha20-Poly1305.hpp" #endif diff --git a/aarch64test b/aarch64test index 24dc047..ab79393 100644 --- a/aarch64test +++ b/aarch64test @@ -1,12 +1,12 @@ -CC := g++ -TESTFLAGS := -g -Og -D_HIDE_WARNING -CXXFLAGS := -std=c++11 -Wall -Wextra +CXX:=g++ +TESTFLAGS:=-g -Og -D_HIDE_WARNING +CXXFLAGS:=-std=c++20 -Wall -Wextra -OS := $(shell uname) +OS:=$(shell uname) -SRC := tests -SRC_FILES := $(wildcard $(SRC)/*.cpp) -OBJ := $(patsubst $(SRC)/%.cpp,$(SRC)/%.out,$(SRC_FILES)) +SRC:=tests +SRC_FILES:=$(wildcard $(SRC)/*.cpp) +OBJ:=$(patsubst $(SRC)/%.cpp,$(SRC)/%.out,$(SRC_FILES)) # -------------------------- run test programs --------------------------- @@ -17,14 +17,6 @@ header_test: $(OBJ) @./$(SRC)/QuarterRound_test.out @./$(SRC)/BlockFunction_test.out @./$(SRC)/Encryption_test.out - @./$(SRC)/constructor.out - @./$(SRC)/comparison.out - @./$(SRC)/leftshifts.out - @./$(SRC)/rightshifts.out - @./$(SRC)/addition.out - @./$(SRC)/subtraction.out - @./$(SRC)/multiplication.out - @./$(SRC)/division.out @./$(SRC)/poly1305_mac_test.out @./$(SRC)/poly1305_keygen.out @./$(SRC)/chacha20_aead_enc_dec.out @@ -58,8 +50,8 @@ header_test: $(OBJ) # -------------------------- test program compilation --------------------------- $(SRC)/%.out: $(SRC)/%.cpp - @echo "compiling test program - compiler : $(CC)" - @$(CC) $(TESTFLAGS) $(CXXFLAGS) -o $@ $< + @echo "compiling test program - compiler : $(CXX)" + @$(CXX) $(TESTFLAGS) $(CXXFLAGS) -o $@ $< clean: ifeq ($(OS), Linux) diff --git a/makefile b/makefile index a39b075..41ffe10 100644 --- a/makefile +++ b/makefile @@ -1,16 +1,16 @@ -CC := g++ -TESTFLAGS := -g -Og -D_HIDE_WARNING -CXXFLAGS := -std=c++20 -Wall -Wextra +CXX:=g++ +TESTFLAGS:=-g -Og -D_HIDE_WARNING +CXXFLAGS:=-std=c++20 -Wall -Wextra -OS := $(shell uname) +OS:=$(shell uname) ifeq ($(OS), Linux) -TESTFLAGS += -fsanitize=address +TESTFLAGS+=-fsanitize=address endif -SRC := tests -SRC_FILES := $(wildcard $(SRC)/*.cpp) -OBJ := $(patsubst $(SRC)/%.cpp,$(SRC)/%.out,$(SRC_FILES)) +SRC:=tests +SRC_FILES:=$(wildcard $(SRC)/*.cpp) +OBJ:=$(patsubst $(SRC)/%.cpp,$(SRC)/%.out,$(SRC_FILES)) # -------------------------- run test programs --------------------------- @@ -21,14 +21,6 @@ header_test: $(OBJ) @./$(SRC)/QuarterRound_test.out @./$(SRC)/BlockFunction_test.out @./$(SRC)/Encryption_test.out - @./$(SRC)/constructor.out - @./$(SRC)/comparison.out - @./$(SRC)/leftshifts.out - @./$(SRC)/rightshifts.out - @./$(SRC)/addition.out - @./$(SRC)/subtraction.out - @./$(SRC)/multiplication.out - @./$(SRC)/division.out @./$(SRC)/poly1305_mac_test.out @./$(SRC)/poly1305_keygen.out @./$(SRC)/chacha20_aead_enc_dec.out @@ -62,9 +54,9 @@ header_test: $(OBJ) # -------------------------- test program compilation --------------------------- $(SRC)/%.out: $(SRC)/%.cpp -# @echo "compiling test program - compiler : $(CC)" +# @echo "compiling test program - compiler : $(CXX)" # @echo "flags: $<" - $(CC) $(TESTFLAGS) $(CXXFLAGS) -o $@ $< + $(CXX) $(TESTFLAGS) $(CXXFLAGS) -o $@ $< clean: ifeq ($(OS), Linux) diff --git a/readme.md b/readme.md index a9dc00e..2382b87 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ ![build](https://github.com/mrdcvlsc/ChaCha20-Poly1305/actions/workflows/build.yml/badge.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) -A from scratch C++ (with slight inline assembly) implementation of ```ChaCha20 & Poly1305``` stream cipher described in [RFC - 8439](https://www.rfc-editor.org/info/rfc8439). +A from scratch C++ implementation of ```ChaCha20 & Poly1305``` stream cipher described in [RFC - 8439](https://www.rfc-editor.org/info/rfc8439). **tests:** diff --git a/staticlib b/staticlib index 061df84..20803e4 100644 --- a/staticlib +++ b/staticlib @@ -1,27 +1,27 @@ -CC := g++ +CXX:=g++ INSTALL_PREFIX=/usr/local/ HEADER_OUT:=build/include LIB_OUT:=build/lib LIB_OUTNAME:=libchacha20.a -CXXFLAGS := -std=c++11 -Wall -Wextra -USERFLAGS := -D_MAKE_LIB -D_HIDE_WARNING -TEST_OPTIMIZATION := -g -Og -HEADER_PATHS := -I./$(HEADER_OUT) -LIB_OPTIMIZATION := -O2 -LIB_PATHS := -L./$(LIB_OUT) -LIBS := -lchacha20 +CXXFLAGS:=-std=c++11 -Wall -Wextra +USERFLAGS:=-D_MAKE_LIB -D_HIDE_WARNING +TEST_OPTIMIZATION:=-g -Og +HEADER_PATHS:=-I./$(HEADER_OUT) +LIB_OPTIMIZATION:=-O2 +LIB_PATHS:=-L./$(LIB_OUT) +LIBS:=-lchacha20 -OS := $(shell uname) +OS:=$(shell uname) ifeq ($(OS), Linux) -TEST_OPTIMIZATION += -fsanitize=address +TEST_OPTIMIZATION+=-fsanitize=address endif -SRC := tests -SRC_FILES := $(wildcard $(SRC)/*.cpp) -OBJ := $(patsubst $(SRC)/%.cpp,$(SRC)/%.out,$(SRC_FILES)) +SRC:=tests +SRC_FILES:=$(wildcard $(SRC)/*.cpp) +OBJ:=$(patsubst $(SRC)/%.cpp,$(SRC)/%.out,$(SRC_FILES)) default: ifeq ($(OS), Linux) @@ -30,12 +30,10 @@ ifeq ($(OS), Linux) @mkdir $(HEADER_OUT) @mkdir $(LIB_OUT) @echo "creating static lib" - @echo "compiling uint320..." - @$(CC) -c uint320.cpp $(LIB_OPTIMIZATION) $(USERFLAGS) @echo "compiling ChaCha20..." - @$(CC) -c ChaCha20-Poly1305.cpp $(LIB_OPTIMIZATION) $(USERFLAGS) + @$(CXX) -c ChaCha20-Poly1305.cpp $(LIB_OPTIMIZATION) $(USERFLAGS) @echo "compiling $(LIB_OUTNAME)..." - @ar -r $(LIB_OUTNAME) uint320.o ChaCha20-Poly1305.o + @ar -r $(LIB_OUTNAME) ChaCha20-Poly1305.o @echo "build done : output -> $(LIB_OUTNAME)" @echo "moving files to build folder" @mv $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_OUTNAME) ./$(LIB_OUT)/ @@ -46,12 +44,10 @@ else @mkdir "$(HEADER_OUT)" @mkdir "$(LIB_OUT)" @echo "creating static lib" - @echo "compiling uint320..." - @$(CC) -c uint320.cpp $(LIB_OPTIMIZATION) $(USERFLAGS) @echo "compiling ChaCha20..." - @$(CC) -c ChaCha20-Poly1305.cpp $(LIB_OPTIMIZATION) $(USERFLAGS) + @$(CXX) -c ChaCha20-Poly1305.cpp $(LIB_OPTIMIZATION) $(USERFLAGS) @echo "compiling $(LIB_OUTNAME)..." - @ar -r $(LIB_OUTNAME) uint320.o ChaCha20.o + @ar -r $(LIB_OUTNAME) ChaCha20.o @echo "build done : output -> $(LIB_OUTNAME)" @echo "moving files to build folder" @move "./$(LIB_OUTNAME)" "$(LIB_OUT)" @@ -74,14 +70,14 @@ ifeq ($(OS), Linux) @echo "" @echo "running build test" @cp static-build.cpp build - @$(CC) build/static-build.cpp -o build/static-build.out -I./$(HEADER_OUT)/ -L./$(LIB_OUT) $(LIBS) + @$(CXX) build/static-build.cpp -o build/static-build.out -I./$(HEADER_OUT)/ -L./$(LIB_OUT) $(LIBS) @./build/static-build.out else @echo "===============================" @echo "" @echo "running build test" @copy static-build.cpp build - @$(CC) build/static-build.cpp -o build/static-build.exe -I./$(HEADER_OUT)/ -L./$(LIB_OUT) $(LIBS) + @$(CXX) build/static-build.cpp -o build/static-build.exe -I./$(HEADER_OUT)/ -L./$(LIB_OUT) $(LIBS) @build/static-build.exe endif @@ -93,14 +89,6 @@ static_test: $(OBJ) @./$(SRC)/QuarterRound_test.out @./$(SRC)/BlockFunction_test.out @./$(SRC)/Encryption_test.out - @./$(SRC)/constructor.out - @./$(SRC)/comparison.out - @./$(SRC)/leftshifts.out - @./$(SRC)/rightshifts.out - @./$(SRC)/addition.out - @./$(SRC)/subtraction.out - @./$(SRC)/multiplication.out - @./$(SRC)/division.out @./$(SRC)/poly1305_mac_test.out @./$(SRC)/poly1305_keygen.out @./$(SRC)/chacha20_aead_enc_dec.out @@ -134,8 +122,8 @@ static_test: $(OBJ) # -------------------------- test program compilation --------------------------- $(SRC)/%.out: $(SRC)/%.cpp - @echo "compiling test program (static build) - compiler : $(CC)" - @$(CC) $(CXXFLAGS) $(USERFLAGS) $(HEADER_PATHS) -o $@ $< $(LIB_PATHS) $(LIBS) $(TEST_OPTIMIZATION) + @echo "compiling test program (static build) - compiler : $(CXX)" + @$(CXX) $(CXXFLAGS) $(USERFLAGS) $(HEADER_PATHS) -o $@ $< $(LIB_PATHS) $(LIBS) $(TEST_OPTIMIZATION) install: ifeq ($(OS), Linux)