More cleanup.
This commit is contained in:
parent
88997a0314
commit
f23a43fb81
3 changed files with 79 additions and 130 deletions
|
@ -55,6 +55,15 @@ namespace ZeroTier {
|
|||
|
||||
const char Utils::HEXCHARS[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
|
||||
|
||||
// Crazy hack to force memory to be securely zeroed in spite of the best efforts of optimizing compilers.
|
||||
static void _Utils_doBurn(volatile uint8_t *ptr,unsigned int len)
|
||||
{
|
||||
volatile uint8_t *const end = ptr + len;
|
||||
while (ptr != end) *(ptr++) = (uint8_t)0;
|
||||
}
|
||||
static void (*volatile _Utils_doBurn_ptr)(volatile uint8_t *,unsigned int) = _Utils_doBurn;
|
||||
void Utils::burn(void *ptr,unsigned int len) { (_Utils_doBurn_ptr)((volatile uint8_t *)ptr,len); }
|
||||
|
||||
static unsigned long _Utils_itoa(unsigned long n,char *s)
|
||||
{
|
||||
if (n == 0)
|
||||
|
@ -76,15 +85,6 @@ char *Utils::decimal(unsigned long n,char s[24])
|
|||
return s;
|
||||
}
|
||||
|
||||
// Crazy hack to force memory to be securely zeroed in spite of the best efforts of optimizing compilers.
|
||||
static void _Utils_doBurn(volatile uint8_t *ptr,unsigned int len)
|
||||
{
|
||||
volatile uint8_t *const end = ptr + len;
|
||||
while (ptr != end) *(ptr++) = (uint8_t)0;
|
||||
}
|
||||
static void (*volatile _Utils_doBurn_ptr)(volatile uint8_t *,unsigned int) = _Utils_doBurn;
|
||||
void Utils::burn(void *ptr,unsigned int len) { (_Utils_doBurn_ptr)((volatile uint8_t *)ptr,len); }
|
||||
|
||||
void Utils::getSecureRandom(void *buf,unsigned int bytes)
|
||||
{
|
||||
static Mutex globalLock;
|
||||
|
@ -171,22 +171,4 @@ void Utils::getSecureRandom(void *buf,unsigned int bytes)
|
|||
#endif // __WINDOWS__ or not
|
||||
}
|
||||
|
||||
bool Utils::scopy(char *dest,unsigned int len,const char *src)
|
||||
{
|
||||
if (!len)
|
||||
return false; // sanity check
|
||||
if (!src) {
|
||||
*dest = (char)0;
|
||||
return true;
|
||||
}
|
||||
char *end = dest + len;
|
||||
while ((*dest++ = *src++)) {
|
||||
if (dest == end) {
|
||||
*(--dest) = (char)0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue