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 |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 9 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 10 | # Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 11 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 12 | |
| 13 | set -eu |
| 14 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 15 | CONFIG_H='include/mbedtls/config.h' |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 16 | |
| 17 | if [ -r $CONFIG_H ]; then :; else |
| 18 | echo "$CONFIG_H not found" >&2 |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | if grep -i cmake Makefile >/dev/null; then :; else |
| 23 | echo "Needs Cmake" >&2 |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | if git status | grep -F $CONFIG_H >/dev/null 2>&1; then |
| 28 | echo "config.h not clean" >&2 |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | CONFIG_BAK=${CONFIG_H}.bak |
| 33 | cp $CONFIG_H $CONFIG_BAK |
| 34 | |
| 35 | cat << EOF >$CONFIG_H |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 36 | #define MBEDTLS_PLATFORM_C |
| 37 | #define MBEDTLS_PLATFORM_MEMORY |
| 38 | #define MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 39 | #define MBEDTLS_MEMORY_DEBUG |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 40 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 41 | #define MBEDTLS_TIMING_C |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 42 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 43 | #define MBEDTLS_BIGNUM_C |
| 44 | #define MBEDTLS_ECP_C |
Manuel Pégourié-Gonnard | b9dee21 | 2022-04-15 09:16:33 +0200 | [diff] [blame] | 45 | #define MBEDTLS_ECP_NO_INTERNAL_RNG |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 46 | #define MBEDTLS_ASN1_PARSE_C |
| 47 | #define MBEDTLS_ASN1_WRITE_C |
| 48 | #define MBEDTLS_ECDSA_C |
Manuel Pégourié-Gonnard | 8c683f9 | 2022-01-05 10:09:49 +0100 | [diff] [blame] | 49 | #define MBEDTLS_SHA256_C // ECDSA benchmark needs it |
| 50 | #define MBEDTLS_SHA224_C // SHA256 requires this for now |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 51 | #define MBEDTLS_ECDH_C |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 52 | |
Manuel Pégourié-Gonnard | d021197 | 2022-01-06 12:20:48 +0100 | [diff] [blame] | 53 | // NIST curves >= 256 bits |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 54 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED |
| 55 | #define MBEDTLS_ECP_DP_SECP384R1_ENABLED |
| 56 | #define MBEDTLS_ECP_DP_SECP521R1_ENABLED |
Manuel Pégourié-Gonnard | d021197 | 2022-01-06 12:20:48 +0100 | [diff] [blame] | 57 | // SECP "koblitz-like" curve >= 256 bits |
| 58 | #define MBEDTLS_ECP_DP_SECP256K1_ENABLED |
| 59 | // Brainpool curves (no specialised "mod p" routine) |
| 60 | #define MBEDTLS_ECP_DP_BP256R1_ENABLED |
| 61 | #define MBEDTLS_ECP_DP_BP384R1_ENABLED |
| 62 | #define MBEDTLS_ECP_DP_BP512R1_ENABLED |
| 63 | // Montgomery curves |
Manuel Pégourié-Gonnard | 0789433 | 2015-06-23 00:18:41 +0200 | [diff] [blame] | 64 | #define MBEDTLS_ECP_DP_CURVE25519_ENABLED |
Manuel Pégourié-Gonnard | d021197 | 2022-01-06 12:20:48 +0100 | [diff] [blame] | 65 | #define MBEDTLS_ECP_DP_CURVE448_ENABLED |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 66 | |
| 67 | #include "check_config.h" |
| 68 | |
Manuel Pégourié-Gonnard | 4ecee83 | 2022-01-05 12:01:38 +0100 | [diff] [blame] | 69 | #define MBEDTLS_HAVE_ASM // just make things a bit faster |
| 70 | #define MBEDTLS_ECP_NIST_OPTIM // faster and less allocations |
| 71 | |
| 72 | //#define MBEDTLS_ECP_WINDOW_SIZE 4 |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 73 | //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 74 | EOF |
| 75 | |
| 76 | for F in 0 1; do |
Manuel Pégourié-Gonnard | d021197 | 2022-01-06 12:20:48 +0100 | [diff] [blame] | 77 | for W in 2 3 4; do |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 78 | scripts/config.py set MBEDTLS_ECP_WINDOW_SIZE $W |
| 79 | scripts/config.py set MBEDTLS_ECP_FIXED_POINT_OPTIM $F |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 80 | make benchmark >/dev/null 2>&1 |
| 81 | echo "fixed point optim = $F, max window size = $W" |
| 82 | echo "--------------------------------------------" |
Manuel Pégourié-Gonnard | 8c683f9 | 2022-01-05 10:09:49 +0100 | [diff] [blame] | 83 | programs/test/benchmark ecdh ecdsa |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 84 | done |
| 85 | done |
| 86 | |
| 87 | # cleanup |
| 88 | |
| 89 | mv $CONFIG_BAK $CONFIG_H |
| 90 | make clean |