Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit d5235f5
Author: vnugent <public@vaughnnugent.com>
Date:   Fri Sep 6 21:44:09 2024 -0400

    update changelog for v0.1.5

commit b4a5a50
Author: vnugent <public@vaughnnugent.com>
Date:   Fri Sep 6 21:37:01 2024 -0400

    configure autobuild for master branch

commit de9741b
Author: vnugent <public@vaughnnugent.com>
Date:   Wed Aug 28 19:54:45 2024 -0400

    feat: add library context alloc util functions
  • Loading branch information
VnUgE committed Sep 7, 2024
1 parent ea15299 commit 13bcaa2
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 22 deletions.
49 changes: 35 additions & 14 deletions .onedev-buildspec.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: 33
version: 35
jobs:
- name: GitHub Push

- name: Git mirror push
steps:
- !PushRepository
name: Github push sync
Expand All @@ -25,22 +26,42 @@ jobs:
maxRetries: 3
retryDelay: 30
timeout: 3600
- name: GitHub Pull

- name: Build and publish
jobExecutor: primary-shell-executor
steps:
- !PullRepository
name: GitHub sync pull
remoteUrl: https://github.com/VnUgE/noscrypt.git
userName: VnUgE
passwordSecret: github-access-token
refs: refs/heads/* refs/tags/*
- !CheckoutStep
name: Code checkout
cloneCredential: !DefaultCredential {}
withLfs: false
force: false
withSubmodules: false
checkoutPath: '@project_name@/'
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: VNBuild build
runInContainer: false
interpreter: !DefaultInterpreter
commands: |
vnbuild build -S --verbose
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: VNBuild publish
runInContainer: false
interpreter: !DefaultInterpreter
commands: |
vnbuild publish --ftp "@secret:ftp_server_address@" --sign
envVars:
- name: FTP_USERNAME
value: '@secret:ftp_username@'
- name: FTP_PASSWORD
value: '@secret:ftp_password@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
triggers:
- !ScheduleTrigger
cronExpression: 0 15 10 ? * *
projects: noscrypt
- !BranchUpdateTrigger
branches: master
retryCondition: never
maxRetries: 3
retryDelay: 30
timeout: 3600
timeout: 3600
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- C# .NET 8.0 library wrapper for noscrypt
- NIP44 vector testing for encryption

- Full NIP44 vector testing for encryption

## [0.1.5]

### Added
- `NCUtilContextAlloc()` and `NCUtilContextFree()` utilities for dynamic library context allocation

### Changed
- Public and Secret key structure definition names have been correctly namespaced __(no breaking changes)__

## [0.1.4]

### Fixed
Expand Down Expand Up @@ -69,7 +77,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- NCContext structure defintion.
- Internal headers from the public include directory.

[unreleased]: https://github.com/VnUgE/noscrypt/compare/v0.1.4...HEAD
[unreleased]: https://github.com/VnUgE/noscrypt/compare/v0.1.5...HEAD
[0.1.5]: https://github.com/VnUgE/noscrypt/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/VnUgE/noscrypt/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/VnUgE/noscrypt/compare/v0.1.2...v0.1.3
[0.1.2]: https://github.com/VnUgE/noscrypt/compare/v0.1.1...v0.1.2
Expand Down
4 changes: 2 additions & 2 deletions include/noscrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ typedef int64_t NCResult;
/*
An secp256k1 secret key (aka private key buffer)
*/
typedef struct secret_key_struct {
typedef struct nc_secret_key_struct {

uint8_t key[NC_SEC_KEY_SIZE];

Expand All @@ -165,7 +165,7 @@ typedef struct secret_key_struct {
/*
An x-only secp256k1 public key
*/
typedef struct xonly_pubkey_struct {
typedef struct nc_xonly_pubkey_struct {

uint8_t key[NC_PUBKEY_SIZE];

Expand Down
13 changes: 13 additions & 0 deletions include/noscryptutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ NC_EXPORT NCResult NC_CC NCUtilGetEncryptionPaddedSize(uint32_t encVersion, uint
*/
NC_EXPORT NCResult NC_CC NCUtilGetEncryptionBufferSize(uint32_t encVersion, uint32_t plaintextSize);

/*
* Allocates a new library context structure dynamically on the heap and returns a pointer to
* it. The library context must be freed with NCUtilContextFree when it is no longer needed.
* @return A valid pointer to a new library context or NULL if the operation failed
*/
NC_EXPORT NCContext* NC_CC NCUtilContextAlloc(void);

/*
* Frees the library context structure and clears the memory it points to.
* @param ctx A valid pointer to a library context memory
*/
NC_EXPORT void NC_CC NCUtilContextFree(NCContext* ctx);

/*
* Allocates a new encryption context and sets the encryption version and flags. The encryption context
* must be freed with NCUtilCipherFree when it is no longer needed.
Expand Down
13 changes: 13 additions & 0 deletions src/noscryptutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,19 @@ NC_EXPORT NCResult NC_CC NCUtilGetEncryptionBufferSize(uint32_t encVersion, uint
}


NC_EXPORT NCContext* NC_CC NCUtilContextAlloc(void)
{
/* Dynamically allocate context aligned and zeroed */
return (NCContext*)_nc_mem_alloc(1, NCGetContextStructSize());
}


NC_EXPORT void NC_CC NCUtilContextFree(NCContext* ctx)
{
_nc_mem_free(ctx);
}


NC_EXPORT NCUtilCipherContext* NC_CC NCUtilCipherAlloc(uint32_t encVersion, uint32_t flags)
{
NCUtilCipherContext* encCtx;
Expand Down
14 changes: 11 additions & 3 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@

#include "hex.h"

#ifdef NC_ENABLE_UTILS
#include <noscryptutil.h>
#endif

/*Pre-computed constants for argument errors */
#define ARG_ERROR_POS_0 E_NULL_PTR
#define ARG_ERROR(pos) NCResultWithArgPosition(E_NULL_PTR, pos)
Expand Down Expand Up @@ -365,7 +369,13 @@ static int TestPublicApiArgumentValidation()
* Alloc context structure on the heap before use.
* THIS WILL LEAK IN THE CURRENT CONFIG ALWAYS FREE UNDER NORMAL CONDITIONS
*/

#ifdef NOSCRYPTUTIL_H
ctx = NCUtilContextAlloc();
#else
ctx = (NCContext*)malloc(NCGetContextStructSize());
#endif

TASSERT(ctx != NULL)

/*Test null context*/
Expand Down Expand Up @@ -608,9 +618,7 @@ static int TestCorrectEncryption(const NCContext* context)
return 0;
}

#ifdef NC_ENABLE_UTILS

#include <noscryptutil.h>
#ifdef NOSCRYPTUTIL_H

/* Padding tests taken from the nip44 repo vectors.json file */
static const uint32_t _padTestActual[24] = { 16, 32, 33, 37, 45, 49, 64, 65, 100, 111, 200, 250, 320, 383, 384, 400, 500, 512, 515, 700, 800, 900, 1020, 65536 };
Expand Down

0 comments on commit 13bcaa2

Please sign in to comment.