summaryrefslogtreecommitdiff
path: root/src/lib/crypt.c
diff options
context:
space:
mode:
authorDimitri Staessens <Dimitri.Staessens@Quantum.Com>2026-01-28 00:35:28 +0100
committerSander Vrijders <sander@ouroboros.rocks>2026-02-02 08:07:04 +0100
commit37e3dbdd8206e4f0f03fab13ff3f38aa932be065 (patch)
treec7508d4a50bb8a1e6025b489418a5f9aae4a308e /src/lib/crypt.c
parente9fb0eb1130a8efacab3add17f524197a9044a88 (diff)
downloadouroboros-37e3dbdd8206e4f0f03fab13ff3f38aa932be065.tar.gz
ouroboros-37e3dbdd8206e4f0f03fab13ff3f38aa932be065.zip
lib: Fix OpenSSL includes and explicit_bzero on OSX
The include headers and NIDs are different on macOS X. It also doesn't have explicit_bzero. The crypt.h includes are now guarded to work on OS X (trying to avoid the includes by defining the OpenSSL mac header guard led to a whole list of other issues). The explicit zero'ing of buffers temporarily holding secrets has now been abstracted in a crypt_secure_clear() function defaulting to OpenSSL_cleanse, explicit_bzero (if present) or a best-effort option using a volatile pointer. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib/crypt.c')
-rw-r--r--src/lib/crypt.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/crypt.c b/src/lib/crypt.c
index fdbae776..38dd9f29 100644
--- a/src/lib/crypt.c
+++ b/src/lib/crypt.c
@@ -1064,3 +1064,24 @@ void crypt_secure_free(void * ptr,
free(ptr);
#endif
}
+
+void crypt_secure_clear(void * ptr,
+ size_t size)
+{
+ volatile uint8_t * p;
+
+ if (ptr == NULL)
+ return;
+
+#ifdef HAVE_OPENSSL
+ (void) p;
+ openssl_secure_clear(ptr, size);
+#elif defined(HAVE_EXPLICIT_BZERO)
+ (void) p;
+ explicit_bzero(ptr, size);
+#else /* best effort to avoid optimizing out */
+ p = ptr;
+ while (size-- > 0)
+ *p++ = 0;
+#endif
+}