Add test helper function unhexify_alloc()
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function
index f6a3529..2be5dcc 100644
--- a/tests/suites/helpers.function
+++ b/tests/suites/helpers.function
@@ -2,6 +2,13 @@
#include "polarssl/memory.h"
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_malloc malloc
+#define polarssl_free free
+#endif
+
#ifdef _MSC_VER
#include <basetsd.h>
typedef UINT32 uint32_t;
@@ -95,6 +102,27 @@
}
/**
+ * Allocate and fill a buffer from hex data.
+ *
+ * The buffer is sized exactly as needed. This allows to detect buffer
+ * overruns (including overreads) when running the test suite under valgrind.
+ *
+ * For convenience, dies if allocation fails.
+ */
+static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
+{
+ unsigned char *obuf;
+
+ *olen = strlen(ibuf) / 2;
+
+ assert( ( obuf = polarssl_malloc( *olen ) ) != NULL );
+
+ (void) unhexify( obuf, ibuf );
+
+ return( obuf );
+}
+
+/**
* This function just returns data from rand().
* Although predictable and often similar on multiple
* runs, this does not result in identical random on