Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 2cee801
Author: vnugent <public@vaughnnugent.com>
Date:   Mon May 6 22:02:39 2024 -0400

    Ensure static and dynamic libs get same args

commit f533694
Author: vnugent <public@vaughnnugent.com>
Date:   Mon May 6 21:50:29 2024 -0400

    feat: CMake install & fetch-content test & updates

commit 940ff20
Author: vnugent <public@vaughnnugent.com>
Date:   Sun May 5 14:07:28 2024 -0400

    codeberg readonly push

commit b34ed05
Merge: 0a40e20 e737556
Author: vnugent <public@vaughnnugent.com>
Date:   Sat May 4 14:06:45 2024 -0400

    Merge branch 'master' into develop

commit 0a40e20
Author: vnugent <public@vaughnnugent.com>
Date:   Sat May 4 13:55:19 2024 -0400

    ci: Force disable testing for win ci builds

commit 55fae18
Author: vnugent <public@vaughnnugent.com>
Date:   Thu May 2 21:54:35 2024 -0400

    feat: Working and tested openssl impl & defaults

commit 6ff8bb1
Author: vnugent <public@vaughnnugent.com>
Date:   Thu Apr 25 17:45:42 2024 -0400

    refactor: Finish support and testing for mbedtls

commit 7cb7a93
Author: vnugent <public@vaughnnugent.com>
Date:   Tue Apr 23 18:19:31 2024 -0400

    refactor!: MbedTLS on Windows, switch to uint32

commit 30e8dda
Author: vnugent <public@vaughnnugent.com>
Date:   Tue Apr 23 14:48:05 2024 -0400

    refactor: Crypto dep redesign working on Windows

commit d09c6c1
Author: vnugent <public@vaughnnugent.com>
Date:   Thu Apr 18 00:28:51 2024 -0400

    refactor!: Pushing what I have to dev

commit 54e06ad
Author: vnugent <public@vaughnnugent.com>
Date:   Sat Apr 13 01:24:00 2024 -0400

    fix: convert constants to hex, inline macro, ParseErrorCode

commit 4215e31
Merge: d3328f4 7485aa5
Author: vnugent <public@vaughnnugent.com>
Date:   Wed Apr 3 18:26:30 2024 -0400

    Merge branch 'master' into develop

commit d3328f4
Author: vnugent <public@vaughnnugent.com>
Date:   Wed Apr 3 18:22:56 2024 -0400

    build: Included dependency and versions in client builds

commit b11bc0b
Author: vnugent <public@vaughnnugent.com>
Date:   Wed Apr 3 18:10:08 2024 -0400

    fix: Fix c89 compatabilty comments and struct assignment

commit 9915bd4
Merge: 8e3d6ea 5184d7d
Author: vnugent <public@vaughnnugent.com>
Date:   Sat Mar 30 09:57:30 2024 -0400

    Merge branch 'master' into develop

commit 8e3d6ea
Author: vnugent <public@vaughnnugent.com>
Date:   Sat Mar 30 09:52:55 2024 -0400

    refactor!: Some api (struct) changes and updated tests

commit e88e842
Merge: 490dfee 21f6c0a
Author: vnugent <public@vaughnnugent.com>
Date:   Sun Mar 3 15:02:34 2024 -0500

    Merge branch 'master' into develop

commit 490dfee
Author: vnugent <public@vaughnnugent.com>
Date:   Sun Mar 3 14:59:25 2024 -0500

    test: #3 tests for encryption/description and Macs

commit efa9749
Merge: 1b84e3c 120022a
Author: vnugent <public@vaughnnugent.com>
Date:   Sun Mar 3 14:55:48 2024 -0500

    merge master

commit 1b84e3c
Author: vnugent <public@vaughnnugent.com>
Date:   Sat Mar 2 22:57:36 2024 -0500

    fix: #2 constent usage of sizeof() operator on struct types

commit 9de5a21
Author: vnugent <public@vaughnnugent.com>
Date:   Fri Mar 1 14:30:36 2024 -0500

    perf: avoid nc_key struct copy, cast and verify instead

commit b917b76
Author: vnugent <public@vaughnnugent.com>
Date:   Mon Feb 12 22:06:50 2024 -0500

    fix: found the constant time memcompare function

commit 9f85fff
Author: vnugent <public@vaughnnugent.com>
Date:   Fri Feb 9 22:48:35 2024 -0500

    feat: added/update MAC functions to sign or verify nip44 payload

commit aa51137
Author: vnugent <public@vaughnnugent.com>
Date:   Wed Feb 7 01:37:53 2024 -0500

    add missing hmac-key output buffer

commit 55f47d2
Author: vnugent <public@vaughnnugent.com>
Date:   Sun Feb 4 21:08:13 2024 -0500

    simple bug fixes, and public api argument validation tests

commit 73c5a71
Author: vnugent <public@vaughnnugent.com>
Date:   Fri Feb 2 23:05:48 2024 -0500

    update api to return secpvalidate return code instead of internal return codes

commit 06c7300
Author: vnugent <public@vaughnnugent.com>
Date:   Fri Feb 2 19:25:17 2024 -0500

    change to lgpl license

commit 6e79fdb
Author: vnugent <public@vaughnnugent.com>
Date:   Wed Jan 31 21:30:49 2024 -0500

    move validation macros, and optionally disable them

commit ac1e588
Author: vnugent <public@vaughnnugent.com>
Date:   Tue Jan 30 12:25:05 2024 -0500

    couple more tests, renable range checks, set flags for all projects
  • Loading branch information
VnUgE committed May 7, 2024
1 parent e737556 commit 872c49d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 63 deletions.
16 changes: 9 additions & 7 deletions .onedev-buildspec.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 17
version: 33
jobs:
- name: GitHub Push
steps:
Expand All @@ -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
Expand All @@ -18,8 +24,6 @@ jobs:
retryCondition: never
maxRetries: 3
retryDelay: 30
cpuRequirement: 250
memoryRequirement: 256
timeout: 3600
- name: GitHub Pull
steps:
Expand All @@ -39,6 +43,4 @@ jobs:
retryCondition: never
maxRetries: 3
retryDelay: 30
cpuRequirement: 250
memoryRequirement: 256
timeout: 3600
110 changes: 75 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

#############################################
#
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions noscrypt.build.sln

This file was deleted.

12 changes: 7 additions & 5 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 872c49d

Please sign in to comment.