• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# Measure heap usage (and performance) of ECC operations with various values of
4# the relevant tunable compile-time parameters.
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
9#
10# Copyright The Mbed TLS Contributors
11# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
12
13set -eu
14
15CONFIG_H='include/mbedtls/config.h'
16
17if [ -r $CONFIG_H ]; then :; else
18    echo "$CONFIG_H not found" >&2
19    exit 1
20fi
21
22if grep -i cmake Makefile >/dev/null; then :; else
23    echo "Needs Cmake" >&2
24    exit 1
25fi
26
27if git status | grep -F $CONFIG_H >/dev/null 2>&1; then
28    echo "config.h not clean" >&2
29    exit 1
30fi
31
32CONFIG_BAK=${CONFIG_H}.bak
33cp $CONFIG_H $CONFIG_BAK
34
35cat << EOF >$CONFIG_H
36#define MBEDTLS_PLATFORM_C
37#define MBEDTLS_PLATFORM_MEMORY
38#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
39#define MBEDTLS_MEMORY_DEBUG
40
41#define MBEDTLS_TIMING_C
42
43#define MBEDTLS_BIGNUM_C
44#define MBEDTLS_ECP_C
45#define MBEDTLS_ECP_NO_INTERNAL_RNG
46#define MBEDTLS_ASN1_PARSE_C
47#define MBEDTLS_ASN1_WRITE_C
48#define MBEDTLS_ECDSA_C
49#define MBEDTLS_SHA256_C // ECDSA benchmark needs it
50#define MBEDTLS_SHA224_C // SHA256 requires this for now
51#define MBEDTLS_ECDH_C
52
53// NIST curves >= 256 bits
54#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
55#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
56#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
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
64#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
65#define MBEDTLS_ECP_DP_CURVE448_ENABLED
66
67#include "check_config.h"
68
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
73//#define MBEDTLS_ECP_FIXED_POINT_OPTIM      1
74EOF
75
76for F in 0 1; do
77    for W in 2 3 4; do
78        scripts/config.py set MBEDTLS_ECP_WINDOW_SIZE $W
79        scripts/config.py set MBEDTLS_ECP_FIXED_POINT_OPTIM $F
80        make benchmark >/dev/null 2>&1
81        echo "fixed point optim = $F, max window size = $W"
82        echo "--------------------------------------------"
83        programs/test/benchmark ecdh ecdsa
84    done
85done
86
87# cleanup
88
89mv $CONFIG_BAK $CONFIG_H
90make clean
91