Apply clang formatting.

Executed with:
`find . -regextype posix-egrep -regex ".*\.([hc]|fmt|function)" | xargs -L1 clang-format-12 -i`

Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c
index 2612fab..50148bf 100644
--- a/programs/test/benchmark.c
+++ b/programs/test/benchmark.c
@@ -23,155 +23,147 @@
 
 #include "mbedtls/platform.h"
 #if !defined(MBEDTLS_PLATFORM_C)
-#include <stdio.h>
-#include <stdlib.h>
-#define mbedtls_exit       exit
-#define mbedtls_printf     printf
-#define mbedtls_free       free
+#    include <stdio.h>
+#    include <stdlib.h>
+#    define mbedtls_exit   exit
+#    define mbedtls_printf printf
+#    define mbedtls_free   free
 #endif
 
 #if !defined(MBEDTLS_TIMING_C)
-int main( void )
+int main(void)
 {
     mbedtls_printf("MBEDTLS_TIMING_C not defined.\n");
-    mbedtls_exit( 0 );
+    mbedtls_exit(0);
 }
 #else
 
-#include <string.h>
-#include <stdlib.h>
+#    include <string.h>
+#    include <stdlib.h>
 
-#include "mbedtls/timing.h"
+#    include "mbedtls/timing.h"
 
-#include "mbedtls/md5.h"
-#include "mbedtls/ripemd160.h"
-#include "mbedtls/sha1.h"
-#include "mbedtls/sha256.h"
-#include "mbedtls/sha512.h"
+#    include "mbedtls/md5.h"
+#    include "mbedtls/ripemd160.h"
+#    include "mbedtls/sha1.h"
+#    include "mbedtls/sha256.h"
+#    include "mbedtls/sha512.h"
 
-#include "mbedtls/des.h"
-#include "mbedtls/aes.h"
-#include "mbedtls/aria.h"
-#include "mbedtls/camellia.h"
-#include "mbedtls/chacha20.h"
-#include "mbedtls/gcm.h"
-#include "mbedtls/ccm.h"
-#include "mbedtls/chachapoly.h"
-#include "mbedtls/cmac.h"
-#include "mbedtls/poly1305.h"
+#    include "mbedtls/des.h"
+#    include "mbedtls/aes.h"
+#    include "mbedtls/aria.h"
+#    include "mbedtls/camellia.h"
+#    include "mbedtls/chacha20.h"
+#    include "mbedtls/gcm.h"
+#    include "mbedtls/ccm.h"
+#    include "mbedtls/chachapoly.h"
+#    include "mbedtls/cmac.h"
+#    include "mbedtls/poly1305.h"
 
-#include "mbedtls/ctr_drbg.h"
-#include "mbedtls/hmac_drbg.h"
+#    include "mbedtls/ctr_drbg.h"
+#    include "mbedtls/hmac_drbg.h"
 
-#include "mbedtls/rsa.h"
-#include "mbedtls/dhm.h"
-#include "mbedtls/ecdsa.h"
-#include "mbedtls/ecdh.h"
+#    include "mbedtls/rsa.h"
+#    include "mbedtls/dhm.h"
+#    include "mbedtls/ecdsa.h"
+#    include "mbedtls/ecdh.h"
 
-#include "mbedtls/error.h"
+#    include "mbedtls/error.h"
 
-#ifndef asm
-#define asm __asm
-#endif
+#    ifndef asm
+#        define asm __asm
+#    endif
 
-#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
+#    if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
 
-#include <windows.h>
-#include <process.h>
+#        include <windows.h>
+#        include <process.h>
 
-struct _hr_time
-{
+struct _hr_time {
     LARGE_INTEGER start;
 };
 
-#else
+#    else
 
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <time.h>
+#        include <unistd.h>
+#        include <sys/types.h>
+#        include <sys/time.h>
+#        include <signal.h>
+#        include <time.h>
 
-struct _hr_time
-{
+struct _hr_time {
     struct timeval start;
 };
 
-#endif /* _WIN32 && !EFIX64 && !EFI32 */
+#    endif /* _WIN32 && !EFIX64 && !EFI32 */
 
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
-#include "mbedtls/memory_buffer_alloc.h"
-#endif
+#    if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
+#        include "mbedtls/memory_buffer_alloc.h"
+#    endif
 
-static void mbedtls_set_alarm( int seconds );
+static void mbedtls_set_alarm(int seconds);
 
 /*
  * For heap usage estimates, we need an estimate of the overhead per allocated
  * block. ptmalloc2/3 (used in gnu libc for instance) uses 2 size_t per block,
  * so use that as our baseline.
  */
-#define MEM_BLOCK_OVERHEAD  ( 2 * sizeof( size_t ) )
+#    define MEM_BLOCK_OVERHEAD (2 * sizeof(size_t))
 
 /*
  * Size to use for the alloc buffer if MEMORY_BUFFER_ALLOC_C is defined.
  */
-#define HEAP_SIZE       (1u << 16)  /* 64k */
+#    define HEAP_SIZE          (1u << 16) /* 64k */
 
-#define BUFSIZE         1024
-#define HEADER_FORMAT   "  %-24s :  "
-#define TITLE_LEN       25
+#    define BUFSIZE       1024
+#    define HEADER_FORMAT "  %-24s :  "
+#    define TITLE_LEN     25
 
-#define OPTIONS                                                         \
-    "md5, ripemd160, sha1, sha256, sha512,\n"                      \
-    "des3, des, camellia, chacha20,\n"                  \
-    "aes_cbc, aes_gcm, aes_ccm, aes_xts, chachapoly,\n"                 \
-    "aes_cmac, des3_cmac, poly1305\n"                                   \
-    "ctr_drbg, hmac_drbg\n"                                     \
-    "rsa, dhm, ecdsa, ecdh.\n"
+#    define OPTIONS                                         \
+        "md5, ripemd160, sha1, sha256, sha512,\n"           \
+        "des3, des, camellia, chacha20,\n"                  \
+        "aes_cbc, aes_gcm, aes_ccm, aes_xts, chachapoly,\n" \
+        "aes_cmac, des3_cmac, poly1305\n"                   \
+        "ctr_drbg, hmac_drbg\n"                             \
+        "rsa, dhm, ecdsa, ecdh.\n"
 
-#if defined(MBEDTLS_ERROR_C)
-#define PRINT_ERROR                                                     \
-        mbedtls_strerror( ret, ( char * )tmp, sizeof( tmp ) );          \
-        mbedtls_printf( "FAILED: %s\n", tmp );
-#else
-#define PRINT_ERROR                                                     \
-        mbedtls_printf( "FAILED: -0x%04x\n", (unsigned int) -ret );
-#endif
+#    if defined(MBEDTLS_ERROR_C)
+#        define PRINT_ERROR                                  \
+            mbedtls_strerror(ret, (char *)tmp, sizeof(tmp)); \
+            mbedtls_printf("FAILED: %s\n", tmp);
+#    else
+#        define PRINT_ERROR \
+            mbedtls_printf("FAILED: -0x%04x\n", (unsigned int)-ret);
+#    endif
 
-#define TIME_AND_TSC( TITLE, CODE )                                     \
-do {                                                                    \
-    unsigned long ii, jj, tsc;                                          \
-    int ret = 0;                                                        \
-                                                                        \
-    mbedtls_printf( HEADER_FORMAT, TITLE );                             \
-    fflush( stdout );                                                   \
-                                                                        \
-    mbedtls_set_alarm( 1 );                                             \
-    for( ii = 1; ret == 0 && ! mbedtls_timing_alarmed; ii++ )           \
-    {                                                                   \
-        ret = CODE;                                                     \
-    }                                                                   \
-                                                                        \
-    tsc = mbedtls_timing_hardclock();                                   \
-    for( jj = 0; ret == 0 && jj < 1024; jj++ )                          \
-    {                                                                   \
-        ret = CODE;                                                     \
-    }                                                                   \
-                                                                        \
-    if( ret != 0 )                                                      \
-    {                                                                   \
-        PRINT_ERROR;                                                    \
-    }                                                                   \
-    else                                                                \
-    {                                                                   \
-        mbedtls_printf( "%9lu KiB/s,  %9lu cycles/byte\n",              \
-                         ii * BUFSIZE / 1024,                           \
-                         ( mbedtls_timing_hardclock() - tsc )           \
-                         / ( jj * BUFSIZE ) );                          \
-    }                                                                   \
-} while( 0 )
+#    define TIME_AND_TSC(TITLE, CODE)                                      \
+        do {                                                               \
+            unsigned long ii, jj, tsc;                                     \
+            int ret = 0;                                                   \
+                                                                           \
+            mbedtls_printf(HEADER_FORMAT, TITLE);                          \
+            fflush(stdout);                                                \
+                                                                           \
+            mbedtls_set_alarm(1);                                          \
+            for (ii = 1; ret == 0 && !mbedtls_timing_alarmed; ii++) {      \
+                ret = CODE;                                                \
+            }                                                              \
+                                                                           \
+            tsc = mbedtls_timing_hardclock();                              \
+            for (jj = 0; ret == 0 && jj < 1024; jj++) {                    \
+                ret = CODE;                                                \
+            }                                                              \
+                                                                           \
+            if (ret != 0) {                                                \
+                PRINT_ERROR;                                               \
+            } else {                                                       \
+                mbedtls_printf(                                            \
+                    "%9lu KiB/s,  %9lu cycles/byte\n", ii *BUFSIZE / 1024, \
+                    (mbedtls_timing_hardclock() - tsc) / (jj * BUFSIZE));  \
+            }                                                              \
+        } while (0)
 
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG)
+#    if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG)
 
 /* How much space to reserve for the title when printing heap usage results.
  * Updated manually as the output of the following command:
@@ -181,67 +173,63 @@
  *
  * This computes the maximum length of a title +2 (because we appends "/s").
  * (If the value is too small, the only consequence is poor alignement.) */
-#define TITLE_SPACE 16
+#        define TITLE_SPACE 16
 
-#define MEMORY_MEASURE_INIT                                             \
-    size_t max_used, max_blocks, max_bytes;                             \
-    size_t prv_used, prv_blocks;                                        \
-    mbedtls_memory_buffer_alloc_cur_get( &prv_used, &prv_blocks );      \
-    mbedtls_memory_buffer_alloc_max_reset( );
+#        define MEMORY_MEASURE_INIT                                      \
+            size_t max_used, max_blocks, max_bytes;                      \
+            size_t prv_used, prv_blocks;                                 \
+            mbedtls_memory_buffer_alloc_cur_get(&prv_used, &prv_blocks); \
+            mbedtls_memory_buffer_alloc_max_reset();
 
-#define MEMORY_MEASURE_PRINT( title_len )                               \
-    mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks );      \
-    ii = TITLE_SPACE > (title_len) ? TITLE_SPACE - (title_len) : 1;     \
-    while( ii-- ) mbedtls_printf( " " );                                \
-    max_used -= prv_used;                                               \
-    max_blocks -= prv_blocks;                                           \
-    max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks;             \
-    mbedtls_printf( "%6u heap bytes", (unsigned) max_bytes );
+#        define MEMORY_MEASURE_PRINT(title_len)                             \
+            mbedtls_memory_buffer_alloc_max_get(&max_used, &max_blocks);    \
+            ii = TITLE_SPACE > (title_len) ? TITLE_SPACE - (title_len) : 1; \
+            while (ii--)                                                    \
+                mbedtls_printf(" ");                                        \
+            max_used -= prv_used;                                           \
+            max_blocks -= prv_blocks;                                       \
+            max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks;         \
+            mbedtls_printf("%6u heap bytes", (unsigned)max_bytes);
 
-#else
-#define MEMORY_MEASURE_INIT
-#define MEMORY_MEASURE_PRINT( title_len )
-#endif
+#    else
+#        define MEMORY_MEASURE_INIT
+#        define MEMORY_MEASURE_PRINT(title_len)
+#    endif
 
-#define TIME_PUBLIC( TITLE, TYPE, CODE )                                \
-do {                                                                    \
-    unsigned long ii;                                                   \
-    int ret;                                                            \
-    MEMORY_MEASURE_INIT;                                                \
-                                                                        \
-    mbedtls_printf( HEADER_FORMAT, TITLE );                             \
-    fflush( stdout );                                                   \
-    mbedtls_set_alarm( 3 );                                             \
-                                                                        \
-    ret = 0;                                                            \
-    for( ii = 1; ! mbedtls_timing_alarmed && ! ret ; ii++ )             \
-    {                                                                   \
-        CODE;                                                           \
-    }                                                                   \
-                                                                        \
-    if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED )               \
-    {                                                                   \
-        mbedtls_printf( "Feature Not Supported. Skipping.\n" );         \
-        ret = 0;                                                        \
-    }                                                                   \
-    else if( ret != 0 )                                                 \
-    {                                                                   \
-        PRINT_ERROR;                                                    \
-    }                                                                   \
-    else                                                                \
-    {                                                                   \
-        mbedtls_printf( "%6lu " TYPE "/s", ii / 3 );                    \
-        MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 );                     \
-        mbedtls_printf( "\n" );                                         \
-    }                                                                   \
-} while( 0 )
+#    define TIME_PUBLIC(TITLE, TYPE, CODE)                            \
+        do {                                                          \
+            unsigned long ii;                                         \
+            int ret;                                                  \
+            MEMORY_MEASURE_INIT;                                      \
+                                                                      \
+            mbedtls_printf(HEADER_FORMAT, TITLE);                     \
+            fflush(stdout);                                           \
+            mbedtls_set_alarm(3);                                     \
+                                                                      \
+            ret = 0;                                                  \
+            for (ii = 1; !mbedtls_timing_alarmed && !ret; ii++) {     \
+                CODE;                                                 \
+            }                                                         \
+                                                                      \
+            if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {    \
+                mbedtls_printf("Feature Not Supported. Skipping.\n"); \
+                ret = 0;                                              \
+            } else if (ret != 0) {                                    \
+                PRINT_ERROR;                                          \
+            } else {                                                  \
+                mbedtls_printf("%6lu " TYPE "/s", ii / 3);            \
+                MEMORY_MEASURE_PRINT(sizeof(TYPE) + 1);               \
+                mbedtls_printf("\n");                                 \
+            }                                                         \
+        } while (0)
 
-#if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
-    ( defined(_MSC_VER) && defined(_M_IX86) ) || defined(__WATCOMC__)
+#    if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) && \
+            (defined(_MSC_VER) && defined(_M_IX86)) ||           \
+        defined(__WATCOMC__)
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     /* clang-format off */
     unsigned long tsc;
@@ -250,180 +238,177 @@
     return tsc;
     /* clang-format on */
 }
-#endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
-          ( _MSC_VER && _M_IX86 ) || __WATCOMC__ */
+#    endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && \
+              ( _MSC_VER && _M_IX86 ) || __WATCOMC__ */
 
 /* some versions of mingw-64 have 32-bit longs even on x84_64 */
-#if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
-    defined(__GNUC__) && ( defined(__i386__) || (                       \
-    ( defined(__amd64__) || defined( __x86_64__) ) && __SIZEOF_LONG__ == 4 ) )
+#    if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&              \
+        defined(__GNUC__) &&                                                  \
+        (defined(__i386__) || ((defined(__amd64__) || defined(__x86_64__)) && \
+                               __SIZEOF_LONG__ == 4))
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     unsigned long lo, hi;
-    asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) );
-    return lo ;
+    asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
+    return lo;
 }
-#endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
-          __GNUC__ && __i386__ */
+#    endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && \
+              __GNUC__ && __i386__ */
 
-#if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
-    defined(__GNUC__) && ( defined(__amd64__) || defined(__x86_64__) )
+#    if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) && \
+        defined(__GNUC__) && (defined(__amd64__) || defined(__x86_64__))
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     unsigned long lo, hi;
-    asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) );
-    return lo | ( hi << 32 ) ;
+    asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
+    return lo | (hi << 32);
 }
-#endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
-          __GNUC__ && ( __amd64__ || __x86_64__ ) */
+#    endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && \
+              __GNUC__ && ( __amd64__ || __x86_64__ ) */
 
-#if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
-    defined(__GNUC__) && ( defined(__powerpc__) || defined(__ppc__) )
+#    if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) && \
+        defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     unsigned long tbl, tbu0, tbu1;
 
-    do
-    {
-        asm volatile( "mftbu %0" : "=r" (tbu0) );
-        asm volatile( "mftb  %0" : "=r" (tbl ) );
-        asm volatile( "mftbu %0" : "=r" (tbu1) );
-    }
-    while( tbu0 != tbu1 );
+    do {
+        asm volatile("mftbu %0" : "=r"(tbu0));
+        asm volatile("mftb  %0" : "=r"(tbl));
+        asm volatile("mftbu %0" : "=r"(tbu1));
+    } while (tbu0 != tbu1);
 
-    return tbl ;
+    return tbl;
 }
-#endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
-          __GNUC__ && ( __powerpc__ || __ppc__ ) */
+#    endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && \
+              __GNUC__ && ( __powerpc__ || __ppc__ ) */
 
-#if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
-    defined(__GNUC__) && defined(__sparc64__)
+#    if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) && \
+        defined(__GNUC__) && defined(__sparc64__)
 
-#if defined(__OpenBSD__)
-#warning OpenBSD does not allow access to tick register using software version instead
-#else
-#define HAVE_HARDCLOCK
+#        if defined(__OpenBSD__)
+#            warning OpenBSD does not allow access to tick register using software version instead
+#        else
+#            define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     unsigned long tick;
-    asm volatile( "rdpr %%tick, %0;" : "=&r" (tick) );
-    return tick ;
+    asm volatile("rdpr %%tick, %0;" : "=&r"(tick));
+    return tick;
 }
-#endif /* __OpenBSD__ */
-#endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
-          __GNUC__ && __sparc64__ */
+#        endif /* __OpenBSD__ */
+#    endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && \
+              __GNUC__ && __sparc64__ */
 
-#if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
-    defined(__GNUC__) && defined(__sparc__) && !defined(__sparc64__)
+#    if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) && \
+        defined(__GNUC__) && defined(__sparc__) && !defined(__sparc64__)
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     unsigned long tick;
-    asm volatile( ".byte 0x83, 0x41, 0x00, 0x00" );
-    asm volatile( "mov   %%g1, %0" : "=r" (tick) );
-    return tick ;
+    asm volatile(".byte 0x83, 0x41, 0x00, 0x00");
+    asm volatile("mov   %%g1, %0" : "=r"(tick));
+    return tick;
 }
-#endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
-          __GNUC__ && __sparc__ && !__sparc64__ */
+#    endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && \
+              __GNUC__ && __sparc__ && !__sparc64__ */
 
-#if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&      \
-    defined(__GNUC__) && defined(__alpha__)
+#    if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) && \
+        defined(__GNUC__) && defined(__alpha__)
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     unsigned long cc;
-    asm volatile( "rpcc %0" : "=r" (cc) );
-    return cc & 0xFFFFFFFF ;
+    asm volatile("rpcc %0" : "=r"(cc));
+    return cc & 0xFFFFFFFF;
 }
-#endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
-          __GNUC__ && __alpha__ */
+#    endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && \
+              __GNUC__ && __alpha__ */
 
-#if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&      \
-    defined(__GNUC__) && defined(__ia64__)
+#    if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) && \
+        defined(__GNUC__) && defined(__ia64__)
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     unsigned long itc;
-    asm volatile( "mov %0 = ar.itc" : "=r" (itc) );
-    return itc ;
+    asm volatile("mov %0 = ar.itc" : "=r"(itc));
+    return itc;
 }
-#endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
-          __GNUC__ && __ia64__ */
+#    endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && \
+              __GNUC__ && __ia64__ */
 
-#if !defined(HAVE_HARDCLOCK) && defined(_MSC_VER) && \
-    !defined(EFIX64) && !defined(EFI32)
+#    if !defined(HAVE_HARDCLOCK) && defined(_MSC_VER) && !defined(EFIX64) && \
+        !defined(EFI32)
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     LARGE_INTEGER offset;
 
-    QueryPerformanceCounter( &offset );
+    QueryPerformanceCounter(&offset);
 
-    return( (unsigned long)( offset.QuadPart ) );
+    return ((unsigned long)(offset.QuadPart));
 }
-#endif /* !HAVE_HARDCLOCK && _MSC_VER && !EFIX64 && !EFI32 */
+#    endif /* !HAVE_HARDCLOCK && _MSC_VER && !EFIX64 && !EFI32 */
 
-#if !defined(HAVE_HARDCLOCK)
+#    if !defined(HAVE_HARDCLOCK)
 
-#define HAVE_HARDCLOCK
+#        define HAVE_HARDCLOCK
 
 static int hardclock_init = 0;
 static struct timeval tv_init;
 
-static unsigned long mbedtls_timing_hardclock( void )
+static unsigned long mbedtls_timing_hardclock(void)
 {
     struct timeval tv_cur;
 
-    if( hardclock_init == 0 )
-    {
-        gettimeofday( &tv_init, NULL );
+    if (hardclock_init == 0) {
+        gettimeofday(&tv_init, NULL);
         hardclock_init = 1;
     }
 
-    gettimeofday( &tv_cur, NULL );
-    return( ( tv_cur.tv_sec  - tv_init.tv_sec  ) * 1000000
-          + ( tv_cur.tv_usec - tv_init.tv_usec ) );
+    gettimeofday(&tv_cur, NULL);
+    return ((tv_cur.tv_sec - tv_init.tv_sec) * 1000000 +
+            (tv_cur.tv_usec - tv_init.tv_usec));
 }
-#endif /* !HAVE_HARDCLOCK */
+#    endif /* !HAVE_HARDCLOCK */
 
 volatile int mbedtls_timing_alarmed = 0;
 
-#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
+#    if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
 
 /* It's OK to use a global because alarm() is supposed to be global anyway */
 static DWORD alarmMs;
 
-static void TimerProc( void *TimerContext )
+static void TimerProc(void *TimerContext)
 {
-    (void) TimerContext;
-    Sleep( alarmMs );
+    (void)TimerContext;
+    Sleep(alarmMs);
     mbedtls_timing_alarmed = 1;
     /* _endthread will be called implicitly on return
      * That ensures execution of thread funcition's epilogue */
 }
 
-static void mbedtls_set_alarm( int seconds )
+static void mbedtls_set_alarm(int seconds)
 {
-    if( seconds == 0 )
-    {
+    if (seconds == 0) {
         /* No need to create a thread for this simple case.
          * Also, this shorcut is more reliable at least on MinGW32 */
         mbedtls_timing_alarmed = 1;
@@ -432,581 +417,542 @@
 
     mbedtls_timing_alarmed = 0;
     alarmMs = seconds * 1000;
-    (void) _beginthread( TimerProc, 0, NULL );
+    (void)_beginthread(TimerProc, 0, NULL);
 }
 
-#else /* _WIN32 && !EFIX64 && !EFI32 */
+#    else /* _WIN32 && !EFIX64 && !EFI32 */
 
-static void sighandler( int signum )
+static void sighandler(int signum)
 {
     mbedtls_timing_alarmed = 1;
-    signal( signum, sighandler );
+    signal(signum, sighandler);
 }
 
-static void mbedtls_set_alarm( int seconds )
+static void mbedtls_set_alarm(int seconds)
 {
     mbedtls_timing_alarmed = 0;
-    signal( SIGALRM, sighandler );
-    alarm( seconds );
-    if( seconds == 0 )
-    {
+    signal(SIGALRM, sighandler);
+    alarm(seconds);
+    if (seconds == 0) {
         /* alarm(0) cancelled any previous pending alarm, but the
            handler won't fire, so raise the flag straight away. */
         mbedtls_timing_alarmed = 1;
     }
 }
 
-#endif /* _WIN32 && !EFIX64 && !EFI32 */
+#    endif /* _WIN32 && !EFIX64 && !EFI32 */
 
-static int myrand( void *rng_state, unsigned char *output, size_t len )
+static int myrand(void *rng_state, unsigned char *output, size_t len)
 {
     size_t use_len;
     int rnd;
 
-    if( rng_state != NULL )
-        rng_state  = NULL;
+    if (rng_state != NULL)
+        rng_state = NULL;
 
-    while( len > 0 )
-    {
+    while (len > 0) {
         use_len = len;
-        if( use_len > sizeof(int) )
+        if (use_len > sizeof(int))
             use_len = sizeof(int);
 
         rnd = rand();
-        memcpy( output, &rnd, use_len );
+        memcpy(output, &rnd, use_len);
         output += use_len;
         len -= use_len;
     }
 
-    return 0 ;
+    return 0;
 }
 
-#define CHECK_AND_CONTINUE( R )                                         \
-    {                                                                   \
-        int CHECK_AND_CONTINUE_ret = ( R );                             \
-        if( CHECK_AND_CONTINUE_ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ) { \
-            mbedtls_printf( "Feature not supported. Skipping.\n" );     \
-            continue;                                                   \
-        }                                                               \
-        else if( CHECK_AND_CONTINUE_ret != 0 ) {                        \
-            mbedtls_exit( 1 );                                          \
-        }                                                               \
-    }
+#    define CHECK_AND_CONTINUE(R)                                     \
+        {                                                             \
+            int CHECK_AND_CONTINUE_ret = (R);                         \
+            if (CHECK_AND_CONTINUE_ret ==                             \
+                MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {           \
+                mbedtls_printf("Feature not supported. Skipping.\n"); \
+                continue;                                             \
+            } else if (CHECK_AND_CONTINUE_ret != 0) {                 \
+                mbedtls_exit(1);                                      \
+            }                                                         \
+        }
 
 /*
  * Clear some memory that was used to prepare the context
  */
-#if defined(MBEDTLS_ECP_C)
-void ecp_clear_precomputed( mbedtls_ecp_group *grp )
+#    if defined(MBEDTLS_ECP_C)
+void ecp_clear_precomputed(mbedtls_ecp_group *grp)
 {
-    if( grp->T != NULL
-#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    if (grp->T != NULL
+#        if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
         && grp->T_size != 0
-#endif
-    )
-    {
+#        endif
+    ) {
         size_t i;
-        for( i = 0; i < grp->T_size; i++ )
-            mbedtls_ecp_point_free( &grp->T[i] );
-        mbedtls_free( grp->T );
+        for (i = 0; i < grp->T_size; i++)
+            mbedtls_ecp_point_free(&grp->T[i]);
+        mbedtls_free(grp->T);
     }
     grp->T = NULL;
     grp->T_size = 0;
 }
-#else
-#define ecp_clear_precomputed( g )
-#endif
+#    else
+#        define ecp_clear_precomputed(g)
+#    endif
 
-#if defined(MBEDTLS_ECP_C)
-static int set_ecp_curve( const char *string, mbedtls_ecp_curve_info *curve )
+#    if defined(MBEDTLS_ECP_C)
+static int set_ecp_curve(const char *string, mbedtls_ecp_curve_info *curve)
 {
     const mbedtls_ecp_curve_info *found =
-        mbedtls_ecp_curve_info_from_name( string );
-    if( found != NULL )
-    {
+        mbedtls_ecp_curve_info_from_name(string);
+    if (found != NULL) {
         *curve = *found;
-        return 1 ;
-    }
-    else
-        return 0 ;
+        return 1;
+    } else
+        return 0;
 }
-#endif
+#    endif
 
 unsigned char buf[BUFSIZE];
 
 typedef struct {
-    char md5, ripemd160, sha1, sha256, sha512,
-         des3, des,
-         aes_cbc, aes_gcm, aes_ccm, aes_xts, chachapoly,
-         aes_cmac, des3_cmac,
-         aria, camellia, chacha20,
-         poly1305,
-         ctr_drbg, hmac_drbg,
-         rsa, dhm, ecdsa, ecdh;
+    char md5, ripemd160, sha1, sha256, sha512, des3, des, aes_cbc, aes_gcm,
+        aes_ccm, aes_xts, chachapoly, aes_cmac, des3_cmac, aria, camellia,
+        chacha20, poly1305, ctr_drbg, hmac_drbg, rsa, dhm, ecdsa, ecdh;
 } todo_list;
 
-
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int i;
     unsigned char tmp[200];
     char title[TITLE_LEN];
     todo_list todo;
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
+#    if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
     unsigned char alloc_buf[HEAP_SIZE] = { 0 };
-#endif
-#if defined(MBEDTLS_ECP_C)
+#    endif
+#    if defined(MBEDTLS_ECP_C)
     mbedtls_ecp_curve_info single_curve[2] = {
         { MBEDTLS_ECP_DP_NONE, 0, 0, NULL },
         { MBEDTLS_ECP_DP_NONE, 0, 0, NULL },
     };
-    const mbedtls_ecp_curve_info *curve_list = mbedtls_ecp_curve_list( );
-#endif
+    const mbedtls_ecp_curve_info *curve_list = mbedtls_ecp_curve_list();
+#    endif
 
-#if defined(MBEDTLS_ECP_C)
-    (void) curve_list; /* Unused in some configurations where no benchmark uses ECC */
-#endif
+#    if defined(MBEDTLS_ECP_C)
+    (void)curve_list; /* Unused in some configurations where no benchmark uses
+                         ECC */
+#    endif
 
-    if( argc <= 1 )
-    {
-        memset( &todo, 1, sizeof( todo ) );
-    }
-    else
-    {
-        memset( &todo, 0, sizeof( todo ) );
+    if (argc <= 1) {
+        memset(&todo, 1, sizeof(todo));
+    } else {
+        memset(&todo, 0, sizeof(todo));
 
-        for( i = 1; i < argc; i++ )
-        {
-            if( strcmp( argv[i], "md5" ) == 0 )
+        for (i = 1; i < argc; i++) {
+            if (strcmp(argv[i], "md5") == 0)
                 todo.md5 = 1;
-            else if( strcmp( argv[i], "ripemd160" ) == 0 )
+            else if (strcmp(argv[i], "ripemd160") == 0)
                 todo.ripemd160 = 1;
-            else if( strcmp( argv[i], "sha1" ) == 0 )
+            else if (strcmp(argv[i], "sha1") == 0)
                 todo.sha1 = 1;
-            else if( strcmp( argv[i], "sha256" ) == 0 )
+            else if (strcmp(argv[i], "sha256") == 0)
                 todo.sha256 = 1;
-            else if( strcmp( argv[i], "sha512" ) == 0 )
+            else if (strcmp(argv[i], "sha512") == 0)
                 todo.sha512 = 1;
-            else if( strcmp( argv[i], "des3" ) == 0 )
+            else if (strcmp(argv[i], "des3") == 0)
                 todo.des3 = 1;
-            else if( strcmp( argv[i], "des" ) == 0 )
+            else if (strcmp(argv[i], "des") == 0)
                 todo.des = 1;
-            else if( strcmp( argv[i], "aes_cbc" ) == 0 )
+            else if (strcmp(argv[i], "aes_cbc") == 0)
                 todo.aes_cbc = 1;
-            else if( strcmp( argv[i], "aes_xts" ) == 0 )
+            else if (strcmp(argv[i], "aes_xts") == 0)
                 todo.aes_xts = 1;
-            else if( strcmp( argv[i], "aes_gcm" ) == 0 )
+            else if (strcmp(argv[i], "aes_gcm") == 0)
                 todo.aes_gcm = 1;
-            else if( strcmp( argv[i], "aes_ccm" ) == 0 )
+            else if (strcmp(argv[i], "aes_ccm") == 0)
                 todo.aes_ccm = 1;
-            else if( strcmp( argv[i], "chachapoly" ) == 0 )
+            else if (strcmp(argv[i], "chachapoly") == 0)
                 todo.chachapoly = 1;
-            else if( strcmp( argv[i], "aes_cmac" ) == 0 )
+            else if (strcmp(argv[i], "aes_cmac") == 0)
                 todo.aes_cmac = 1;
-            else if( strcmp( argv[i], "des3_cmac" ) == 0 )
+            else if (strcmp(argv[i], "des3_cmac") == 0)
                 todo.des3_cmac = 1;
-            else if( strcmp( argv[i], "aria" ) == 0 )
+            else if (strcmp(argv[i], "aria") == 0)
                 todo.aria = 1;
-            else if( strcmp( argv[i], "camellia" ) == 0 )
+            else if (strcmp(argv[i], "camellia") == 0)
                 todo.camellia = 1;
-            else if( strcmp( argv[i], "chacha20" ) == 0 )
+            else if (strcmp(argv[i], "chacha20") == 0)
                 todo.chacha20 = 1;
-            else if( strcmp( argv[i], "poly1305" ) == 0 )
+            else if (strcmp(argv[i], "poly1305") == 0)
                 todo.poly1305 = 1;
-            else if( strcmp( argv[i], "ctr_drbg" ) == 0 )
+            else if (strcmp(argv[i], "ctr_drbg") == 0)
                 todo.ctr_drbg = 1;
-            else if( strcmp( argv[i], "hmac_drbg" ) == 0 )
+            else if (strcmp(argv[i], "hmac_drbg") == 0)
                 todo.hmac_drbg = 1;
-            else if( strcmp( argv[i], "rsa" ) == 0 )
+            else if (strcmp(argv[i], "rsa") == 0)
                 todo.rsa = 1;
-            else if( strcmp( argv[i], "dhm" ) == 0 )
+            else if (strcmp(argv[i], "dhm") == 0)
                 todo.dhm = 1;
-            else if( strcmp( argv[i], "ecdsa" ) == 0 )
+            else if (strcmp(argv[i], "ecdsa") == 0)
                 todo.ecdsa = 1;
-            else if( strcmp( argv[i], "ecdh" ) == 0 )
+            else if (strcmp(argv[i], "ecdh") == 0)
                 todo.ecdh = 1;
-#if defined(MBEDTLS_ECP_C)
-            else if( set_ecp_curve( argv[i], single_curve ) )
+#    if defined(MBEDTLS_ECP_C)
+            else if (set_ecp_curve(argv[i], single_curve))
                 curve_list = single_curve;
-#endif
-            else
-            {
-                mbedtls_printf( "Unrecognized option: %s\n", argv[i] );
-                mbedtls_printf( "Available options: " OPTIONS );
+#    endif
+            else {
+                mbedtls_printf("Unrecognized option: %s\n", argv[i]);
+                mbedtls_printf("Available options: " OPTIONS);
             }
         }
     }
 
-    mbedtls_printf( "\n" );
+    mbedtls_printf("\n");
 
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
-    mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof( alloc_buf ) );
-#endif
-    memset( buf, 0xAA, sizeof( buf ) );
-    memset( tmp, 0xBB, sizeof( tmp ) );
+#    if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
+    mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
+#    endif
+    memset(buf, 0xAA, sizeof(buf));
+    memset(tmp, 0xBB, sizeof(tmp));
 
-#if defined(MBEDTLS_MD5_C)
-    if( todo.md5 )
-        TIME_AND_TSC( "MD5", mbedtls_md5( buf, BUFSIZE, tmp ) );
-#endif
+#    if defined(MBEDTLS_MD5_C)
+    if (todo.md5)
+        TIME_AND_TSC("MD5", mbedtls_md5(buf, BUFSIZE, tmp));
+#    endif
 
-#if defined(MBEDTLS_RIPEMD160_C)
-    if( todo.ripemd160 )
-        TIME_AND_TSC( "RIPEMD160", mbedtls_ripemd160( buf, BUFSIZE, tmp ) );
-#endif
+#    if defined(MBEDTLS_RIPEMD160_C)
+    if (todo.ripemd160)
+        TIME_AND_TSC("RIPEMD160", mbedtls_ripemd160(buf, BUFSIZE, tmp));
+#    endif
 
-#if defined(MBEDTLS_SHA1_C)
-    if( todo.sha1 )
-        TIME_AND_TSC( "SHA-1", mbedtls_sha1( buf, BUFSIZE, tmp ) );
-#endif
+#    if defined(MBEDTLS_SHA1_C)
+    if (todo.sha1)
+        TIME_AND_TSC("SHA-1", mbedtls_sha1(buf, BUFSIZE, tmp));
+#    endif
 
-#if defined(MBEDTLS_SHA256_C)
-    if( todo.sha256 )
-        TIME_AND_TSC( "SHA-256", mbedtls_sha256( buf, BUFSIZE, tmp, 0 ) );
-#endif
+#    if defined(MBEDTLS_SHA256_C)
+    if (todo.sha256)
+        TIME_AND_TSC("SHA-256", mbedtls_sha256(buf, BUFSIZE, tmp, 0));
+#    endif
 
-#if defined(MBEDTLS_SHA512_C)
-    if( todo.sha512 )
-        TIME_AND_TSC( "SHA-512", mbedtls_sha512( buf, BUFSIZE, tmp, 0 ) );
-#endif
+#    if defined(MBEDTLS_SHA512_C)
+    if (todo.sha512)
+        TIME_AND_TSC("SHA-512", mbedtls_sha512(buf, BUFSIZE, tmp, 0));
+#    endif
 
-#if defined(MBEDTLS_DES_C)
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
-    if( todo.des3 )
-    {
+#    if defined(MBEDTLS_DES_C)
+#        if defined(MBEDTLS_CIPHER_MODE_CBC)
+    if (todo.des3) {
         mbedtls_des3_context des3;
-        mbedtls_des3_init( &des3 );
-        mbedtls_des3_set3key_enc( &des3, tmp );
-        TIME_AND_TSC( "3DES",
-                mbedtls_des3_crypt_cbc( &des3, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
-        mbedtls_des3_free( &des3 );
+        mbedtls_des3_init(&des3);
+        mbedtls_des3_set3key_enc(&des3, tmp);
+        TIME_AND_TSC("3DES", mbedtls_des3_crypt_cbc(&des3, MBEDTLS_DES_ENCRYPT,
+                                                    BUFSIZE, tmp, buf, buf));
+        mbedtls_des3_free(&des3);
     }
 
-    if( todo.des )
-    {
+    if (todo.des) {
         mbedtls_des_context des;
-        mbedtls_des_init( &des );
-        mbedtls_des_setkey_enc( &des, tmp );
-        TIME_AND_TSC( "DES",
-                mbedtls_des_crypt_cbc( &des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
-        mbedtls_des_free( &des );
+        mbedtls_des_init(&des);
+        mbedtls_des_setkey_enc(&des, tmp);
+        TIME_AND_TSC("DES", mbedtls_des_crypt_cbc(&des, MBEDTLS_DES_ENCRYPT,
+                                                  BUFSIZE, tmp, buf, buf));
+        mbedtls_des_free(&des);
     }
 
-#endif /* MBEDTLS_CIPHER_MODE_CBC */
-#if defined(MBEDTLS_CMAC_C)
-    if( todo.des3_cmac )
-    {
+#        endif /* MBEDTLS_CIPHER_MODE_CBC */
+#        if defined(MBEDTLS_CMAC_C)
+    if (todo.des3_cmac) {
         unsigned char output[8];
         const mbedtls_cipher_info_t *cipher_info;
 
-        memset( buf, 0, sizeof( buf ) );
-        memset( tmp, 0, sizeof( tmp ) );
+        memset(buf, 0, sizeof(buf));
+        memset(tmp, 0, sizeof(tmp));
 
-        cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_DES_EDE3_ECB );
+        cipher_info =
+            mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_DES_EDE3_ECB);
 
-        TIME_AND_TSC( "3DES-CMAC",
-                      mbedtls_cipher_cmac( cipher_info, tmp, 192, buf,
-                      BUFSIZE, output ) );
+        TIME_AND_TSC("3DES-CMAC", mbedtls_cipher_cmac(cipher_info, tmp, 192,
+                                                      buf, BUFSIZE, output));
     }
-#endif /* MBEDTLS_CMAC_C */
-#endif /* MBEDTLS_DES_C */
+#        endif /* MBEDTLS_CMAC_C */
+#    endif /* MBEDTLS_DES_C */
 
-#if defined(MBEDTLS_AES_C)
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
-    if( todo.aes_cbc )
-    {
+#    if defined(MBEDTLS_AES_C)
+#        if defined(MBEDTLS_CIPHER_MODE_CBC)
+    if (todo.aes_cbc) {
         int keysize;
         mbedtls_aes_context aes;
-        mbedtls_aes_init( &aes );
-        for( keysize = 128; keysize <= 256; keysize += 64 )
-        {
-            mbedtls_snprintf( title, sizeof( title ), "AES-CBC-%d", keysize );
+        mbedtls_aes_init(&aes);
+        for (keysize = 128; keysize <= 256; keysize += 64) {
+            mbedtls_snprintf(title, sizeof(title), "AES-CBC-%d", keysize);
 
-            memset( buf, 0, sizeof( buf ) );
-            memset( tmp, 0, sizeof( tmp ) );
-            mbedtls_aes_setkey_enc( &aes, tmp, keysize );
+            memset(buf, 0, sizeof(buf));
+            memset(tmp, 0, sizeof(tmp));
+            mbedtls_aes_setkey_enc(&aes, tmp, keysize);
 
-            TIME_AND_TSC( title,
-                mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
+            TIME_AND_TSC(title, mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_ENCRYPT,
+                                                      BUFSIZE, tmp, buf, buf));
         }
-        mbedtls_aes_free( &aes );
+        mbedtls_aes_free(&aes);
     }
-#endif
-#if defined(MBEDTLS_CIPHER_MODE_XTS)
-    if( todo.aes_xts )
-    {
+#        endif
+#        if defined(MBEDTLS_CIPHER_MODE_XTS)
+    if (todo.aes_xts) {
         int keysize;
         mbedtls_aes_xts_context ctx;
 
-        mbedtls_aes_xts_init( &ctx );
-        for( keysize = 128; keysize <= 256; keysize += 128 )
-        {
-            mbedtls_snprintf( title, sizeof( title ), "AES-XTS-%d", keysize );
+        mbedtls_aes_xts_init(&ctx);
+        for (keysize = 128; keysize <= 256; keysize += 128) {
+            mbedtls_snprintf(title, sizeof(title), "AES-XTS-%d", keysize);
 
-            memset( buf, 0, sizeof( buf ) );
-            memset( tmp, 0, sizeof( tmp ) );
-            mbedtls_aes_xts_setkey_enc( &ctx, tmp, keysize * 2 );
+            memset(buf, 0, sizeof(buf));
+            memset(tmp, 0, sizeof(tmp));
+            mbedtls_aes_xts_setkey_enc(&ctx, tmp, keysize * 2);
 
-            TIME_AND_TSC( title,
-                    mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, BUFSIZE,
-                                           tmp, buf, buf ) );
+            TIME_AND_TSC(title, mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_ENCRYPT,
+                                                      BUFSIZE, tmp, buf, buf));
 
-            mbedtls_aes_xts_free( &ctx );
+            mbedtls_aes_xts_free(&ctx);
         }
     }
-#endif
-#if defined(MBEDTLS_GCM_C)
-    if( todo.aes_gcm )
-    {
+#        endif
+#        if defined(MBEDTLS_GCM_C)
+    if (todo.aes_gcm) {
         int keysize;
         mbedtls_gcm_context gcm;
 
-        mbedtls_gcm_init( &gcm );
-        for( keysize = 128; keysize <= 256; keysize += 64 )
-        {
-            mbedtls_snprintf( title, sizeof( title ), "AES-GCM-%d", keysize );
+        mbedtls_gcm_init(&gcm);
+        for (keysize = 128; keysize <= 256; keysize += 64) {
+            mbedtls_snprintf(title, sizeof(title), "AES-GCM-%d", keysize);
 
-            memset( buf, 0, sizeof( buf ) );
-            memset( tmp, 0, sizeof( tmp ) );
-            mbedtls_gcm_setkey( &gcm, MBEDTLS_CIPHER_ID_AES, tmp, keysize );
+            memset(buf, 0, sizeof(buf));
+            memset(tmp, 0, sizeof(tmp));
+            mbedtls_gcm_setkey(&gcm, MBEDTLS_CIPHER_ID_AES, tmp, keysize);
 
-            TIME_AND_TSC( title,
-                    mbedtls_gcm_crypt_and_tag( &gcm, MBEDTLS_GCM_ENCRYPT, BUFSIZE, tmp,
-                        12, NULL, 0, buf, buf, 16, tmp ) );
+            TIME_AND_TSC(title, mbedtls_gcm_crypt_and_tag(
+                                    &gcm, MBEDTLS_GCM_ENCRYPT, BUFSIZE, tmp, 12,
+                                    NULL, 0, buf, buf, 16, tmp));
 
-            mbedtls_gcm_free( &gcm );
+            mbedtls_gcm_free(&gcm);
         }
     }
-#endif
-#if defined(MBEDTLS_CCM_C)
-    if( todo.aes_ccm )
-    {
+#        endif
+#        if defined(MBEDTLS_CCM_C)
+    if (todo.aes_ccm) {
         int keysize;
         mbedtls_ccm_context ccm;
 
-        mbedtls_ccm_init( &ccm );
-        for( keysize = 128; keysize <= 256; keysize += 64 )
-        {
-            mbedtls_snprintf( title, sizeof( title ), "AES-CCM-%d", keysize );
+        mbedtls_ccm_init(&ccm);
+        for (keysize = 128; keysize <= 256; keysize += 64) {
+            mbedtls_snprintf(title, sizeof(title), "AES-CCM-%d", keysize);
 
-            memset( buf, 0, sizeof( buf ) );
-            memset( tmp, 0, sizeof( tmp ) );
-            mbedtls_ccm_setkey( &ccm, MBEDTLS_CIPHER_ID_AES, tmp, keysize );
+            memset(buf, 0, sizeof(buf));
+            memset(tmp, 0, sizeof(tmp));
+            mbedtls_ccm_setkey(&ccm, MBEDTLS_CIPHER_ID_AES, tmp, keysize);
 
-            TIME_AND_TSC( title,
-                    mbedtls_ccm_encrypt_and_tag( &ccm, BUFSIZE, tmp,
-                        12, NULL, 0, buf, buf, tmp, 16 ) );
+            TIME_AND_TSC(title, mbedtls_ccm_encrypt_and_tag(&ccm, BUFSIZE, tmp,
+                                                            12, NULL, 0, buf,
+                                                            buf, tmp, 16));
 
-            mbedtls_ccm_free( &ccm );
+            mbedtls_ccm_free(&ccm);
         }
     }
-#endif
-#if defined(MBEDTLS_CHACHAPOLY_C)
-    if( todo.chachapoly )
-    {
+#        endif
+#        if defined(MBEDTLS_CHACHAPOLY_C)
+    if (todo.chachapoly) {
         mbedtls_chachapoly_context chachapoly;
 
-        mbedtls_chachapoly_init( &chachapoly );
-        memset( buf, 0, sizeof( buf ) );
-        memset( tmp, 0, sizeof( tmp ) );
+        mbedtls_chachapoly_init(&chachapoly);
+        memset(buf, 0, sizeof(buf));
+        memset(tmp, 0, sizeof(tmp));
 
-        mbedtls_snprintf( title, sizeof( title ), "ChaCha20-Poly1305" );
+        mbedtls_snprintf(title, sizeof(title), "ChaCha20-Poly1305");
 
-        mbedtls_chachapoly_setkey( &chachapoly, tmp );
+        mbedtls_chachapoly_setkey(&chachapoly, tmp);
 
-        TIME_AND_TSC( title,
-                mbedtls_chachapoly_encrypt_and_tag( &chachapoly,
-                    BUFSIZE, tmp, NULL, 0, buf, buf, tmp ) );
+        TIME_AND_TSC(
+            title, mbedtls_chachapoly_encrypt_and_tag(&chachapoly, BUFSIZE, tmp,
+                                                      NULL, 0, buf, buf, tmp));
 
-        mbedtls_chachapoly_free( &chachapoly );
+        mbedtls_chachapoly_free(&chachapoly);
     }
-#endif
-#if defined(MBEDTLS_CMAC_C)
-    if( todo.aes_cmac )
-    {
+#        endif
+#        if defined(MBEDTLS_CMAC_C)
+    if (todo.aes_cmac) {
         unsigned char output[16];
         const mbedtls_cipher_info_t *cipher_info;
         mbedtls_cipher_type_t cipher_type;
         int keysize;
 
-        for( keysize = 128, cipher_type = MBEDTLS_CIPHER_AES_128_ECB;
-             keysize <= 256;
-             keysize += 64, cipher_type++ )
-        {
-            mbedtls_snprintf( title, sizeof( title ), "AES-CMAC-%d", keysize );
+        for (keysize = 128, cipher_type = MBEDTLS_CIPHER_AES_128_ECB;
+             keysize <= 256; keysize += 64, cipher_type++) {
+            mbedtls_snprintf(title, sizeof(title), "AES-CMAC-%d", keysize);
 
-            memset( buf, 0, sizeof( buf ) );
-            memset( tmp, 0, sizeof( tmp ) );
+            memset(buf, 0, sizeof(buf));
+            memset(tmp, 0, sizeof(tmp));
 
-            cipher_info = mbedtls_cipher_info_from_type( cipher_type );
+            cipher_info = mbedtls_cipher_info_from_type(cipher_type);
 
-            TIME_AND_TSC( title,
-                          mbedtls_cipher_cmac( cipher_info, tmp, keysize,
-                                               buf, BUFSIZE, output ) );
+            TIME_AND_TSC(title, mbedtls_cipher_cmac(cipher_info, tmp, keysize,
+                                                    buf, BUFSIZE, output));
         }
 
-        memset( buf, 0, sizeof( buf ) );
-        memset( tmp, 0, sizeof( tmp ) );
-        TIME_AND_TSC( "AES-CMAC-PRF-128",
-                      mbedtls_aes_cmac_prf_128( tmp, 16, buf, BUFSIZE,
-                                                output ) );
+        memset(buf, 0, sizeof(buf));
+        memset(tmp, 0, sizeof(tmp));
+        TIME_AND_TSC("AES-CMAC-PRF-128",
+                     mbedtls_aes_cmac_prf_128(tmp, 16, buf, BUFSIZE, output));
     }
-#endif /* MBEDTLS_CMAC_C */
-#endif /* MBEDTLS_AES_C */
+#        endif /* MBEDTLS_CMAC_C */
+#    endif /* MBEDTLS_AES_C */
 
-#if defined(MBEDTLS_ARIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
-    if( todo.aria )
-    {
+#    if defined(MBEDTLS_ARIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
+    if (todo.aria) {
         int keysize;
         mbedtls_aria_context aria;
-        mbedtls_aria_init( &aria );
-        for( keysize = 128; keysize <= 256; keysize += 64 )
-        {
-            mbedtls_snprintf( title, sizeof( title ), "ARIA-CBC-%d", keysize );
+        mbedtls_aria_init(&aria);
+        for (keysize = 128; keysize <= 256; keysize += 64) {
+            mbedtls_snprintf(title, sizeof(title), "ARIA-CBC-%d", keysize);
 
-            memset( buf, 0, sizeof( buf ) );
-            memset( tmp, 0, sizeof( tmp ) );
-            mbedtls_aria_setkey_enc( &aria, tmp, keysize );
+            memset(buf, 0, sizeof(buf));
+            memset(tmp, 0, sizeof(tmp));
+            mbedtls_aria_setkey_enc(&aria, tmp, keysize);
 
-            TIME_AND_TSC( title,
-                    mbedtls_aria_crypt_cbc( &aria, MBEDTLS_ARIA_ENCRYPT,
-                        BUFSIZE, tmp, buf, buf ) );
+            TIME_AND_TSC(title,
+                         mbedtls_aria_crypt_cbc(&aria, MBEDTLS_ARIA_ENCRYPT,
+                                                BUFSIZE, tmp, buf, buf));
         }
-        mbedtls_aria_free( &aria );
+        mbedtls_aria_free(&aria);
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
-    if( todo.camellia )
-    {
+#    if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
+    if (todo.camellia) {
         int keysize;
         mbedtls_camellia_context camellia;
-        mbedtls_camellia_init( &camellia );
-        for( keysize = 128; keysize <= 256; keysize += 64 )
-        {
-            mbedtls_snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize );
+        mbedtls_camellia_init(&camellia);
+        for (keysize = 128; keysize <= 256; keysize += 64) {
+            mbedtls_snprintf(title, sizeof(title), "CAMELLIA-CBC-%d", keysize);
 
-            memset( buf, 0, sizeof( buf ) );
-            memset( tmp, 0, sizeof( tmp ) );
-            mbedtls_camellia_setkey_enc( &camellia, tmp, keysize );
+            memset(buf, 0, sizeof(buf));
+            memset(tmp, 0, sizeof(tmp));
+            mbedtls_camellia_setkey_enc(&camellia, tmp, keysize);
 
-            TIME_AND_TSC( title,
-                    mbedtls_camellia_crypt_cbc( &camellia, MBEDTLS_CAMELLIA_ENCRYPT,
-                        BUFSIZE, tmp, buf, buf ) );
+            TIME_AND_TSC(title, mbedtls_camellia_crypt_cbc(
+                                    &camellia, MBEDTLS_CAMELLIA_ENCRYPT,
+                                    BUFSIZE, tmp, buf, buf));
         }
-        mbedtls_camellia_free( &camellia );
+        mbedtls_camellia_free(&camellia);
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_CHACHA20_C)
-    if ( todo.chacha20 )
-    {
-        TIME_AND_TSC( "ChaCha20", mbedtls_chacha20_crypt( buf, buf, 0U, BUFSIZE, buf, buf ) );
+#    if defined(MBEDTLS_CHACHA20_C)
+    if (todo.chacha20) {
+        TIME_AND_TSC("ChaCha20",
+                     mbedtls_chacha20_crypt(buf, buf, 0U, BUFSIZE, buf, buf));
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_POLY1305_C)
-    if ( todo.poly1305 )
-    {
-        TIME_AND_TSC( "Poly1305", mbedtls_poly1305_mac( buf, buf, BUFSIZE, buf ) );
+#    if defined(MBEDTLS_POLY1305_C)
+    if (todo.poly1305) {
+        TIME_AND_TSC("Poly1305", mbedtls_poly1305_mac(buf, buf, BUFSIZE, buf));
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_CTR_DRBG_C)
-    if( todo.ctr_drbg )
-    {
+#    if defined(MBEDTLS_CTR_DRBG_C)
+    if (todo.ctr_drbg) {
         mbedtls_ctr_drbg_context ctr_drbg;
 
-        mbedtls_ctr_drbg_init( &ctr_drbg );
-        if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
+        mbedtls_ctr_drbg_init(&ctr_drbg);
+        if (mbedtls_ctr_drbg_seed(&ctr_drbg, myrand, NULL, NULL, 0) != 0)
             mbedtls_exit(1);
-        TIME_AND_TSC( "CTR_DRBG (NOPR)",
-                mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) );
-        mbedtls_ctr_drbg_free( &ctr_drbg );
+        TIME_AND_TSC("CTR_DRBG (NOPR)",
+                     mbedtls_ctr_drbg_random(&ctr_drbg, buf, BUFSIZE));
+        mbedtls_ctr_drbg_free(&ctr_drbg);
 
-        mbedtls_ctr_drbg_init( &ctr_drbg );
-        if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
+        mbedtls_ctr_drbg_init(&ctr_drbg);
+        if (mbedtls_ctr_drbg_seed(&ctr_drbg, myrand, NULL, NULL, 0) != 0)
             mbedtls_exit(1);
-        mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON );
-        TIME_AND_TSC( "CTR_DRBG (PR)",
-                mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) );
-        mbedtls_ctr_drbg_free( &ctr_drbg );
+        mbedtls_ctr_drbg_set_prediction_resistance(&ctr_drbg,
+                                                   MBEDTLS_CTR_DRBG_PR_ON);
+        TIME_AND_TSC("CTR_DRBG (PR)",
+                     mbedtls_ctr_drbg_random(&ctr_drbg, buf, BUFSIZE));
+        mbedtls_ctr_drbg_free(&ctr_drbg);
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_HMAC_DRBG_C)
-    if( todo.hmac_drbg )
-    {
+#    if defined(MBEDTLS_HMAC_DRBG_C)
+    if (todo.hmac_drbg) {
         mbedtls_hmac_drbg_context hmac_drbg;
         const mbedtls_md_info_t *md_info;
 
-        mbedtls_hmac_drbg_init( &hmac_drbg );
+        mbedtls_hmac_drbg_init(&hmac_drbg);
 
-#if defined(MBEDTLS_SHA1_C)
-        if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 ) ) == NULL )
+#        if defined(MBEDTLS_SHA1_C)
+        if ((md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1)) == NULL)
             mbedtls_exit(1);
 
-        if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
+        if (mbedtls_hmac_drbg_seed(&hmac_drbg, md_info, myrand, NULL, NULL,
+                                   0) != 0)
             mbedtls_exit(1);
-        TIME_AND_TSC( "HMAC_DRBG SHA-1 (NOPR)",
-                mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) );
+        TIME_AND_TSC("HMAC_DRBG SHA-1 (NOPR)",
+                     mbedtls_hmac_drbg_random(&hmac_drbg, buf, BUFSIZE));
 
-        if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
+        if (mbedtls_hmac_drbg_seed(&hmac_drbg, md_info, myrand, NULL, NULL,
+                                   0) != 0)
             mbedtls_exit(1);
-        mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg,
-                                             MBEDTLS_HMAC_DRBG_PR_ON );
-        TIME_AND_TSC( "HMAC_DRBG SHA-1 (PR)",
-                mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) );
-#endif
+        mbedtls_hmac_drbg_set_prediction_resistance(&hmac_drbg,
+                                                    MBEDTLS_HMAC_DRBG_PR_ON);
+        TIME_AND_TSC("HMAC_DRBG SHA-1 (PR)",
+                     mbedtls_hmac_drbg_random(&hmac_drbg, buf, BUFSIZE));
+#        endif
 
-#if defined(MBEDTLS_SHA256_C)
-        if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ) ) == NULL )
+#        if defined(MBEDTLS_SHA256_C)
+        if ((md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256)) == NULL)
             mbedtls_exit(1);
 
-        if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
+        if (mbedtls_hmac_drbg_seed(&hmac_drbg, md_info, myrand, NULL, NULL,
+                                   0) != 0)
             mbedtls_exit(1);
-        TIME_AND_TSC( "HMAC_DRBG SHA-256 (NOPR)",
-                mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) );
+        TIME_AND_TSC("HMAC_DRBG SHA-256 (NOPR)",
+                     mbedtls_hmac_drbg_random(&hmac_drbg, buf, BUFSIZE));
 
-        if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
+        if (mbedtls_hmac_drbg_seed(&hmac_drbg, md_info, myrand, NULL, NULL,
+                                   0) != 0)
             mbedtls_exit(1);
-        mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg,
-                                             MBEDTLS_HMAC_DRBG_PR_ON );
-        TIME_AND_TSC( "HMAC_DRBG SHA-256 (PR)",
-                mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) );
-#endif
-        mbedtls_hmac_drbg_free( &hmac_drbg );
+        mbedtls_hmac_drbg_set_prediction_resistance(&hmac_drbg,
+                                                    MBEDTLS_HMAC_DRBG_PR_ON);
+        TIME_AND_TSC("HMAC_DRBG SHA-256 (PR)",
+                     mbedtls_hmac_drbg_random(&hmac_drbg, buf, BUFSIZE));
+#        endif
+        mbedtls_hmac_drbg_free(&hmac_drbg);
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME)
-    if( todo.rsa )
-    {
+#    if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME)
+    if (todo.rsa) {
         int keysize;
         mbedtls_rsa_context rsa;
-        for( keysize = 2048; keysize <= 4096; keysize *= 2 )
-        {
-            mbedtls_snprintf( title, sizeof( title ), "RSA-%d", keysize );
+        for (keysize = 2048; keysize <= 4096; keysize *= 2) {
+            mbedtls_snprintf(title, sizeof(title), "RSA-%d", keysize);
 
-            mbedtls_rsa_init( &rsa );
-            mbedtls_rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 );
+            mbedtls_rsa_init(&rsa);
+            mbedtls_rsa_gen_key(&rsa, myrand, NULL, keysize, 65537);
 
-            TIME_PUBLIC( title, " public",
-                    buf[0] = 0;
-                    ret = mbedtls_rsa_public( &rsa, buf, buf ) );
+            TIME_PUBLIC(title, " public", buf[0] = 0;
+                        ret = mbedtls_rsa_public(&rsa, buf, buf));
 
-            TIME_PUBLIC( title, "private",
-                    buf[0] = 0;
-                    ret = mbedtls_rsa_private( &rsa, myrand, NULL, buf, buf ) );
+            TIME_PUBLIC(title, "private", buf[0] = 0;
+                        ret =
+                            mbedtls_rsa_private(&rsa, myrand, NULL, buf, buf));
 
-            mbedtls_rsa_free( &rsa );
+            mbedtls_rsa_free(&rsa);
         }
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_BIGNUM_C)
-    if( todo.dhm )
-    {
+#    if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_BIGNUM_C)
+    if (todo.dhm) {
         int dhm_sizes[] = { 2048, 3072 };
         static const unsigned char dhm_P_2048[] =
             MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN;
@@ -1018,119 +964,113 @@
             MBEDTLS_DHM_RFC3526_MODP_3072_G_BIN;
 
         const unsigned char *dhm_P[] = { dhm_P_2048, dhm_P_3072 };
-        const size_t dhm_P_size[] = { sizeof( dhm_P_2048 ),
-                                      sizeof( dhm_P_3072 ) };
+        const size_t dhm_P_size[] = { sizeof(dhm_P_2048), sizeof(dhm_P_3072) };
 
         const unsigned char *dhm_G[] = { dhm_G_2048, dhm_G_3072 };
-        const size_t dhm_G_size[] = { sizeof( dhm_G_2048 ),
-                                      sizeof( dhm_G_3072 ) };
+        const size_t dhm_G_size[] = { sizeof(dhm_G_2048), sizeof(dhm_G_3072) };
 
         mbedtls_dhm_context dhm;
         size_t olen;
         size_t n;
-        for( i = 0; (size_t) i < sizeof( dhm_sizes ) / sizeof( dhm_sizes[0] ); i++ )
-        {
-            mbedtls_dhm_init( &dhm );
+        for (i = 0; (size_t)i < sizeof(dhm_sizes) / sizeof(dhm_sizes[0]); i++) {
+            mbedtls_dhm_init(&dhm);
 
-            if( mbedtls_mpi_read_binary( &dhm.P, dhm_P[i],
-                                         dhm_P_size[i] ) != 0 ||
-                mbedtls_mpi_read_binary( &dhm.G, dhm_G[i],
-                                         dhm_G_size[i] ) != 0 )
-            {
-                mbedtls_exit( 1 );
+            if (mbedtls_mpi_read_binary(&dhm.P, dhm_P[i], dhm_P_size[i]) != 0 ||
+                mbedtls_mpi_read_binary(&dhm.G, dhm_G[i], dhm_G_size[i]) != 0) {
+                mbedtls_exit(1);
             }
 
-            n = mbedtls_mpi_size( &dhm.P );
-            mbedtls_dhm_make_public( &dhm, (int) n, buf, n, myrand, NULL );
-            if( mbedtls_mpi_copy( &dhm.GY, &dhm.GX ) != 0 )
-                mbedtls_exit( 1 );
+            n = mbedtls_mpi_size(&dhm.P);
+            mbedtls_dhm_make_public(&dhm, (int)n, buf, n, myrand, NULL);
+            if (mbedtls_mpi_copy(&dhm.GY, &dhm.GX) != 0)
+                mbedtls_exit(1);
 
-            mbedtls_snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] );
-            TIME_PUBLIC( title, "handshake",
-                    ret |= mbedtls_dhm_make_public( &dhm, (int) n, buf, n,
-                                            myrand, NULL );
-                    ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) );
+            mbedtls_snprintf(title, sizeof(title), "DHE-%d", dhm_sizes[i]);
+            TIME_PUBLIC(title, "handshake",
+                        ret |= mbedtls_dhm_make_public(&dhm, (int)n, buf, n,
+                                                       myrand, NULL);
+                        ret |= mbedtls_dhm_calc_secret(&dhm, buf, sizeof(buf),
+                                                       &olen, myrand, NULL));
 
-            mbedtls_snprintf( title, sizeof( title ), "DH-%d", dhm_sizes[i] );
-            TIME_PUBLIC( title, "handshake",
-                    ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) );
+            mbedtls_snprintf(title, sizeof(title), "DH-%d", dhm_sizes[i]);
+            TIME_PUBLIC(title, "handshake",
+                        ret |= mbedtls_dhm_calc_secret(&dhm, buf, sizeof(buf),
+                                                       &olen, myrand, NULL));
 
-            mbedtls_dhm_free( &dhm );
+            mbedtls_dhm_free(&dhm);
         }
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_SHA256_C)
-    if( todo.ecdsa )
-    {
+#    if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_SHA256_C)
+    if (todo.ecdsa) {
         mbedtls_ecdsa_context ecdsa;
         const mbedtls_ecp_curve_info *curve_info;
         size_t sig_len;
 
-        memset( buf, 0x2A, sizeof( buf ) );
+        memset(buf, 0x2A, sizeof(buf));
 
-        for( curve_info = curve_list;
-             curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
-             curve_info++ )
-        {
-            if( ! mbedtls_ecdsa_can_do( curve_info->grp_id ) )
+        for (curve_info = curve_list; curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+             curve_info++) {
+            if (!mbedtls_ecdsa_can_do(curve_info->grp_id))
                 continue;
 
-            mbedtls_ecdsa_init( &ecdsa );
+            mbedtls_ecdsa_init(&ecdsa);
 
-            if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 )
-                mbedtls_exit( 1 );
-            ecp_clear_precomputed( &ecdsa.grp );
+            if (mbedtls_ecdsa_genkey(&ecdsa, curve_info->grp_id, myrand,
+                                     NULL) != 0)
+                mbedtls_exit(1);
+            ecp_clear_precomputed(&ecdsa.grp);
 
-            mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s",
-                                              curve_info->name );
-            TIME_PUBLIC( title, "sign",
-                    ret = mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->bit_size,
-                                                tmp, sizeof( tmp ), &sig_len, myrand, NULL ) );
+            mbedtls_snprintf(title, sizeof(title), "ECDSA-%s",
+                             curve_info->name);
+            TIME_PUBLIC(title, "sign",
+                        ret = mbedtls_ecdsa_write_signature(
+                            &ecdsa, MBEDTLS_MD_SHA256, buf,
+                            curve_info->bit_size, tmp, sizeof(tmp), &sig_len,
+                            myrand, NULL));
 
-            mbedtls_ecdsa_free( &ecdsa );
+            mbedtls_ecdsa_free(&ecdsa);
         }
 
-        for( curve_info = curve_list;
-             curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
-             curve_info++ )
-        {
-            if( ! mbedtls_ecdsa_can_do( curve_info->grp_id ) )
+        for (curve_info = curve_list; curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+             curve_info++) {
+            if (!mbedtls_ecdsa_can_do(curve_info->grp_id))
                 continue;
 
-            mbedtls_ecdsa_init( &ecdsa );
+            mbedtls_ecdsa_init(&ecdsa);
 
-            if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 ||
-                mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->bit_size,
-                                               tmp, sizeof( tmp ), &sig_len, myrand, NULL ) != 0 )
-            {
-                mbedtls_exit( 1 );
+            if (mbedtls_ecdsa_genkey(&ecdsa, curve_info->grp_id, myrand,
+                                     NULL) != 0 ||
+                mbedtls_ecdsa_write_signature(
+                    &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->bit_size, tmp,
+                    sizeof(tmp), &sig_len, myrand, NULL) != 0) {
+                mbedtls_exit(1);
             }
-            ecp_clear_precomputed( &ecdsa.grp );
+            ecp_clear_precomputed(&ecdsa.grp);
 
-            mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s",
-                                              curve_info->name );
-            TIME_PUBLIC( title, "verify",
-                    ret = mbedtls_ecdsa_read_signature( &ecdsa, buf, curve_info->bit_size,
-                                                tmp, sig_len ) );
+            mbedtls_snprintf(title, sizeof(title), "ECDSA-%s",
+                             curve_info->name);
+            TIME_PUBLIC(title, "verify",
+                        ret = mbedtls_ecdsa_read_signature(
+                            &ecdsa, buf, curve_info->bit_size, tmp, sig_len));
 
-            mbedtls_ecdsa_free( &ecdsa );
+            mbedtls_ecdsa_free(&ecdsa);
         }
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_ECDH_C) && defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
-    if( todo.ecdh )
-    {
+#    if defined(MBEDTLS_ECDH_C) && defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+    if (todo.ecdh) {
         mbedtls_ecdh_context ecdh;
         mbedtls_mpi z;
         const mbedtls_ecp_curve_info montgomery_curve_list[] = {
-#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+#        if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
             { MBEDTLS_ECP_DP_CURVE25519, 0, 0, "Curve25519" },
-#endif
-#if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+#        endif
+#        if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
             { MBEDTLS_ECP_DP_CURVE448, 0, 0, "Curve448" },
-#endif
+#        endif
             { MBEDTLS_ECP_DP_NONE, 0, 0, 0 }
         };
         const mbedtls_ecp_curve_info *curve_info;
@@ -1138,170 +1078,169 @@
         const mbedtls_ecp_curve_info *selected_montgomery_curve_list =
             montgomery_curve_list;
 
-        if( curve_list == (const mbedtls_ecp_curve_info*) &single_curve )
-        {
+        if (curve_list == (const mbedtls_ecp_curve_info *)&single_curve) {
             mbedtls_ecp_group grp;
-            mbedtls_ecp_group_init( &grp );
-            if( mbedtls_ecp_group_load( &grp, curve_list->grp_id ) != 0 )
-                mbedtls_exit( 1 );
-            if( mbedtls_ecp_get_type( &grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY )
+            mbedtls_ecp_group_init(&grp);
+            if (mbedtls_ecp_group_load(&grp, curve_list->grp_id) != 0)
+                mbedtls_exit(1);
+            if (mbedtls_ecp_get_type(&grp) == MBEDTLS_ECP_TYPE_MONTGOMERY)
                 selected_montgomery_curve_list = single_curve;
             else /* empty list */
                 selected_montgomery_curve_list = single_curve + 1;
-            mbedtls_ecp_group_free( &grp );
+            mbedtls_ecp_group_free(&grp);
         }
 
-        for( curve_info = curve_list;
-             curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
-             curve_info++ )
-        {
-            if( ! mbedtls_ecdh_can_do( curve_info->grp_id ) )
+        for (curve_info = curve_list; curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+             curve_info++) {
+            if (!mbedtls_ecdh_can_do(curve_info->grp_id))
                 continue;
 
-            mbedtls_ecdh_init( &ecdh );
+            mbedtls_ecdh_init(&ecdh);
 
-            CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
-            CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
-                                                    myrand, NULL ) );
-            CHECK_AND_CONTINUE( mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) );
-            ecp_clear_precomputed( &ecdh.grp );
+            CHECK_AND_CONTINUE(
+                mbedtls_ecp_group_load(&ecdh.grp, curve_info->grp_id));
+            CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(
+                &ecdh, &olen, buf, sizeof(buf), myrand, NULL));
+            CHECK_AND_CONTINUE(mbedtls_ecp_copy(&ecdh.Qp, &ecdh.Q));
+            ecp_clear_precomputed(&ecdh.grp);
 
-            mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s",
-                                              curve_info->name );
-            TIME_PUBLIC( title, "handshake",
-                    CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
-                                             myrand, NULL ) );
-                    CHECK_AND_CONTINUE( mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
-                                             myrand, NULL ) ) );
-            mbedtls_ecdh_free( &ecdh );
+            mbedtls_snprintf(title, sizeof(title), "ECDHE-%s",
+                             curve_info->name);
+            TIME_PUBLIC(title, "handshake",
+                        CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(
+                            &ecdh, &olen, buf, sizeof(buf), myrand, NULL));
+                        CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(
+                            &ecdh, &olen, buf, sizeof(buf), myrand, NULL)));
+            mbedtls_ecdh_free(&ecdh);
         }
 
         /* Montgomery curves need to be handled separately */
-        for ( curve_info = selected_montgomery_curve_list;
-              curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
-              curve_info++ )
-        {
-            mbedtls_ecdh_init( &ecdh );
-            mbedtls_mpi_init( &z );
+        for (curve_info = selected_montgomery_curve_list;
+             curve_info->grp_id != MBEDTLS_ECP_DP_NONE; curve_info++) {
+            mbedtls_ecdh_init(&ecdh);
+            mbedtls_mpi_init(&z);
 
-            CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
-            CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, myrand, NULL ) );
+            CHECK_AND_CONTINUE(
+                mbedtls_ecp_group_load(&ecdh.grp, curve_info->grp_id));
+            CHECK_AND_CONTINUE(mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d,
+                                                       &ecdh.Qp, myrand, NULL));
 
-            mbedtls_snprintf( title, sizeof(title), "ECDHE-%s",
-                              curve_info->name );
-            TIME_PUBLIC(  title, "handshake",
-                    CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q,
-                                            myrand, NULL ) );
-                    CHECK_AND_CONTINUE( mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
-                                                myrand, NULL ) ) );
+            mbedtls_snprintf(title, sizeof(title), "ECDHE-%s",
+                             curve_info->name);
+            TIME_PUBLIC(title, "handshake",
+                        CHECK_AND_CONTINUE(mbedtls_ecdh_gen_public(
+                            &ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL));
+                        CHECK_AND_CONTINUE(mbedtls_ecdh_compute_shared(
+                            &ecdh.grp, &z, &ecdh.Qp, &ecdh.d, myrand, NULL)));
 
-            mbedtls_ecdh_free( &ecdh );
-            mbedtls_mpi_free( &z );
+            mbedtls_ecdh_free(&ecdh);
+            mbedtls_mpi_free(&z);
         }
 
-        for( curve_info = curve_list;
-             curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
-             curve_info++ )
-        {
-            if( ! mbedtls_ecdh_can_do( curve_info->grp_id ) )
+        for (curve_info = curve_list; curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+             curve_info++) {
+            if (!mbedtls_ecdh_can_do(curve_info->grp_id))
                 continue;
 
-            mbedtls_ecdh_init( &ecdh );
+            mbedtls_ecdh_init(&ecdh);
 
-            CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
-            CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
-                                  myrand, NULL ) );
-            CHECK_AND_CONTINUE( mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) );
-            CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
-                                  myrand, NULL ) );
-            ecp_clear_precomputed( &ecdh.grp );
+            CHECK_AND_CONTINUE(
+                mbedtls_ecp_group_load(&ecdh.grp, curve_info->grp_id));
+            CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(
+                &ecdh, &olen, buf, sizeof(buf), myrand, NULL));
+            CHECK_AND_CONTINUE(mbedtls_ecp_copy(&ecdh.Qp, &ecdh.Q));
+            CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(
+                &ecdh, &olen, buf, sizeof(buf), myrand, NULL));
+            ecp_clear_precomputed(&ecdh.grp);
 
-            mbedtls_snprintf( title, sizeof( title ), "ECDH-%s",
-                                              curve_info->name );
-            TIME_PUBLIC( title, "handshake",
-                    CHECK_AND_CONTINUE( mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
-                                             myrand, NULL ) ) );
-            mbedtls_ecdh_free( &ecdh );
+            mbedtls_snprintf(title, sizeof(title), "ECDH-%s", curve_info->name);
+            TIME_PUBLIC(title, "handshake",
+                        CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(
+                            &ecdh, &olen, buf, sizeof(buf), myrand, NULL)));
+            mbedtls_ecdh_free(&ecdh);
         }
 
         /* Montgomery curves need to be handled separately */
-        for ( curve_info = selected_montgomery_curve_list;
-              curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
-              curve_info++)
-        {
-            mbedtls_ecdh_init( &ecdh );
-            mbedtls_mpi_init( &z );
+        for (curve_info = selected_montgomery_curve_list;
+             curve_info->grp_id != MBEDTLS_ECP_DP_NONE; curve_info++) {
+            mbedtls_ecdh_init(&ecdh);
+            mbedtls_mpi_init(&z);
 
-            CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
-            CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp,
-                                 myrand, NULL ) );
-            CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL ) );
+            CHECK_AND_CONTINUE(
+                mbedtls_ecp_group_load(&ecdh.grp, curve_info->grp_id));
+            CHECK_AND_CONTINUE(mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d,
+                                                       &ecdh.Qp, myrand, NULL));
+            CHECK_AND_CONTINUE(mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d,
+                                                       &ecdh.Q, myrand, NULL));
 
-            mbedtls_snprintf( title, sizeof(title), "ECDH-%s",
-                              curve_info->name );
-            TIME_PUBLIC(  title, "handshake",
-                    CHECK_AND_CONTINUE( mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
-                                                myrand, NULL ) ) );
+            mbedtls_snprintf(title, sizeof(title), "ECDH-%s", curve_info->name);
+            TIME_PUBLIC(title, "handshake",
+                        CHECK_AND_CONTINUE(mbedtls_ecdh_compute_shared(
+                            &ecdh.grp, &z, &ecdh.Qp, &ecdh.d, myrand, NULL)));
 
-            mbedtls_ecdh_free( &ecdh );
-            mbedtls_mpi_free( &z );
+            mbedtls_ecdh_free(&ecdh);
+            mbedtls_mpi_free(&z);
         }
     }
-#endif
+#    endif
 
-#if defined(MBEDTLS_ECDH_C)
-    if( todo.ecdh )
-    {
+#    if defined(MBEDTLS_ECDH_C)
+    if (todo.ecdh) {
         mbedtls_ecdh_context ecdh_srv, ecdh_cli;
         unsigned char buf_srv[BUFSIZE], buf_cli[BUFSIZE];
         const mbedtls_ecp_curve_info *curve_info;
         size_t olen;
 
-        for( curve_info = curve_list;
-            curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
-            curve_info++ )
-        {
-            if( ! mbedtls_ecdh_can_do( curve_info->grp_id ) )
+        for (curve_info = curve_list; curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+             curve_info++) {
+            if (!mbedtls_ecdh_can_do(curve_info->grp_id))
                 continue;
 
-            mbedtls_ecdh_init( &ecdh_srv );
-            mbedtls_ecdh_init( &ecdh_cli );
+            mbedtls_ecdh_init(&ecdh_srv);
+            mbedtls_ecdh_init(&ecdh_cli);
 
-            mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", curve_info->name );
-            TIME_PUBLIC( title, "full handshake",
-                const unsigned char * p_srv = buf_srv;
+            mbedtls_snprintf(title, sizeof(title), "ECDHE-%s",
+                             curve_info->name);
+            TIME_PUBLIC(
+                title, "full handshake", const unsigned char *p_srv = buf_srv;
 
-                CHECK_AND_CONTINUE( mbedtls_ecdh_setup( &ecdh_srv, curve_info->grp_id ) );
-                CHECK_AND_CONTINUE( mbedtls_ecdh_make_params( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ) );
+                CHECK_AND_CONTINUE(
+                    mbedtls_ecdh_setup(&ecdh_srv, curve_info->grp_id));
+                CHECK_AND_CONTINUE(mbedtls_ecdh_make_params(
+                    &ecdh_srv, &olen, buf_srv, sizeof(buf_srv), myrand, NULL));
 
-                CHECK_AND_CONTINUE( mbedtls_ecdh_read_params( &ecdh_cli, &p_srv, p_srv + olen ) );
-                CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ) );
+                CHECK_AND_CONTINUE(
+                    mbedtls_ecdh_read_params(&ecdh_cli, &p_srv, p_srv + olen));
+                CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(
+                    &ecdh_cli, &olen, buf_cli, sizeof(buf_cli), myrand, NULL));
 
-                CHECK_AND_CONTINUE( mbedtls_ecdh_read_public( &ecdh_srv, buf_cli, olen ) );
-                CHECK_AND_CONTINUE( mbedtls_ecdh_calc_secret( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ) );
+                CHECK_AND_CONTINUE(
+                    mbedtls_ecdh_read_public(&ecdh_srv, buf_cli, olen));
+                CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(
+                    &ecdh_srv, &olen, buf_srv, sizeof(buf_srv), myrand, NULL));
 
-                CHECK_AND_CONTINUE( mbedtls_ecdh_calc_secret( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ) );
-                mbedtls_ecdh_free( &ecdh_cli );
+                CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(
+                    &ecdh_cli, &olen, buf_cli, sizeof(buf_cli), myrand, NULL));
+                mbedtls_ecdh_free(&ecdh_cli);
 
-                mbedtls_ecdh_free( &ecdh_srv );
-            );
-
+                mbedtls_ecdh_free(&ecdh_srv););
         }
     }
-#endif
+#    endif
 
-    mbedtls_printf( "\n" );
+    mbedtls_printf("\n");
 
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
+#    if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
     mbedtls_memory_buffer_alloc_free();
-#endif
+#    endif
 
-#if defined(_WIN32)
-    mbedtls_printf( "  Press Enter to exit this program.\n" );
-    fflush( stdout ); getchar();
-#endif
+#    if defined(_WIN32)
+    mbedtls_printf("  Press Enter to exit this program.\n");
+    fflush(stdout);
+    getchar();
+#    endif
 
-    mbedtls_exit( 0 );
+    mbedtls_exit(0);
 }
 
 #endif /* MBEDTLS_TIMING_C */
diff --git a/programs/test/cmake_package/cmake_package.c b/programs/test/cmake_package/cmake_package.c
index 4263bd9..be21cc3 100644
--- a/programs/test/cmake_package/cmake_package.c
+++ b/programs/test/cmake_package/cmake_package.c
@@ -20,15 +20,15 @@
 #include "mbedtls/build_info.h"
 
 #if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
+#    include "mbedtls/platform.h"
 #else
-#include <stdio.h>
-#include <stdlib.h>
-#define mbedtls_fprintf         fprintf
-#define mbedtls_printf          printf
-#define mbedtls_exit            exit
-#define MBEDTLS_EXIT_SUCCESS    EXIT_SUCCESS
-#define MBEDTLS_EXIT_FAILURE    EXIT_FAILURE
+#    include <stdio.h>
+#    include <stdlib.h>
+#    define mbedtls_fprintf      fprintf
+#    define mbedtls_printf       printf
+#    define mbedtls_exit         exit
+#    define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
+#    define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
 #endif /* MBEDTLS_PLATFORM_C */
 
 #include "mbedtls/version.h"
@@ -41,9 +41,9 @@
     /* This version string is 18 bytes long, as advised by version.h. */
     char version[18];
 
-    mbedtls_version_get_string_full( version );
+    mbedtls_version_get_string_full(version);
 
-    mbedtls_printf( "Built against %s\n", version );
+    mbedtls_printf("Built against %s\n", version);
 
-    return 0 ;
+    return 0;
 }
diff --git a/programs/test/cmake_package_install/cmake_package_install.c b/programs/test/cmake_package_install/cmake_package_install.c
index e8517ba..735f74a 100644
--- a/programs/test/cmake_package_install/cmake_package_install.c
+++ b/programs/test/cmake_package_install/cmake_package_install.c
@@ -21,15 +21,15 @@
 #include "mbedtls/build_info.h"
 
 #if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
+#    include "mbedtls/platform.h"
 #else
-#include <stdio.h>
-#include <stdlib.h>
-#define mbedtls_fprintf         fprintf
-#define mbedtls_printf          printf
-#define mbedtls_exit            exit
-#define MBEDTLS_EXIT_SUCCESS    EXIT_SUCCESS
-#define MBEDTLS_EXIT_FAILURE    EXIT_FAILURE
+#    include <stdio.h>
+#    include <stdlib.h>
+#    define mbedtls_fprintf      fprintf
+#    define mbedtls_printf       printf
+#    define mbedtls_exit         exit
+#    define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
+#    define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
 #endif /* MBEDTLS_PLATFORM_C */
 
 #include "mbedtls/version.h"
@@ -42,9 +42,9 @@
     /* This version string is 18 bytes long, as advised by version.h. */
     char version[18];
 
-    mbedtls_version_get_string_full( version );
+    mbedtls_version_get_string_full(version);
 
-    mbedtls_printf( "Built against %s\n", version );
+    mbedtls_printf("Built against %s\n", version);
 
-    return 0 ;
+    return 0;
 }
diff --git a/programs/test/cmake_subproject/cmake_subproject.c b/programs/test/cmake_subproject/cmake_subproject.c
index 6f9d383..b9e093c 100644
--- a/programs/test/cmake_subproject/cmake_subproject.c
+++ b/programs/test/cmake_subproject/cmake_subproject.c
@@ -21,15 +21,15 @@
 #include "mbedtls/build_info.h"
 
 #if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
+#    include "mbedtls/platform.h"
 #else
-#include <stdio.h>
-#include <stdlib.h>
-#define mbedtls_fprintf         fprintf
-#define mbedtls_printf          printf
-#define mbedtls_exit            exit
-#define MBEDTLS_EXIT_SUCCESS    EXIT_SUCCESS
-#define MBEDTLS_EXIT_FAILURE    EXIT_FAILURE
+#    include <stdio.h>
+#    include <stdlib.h>
+#    define mbedtls_fprintf      fprintf
+#    define mbedtls_printf       printf
+#    define mbedtls_exit         exit
+#    define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
+#    define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
 #endif /* MBEDTLS_PLATFORM_C */
 
 #include "mbedtls/version.h"
@@ -42,9 +42,9 @@
     /* This version string is 18 bytes long, as advised by version.h. */
     char version[18];
 
-    mbedtls_version_get_string_full( version );
+    mbedtls_version_get_string_full(version);
 
-    mbedtls_printf( "Built against %s\n", version );
+    mbedtls_printf("Built against %s\n", version);
 
-    return 0 ;
+    return 0;
 }
diff --git a/programs/test/query_compile_time_config.c b/programs/test/query_compile_time_config.c
index e640335..8f6abc7 100644
--- a/programs/test/query_compile_time_config.c
+++ b/programs/test/query_compile_time_config.c
@@ -20,12 +20,12 @@
 #include "mbedtls/build_info.h"
 
 #if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
+#    include "mbedtls/platform.h"
 #else
-#include <stdio.h>
-#include <stdlib.h>
-#define mbedtls_printf       printf
-#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
+#    include <stdio.h>
+#    include <stdlib.h>
+#    define mbedtls_printf       printf
+#    define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
 #endif
 
 #define USAGE                                                                \
@@ -38,13 +38,12 @@
 
 #include "query_config.h"
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
-    if ( argc != 2 )
-    {
-        mbedtls_printf( USAGE, argv[0] );
-        return MBEDTLS_EXIT_FAILURE ;
+    if (argc != 2) {
+        mbedtls_printf(USAGE, argv[0]);
+        return MBEDTLS_EXIT_FAILURE;
     }
 
-    return query_config( argv[1] ) ;
+    return query_config(argv[1]);
 }
diff --git a/programs/test/query_config.h b/programs/test/query_config.h
index 0fad886..9e8a74e 100644
--- a/programs/test/query_config.h
+++ b/programs/test/query_config.h
@@ -33,6 +33,6 @@
  *                  which is automatically generated by
  *                  `scripts/generate_query_config.pl`.
  */
-int query_config( const char *config );
+int query_config(const char *config);
 
 #endif /* MBEDTLS_PROGRAMS_TEST_QUERY_CONFIG_H */
diff --git a/programs/test/selftest.c b/programs/test/selftest.c
index 72180bb..56b711e 100644
--- a/programs/test/selftest.c
+++ b/programs/test/selftest.c
@@ -53,132 +53,113 @@
 #include <string.h>
 
 #if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
+#    include "mbedtls/platform.h"
 #else
-#include <stdio.h>
-#include <stdlib.h>
-#define mbedtls_calloc     calloc
-#define mbedtls_free       free
-#define mbedtls_printf     printf
-#define mbedtls_snprintf   snprintf
-#define mbedtls_exit       exit
-#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
-#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
+#    include <stdio.h>
+#    include <stdlib.h>
+#    define mbedtls_calloc       calloc
+#    define mbedtls_free         free
+#    define mbedtls_printf       printf
+#    define mbedtls_snprintf     snprintf
+#    define mbedtls_exit         exit
+#    define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
+#    define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
 #endif
 
 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
-#include "mbedtls/memory_buffer_alloc.h"
+#    include "mbedtls/memory_buffer_alloc.h"
 #endif
 
-
 #if defined MBEDTLS_SELF_TEST
 /* Sanity check for malloc. This is not expected to fail, and is rather
  * intended to display potentially useful information about the platform,
  * in particular the behavior of malloc(0). */
-static int calloc_self_test( int verbose )
+static int calloc_self_test(int verbose)
 {
     int failures = 0;
-    void *empty1 = mbedtls_calloc( 0, 1 );
-    void *empty2 = mbedtls_calloc( 0, 1 );
-    void *buffer1 = mbedtls_calloc( 1, 1 );
-    void *buffer2 = mbedtls_calloc( 1, 1 );
+    void *empty1 = mbedtls_calloc(0, 1);
+    void *empty2 = mbedtls_calloc(0, 1);
+    void *buffer1 = mbedtls_calloc(1, 1);
+    void *buffer2 = mbedtls_calloc(1, 1);
     uintptr_t old_buffer1;
 
-    if( empty1 == NULL && empty2 == NULL )
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(0): passed (NULL)\n" );
-    }
-    else if( empty1 == NULL || empty2 == NULL )
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(0): failed (mix of NULL and non-NULL)\n" );
+    if (empty1 == NULL && empty2 == NULL) {
+        if (verbose)
+            mbedtls_printf("  CALLOC(0): passed (NULL)\n");
+    } else if (empty1 == NULL || empty2 == NULL) {
+        if (verbose)
+            mbedtls_printf("  CALLOC(0): failed (mix of NULL and non-NULL)\n");
         ++failures;
-    }
-    else if( empty1 == empty2 )
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(0): passed (same non-null)\n" );
-    }
-    else
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(0): passed (distinct non-null)\n" );
+    } else if (empty1 == empty2) {
+        if (verbose)
+            mbedtls_printf("  CALLOC(0): passed (same non-null)\n");
+    } else {
+        if (verbose)
+            mbedtls_printf("  CALLOC(0): passed (distinct non-null)\n");
     }
 
-    if( buffer1 == NULL || buffer2 == NULL )
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(1): failed (NULL)\n" );
+    if (buffer1 == NULL || buffer2 == NULL) {
+        if (verbose)
+            mbedtls_printf("  CALLOC(1): failed (NULL)\n");
         ++failures;
-    }
-    else if( buffer1 == buffer2 )
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(1): failed (same buffer twice)\n" );
+    } else if (buffer1 == buffer2) {
+        if (verbose)
+            mbedtls_printf("  CALLOC(1): failed (same buffer twice)\n");
         ++failures;
-    }
-    else
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(1): passed\n" );
+    } else {
+        if (verbose)
+            mbedtls_printf("  CALLOC(1): passed\n");
     }
 
-    old_buffer1 = (uintptr_t) buffer1;
-    mbedtls_free( buffer1 );
-    buffer1 = mbedtls_calloc( 1, 1 );
-    if( buffer1 == NULL )
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(1 again): failed (NULL)\n" );
+    old_buffer1 = (uintptr_t)buffer1;
+    mbedtls_free(buffer1);
+    buffer1 = mbedtls_calloc(1, 1);
+    if (buffer1 == NULL) {
+        if (verbose)
+            mbedtls_printf("  CALLOC(1 again): failed (NULL)\n");
         ++failures;
-    }
-    else
-    {
-        if( verbose )
-            mbedtls_printf( "  CALLOC(1 again): passed (%s address)\n",
-                            (uintptr_t) old_buffer1 == (uintptr_t) buffer1 ?
-                            "same" : "different" );
+    } else {
+        if (verbose)
+            mbedtls_printf("  CALLOC(1 again): passed (%s address)\n",
+                           (uintptr_t)old_buffer1 == (uintptr_t)buffer1 ?
+                               "same" :
+                               "different");
     }
 
-    if( verbose )
-        mbedtls_printf( "\n" );
-    mbedtls_free( empty1 );
-    mbedtls_free( empty2 );
-    mbedtls_free( buffer1 );
-    mbedtls_free( buffer2 );
-    return failures ;
+    if (verbose)
+        mbedtls_printf("\n");
+    mbedtls_free(empty1);
+    mbedtls_free(empty2);
+    mbedtls_free(buffer1);
+    mbedtls_free(buffer2);
+    return failures;
 }
 #endif /* MBEDTLS_SELF_TEST */
 
-static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
+static int test_snprintf(size_t n, const char *ref_buf, int ref_ret)
 {
     int ret;
     char buf[10] = "xxxxxxxxx";
     const char ref[10] = "xxxxxxxxx";
 
-    ret = mbedtls_snprintf( buf, n, "%s", "123" );
-    if( ret < 0 || (size_t) ret >= n )
+    ret = mbedtls_snprintf(buf, n, "%s", "123");
+    if (ret < 0 || (size_t)ret >= n)
         ret = -1;
 
-    if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
-        ref_ret != ret ||
-        memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
-    {
-        return 1 ;
+    if (strncmp(ref_buf, buf, sizeof(buf)) != 0 || ref_ret != ret ||
+        memcmp(buf + n, ref + n, sizeof(buf) - n) != 0) {
+        return 1;
     }
 
-    return 0 ;
+    return 0;
 }
 
-static int run_test_snprintf( void )
+static int run_test_snprintf(void)
 {
-    return( test_snprintf( 0, "xxxxxxxxx",  -1 ) != 0 ||
-            test_snprintf( 1, "",           -1 ) != 0 ||
-            test_snprintf( 2, "1",          -1 ) != 0 ||
-            test_snprintf( 3, "12",         -1 ) != 0 ||
-            test_snprintf( 4, "123",         3 ) != 0 ||
-            test_snprintf( 5, "123",         3 ) != 0 );
+    return (test_snprintf(0, "xxxxxxxxx", -1) != 0 ||
+            test_snprintf(1, "", -1) != 0 || test_snprintf(2, "1", -1) != 0 ||
+            test_snprintf(3, "12", -1) != 0 ||
+            test_snprintf(4, "123", 3) != 0 || test_snprintf(5, "123", 3) != 0);
 }
 
 /*
@@ -187,8 +168,9 @@
  * back.
  */
 #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C)
-#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
-static void create_entropy_seed_file( void )
+#    if defined(MBEDTLS_ENTROPY_NV_SEED) && \
+        !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
+static void create_entropy_seed_file(void)
 {
     int result;
     size_t output_len = 0;
@@ -196,145 +178,141 @@
 
     /* Attempt to read the entropy seed file. If this fails - attempt to write
      * to the file to ensure one is present. */
-    result = mbedtls_platform_std_nv_seed_read( seed_value,
-                                                    MBEDTLS_ENTROPY_BLOCK_SIZE );
-    if( 0 == result )
+    result = mbedtls_platform_std_nv_seed_read(seed_value,
+                                               MBEDTLS_ENTROPY_BLOCK_SIZE);
+    if (0 == result)
         return;
 
-    result = mbedtls_platform_entropy_poll( NULL,
-                                            seed_value,
-                                            MBEDTLS_ENTROPY_BLOCK_SIZE,
-                                            &output_len );
-    if( 0 != result )
+    result = mbedtls_platform_entropy_poll(
+        NULL, seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE, &output_len);
+    if (0 != result)
         return;
 
-    if( MBEDTLS_ENTROPY_BLOCK_SIZE != output_len )
+    if (MBEDTLS_ENTROPY_BLOCK_SIZE != output_len)
         return;
 
-    mbedtls_platform_std_nv_seed_write( seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE );
+    mbedtls_platform_std_nv_seed_write(seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE);
 }
-#endif
+#    endif
 
-int mbedtls_entropy_self_test_wrapper( int verbose )
+int mbedtls_entropy_self_test_wrapper(int verbose)
 {
-#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
-    create_entropy_seed_file( );
-#endif
-    return mbedtls_entropy_self_test( verbose ) ;
+#    if defined(MBEDTLS_ENTROPY_NV_SEED) && \
+        !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
+    create_entropy_seed_file();
+#    endif
+    return mbedtls_entropy_self_test(verbose);
 }
 #endif
 
 #if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
-int mbedtls_memory_buffer_alloc_free_and_self_test( int verbose )
+#    if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
+int mbedtls_memory_buffer_alloc_free_and_self_test(int verbose)
 {
-    if( verbose != 0 )
-    {
-#if defined(MBEDTLS_MEMORY_DEBUG)
-        mbedtls_memory_buffer_alloc_status( );
-#endif
+    if (verbose != 0) {
+#        if defined(MBEDTLS_MEMORY_DEBUG)
+        mbedtls_memory_buffer_alloc_status();
+#        endif
     }
-    mbedtls_memory_buffer_alloc_free( );
-    return mbedtls_memory_buffer_alloc_self_test( verbose ) ;
+    mbedtls_memory_buffer_alloc_free();
+    return mbedtls_memory_buffer_alloc_self_test(verbose);
 }
-#endif
+#    endif
 
-typedef struct
-{
+typedef struct {
     const char *name;
-    int ( *function )( int );
+    int (*function)(int);
 } selftest_t;
 
-const selftest_t selftests[] =
-{
-    {"calloc", calloc_self_test},
-#if defined(MBEDTLS_MD5_C)
-    {"md5", mbedtls_md5_self_test},
-#endif
-#if defined(MBEDTLS_RIPEMD160_C)
-    {"ripemd160", mbedtls_ripemd160_self_test},
-#endif
-#if defined(MBEDTLS_SHA1_C)
-    {"sha1", mbedtls_sha1_self_test},
-#endif
-#if defined(MBEDTLS_SHA256_C)
-    {"sha256", mbedtls_sha256_self_test},
-#endif
-#if defined(MBEDTLS_SHA512_C)
-    {"sha512", mbedtls_sha512_self_test},
-#endif
-#if defined(MBEDTLS_DES_C)
-    {"des", mbedtls_des_self_test},
-#endif
-#if defined(MBEDTLS_AES_C)
-    {"aes", mbedtls_aes_self_test},
-#endif
-#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
-    {"gcm", mbedtls_gcm_self_test},
-#endif
-#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
-    {"ccm", mbedtls_ccm_self_test},
-#endif
-#if defined(MBEDTLS_NIST_KW_C) && defined(MBEDTLS_AES_C)
-    {"nist_kw", mbedtls_nist_kw_self_test},
-#endif
-#if defined(MBEDTLS_CMAC_C)
-    {"cmac", mbedtls_cmac_self_test},
-#endif
-#if defined(MBEDTLS_CHACHA20_C)
-    {"chacha20", mbedtls_chacha20_self_test},
-#endif
-#if defined(MBEDTLS_POLY1305_C)
-    {"poly1305", mbedtls_poly1305_self_test},
-#endif
-#if defined(MBEDTLS_CHACHAPOLY_C)
-    {"chacha20-poly1305", mbedtls_chachapoly_self_test},
-#endif
-#if defined(MBEDTLS_BASE64_C)
-    {"base64", mbedtls_base64_self_test},
-#endif
-#if defined(MBEDTLS_BIGNUM_C)
-    {"mpi", mbedtls_mpi_self_test},
-#endif
-#if defined(MBEDTLS_RSA_C)
-    {"rsa", mbedtls_rsa_self_test},
-#endif
-#if defined(MBEDTLS_CAMELLIA_C)
-    {"camellia", mbedtls_camellia_self_test},
-#endif
-#if defined(MBEDTLS_ARIA_C)
-    {"aria", mbedtls_aria_self_test},
-#endif
-#if defined(MBEDTLS_CTR_DRBG_C)
-    {"ctr_drbg", mbedtls_ctr_drbg_self_test},
-#endif
-#if defined(MBEDTLS_HMAC_DRBG_C)
-    {"hmac_drbg", mbedtls_hmac_drbg_self_test},
-#endif
-#if defined(MBEDTLS_ECP_C)
-    {"ecp", mbedtls_ecp_self_test},
-#endif
-#if defined(MBEDTLS_ECJPAKE_C)
-    {"ecjpake", mbedtls_ecjpake_self_test},
-#endif
-#if defined(MBEDTLS_DHM_C)
-    {"dhm", mbedtls_dhm_self_test},
-#endif
-#if defined(MBEDTLS_ENTROPY_C)
-    {"entropy", mbedtls_entropy_self_test_wrapper},
-#endif
-#if defined(MBEDTLS_PKCS5_C)
-    {"pkcs5", mbedtls_pkcs5_self_test},
-#endif
+const selftest_t selftests[] = {
+    { "calloc", calloc_self_test },
+#    if defined(MBEDTLS_MD5_C)
+    { "md5", mbedtls_md5_self_test },
+#    endif
+#    if defined(MBEDTLS_RIPEMD160_C)
+    { "ripemd160", mbedtls_ripemd160_self_test },
+#    endif
+#    if defined(MBEDTLS_SHA1_C)
+    { "sha1", mbedtls_sha1_self_test },
+#    endif
+#    if defined(MBEDTLS_SHA256_C)
+    { "sha256", mbedtls_sha256_self_test },
+#    endif
+#    if defined(MBEDTLS_SHA512_C)
+    { "sha512", mbedtls_sha512_self_test },
+#    endif
+#    if defined(MBEDTLS_DES_C)
+    { "des", mbedtls_des_self_test },
+#    endif
+#    if defined(MBEDTLS_AES_C)
+    { "aes", mbedtls_aes_self_test },
+#    endif
+#    if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
+    { "gcm", mbedtls_gcm_self_test },
+#    endif
+#    if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
+    { "ccm", mbedtls_ccm_self_test },
+#    endif
+#    if defined(MBEDTLS_NIST_KW_C) && defined(MBEDTLS_AES_C)
+    { "nist_kw", mbedtls_nist_kw_self_test },
+#    endif
+#    if defined(MBEDTLS_CMAC_C)
+    { "cmac", mbedtls_cmac_self_test },
+#    endif
+#    if defined(MBEDTLS_CHACHA20_C)
+    { "chacha20", mbedtls_chacha20_self_test },
+#    endif
+#    if defined(MBEDTLS_POLY1305_C)
+    { "poly1305", mbedtls_poly1305_self_test },
+#    endif
+#    if defined(MBEDTLS_CHACHAPOLY_C)
+    { "chacha20-poly1305", mbedtls_chachapoly_self_test },
+#    endif
+#    if defined(MBEDTLS_BASE64_C)
+    { "base64", mbedtls_base64_self_test },
+#    endif
+#    if defined(MBEDTLS_BIGNUM_C)
+    { "mpi", mbedtls_mpi_self_test },
+#    endif
+#    if defined(MBEDTLS_RSA_C)
+    { "rsa", mbedtls_rsa_self_test },
+#    endif
+#    if defined(MBEDTLS_CAMELLIA_C)
+    { "camellia", mbedtls_camellia_self_test },
+#    endif
+#    if defined(MBEDTLS_ARIA_C)
+    { "aria", mbedtls_aria_self_test },
+#    endif
+#    if defined(MBEDTLS_CTR_DRBG_C)
+    { "ctr_drbg", mbedtls_ctr_drbg_self_test },
+#    endif
+#    if defined(MBEDTLS_HMAC_DRBG_C)
+    { "hmac_drbg", mbedtls_hmac_drbg_self_test },
+#    endif
+#    if defined(MBEDTLS_ECP_C)
+    { "ecp", mbedtls_ecp_self_test },
+#    endif
+#    if defined(MBEDTLS_ECJPAKE_C)
+    { "ecjpake", mbedtls_ecjpake_self_test },
+#    endif
+#    if defined(MBEDTLS_DHM_C)
+    { "dhm", mbedtls_dhm_self_test },
+#    endif
+#    if defined(MBEDTLS_ENTROPY_C)
+    { "entropy", mbedtls_entropy_self_test_wrapper },
+#    endif
+#    if defined(MBEDTLS_PKCS5_C)
+    { "pkcs5", mbedtls_pkcs5_self_test },
+#    endif
 /* Heap test comes last */
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
-    {"memory_buffer_alloc", mbedtls_memory_buffer_alloc_free_and_self_test},
-#endif
-    {NULL, NULL}
+#    if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
+    { "memory_buffer_alloc", mbedtls_memory_buffer_alloc_free_and_self_test },
+#    endif
+    { NULL, NULL }
 };
 #endif /* MBEDTLS_SELF_TEST */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
 #if defined(MBEDTLS_SELF_TEST)
     const selftest_t *test;
@@ -353,93 +331,73 @@
      * of a NULL pointer. We do however use that in our code for initializing
      * structures, which should work on every modern platform. Let's be sure.
      */
-    memset( &pointer, 0, sizeof( void * ) );
-    if( pointer != NULL )
-    {
-        mbedtls_printf( "all-bits-zero is not a NULL pointer\n" );
-        mbedtls_exit( MBEDTLS_EXIT_FAILURE );
+    memset(&pointer, 0, sizeof(void *));
+    if (pointer != NULL) {
+        mbedtls_printf("all-bits-zero is not a NULL pointer\n");
+        mbedtls_exit(MBEDTLS_EXIT_FAILURE);
     }
 
     /*
      * Make sure we have a snprintf that correctly zero-terminates
      */
-    if( run_test_snprintf() != 0 )
-    {
-        mbedtls_printf( "the snprintf implementation is broken\n" );
-        mbedtls_exit( MBEDTLS_EXIT_FAILURE );
+    if (run_test_snprintf() != 0) {
+        mbedtls_printf("the snprintf implementation is broken\n");
+        mbedtls_exit(MBEDTLS_EXIT_FAILURE);
     }
 
-    for( argp = argv + ( argc >= 1 ? 1 : argc ); *argp != NULL; ++argp )
-    {
-        if( strcmp( *argp, "--quiet" ) == 0 ||
-            strcmp( *argp, "-q" ) == 0 )
-        {
+    for (argp = argv + (argc >= 1 ? 1 : argc); *argp != NULL; ++argp) {
+        if (strcmp(*argp, "--quiet") == 0 || strcmp(*argp, "-q") == 0) {
             v = 0;
-        }
-        else if( strcmp( *argp, "--exclude" ) == 0 ||
-                 strcmp( *argp, "-x" ) == 0 )
-        {
+        } else if (strcmp(*argp, "--exclude") == 0 ||
+                   strcmp(*argp, "-x") == 0) {
             exclude_mode = 1;
-        }
-        else
+        } else
             break;
     }
 
-    if( v != 0 )
-        mbedtls_printf( "\n" );
+    if (v != 0)
+        mbedtls_printf("\n");
 
 #if defined(MBEDTLS_SELF_TEST)
 
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
-    mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
-#endif
+#    if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
+    mbedtls_memory_buffer_alloc_init(buf, sizeof(buf));
+#    endif
 
-    if( *argp != NULL && exclude_mode == 0 )
-    {
+    if (*argp != NULL && exclude_mode == 0) {
         /* Run the specified tests */
-        for( ; *argp != NULL; argp++ )
-        {
-            for( test = selftests; test->name != NULL; test++ )
-            {
-                if( !strcmp( *argp, test->name ) )
-                {
-                    if( test->function( v )  != 0 )
-                    {
+        for (; *argp != NULL; argp++) {
+            for (test = selftests; test->name != NULL; test++) {
+                if (!strcmp(*argp, test->name)) {
+                    if (test->function(v) != 0) {
                         suites_failed++;
                     }
                     suites_tested++;
                     break;
                 }
             }
-            if( test->name == NULL )
-            {
-                mbedtls_printf( "  Test suite %s not available -> failed\n\n", *argp );
+            if (test->name == NULL) {
+                mbedtls_printf("  Test suite %s not available -> failed\n\n",
+                               *argp);
                 suites_failed++;
             }
         }
-    }
-    else
-    {
+    } else {
         /* Run all the tests except excluded ones */
-        for( test = selftests; test->name != NULL; test++ )
-        {
-            if( exclude_mode )
-            {
+        for (test = selftests; test->name != NULL; test++) {
+            if (exclude_mode) {
                 char **excluded;
-                for( excluded = argp; *excluded != NULL; ++excluded )
-                {
-                    if( !strcmp( *excluded, test->name ) )
+                for (excluded = argp; *excluded != NULL; ++excluded) {
+                    if (!strcmp(*excluded, test->name))
                         break;
                 }
-                if( *excluded )
-                {
-                    if( v )
-                        mbedtls_printf( "  Skip: %s\n", test->name );
+                if (*excluded) {
+                    if (v)
+                        mbedtls_printf("  Skip: %s\n", test->name);
                     continue;
                 }
             }
-            if( test->function( v )  != 0 )
-            {
+            if (test->function(v) != 0) {
                 suites_failed++;
             }
             suites_tested++;
@@ -447,30 +405,27 @@
     }
 
 #else
-    (void) exclude_mode;
-    mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
+    (void)exclude_mode;
+    mbedtls_printf(" MBEDTLS_SELF_TEST not defined.\n");
 #endif
 
-    if( v != 0 )
-    {
-        mbedtls_printf( "  Executed %d test suites\n\n", suites_tested );
+    if (v != 0) {
+        mbedtls_printf("  Executed %d test suites\n\n", suites_tested);
 
-        if( suites_failed > 0)
-        {
-            mbedtls_printf( "  [ %d tests FAIL ]\n\n", suites_failed );
-        }
-        else
-        {
-            mbedtls_printf( "  [ All tests PASS ]\n\n" );
+        if (suites_failed > 0) {
+            mbedtls_printf("  [ %d tests FAIL ]\n\n", suites_failed);
+        } else {
+            mbedtls_printf("  [ All tests PASS ]\n\n");
         }
 #if defined(_WIN32)
-        mbedtls_printf( "  Press Enter to exit this program.\n" );
-        fflush( stdout ); getchar();
+        mbedtls_printf("  Press Enter to exit this program.\n");
+        fflush(stdout);
+        getchar();
 #endif
     }
 
-    if( suites_failed > 0)
-        mbedtls_exit( MBEDTLS_EXIT_FAILURE );
+    if (suites_failed > 0)
+        mbedtls_exit(MBEDTLS_EXIT_FAILURE);
 
-    mbedtls_exit( MBEDTLS_EXIT_SUCCESS );
+    mbedtls_exit(MBEDTLS_EXIT_SUCCESS);
 }
diff --git a/programs/test/udp_proxy.c b/programs/test/udp_proxy.c
index aa01562..34c23ea 100644
--- a/programs/test/udp_proxy.c
+++ b/programs/test/udp_proxy.c
@@ -28,367 +28,353 @@
 #include "mbedtls/build_info.h"
 
 #if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
+#    include "mbedtls/platform.h"
 #else
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#define mbedtls_time            time
-#define mbedtls_time_t          time_t
-#define mbedtls_printf          printf
-#define mbedtls_calloc          calloc
-#define mbedtls_free            free
-#define mbedtls_exit            exit
-#define MBEDTLS_EXIT_SUCCESS    EXIT_SUCCESS
-#define MBEDTLS_EXIT_FAILURE    EXIT_FAILURE
+#    include <stdio.h>
+#    include <stdlib.h>
+#    include <time.h>
+#    define mbedtls_time         time
+#    define mbedtls_time_t       time_t
+#    define mbedtls_printf       printf
+#    define mbedtls_calloc       calloc
+#    define mbedtls_free         free
+#    define mbedtls_exit         exit
+#    define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
+#    define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
 #endif /* MBEDTLS_PLATFORM_C */
 
 #if !defined(MBEDTLS_NET_C)
-int main( void )
+int main(void)
 {
-    mbedtls_printf( "MBEDTLS_NET_C not defined.\n" );
-    mbedtls_exit( 0 );
+    mbedtls_printf("MBEDTLS_NET_C not defined.\n");
+    mbedtls_exit(0);
 }
 #else
 
-#include "mbedtls/net_sockets.h"
-#include "mbedtls/error.h"
-#include "mbedtls/ssl.h"
-#include "mbedtls/timing.h"
+#    include "mbedtls/net_sockets.h"
+#    include "mbedtls/error.h"
+#    include "mbedtls/ssl.h"
+#    include "mbedtls/timing.h"
 
-#include <string.h>
+#    include <string.h>
 
 /* For select() */
-#if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(EFIX64) && \
-    !defined(EFI32)
-#include <winsock2.h>
-#include <windows.h>
-#if defined(_MSC_VER)
-#if defined(_WIN32_WCE)
-#pragma comment( lib, "ws2.lib" )
-#else
-#pragma comment( lib, "ws2_32.lib" )
-#endif
-#endif /* _MSC_VER */
-#else /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#endif /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
+#    if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(EFIX64) && \
+        !defined(EFI32)
+#        include <winsock2.h>
+#        include <windows.h>
+#        if defined(_MSC_VER)
+#            if defined(_WIN32_WCE)
+#                pragma comment(lib, "ws2.lib")
+#            else
+#                pragma comment(lib, "ws2_32.lib")
+#            endif
+#        endif /* _MSC_VER */
+#    else /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
+#        include <sys/time.h>
+#        include <sys/types.h>
+#        include <unistd.h>
+#    endif /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
 
-#define MAX_MSG_SIZE            16384 + 2048 /* max record/datagram size */
+#    define MAX_MSG_SIZE 16384 + 2048 /* max record/datagram size */
 
-#define DFL_SERVER_ADDR         "localhost"
-#define DFL_SERVER_PORT         "4433"
-#define DFL_LISTEN_ADDR         "localhost"
-#define DFL_LISTEN_PORT         "5556"
-#define DFL_PACK                0
+#    define DFL_SERVER_ADDR "localhost"
+#    define DFL_SERVER_PORT "4433"
+#    define DFL_LISTEN_ADDR "localhost"
+#    define DFL_LISTEN_PORT "5556"
+#    define DFL_PACK        0
 
-#if defined(MBEDTLS_TIMING_C)
-#define USAGE_PACK                                                          \
-    "    pack=%%d             default: 0     (don't pack)\n"                \
-    "                         options: t > 0 (pack for t milliseconds)\n"
-#else
-#define USAGE_PACK
-#endif
+#    if defined(MBEDTLS_TIMING_C)
+#        define USAGE_PACK                                           \
+            "    pack=%%d             default: 0     (don't pack)\n" \
+            "                         options: t > 0 (pack for t milliseconds)\n"
+#    else
+#        define USAGE_PACK
+#    endif
 
-#define USAGE                                                               \
-    "\n usage: udp_proxy param=<>...\n"                                     \
-    "\n acceptable parameters:\n"                                           \
-    "    server_addr=%%s      default: localhost\n"                         \
-    "    server_port=%%d      default: 4433\n"                              \
-    "    listen_addr=%%s      default: localhost\n"                         \
-    "    listen_port=%%d      default: 4433\n"                              \
-    "\n"                                                                    \
-    "    duplicate=%%d        default: 0 (no duplication)\n"                \
-    "                        duplicate about 1:N packets randomly\n"        \
-    "    delay=%%d            default: 0 (no delayed packets)\n"            \
-    "                        delay about 1:N packets randomly\n"            \
-    "    delay_ccs=0/1       default: 0 (don't delay ChangeCipherSpec)\n"   \
-    "    delay_cli=%%s        Handshake message from client that should be\n"\
-    "                        delayed. Possible values are 'ClientHello',\n" \
-    "                        'Certificate', 'CertificateVerify', and\n"     \
-    "                        'ClientKeyExchange'.\n"                        \
-    "                        May be used multiple times, even for the same\n"\
-    "                        message, in which case the respective message\n"\
-    "                        gets delayed multiple times.\n"                 \
-    "    delay_srv=%%s        Handshake message from server that should be\n"\
-    "                        delayed. Possible values are 'HelloRequest',\n"\
-    "                        'ServerHello', 'ServerHelloDone', 'Certificate'\n"\
-    "                        'ServerKeyExchange', 'NewSessionTicket',\n"\
-    "                        'HelloVerifyRequest' and ''CertificateRequest'.\n"\
-    "                        May be used multiple times, even for the same\n"\
-    "                        message, in which case the respective message\n"\
-    "                        gets delayed multiple times.\n"                 \
-    "    drop=%%d             default: 0 (no dropped packets)\n"            \
-    "                        drop about 1:N packets randomly\n"             \
-    "    mtu=%%d              default: 0 (unlimited)\n"                     \
-    "                        drop packets larger than N bytes\n"            \
-    "    bad_ad=0/1          default: 0 (don't add bad ApplicationData)\n"  \
-    "    bad_cid=%%d          default: 0 (don't corrupt Connection IDs)\n"   \
-    "                        duplicate 1:N packets containing a CID,\n" \
-    "                        modifying CID in first instance of the packet.\n" \
-    "    protect_hvr=0/1     default: 0 (don't protect HelloVerifyRequest)\n" \
-    "    protect_len=%%d      default: (don't protect packets of this size)\n" \
-    "    inject_clihlo=0/1   default: 0 (don't inject fake ClientHello)\n"  \
-    "\n"                                                                    \
-    "    seed=%%d             default: (use current time)\n"                \
-    USAGE_PACK                                                              \
-    "\n"
+#    define USAGE                                                                   \
+        "\n usage: udp_proxy param=<>...\n"                                         \
+        "\n acceptable parameters:\n"                                               \
+        "    server_addr=%%s      default: localhost\n"                             \
+        "    server_port=%%d      default: 4433\n"                                  \
+        "    listen_addr=%%s      default: localhost\n"                             \
+        "    listen_port=%%d      default: 4433\n"                                  \
+        "\n"                                                                        \
+        "    duplicate=%%d        default: 0 (no duplication)\n"                    \
+        "                        duplicate about 1:N packets randomly\n"            \
+        "    delay=%%d            default: 0 (no delayed packets)\n"                \
+        "                        delay about 1:N packets randomly\n"                \
+        "    delay_ccs=0/1       default: 0 (don't delay ChangeCipherSpec)\n"       \
+        "    delay_cli=%%s        Handshake message from client that should be\n"   \
+        "                        delayed. Possible values are 'ClientHello',\n"     \
+        "                        'Certificate', 'CertificateVerify', and\n"         \
+        "                        'ClientKeyExchange'.\n"                            \
+        "                        May be used multiple times, even for the same\n"   \
+        "                        message, in which case the respective message\n"   \
+        "                        gets delayed multiple times.\n"                    \
+        "    delay_srv=%%s        Handshake message from server that should be\n"   \
+        "                        delayed. Possible values are 'HelloRequest',\n"    \
+        "                        'ServerHello', 'ServerHelloDone', 'Certificate'\n" \
+        "                        'ServerKeyExchange', 'NewSessionTicket',\n"        \
+        "                        'HelloVerifyRequest' and ''CertificateRequest'.\n" \
+        "                        May be used multiple times, even for the same\n"   \
+        "                        message, in which case the respective message\n"   \
+        "                        gets delayed multiple times.\n"                    \
+        "    drop=%%d             default: 0 (no dropped packets)\n"                \
+        "                        drop about 1:N packets randomly\n"                 \
+        "    mtu=%%d              default: 0 (unlimited)\n"                         \
+        "                        drop packets larger than N bytes\n"                \
+        "    bad_ad=0/1          default: 0 (don't add bad ApplicationData)\n"      \
+        "    bad_cid=%%d          default: 0 (don't corrupt Connection IDs)\n"      \
+        "                        duplicate 1:N packets containing a CID,\n"         \
+        "                        modifying CID in first instance of the packet.\n"  \
+        "    protect_hvr=0/1     default: 0 (don't protect HelloVerifyRequest)\n"   \
+        "    protect_len=%%d      default: (don't protect packets of this size)\n"  \
+        "    inject_clihlo=0/1   default: 0 (don't inject fake ClientHello)\n"      \
+        "\n"                                                                        \
+        "    seed=%%d             default: (use current time)\n" USAGE_PACK         \
+        "\n"
 
 /*
  * global options
  */
 
-#define MAX_DELAYED_HS 10
+#    define MAX_DELAYED_HS 10
 
-static struct options
-{
-    const char *server_addr;    /* address to forward packets to            */
-    const char *server_port;    /* port to forward packets to               */
-    const char *listen_addr;    /* address for accepting client connections */
-    const char *listen_port;    /* port for accepting client connections    */
+static struct options {
+    const char *server_addr; /* address to forward packets to            */
+    const char *server_port; /* port to forward packets to               */
+    const char *listen_addr; /* address for accepting client connections */
+    const char *listen_port; /* port for accepting client connections    */
 
-    int duplicate;              /* duplicate 1 in N packets (none if 0)     */
-    int delay;                  /* delay 1 packet in N (none if 0)          */
-    int delay_ccs;              /* delay ChangeCipherSpec                   */
-    char* delay_cli[MAX_DELAYED_HS];  /* handshake types of messages from
-                                       * client that should be delayed.     */
-    uint8_t delay_cli_cnt;      /* Number of entries in delay_cli.          */
-    char* delay_srv[MAX_DELAYED_HS];  /* handshake types of messages from
-                                       * server that should be delayed.     */
-    uint8_t delay_srv_cnt;      /* Number of entries in delay_srv.          */
-    int drop;                   /* drop 1 packet in N (none if 0)           */
-    int mtu;                    /* drop packets larger than this            */
-    int bad_ad;                 /* inject corrupted ApplicationData record  */
-    unsigned bad_cid;           /* inject corrupted CID record              */
-    int protect_hvr;            /* never drop or delay HelloVerifyRequest   */
-    int protect_len;            /* never drop/delay packet of the given size*/
-    int inject_clihlo;          /* inject fake ClientHello after handshake  */
-    unsigned pack;              /* merge packets into single datagram for
-                                 * at most \c merge milliseconds if > 0     */
-    unsigned int seed;          /* seed for "random" events                 */
+    int duplicate; /* duplicate 1 in N packets (none if 0)     */
+    int delay; /* delay 1 packet in N (none if 0)          */
+    int delay_ccs; /* delay ChangeCipherSpec                   */
+    char *delay_cli[MAX_DELAYED_HS]; /* handshake types of messages from
+                                      * client that should be delayed.     */
+    uint8_t delay_cli_cnt; /* Number of entries in delay_cli.          */
+    char *delay_srv[MAX_DELAYED_HS]; /* handshake types of messages from
+                                      * server that should be delayed.     */
+    uint8_t delay_srv_cnt; /* Number of entries in delay_srv.          */
+    int drop; /* drop 1 packet in N (none if 0)           */
+    int mtu; /* drop packets larger than this            */
+    int bad_ad; /* inject corrupted ApplicationData record  */
+    unsigned bad_cid; /* inject corrupted CID record              */
+    int protect_hvr; /* never drop or delay HelloVerifyRequest   */
+    int protect_len; /* never drop/delay packet of the given size*/
+    int inject_clihlo; /* inject fake ClientHello after handshake  */
+    unsigned pack; /* merge packets into single datagram for
+                    * at most \c merge milliseconds if > 0     */
+    unsigned int seed; /* seed for "random" events                 */
 } opt;
 
-static void exit_usage( const char *name, const char *value )
+static void exit_usage(const char *name, const char *value)
 {
-    if( value == NULL )
-        mbedtls_printf( " unknown option or missing value: %s\n", name );
+    if (value == NULL)
+        mbedtls_printf(" unknown option or missing value: %s\n", name);
     else
-        mbedtls_printf( " option %s: illegal value: %s\n", name, value );
+        mbedtls_printf(" option %s: illegal value: %s\n", name, value);
 
-    mbedtls_printf( USAGE );
-    mbedtls_exit( 1 );
+    mbedtls_printf(USAGE);
+    mbedtls_exit(1);
 }
 
-static void get_options( int argc, char *argv[] )
+static void get_options(int argc, char *argv[])
 {
     int i;
     char *p, *q;
 
-    opt.server_addr    = DFL_SERVER_ADDR;
-    opt.server_port    = DFL_SERVER_PORT;
-    opt.listen_addr    = DFL_LISTEN_ADDR;
-    opt.listen_port    = DFL_LISTEN_PORT;
-    opt.pack           = DFL_PACK;
+    opt.server_addr = DFL_SERVER_ADDR;
+    opt.server_port = DFL_SERVER_PORT;
+    opt.listen_addr = DFL_LISTEN_ADDR;
+    opt.listen_port = DFL_LISTEN_PORT;
+    opt.pack = DFL_PACK;
     /* Other members default to 0 */
 
     opt.delay_cli_cnt = 0;
     opt.delay_srv_cnt = 0;
-    memset( opt.delay_cli, 0, sizeof( opt.delay_cli ) );
-    memset( opt.delay_srv, 0, sizeof( opt.delay_srv ) );
+    memset(opt.delay_cli, 0, sizeof(opt.delay_cli));
+    memset(opt.delay_srv, 0, sizeof(opt.delay_srv));
 
-    for( i = 1; i < argc; i++ )
-    {
+    for (i = 1; i < argc; i++) {
         p = argv[i];
-        if( ( q = strchr( p, '=' ) ) == NULL )
-            exit_usage( p, NULL );
+        if ((q = strchr(p, '=')) == NULL)
+            exit_usage(p, NULL);
         *q++ = '\0';
 
-        if( strcmp( p, "server_addr" ) == 0 )
+        if (strcmp(p, "server_addr") == 0)
             opt.server_addr = q;
-        else if( strcmp( p, "server_port" ) == 0 )
+        else if (strcmp(p, "server_port") == 0)
             opt.server_port = q;
-        else if( strcmp( p, "listen_addr" ) == 0 )
+        else if (strcmp(p, "listen_addr") == 0)
             opt.listen_addr = q;
-        else if( strcmp( p, "listen_port" ) == 0 )
+        else if (strcmp(p, "listen_port") == 0)
             opt.listen_port = q;
-        else if( strcmp( p, "duplicate" ) == 0 )
-        {
-            opt.duplicate = atoi( q );
-            if( opt.duplicate < 0 || opt.duplicate > 20 )
-                exit_usage( p, q );
-        }
-        else if( strcmp( p, "delay" ) == 0 )
-        {
-            opt.delay = atoi( q );
-            if( opt.delay < 0 || opt.delay > 20 || opt.delay == 1 )
-                exit_usage( p, q );
-        }
-        else if( strcmp( p, "delay_ccs" ) == 0 )
-        {
-            opt.delay_ccs = atoi( q );
-            if( opt.delay_ccs < 0 || opt.delay_ccs > 1 )
-                exit_usage( p, q );
-        }
-        else if( strcmp( p, "delay_cli" ) == 0 ||
-                 strcmp( p, "delay_srv" ) == 0 )
-        {
+        else if (strcmp(p, "duplicate") == 0) {
+            opt.duplicate = atoi(q);
+            if (opt.duplicate < 0 || opt.duplicate > 20)
+                exit_usage(p, q);
+        } else if (strcmp(p, "delay") == 0) {
+            opt.delay = atoi(q);
+            if (opt.delay < 0 || opt.delay > 20 || opt.delay == 1)
+                exit_usage(p, q);
+        } else if (strcmp(p, "delay_ccs") == 0) {
+            opt.delay_ccs = atoi(q);
+            if (opt.delay_ccs < 0 || opt.delay_ccs > 1)
+                exit_usage(p, q);
+        } else if (strcmp(p, "delay_cli") == 0 || strcmp(p, "delay_srv") == 0) {
             uint8_t *delay_cnt;
             char **delay_list;
             size_t len;
             char *buf;
 
-            if( strcmp( p, "delay_cli" ) == 0 )
-            {
-                delay_cnt  = &opt.delay_cli_cnt;
+            if (strcmp(p, "delay_cli") == 0) {
+                delay_cnt = &opt.delay_cli_cnt;
                 delay_list = opt.delay_cli;
-            }
-            else
-            {
-                delay_cnt  = &opt.delay_srv_cnt;
+            } else {
+                delay_cnt = &opt.delay_srv_cnt;
                 delay_list = opt.delay_srv;
             }
 
-            if( *delay_cnt == MAX_DELAYED_HS )
-            {
-                mbedtls_printf( " too many uses of %s: only %d allowed\n",
-                                p, MAX_DELAYED_HS );
-                exit_usage( p, NULL );
+            if (*delay_cnt == MAX_DELAYED_HS) {
+                mbedtls_printf(" too many uses of %s: only %d allowed\n", p,
+                               MAX_DELAYED_HS);
+                exit_usage(p, NULL);
             }
 
-            len = strlen( q );
-            buf = mbedtls_calloc( 1, len + 1 );
-            if( buf == NULL )
-            {
-                mbedtls_printf( " Allocation failure\n" );
-                exit( 1 );
+            len = strlen(q);
+            buf = mbedtls_calloc(1, len + 1);
+            if (buf == NULL) {
+                mbedtls_printf(" Allocation failure\n");
+                exit(1);
             }
-            memcpy( buf, q, len + 1 );
+            memcpy(buf, q, len + 1);
 
-            delay_list[ (*delay_cnt)++ ] = buf;
+            delay_list[(*delay_cnt)++] = buf;
+        } else if (strcmp(p, "drop") == 0) {
+            opt.drop = atoi(q);
+            if (opt.drop < 0 || opt.drop > 20 || opt.drop == 1)
+                exit_usage(p, q);
+        } else if (strcmp(p, "pack") == 0) {
+#    if defined(MBEDTLS_TIMING_C)
+            opt.pack = (unsigned)atoi(q);
+#    else
+            mbedtls_printf(
+                " option pack only defined if MBEDTLS_TIMING_C is enabled\n");
+            exit(1);
+#    endif
+        } else if (strcmp(p, "mtu") == 0) {
+            opt.mtu = atoi(q);
+            if (opt.mtu < 0 || opt.mtu > MAX_MSG_SIZE)
+                exit_usage(p, q);
+        } else if (strcmp(p, "bad_ad") == 0) {
+            opt.bad_ad = atoi(q);
+            if (opt.bad_ad < 0 || opt.bad_ad > 1)
+                exit_usage(p, q);
         }
-        else if( strcmp( p, "drop" ) == 0 )
-        {
-            opt.drop = atoi( q );
-            if( opt.drop < 0 || opt.drop > 20 || opt.drop == 1 )
-                exit_usage( p, q );
+#    if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
+        else if (strcmp(p, "bad_cid") == 0) {
+            opt.bad_cid = (unsigned)atoi(q);
         }
-        else if( strcmp( p, "pack" ) == 0 )
-        {
-#if defined(MBEDTLS_TIMING_C)
-            opt.pack = (unsigned) atoi( q );
-#else
-            mbedtls_printf( " option pack only defined if MBEDTLS_TIMING_C is enabled\n" );
-            exit( 1 );
-#endif
-        }
-        else if( strcmp( p, "mtu" ) == 0 )
-        {
-            opt.mtu = atoi( q );
-            if( opt.mtu < 0 || opt.mtu > MAX_MSG_SIZE )
-                exit_usage( p, q );
-        }
-        else if( strcmp( p, "bad_ad" ) == 0 )
-        {
-            opt.bad_ad = atoi( q );
-            if( opt.bad_ad < 0 || opt.bad_ad > 1 )
-                exit_usage( p, q );
-        }
-#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
-        else if( strcmp( p, "bad_cid" ) == 0 )
-        {
-            opt.bad_cid = (unsigned) atoi( q );
-        }
-#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
-        else if( strcmp( p, "protect_hvr" ) == 0 )
-        {
-            opt.protect_hvr = atoi( q );
-            if( opt.protect_hvr < 0 || opt.protect_hvr > 1 )
-                exit_usage( p, q );
-        }
-        else if( strcmp( p, "protect_len" ) == 0 )
-        {
-            opt.protect_len = atoi( q );
-            if( opt.protect_len < 0 )
-                exit_usage( p, q );
-        }
-        else if( strcmp( p, "inject_clihlo" ) == 0 )
-        {
-            opt.inject_clihlo = atoi( q );
-            if( opt.inject_clihlo < 0 || opt.inject_clihlo > 1 )
-                exit_usage( p, q );
-        }
-        else if( strcmp( p, "seed" ) == 0 )
-        {
-            opt.seed = atoi( q );
-            if( opt.seed == 0 )
-                exit_usage( p, q );
-        }
-        else
-            exit_usage( p, NULL );
+#    endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
+        else if (strcmp(p, "protect_hvr") == 0) {
+            opt.protect_hvr = atoi(q);
+            if (opt.protect_hvr < 0 || opt.protect_hvr > 1)
+                exit_usage(p, q);
+        } else if (strcmp(p, "protect_len") == 0) {
+            opt.protect_len = atoi(q);
+            if (opt.protect_len < 0)
+                exit_usage(p, q);
+        } else if (strcmp(p, "inject_clihlo") == 0) {
+            opt.inject_clihlo = atoi(q);
+            if (opt.inject_clihlo < 0 || opt.inject_clihlo > 1)
+                exit_usage(p, q);
+        } else if (strcmp(p, "seed") == 0) {
+            opt.seed = atoi(q);
+            if (opt.seed == 0)
+                exit_usage(p, q);
+        } else
+            exit_usage(p, NULL);
     }
 }
 
-static const char *msg_type( unsigned char *msg, size_t len )
+static const char *msg_type(unsigned char *msg, size_t len)
 {
-    if( len < 1 )                           return "Invalid" ;
-    switch( msg[0] )
-    {
-        case MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC:    return "ChangeCipherSpec" ;
-        case MBEDTLS_SSL_MSG_ALERT:                 return "Alert" ;
-        case MBEDTLS_SSL_MSG_APPLICATION_DATA:      return "ApplicationData" ;
-        case MBEDTLS_SSL_MSG_CID:                   return "CID" ;
-        case MBEDTLS_SSL_MSG_HANDSHAKE:             break; /* See below */
-        default:                            return "Unknown" ;
+    if (len < 1)
+        return "Invalid";
+    switch (msg[0]) {
+        case MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC:
+            return "ChangeCipherSpec";
+        case MBEDTLS_SSL_MSG_ALERT:
+            return "Alert";
+        case MBEDTLS_SSL_MSG_APPLICATION_DATA:
+            return "ApplicationData";
+        case MBEDTLS_SSL_MSG_CID:
+            return "CID";
+        case MBEDTLS_SSL_MSG_HANDSHAKE:
+            break; /* See below */
+        default:
+            return "Unknown";
     }
 
-    if( len < 13 + 12 )                     return "Invalid handshake" ;
+    if (len < 13 + 12)
+        return "Invalid handshake";
 
     /*
      * Our handshake message are less than 2^16 bytes long, so they should
      * have 0 as the first byte of length, frag_offset and frag_length.
      * Otherwise, assume they are encrypted.
      */
-    if( msg[14] || msg[19] || msg[22] )     return "Encrypted handshake" ;
+    if (msg[14] || msg[19] || msg[22])
+        return "Encrypted handshake";
 
-    switch( msg[13] )
-    {
-        case MBEDTLS_SSL_HS_HELLO_REQUEST:          return "HelloRequest" ;
-        case MBEDTLS_SSL_HS_CLIENT_HELLO:           return "ClientHello" ;
-        case MBEDTLS_SSL_HS_SERVER_HELLO:           return "ServerHello" ;
-        case MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST:   return "HelloVerifyRequest" ;
-        case MBEDTLS_SSL_HS_NEW_SESSION_TICKET:     return "NewSessionTicket" ;
-        case MBEDTLS_SSL_HS_CERTIFICATE:            return "Certificate" ;
-        case MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE:    return "ServerKeyExchange" ;
-        case MBEDTLS_SSL_HS_CERTIFICATE_REQUEST:    return "CertificateRequest" ;
-        case MBEDTLS_SSL_HS_SERVER_HELLO_DONE:      return "ServerHelloDone" ;
-        case MBEDTLS_SSL_HS_CERTIFICATE_VERIFY:     return "CertificateVerify" ;
-        case MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE:    return "ClientKeyExchange" ;
-        case MBEDTLS_SSL_HS_FINISHED:               return "Finished" ;
-        default:                            return "Unknown handshake" ;
+    switch (msg[13]) {
+        case MBEDTLS_SSL_HS_HELLO_REQUEST:
+            return "HelloRequest";
+        case MBEDTLS_SSL_HS_CLIENT_HELLO:
+            return "ClientHello";
+        case MBEDTLS_SSL_HS_SERVER_HELLO:
+            return "ServerHello";
+        case MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST:
+            return "HelloVerifyRequest";
+        case MBEDTLS_SSL_HS_NEW_SESSION_TICKET:
+            return "NewSessionTicket";
+        case MBEDTLS_SSL_HS_CERTIFICATE:
+            return "Certificate";
+        case MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE:
+            return "ServerKeyExchange";
+        case MBEDTLS_SSL_HS_CERTIFICATE_REQUEST:
+            return "CertificateRequest";
+        case MBEDTLS_SSL_HS_SERVER_HELLO_DONE:
+            return "ServerHelloDone";
+        case MBEDTLS_SSL_HS_CERTIFICATE_VERIFY:
+            return "CertificateVerify";
+        case MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE:
+            return "ClientKeyExchange";
+        case MBEDTLS_SSL_HS_FINISHED:
+            return "Finished";
+        default:
+            return "Unknown handshake";
     }
 }
 
-#if defined(MBEDTLS_TIMING_C)
+#    if defined(MBEDTLS_TIMING_C)
 /* Return elapsed time in milliseconds since the first call */
-static unsigned ellapsed_time( void )
+static unsigned ellapsed_time(void)
 {
     static int initialized = 0;
     static struct mbedtls_timing_hr_time hires;
 
-    if( initialized == 0 )
-    {
-        (void) mbedtls_timing_get_timer( &hires, 1 );
+    if (initialized == 0) {
+        (void)mbedtls_timing_get_timer(&hires, 1);
         initialized = 1;
-        return 0 ;
+        return 0;
     }
 
-    return mbedtls_timing_get_timer( &hires, 0 ) ;
+    return mbedtls_timing_get_timer(&hires, 0);
 }
 
-typedef struct
-{
+typedef struct {
     mbedtls_net_context *ctx;
 
     const char *description;
@@ -403,102 +389,94 @@
 
 static ctx_buffer outbuf[2];
 
-static int ctx_buffer_flush( ctx_buffer *buf )
+static int ctx_buffer_flush(ctx_buffer *buf)
 {
     int ret;
 
-    mbedtls_printf( "  %05u flush    %s: %u bytes, %u datagrams, last %u ms\n",
-                    ellapsed_time(), buf->description,
-                    (unsigned) buf->len, buf->num_datagrams,
-                    ellapsed_time() - buf->packet_lifetime );
+    mbedtls_printf("  %05u flush    %s: %u bytes, %u datagrams, last %u ms\n",
+                   ellapsed_time(), buf->description, (unsigned)buf->len,
+                   buf->num_datagrams, ellapsed_time() - buf->packet_lifetime);
 
-    ret = mbedtls_net_send( buf->ctx, buf->data, buf->len );
+    ret = mbedtls_net_send(buf->ctx, buf->data, buf->len);
 
-    buf->len           = 0;
+    buf->len = 0;
     buf->num_datagrams = 0;
 
-    return ret ;
+    return ret;
 }
 
-static unsigned ctx_buffer_time_remaining( ctx_buffer *buf )
+static unsigned ctx_buffer_time_remaining(ctx_buffer *buf)
 {
     unsigned const cur_time = ellapsed_time();
 
-    if( buf->num_datagrams == 0 )
-        return (unsigned) -1 ;
+    if (buf->num_datagrams == 0)
+        return (unsigned)-1;
 
-    if( cur_time - buf->packet_lifetime >= opt.pack )
-        return 0 ;
+    if (cur_time - buf->packet_lifetime >= opt.pack)
+        return 0;
 
-    return opt.pack - ( cur_time - buf->packet_lifetime ) ;
+    return opt.pack - (cur_time - buf->packet_lifetime);
 }
 
-static int ctx_buffer_append( ctx_buffer *buf,
-                              const unsigned char * data,
-                              size_t len )
+static int
+ctx_buffer_append(ctx_buffer *buf, const unsigned char *data, size_t len)
 {
     int ret;
 
-    if( len > (size_t) INT_MAX )
-        return -1 ;
+    if (len > (size_t)INT_MAX)
+        return -1;
 
-    if( len > sizeof( buf->data ) )
-    {
-        mbedtls_printf( "  ! buffer size %u too large (max %u)\n",
-                        (unsigned) len, (unsigned) sizeof( buf->data ) );
-        return -1 ;
+    if (len > sizeof(buf->data)) {
+        mbedtls_printf("  ! buffer size %u too large (max %u)\n", (unsigned)len,
+                       (unsigned)sizeof(buf->data));
+        return -1;
     }
 
-    if( sizeof( buf->data ) - buf->len < len )
-    {
-        if( ( ret = ctx_buffer_flush( buf ) ) <= 0 )
-        {
-            mbedtls_printf( "ctx_buffer_flush failed with -%#04x", (unsigned int) -ret );
-            return ret ;
+    if (sizeof(buf->data) - buf->len < len) {
+        if ((ret = ctx_buffer_flush(buf)) <= 0) {
+            mbedtls_printf("ctx_buffer_flush failed with -%#04x",
+                           (unsigned int)-ret);
+            return ret;
         }
     }
 
-    memcpy( buf->data + buf->len, data, len );
+    memcpy(buf->data + buf->len, data, len);
 
     buf->len += len;
-    if( ++buf->num_datagrams == 1 )
+    if (++buf->num_datagrams == 1)
         buf->packet_lifetime = ellapsed_time();
 
-    return (int) len ;
+    return (int)len;
 }
-#endif /* MBEDTLS_TIMING_C */
+#    endif /* MBEDTLS_TIMING_C */
 
-static int dispatch_data( mbedtls_net_context *ctx,
-                          const unsigned char * data,
-                          size_t len )
+static int
+dispatch_data(mbedtls_net_context *ctx, const unsigned char *data, size_t len)
 {
     int ret;
-#if defined(MBEDTLS_TIMING_C)
+#    if defined(MBEDTLS_TIMING_C)
     ctx_buffer *buf = NULL;
-    if( opt.pack > 0 )
-    {
-        if( outbuf[0].ctx == ctx )
+    if (opt.pack > 0) {
+        if (outbuf[0].ctx == ctx)
             buf = &outbuf[0];
-        else if( outbuf[1].ctx == ctx )
+        else if (outbuf[1].ctx == ctx)
             buf = &outbuf[1];
 
-        if( buf == NULL )
-            return -1 ;
+        if (buf == NULL)
+            return -1;
 
-        return ctx_buffer_append( buf, data, len ) ;
+        return ctx_buffer_append(buf, data, len);
     }
-#endif /* MBEDTLS_TIMING_C */
+#    endif /* MBEDTLS_TIMING_C */
 
-    ret = mbedtls_net_send( ctx, data, len );
-    if( ret < 0 )
-    {
-        mbedtls_printf( "net_send returned -%#04x\n", (unsigned int) -ret );
+    ret = mbedtls_net_send(ctx, data, len);
+    if (ret < 0) {
+        mbedtls_printf("net_send returned -%#04x\n", (unsigned int)-ret);
     }
-    return ret ;
+    return ret;
 }
 
-typedef struct
-{
+typedef struct {
     mbedtls_net_context *dst;
     const char *way;
     const char *type;
@@ -507,25 +485,25 @@
 } packet;
 
 /* Print packet. Outgoing packets come with a reason (forward, dupl, etc.) */
-void print_packet( const packet *p, const char *why )
+void print_packet(const packet *p, const char *why)
 {
-#if defined(MBEDTLS_TIMING_C)
-    if( why == NULL )
-        mbedtls_printf( "  %05u dispatch %s %s (%u bytes)\n",
-                ellapsed_time(), p->way, p->type, p->len );
+#    if defined(MBEDTLS_TIMING_C)
+    if (why == NULL)
+        mbedtls_printf("  %05u dispatch %s %s (%u bytes)\n", ellapsed_time(),
+                       p->way, p->type, p->len);
     else
-        mbedtls_printf( "  %05u dispatch %s %s (%u bytes): %s\n",
-                ellapsed_time(), p->way, p->type, p->len, why );
-#else
-    if( why == NULL )
-        mbedtls_printf( "        dispatch %s %s (%u bytes)\n",
-                p->way, p->type, p->len );
+        mbedtls_printf("  %05u dispatch %s %s (%u bytes): %s\n",
+                       ellapsed_time(), p->way, p->type, p->len, why);
+#    else
+    if (why == NULL)
+        mbedtls_printf("        dispatch %s %s (%u bytes)\n", p->way, p->type,
+                       p->len);
     else
-        mbedtls_printf( "        dispatch %s %s (%u bytes): %s\n",
-                p->way, p->type, p->len, why );
-#endif
+        mbedtls_printf("        dispatch %s %s (%u bytes): %s\n", p->way,
+                       p->type, p->len, why);
+#    endif
 
-    fflush( stdout );
+    fflush(stdout);
 }
 
 /*
@@ -540,144 +518,126 @@
  *
  * We want an explicit state and a place to store the packet.
  */
-typedef enum {
-    ICH_INIT,       /* haven't seen the first ClientHello yet */
-    ICH_CACHED,     /* cached the initial ClientHello */
-    ICH_INJECTED,   /* ClientHello already injected, done */
+typedef enum
+{
+    ICH_INIT, /* haven't seen the first ClientHello yet */
+    ICH_CACHED, /* cached the initial ClientHello */
+    ICH_INJECTED, /* ClientHello already injected, done */
 } inject_clihlo_state_t;
 
 static inject_clihlo_state_t inject_clihlo_state;
 static packet initial_clihlo;
 
-int send_packet( const packet *p, const char *why )
+int send_packet(const packet *p, const char *why)
 {
     int ret;
     mbedtls_net_context *dst = p->dst;
 
     /* save initial ClientHello? */
-    if( opt.inject_clihlo != 0 &&
-        inject_clihlo_state == ICH_INIT &&
-        strcmp( p->type, "ClientHello" ) == 0 )
-    {
-        memcpy( &initial_clihlo, p, sizeof( packet ) );
+    if (opt.inject_clihlo != 0 && inject_clihlo_state == ICH_INIT &&
+        strcmp(p->type, "ClientHello") == 0) {
+        memcpy(&initial_clihlo, p, sizeof(packet));
         inject_clihlo_state = ICH_CACHED;
     }
 
     /* insert corrupted CID record? */
-    if( opt.bad_cid != 0 &&
-        strcmp( p->type, "CID" ) == 0 &&
-        ( rand() % opt.bad_cid ) == 0 )
-    {
+    if (opt.bad_cid != 0 && strcmp(p->type, "CID") == 0 &&
+        (rand() % opt.bad_cid) == 0) {
         unsigned char buf[MAX_MSG_SIZE];
-        memcpy( buf, p->buf, p->len );
+        memcpy(buf, p->buf, p->len);
 
         /* The CID resides at offset 11 in the DTLS record header. */
         buf[11] ^= 1;
-        print_packet( p, "modified CID" );
+        print_packet(p, "modified CID");
 
-        if( ( ret = dispatch_data( dst, buf, p->len ) ) <= 0 )
-        {
-            mbedtls_printf( "  ! dispatch returned %d\n", ret );
-            return ret ;
+        if ((ret = dispatch_data(dst, buf, p->len)) <= 0) {
+            mbedtls_printf("  ! dispatch returned %d\n", ret);
+            return ret;
         }
     }
 
     /* insert corrupted ApplicationData record? */
-    if( opt.bad_ad &&
-        strcmp( p->type, "ApplicationData" ) == 0 )
-    {
+    if (opt.bad_ad && strcmp(p->type, "ApplicationData") == 0) {
         unsigned char buf[MAX_MSG_SIZE];
-        memcpy( buf, p->buf, p->len );
+        memcpy(buf, p->buf, p->len);
 
-        if( p->len <= 13 )
-        {
-            mbedtls_printf( "  ! can't corrupt empty AD record" );
-        }
-        else
-        {
+        if (p->len <= 13) {
+            mbedtls_printf("  ! can't corrupt empty AD record");
+        } else {
             ++buf[13];
-            print_packet( p, "corrupted" );
+            print_packet(p, "corrupted");
         }
 
-        if( ( ret = dispatch_data( dst, buf, p->len ) ) <= 0 )
-        {
-            mbedtls_printf( "  ! dispatch returned %d\n", ret );
-            return ret ;
+        if ((ret = dispatch_data(dst, buf, p->len)) <= 0) {
+            mbedtls_printf("  ! dispatch returned %d\n", ret);
+            return ret;
         }
     }
 
-    print_packet( p, why );
-    if( ( ret = dispatch_data( dst, p->buf, p->len ) ) <= 0 )
-    {
-        mbedtls_printf( "  ! dispatch returned %d\n", ret );
-        return ret ;
+    print_packet(p, why);
+    if ((ret = dispatch_data(dst, p->buf, p->len)) <= 0) {
+        mbedtls_printf("  ! dispatch returned %d\n", ret);
+        return ret;
     }
 
     /* Don't duplicate Application Data, only handshake covered */
-    if( opt.duplicate != 0 &&
-        strcmp( p->type, "ApplicationData" ) != 0 &&
-        rand() % opt.duplicate == 0 )
-    {
-        print_packet( p, "duplicated" );
+    if (opt.duplicate != 0 && strcmp(p->type, "ApplicationData") != 0 &&
+        rand() % opt.duplicate == 0) {
+        print_packet(p, "duplicated");
 
-        if( ( ret = dispatch_data( dst, p->buf, p->len ) ) <= 0 )
-        {
-            mbedtls_printf( "  ! dispatch returned %d\n", ret );
-            return ret ;
+        if ((ret = dispatch_data(dst, p->buf, p->len)) <= 0) {
+            mbedtls_printf("  ! dispatch returned %d\n", ret);
+            return ret;
         }
     }
 
     /* Inject ClientHello after first ApplicationData */
-    if( opt.inject_clihlo != 0 &&
-        inject_clihlo_state == ICH_CACHED &&
-        strcmp( p->type, "ApplicationData" ) == 0 )
-    {
-        print_packet( &initial_clihlo, "injected" );
+    if (opt.inject_clihlo != 0 && inject_clihlo_state == ICH_CACHED &&
+        strcmp(p->type, "ApplicationData") == 0) {
+        print_packet(&initial_clihlo, "injected");
 
-        if( ( ret = dispatch_data( dst, initial_clihlo.buf,
-                                        initial_clihlo.len ) ) <= 0 )
-        {
-            mbedtls_printf( "  ! dispatch returned %d\n", ret );
-            return ret ;
+        if ((ret = dispatch_data(dst, initial_clihlo.buf,
+                                 initial_clihlo.len)) <= 0) {
+            mbedtls_printf("  ! dispatch returned %d\n", ret);
+            return ret;
         }
 
         inject_clihlo_state = ICH_INJECTED;
     }
 
-    return 0 ;
+    return 0;
 }
 
-#define MAX_DELAYED_MSG 5
+#    define MAX_DELAYED_MSG 5
 static size_t prev_len;
 static packet prev[MAX_DELAYED_MSG];
 
-void clear_pending( void )
+void clear_pending(void)
 {
-    memset( &prev, 0, sizeof( prev ) );
+    memset(&prev, 0, sizeof(prev));
     prev_len = 0;
 }
 
-void delay_packet( packet *delay )
+void delay_packet(packet *delay)
 {
-    if( prev_len == MAX_DELAYED_MSG )
+    if (prev_len == MAX_DELAYED_MSG)
         return;
 
-    memcpy( &prev[prev_len++], delay, sizeof( packet ) );
+    memcpy(&prev[prev_len++], delay, sizeof(packet));
 }
 
 int send_delayed()
 {
     uint8_t offset;
     int ret;
-    for( offset = 0; offset < prev_len; offset++ )
-    {
-        ret = send_packet( &prev[offset], "delayed" );
-        if( ret != 0 )
-            return ret ;
+    for (offset = 0; offset < prev_len; offset++) {
+        ret = send_packet(&prev[offset], "delayed");
+        if (ret != 0)
+            return ret;
     }
 
     clear_pending();
-    return 0 ;
+    return 0;
 }
 
 /*
@@ -695,110 +655,93 @@
  * HOLD_MAX + 1 times.
  */
 static unsigned char held[2048] = { 0 };
-#define HOLD_MAX 2
+#    define HOLD_MAX        2
 
-int handle_message( const char *way,
-                    mbedtls_net_context *dst,
-                    mbedtls_net_context *src )
+int handle_message(const char *way,
+                   mbedtls_net_context *dst,
+                   mbedtls_net_context *src)
 {
     int ret;
     packet cur;
     size_t id;
 
     uint8_t delay_idx;
-    char ** delay_list;
+    char **delay_list;
     uint8_t delay_list_len;
 
     /* receive packet */
-    if( ( ret = mbedtls_net_recv( src, cur.buf, sizeof( cur.buf ) ) ) <= 0 )
-    {
-        mbedtls_printf( "  ! mbedtls_net_recv returned %d\n", ret );
-        return ret ;
+    if ((ret = mbedtls_net_recv(src, cur.buf, sizeof(cur.buf))) <= 0) {
+        mbedtls_printf("  ! mbedtls_net_recv returned %d\n", ret);
+        return ret;
     }
 
-    cur.len  = ret;
-    cur.type = msg_type( cur.buf, cur.len );
-    cur.way  = way;
-    cur.dst  = dst;
-    print_packet( &cur, NULL );
+    cur.len = ret;
+    cur.type = msg_type(cur.buf, cur.len);
+    cur.way = way;
+    cur.dst = dst;
+    print_packet(&cur, NULL);
 
-    id = cur.len % sizeof( held );
+    id = cur.len % sizeof(held);
 
-    if( strcmp( way, "S <- C" ) == 0 )
-    {
-        delay_list     = opt.delay_cli;
+    if (strcmp(way, "S <- C") == 0) {
+        delay_list = opt.delay_cli;
         delay_list_len = opt.delay_cli_cnt;
-    }
-    else
-    {
-        delay_list     = opt.delay_srv;
+    } else {
+        delay_list = opt.delay_srv;
         delay_list_len = opt.delay_srv_cnt;
     }
 
     /* Check if message type is in the list of messages
      * that should be delayed */
-    for( delay_idx = 0; delay_idx < delay_list_len; delay_idx++ )
-    {
-        if( delay_list[ delay_idx ] == NULL )
+    for (delay_idx = 0; delay_idx < delay_list_len; delay_idx++) {
+        if (delay_list[delay_idx] == NULL)
             continue;
 
-        if( strcmp( delay_list[ delay_idx ], cur.type ) == 0 )
-        {
+        if (strcmp(delay_list[delay_idx], cur.type) == 0) {
             /* Delay message */
-            delay_packet( &cur );
+            delay_packet(&cur);
 
             /* Remove entry from list */
-            mbedtls_free( delay_list[delay_idx] );
+            mbedtls_free(delay_list[delay_idx]);
             delay_list[delay_idx] = NULL;
 
-            return 0 ;
+            return 0;
         }
     }
 
     /* do we want to drop, delay, or forward it? */
-    if( ( opt.mtu != 0 &&
-          cur.len > (unsigned) opt.mtu ) ||
-        ( opt.drop != 0 &&
-          strcmp( cur.type, "CID" ) != 0             &&
-          strcmp( cur.type, "ApplicationData" ) != 0 &&
-          ! ( opt.protect_hvr &&
-              strcmp( cur.type, "HelloVerifyRequest" ) == 0 ) &&
-          cur.len != (size_t) opt.protect_len &&
-          held[id] < HOLD_MAX &&
-          rand() % opt.drop == 0 ) )
-    {
+    if ((opt.mtu != 0 && cur.len > (unsigned)opt.mtu) ||
+        (opt.drop != 0 && strcmp(cur.type, "CID") != 0 &&
+         strcmp(cur.type, "ApplicationData") != 0 &&
+         !(opt.protect_hvr && strcmp(cur.type, "HelloVerifyRequest") == 0) &&
+         cur.len != (size_t)opt.protect_len && held[id] < HOLD_MAX &&
+         rand() % opt.drop == 0)) {
         ++held[id];
-    }
-    else if( ( opt.delay_ccs == 1 &&
-               strcmp( cur.type, "ChangeCipherSpec" ) == 0 ) ||
-             ( opt.delay != 0 &&
-               strcmp( cur.type, "CID" ) != 0             &&
-               strcmp( cur.type, "ApplicationData" ) != 0 &&
-               ! ( opt.protect_hvr &&
-                   strcmp( cur.type, "HelloVerifyRequest" ) == 0 ) &&
-               cur.len != (size_t) opt.protect_len &&
-               held[id] < HOLD_MAX &&
-               rand() % opt.delay == 0 ) )
-    {
+    } else if ((opt.delay_ccs == 1 &&
+                strcmp(cur.type, "ChangeCipherSpec") == 0) ||
+               (opt.delay != 0 && strcmp(cur.type, "CID") != 0 &&
+                strcmp(cur.type, "ApplicationData") != 0 &&
+                !(opt.protect_hvr &&
+                  strcmp(cur.type, "HelloVerifyRequest") == 0) &&
+                cur.len != (size_t)opt.protect_len && held[id] < HOLD_MAX &&
+                rand() % opt.delay == 0)) {
         ++held[id];
-        delay_packet( &cur );
-    }
-    else
-    {
+        delay_packet(&cur);
+    } else {
         /* forward and possibly duplicate */
-        if( ( ret = send_packet( &cur, "forwarded" ) ) != 0 )
-            return ret ;
+        if ((ret = send_packet(&cur, "forwarded")) != 0)
+            return ret;
 
         /* send previously delayed messages if any */
         ret = send_delayed();
-        if( ret != 0 )
-            return ret ;
+        if (ret != 0)
+            return ret;
     }
 
-    return 0 ;
+    return 0;
 }
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int ret = 1;
     int exit_code = MBEDTLS_EXIT_FAILURE;
@@ -806,20 +749,20 @@
 
     mbedtls_net_context listen_fd, client_fd, server_fd;
 
-#if defined( MBEDTLS_TIMING_C )
+#    if defined(MBEDTLS_TIMING_C)
     struct timeval tm;
-#endif
+#    endif
 
     struct timeval *tm_ptr = NULL;
 
     int nb_fds;
     fd_set read_fds;
 
-    mbedtls_net_init( &listen_fd );
-    mbedtls_net_init( &client_fd );
-    mbedtls_net_init( &server_fd );
+    mbedtls_net_init(&listen_fd);
+    mbedtls_net_init(&client_fd);
+    mbedtls_net_init(&server_fd);
 
-    get_options( argc, argv );
+    get_options(argc, argv);
 
     /*
      * Decisions to drop/delay/duplicate packets are pseudo-random: dropping
@@ -829,80 +772,75 @@
      * In order to be able to reproduce problems reliably, the seed may be
      * specified explicitly.
      */
-    if( opt.seed == 0 )
-    {
-        opt.seed = (unsigned int) time( NULL );
-        mbedtls_printf( "  . Pseudo-random seed: %u\n", opt.seed );
+    if (opt.seed == 0) {
+        opt.seed = (unsigned int)time(NULL);
+        mbedtls_printf("  . Pseudo-random seed: %u\n", opt.seed);
     }
 
-    srand( opt.seed );
+    srand(opt.seed);
 
     /*
      * 0. "Connect" to the server
      */
-    mbedtls_printf( "  . Connect to server on UDP/%s/%s ...",
-            opt.server_addr, opt.server_port );
-    fflush( stdout );
+    mbedtls_printf("  . Connect to server on UDP/%s/%s ...", opt.server_addr,
+                   opt.server_port);
+    fflush(stdout);
 
-    if( ( ret = mbedtls_net_connect( &server_fd, opt.server_addr, opt.server_port,
-                             MBEDTLS_NET_PROTO_UDP ) ) != 0 )
-    {
-        mbedtls_printf( " failed\n  ! mbedtls_net_connect returned %d\n\n", ret );
+    if ((ret = mbedtls_net_connect(&server_fd, opt.server_addr, opt.server_port,
+                                   MBEDTLS_NET_PROTO_UDP)) != 0) {
+        mbedtls_printf(" failed\n  ! mbedtls_net_connect returned %d\n\n", ret);
         goto exit;
     }
 
-    mbedtls_printf( " ok\n" );
+    mbedtls_printf(" ok\n");
 
     /*
      * 1. Setup the "listening" UDP socket
      */
-    mbedtls_printf( "  . Bind on UDP/%s/%s ...",
-            opt.listen_addr, opt.listen_port );
-    fflush( stdout );
+    mbedtls_printf("  . Bind on UDP/%s/%s ...", opt.listen_addr,
+                   opt.listen_port);
+    fflush(stdout);
 
-    if( ( ret = mbedtls_net_bind( &listen_fd, opt.listen_addr, opt.listen_port,
-                          MBEDTLS_NET_PROTO_UDP ) ) != 0 )
-    {
-        mbedtls_printf( " failed\n  ! mbedtls_net_bind returned %d\n\n", ret );
+    if ((ret = mbedtls_net_bind(&listen_fd, opt.listen_addr, opt.listen_port,
+                                MBEDTLS_NET_PROTO_UDP)) != 0) {
+        mbedtls_printf(" failed\n  ! mbedtls_net_bind returned %d\n\n", ret);
         goto exit;
     }
 
-    mbedtls_printf( " ok\n" );
+    mbedtls_printf(" ok\n");
 
     /*
      * 2. Wait until a client connects
      */
 accept:
-    mbedtls_net_free( &client_fd );
+    mbedtls_net_free(&client_fd);
 
-    mbedtls_printf( "  . Waiting for a remote connection ..." );
-    fflush( stdout );
+    mbedtls_printf("  . Waiting for a remote connection ...");
+    fflush(stdout);
 
-    if( ( ret = mbedtls_net_accept( &listen_fd, &client_fd,
-                                    NULL, 0, NULL ) ) != 0 )
-    {
-        mbedtls_printf( " failed\n  ! mbedtls_net_accept returned %d\n\n", ret );
+    if ((ret = mbedtls_net_accept(&listen_fd, &client_fd, NULL, 0, NULL)) !=
+        0) {
+        mbedtls_printf(" failed\n  ! mbedtls_net_accept returned %d\n\n", ret);
         goto exit;
     }
 
-    mbedtls_printf( " ok\n" );
+    mbedtls_printf(" ok\n");
 
     /*
      * 3. Forward packets forever (kill the process to terminate it)
      */
     clear_pending();
-    memset( held, 0, sizeof( held ) );
+    memset(held, 0, sizeof(held));
 
     nb_fds = client_fd.fd;
-    if( nb_fds < server_fd.fd )
+    if (nb_fds < server_fd.fd)
         nb_fds = server_fd.fd;
-    if( nb_fds < listen_fd.fd )
+    if (nb_fds < listen_fd.fd)
         nb_fds = listen_fd.fd;
     ++nb_fds;
 
-#if defined(MBEDTLS_TIMING_C)
-    if( opt.pack > 0 )
-    {
+#    if defined(MBEDTLS_TIMING_C)
+    if (opt.pack > 0) {
         outbuf[0].ctx = &server_fd;
         outbuf[0].description = "S <- C";
         outbuf[0].num_datagrams = 0;
@@ -913,106 +851,94 @@
         outbuf[1].num_datagrams = 0;
         outbuf[1].len = 0;
     }
-#endif /* MBEDTLS_TIMING_C */
+#    endif /* MBEDTLS_TIMING_C */
 
-    while( 1 )
-    {
-#if defined(MBEDTLS_TIMING_C)
-        if( opt.pack > 0 )
-        {
+    while (1) {
+#    if defined(MBEDTLS_TIMING_C)
+        if (opt.pack > 0) {
             unsigned max_wait_server, max_wait_client, max_wait;
-            max_wait_server = ctx_buffer_time_remaining( &outbuf[0] );
-            max_wait_client = ctx_buffer_time_remaining( &outbuf[1] );
+            max_wait_server = ctx_buffer_time_remaining(&outbuf[0]);
+            max_wait_client = ctx_buffer_time_remaining(&outbuf[1]);
 
-            max_wait = (unsigned) -1;
+            max_wait = (unsigned)-1;
 
-            if( max_wait_server == 0 )
-                ctx_buffer_flush( &outbuf[0] );
+            if (max_wait_server == 0)
+                ctx_buffer_flush(&outbuf[0]);
             else
                 max_wait = max_wait_server;
 
-            if( max_wait_client == 0 )
-                ctx_buffer_flush( &outbuf[1] );
-            else
-            {
-                if( max_wait_client < max_wait )
+            if (max_wait_client == 0)
+                ctx_buffer_flush(&outbuf[1]);
+            else {
+                if (max_wait_client < max_wait)
                     max_wait = max_wait_client;
             }
 
-            if( max_wait != (unsigned) -1 )
-            {
-                tm.tv_sec  = max_wait / 1000;
-                tm.tv_usec = ( max_wait % 1000 ) * 1000;
+            if (max_wait != (unsigned)-1) {
+                tm.tv_sec = max_wait / 1000;
+                tm.tv_usec = (max_wait % 1000) * 1000;
 
                 tm_ptr = &tm;
-            }
-            else
-            {
+            } else {
                 tm_ptr = NULL;
             }
         }
-#endif /* MBEDTLS_TIMING_C */
+#    endif /* MBEDTLS_TIMING_C */
 
-        FD_ZERO( &read_fds );
-        FD_SET( server_fd.fd, &read_fds );
-        FD_SET( client_fd.fd, &read_fds );
-        FD_SET( listen_fd.fd, &read_fds );
+        FD_ZERO(&read_fds);
+        FD_SET(server_fd.fd, &read_fds);
+        FD_SET(client_fd.fd, &read_fds);
+        FD_SET(listen_fd.fd, &read_fds);
 
-        if( ( ret = select( nb_fds, &read_fds, NULL, NULL, tm_ptr ) ) < 0 )
-        {
-            perror( "select" );
+        if ((ret = select(nb_fds, &read_fds, NULL, NULL, tm_ptr)) < 0) {
+            perror("select");
             goto exit;
         }
 
-        if( FD_ISSET( listen_fd.fd, &read_fds ) )
+        if (FD_ISSET(listen_fd.fd, &read_fds))
             goto accept;
 
-        if( FD_ISSET( client_fd.fd, &read_fds ) )
-        {
-            if( ( ret = handle_message( "S <- C",
-                                        &server_fd, &client_fd ) ) != 0 )
+        if (FD_ISSET(client_fd.fd, &read_fds)) {
+            if ((ret = handle_message("S <- C", &server_fd, &client_fd)) != 0)
                 goto accept;
         }
 
-        if( FD_ISSET( server_fd.fd, &read_fds ) )
-        {
-            if( ( ret = handle_message( "S -> C",
-                                        &client_fd, &server_fd ) ) != 0 )
+        if (FD_ISSET(server_fd.fd, &read_fds)) {
+            if ((ret = handle_message("S -> C", &client_fd, &server_fd)) != 0)
                 goto accept;
         }
-
     }
 
     exit_code = MBEDTLS_EXIT_SUCCESS;
 
 exit:
 
-#ifdef MBEDTLS_ERROR_C
-    if( exit_code != MBEDTLS_EXIT_SUCCESS )
-    {
+#    ifdef MBEDTLS_ERROR_C
+    if (exit_code != MBEDTLS_EXIT_SUCCESS) {
         char error_buf[100];
-        mbedtls_strerror( ret, error_buf, 100 );
-        mbedtls_printf( "Last error was: -0x%04X - %s\n\n", (unsigned int) -ret, error_buf );
-        fflush( stdout );
+        mbedtls_strerror(ret, error_buf, 100);
+        mbedtls_printf("Last error was: -0x%04X - %s\n\n", (unsigned int)-ret,
+                       error_buf);
+        fflush(stdout);
     }
-#endif
+#    endif
 
-    for( delay_idx = 0; delay_idx < MAX_DELAYED_HS; delay_idx++ )
-    {
-        mbedtls_free( opt.delay_cli[delay_idx] );
-        mbedtls_free( opt.delay_srv[delay_idx] );
+    for (delay_idx = 0; delay_idx < MAX_DELAYED_HS; delay_idx++) {
+        mbedtls_free(opt.delay_cli[delay_idx]);
+        mbedtls_free(opt.delay_srv[delay_idx]);
     }
 
-    mbedtls_net_free( &client_fd );
-    mbedtls_net_free( &server_fd );
-    mbedtls_net_free( &listen_fd );
+    mbedtls_net_free(&client_fd);
+    mbedtls_net_free(&server_fd);
+    mbedtls_net_free(&listen_fd);
 
-#if defined(_WIN32)
-    mbedtls_printf( "  Press Enter to exit this program.\n" );
-    fflush( stdout ); getchar();
-#endif
+#    if defined(_WIN32)
+    mbedtls_printf("  Press Enter to exit this program.\n");
+    fflush(stdout);
+    getchar();
+#    endif
 
-    mbedtls_exit( exit_code );
+    mbedtls_exit(exit_code);
 }
 
 #endif /* MBEDTLS_NET_C */
diff --git a/programs/test/zeroize.c b/programs/test/zeroize.c
index a44099d..8ff3d49 100644
--- a/programs/test/zeroize.c
+++ b/programs/test/zeroize.c
@@ -30,29 +30,29 @@
 #include <stdio.h>
 
 #if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
+#    include "mbedtls/platform.h"
 #else
-#include <stdlib.h>
-#define mbedtls_printf     printf
-#define mbedtls_exit       exit
-#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
-#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
+#    include <stdlib.h>
+#    define mbedtls_printf       printf
+#    define mbedtls_exit         exit
+#    define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
+#    define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
 #endif
 
 #include "mbedtls/platform_util.h"
 
 #define BUFFER_LEN 1024
 
-void usage( void )
+void usage(void)
 {
-    mbedtls_printf( "Zeroize is a simple program to assist with testing\n" );
-    mbedtls_printf( "the mbedtls_platform_zeroize() function by using the\n" );
-    mbedtls_printf( "debugger. This program takes a file as input and\n" );
-    mbedtls_printf( "prints the first %d characters. Usage:\n\n", BUFFER_LEN );
-    mbedtls_printf( "       zeroize <FILE>\n" );
+    mbedtls_printf("Zeroize is a simple program to assist with testing\n");
+    mbedtls_printf("the mbedtls_platform_zeroize() function by using the\n");
+    mbedtls_printf("debugger. This program takes a file as input and\n");
+    mbedtls_printf("prints the first %d characters. Usage:\n\n", BUFFER_LEN);
+    mbedtls_printf("       zeroize <FILE>\n");
 }
 
-int main( int argc, char** argv )
+int main(int argc, char **argv)
 {
     int exit_code = MBEDTLS_EXIT_FAILURE;
     FILE *fp;
@@ -61,34 +61,30 @@
     char *end = p + BUFFER_LEN;
     int c;
 
-    if( argc != 2 )
-    {
-        mbedtls_printf( "This program takes exactly 1 agument\n" );
+    if (argc != 2) {
+        mbedtls_printf("This program takes exactly 1 agument\n");
         usage();
-        mbedtls_exit( exit_code );
+        mbedtls_exit(exit_code);
     }
 
-    fp = fopen( argv[1], "r" );
-    if( fp == NULL )
-    {
-        mbedtls_printf( "Could not open file '%s'\n", argv[1] );
-        mbedtls_exit( exit_code );
+    fp = fopen(argv[1], "r");
+    if (fp == NULL) {
+        mbedtls_printf("Could not open file '%s'\n", argv[1]);
+        mbedtls_exit(exit_code);
     }
 
-    while( ( c = fgetc( fp ) ) != EOF && p < end - 1 )
+    while ((c = fgetc(fp)) != EOF && p < end - 1)
         *p++ = (char)c;
     *p = '\0';
 
-    if( p - buf != 0 )
-    {
-        mbedtls_printf( "%s\n", buf );
+    if (p - buf != 0) {
+        mbedtls_printf("%s\n", buf);
         exit_code = MBEDTLS_EXIT_SUCCESS;
-    }
-    else
-        mbedtls_printf( "The file is empty!\n" );
+    } else
+        mbedtls_printf("The file is empty!\n");
 
-    fclose( fp );
-    mbedtls_platform_zeroize( buf, sizeof( buf ) );
+    fclose(fp);
+    mbedtls_platform_zeroize(buf, sizeof(buf));
 
-    mbedtls_exit( exit_code ); // GDB_BREAK_HERE -- don't remove this comment!
+    mbedtls_exit(exit_code); // GDB_BREAK_HERE -- don't remove this comment!
 }