From c28af52040959d475539d2053913106edf87ad22 Mon Sep 17 00:00:00 2001 From: mrdcvlsc Date: Tue, 28 May 2024 22:44:38 +0800 Subject: [PATCH] added ci for msvc --- .clang-format | 43 ++++++++++++++++++++++++++++++++++++++ .clangd | 17 +++++++++++++++ .github/workflows/msvc.yml | 34 ++++++++++++++++++++++++++++++ ChaCha20-Poly1305.hpp | 3 ++- makefile | 5 +++-- tests/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++ uint320.cpp | 26 +++++++++++++---------- 7 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 .clang-format create mode 100644 .clangd create mode 100644 .github/workflows/msvc.yml create mode 100644 tests/CMakeLists.txt diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a149273 --- /dev/null +++ b/.clang-format @@ -0,0 +1,43 @@ +--- +BasedOnStyle: Microsoft +IndentWidth: 4 + +Language: Cpp +SortIncludes: false + +UseTab: Never +TabWidth: 2 +AlignConsecutiveDeclarations: true +ContinuationIndentWidth: 2 + +# LINES +AllowShortEnumsOnASingleLine: true +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +EmptyLineAfterAccessModifier: Always + +# BRACE WRAPPINGS +BraceWrapping: + AfterControlStatement: Never + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterFunction: false + AfterClass: false + BeforeCatch: false + BeforeElse: false + BeforeWhile: false +# AfterCaseLabel: false + +# INDENTATIONS +AlignAfterOpenBracket: BlockIndent +NamespaceIndentation: All +IndentCaseLabels: true +IndentPPDirectives: BeforeHash +# IndentAccessModifiers: true +AccessModifierOffset: 0 + +# SPACES +FixNamespaceComments: true +SpaceBeforeRangeBasedForLoopColon: false +SpaceAfterCStyleCast: true \ No newline at end of file diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..2fe90f3 --- /dev/null +++ b/.clangd @@ -0,0 +1,17 @@ +InlayHints: + Designators: No + Enabled: Yes + ParameterNames: No + DeducedTypes: Yes + +CompileFlags: + Add: [-std=c++11, -I"include/epi", -I"benchmark/boost/include", -Wall, -Wextra, -Wpedantic, -Werror] + Compiler: clang++ + +Diagnostics: + ClangTidy: + Add: [modernize*, cppcoreguidelines*, performance*, bugprone*, clang-analyzer*, darwin*, abseil* ] + Remove: [ + modernize-use-trailing-return-type, + cppcoreguidelines-avoid-magic-numbers + ] \ No newline at end of file diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml new file mode 100644 index 0000000..3fd8863 --- /dev/null +++ b/.github/workflows/msvc.yml @@ -0,0 +1,34 @@ +name: msvc + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + header-mode-tests: + + name: ${{ matrix.platform.name }} + runs-on: ${{ matrix.platform.os }} + + strategy: + fail-fast: false + matrix: + platform: + - { name: Windows VS2019, os: windows-2019, flags: -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Debug } + - { name: Windows VS2022, os: windows-2022, flags: -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Debug } + - { name: Windows VS2022, os: windows-latest, flags: -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Debug } + - { name: Windows Clang, os: windows-latest, flags: -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ } + + steps: + - uses: actions/checkout@v3 + + - name: Configure test executables + run: cmake -S tests -B tests ${{matrix.platform.flags}} + + - name: Build ${{matrix.platform.bin}} test executables + run: cmake --build tests --config Debug + + - name: Run ${{matrix.platform.bin}} test executables + run: ctest --test-dir tests \ No newline at end of file diff --git a/ChaCha20-Poly1305.hpp b/ChaCha20-Poly1305.hpp index a935b89..db2bd8e 100644 --- a/ChaCha20-Poly1305.hpp +++ b/ChaCha20-Poly1305.hpp @@ -51,7 +51,8 @@ typedef unsigned long long ulongint; typedef unsigned long ulongint; #define PRINT_LIMBHEX "%016lx " #else -#error not supported +#define PRINT_LIMBHEX "%016lx " +#define _PURE_CPP #endif /// for intel & amd x86_64 & x64 architectures only. diff --git a/makefile b/makefile index 7b8e7ff..87e53fa 100644 --- a/makefile +++ b/makefile @@ -62,8 +62,9 @@ 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 : $(CC)" +# @echo "flags: $<" + $(CC) $(TESTFLAGS) $(CXXFLAGS) -o $@ $< clean: ifeq ($(OS), Linux) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..7381ca0 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.16) + +file(GLOB SOURCES "*.cpp") + +message("=========================") +# message(CMAKE_C_COMPILER="${CMAKE_C_COMPILER}") +# message(CMAKE_CPP_COMPILER="${CMAKE_CPP_COMPILER}") +# message(CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}") +# message(CMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}") +message("=========================") + + +set(CMAKE_VERBOSE_MAKEFILE ON) + +enable_testing() + +add_compile_definitions(_HIDE_WARNING) + +foreach(test_src_code ${SOURCES}) + get_filename_component(test_exec_name ${test_src_code} NAME_WE) + message("Source Code = ${test_src_code} | ${test_exec_name}") + add_executable(${test_exec_name} ${test_src_code}) + target_compile_features(${test_exec_name} PRIVATE cxx_std_11) + target_compile_options(${test_exec_name} PRIVATE -fsanitize=address) + target_link_options(${test_exec_name} PRIVATE -fsanitize=address) + + # message(CMAKE_C_COMPILER="${CMAKE_C_COMPILER}") + # message(CMAKE_CPP_COMPILER="${CMAKE_CPP_COMPILER}") + + add_test( + NAME ${test_exec_name} + COMMAND $ + ) +endforeach(test_src_code ${SOURCES}) diff --git a/uint320.cpp b/uint320.cpp index 2a8bd94..828cd47 100644 --- a/uint320.cpp +++ b/uint320.cpp @@ -19,6 +19,8 @@ #include "ChaCha20-Poly1305.hpp" #endif +#include "ChaCha20-Poly1305.hpp" + uint320::uint320(ulongint num) { limbs[0] = num; limbs[1] = 0UL; @@ -59,7 +61,9 @@ uint320& uint320::operator=(const uint320& src) { return *this; } -uint320::~uint320(){} +uint320::~uint320(){ + memset(limbs, 0x00, UINT320BYTES); +} /// @return returns; 0 : if uint320 == 0, 1 : if uint320 == 1, and -1 : if uint320 != to 0 or 1. int uint320::one_or_zero() const { @@ -154,11 +158,11 @@ uint320& uint320::operator+=(const uint320& add) { "adcq %[adn3], %[sum3]\n\t" "adcq %[adn4], %[sum4]" : - [sum0]"+r"(limbs[0]), - [sum1]"+r"(limbs[1]), - [sum2]"+r"(limbs[2]), - [sum3]"+r"(limbs[3]), - [sum4]"+r"(limbs[4]) + [sum0]"+g"(limbs[0]), + [sum1]"+g"(limbs[1]), + [sum2]"+g"(limbs[2]), + [sum3]"+g"(limbs[3]), + [sum4]"+g"(limbs[4]) : [adn0]"m"(add.limbs[0]), [adn1]"m"(add.limbs[1]), @@ -361,11 +365,11 @@ uint320 uint320::operator*(const uint320& mr) const { "addq %%rax, %[pd4]\n\t" : - [pd0]"+r"(pd.limbs[0]), - [pd1]"+r"(pd.limbs[1]), - [pd2]"+r"(pd.limbs[2]), - [pd3]"+r"(pd.limbs[3]), - [pd4]"+r"(pd.limbs[4]) + [pd0]"+g"(pd.limbs[0]), + [pd1]"+g"(pd.limbs[1]), + [pd2]"+g"(pd.limbs[2]), + [pd3]"+g"(pd.limbs[3]), + [pd4]"+g"(pd.limbs[4]) : [mr0]"m"(mr.limbs[0]), [mr1]"m"(mr.limbs[1]),