From 77511c68e4f8dad16bd215b541c53cd730d0df51 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 17 Jan 2022 16:48:23 +0100 Subject: Fix typo: libar2_earse -> libar2_erase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 2 +- common.h | 2 +- libar2.h | 8 ++++---- libar2_earse.c | 38 -------------------------------------- libar2_erase.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 44 deletions(-) delete mode 100644 libar2_earse.c create mode 100644 libar2_erase.c diff --git a/Makefile b/Makefile index ea08bac..346de0e 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ OBJ =\ libar2_decode_params.o\ libar2_encode_base64.o\ libar2_encode_params.o\ - libar2_earse.o\ + libar2_erase.o\ libar2_hash.o\ libar2_latest_argon2_version.o\ libar2_string_to_type.o\ diff --git a/common.h b/common.h index dd6f6c1..ba49332 100644 --- a/common.h +++ b/common.h @@ -54,7 +54,7 @@ #define MIN(A, B) ((A) < (B) ? (A) : (B)) -#define ERASE(PTR, N) libar2_earse(PTR, N) +#define ERASE(PTR, N) libar2_erase(PTR, N) #define ERASE_ARRAY(ARR) ERASE(ARR, sizeof(ARR)) #define ERASE_STRUCT(S) ERASE(&(S), sizeof(S)) diff --git a/libar2.h b/libar2.h index 07e60eb..835a02f 100644 --- a/libar2.h +++ b/libar2.h @@ -316,9 +316,9 @@ struct libar2_context { /** * Memory deallocation function * - * The application may which to earse the memory before + * The application may which to erase the memory before * deallocating it; this is not done by the library. - * This can be done using `libar2_earse`; + * This can be done using `libar2_erase`; * * Example implementation: * @@ -572,12 +572,12 @@ size_t libar2_decode_base64(const char *str, void *data, size_t *lenp); enum libar2_parameter_error libar2_validate_params(const struct libar2_argon2_parameters *params, const char **errmsgp); /** - * Securily earse memory + * Securily erase memory * * @param mem The memory to erase * @param size The number of bytes to erase */ -void libar2_earse(volatile void *mem, size_t size); +void libar2_erase(volatile void *mem, size_t size); /** * Hash a message diff --git a/libar2_earse.c b/libar2_earse.c deleted file mode 100644 index 905695a..0000000 --- a/libar2_earse.c +++ /dev/null @@ -1,38 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include "common.h" - - -#if defined(memset_s) -#elif defined(explicit_bzero) || defined(__OpenBSD__) -#elif defined(explicit_memset) -#else -# if defined(__GNUC__) -__attribute__((visibility("hidden"))) -# endif -void *(*const volatile libar2_internal_explicit_memset__)(void *, int, size_t) = &memset; -#endif - - -#if defined(__clang__) /* before __GNUC__ because that is also set in clang */ -# if __has_attribute(optnone) -__attribute__((optnone)) -# endif -#elif defined(__GNUC__) -# if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ >= 40400 -__attribute__((optimize("O0"))) -# endif -#endif -void -libar2_earse(volatile void *mem_, size_t size) -{ - void *mem = *(void **)(void *)&mem_; -#if defined(memset_s) - memset_s(mem, size); -#elif defined(explicit_bzero) || defined(__OpenBSD__) - explicit_bzero(mem, size); -#elif defined(explicit_memset) - explicit_memset(mem, 0, size); -#else - libar2_internal_explicit_memset__(mem, 0, size); -#endif -} diff --git a/libar2_erase.c b/libar2_erase.c new file mode 100644 index 0000000..490cc4a --- /dev/null +++ b/libar2_erase.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +#if defined(memset_s) +#elif defined(explicit_bzero) || defined(__OpenBSD__) +#elif defined(explicit_memset) +#else +# if defined(__GNUC__) +__attribute__((visibility("hidden"))) +# endif +void *(*const volatile libar2_internal_explicit_memset__)(void *, int, size_t) = &memset; +#endif + + +#if defined(__clang__) /* before __GNUC__ because that is also set in clang */ +# if __has_attribute(optnone) +__attribute__((optnone)) +# endif +#elif defined(__GNUC__) +# if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ >= 40400 +__attribute__((optimize("O0"))) +# endif +#endif +void +libar2_erase(volatile void *mem_, size_t size) +{ + void *mem = *(void **)(void *)&mem_; +#if defined(memset_s) + memset_s(mem, size); +#elif defined(explicit_bzero) || defined(__OpenBSD__) + explicit_bzero(mem, size); +#elif defined(explicit_memset) + explicit_memset(mem, 0, size); +#else + libar2_internal_explicit_memset__(mem, 0, size); +#endif +} + +/* Typo in version 1.0 */ +#if defined(__GNUC__) +extern __typeof(libar2_erase) libar2_earse __attribute__((__weak__, __alias__("libar2_erase"))); +#else +void libar2_earse(volatile void *mem, size_t size); +void +libar2_earse(volatile void *mem, size_t size) +{ + libar2_erase(mem, size); +} +#endif -- cgit v1.2.3-70-g09d2