ecc-heap.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 OR GPL-2.0-or-later
  11. #
  12. # This file is provided under the Apache License 2.0, or the
  13. # GNU General Public License v2.0 or later.
  14. #
  15. # **********
  16. # Apache License 2.0:
  17. #
  18. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  19. # not use this file except in compliance with the License.
  20. # You may obtain a copy of the License at
  21. #
  22. # http://www.apache.org/licenses/LICENSE-2.0
  23. #
  24. # Unless required by applicable law or agreed to in writing, software
  25. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  26. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  27. # See the License for the specific language governing permissions and
  28. # limitations under the License.
  29. #
  30. # **********
  31. #
  32. # **********
  33. # GNU General Public License v2.0 or later:
  34. #
  35. # This program is free software; you can redistribute it and/or modify
  36. # it under the terms of the GNU General Public License as published by
  37. # the Free Software Foundation; either version 2 of the License, or
  38. # (at your option) any later version.
  39. #
  40. # This program is distributed in the hope that it will be useful,
  41. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  43. # GNU General Public License for more details.
  44. #
  45. # You should have received a copy of the GNU General Public License along
  46. # with this program; if not, write to the Free Software Foundation, Inc.,
  47. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  48. #
  49. # **********
  50. set -eu
  51. CONFIG_H='include/mbedtls/config.h'
  52. if [ -r $CONFIG_H ]; then :; else
  53. echo "$CONFIG_H not found" >&2
  54. exit 1
  55. fi
  56. if grep -i cmake Makefile >/dev/null; then :; else
  57. echo "Needs Cmake" >&2
  58. exit 1
  59. fi
  60. if git status | grep -F $CONFIG_H >/dev/null 2>&1; then
  61. echo "config.h not clean" >&2
  62. exit 1
  63. fi
  64. CONFIG_BAK=${CONFIG_H}.bak
  65. cp $CONFIG_H $CONFIG_BAK
  66. cat << EOF >$CONFIG_H
  67. #define MBEDTLS_PLATFORM_C
  68. #define MBEDTLS_PLATFORM_MEMORY
  69. #define MBEDTLS_MEMORY_BUFFER_ALLOC_C
  70. #define MBEDTLS_MEMORY_DEBUG
  71. #define MBEDTLS_TIMING_C
  72. #define MBEDTLS_BIGNUM_C
  73. #define MBEDTLS_ECP_C
  74. #define MBEDTLS_ASN1_PARSE_C
  75. #define MBEDTLS_ASN1_WRITE_C
  76. #define MBEDTLS_ECDSA_C
  77. #define MBEDTLS_ECDH_C
  78. #define MBEDTLS_ECP_DP_SECP192R1_ENABLED
  79. #define MBEDTLS_ECP_DP_SECP224R1_ENABLED
  80. #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
  81. #define MBEDTLS_ECP_DP_SECP384R1_ENABLED
  82. #define MBEDTLS_ECP_DP_SECP521R1_ENABLED
  83. #define MBEDTLS_ECP_DP_CURVE25519_ENABLED
  84. #include "check_config.h"
  85. //#define MBEDTLS_ECP_WINDOW_SIZE 6
  86. //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
  87. EOF
  88. for F in 0 1; do
  89. for W in 2 3 4 5 6; do
  90. scripts/config.pl set MBEDTLS_ECP_WINDOW_SIZE $W
  91. scripts/config.pl set MBEDTLS_ECP_FIXED_POINT_OPTIM $F
  92. make benchmark >/dev/null 2>&1
  93. echo "fixed point optim = $F, max window size = $W"
  94. echo "--------------------------------------------"
  95. programs/test/benchmark
  96. done
  97. done
  98. # cleanup
  99. mv $CONFIG_BAK $CONFIG_H
  100. make clean