aboutsummaryrefslogtreecommitdiff
path: root/include/axolotl/memory.hh
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-02-27 16:11:30 +0000
committerMark Haines <mark.haines@matrix.org>2015-02-27 16:11:30 +0000
commitc7419e7cdffc8c8d54dd918b03ed2c497fe7ca42 (patch)
tree6fd1bf8666863e36ab4729ec0f1ca8438e88e745 /include/axolotl/memory.hh
parentb3496b0aa16b8c4f9974ed54fca59ef631f83705 (diff)
Try to ensure the compiler cannot optimise away attempts to erase secrets from memory
Diffstat (limited to 'include/axolotl/memory.hh')
-rw-r--r--include/axolotl/memory.hh17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/axolotl/memory.hh b/include/axolotl/memory.hh
new file mode 100644
index 0000000..7749c54
--- /dev/null
+++ b/include/axolotl/memory.hh
@@ -0,0 +1,17 @@
+#include <cstddef>
+
+namespace axolotl {
+
+/** Clear the memory held in the buffer */
+void unset(
+ volatile void * buffer, std::size_t buffer_length
+);
+
+/** Clear the memory backing an object */
+template<typename T>
+void unset(T & value) {
+ unset(reinterpret_cast<volatile void *>(&value), sizeof(T));
+}
+
+
+} // namespace axolotl