mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 04:29:02 -04:00
add kore_mem_zero().
use it in places explicit_bzero() used to be called. The kore_mem_zero() is a best effort to try and let the compiler not optimize the code away. Highly platform dependent.
This commit is contained in:
parent
722a0eca21
commit
045beb8622
@ -909,6 +909,7 @@ void kore_mem_init(void);
|
||||
void kore_mem_cleanup(void);
|
||||
void kore_mem_untag(void *);
|
||||
void *kore_mem_lookup(u_int32_t);
|
||||
void kore_mem_zero(void *, size_t);
|
||||
void kore_mem_tag(void *, u_int32_t);
|
||||
void *kore_malloc_tagged(size_t, u_int32_t);
|
||||
|
||||
|
14
src/mem.c
14
src/mem.c
@ -264,6 +264,20 @@ kore_mem_lookup(u_int32_t id)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Best effort to try and let the compiler not optimize this call away. */
|
||||
void
|
||||
kore_mem_zero(void *ptr, size_t len)
|
||||
{
|
||||
volatile char *p;
|
||||
|
||||
p = (volatile char *)ptr;
|
||||
|
||||
if (p != NULL) {
|
||||
while (len-- > 0)
|
||||
*(p)++ = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t
|
||||
memblock_index(size_t len)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "kore.h"
|
||||
#include "sha1.h"
|
||||
|
||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||
@ -167,5 +168,5 @@ SHA1Final(u_int8_t digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context)
|
||||
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
||||
}
|
||||
|
||||
//explicit_bzero(context, sizeof(*context));
|
||||
kore_mem_zero(context, sizeof(*context));
|
||||
}
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#include "kore.h"
|
||||
#include "sha2.h"
|
||||
|
||||
/*
|
||||
@ -551,7 +552,7 @@ SHA256Final(u_int8_t digest[SHA256_DIGEST_LENGTH], SHA2_CTX *context)
|
||||
#else
|
||||
memcpy(digest, context->state.st32, SHA256_DIGEST_LENGTH);
|
||||
#endif
|
||||
//explicit_bzero(context, sizeof(*context));
|
||||
kore_mem_zero(context, sizeof(*context));
|
||||
}
|
||||
|
||||
|
||||
@ -827,7 +828,7 @@ SHA512Final(u_int8_t digest[SHA512_DIGEST_LENGTH], SHA2_CTX *context)
|
||||
#else
|
||||
memcpy(digest, context->state.st64, SHA512_DIGEST_LENGTH);
|
||||
#endif
|
||||
//explicit_bzero(context, sizeof(*context));
|
||||
kore_mem_zero(context, sizeof(*context));
|
||||
}
|
||||
|
||||
/*** SHA-384: *********************************************************/
|
||||
@ -874,5 +875,5 @@ SHA384Final(u_int8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context)
|
||||
memcpy(digest, context->state.st64, SHA384_DIGEST_LENGTH);
|
||||
#endif
|
||||
/* Zero out state data */
|
||||
//explicit_bzero(context, sizeof(*context));
|
||||
kore_mem_zero(context, sizeof(*context));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user