blob: d02b69e14488efda0b3562ccdeb0a8b8a14ff43c [file] [log] [blame]
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +01001#!/bin/sh
2
Paul Bakker6152b022015-04-14 15:00:09 +02003# Measure heap usage (and performance) of ECC operations with various values of
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +01004# the relevant tunable compile-time parameters.
Manuel Pégourié-Gonnard8b7d7d62015-02-05 10:00:30 +00005#
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úti468a76f2020-05-26 00:33:31 +02009#
10# Copyright (C) 2014-2015, Arm Limited, All Rights Reserved
Bence Szépkúti51b41d52020-05-26 01:54:15 +020011# 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.
Bence Szépkúti468a76f2020-05-26 00:33:31 +020024#
25# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +010026
27set -eu
28
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000029CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +010030
31if [ -r $CONFIG_H ]; then :; else
32 echo "$CONFIG_H not found" >&2
33 exit 1
34fi
35
36if grep -i cmake Makefile >/dev/null; then :; else
37 echo "Needs Cmake" >&2
38 exit 1
39fi
40
41if git status | grep -F $CONFIG_H >/dev/null 2>&1; then
42 echo "config.h not clean" >&2
43 exit 1
44fi
45
46CONFIG_BAK=${CONFIG_H}.bak
47cp $CONFIG_H $CONFIG_BAK
48
49cat << EOF >$CONFIG_H
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#define MBEDTLS_PLATFORM_C
51#define MBEDTLS_PLATFORM_MEMORY
52#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
53#define MBEDTLS_MEMORY_DEBUG
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +010054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#define MBEDTLS_TIMING_C
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +010056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#define MBEDTLS_BIGNUM_C
58#define MBEDTLS_ECP_C
59#define MBEDTLS_ASN1_PARSE_C
60#define MBEDTLS_ASN1_WRITE_C
61#define MBEDTLS_ECDSA_C
62#define MBEDTLS_ECDH_C
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +010063
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
65#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
66#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
67#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
68#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
Manuel Pégourié-Gonnard07894332015-06-23 00:18:41 +020069#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +010070
71#include "check_config.h"
72
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073//#define MBEDTLS_ECP_WINDOW_SIZE 6
74//#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +010075EOF
76
77for F in 0 1; do
78 for W in 2 3 4 5 6; do
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079 scripts/config.pl set MBEDTLS_ECP_WINDOW_SIZE $W
80 scripts/config.pl set MBEDTLS_ECP_FIXED_POINT_OPTIM $F
Manuel Pégourié-Gonnard500de6e2014-12-19 18:06:47 +010081 make benchmark >/dev/null 2>&1
82 echo "fixed point optim = $F, max window size = $W"
83 echo "--------------------------------------------"
84 programs/test/benchmark
85 done
86done
87
88# cleanup
89
90mv $CONFIG_BAK $CONFIG_H
91make clean