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 | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 9 | # |
Bence Szépkúti | a2947ac | 2020-08-19 16:37:36 +0200 | [diff] [blame^] | 10 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 11 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 12 | # |
| 13 | # This file is provided under the Apache License 2.0, or the |
| 14 | # GNU General Public License v2.0 or later. |
| 15 | # |
| 16 | # ********** |
| 17 | # Apache License 2.0: |
Bence Szépkúti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 18 | # |
| 19 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 20 | # not use this file except in compliance with the License. |
| 21 | # You may obtain a copy of the License at |
| 22 | # |
| 23 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 24 | # |
| 25 | # Unless required by applicable law or agreed to in writing, software |
| 26 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 27 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 28 | # See the License for the specific language governing permissions and |
| 29 | # limitations under the License. |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 30 | # |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 31 | # ********** |
| 32 | # |
| 33 | # ********** |
| 34 | # GNU General Public License v2.0 or later: |
| 35 | # |
| 36 | # This program is free software; you can redistribute it and/or modify |
| 37 | # it under the terms of the GNU General Public License as published by |
| 38 | # the Free Software Foundation; either version 2 of the License, or |
| 39 | # (at your option) any later version. |
| 40 | # |
| 41 | # This program is distributed in the hope that it will be useful, |
| 42 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 43 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 44 | # GNU General Public License for more details. |
| 45 | # |
| 46 | # You should have received a copy of the GNU General Public License along |
| 47 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 48 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 49 | # |
| 50 | # ********** |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 51 | |
| 52 | set -eu |
| 53 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 54 | CONFIG_H='include/mbedtls/config.h' |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 55 | |
| 56 | if [ -r $CONFIG_H ]; then :; else |
| 57 | echo "$CONFIG_H not found" >&2 |
| 58 | exit 1 |
| 59 | fi |
| 60 | |
| 61 | if grep -i cmake Makefile >/dev/null; then :; else |
| 62 | echo "Needs Cmake" >&2 |
| 63 | exit 1 |
| 64 | fi |
| 65 | |
| 66 | if git status | grep -F $CONFIG_H >/dev/null 2>&1; then |
| 67 | echo "config.h not clean" >&2 |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | CONFIG_BAK=${CONFIG_H}.bak |
| 72 | cp $CONFIG_H $CONFIG_BAK |
| 73 | |
| 74 | cat << EOF >$CONFIG_H |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 75 | #define MBEDTLS_PLATFORM_C |
| 76 | #define MBEDTLS_PLATFORM_MEMORY |
| 77 | #define MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 78 | #define MBEDTLS_MEMORY_DEBUG |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 79 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 80 | #define MBEDTLS_TIMING_C |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 81 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 82 | #define MBEDTLS_BIGNUM_C |
| 83 | #define MBEDTLS_ECP_C |
| 84 | #define MBEDTLS_ASN1_PARSE_C |
| 85 | #define MBEDTLS_ASN1_WRITE_C |
| 86 | #define MBEDTLS_ECDSA_C |
| 87 | #define MBEDTLS_ECDH_C |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 88 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 89 | #define MBEDTLS_ECP_DP_SECP192R1_ENABLED |
| 90 | #define MBEDTLS_ECP_DP_SECP224R1_ENABLED |
| 91 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED |
| 92 | #define MBEDTLS_ECP_DP_SECP384R1_ENABLED |
| 93 | #define MBEDTLS_ECP_DP_SECP521R1_ENABLED |
Manuel Pégourié-Gonnard | 0789433 | 2015-06-23 00:18:41 +0200 | [diff] [blame] | 94 | #define MBEDTLS_ECP_DP_CURVE25519_ENABLED |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 95 | |
| 96 | #include "check_config.h" |
| 97 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 98 | //#define MBEDTLS_ECP_WINDOW_SIZE 6 |
| 99 | //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 100 | EOF |
| 101 | |
| 102 | for F in 0 1; do |
| 103 | for W in 2 3 4 5 6; do |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 104 | scripts/config.pl set MBEDTLS_ECP_WINDOW_SIZE $W |
| 105 | scripts/config.pl set MBEDTLS_ECP_FIXED_POINT_OPTIM $F |
Manuel Pégourié-Gonnard | 500de6e | 2014-12-19 18:06:47 +0100 | [diff] [blame] | 106 | make benchmark >/dev/null 2>&1 |
| 107 | echo "fixed point optim = $F, max window size = $W" |
| 108 | echo "--------------------------------------------" |
| 109 | programs/test/benchmark |
| 110 | done |
| 111 | done |
| 112 | |
| 113 | # cleanup |
| 114 | |
| 115 | mv $CONFIG_BAK $CONFIG_H |
| 116 | make clean |