summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-02-24 21:46:21 -0800
committerOri Bernstein <ori@eigenstate.org>2018-02-24 21:52:51 -0800
commit3ac4d72f007d089e96b5f06068338cb48c5521df (patch)
treef690f9dc27e12460a5058295016ca41f559357e2
parent3782820d83a94660fe1ab05089782a1a29c37b61 (diff)
downloadmc-3ac4d72f007d089e96b5f06068338cb48c5521df.tar.gz
Add secure clearing util functions.
-rw-r--r--lib/crypto/bld.sub3
-rw-r--r--lib/crypto/clear.myr27
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/crypto/bld.sub b/lib/crypto/bld.sub
index cf53bee..1c58997 100644
--- a/lib/crypto/bld.sub
+++ b/lib/crypto/bld.sub
@@ -20,8 +20,9 @@ lib crypto =
entropy.myr # currently assumes a /dev/random
rand.myr
- # constant time arithmetic
+ # utilities for subtle bits
ct.myr
+ clear.myr
lib ../std:std
lib ../sys:sys
diff --git a/lib/crypto/clear.myr b/lib/crypto/clear.myr
new file mode 100644
index 0000000..1b68cd7
--- /dev/null
+++ b/lib/crypto/clear.myr
@@ -0,0 +1,27 @@
+use std
+
+pkg crypto =
+ /* designed to facilitating freeing sensitive data */
+ generic clear : (p : @a# -> void)
+ generic slclear : (sl : @a[:] -> void)
+ generic free : (p : @a# -> void)
+ generic slfree : (sl : @a[:] -> void)
+;;
+
+generic clear = {p : @a#
+ std.memfill(p, 0, sizeof(@a))
+}
+
+generic slclear = {p : @a[:]
+ std.memfill(sl, 0, sizeof(@a)*sl.len)
+}
+
+generic free = {p : @a#
+ clear(p)
+ std.free(p)
+}
+
+generic slfree = {sl : @a[:]
+ slclear(p)
+ std.slfree(p)
+}