quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

ecc-heap.sh (2347B)


      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 
     13 set -eu
     14 
     15 CONFIG_H='include/mbedtls/mbedtls_config.h'
     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 "mbedtls_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
     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_ASN1_PARSE_C
     46 #define MBEDTLS_ASN1_WRITE_C
     47 #define MBEDTLS_ECDSA_C
     48 #define MBEDTLS_SHA256_C // ECDSA benchmark needs it
     49 #define MBEDTLS_SHA224_C // SHA256 requires this for now
     50 #define MBEDTLS_ECDH_C
     51 
     52 // NIST curves >= 256 bits
     53 #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
     54 #define MBEDTLS_ECP_DP_SECP384R1_ENABLED
     55 #define MBEDTLS_ECP_DP_SECP521R1_ENABLED
     56 // SECP "koblitz-like" curve >= 256 bits
     57 #define MBEDTLS_ECP_DP_SECP256K1_ENABLED
     58 // Brainpool curves (no specialised "mod p" routine)
     59 #define MBEDTLS_ECP_DP_BP256R1_ENABLED
     60 #define MBEDTLS_ECP_DP_BP384R1_ENABLED
     61 #define MBEDTLS_ECP_DP_BP512R1_ENABLED
     62 // Montgomery curves
     63 #define MBEDTLS_ECP_DP_CURVE25519_ENABLED
     64 #define MBEDTLS_ECP_DP_CURVE448_ENABLED
     65 
     66 #define MBEDTLS_HAVE_ASM // just make things a bit faster
     67 #define MBEDTLS_ECP_NIST_OPTIM // faster and less allocations
     68 
     69 //#define MBEDTLS_ECP_WINDOW_SIZE            4
     70 //#define MBEDTLS_ECP_FIXED_POINT_OPTIM      1
     71 EOF
     72 
     73 for F in 0 1; do
     74     for W in 2 3 4; do
     75         scripts/config.py set MBEDTLS_ECP_WINDOW_SIZE $W
     76         scripts/config.py set MBEDTLS_ECP_FIXED_POINT_OPTIM $F
     77         make benchmark >/dev/null 2>&1
     78         echo "fixed point optim = $F, max window size = $W"
     79         echo "--------------------------------------------"
     80         programs/test/benchmark ecdh ecdsa
     81     done
     82 done
     83 
     84 # cleanup
     85 
     86 mv $CONFIG_BAK $CONFIG_H
     87 make clean