ref: 3ac4d72f007d089e96b5f06068338cb48c5521df
parent: 3782820d83a94660fe1ab05089782a1a29c37b61
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Feb 24 16:46:21 EST 2018
Add secure clearing util functions.
--- a/lib/crypto/bld.sub
+++ b/lib/crypto/bld.sub
@@ -20,8 +20,9 @@
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
--- /dev/null
+++ b/lib/crypto/clear.myr
@@ -1,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)
+}