| 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 | 
| Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 11 | # SPDX-License-Identifier: Apache-2.0 | 
|  | 12 | # | 
|  | 13 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | 
|  | 14 | # not use this file except in compliance with the License. | 
|  | 15 | # You may obtain a copy of the License at | 
|  | 16 | # | 
|  | 17 | # http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 18 | # | 
|  | 19 | # Unless required by applicable law or agreed to in writing, software | 
|  | 20 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 
|  | 21 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 22 | # See the License for the specific language governing permissions and | 
|  | 23 | # limitations under the License. | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 24 |  | 
|  | 25 | set -eu | 
|  | 26 |  | 
| Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 27 | CONFIG_H='include/mbedtls/mbedtls_config.h' | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 28 |  | 
|  | 29 | if [ -r $CONFIG_H ]; then :; else | 
|  | 30 | echo "$CONFIG_H not found" >&2 | 
|  | 31 | exit 1 | 
|  | 32 | fi | 
|  | 33 |  | 
|  | 34 | if grep -i cmake Makefile >/dev/null; then :; else | 
|  | 35 | echo "Needs Cmake" >&2 | 
|  | 36 | exit 1 | 
|  | 37 | fi | 
|  | 38 |  | 
|  | 39 | if git status | grep -F $CONFIG_H >/dev/null 2>&1; then | 
| Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 40 | echo "mbedtls_config.h not clean" >&2 | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 41 | exit 1 | 
|  | 42 | fi | 
|  | 43 |  | 
|  | 44 | CONFIG_BAK=${CONFIG_H}.bak | 
|  | 45 | cp $CONFIG_H $CONFIG_BAK | 
|  | 46 |  | 
|  | 47 | cat << EOF >$CONFIG_H | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 48 | #define MBEDTLS_PLATFORM_C | 
|  | 49 | #define MBEDTLS_PLATFORM_MEMORY | 
|  | 50 | #define MBEDTLS_MEMORY_BUFFER_ALLOC_C | 
|  | 51 | #define MBEDTLS_MEMORY_DEBUG | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 52 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 53 | #define MBEDTLS_TIMING_C | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 54 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | #define MBEDTLS_BIGNUM_C | 
|  | 56 | #define MBEDTLS_ECP_C | 
|  | 57 | #define MBEDTLS_ASN1_PARSE_C | 
|  | 58 | #define MBEDTLS_ASN1_WRITE_C | 
|  | 59 | #define MBEDTLS_ECDSA_C | 
|  | 60 | #define MBEDTLS_ECDH_C | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 61 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | #define MBEDTLS_ECP_DP_SECP192R1_ENABLED | 
|  | 63 | #define MBEDTLS_ECP_DP_SECP224R1_ENABLED | 
|  | 64 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED | 
|  | 65 | #define MBEDTLS_ECP_DP_SECP384R1_ENABLED | 
|  | 66 | #define MBEDTLS_ECP_DP_SECP521R1_ENABLED | 
| Manuel Pégourié-Gonnard | 0789433 | 2015-06-23 00:18:41 +0200 | [diff] [blame] | 67 | #define MBEDTLS_ECP_DP_CURVE25519_ENABLED | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 68 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 69 | //#define MBEDTLS_ECP_WINDOW_SIZE            6 | 
|  | 70 | //#define MBEDTLS_ECP_FIXED_POINT_OPTIM      1 | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 71 | EOF | 
|  | 72 |  | 
|  | 73 | for F in 0 1; do | 
|  | 74 | for W in 2 3 4 5 6; do | 
| Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 75 | scripts/config.py set MBEDTLS_ECP_WINDOW_SIZE $W | 
|  | 76 | scripts/config.py set MBEDTLS_ECP_FIXED_POINT_OPTIM $F | 
| Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 77 | make benchmark >/dev/null 2>&1 | 
|  | 78 | echo "fixed point optim = $F, max window size = $W" | 
|  | 79 | echo "--------------------------------------------" | 
|  | 80 | programs/test/benchmark | 
|  | 81 | done | 
|  | 82 | done | 
|  | 83 |  | 
|  | 84 | # cleanup | 
|  | 85 |  | 
|  | 86 | mv $CONFIG_BAK $CONFIG_H | 
|  | 87 | make clean |