aboutsummaryrefslogtreecommitdiff
path: root/src/noscrypt.c
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-01-31 21:30:49 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2024-01-31 21:30:49 -0500
commit6e79fdb3b6b6739fc7797d47e55a7691306cf736 (patch)
tree9c6fb05bec80d34f762752e984588aa3efb31a31 /src/noscrypt.c
parentac1e58837f1ba687939f78b5c03cadd346c10ddd (diff)
move validation macros, and optionally disable them
Diffstat (limited to 'src/noscrypt.c')
-rw-r--r--src/noscrypt.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/noscrypt.c b/src/noscrypt.c
index 55a098e..5c4691f 100644
--- a/src/noscrypt.c
+++ b/src/noscrypt.c
@@ -44,6 +44,35 @@
#include <string.h>
#define MEMMOV(dst, src, size) memmove(dst, src, size)
+/*
+* Validation macros
+*/
+
+#ifdef NC_INPUT_VALIDATION_OFF
+ #define CHECK_NULL_PTR(ptr) if(ptr == NULL) return E_NULL_PTR;
+ #define CHECK_INVALID_ARG(x) if(x == NULL) return E_INVALID_ARG;
+ #define CHECK_NULL_ARG(x, argPos) if(x == NULL) return NCResultWithArgPosition(E_NULL_PTR, argPos);
+ #define CHECK_ARG_RANGE(x, min, max, argPos) if(x < min || x > max) return NCResultWithArgPosition(E_ARGUMENT_OUT_OF_RANGE, argPos);
+#else
+ //empty macros
+ #define CHECK_NULL_PTR(ptr)
+ #define CHECK_INVALID_ARG(x)
+ #define CHECK_NULL_ARG(x, argPos)
+ #define CHECK_ARG_RANGE(x, min, max, argPos)
+#endif // !NC_DISABLE_INPUT_VALIDATION
+
+
+#ifdef DEBUG
+ /* Must include assert.h for assertions */
+ #include <assert.h>
+ #define DEBUG_ASSERT(x) assert(x);
+ #define DEBUG_ASSERT2(x, message) assert(x && message);
+#else
+ #define DEBUG_ASSERT(x)
+ #define DEBUG_ASSERT2(x, message)
+#endif
+
+
struct nc_expand_keys {
uint8_t chacha_key[CHACHA_KEY_SIZE];
uint8_t chacha_nonce[CHACHA_NONCE_SIZE];