using secure memory where applicable using sodium_malloc or sodium_mlock, where not

This commit is contained in:
TLINDEN
2015-01-13 13:07:32 +01:00
parent ecf243b7ae
commit 3c30d8871b
14 changed files with 92 additions and 50 deletions

View File

@@ -36,13 +36,28 @@ void *ucmalloc(size_t s) {
exit(-1);
}
memset (value, 0, size);
sodium_memzero(value, size);
/* printf("allocated %ld bytes at %p\n", size, value); */
return value;
}
void *smalloc(size_t s) {
if (s == 0)
return NULL;
size_t size = s * sizeof(byte);
void *value = sodium_malloc (size);
if (value == NULL) {
err(errno, "Cannot allocate %d bytes of memory", (int)s);
exit(-1);
}
return value;
}
void *urmalloc(size_t s) {
void *value = ucmalloc (s);
@@ -51,6 +66,14 @@ void *urmalloc(size_t s) {
return value;
}
void *srmalloc(size_t s) {
void *value = sodium_malloc (s);
arc4random_buf(value, s);
return value;
}
void *ucrealloc(void *d, size_t oldlen, size_t newlen) {
newlen = newlen * sizeof(byte);
@@ -75,3 +98,7 @@ void ucfree(void *d, size_t len) {
free(d);
}
}
void sfree(void *d) {
sodium_free(d);
}