ecc-heap.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/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 "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. #include "check_config.h"
  58. //#define MBEDTLS_ECP_WINDOW_SIZE 6
  59. //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
  60. EOF
  61. for F in 0 1; do
  62. for W in 2 3 4 5 6; do
  63. scripts/config.py set MBEDTLS_ECP_WINDOW_SIZE $W
  64. scripts/config.py set MBEDTLS_ECP_FIXED_POINT_OPTIM $F
  65. make benchmark >/dev/null 2>&1
  66. echo "fixed point optim = $F, max window size = $W"
  67. echo "--------------------------------------------"
  68. programs/test/benchmark
  69. done
  70. done
  71. # cleanup
  72. mv $CONFIG_BAK $CONFIG_H
  73. make clean