ecc-heap.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. # Measure heap usage (and performance) of ECC operations with various values of
  3. # the relevant tunable compile-time parameters.
  4. #
  5. # Usage (preferably on a 32-bit platform):
  6. # cmake -D CMAKE_BUILD_TYPE=Release .
  7. # scripts/ecc-heap.sh | tee ecc-heap.log
  8. #
  9. # Copyright The Mbed TLS Contributors
  10. # SPDX-License-Identifier: Apache-2.0
  11. #
  12. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  13. # not use this file except in compliance with the License.
  14. # You may obtain a copy of the License at
  15. #
  16. # http://www.apache.org/licenses/LICENSE-2.0
  17. #
  18. # Unless required by applicable law or agreed to in writing, software
  19. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  20. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. # See the License for the specific language governing permissions and
  22. # limitations under the License.
  23. set -eu
  24. CONFIG_H='include/mbedtls/mbedtls_config.h'
  25. if [ -r $CONFIG_H ]; then :; else
  26. echo "$CONFIG_H not found" >&2
  27. exit 1
  28. fi
  29. if grep -i cmake Makefile >/dev/null; then :; else
  30. echo "Needs Cmake" >&2
  31. exit 1
  32. fi
  33. if git status | grep -F $CONFIG_H >/dev/null 2>&1; then
  34. echo "mbedtls_config.h not clean" >&2
  35. exit 1
  36. fi
  37. CONFIG_BAK=${CONFIG_H}.bak
  38. cp $CONFIG_H $CONFIG_BAK
  39. cat << EOF >$CONFIG_H
  40. #define MBEDTLS_PLATFORM_C
  41. #define MBEDTLS_PLATFORM_MEMORY
  42. #define MBEDTLS_MEMORY_BUFFER_ALLOC_C
  43. #define MBEDTLS_MEMORY_DEBUG
  44. #define MBEDTLS_TIMING_C
  45. #define MBEDTLS_BIGNUM_C
  46. #define MBEDTLS_ECP_C
  47. #define MBEDTLS_ASN1_PARSE_C
  48. #define MBEDTLS_ASN1_WRITE_C
  49. #define MBEDTLS_ECDSA_C
  50. #define MBEDTLS_ECDH_C
  51. #define MBEDTLS_ECP_DP_SECP192R1_ENABLED
  52. #define MBEDTLS_ECP_DP_SECP224R1_ENABLED
  53. #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
  54. #define MBEDTLS_ECP_DP_SECP384R1_ENABLED
  55. #define MBEDTLS_ECP_DP_SECP521R1_ENABLED
  56. #define MBEDTLS_ECP_DP_CURVE25519_ENABLED
  57. //#define MBEDTLS_ECP_WINDOW_SIZE 6
  58. //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
  59. EOF
  60. for F in 0 1; do
  61. for W in 2 3 4 5 6; do
  62. scripts/config.py set MBEDTLS_ECP_WINDOW_SIZE $W
  63. scripts/config.py set MBEDTLS_ECP_FIXED_POINT_OPTIM $F
  64. make benchmark >/dev/null 2>&1
  65. echo "fixed point optim = $F, max window size = $W"
  66. echo "--------------------------------------------"
  67. programs/test/benchmark
  68. done
  69. done
  70. # cleanup
  71. mv $CONFIG_BAK $CONFIG_H
  72. make clean