xtest: remove security_utils_mem.[ch]
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/host/xtest/Makefile b/host/xtest/Makefile
index 0607210..81421e5 100644
--- a/host/xtest/Makefile
+++ b/host/xtest/Makefile
@@ -45,8 +45,7 @@
adbg/src/adbg_log.c \
adbg/src/adbg_run.c \
adbg/src/adbg_util.c \
- adbg/src/security_utils_hex.c \
- adbg/src/security_utils_mem.c
+ adbg/src/security_utils_hex.c
ifdef CFG_GP_PACKAGE_PATH
CFLAGS += -DWITH_GP_TESTS
diff --git a/host/xtest/adbg/src/adbg_int.h b/host/xtest/adbg/src/adbg_int.h
index 8c87b2a..7d4323b 100644
--- a/host/xtest/adbg/src/adbg_int.h
+++ b/host/xtest/adbg/src/adbg_int.h
@@ -19,7 +19,6 @@
#include <adbg.h>
#include "security_utils_hex.h"
-#include "security_utils_mem.h"
#include <sys/queue.h>
diff --git a/host/xtest/adbg/src/security_utils_mem.c b/host/xtest/adbg/src/security_utils_mem.c
deleted file mode 100644
index 07d9984..0000000
--- a/host/xtest/adbg/src/security_utils_mem.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2014, STMicroelectronics International N.V.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-/*************************************************************************
-* 1. Includes
-*************************************************************************/
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include "security_utils_mem.h"
-
-/*************************************************************************
-* 2. Definition of external constants and variables
-*************************************************************************/
-
-/*************************************************************************
-* 3. File scope types, constants and variables
-*************************************************************************/
-
-/*************************************************************************
-* 4. Declaration of file local functions
-*************************************************************************/
-
-static uint32_t MWC_Random(void *Pointer_p);
-
-/*************************************************************************
-* 5. Definition of external functions
-*************************************************************************/
-void SecUtil_WipeMemory(
- void *const Buffer_p,
- const size_t BufferLength
- )
-{
- uint8_t *p = Buffer_p;
- size_t n;
- uint32_t Number;
-
- for (n = 0; n < BufferLength; n++)
- p[n] = (uint8_t)n;
-
- memset(p, 0xAA, BufferLength);
- memset(p, 0x55, BufferLength);
-
- for (n = 0; n < BufferLength / sizeof(uint32_t); n++) {
- Number = MWC_Random(Buffer_p);
- memcpy(p + n, &Number, sizeof(uint32_t));
- }
-
- n = (n - 1) * sizeof(uint32_t);
-
-/* Add the last bytes which didn't fill a complete uint32_t */
- Number = MWC_Random(Buffer_p);
- for (; n < BufferLength; n++) {
- p[n] = 0xF & (uint8_t)Number;
- Number >>= 8;
- }
-}
-
-void SecUtil_SecureHeapFree_helper(
- void **const Buffer_pp
- )
-{
- if (Buffer_pp != NULL) {
- if (*Buffer_pp != NULL) {
- free(*Buffer_pp);
- *Buffer_pp = NULL;
- }
- }
-}
-
-/*************************************************************************
-* 6. Definition of internal functions
-*************************************************************************/
-
-/*
- * There may be concurrent calls to this function but it doesn't matter,
- * the result will still be hard to predict.
- *
- * Inspiration for implementation of this function was collected from
- * http://www.bobwheeler.com/statistics/Password/MarsagliaPost.txt
- * It doesn't seem to have any specified license, but in any case
- * this a somewhat different implementation.
- */
-static uint32_t MWC_Random(void *Pointer_p)
-{
- static uint32_t static_z;
- static uint32_t static_w;
- static bool Initialized;
-/*
- * In case of concurrent access, use private variables for
- * the actual calculation.
- */
- uint32_t z = static_z;
- uint32_t w = static_w;
-
- if (!Initialized) {
- z = 362436069 * ((uint32_t)(uintptr_t)Pointer_p >> 16);
- w = 521288629 * ((uint32_t)(uintptr_t)Pointer_p & 0xFFFF);
- Initialized = true;
- }
-
- z = 36969 * (z & 65535) + (z >> 16);
- w = 18000 * (w & 65535) + (w >> 16);
-
- static_z = z;
- static_w = w;
-
- return (z << 16) + (w & 65535);
-}
diff --git a/host/xtest/adbg/src/security_utils_mem.h b/host/xtest/adbg/src/security_utils_mem.h
deleted file mode 100644
index 831710f..0000000
--- a/host/xtest/adbg/src/security_utils_mem.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2014, STMicroelectronics International N.V.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-#ifndef INCLUSION_GUARD_SECURITY_UTILS_MEM_H
-#define INCLUSION_GUARD_SECURITY_UTILS_MEM_H
-
-/*************************************************************************
-* 1. Includes
-*************************************************************************/
-
-#include <stdbool.h>
-/*************************************************************************
-* 2. Types, constants and external variables
-*************************************************************************/
-
-/*************************************************************************
-* 3. Functions and macros
-*************************************************************************/
-
-/**
- * Creates an allocated copy if a string while keeping track of
- * where the memory allocation was initiated.
- *
- * The copy should later be freed with HEAP_FREE
- *
- * @param in String_p The string to be copied
- *
- * @return Returns a pointer to a copy of String_p on success and NULL
- * if memory allocation failed.
- */
-#define SECUTIL_HEAP_STRDUP(String_p) \
- SecUtil_Heap_StrDup((String_p), false, __FILE__, __LINE__)
-
-/**
- * Creates an allocated copy if a string while keeping track of
- * where the memory allocation was initiated.
- *
- * The copy should later be freed with HEAP_UNSAFE_FREE
- *
- * @param in String_p The string to be copied
- *
- * @return Returns a pointer to a copy of String_p on success and NULL
- * if memory allocation failed.
- */
-#define SECUTIL_HEAP_UNSAFE_STRDUP(String_p) \
- SecUtil_Heap_StrDup((String_p), true, __FILE__, __LINE__)
-
-/**
- * This function is a helper function for the two macros
- * SECUTIL_HEAP_STRDUP and SECUTIL_HEAP_UNSAFE_STRDUP.
- *
- * The function allocates sufficient memroy for
- * a copy of the string String_p.
- *
- * @param in String_p The string to be copied
- * @param in Unsafe If true use HEAP_UNSAFE_UNTYPED_ALLOC_DBG else
- * use HEAP_UNTYPED_ALLOC_DBG
- * @param in File_p Name of the file where the function is called
- * @param in Line Line number of the file where the function is called
- *
- * @return Returns a pointer to a copy of String_p on success and NULL
- * if memory allocation failed.
- */
-char *SecUtil_Heap_StrDup(const char *const String_p, const bool Unsafe,
- const char *const File_p, const unsigned int Line);
-
-/**
- * Wipes the buffer using several different bit patterns to avoid
- * leaking information.
- *
- * This function should preferably be used as a help function in
- * a FREE macro.
- *
- * @param in Buffer_p Pointer to the buffer to wipe
- * @param in BufferLength Length (in bytes) of the buffer to wipe
- */
-void SecUtil_WipeMemory(void *const Buffer_p, const size_t BufferLength);
-
-
-/*
- * Modules using the SECURE_HEAP macros below should use them through
- * a private define. This makes it easier during code inspection to see
- * that the policy for handling memory is consistent.
- */
-
-/**
- * Macro for secure memory allocation. Only a wrapper for
- * HEAP_ALLOC. The interesting part is SECUTIL_SECURE_HEAP_FREE
- * below.
- *
- * @param in Type The type that memory should be allocated for
- *
- * @return a pointer to a buffer large enough to hald the supplied type,
- * or NULL on failure.
- */
-#define SECUTIL_SECURE_HEAP_ALLOC(Type) HEAP_ALLOC((TypeNmae))
-
-/**
- * Macro for secure memory allocation. Only a wrapper for
- * HEAP_UNTYPED_ALLOC. The interesting part is SECUTIL_SECURE_HEAP_FREE
- * below.
- *
- * @param in Size The size of the buffer to be allocated
- *
- * @return a pointer to a buffer of the specified size,
- * or NULL on failure.
- */
-#define SECUTIL_SECURE_UNTYPED_HEAP_ALLOC(Size) \
- HEAP_UNTYPED_ALLOC((Size))
-
-/**
- * Macro for secure memory free. Secure is in the sense that information
- * leakage is avoided by wiping the memory before it's released.
- *
- * Note that buffer must have been allocated with SECUTIL_SECURE_HEAP_ALLOC
- * or SECUTIL_SECURE_UNTYPED_HEAP_ALLOC before of anything could happen
- * (most likely a crash).
- *
- * @param in Buffer_pp A pointer to a pointer of the buffer to free.
- */
-#define SECUTIL_SECURE_HEAP_FREE(Buffer_pp) \
- SecUtil_SecureHeapFree_helper((void **)(Buffer_pp))
-
-
-/**
- * Helper function for SECUTIL_SECURE_HEAP_FREE. The function
- * calls HEAP_BUFFER_SIZE to determine the size of the buffer
- * and then calls SecUtil_WipeMemory to wipe the memory. Finally
- * the buffer is freed with HEAP_FREE
- *
- * If the supplied buffer is NULL this function does nothing.
- *
- * Note that the buffer has be allocated with HEAP_ALLOC or
- * HEAP_UNTYPED_HEAP_ALLOC before or anything could happen.
- *
- * @param in Buffer_pp A pointer to a pointer of the buffer to
- * wipe and free
- */
-void SecUtil_SecureHeapFree_helper(void **const Buffer_pp);
-
-/**
- * Macro for unaligned memcpy(). To be used when source or destination
- * may not be properly aligned. Usage of this macro will only affect
- * performance when copying large chunks of data (which is already
- * present in the memory cache).
- *
- * Use this macro if you cannot guarantee that the pointers
- * have properly aligned values.
- */
-#define SEC_MEMCPY_UNALIGNED(x, y, z) \
- do { \
- void *memcpy_hack_dst = (x); \
- const void *memcpy_hack_src = (y); \
- memcpy(memcpy_hack_dst, memcpy_hack_src, (z)); \
- } while (0)
-
-/**
- * Macros for secure erase.
- */
-#define SECUTIL_SECURE_ERASE_UINT32(X) { \
- *((volatile uint32*)(&X)) = 0 }
-
-#define SECUTIL_SECURE_ERASE_UINT16(X) { \
- *((volatile uint16*)(&X)) = 0 }
-
-#define SECUTIL_SECURE_ERASE_UINT8(X) { \
- *((volatile uint8*)(&X)) = 0 }
-
-#define SECUTIL_SECURE_ERASE_BOOLEAN(X) { \
- *((volatile bool*)(&X)) = 0 }
-
-#define SECUTIL_SECURE_ERASE_ARRAY(X) { \
- memset(((void *)(X)), 0x0, sizeof(X)) }
-
-#define SECUTIL_SECURE_ERASE_TYPED_ARRAY(X) { \
- SECUTIL_SECURE_ERASE_UNTYPED_ARRAY(X, sizeof(X)) }
-
-#define SECUTIL_SECURE_ERASE_UNTYPED_ARRAY(X, L) { \
- memset(((void *)(X)), 0x0, L) }
-
-#define SECUTIL_SECURE_ERASE_STRUCT(X) { \
- memset(((void *)(&X)), 0x0, sizeof(X)) }
-
-#endif /* INCLUSION_GUARD_SECURITY_UTILS_MEM_H */