ecc-heap.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. set -eu
  9. CONFIG_H='include/mbedtls/config.h'
  10. if [ -r $CONFIG_H ]; then :; else
  11. echo "$CONFIG_H not found" >&2
  12. exit 1
  13. fi
  14. if grep -i cmake Makefile >/dev/null; then :; else
  15. echo "Needs Cmake" >&2
  16. exit 1
  17. fi
  18. if git status | grep -F $CONFIG_H >/dev/null 2>&1; then
  19. echo "config.h not clean" >&2
  20. exit 1
  21. fi
  22. CONFIG_BAK=${CONFIG_H}.bak
  23. cp $CONFIG_H $CONFIG_BAK
  24. cat << EOF >$CONFIG_H
  25. #define MBEDTLS_PLATFORM_C
  26. #define MBEDTLS_PLATFORM_MEMORY
  27. #define MBEDTLS_MEMORY_BUFFER_ALLOC_C
  28. #define MBEDTLS_MEMORY_DEBUG
  29. #define MBEDTLS_TIMING_C
  30. #define MBEDTLS_BIGNUM_C
  31. #define MBEDTLS_ECP_C
  32. #define MBEDTLS_ASN1_PARSE_C
  33. #define MBEDTLS_ASN1_WRITE_C
  34. #define MBEDTLS_ECDSA_C
  35. #define MBEDTLS_ECDH_C
  36. #define MBEDTLS_ECP_DP_SECP192R1_ENABLED
  37. #define MBEDTLS_ECP_DP_SECP224R1_ENABLED
  38. #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
  39. #define MBEDTLS_ECP_DP_SECP384R1_ENABLED
  40. #define MBEDTLS_ECP_DP_SECP521R1_ENABLED
  41. #define MBEDTLS_ECP_DP_CURVE25519_ENABLED
  42. #include "check_config.h"
  43. //#define MBEDTLS_ECP_WINDOW_SIZE 6
  44. //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
  45. EOF
  46. for F in 0 1; do
  47. for W in 2 3 4 5 6; do
  48. scripts/config.pl set MBEDTLS_ECP_WINDOW_SIZE $W
  49. scripts/config.pl set MBEDTLS_ECP_FIXED_POINT_OPTIM $F
  50. make benchmark >/dev/null 2>&1
  51. echo "fixed point optim = $F, max window size = $W"
  52. echo "--------------------------------------------"
  53. programs/test/benchmark
  54. done
  55. done
  56. # cleanup
  57. mv $CONFIG_BAK $CONFIG_H
  58. make clean