As a spare-time personal project, I'm implementing a set of symmetric-key cryptographic primitives.
One thing I've left vacant for a long time, is the key/state eraser, which I decide to add right now.
I intend it to be a macro, so that it doesn't require any additional object file; the macro should be statement-like (as per this question), so that its usage is consistent with those from other lines.
Here's my current code:
#define ERASE_STATES(buf, len) \
do { \
for(uintptr_t i=0; i<len; i++) \
((char *)buf)[i] = 0; \
} while(0)
There's a few things I'm not entirely confident about.
len
is a cardinal and it'd probably be asize_t
, buti
is an ordinal, should I also usesize_t
, or change it to some other type for semantic consistency? (I'm usinguintptr_t
right now.)The signedness of the type
char
is explicitly undefined according to standard, but could it nontheless be used without sacrificing semantic consistency, as a generic type representing a byte when assigning non-negative values to it?Anything else I've missed?
Update
I'm not using memset
because I designed my code to be compilable in free-standing environment.
buf
would end up with non-zero bits, or observable gap didn't get re-initialized. \$\endgroup\$