mbedtls: add benchmark
authorHauke Mehrtens <hauke@hauke-m.de>
Thu, 31 May 2018 12:05:24 +0000 (14:05 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 20 Oct 2018 17:01:47 +0000 (19:01 +0200)
package/libs/mbedtls/Makefile
package/libs/mbedtls/patches/999-tmp.patch [new file with mode: 0644]

index b775c72a5c3362b7e6886792e17fab0dfcc3a12e..76c1bedd7819a2ca301e18dec0a45ac2b5dadf8c 100644 (file)
@@ -61,6 +61,14 @@ This package contains mbedtls helper programs for private key and
 CSR generation (gen_key, cert_req)
 endef
 
+define Package/mbedtls-benchmark
+$(call Package/mbedtls/Default)
+  SECTION:=utils
+  CATEGORY:=Utilities
+  TITLE+= (benchmark)
+  DEPENDS:=+libmbedtls
+endef
+
 PKG_INSTALL:=1
 
 TARGET_CFLAGS += -ffunction-sections -fdata-sections
@@ -90,5 +98,11 @@ define Package/mbedtls-util/install
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/cert_req $(1)/usr/bin/
 endef
 
+define Package/mbedtls-benchmark/install
+       $(INSTALL_DIR) $(1)/usr/bin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/benchmark $(1)/usr/bin/
+endef
+
 $(eval $(call BuildPackage,libmbedtls))
 $(eval $(call BuildPackage,mbedtls-util))
+$(eval $(call BuildPackage,mbedtls-benchmark))
diff --git a/package/libs/mbedtls/patches/999-tmp.patch b/package/libs/mbedtls/patches/999-tmp.patch
new file mode 100644 (file)
index 0000000..d1b7a3a
--- /dev/null
@@ -0,0 +1,78 @@
+diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c
+index cecf3e36..f756ed39 100644
+--- a/programs/test/benchmark.c
++++ b/programs/test/benchmark.c
+@@ -45,6 +45,10 @@ int main( void )
+ #include <string.h>
+ #include <stdlib.h>
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <fcntl.h>
++#include <unistd.h>
+ #include "mbedtls/timing.h"
+@@ -160,7 +164,7 @@ do {                                                                    \
+                                                                         \
+     mbedtls_printf( HEADER_FORMAT, TITLE );                             \
+     fflush( stdout );                                                   \
+-    mbedtls_set_alarm( 3 );                                             \
++    mbedtls_set_alarm( 10 );                                             \
+                                                                         \
+     ret = 0;                                                            \
+     for( ii = 1; ! mbedtls_timing_alarmed && ! ret ; ii++ )             \
+@@ -174,31 +178,21 @@ do {                                                                    \
+     }                                                                   \
+     else                                                                \
+     {                                                                   \
+-        mbedtls_printf( "%6lu " TYPE "/s", ii / 3 );                    \
++        mbedtls_printf( "%6f " TYPE "/s", ((double)ii) / 10 );                    \
+         MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 );                     \
+         mbedtls_printf( "\n" );                                         \
+     }                                                                   \
+ } while( 0 )
++static int urandom_fd;
++
+ 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;
+-    while( len > 0 )
+-    {
+-        use_len = len;
+-        if( use_len > sizeof(int) )
+-            use_len = sizeof(int);
+-
+-        rnd = rand();
+-        memcpy( output, &rnd, use_len );
+-        output += use_len;
+-        len -= use_len;
+-    }
++    read(urandom_fd, output, len);
+     return( 0 );
+ }
+@@ -308,6 +302,7 @@ int main( int argc, char *argv[] )
+         }
+     }
++    urandom_fd = open("/dev/urandom", O_RDONLY);
+     mbedtls_printf( "\n" );
+ #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
+@@ -639,7 +634,9 @@ int main( int argc, char *argv[] )
+             mbedtls_snprintf( title, sizeof( title ), "RSA-%d", keysize );
+             mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
++printf("before mbedtls_rsa_gen_key\n");
+             mbedtls_rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 );
++printf("after mbedtls_rsa_gen_key\n");
+             TIME_PUBLIC( title, " public",
+                     buf[0] = 0;