| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 1 | #!/bin/sh | 
|  | 2 |  | 
| Paul Bakker | 6152b02 | 2015-04-14 15:00:09 +0200 | [diff] [blame] | 3 | # Measure heap usage (and performance) of ECC operations with various values of | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 4 | # the relevant tunable compile-time parameters. | 
| Manuel Pégourié-Gonnard | 8b7d7d6 | 2015-02-05 10:00:30 +0000 | [diff] [blame] | 5 | # | 
|  | 6 | # Usage (preferably on a 32-bit platform): | 
|  | 7 | # cmake -D CMAKE_BUILD_TYPE=Release . | 
|  | 8 | # scripts/ecc-heap.sh | tee ecc-heap.log | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 9 |  | 
|  | 10 | set -eu | 
|  | 11 |  | 
| Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 12 | CONFIG_H='include/mbedtls/config.h' | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 13 |  | 
|  | 14 | if [ -r $CONFIG_H ]; then :; else | 
|  | 15 | echo "$CONFIG_H not found" >&2 | 
|  | 16 | exit 1 | 
|  | 17 | fi | 
|  | 18 |  | 
|  | 19 | if grep -i cmake Makefile >/dev/null; then :; else | 
|  | 20 | echo "Needs Cmake" >&2 | 
|  | 21 | exit 1 | 
|  | 22 | fi | 
|  | 23 |  | 
|  | 24 | if git status | grep -F $CONFIG_H >/dev/null 2>&1; then | 
|  | 25 | echo "config.h not clean" >&2 | 
|  | 26 | exit 1 | 
|  | 27 | fi | 
|  | 28 |  | 
|  | 29 | CONFIG_BAK=${CONFIG_H}.bak | 
|  | 30 | cp $CONFIG_H $CONFIG_BAK | 
|  | 31 |  | 
|  | 32 | cat << EOF >$CONFIG_H | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 33 | #define MBEDTLS_PLATFORM_C | 
|  | 34 | #define MBEDTLS_PLATFORM_MEMORY | 
|  | 35 | #define MBEDTLS_MEMORY_BUFFER_ALLOC_C | 
|  | 36 | #define MBEDTLS_MEMORY_DEBUG | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 37 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 38 | #define MBEDTLS_TIMING_C | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 39 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 40 | #define MBEDTLS_BIGNUM_C | 
|  | 41 | #define MBEDTLS_ECP_C | 
|  | 42 | #define MBEDTLS_ASN1_PARSE_C | 
|  | 43 | #define MBEDTLS_ASN1_WRITE_C | 
|  | 44 | #define MBEDTLS_ECDSA_C | 
|  | 45 | #define MBEDTLS_ECDH_C | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 46 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 47 | #define MBEDTLS_ECP_DP_SECP192R1_ENABLED | 
|  | 48 | #define MBEDTLS_ECP_DP_SECP224R1_ENABLED | 
|  | 49 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED | 
|  | 50 | #define MBEDTLS_ECP_DP_SECP384R1_ENABLED | 
|  | 51 | #define MBEDTLS_ECP_DP_SECP521R1_ENABLED | 
| Manuel Pégourié-Gonnard | 0789433 | 2015-06-23 00:18:41 +0200 | [diff] [blame] | 52 | #define MBEDTLS_ECP_DP_CURVE25519_ENABLED | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 53 |  | 
|  | 54 | #include "check_config.h" | 
|  | 55 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 56 | //#define MBEDTLS_ECP_WINDOW_SIZE            6 | 
|  | 57 | //#define MBEDTLS_ECP_FIXED_POINT_OPTIM      1 | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 58 | EOF | 
|  | 59 |  | 
|  | 60 | for F in 0 1; do | 
|  | 61 | for W in 2 3 4 5 6; do | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | scripts/config.pl set MBEDTLS_ECP_WINDOW_SIZE $W | 
|  | 63 | scripts/config.pl set MBEDTLS_ECP_FIXED_POINT_OPTIM $F | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 64 | make benchmark >/dev/null 2>&1 | 
|  | 65 | echo "fixed point optim = $F, max window size = $W" | 
|  | 66 | echo "--------------------------------------------" | 
|  | 67 | programs/test/benchmark | 
|  | 68 | done | 
|  | 69 | done | 
|  | 70 |  | 
|  | 71 | # cleanup | 
|  | 72 |  | 
|  | 73 | mv $CONFIG_BAK $CONFIG_H | 
|  | 74 | make clean |