Skip to content

Commit

Permalink
feat: Add cipher mode mask and fix cc
Browse files Browse the repository at this point in the history
  • Loading branch information
VnUgE committed Aug 8, 2024
1 parent 7c8f910 commit f58245b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/noscryptutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern "C" {
#define E_CIPHER_BAD_INPUT -15
#define E_CIPHER_BAD_INPUT_SIZE -16

#define NC_UTIL_CIPHER_MODE 0x01u

#define NC_UTIL_CIPHER_MODE_ENCRYPT 0x00u
#define NC_UTIL_CIPHER_MODE_DECRYPT 0x01u
#define NC_UTIL_CIPHER_ZERO_ON_FREE 0x02u
Expand Down
10 changes: 7 additions & 3 deletions src/noscryptutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ NC_EXPORT NCUtilCipherContext* NC_CC NCUtilCipherAlloc(uint32_t encVersion, uint

if (encCtx != NULL)
{
/*
* Technically I should be using the NCEncSetProperty but this
* is an acceptable shortcut for now, may break in future
*/
encCtx->encArgs.version = encVersion;
encCtx->_flags = flags;
}
Expand Down Expand Up @@ -706,7 +710,7 @@ NC_EXPORT NCResult NC_CC NCUtilCipherInit(
CHECK_NULL_ARG(encCtx, 0);
CHECK_NULL_ARG(inputData, 1);

if ((encCtx->_flags & NC_UTIL_CIPHER_MODE_DECRYPT) > 0)
if ((encCtx->_flags & NC_UTIL_CIPHER_MODE) == NC_UTIL_CIPHER_MODE_DECRYPT)
{
/*
* Validate the input data for proper format for
Expand Down Expand Up @@ -854,7 +858,7 @@ NC_EXPORT NCResult NC_CC NCUtilCipherReadOutput(
return (NCResult)encCtx->buffer.actualOutput.size;
}

NC_EXPORT NCResult NCUtilCipherSetProperty(
NC_EXPORT NCResult NC_CC NCUtilCipherSetProperty(
NCUtilCipherContext* ctx,
uint32_t property,
uint8_t* value,
Expand Down Expand Up @@ -901,7 +905,7 @@ NC_EXPORT NCResult NC_CC NCUtilCipherUpdate(
{
case NC_ENC_VERSION_NIP44:

if ((encCtx->_flags & NC_UTIL_CIPHER_MODE_DECRYPT) > 0)
if ((encCtx->_flags & NC_UTIL_CIPHER_MODE) == NC_UTIL_CIPHER_MODE_DECRYPT)
{
return _nip44DecryptCompleteCore(libContext, sk, pk, encCtx);
}
Expand Down

0 comments on commit f58245b

Please sign in to comment.