summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-09-12 14:26:59 -0700
committerAndreas Kling <kling@serenityos.org>2021-09-13 00:02:42 +0200
commitff1e5aa93568c916cc5d78d4dcf92f08db537561 (patch)
tree89c2ce3fca93c334a16427095fdbdd828af538ef
parentf6ad7dfc0bdc2c7c05ec07c3d8c0df8e7f520020 (diff)
downloadserenity-ff1e5aa93568c916cc5d78d4dcf92f08db537561.zip
AK: Add secure_zero() implementation so it can be used on all platforms
Serenity has explicit_bzero() in LibC with the same implementation, however we need to be able to use this from Lagom on all platforms that we support building serenity on. I've implemented it in AK for this reason.
-rw-r--r--AK/Memory.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/AK/Memory.h b/AK/Memory.h
index 45d148f74d..8b5546f729 100644
--- a/AK/Memory.h
+++ b/AK/Memory.h
@@ -40,3 +40,16 @@ ALWAYS_INLINE void fast_u32_fill(u32* dest, u32 value, size_t count)
}
#endif
}
+
+namespace AK {
+inline void secure_zero(void* ptr, size_t size)
+{
+ __builtin_memset(ptr, 0, size);
+ // The memory barrier is here to avoid the compiler optimizing
+ // away the memset when we rely on it for wiping secrets.
+ asm volatile("" ::
+ : "memory");
+}
+}
+
+using AK::secure_zero;