diff options
-rw-r--r-- | .onedev-buildspec.yml | 16 | ||||
-rw-r--r-- | CMakeLists.txt | 110 | ||||
-rw-r--r-- | Taskfile.yaml | 8 | ||||
-rw-r--r-- | noscrypt.build.sln | 14 | ||||
-rw-r--r-- | tests/test.c | 12 |
5 files changed, 97 insertions, 63 deletions
diff --git a/.onedev-buildspec.yml b/.onedev-buildspec.yml index 716f0b2..ef1ac9d 100644 --- a/.onedev-buildspec.yml +++ b/.onedev-buildspec.yml @@ -1,4 +1,4 @@ -version: 17 +version: 33 jobs: - name: GitHub Push steps: @@ -7,8 +7,14 @@ jobs: remoteUrl: https://github.com/VnUgE/noscrypt.git userName: VnUgE passwordSecret: github-access-token - withLfs: false - force: false + force: true + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !PushRepository + name: Codeberg push sync + remoteUrl: https://codeberg.com/VnUgE/noscrypt.git + userName: VnUgE + passwordSecret: codeberg-access-token + force: true condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL triggers: - !TagCreateTrigger @@ -18,8 +24,6 @@ jobs: retryCondition: never maxRetries: 3 retryDelay: 30 - cpuRequirement: 250 - memoryRequirement: 256 timeout: 3600 - name: GitHub Pull steps: @@ -39,6 +43,4 @@ jobs: retryCondition: never maxRetries: 3 retryDelay: 30 - cpuRequirement: 250 - memoryRequirement: 256 timeout: 3600 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b8ce3d..8505d8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,13 @@ cmake_minimum_required (VERSION 3.10) -project(noscrypt C) +project( + noscrypt + LANGUAGES C + DESCRIPTION "A compact, C90 cross-platform, cryptography library built specifically for nostr" + HOMEPAGE_URL "https://www.vaughnnugent.com/resources/software/modules/noscrypt" +) +set(_NC_PROJ_NAME "noscrypt") option(NC_BUILD_TESTS "Build tests" OFF) option(NC_DISABLE_INPUT_VALIDATION "Disables public function input validation" OFF) @@ -86,22 +92,22 @@ set(NOSCRYPT_HEADERS ) #static/shared library -add_library(${CMAKE_PROJECT_NAME} SHARED ${NOSCRYPT_SRCS} ${NOSCRYPT_HEADERS}) -add_library(${CMAKE_PROJECT_NAME}_static STATIC ${NOSCRYPT_SRCS} ${NOSCRYPT_HEADERS}) -target_compile_features(${CMAKE_PROJECT_NAME} PUBLIC c_std_90) #force compiler to use c90 standard for library +add_library(${_NC_PROJ_NAME} SHARED ${NOSCRYPT_SRCS} ${NOSCRYPT_HEADERS}) +add_library(${_NC_PROJ_NAME}_static STATIC ${NOSCRYPT_SRCS} ${NOSCRYPT_HEADERS}) +target_compile_features(${_NC_PROJ_NAME} PUBLIC c_std_90) #force compiler to use c90 standard for library #link libsecp256k1 if(MSVC) - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE secp256k1) - target_link_libraries(${CMAKE_PROJECT_NAME}_static PRIVATE secp256k1) + target_link_libraries(${_NC_PROJ_NAME} PRIVATE secp256k1) + target_link_libraries(${_NC_PROJ_NAME}_static PRIVATE secp256k1) else() - target_link_libraries(${CMAKE_PROJECT_NAME} INTERFACE secp256k1) - target_link_libraries(${CMAKE_PROJECT_NAME}_static INTERFACE secp256k1) + target_link_libraries(${_NC_PROJ_NAME} INTERFACE secp256k1) + target_link_libraries(${_NC_PROJ_NAME}_static INTERFACE secp256k1) endif() #include secp256k1 headers -target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC vendor/secp256k1/include) -target_include_directories(${CMAKE_PROJECT_NAME}_static SYSTEM PUBLIC vendor/secp256k1/include) +target_include_directories(${_NC_PROJ_NAME} SYSTEM PUBLIC vendor/secp256k1/include) +target_include_directories(${_NC_PROJ_NAME}_static SYSTEM PUBLIC vendor/secp256k1/include) ############################################# # @@ -151,13 +157,13 @@ if(CRYPTO_LIB STREQUAL "mbedtls") message(STATUS "Linking to MbedTLS crypto library") #include mbedtls headers - target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC vendor/mbedtls/include) - target_include_directories(${CMAKE_PROJECT_NAME}_static SYSTEM PUBLIC vendor/mbedtls/include) + target_include_directories(${_NC_PROJ_NAME} SYSTEM PUBLIC vendor/mbedtls/include) + target_include_directories(${_NC_PROJ_NAME}_static SYSTEM PUBLIC vendor/mbedtls/include) if(NC_FETCH_MBEDTLS) #link to included mbedtls - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE mbedcrypto PRIVATE mbedtls) - target_link_libraries(${CMAKE_PROJECT_NAME}_static PRIVATE mbedcrypto PRIVATE mbedtls) + target_link_libraries(${_NC_PROJ_NAME} PRIVATE mbedcrypto PRIVATE mbedtls) + target_link_libraries(${_NC_PROJ_NAME}_static PRIVATE mbedcrypto PRIVATE mbedtls) else() #find the library find_library(MBEDTLS_LIB_CRYPTO @@ -174,8 +180,8 @@ if(CRYPTO_LIB STREQUAL "mbedtls") message(STATUS "Found mbedtls tls library at ${MBEDTLS_LIB_TLS}") #link to the library - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${MBEDTLS_LIB_CRYPTO} PRIVATE ${MBEDTLS_LIB_TLS}) - target_link_libraries(${CMAKE_PROJECT_NAME}_static PRIVATE ${MBEDTLS_LIB_CRYPTO} PRIVATE ${MBEDTLS_LIB_TLS}) + target_link_libraries(${_NC_PROJ_NAME} PRIVATE ${MBEDTLS_LIB_CRYPTO} PRIVATE ${MBEDTLS_LIB_TLS}) + target_link_libraries(${_NC_PROJ_NAME}_static PRIVATE ${MBEDTLS_LIB_CRYPTO} PRIVATE ${MBEDTLS_LIB_TLS}) endif() #enable mbedtls crypto library bindings @@ -187,13 +193,13 @@ elseif(CRYPTO_LIB STREQUAL "openssl") find_package(OpenSSL REQUIRED) #include openssl headers - target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC vendor/openssl/include) - target_include_directories(${CMAKE_PROJECT_NAME}_static SYSTEM PUBLIC vendor/openssl/include) + target_include_directories(${_NC_PROJ_NAME} SYSTEM PUBLIC vendor/openssl/include) + target_include_directories(${_NC_PROJ_NAME}_static SYSTEM PUBLIC vendor/openssl/include) #link to openssl message(STATUS "Linking to OpenSSL crypto library") - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OpenSSL::Crypto) - target_link_libraries(${CMAKE_PROJECT_NAME}_static PRIVATE OpenSSL::Crypto) + target_link_libraries(${_NC_PROJ_NAME} PRIVATE OpenSSL::Crypto) + target_link_libraries(${_NC_PROJ_NAME}_static PRIVATE OpenSSL::Crypto) #enable openssl crypto library bindings list(APPEND NC_PROJ_DEFINTIONS OPENSSL_CRYPTO_LIB) @@ -202,8 +208,8 @@ elseif(CRYPTO_LIB STREQUAL "bcrypt") if(MSVC) #link bcrypt for Windows platforms - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "bcrypt.lib") - target_link_libraries(${CMAKE_PROJECT_NAME}_static PRIVATE "bcrypt.lib") + target_link_libraries(${_NC_PROJ_NAME} PRIVATE "bcrypt.lib") + target_link_libraries(${_NC_PROJ_NAME}_static PRIVATE "bcrypt.lib") else() message(FATAL_ERROR "Bcrypt is only supported on Windows platforms") endif() @@ -221,11 +227,12 @@ if(NC_DISABLE_INPUT_VALIDATION) list(APPEND NC_PROJ_DEFINTIONS NC_INPUT_VALIDATION_OFF) endif() +set(_NC_COMPILE_OPTS) + #setup flags for windows compilation if(MSVC) - - #global windows cl flags - target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE + + list(APPEND _NC_COMPILE_OPTS /sdl #enable additional security checks /TC #compile as c /GS #buffer security check @@ -242,7 +249,7 @@ if(MSVC) $<$<CONFIG:Debug>:/WX> #warnings as errors (only for our project) $<$<CONFIG:Debug>:/Zi> #enable rich debug info $<$<CONFIG:Debug>:/Zo> - ) + ) #set build macros list(APPEND NC_PROJ_DEFINTIONS @@ -253,13 +260,14 @@ if(MSVC) #configure gcc flags elseif(CMAKE_COMPILER_IS_GNUCC) - target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wextra -fstack-protector) + list(APPEND _NC_COMPILE_OPTS + -Wextra + -fstack-protector + ) #if debug build enable additional debug flags if(build_type STREQUAL "debug") - target_compile_options( - ${CMAKE_PROJECT_NAME} - PRIVATE + list(APPEND _NC_COMPILE_OPTS -g -Og @@ -270,6 +278,9 @@ elseif(CMAKE_COMPILER_IS_GNUCC) endif() endif() +target_compile_options(${_NC_PROJ_NAME} PRIVATE ${_NC_COMPILE_OPTS}) +target_compile_options(${_NC_PROJ_NAME}_static PRIVATE ${_NC_COMPILE_OPTS}) + ############################################# # # Build/link monocypher @@ -289,8 +300,8 @@ if(NC_INCLUDE_MONOCYPHER) "vendor/monocypher/monocypher.h" ) - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE monocypher) - target_link_libraries(${CMAKE_PROJECT_NAME}_static PRIVATE monocypher) + target_link_libraries(${_NC_PROJ_NAME} PRIVATE monocypher) + target_link_libraries(${_NC_PROJ_NAME}_static PRIVATE monocypher) #share mc header with project target_include_directories(monocypher SYSTEM PUBLIC vendor/monocypher) @@ -319,21 +330,50 @@ if(NC_INCLUDE_MONOCYPHER) endif() #Set NC variables to both projects -target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE ${NC_PROJ_DEFINTIONS}) -target_compile_definitions(${CMAKE_PROJECT_NAME}_static PRIVATE ${NC_PROJ_DEFINTIONS}) +target_compile_definitions(${_NC_PROJ_NAME} PRIVATE ${NC_PROJ_DEFINTIONS}) +target_compile_definitions(${_NC_PROJ_NAME}_static PRIVATE ${NC_PROJ_DEFINTIONS}) #TESTS if(NC_BUILD_TESTS) #add test executable and link to library add_executable(nctest tests/test.c) - target_link_libraries(nctest ${CMAKE_PROJECT_NAME}_static) + target_link_libraries(nctest ${_NC_PROJ_NAME}_static) target_include_directories(nctest PRIVATE include) #enable c11 for testing target_compile_features(nctest PRIVATE c_std_11) endif() +########################### +# +# Installing +# +########################### + +#export shared library +install(TARGETS ${_NC_PROJ_NAME} + EXPORT MyLibraryTargets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) + +#export static library +install(TARGETS ${_NC_PROJ_NAME}_static + EXPORT MyLibraryTargets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) + +install(FILES + include/noscrypt.h + include/platform.h + DESTINATION noscrypt +) # Enable Hot Reload for MSVC compilers if supported. if (POLICY CMP0141) diff --git a/Taskfile.yaml b/Taskfile.yaml index 6524c5c..2fbda5a 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -43,13 +43,17 @@ tasks: cmds: - task: build-debug - cmd: cd {{.CMAKE_BUILD_DIR}} && {{if eq OS "windows"}}debug/nctest.exe{{else}}./nctest{{end}} + + install: + desc: "Uses cmake to install the library on your system" + cmds: + - cmd: cmake --install {{.CMAKE_BUILD_DIR}} {{.CLI_ARGS}} #CI ONLY!! #called by build pipeline to build module build: - desc: "DO NOT RUN! CI Only" cmds: - echo "building project {{.PROJECT_NAME}}" - cmd: powershell -Command "mkdir bin/ -Force" @@ -109,7 +113,7 @@ tasks: desc: "Packs up the project source code and creates a tarball in the builds binary directory" vars: TARGET_SOURCE: '{{.PROJECT_DIR}}/{{.BINARY_DIR}}/{{.PROJECT_NAME}}-src.tgz' - SOURCE_FILES: 'CMakeLists.txt src include license tests Taskfile.yaml' + SOURCE_FILES: 'CMakeLists.txt src include license tests vendor readme.md Taskfile.yaml' cmds: #tar up the source diff --git a/noscrypt.build.sln b/noscrypt.build.sln deleted file mode 100644 index 58ea566..0000000 --- a/noscrypt.build.sln +++ /dev/null @@ -1,14 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31903.59 -MinimumVisualStudioVersion = 10.0.40219.1 -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/tests/test.c b/tests/test.c index 3aaf067..bcda32f 100644 --- a/tests/test.c +++ b/tests/test.c @@ -205,23 +205,24 @@ static int TestEcdsa(NCContext* context, NCSecretKey* secKey, NCPublicKey* pubKe FillRandomData(invalidSig, sizeof(invalidSig)); FillRandomData(sigEntropy, sizeof(sigEntropy)); + /* This is the sha256 digest of the message charater buffer above */ digestHex = FromHexString("58884db8f9b2d5583a54b44daeccf029af4dd2874aa5e3dc0e55febebab55d18", 32); - /* Sign and verify sig64 */ + /* Test signing just the message digest */ { uint8_t sig[64]; TEST(NCSignDigest(context, secKey, sigEntropy, digestHex->data, sig), NC_SUCCESS); TEST(NCVerifyDigest(context, pubKey, digestHex->data, sig), NC_SUCCESS); } - /* Sign and verify raw data */ + /* Sign and verify the raw message */ { uint8_t sig[64]; TEST(NCSignData(context, secKey, sigEntropy, (uint8_t*)message, strlen32(message), sig), NC_SUCCESS); TEST(NCVerifyData(context, pubKey, (uint8_t*)message, strlen32(message), sig), NC_SUCCESS); } - /* ensure the signature is the same for signing data and sig64 */ + /* Tests that signing the message and it's digest result in the same signature */ { uint8_t sig1[64]; uint8_t sig2[64]; @@ -234,7 +235,7 @@ static int TestEcdsa(NCContext* context, NCSecretKey* secKey, NCPublicKey* pubKe TEST(memcmp(sig1, sig2, 64), 0); } - /* Try signing data then veriyfing the sig64 */ + /* Checks that the signature raw message can be verified against the digest of the message */ { uint8_t sig[64]; @@ -292,7 +293,8 @@ static int TestPublicApiArgumentValidation(void) /* * Test null context * NOTE: This is never freed, this shouldnt be an issue - * for testing, but this will leak memory. + * for testing, but this will leak memory. (libsecp256k2 + * allocates internally) */ TEST(NCDestroyContext(NULL), ARG_ERROR_POS_0) |