Benchmark demonstration program for mbed TLS. The canonical source for this example lives at https://github.com/ARMmbed/mbed-os-example-tls

Mbed TLS Benchmark example on Mbed OS

This application benchmarks the various cryptographic primitives offered by Mbed TLS.

Getting started

Building with Mbed CLI

If you'd like to use Mbed CLI to build this, then you should set up your environment if you have not done so already. For instructions, refer to the main readme. The instructions on this page relate to using the developer.mbed.org Online Compiler

Import the program in to the Online Compiler, select your board from the drop down in the top right hand corner and then compile the application. Once it has built, you can drag and drop the binary onto your device.

Monitoring the application

The output in the terminal window should be similar to this:

terminal output

  SHA-256                  :       1673 Kb/s,         70 cycles/byte
  SHA-512                  :        546 Kb/s,        215 cycles/byte
  AES-CBC-128              :       1428 Kb/s,         82 cycles/byte
  AES-CBC-192              :       1260 Kb/s,         93 cycles/byte
  AES-CBC-256              :       1127 Kb/s,        104 cycles/byte
  AES-GCM-128              :        486 Kb/s,        242 cycles/byte
  AES-GCM-192              :        464 Kb/s,        253 cycles/byte
  AES-GCM-256              :        445 Kb/s,        264 cycles/byte
  AES-CCM-128              :        610 Kb/s,        192 cycles/byte
  AES-CCM-192              :        547 Kb/s,        214 cycles/byte
  AES-CCM-256              :        496 Kb/s,        237 cycles/byte
  CTR_DRBG (NOPR)          :       1139 Kb/s,        102 cycles/byte
  CTR_DRBG (PR)            :        826 Kb/s,        142 cycles/byte
  HMAC_DRBG SHA-256 (NOPR) :        193 Kb/s,        611 cycles/byte
  HMAC_DRBG SHA-256 (PR)   :        170 Kb/s,        695 cycles/byte
  RSA-2048                 :      28 ms/ public
  RSA-2048                 :     953 ms/private
  RSA-4096                 :      93 ms/ public
  RSA-4096                 :    5327 ms/private
  ECDSA-secp384r1          :     451 ms/sign
  ECDSA-secp256r1          :     304 ms/sign
  ECDSA-secp384r1          :     863 ms/verify
  ECDSA-secp256r1          :     594 ms/verify
  ECDHE-secp384r1          :     829 ms/handshake
  ECDHE-secp256r1          :     566 ms/handshake
  ECDHE-Curve25519         :     533 ms/handshake
  ECDH-secp384r1           :     407 ms/handshake
  ECDH-secp256r1           :     281 ms/handshake
  ECDH-Curve25519          :     268 ms/handshake

DONE
Committer:
mbed_official
Date:
Wed Jun 07 11:00:05 2017 +0100
Revision:
30:e0ea8c1ef9f5
Parent:
11:6ccae3ebafd5
Child:
31:fc594198ff6e
Merge pull request #70 from RonEld/aes_ctr_benchmark

AES CTR benchmark
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-tls

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Janos Follath 0:1f7c5025e59d 1 /*
Janos Follath 0:1f7c5025e59d 2 * Benchmark demonstration program
Janos Follath 0:1f7c5025e59d 3 *
Janos Follath 0:1f7c5025e59d 4 * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
Janos Follath 0:1f7c5025e59d 5 * SPDX-License-Identifier: Apache-2.0
Janos Follath 0:1f7c5025e59d 6 *
Janos Follath 0:1f7c5025e59d 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Janos Follath 0:1f7c5025e59d 8 * not use this file except in compliance with the License.
Janos Follath 0:1f7c5025e59d 9 * You may obtain a copy of the License at
Janos Follath 0:1f7c5025e59d 10 *
Janos Follath 0:1f7c5025e59d 11 * http://www.apache.org/licenses/LICENSE-2.0
Janos Follath 0:1f7c5025e59d 12 *
Janos Follath 0:1f7c5025e59d 13 * Unless required by applicable law or agreed to in writing, software
Janos Follath 0:1f7c5025e59d 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Janos Follath 0:1f7c5025e59d 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Janos Follath 0:1f7c5025e59d 16 * See the License for the specific language governing permissions and
Janos Follath 0:1f7c5025e59d 17 * limitations under the License.
Janos Follath 0:1f7c5025e59d 18 */
Janos Follath 0:1f7c5025e59d 19
Janos Follath 0:1f7c5025e59d 20 #include "mbed.h"
Janos Follath 0:1f7c5025e59d 21 #if DEBUG_LEVEL > 0
Janos Follath 0:1f7c5025e59d 22 #include "mbedtls/debug.h"
Janos Follath 0:1f7c5025e59d 23 #endif
Janos Follath 0:1f7c5025e59d 24
Janos Follath 0:1f7c5025e59d 25 #if !defined(MBEDTLS_CONFIG_FILE)
Janos Follath 0:1f7c5025e59d 26 #include "mbedtls/config.h"
Janos Follath 0:1f7c5025e59d 27 #else
Janos Follath 0:1f7c5025e59d 28 #include MBEDTLS_CONFIG_FILE
Janos Follath 0:1f7c5025e59d 29 #endif
Janos Follath 0:1f7c5025e59d 30
Janos Follath 0:1f7c5025e59d 31 #include "mbedtls/platform.h"
Janos Follath 0:1f7c5025e59d 32
Janos Follath 0:1f7c5025e59d 33 #include <string.h>
Janos Follath 0:1f7c5025e59d 34
Janos Follath 0:1f7c5025e59d 35 #include "mbedtls/md4.h"
Janos Follath 0:1f7c5025e59d 36 #include "mbedtls/md5.h"
Janos Follath 0:1f7c5025e59d 37 #include "mbedtls/ripemd160.h"
Janos Follath 0:1f7c5025e59d 38 #include "mbedtls/sha1.h"
Janos Follath 0:1f7c5025e59d 39 #include "mbedtls/sha256.h"
Janos Follath 0:1f7c5025e59d 40 #include "mbedtls/sha512.h"
Janos Follath 0:1f7c5025e59d 41 #include "mbedtls/arc4.h"
Janos Follath 0:1f7c5025e59d 42 #include "mbedtls/des.h"
Janos Follath 0:1f7c5025e59d 43 #include "mbedtls/aes.h"
mbed_official 11:6ccae3ebafd5 44 #include "mbedtls/cmac.h"
Janos Follath 0:1f7c5025e59d 45 #include "mbedtls/blowfish.h"
Janos Follath 0:1f7c5025e59d 46 #include "mbedtls/camellia.h"
Janos Follath 0:1f7c5025e59d 47 #include "mbedtls/gcm.h"
Janos Follath 0:1f7c5025e59d 48 #include "mbedtls/ccm.h"
Janos Follath 0:1f7c5025e59d 49 #include "mbedtls/havege.h"
Janos Follath 0:1f7c5025e59d 50 #include "mbedtls/ctr_drbg.h"
Janos Follath 0:1f7c5025e59d 51 #include "mbedtls/hmac_drbg.h"
Janos Follath 0:1f7c5025e59d 52 #include "mbedtls/rsa.h"
Janos Follath 0:1f7c5025e59d 53 #include "mbedtls/pk.h"
Janos Follath 0:1f7c5025e59d 54 #include "mbedtls/dhm.h"
Janos Follath 0:1f7c5025e59d 55 #include "mbedtls/ecdsa.h"
Janos Follath 0:1f7c5025e59d 56 #include "mbedtls/ecdh.h"
Janos Follath 0:1f7c5025e59d 57 #include "mbedtls/error.h"
Janos Follath 0:1f7c5025e59d 58
Janos Follath 0:1f7c5025e59d 59 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Janos Follath 0:1f7c5025e59d 60 #include "mbedtls/memory_buffer_alloc.h"
Janos Follath 0:1f7c5025e59d 61 #endif
Janos Follath 0:1f7c5025e59d 62
Janos Follath 0:1f7c5025e59d 63 #define RSA_PRIVATE_KEY_2048 \
Janos Follath 0:1f7c5025e59d 64 "-----BEGIN RSA PRIVATE KEY-----\r\n" \
Janos Follath 0:1f7c5025e59d 65 "MIIEogIBAAKCAQEA2dwVr+IMGEtA2/MCP6fA5eb/6B18Bq6e7gw8brNPkm3E6LyR\r\n" \
Janos Follath 0:1f7c5025e59d 66 "4DnMJVxZmw3bPDKBDoKzfntkMESi/Yw5UopLtVfjGfWeQWPClqffLZBsZ60BRAsg\r\n" \
Janos Follath 0:1f7c5025e59d 67 "/g+ID5tgzxSuxzftypK59uexOVCAm7hCKZHGO3DbI7bLY27j7VAgEP7d/yuaz5Fx\r\n" \
Janos Follath 0:1f7c5025e59d 68 "Kl/vu7shqrBoz6ABJVJD3KC8nUiMRUCXRINmxbyUUjA4DnicZv6+xrGKr36r6M8h\r\n" \
Janos Follath 0:1f7c5025e59d 69 "VYLa5msKc8WzbnBWzpUsrpb4/r7ML+qp92gdSfVJ8/bLiU7h2C7faDA59uaqrFK9\r\n" \
Janos Follath 0:1f7c5025e59d 70 "xmDdx7FaWhGQs3LWW6w1UNgkPS0FDYUslpsnsQIDAQABAoIBAC7IJNwM5V3+IuJY\r\n" \
Janos Follath 0:1f7c5025e59d 71 "T35Nzo1PyloUosJokvY5KGz5Ejg2XBdCDu0gXCcVqqQyGIbXrYDpLhQV+RCoXHun\r\n" \
Janos Follath 0:1f7c5025e59d 72 "tdN0oQdC5SB47s/J1Uo2qCUHo0+sBd6PqTkFKsl3KxWssk9TQjvCwC412IefMs69\r\n" \
Janos Follath 0:1f7c5025e59d 73 "hW+ZvwCanmQP56LleApIr2oW4KLfW8Ry/QfZlua+dizctdN7+H1mWwgZQTY9T27J\r\n" \
Janos Follath 0:1f7c5025e59d 74 "6RtGRA5NVkKVPzIHVJfdpKoO7xGg1g06aEbPB/VmGvZaaFWWnaf7uRvFjLZecBLu\r\n" \
Janos Follath 0:1f7c5025e59d 75 "QSx2DA/GDjirlDYj99PJb7DtB4xRtKzsyw0o+xapC8w6OtIl/3xFt9moCu2jGrsx\r\n" \
Janos Follath 0:1f7c5025e59d 76 "vpjHdfECgYEA7fSACRseIs9gAIVX8wq6gayTpA47DHYWAD6IQfIj35SJ+AgsvbFF\r\n" \
Janos Follath 0:1f7c5025e59d 77 "4AmrwDhcJVPmDy1N4nLBfyGAMt/2CfiYkdkW6QFX/ULRMMBL/G7kWV8hYQDICB2g\r\n" \
Janos Follath 0:1f7c5025e59d 78 "xaMRN1lPCmFq6BkSWjwIYTnYDFBDWVm1GVT8TMtJoM8Erej9qC0PeFUCgYEA6mF3\r\n" \
Janos Follath 0:1f7c5025e59d 79 "bigO3t8f5sig+XepaftEUbkJMzo72TVRnIR2ycdR2ihelPQ+25g9dwV0ZA5XXhBS\r\n" \
Janos Follath 0:1f7c5025e59d 80 "DKOABWjMM739Mwmy9v26Dlmu9R01zHQktMvtEAyfz7lk2NF0aMuj8285OJUBf9bz\r\n" \
Janos Follath 0:1f7c5025e59d 81 "Cq3MjtMCD+4CZ6iaEqCdUKOuxfpx5cWVJV+qve0CgYBhD1YaYMFOGaBjFgDl1f51\r\n" \
Janos Follath 0:1f7c5025e59d 82 "Xltqk5NqZdBbkSYrIAWZ8RDF5y+4wFJsLAWuhk6vuyUgE66tK3nZzWRpXAkT0B8L\r\n" \
Janos Follath 0:1f7c5025e59d 83 "fq1lpXKqj1KcvBNCiEkEW1VWJ+dvyAYIF5eyJ++hoFLnETL3M32HivyhKSwPihPg\r\n" \
Janos Follath 0:1f7c5025e59d 84 "nVW8TT9fJJIYDe1JZ/fjcQKBgHJfv7UsrR0LSvkG3K8AOtbx+8PZhOjPuRbk0v+L\r\n" \
Janos Follath 0:1f7c5025e59d 85 "EKCkuIe5/XW4vtfQMeZb7hFJgk7vrepm+vkoy8VQKDf4urGW3W1VTHBmobM01hi4\r\n" \
Janos Follath 0:1f7c5025e59d 86 "DuYvEul+Mf0wMRtWjJolo4m+BO5KiW2jpFfqFm6JmfjVqOIAKOSKC6am8V/MDF0h\r\n" \
Janos Follath 0:1f7c5025e59d 87 "kyN9AoGAT9oOiEXMolbkDZw/QCaBiRoAGlGlNYUkJ+58U6OjIZLISw6aFv+Y2uE0\r\n" \
Janos Follath 0:1f7c5025e59d 88 "mEImItjuYZtSYKblWikp6ldPoKlt9bwEFe3c6IZ8kJ3+xyEyAGrvjXjEY7PzP6dp\r\n" \
Janos Follath 0:1f7c5025e59d 89 "Ajbjp9X9uocEBv9W/KsBLdQ7yizcL/toHwdBO4vQqmqTvAc5IIw=\r\n" \
Janos Follath 0:1f7c5025e59d 90 "-----END RSA PRIVATE KEY-----\r\n"
Janos Follath 0:1f7c5025e59d 91
Janos Follath 0:1f7c5025e59d 92 #define RSA_PRIVATE_KEY_4096 \
Janos Follath 0:1f7c5025e59d 93 "-----BEGIN RSA PRIVATE KEY-----\r\n" \
Janos Follath 0:1f7c5025e59d 94 "MIIJKgIBAAKCAgEAmkdGjoIshJuOt2NO47qB3Z3yyvmLg2j351isItSNuFQU3qr+\r\n" \
Janos Follath 0:1f7c5025e59d 95 "jXHIeANf03yw/K0Zvos8RPd+CqLjoxAQL3QDH4bZAl88bIo29i+SANbNSrKQmc0k\r\n" \
Janos Follath 0:1f7c5025e59d 96 "pH+yzw3alDzO0GZaOPZjsbo6AwBrno5msi0vRuC2aY8vGLPsZWSyLai7tneS1j/o\r\n" \
Janos Follath 0:1f7c5025e59d 97 "vYW6XIo8Cj61j2Ypy9HhVUW/4Wc+zAT25D/x7jTpkqJLWWT+YzibNbOY48M5eJcB\r\n" \
Janos Follath 0:1f7c5025e59d 98 "6/sMyUIeI3/u/wXyMrooNyLiCpedkuHRA0m7u5cWPTUISTunSRlVFij/NHJjuU8e\r\n" \
Janos Follath 0:1f7c5025e59d 99 "wA3B29yfZFsUqDEnyc+OxniIueAixTomVszxAaVn8zFEbYhFMPqziiFp99u3jfeG\r\n" \
Janos Follath 0:1f7c5025e59d 100 "k1q9mmUi/uCfUC4e2IC5rqq1ZbKSduH7Ug/Vn2bGQahww0sZFRHDXFrnBcotcW+M\r\n" \
Janos Follath 0:1f7c5025e59d 101 "bnC290VBDnYgzmdYrIOxuPb2aUwJo4ZlbKh5uBB1PigMuyhLKibQ1a+V5ZJGdpP6\r\n" \
Janos Follath 0:1f7c5025e59d 102 "SE9PGIdgYWSmh2QEMuLE6v+wTO2LQ5JgqsvFfi3GIZvkn0s8jTS72Jq2uMkFkMer\r\n" \
Janos Follath 0:1f7c5025e59d 103 "UBjPDYaSPy5kpo103KerWs+cMPOJ/3FtZzI++7MoSUTkWVr1ySQFt5i1EIZ/0Thi\r\n" \
Janos Follath 0:1f7c5025e59d 104 "jut2jNe8a4AoA3TtC8Rkk/3AIIbg8MVNT4EnT+KHROTMu6gET1oJ3YfBRpUCAwEA\r\n" \
Janos Follath 0:1f7c5025e59d 105 "AQKCAgEAhuNSmT7PVZH8kfLOAuYKrY1vvm+4v0iDl048Eqfs0QESziyLK3gUYnnw\r\n" \
Janos Follath 0:1f7c5025e59d 106 "yqP2yrU+EQ8Dvvj0xq/sf6GHxTWVlXb9PcmutueRbmXhLcKg83J0Y0StiPXtjIL8\r\n" \
Janos Follath 0:1f7c5025e59d 107 "XSddW3Bh6fPi7n14Qy+W6KZwu9AtybanRlvePabyRSRpdOpWVQ7u30w5XZsSed6S\r\n" \
Janos Follath 0:1f7c5025e59d 108 "6BI0BBC68m2qqje1sInoqdCdXKtcB31TytUDNEHM+UuAyM8iGeGS2hCNqZlycHTS\r\n" \
Janos Follath 0:1f7c5025e59d 109 "jQ9KEsdMH3YLu0lQgRpWtxmg+VL6ROWwmAtKF12EwbDYZ+uoVl69OkQnCpv8pxKa\r\n" \
Janos Follath 0:1f7c5025e59d 110 "ec/4m6V+uEA1AOpaAMorHG3fH31IKWC/fTZstovgO/eG2XCtlbcCoWCQ7amFq16l\r\n" \
Janos Follath 0:1f7c5025e59d 111 "Gh1UKeBHxMXpDj4oDmIUGUvgzSNnEeSN/v76losWvWYQDjXR/LMDa/CNYsD8BmJR\r\n" \
Janos Follath 0:1f7c5025e59d 112 "PZidIjIXdVRlYOhA7ljtySQvp6RBujBfw3tsVMyZw2XzXFwM9O89b1xXC6+M5jf9\r\n" \
Janos Follath 0:1f7c5025e59d 113 "DXs/U7Fw+J9qq/YpByABcPCwWdttwdQFRbOxwxaSOKarIqS87TW1JuFcNJ59Ut6G\r\n" \
Janos Follath 0:1f7c5025e59d 114 "kMvAg6gC34U+0ktkG/AmI1hgjC+P7ErHCXBR2xARoGzcO/CMZF59S+Z2HFchpTSP\r\n" \
Janos Follath 0:1f7c5025e59d 115 "5T2o4mGy3VfHSBidQQrcZRukg8ZP8M1NF3bXjpY6QZpeLHc4oHECggEBAMjdgzzk\r\n" \
Janos Follath 0:1f7c5025e59d 116 "xp4mIYFxAEiXYt7tzuUXJk+0UpEJj5uboWLirUZqZmNUPyh6WDnzlREBH++Ms0LO\r\n" \
Janos Follath 0:1f7c5025e59d 117 "+AWSfaGPDoMb0NE2j3c4FRWAhe7Vn6lj7nLVpF2RdwRo88yGerZ4uwGMY8NUQCtn\r\n" \
Janos Follath 0:1f7c5025e59d 118 "zum3J7eCJ5DojiceRb6uMxTJ8xZmUC4W2f3J/lrR7wlYjyVnnHqH5HcemYUipWSw\r\n" \
Janos Follath 0:1f7c5025e59d 119 "sM0/cHp3lrz2VWrbAEu8HVpklvDQpdAgl7cjXt/JHYawY+p426IF/PzQSRROnzgy\r\n" \
Janos Follath 0:1f7c5025e59d 120 "4WI8FVYNV2tgu0TOFURbkkEvuj/duDKeooUIF0G0XHzha5oAX/j0iWiHbrOF6wHj\r\n" \
Janos Follath 0:1f7c5025e59d 121 "0xeajL9msKBnmD8CggEBAMSgLWmv7G31x4tndJCcXnX4AyVL7KpygAx/ZwCcyTR8\r\n" \
Janos Follath 0:1f7c5025e59d 122 "rY1rO07f/ta2noEra/xmEW/BW98qJFCHSU2nSLAQ5FpFSWyuQqrnffrMJnfWyvpr\r\n" \
Janos Follath 0:1f7c5025e59d 123 "ceQ0yQ/MiA6/JIOvGAjabcspzZijxzGp+Qk3eTT0yOXLSVOCH9B9XVHLodcy4PQM\r\n" \
Janos Follath 0:1f7c5025e59d 124 "KSCxy0vVHhVNl2SdPEwTXRmxk99Q/rw6IHVpQxBq1OhQt05nTKT+rZMD/grSK22e\r\n" \
Janos Follath 0:1f7c5025e59d 125 "my2F0DodAJwLo063Zv3RXQZhDYodMmjcp9Hqrtvj9P3HD7J3z6ACiV3SCi8cZumL\r\n" \
Janos Follath 0:1f7c5025e59d 126 "bSmnKCcd0bb45+aOWm31ieECJuIcJ9rOREEa/KDYTCsCggEBAMG5WkSVhLWsou37\r\n" \
Janos Follath 0:1f7c5025e59d 127 "dUGNuA63nq42SH3gtS0q4nU6gUkkw+dA4ST1cMByVrr1oRQ4WHup4I4TnQOKyF3T\r\n" \
Janos Follath 0:1f7c5025e59d 128 "4jQy1I+ipnVeAn+tZ/7zyzwMpEHeqNqRXA9FxbTBEoMAJ6QTqXgOvqDeSqIAQm7r\r\n" \
Janos Follath 0:1f7c5025e59d 129 "OYu5rrgtqyh/S8bGCwvUe4ooAfCSKx2ekYMbBVwW9MT8YS09tuS/iHJ3Mt2RTMLg\r\n" \
Janos Follath 0:1f7c5025e59d 130 "qeHvVmxrcXqZoFm44Ba7tN/pP0mi9HKyviZT4tmV3IYEbn3JyGGsfkUuVU9wEUfg\r\n" \
Janos Follath 0:1f7c5025e59d 131 "MCrgrVxrwfketAzooiHMjkVL2ASjzAJTmEvdAPETYXxzJD9LN0ovY3t8JfAC37IN\r\n" \
Janos Follath 0:1f7c5025e59d 132 "sVXS8/MCggEBALByOS59Y4Ktq1rLBQx8djwQyuneP0wZohUVAx7Gk7xZIfklQDyg\r\n" \
Janos Follath 0:1f7c5025e59d 133 "v/R4PrcVezstcPpDnykdjScCsGJR+uWc0v667I/ttP/e6utz5hVmmBGu965dPAzE\r\n" \
Janos Follath 0:1f7c5025e59d 134 "c1ggaSkOqFfRg/Nr2Qbf+fH0YPnHYSqHe/zSt0OMIvaaeXLcdKhEDSCUBRhE1HWB\r\n" \
Janos Follath 0:1f7c5025e59d 135 "kxR046WzgBeYzNQwycz9xwqsctJKGpeR9ute+5ANHPd3X9XtID0fqz8ctI5eZaSw\r\n" \
Janos Follath 0:1f7c5025e59d 136 "wApIW01ZQcAF8B+4WkkVuFXnpWW33yCOaRyPVOPHpnclr5WU1fS+3Q85QkW9rkej\r\n" \
Janos Follath 0:1f7c5025e59d 137 "97zlkl0QY9AHJqrXnoML1ywAK7ns+MVyNK8CggEAf62xcKZhOb1djeF72Ms+i/i/\r\n" \
Janos Follath 0:1f7c5025e59d 138 "WIAq4Q4YpsElgvJTHpNH2v9g4ngSTKe3ws3bGc502sWRlhcoTFMOW2rJNe/iqKkb\r\n" \
Janos Follath 0:1f7c5025e59d 139 "3cdeTkseDbpqozmJWz9dJWSVtXas2bZjzBEa//gQ7nHGVeQdqZJQ9rxPsoOAkfpi\r\n" \
Janos Follath 0:1f7c5025e59d 140 "qCFrmfUVUqC53e3XMt8+W+aSvKl+JZiB9ozkO9A6Q0vfQLKtjUMdQE3XaCFQT8DI\r\n" \
Janos Follath 0:1f7c5025e59d 141 "smaLBlBmeRaBpc02ENeC4ADlWosm1SwgxqMhuh2Alba/GrHOoPlVl4hDs9Fb5a6R\r\n" \
Janos Follath 0:1f7c5025e59d 142 "rmpXSt07GAxnG6j9jssA95E4rc1zO0CVKG5bvjVTxwi/sT0/VVX7VsJM4uTAQg==\r\n" \
Janos Follath 0:1f7c5025e59d 143 "-----END RSA PRIVATE KEY-----\r\n"
Janos Follath 0:1f7c5025e59d 144
Janos Follath 0:1f7c5025e59d 145 /*
mbed_official 11:6ccae3ebafd5 146 * Uncomment this line to enable ECDSA benchmark.
mbed_official 11:6ccae3ebafd5 147 */
mbed_official 11:6ccae3ebafd5 148 //#define ENABLE_ECDSA
mbed_official 11:6ccae3ebafd5 149
mbed_official 11:6ccae3ebafd5 150 /*
Janos Follath 0:1f7c5025e59d 151 * For heap usage estimates, we need an estimate of the overhead per allocated
Janos Follath 0:1f7c5025e59d 152 * block. ptmalloc2/3 (used in gnu libc for instance) uses 2 size_t per block,
Janos Follath 0:1f7c5025e59d 153 * so use that as our baseline.
Janos Follath 0:1f7c5025e59d 154 */
Janos Follath 0:1f7c5025e59d 155 #define MEM_BLOCK_OVERHEAD ( 2 * sizeof( size_t ) )
Janos Follath 0:1f7c5025e59d 156
Janos Follath 0:1f7c5025e59d 157 /*
Janos Follath 0:1f7c5025e59d 158 * Size to use for the malloc buffer if MEMORY_BUFFER_ALLOC_C is defined.
Janos Follath 0:1f7c5025e59d 159 */
Janos Follath 0:1f7c5025e59d 160 #define HEAP_SIZE (1u << 16) // 64k
Janos Follath 0:1f7c5025e59d 161
Janos Follath 0:1f7c5025e59d 162 #define BUFSIZE 1024
Janos Follath 0:1f7c5025e59d 163 #define HEADER_FORMAT " %-24s : "
Janos Follath 0:1f7c5025e59d 164 #define TITLE_LEN 25
Janos Follath 0:1f7c5025e59d 165
Janos Follath 0:1f7c5025e59d 166 #define OPTIONS \
Janos Follath 0:1f7c5025e59d 167 "md4, md5, ripemd160, sha1, sha256, sha512,\r\n" \
mbed_official 11:6ccae3ebafd5 168 "arc4, camellia, blowfish,\r\n" \
mbed_official 30:e0ea8c1ef9f5 169 "des3, des, aes_cmac, des3_cmac, aes_cbc, \r\n" \
mbed_official 30:e0ea8c1ef9f5 170 "aes_ctr, aes_gcm, aes_ccm,\r\n" \
mbed_official 30:e0ea8c1ef9f5 171 "havege, ctr_drbg, hmac_drbg,\r\n" \
Janos Follath 0:1f7c5025e59d 172 "rsa, dhm, ecdsa, ecdh.\r\n"
Janos Follath 0:1f7c5025e59d 173
Janos Follath 0:1f7c5025e59d 174 #if defined(MBEDTLS_ERROR_C)
Janos Follath 0:1f7c5025e59d 175 #define PRINT_ERROR \
Janos Follath 0:1f7c5025e59d 176 mbedtls_strerror( ret, ( char * )tmp, sizeof( tmp ) ); \
Janos Follath 0:1f7c5025e59d 177 mbedtls_printf( "FAILED: %s\r\n", tmp );
Janos Follath 0:1f7c5025e59d 178 #else
Janos Follath 0:1f7c5025e59d 179 #define PRINT_ERROR \
Janos Follath 0:1f7c5025e59d 180 mbedtls_printf( "FAILED: -0x%04x\r\n", -ret );
Janos Follath 0:1f7c5025e59d 181 #endif
Janos Follath 0:1f7c5025e59d 182
Janos Follath 0:1f7c5025e59d 183 static unsigned long mbedtls_timing_hardclock( void )
Janos Follath 0:1f7c5025e59d 184 {
Janos Follath 0:1f7c5025e59d 185 static int dwt_started = 0;
Janos Follath 0:1f7c5025e59d 186
Janos Follath 0:1f7c5025e59d 187 if( dwt_started == 0 )
Janos Follath 0:1f7c5025e59d 188 {
Janos Follath 0:1f7c5025e59d 189 CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
Janos Follath 0:1f7c5025e59d 190 DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
Janos Follath 0:1f7c5025e59d 191 }
Janos Follath 0:1f7c5025e59d 192
Janos Follath 0:1f7c5025e59d 193 return( DWT->CYCCNT );
Janos Follath 0:1f7c5025e59d 194 }
Janos Follath 0:1f7c5025e59d 195
Janos Follath 0:1f7c5025e59d 196 static volatile int alarmed;
Janos Follath 0:1f7c5025e59d 197 static void alarm() { alarmed = 1; }
Janos Follath 0:1f7c5025e59d 198
Janos Follath 0:1f7c5025e59d 199 #define TIME_AND_TSC( TITLE, CODE ) \
Janos Follath 0:1f7c5025e59d 200 do { \
Janos Follath 0:1f7c5025e59d 201 unsigned long i, j, tsc; \
Janos Follath 0:1f7c5025e59d 202 Timeout t; \
Janos Follath 0:1f7c5025e59d 203 \
Janos Follath 0:1f7c5025e59d 204 mbedtls_printf( HEADER_FORMAT, TITLE ); \
Janos Follath 0:1f7c5025e59d 205 \
Janos Follath 0:1f7c5025e59d 206 for( i = 1, alarmed = 0, t.attach( alarm, 1.0 ); !alarmed; i++ ) \
Janos Follath 0:1f7c5025e59d 207 { \
Janos Follath 0:1f7c5025e59d 208 CODE; \
Janos Follath 0:1f7c5025e59d 209 } \
Janos Follath 0:1f7c5025e59d 210 \
Janos Follath 0:1f7c5025e59d 211 tsc = mbedtls_timing_hardclock(); \
Janos Follath 0:1f7c5025e59d 212 for( j = 0; j < 1024; j++ ) \
Janos Follath 0:1f7c5025e59d 213 { \
Janos Follath 0:1f7c5025e59d 214 CODE; \
Janos Follath 0:1f7c5025e59d 215 } \
Janos Follath 0:1f7c5025e59d 216 \
Janos Follath 0:1f7c5025e59d 217 mbedtls_printf( "%9lu Kb/s, %9lu cycles/byte\r\n", \
Janos Follath 0:1f7c5025e59d 218 i * BUFSIZE / 1024, \
Janos Follath 0:1f7c5025e59d 219 ( mbedtls_timing_hardclock() - tsc ) / ( j * BUFSIZE ) ); \
Janos Follath 0:1f7c5025e59d 220 } while( 0 )
Janos Follath 0:1f7c5025e59d 221
Janos Follath 0:1f7c5025e59d 222 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG)
Janos Follath 0:1f7c5025e59d 223
Janos Follath 0:1f7c5025e59d 224 #define MEMORY_MEASURE_INIT \
Janos Follath 0:1f7c5025e59d 225 size_t max_used, max_blocks, max_bytes; \
Janos Follath 0:1f7c5025e59d 226 size_t prv_used, prv_blocks; \
Janos Follath 0:1f7c5025e59d 227 mbedtls_memory_buffer_alloc_cur_get( &prv_used, &prv_blocks ); \
Janos Follath 0:1f7c5025e59d 228 mbedtls_memory_buffer_alloc_max_reset( );
Janos Follath 0:1f7c5025e59d 229
Janos Follath 0:1f7c5025e59d 230 #define MEMORY_MEASURE_PRINT( title_len ) \
Janos Follath 0:1f7c5025e59d 231 mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \
Janos Follath 0:1f7c5025e59d 232 for( i = 12 - title_len; i != 0; i-- ) mbedtls_printf( " " ); \
Janos Follath 0:1f7c5025e59d 233 max_used -= prv_used; \
Janos Follath 0:1f7c5025e59d 234 max_blocks -= prv_blocks; \
Janos Follath 0:1f7c5025e59d 235 max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \
Janos Follath 0:1f7c5025e59d 236 mbedtls_printf( "%6u heap bytes", (unsigned) max_bytes );
Janos Follath 0:1f7c5025e59d 237
Janos Follath 0:1f7c5025e59d 238 #else
Janos Follath 0:1f7c5025e59d 239 #define MEMORY_MEASURE_INIT
Janos Follath 0:1f7c5025e59d 240 #define MEMORY_MEASURE_PRINT( title_len )
Janos Follath 0:1f7c5025e59d 241 #endif
Janos Follath 0:1f7c5025e59d 242
Janos Follath 0:1f7c5025e59d 243 #define TIME_PUBLIC( TITLE, TYPE, CODE ) \
Janos Follath 0:1f7c5025e59d 244 do { \
Janos Follath 0:1f7c5025e59d 245 unsigned long ms; \
Janos Follath 0:1f7c5025e59d 246 int ret = 0; \
Janos Follath 0:1f7c5025e59d 247 Timer t; \
Janos Follath 0:1f7c5025e59d 248 MEMORY_MEASURE_INIT; \
Janos Follath 0:1f7c5025e59d 249 \
Janos Follath 0:1f7c5025e59d 250 mbedtls_printf( HEADER_FORMAT, TITLE ); \
Janos Follath 0:1f7c5025e59d 251 fflush( stdout ); \
Janos Follath 0:1f7c5025e59d 252 \
Janos Follath 0:1f7c5025e59d 253 t.start(); \
Janos Follath 0:1f7c5025e59d 254 CODE; \
Janos Follath 0:1f7c5025e59d 255 t.stop(); \
Janos Follath 0:1f7c5025e59d 256 ms = t.read_ms(); \
Janos Follath 0:1f7c5025e59d 257 \
Janos Follath 0:1f7c5025e59d 258 if( ret != 0 ) \
Janos Follath 0:1f7c5025e59d 259 { \
Janos Follath 0:1f7c5025e59d 260 PRINT_ERROR; \
Janos Follath 0:1f7c5025e59d 261 } \
Janos Follath 0:1f7c5025e59d 262 else \
Janos Follath 0:1f7c5025e59d 263 { \
Janos Follath 0:1f7c5025e59d 264 mbedtls_printf( "%6lu ms/" TYPE, ms ); \
Janos Follath 0:1f7c5025e59d 265 MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 ); \
Janos Follath 0:1f7c5025e59d 266 mbedtls_printf( "\r\n" ); \
Janos Follath 0:1f7c5025e59d 267 } \
Janos Follath 0:1f7c5025e59d 268 } while( 0 )
Janos Follath 0:1f7c5025e59d 269
Janos Follath 0:1f7c5025e59d 270 static int myrand( void *rng_state, unsigned char *output, size_t len )
Janos Follath 0:1f7c5025e59d 271 {
Janos Follath 0:1f7c5025e59d 272 size_t use_len;
Janos Follath 0:1f7c5025e59d 273 int rnd;
Janos Follath 0:1f7c5025e59d 274
Janos Follath 0:1f7c5025e59d 275 if( rng_state != NULL )
Janos Follath 0:1f7c5025e59d 276 rng_state = NULL;
Janos Follath 0:1f7c5025e59d 277
Janos Follath 0:1f7c5025e59d 278 while( len > 0 )
Janos Follath 0:1f7c5025e59d 279 {
Janos Follath 0:1f7c5025e59d 280 use_len = len;
Janos Follath 0:1f7c5025e59d 281 if( use_len > sizeof(int) )
Janos Follath 0:1f7c5025e59d 282 use_len = sizeof(int);
Janos Follath 0:1f7c5025e59d 283
Janos Follath 0:1f7c5025e59d 284 rnd = rand();
Janos Follath 0:1f7c5025e59d 285 memcpy( output, &rnd, use_len );
Janos Follath 0:1f7c5025e59d 286 output += use_len;
Janos Follath 0:1f7c5025e59d 287 len -= use_len;
Janos Follath 0:1f7c5025e59d 288 }
Janos Follath 0:1f7c5025e59d 289
Janos Follath 0:1f7c5025e59d 290 return( 0 );
Janos Follath 0:1f7c5025e59d 291 }
Janos Follath 0:1f7c5025e59d 292
Janos Follath 0:1f7c5025e59d 293 /*
Janos Follath 0:1f7c5025e59d 294 * Clear some memory that was used to prepare the context
Janos Follath 0:1f7c5025e59d 295 */
Janos Follath 0:1f7c5025e59d 296 #if defined(MBEDTLS_ECP_C)
Janos Follath 0:1f7c5025e59d 297 void ecp_clear_precomputed( mbedtls_ecp_group *grp )
Janos Follath 0:1f7c5025e59d 298 {
Janos Follath 0:1f7c5025e59d 299 if( grp->T != NULL )
Janos Follath 0:1f7c5025e59d 300 {
Janos Follath 0:1f7c5025e59d 301 size_t i;
Janos Follath 0:1f7c5025e59d 302 for( i = 0; i < grp->T_size; i++ )
Janos Follath 0:1f7c5025e59d 303 mbedtls_ecp_point_free( &grp->T[i] );
Janos Follath 0:1f7c5025e59d 304 mbedtls_free( grp->T );
Janos Follath 0:1f7c5025e59d 305 }
Janos Follath 0:1f7c5025e59d 306 grp->T = NULL;
Janos Follath 0:1f7c5025e59d 307 grp->T_size = 0;
Janos Follath 0:1f7c5025e59d 308 }
Janos Follath 0:1f7c5025e59d 309 #else
Janos Follath 0:1f7c5025e59d 310 #define ecp_clear_precomputed( g )
Janos Follath 0:1f7c5025e59d 311 #endif
Janos Follath 0:1f7c5025e59d 312
Janos Follath 0:1f7c5025e59d 313 unsigned char buf[BUFSIZE];
Janos Follath 0:1f7c5025e59d 314
Janos Follath 0:1f7c5025e59d 315 typedef struct {
Janos Follath 0:1f7c5025e59d 316 char md4, md5, ripemd160, sha1, sha256, sha512,
mbed_official 30:e0ea8c1ef9f5 317 arc4, des3, des, aes_cbc, aes_ctr, aes_gcm, aes_ccm,
mbed_official 11:6ccae3ebafd5 318 aes_cmac, des3_cmac, camellia, blowfish,
Janos Follath 0:1f7c5025e59d 319 havege, ctr_drbg, hmac_drbg,
Janos Follath 0:1f7c5025e59d 320 rsa, dhm, ecdsa, ecdh;
Janos Follath 0:1f7c5025e59d 321 } todo_list;
Janos Follath 0:1f7c5025e59d 322
Janos Follath 0:1f7c5025e59d 323 static int benchmark( int argc, char *argv[] )
Janos Follath 0:1f7c5025e59d 324 {
Janos Follath 0:1f7c5025e59d 325 int i;
Janos Follath 0:1f7c5025e59d 326 unsigned char tmp[200];
Janos Follath 0:1f7c5025e59d 327 char title[TITLE_LEN];
Janos Follath 0:1f7c5025e59d 328 todo_list todo;
Janos Follath 0:1f7c5025e59d 329 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Janos Follath 0:1f7c5025e59d 330 unsigned char malloc_buf[HEAP_SIZE] = { 0 };
Janos Follath 0:1f7c5025e59d 331 #endif
Janos Follath 0:1f7c5025e59d 332
Janos Follath 0:1f7c5025e59d 333 if( argc <= 1 )
Janos Follath 0:1f7c5025e59d 334 {
Janos Follath 0:1f7c5025e59d 335 memset( &todo, 1, sizeof( todo ) );
Janos Follath 0:1f7c5025e59d 336 }
Janos Follath 0:1f7c5025e59d 337 else
Janos Follath 0:1f7c5025e59d 338 {
Janos Follath 0:1f7c5025e59d 339 memset( &todo, 0, sizeof( todo ) );
Janos Follath 0:1f7c5025e59d 340
Janos Follath 0:1f7c5025e59d 341 for( i = 1; i < argc; i++ )
Janos Follath 0:1f7c5025e59d 342 {
Janos Follath 0:1f7c5025e59d 343 if( strcmp( argv[i], "md4" ) == 0 )
Janos Follath 0:1f7c5025e59d 344 todo.md4 = 1;
Janos Follath 0:1f7c5025e59d 345 else if( strcmp( argv[i], "md5" ) == 0 )
Janos Follath 0:1f7c5025e59d 346 todo.md5 = 1;
Janos Follath 0:1f7c5025e59d 347 else if( strcmp( argv[i], "ripemd160" ) == 0 )
Janos Follath 0:1f7c5025e59d 348 todo.ripemd160 = 1;
Janos Follath 0:1f7c5025e59d 349 else if( strcmp( argv[i], "sha1" ) == 0 )
Janos Follath 0:1f7c5025e59d 350 todo.sha1 = 1;
Janos Follath 0:1f7c5025e59d 351 else if( strcmp( argv[i], "sha256" ) == 0 )
Janos Follath 0:1f7c5025e59d 352 todo.sha256 = 1;
Janos Follath 0:1f7c5025e59d 353 else if( strcmp( argv[i], "sha512" ) == 0 )
Janos Follath 0:1f7c5025e59d 354 todo.sha512 = 1;
Janos Follath 0:1f7c5025e59d 355 else if( strcmp( argv[i], "arc4" ) == 0 )
Janos Follath 0:1f7c5025e59d 356 todo.arc4 = 1;
Janos Follath 0:1f7c5025e59d 357 else if( strcmp( argv[i], "des3" ) == 0 )
Janos Follath 0:1f7c5025e59d 358 todo.des3 = 1;
Janos Follath 0:1f7c5025e59d 359 else if( strcmp( argv[i], "des" ) == 0 )
Janos Follath 0:1f7c5025e59d 360 todo.des = 1;
Janos Follath 0:1f7c5025e59d 361 else if( strcmp( argv[i], "aes_cbc" ) == 0 )
Janos Follath 0:1f7c5025e59d 362 todo.aes_cbc = 1;
mbed_official 30:e0ea8c1ef9f5 363 else if( strcmp( argv[i], "aes_ctr" ) == 0 )
mbed_official 30:e0ea8c1ef9f5 364 todo.aes_ctr = 1;
Janos Follath 0:1f7c5025e59d 365 else if( strcmp( argv[i], "aes_gcm" ) == 0 )
Janos Follath 0:1f7c5025e59d 366 todo.aes_gcm = 1;
Janos Follath 0:1f7c5025e59d 367 else if( strcmp( argv[i], "aes_ccm" ) == 0 )
Janos Follath 0:1f7c5025e59d 368 todo.aes_ccm = 1;
mbed_official 11:6ccae3ebafd5 369 else if( strcmp( argv[i], "aes_cmac" ) == 0 )
mbed_official 11:6ccae3ebafd5 370 todo.aes_cmac = 1;
mbed_official 11:6ccae3ebafd5 371 else if( strcmp( argv[i], "des3_cmac" ) == 0 )
mbed_official 11:6ccae3ebafd5 372 todo.des3_cmac = 1;
Janos Follath 0:1f7c5025e59d 373 else if( strcmp( argv[i], "camellia" ) == 0 )
Janos Follath 0:1f7c5025e59d 374 todo.camellia = 1;
Janos Follath 0:1f7c5025e59d 375 else if( strcmp( argv[i], "blowfish" ) == 0 )
Janos Follath 0:1f7c5025e59d 376 todo.blowfish = 1;
Janos Follath 0:1f7c5025e59d 377 else if( strcmp( argv[i], "havege" ) == 0 )
Janos Follath 0:1f7c5025e59d 378 todo.havege = 1;
Janos Follath 0:1f7c5025e59d 379 else if( strcmp( argv[i], "ctr_drbg" ) == 0 )
Janos Follath 0:1f7c5025e59d 380 todo.ctr_drbg = 1;
Janos Follath 0:1f7c5025e59d 381 else if( strcmp( argv[i], "hmac_drbg" ) == 0 )
Janos Follath 0:1f7c5025e59d 382 todo.hmac_drbg = 1;
Janos Follath 0:1f7c5025e59d 383 else if( strcmp( argv[i], "rsa" ) == 0 )
Janos Follath 0:1f7c5025e59d 384 todo.rsa = 1;
Janos Follath 0:1f7c5025e59d 385 else if( strcmp( argv[i], "dhm" ) == 0 )
Janos Follath 0:1f7c5025e59d 386 todo.dhm = 1;
Janos Follath 0:1f7c5025e59d 387 else if( strcmp( argv[i], "ecdsa" ) == 0 )
Janos Follath 0:1f7c5025e59d 388 todo.ecdsa = 1;
Janos Follath 0:1f7c5025e59d 389 else if( strcmp( argv[i], "ecdh" ) == 0 )
Janos Follath 0:1f7c5025e59d 390 todo.ecdh = 1;
Janos Follath 0:1f7c5025e59d 391 else
Janos Follath 0:1f7c5025e59d 392 {
Janos Follath 0:1f7c5025e59d 393 mbedtls_printf( "Unrecognized option: %s\r\n", argv[i] );
Janos Follath 0:1f7c5025e59d 394 mbedtls_printf( "Available options: " OPTIONS );
Janos Follath 0:1f7c5025e59d 395 }
Janos Follath 0:1f7c5025e59d 396 }
Janos Follath 0:1f7c5025e59d 397 }
Janos Follath 0:1f7c5025e59d 398
Janos Follath 0:1f7c5025e59d 399 mbedtls_printf( "\r\n\r\n" );
Janos Follath 0:1f7c5025e59d 400
Janos Follath 0:1f7c5025e59d 401 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Janos Follath 0:1f7c5025e59d 402 mbedtls_memory_buffer_alloc_init( malloc_buf, sizeof( malloc_buf ) );
Janos Follath 0:1f7c5025e59d 403 #endif
Janos Follath 0:1f7c5025e59d 404 memset( buf, 0xAA, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 405 memset( tmp, 0xBB, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 406
Janos Follath 0:1f7c5025e59d 407 #if defined(MBEDTLS_MD4_C)
Janos Follath 0:1f7c5025e59d 408 if( todo.md4 )
Janos Follath 0:1f7c5025e59d 409 TIME_AND_TSC( "MD4", mbedtls_md4( buf, BUFSIZE, tmp ) );
Janos Follath 0:1f7c5025e59d 410 #endif
Janos Follath 0:1f7c5025e59d 411
Janos Follath 0:1f7c5025e59d 412 #if defined(MBEDTLS_MD5_C)
Janos Follath 0:1f7c5025e59d 413 if( todo.md5 )
Janos Follath 0:1f7c5025e59d 414 TIME_AND_TSC( "MD5", mbedtls_md5( buf, BUFSIZE, tmp ) );
Janos Follath 0:1f7c5025e59d 415 #endif
Janos Follath 0:1f7c5025e59d 416
Janos Follath 0:1f7c5025e59d 417 #if defined(MBEDTLS_RIPEMD160_C)
Janos Follath 0:1f7c5025e59d 418 if( todo.ripemd160 )
Janos Follath 0:1f7c5025e59d 419 TIME_AND_TSC( "RIPEMD160", mbedtls_ripemd160( buf, BUFSIZE, tmp ) );
Janos Follath 0:1f7c5025e59d 420 #endif
Janos Follath 0:1f7c5025e59d 421
Janos Follath 0:1f7c5025e59d 422 #if defined(MBEDTLS_SHA1_C)
Janos Follath 0:1f7c5025e59d 423 if( todo.sha1 )
Janos Follath 0:1f7c5025e59d 424 TIME_AND_TSC( "SHA-1", mbedtls_sha1( buf, BUFSIZE, tmp ) );
Janos Follath 0:1f7c5025e59d 425 #endif
Janos Follath 0:1f7c5025e59d 426
Janos Follath 0:1f7c5025e59d 427 #if defined(MBEDTLS_SHA256_C)
Janos Follath 0:1f7c5025e59d 428 if( todo.sha256 )
Janos Follath 0:1f7c5025e59d 429 TIME_AND_TSC( "SHA-256", mbedtls_sha256( buf, BUFSIZE, tmp, 0 ) );
Janos Follath 0:1f7c5025e59d 430 #endif
Janos Follath 0:1f7c5025e59d 431
Janos Follath 0:1f7c5025e59d 432 #if defined(MBEDTLS_SHA512_C)
Janos Follath 0:1f7c5025e59d 433 if( todo.sha512 )
Janos Follath 0:1f7c5025e59d 434 TIME_AND_TSC( "SHA-512", mbedtls_sha512( buf, BUFSIZE, tmp, 0 ) );
Janos Follath 0:1f7c5025e59d 435 #endif
Janos Follath 0:1f7c5025e59d 436
Janos Follath 0:1f7c5025e59d 437 #if defined(MBEDTLS_ARC4_C)
Janos Follath 0:1f7c5025e59d 438 if( todo.arc4 )
Janos Follath 0:1f7c5025e59d 439 {
Janos Follath 0:1f7c5025e59d 440 mbedtls_arc4_context arc4;
Janos Follath 0:1f7c5025e59d 441 mbedtls_arc4_init( &arc4 );
Janos Follath 0:1f7c5025e59d 442 mbedtls_arc4_setup( &arc4, tmp, 32 );
Janos Follath 0:1f7c5025e59d 443 TIME_AND_TSC( "ARC4", mbedtls_arc4_crypt( &arc4, BUFSIZE, buf, buf ) );
Janos Follath 0:1f7c5025e59d 444 mbedtls_arc4_free( &arc4 );
Janos Follath 0:1f7c5025e59d 445 }
Janos Follath 0:1f7c5025e59d 446 #endif
Janos Follath 0:1f7c5025e59d 447
Janos Follath 0:1f7c5025e59d 448 #if defined(MBEDTLS_DES_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
Janos Follath 0:1f7c5025e59d 449 if( todo.des3 )
Janos Follath 0:1f7c5025e59d 450 {
Janos Follath 0:1f7c5025e59d 451 mbedtls_des3_context des3;
Janos Follath 0:1f7c5025e59d 452 mbedtls_des3_init( &des3 );
Janos Follath 0:1f7c5025e59d 453 mbedtls_des3_set3key_enc( &des3, tmp );
Janos Follath 0:1f7c5025e59d 454 TIME_AND_TSC( "3DES",
Janos Follath 0:1f7c5025e59d 455 mbedtls_des3_crypt_cbc( &des3, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 456 mbedtls_des3_free( &des3 );
Janos Follath 0:1f7c5025e59d 457 }
Janos Follath 0:1f7c5025e59d 458
Janos Follath 0:1f7c5025e59d 459 if( todo.des )
Janos Follath 0:1f7c5025e59d 460 {
Janos Follath 0:1f7c5025e59d 461 mbedtls_des_context des;
Janos Follath 0:1f7c5025e59d 462 mbedtls_des_init( &des );
Janos Follath 0:1f7c5025e59d 463 mbedtls_des_setkey_enc( &des, tmp );
Janos Follath 0:1f7c5025e59d 464 TIME_AND_TSC( "DES",
Janos Follath 0:1f7c5025e59d 465 mbedtls_des_crypt_cbc( &des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 466 mbedtls_des_free( &des );
Janos Follath 0:1f7c5025e59d 467 }
mbed_official 11:6ccae3ebafd5 468 #if defined(MBEDTLS_CMAC_C)
mbed_official 11:6ccae3ebafd5 469 if( todo.des3_cmac )
mbed_official 11:6ccae3ebafd5 470 {
mbed_official 11:6ccae3ebafd5 471 unsigned char output[8];
mbed_official 11:6ccae3ebafd5 472 const mbedtls_cipher_info_t *cipher_info;
mbed_official 11:6ccae3ebafd5 473
mbed_official 11:6ccae3ebafd5 474 memset( buf, 0, sizeof( buf ) );
mbed_official 11:6ccae3ebafd5 475 memset( tmp, 0, sizeof( tmp ) );
mbed_official 11:6ccae3ebafd5 476
mbed_official 11:6ccae3ebafd5 477 cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_DES_EDE3_ECB );
mbed_official 11:6ccae3ebafd5 478
mbed_official 11:6ccae3ebafd5 479 TIME_AND_TSC( "3DES-CMAC",
mbed_official 11:6ccae3ebafd5 480 mbedtls_cipher_cmac( cipher_info, tmp, 192, buf,
mbed_official 11:6ccae3ebafd5 481 BUFSIZE, output ) );
mbed_official 11:6ccae3ebafd5 482 }
mbed_official 11:6ccae3ebafd5 483 #endif /* MBEDTLS_CMAC_C */
Janos Follath 0:1f7c5025e59d 484 #endif
Janos Follath 0:1f7c5025e59d 485
Janos Follath 0:1f7c5025e59d 486 #if defined(MBEDTLS_AES_C)
Janos Follath 0:1f7c5025e59d 487 #if defined(MBEDTLS_CIPHER_MODE_CBC)
Janos Follath 0:1f7c5025e59d 488 if( todo.aes_cbc )
Janos Follath 0:1f7c5025e59d 489 {
Janos Follath 0:1f7c5025e59d 490 int keysize;
Janos Follath 0:1f7c5025e59d 491 mbedtls_aes_context aes;
Janos Follath 0:1f7c5025e59d 492 mbedtls_aes_init( &aes );
Janos Follath 0:1f7c5025e59d 493 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 494 {
Janos Follath 0:1f7c5025e59d 495 mbedtls_snprintf( title, sizeof( title ), "AES-CBC-%d", keysize );
Janos Follath 0:1f7c5025e59d 496
Janos Follath 0:1f7c5025e59d 497 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 498 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 499 mbedtls_aes_setkey_enc( &aes, tmp, keysize );
Janos Follath 0:1f7c5025e59d 500
Janos Follath 0:1f7c5025e59d 501 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 502 mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 503 }
Janos Follath 0:1f7c5025e59d 504 mbedtls_aes_free( &aes );
Janos Follath 0:1f7c5025e59d 505 }
Janos Follath 0:1f7c5025e59d 506 #endif
mbed_official 30:e0ea8c1ef9f5 507
mbed_official 30:e0ea8c1ef9f5 508 #if defined(MBEDTLS_CIPHER_MODE_CTR)
mbed_official 30:e0ea8c1ef9f5 509 if( todo.aes_ctr )
mbed_official 30:e0ea8c1ef9f5 510 {
mbed_official 30:e0ea8c1ef9f5 511 int keysize;
mbed_official 30:e0ea8c1ef9f5 512 size_t nc_offset = 0;
mbed_official 30:e0ea8c1ef9f5 513 unsigned char stream_block[16];
mbed_official 30:e0ea8c1ef9f5 514 mbedtls_aes_context aes;
mbed_official 30:e0ea8c1ef9f5 515 mbedtls_aes_init( &aes );
mbed_official 30:e0ea8c1ef9f5 516 for( keysize = 128; keysize <= 256; keysize += 64 )
mbed_official 30:e0ea8c1ef9f5 517 {
mbed_official 30:e0ea8c1ef9f5 518 mbedtls_snprintf( title, sizeof( title ), "AES-CTR-%d", keysize );
mbed_official 30:e0ea8c1ef9f5 519
mbed_official 30:e0ea8c1ef9f5 520 memset( buf, 0, sizeof( buf ) );
mbed_official 30:e0ea8c1ef9f5 521 memset( tmp, 0, sizeof( tmp ) );
mbed_official 30:e0ea8c1ef9f5 522 mbedtls_aes_setkey_enc( &aes, tmp, keysize );
mbed_official 30:e0ea8c1ef9f5 523
mbed_official 30:e0ea8c1ef9f5 524 TIME_AND_TSC( title,
mbed_official 30:e0ea8c1ef9f5 525 mbedtls_aes_crypt_ctr( &aes, BUFSIZE, &nc_offset, tmp, stream_block, buf, buf ) );
mbed_official 30:e0ea8c1ef9f5 526 }
mbed_official 30:e0ea8c1ef9f5 527 mbedtls_aes_free( &aes );
mbed_official 30:e0ea8c1ef9f5 528 }
mbed_official 30:e0ea8c1ef9f5 529 #endif
mbed_official 30:e0ea8c1ef9f5 530
Janos Follath 0:1f7c5025e59d 531 #if defined(MBEDTLS_GCM_C)
Janos Follath 0:1f7c5025e59d 532 if( todo.aes_gcm )
Janos Follath 0:1f7c5025e59d 533 {
Janos Follath 0:1f7c5025e59d 534 int keysize;
Janos Follath 0:1f7c5025e59d 535 mbedtls_gcm_context gcm;
Janos Follath 0:1f7c5025e59d 536
Janos Follath 0:1f7c5025e59d 537 mbedtls_gcm_init( &gcm );
Janos Follath 0:1f7c5025e59d 538 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 539 {
Janos Follath 0:1f7c5025e59d 540 mbedtls_snprintf( title, sizeof( title ), "AES-GCM-%d", keysize );
Janos Follath 0:1f7c5025e59d 541
Janos Follath 0:1f7c5025e59d 542 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 543 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 544 mbedtls_gcm_setkey( &gcm, MBEDTLS_CIPHER_ID_AES, tmp, keysize );
Janos Follath 0:1f7c5025e59d 545
Janos Follath 0:1f7c5025e59d 546 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 547 mbedtls_gcm_crypt_and_tag( &gcm, MBEDTLS_GCM_ENCRYPT, BUFSIZE, tmp,
Janos Follath 0:1f7c5025e59d 548 12, NULL, 0, buf, buf, 16, tmp ) );
Janos Follath 0:1f7c5025e59d 549
Janos Follath 0:1f7c5025e59d 550 mbedtls_gcm_free( &gcm );
Janos Follath 0:1f7c5025e59d 551 }
Janos Follath 0:1f7c5025e59d 552 }
Janos Follath 0:1f7c5025e59d 553 #endif
Janos Follath 0:1f7c5025e59d 554 #if defined(MBEDTLS_CCM_C)
Janos Follath 0:1f7c5025e59d 555 if( todo.aes_ccm )
Janos Follath 0:1f7c5025e59d 556 {
Janos Follath 0:1f7c5025e59d 557 int keysize;
Janos Follath 0:1f7c5025e59d 558 mbedtls_ccm_context ccm;
Janos Follath 0:1f7c5025e59d 559
Janos Follath 0:1f7c5025e59d 560 mbedtls_ccm_init( &ccm );
Janos Follath 0:1f7c5025e59d 561 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 562 {
Janos Follath 0:1f7c5025e59d 563 mbedtls_snprintf( title, sizeof( title ), "AES-CCM-%d", keysize );
Janos Follath 0:1f7c5025e59d 564
Janos Follath 0:1f7c5025e59d 565 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 566 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 567 mbedtls_ccm_setkey( &ccm, MBEDTLS_CIPHER_ID_AES, tmp, keysize );
Janos Follath 0:1f7c5025e59d 568
Janos Follath 0:1f7c5025e59d 569 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 570 mbedtls_ccm_encrypt_and_tag( &ccm, BUFSIZE, tmp,
Janos Follath 0:1f7c5025e59d 571 12, NULL, 0, buf, buf, tmp, 16 ) );
Janos Follath 0:1f7c5025e59d 572
Janos Follath 0:1f7c5025e59d 573 mbedtls_ccm_free( &ccm );
Janos Follath 0:1f7c5025e59d 574 }
Janos Follath 0:1f7c5025e59d 575 }
Janos Follath 0:1f7c5025e59d 576 #endif
mbed_official 11:6ccae3ebafd5 577 #if defined(MBEDTLS_CMAC_C)
mbed_official 11:6ccae3ebafd5 578 if( todo.aes_cmac )
mbed_official 11:6ccae3ebafd5 579 {
mbed_official 11:6ccae3ebafd5 580 unsigned char output[16];
mbed_official 11:6ccae3ebafd5 581 const mbedtls_cipher_info_t *cipher_info;
mbed_official 11:6ccae3ebafd5 582 mbedtls_cipher_type_t cipher_type;
mbed_official 11:6ccae3ebafd5 583 int keysize;
mbed_official 11:6ccae3ebafd5 584
mbed_official 11:6ccae3ebafd5 585 cipher_type = MBEDTLS_CIPHER_AES_128_ECB;
mbed_official 11:6ccae3ebafd5 586 for( keysize = 128; keysize <= 256; keysize += 64 )
mbed_official 11:6ccae3ebafd5 587 {
mbed_official 11:6ccae3ebafd5 588 mbedtls_snprintf( title, sizeof( title ), "AES-CMAC-%d", keysize );
mbed_official 11:6ccae3ebafd5 589
mbed_official 11:6ccae3ebafd5 590 memset( buf, 0, sizeof( buf ) );
mbed_official 11:6ccae3ebafd5 591 memset( tmp, 0, sizeof( tmp ) );
mbed_official 11:6ccae3ebafd5 592
mbed_official 11:6ccae3ebafd5 593 cipher_info = mbedtls_cipher_info_from_type( cipher_type );
mbed_official 11:6ccae3ebafd5 594
mbed_official 11:6ccae3ebafd5 595 TIME_AND_TSC( title,
mbed_official 11:6ccae3ebafd5 596 mbedtls_cipher_cmac( cipher_info, tmp, keysize,
mbed_official 11:6ccae3ebafd5 597 buf, BUFSIZE, output ) );
mbed_official 11:6ccae3ebafd5 598 cipher_type = (mbedtls_cipher_type_t)( cipher_type + 1 );
mbed_official 11:6ccae3ebafd5 599 }
mbed_official 11:6ccae3ebafd5 600
mbed_official 11:6ccae3ebafd5 601 memset( buf, 0, sizeof( buf ) );
mbed_official 11:6ccae3ebafd5 602 memset( tmp, 0, sizeof( tmp ) );
mbed_official 11:6ccae3ebafd5 603 TIME_AND_TSC( "AES-CMAC-PRF-128",
mbed_official 11:6ccae3ebafd5 604 mbedtls_aes_cmac_prf_128( tmp, 16, buf, BUFSIZE,
mbed_official 11:6ccae3ebafd5 605 output ) );
mbed_official 11:6ccae3ebafd5 606 }
mbed_official 11:6ccae3ebafd5 607 #endif /* MBEDTLS_CMAC_C */
Janos Follath 0:1f7c5025e59d 608 #endif
Janos Follath 0:1f7c5025e59d 609
Janos Follath 0:1f7c5025e59d 610 #if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
Janos Follath 0:1f7c5025e59d 611 if( todo.camellia )
Janos Follath 0:1f7c5025e59d 612 {
Janos Follath 0:1f7c5025e59d 613 int keysize;
Janos Follath 0:1f7c5025e59d 614 mbedtls_camellia_context camellia;
Janos Follath 0:1f7c5025e59d 615 mbedtls_camellia_init( &camellia );
Janos Follath 0:1f7c5025e59d 616 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 617 {
Janos Follath 0:1f7c5025e59d 618 mbedtls_snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize );
Janos Follath 0:1f7c5025e59d 619
Janos Follath 0:1f7c5025e59d 620 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 621 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 622 mbedtls_camellia_setkey_enc( &camellia, tmp, keysize );
Janos Follath 0:1f7c5025e59d 623
Janos Follath 0:1f7c5025e59d 624 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 625 mbedtls_camellia_crypt_cbc( &camellia, MBEDTLS_CAMELLIA_ENCRYPT,
Janos Follath 0:1f7c5025e59d 626 BUFSIZE, tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 627 }
Janos Follath 0:1f7c5025e59d 628 mbedtls_camellia_free( &camellia );
Janos Follath 0:1f7c5025e59d 629 }
Janos Follath 0:1f7c5025e59d 630 #endif
Janos Follath 0:1f7c5025e59d 631
Janos Follath 0:1f7c5025e59d 632 #if defined(MBEDTLS_BLOWFISH_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
Janos Follath 0:1f7c5025e59d 633 if( todo.blowfish )
Janos Follath 0:1f7c5025e59d 634 {
Janos Follath 0:1f7c5025e59d 635 int keysize;
Janos Follath 0:1f7c5025e59d 636 mbedtls_blowfish_context blowfish;
Janos Follath 0:1f7c5025e59d 637 mbedtls_blowfish_init( &blowfish );
Janos Follath 0:1f7c5025e59d 638
Janos Follath 0:1f7c5025e59d 639 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 640 {
Janos Follath 0:1f7c5025e59d 641 mbedtls_snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize );
Janos Follath 0:1f7c5025e59d 642
Janos Follath 0:1f7c5025e59d 643 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 644 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 645 mbedtls_blowfish_setkey( &blowfish, tmp, keysize );
Janos Follath 0:1f7c5025e59d 646
Janos Follath 0:1f7c5025e59d 647 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 648 mbedtls_blowfish_crypt_cbc( &blowfish, MBEDTLS_BLOWFISH_ENCRYPT, BUFSIZE,
Janos Follath 0:1f7c5025e59d 649 tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 650 }
Janos Follath 0:1f7c5025e59d 651
Janos Follath 0:1f7c5025e59d 652 mbedtls_blowfish_free( &blowfish );
Janos Follath 0:1f7c5025e59d 653 }
Janos Follath 0:1f7c5025e59d 654 #endif
Janos Follath 0:1f7c5025e59d 655
Janos Follath 0:1f7c5025e59d 656 #if defined(MBEDTLS_HAVEGE_C)
Janos Follath 0:1f7c5025e59d 657 if( todo.havege )
Janos Follath 0:1f7c5025e59d 658 {
Janos Follath 0:1f7c5025e59d 659 mbedtls_havege_state hs;
Janos Follath 0:1f7c5025e59d 660 mbedtls_havege_init( &hs );
Janos Follath 0:1f7c5025e59d 661 TIME_AND_TSC( "HAVEGE", mbedtls_havege_random( &hs, buf, BUFSIZE ) );
Janos Follath 0:1f7c5025e59d 662 mbedtls_havege_free( &hs );
Janos Follath 0:1f7c5025e59d 663 }
Janos Follath 0:1f7c5025e59d 664 #endif
Janos Follath 0:1f7c5025e59d 665
Janos Follath 0:1f7c5025e59d 666 #if defined(MBEDTLS_CTR_DRBG_C)
Janos Follath 0:1f7c5025e59d 667 if( todo.ctr_drbg )
Janos Follath 0:1f7c5025e59d 668 {
Janos Follath 0:1f7c5025e59d 669 mbedtls_ctr_drbg_context ctr_drbg;
Janos Follath 0:1f7c5025e59d 670
Janos Follath 0:1f7c5025e59d 671 mbedtls_ctr_drbg_init( &ctr_drbg );
Janos Follath 0:1f7c5025e59d 672
Janos Follath 0:1f7c5025e59d 673 if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
Janos Follath 0:1f7c5025e59d 674 mbedtls_exit(1);
Janos Follath 0:1f7c5025e59d 675 TIME_AND_TSC( "CTR_DRBG (NOPR)",
Janos Follath 0:1f7c5025e59d 676 if( mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
Janos Follath 0:1f7c5025e59d 677 mbedtls_exit(1) );
Janos Follath 0:1f7c5025e59d 678
Janos Follath 0:1f7c5025e59d 679 if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
Janos Follath 0:1f7c5025e59d 680 mbedtls_exit(1);
Janos Follath 0:1f7c5025e59d 681 mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON );
Janos Follath 0:1f7c5025e59d 682 TIME_AND_TSC( "CTR_DRBG (PR)",
Janos Follath 0:1f7c5025e59d 683 if( mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
Janos Follath 0:1f7c5025e59d 684 mbedtls_exit(1) );
Janos Follath 0:1f7c5025e59d 685 mbedtls_ctr_drbg_free( &ctr_drbg );
Janos Follath 0:1f7c5025e59d 686 }
Janos Follath 0:1f7c5025e59d 687 #endif
Janos Follath 0:1f7c5025e59d 688
Janos Follath 0:1f7c5025e59d 689 #if defined(MBEDTLS_HMAC_DRBG_C)
Janos Follath 0:1f7c5025e59d 690 if( todo.hmac_drbg )
Janos Follath 0:1f7c5025e59d 691 {
Janos Follath 0:1f7c5025e59d 692 mbedtls_hmac_drbg_context hmac_drbg;
Janos Follath 0:1f7c5025e59d 693 const mbedtls_md_info_t *md_info;
Janos Follath 0:1f7c5025e59d 694
Janos Follath 0:1f7c5025e59d 695 mbedtls_hmac_drbg_init( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 696
Janos Follath 0:1f7c5025e59d 697 #if defined(MBEDTLS_SHA1_C)
Janos Follath 0:1f7c5025e59d 698 if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 ) ) == NULL )
Janos Follath 0:1f7c5025e59d 699 mbedtls_exit(1);
Janos Follath 0:1f7c5025e59d 700
Janos Follath 0:1f7c5025e59d 701 if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
Janos Follath 0:1f7c5025e59d 702 mbedtls_exit(1);
Janos Follath 0:1f7c5025e59d 703 TIME_AND_TSC( "HMAC_DRBG SHA-1 (NOPR)",
Janos Follath 0:1f7c5025e59d 704 if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
Janos Follath 0:1f7c5025e59d 705 mbedtls_exit(1) );
Janos Follath 0:1f7c5025e59d 706 mbedtls_hmac_drbg_free( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 707
Janos Follath 0:1f7c5025e59d 708 if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
Janos Follath 0:1f7c5025e59d 709 mbedtls_exit(1);
Janos Follath 0:1f7c5025e59d 710 mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg,
Janos Follath 0:1f7c5025e59d 711 MBEDTLS_HMAC_DRBG_PR_ON );
Janos Follath 0:1f7c5025e59d 712 TIME_AND_TSC( "HMAC_DRBG SHA-1 (PR)",
Janos Follath 0:1f7c5025e59d 713 if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
Janos Follath 0:1f7c5025e59d 714 mbedtls_exit(1) );
Janos Follath 0:1f7c5025e59d 715 mbedtls_hmac_drbg_free( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 716 #endif
Janos Follath 0:1f7c5025e59d 717
Janos Follath 0:1f7c5025e59d 718 #if defined(MBEDTLS_SHA256_C)
Janos Follath 0:1f7c5025e59d 719 if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ) ) == NULL )
Janos Follath 0:1f7c5025e59d 720 mbedtls_exit(1);
Janos Follath 0:1f7c5025e59d 721
Janos Follath 0:1f7c5025e59d 722 if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
Janos Follath 0:1f7c5025e59d 723 mbedtls_exit(1);
Janos Follath 0:1f7c5025e59d 724 TIME_AND_TSC( "HMAC_DRBG SHA-256 (NOPR)",
Janos Follath 0:1f7c5025e59d 725 if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
Janos Follath 0:1f7c5025e59d 726 mbedtls_exit(1) );
Janos Follath 0:1f7c5025e59d 727 mbedtls_hmac_drbg_free( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 728
Janos Follath 0:1f7c5025e59d 729 if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
Janos Follath 0:1f7c5025e59d 730 mbedtls_exit(1);
Janos Follath 0:1f7c5025e59d 731 mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg,
Janos Follath 0:1f7c5025e59d 732 MBEDTLS_HMAC_DRBG_PR_ON );
Janos Follath 0:1f7c5025e59d 733 TIME_AND_TSC( "HMAC_DRBG SHA-256 (PR)",
Janos Follath 0:1f7c5025e59d 734 if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
Janos Follath 0:1f7c5025e59d 735 mbedtls_exit(1) );
Janos Follath 0:1f7c5025e59d 736 mbedtls_hmac_drbg_free( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 737 #endif
Janos Follath 0:1f7c5025e59d 738 }
Janos Follath 0:1f7c5025e59d 739 #endif
Janos Follath 0:1f7c5025e59d 740
Janos Follath 0:1f7c5025e59d 741 #if defined(MBEDTLS_RSA_C) && \
Janos Follath 0:1f7c5025e59d 742 defined(MBEDTLS_PEM_PARSE_C) && defined(MBEDTLS_PK_PARSE_C)
Janos Follath 0:1f7c5025e59d 743 if( todo.rsa )
Janos Follath 0:1f7c5025e59d 744 {
Janos Follath 0:1f7c5025e59d 745 mbedtls_pk_context pk;
Janos Follath 0:1f7c5025e59d 746 mbedtls_rsa_context *rsa;
Janos Follath 0:1f7c5025e59d 747 const char *rsa_keys[] = { RSA_PRIVATE_KEY_2048, RSA_PRIVATE_KEY_4096 };
Janos Follath 0:1f7c5025e59d 748 size_t i;
Janos Follath 0:1f7c5025e59d 749
Janos Follath 0:1f7c5025e59d 750 for( i = 0; i < sizeof( rsa_keys ) / sizeof( rsa_keys[0] ); i++ )
Janos Follath 0:1f7c5025e59d 751 {
Janos Follath 0:1f7c5025e59d 752 mbedtls_pk_init( &pk );
Janos Follath 0:1f7c5025e59d 753 mbedtls_pk_parse_key( &pk, (const unsigned char *) rsa_keys[i],
Janos Follath 0:1f7c5025e59d 754 strlen( rsa_keys[i] ) + 1, NULL, 0 );
Janos Follath 0:1f7c5025e59d 755 rsa = mbedtls_pk_rsa( pk );
Janos Follath 0:1f7c5025e59d 756
Janos Follath 0:1f7c5025e59d 757 mbedtls_snprintf( title, sizeof( title ), "RSA-%d", mbedtls_pk_get_bitlen( &pk ) );
Janos Follath 0:1f7c5025e59d 758
Janos Follath 0:1f7c5025e59d 759 TIME_PUBLIC( title, " public",
Janos Follath 0:1f7c5025e59d 760 buf[0] = 0;
Janos Follath 0:1f7c5025e59d 761 ret = mbedtls_rsa_public( rsa, buf, buf ) );
Janos Follath 0:1f7c5025e59d 762
Janos Follath 0:1f7c5025e59d 763 TIME_PUBLIC( title, "private",
Janos Follath 0:1f7c5025e59d 764 buf[0] = 0;
Janos Follath 0:1f7c5025e59d 765 ret = mbedtls_rsa_private( rsa, myrand, NULL, buf, buf ) );
Janos Follath 0:1f7c5025e59d 766
Janos Follath 0:1f7c5025e59d 767 mbedtls_pk_free( &pk );
Janos Follath 0:1f7c5025e59d 768 }
Janos Follath 0:1f7c5025e59d 769 }
Janos Follath 0:1f7c5025e59d 770 #endif
Janos Follath 0:1f7c5025e59d 771
Janos Follath 0:1f7c5025e59d 772 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_BIGNUM_C)
Janos Follath 0:1f7c5025e59d 773 if( todo.dhm )
Janos Follath 0:1f7c5025e59d 774 {
Janos Follath 0:1f7c5025e59d 775 int dhm_sizes[] = { 2048, 3072 };
Janos Follath 0:1f7c5025e59d 776 const char *dhm_P[] = {
Janos Follath 0:1f7c5025e59d 777 MBEDTLS_DHM_RFC3526_MODP_2048_P,
Janos Follath 0:1f7c5025e59d 778 MBEDTLS_DHM_RFC3526_MODP_3072_P,
Janos Follath 0:1f7c5025e59d 779 };
Janos Follath 0:1f7c5025e59d 780 const char *dhm_G[] = {
Janos Follath 0:1f7c5025e59d 781 MBEDTLS_DHM_RFC3526_MODP_2048_G,
Janos Follath 0:1f7c5025e59d 782 MBEDTLS_DHM_RFC3526_MODP_3072_G,
Janos Follath 0:1f7c5025e59d 783 };
Janos Follath 0:1f7c5025e59d 784
Janos Follath 0:1f7c5025e59d 785 mbedtls_dhm_context dhm;
Janos Follath 0:1f7c5025e59d 786 size_t olen;
Janos Follath 0:1f7c5025e59d 787 for( i = 0; (size_t) i < sizeof( dhm_sizes ) / sizeof( dhm_sizes[0] ); i++ )
Janos Follath 0:1f7c5025e59d 788 {
Janos Follath 0:1f7c5025e59d 789 mbedtls_dhm_init( &dhm );
Janos Follath 0:1f7c5025e59d 790
Janos Follath 0:1f7c5025e59d 791 if( mbedtls_mpi_read_string( &dhm.P, 16, dhm_P[i] ) != 0 ||
Janos Follath 0:1f7c5025e59d 792 mbedtls_mpi_read_string( &dhm.G, 16, dhm_G[i] ) != 0 )
Janos Follath 0:1f7c5025e59d 793 {
Janos Follath 0:1f7c5025e59d 794 mbedtls_exit( 1 );
Janos Follath 0:1f7c5025e59d 795 }
Janos Follath 0:1f7c5025e59d 796
Janos Follath 0:1f7c5025e59d 797 dhm.len = mbedtls_mpi_size( &dhm.P );
Janos Follath 0:1f7c5025e59d 798 mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL );
Janos Follath 0:1f7c5025e59d 799 if( mbedtls_mpi_copy( &dhm.GY, &dhm.GX ) != 0 )
Janos Follath 0:1f7c5025e59d 800 mbedtls_exit( 1 );
Janos Follath 0:1f7c5025e59d 801
Janos Follath 0:1f7c5025e59d 802 mbedtls_snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] );
Janos Follath 0:1f7c5025e59d 803 TIME_PUBLIC( title, "handshake",
Janos Follath 0:1f7c5025e59d 804 ret |= mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len,
Janos Follath 0:1f7c5025e59d 805 myrand, NULL );
Janos Follath 0:1f7c5025e59d 806 ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 807
Janos Follath 0:1f7c5025e59d 808 mbedtls_snprintf( title, sizeof( title ), "DH-%d", dhm_sizes[i] );
Janos Follath 0:1f7c5025e59d 809 TIME_PUBLIC( title, "handshake",
Janos Follath 0:1f7c5025e59d 810 ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 811
Janos Follath 0:1f7c5025e59d 812 mbedtls_dhm_free( &dhm );
Janos Follath 0:1f7c5025e59d 813 }
Janos Follath 0:1f7c5025e59d 814 }
Janos Follath 0:1f7c5025e59d 815 #endif
Janos Follath 0:1f7c5025e59d 816
mbed_official 11:6ccae3ebafd5 817 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_SHA256_C) && defined(ENABLE_ECDSA)
Janos Follath 0:1f7c5025e59d 818 if( todo.ecdsa )
Janos Follath 0:1f7c5025e59d 819 {
Janos Follath 0:1f7c5025e59d 820 mbedtls_ecdsa_context ecdsa;
Janos Follath 0:1f7c5025e59d 821 const mbedtls_ecp_curve_info *curve_info;
Janos Follath 0:1f7c5025e59d 822 size_t sig_len;
Janos Follath 0:1f7c5025e59d 823
Janos Follath 0:1f7c5025e59d 824 memset( buf, 0x2A, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 825
Janos Follath 0:1f7c5025e59d 826 for( curve_info = mbedtls_ecp_curve_list();
Janos Follath 0:1f7c5025e59d 827 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Janos Follath 0:1f7c5025e59d 828 curve_info++ )
Janos Follath 0:1f7c5025e59d 829 {
Janos Follath 0:1f7c5025e59d 830 mbedtls_ecdsa_init( &ecdsa );
Janos Follath 0:1f7c5025e59d 831
Janos Follath 0:1f7c5025e59d 832 if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 833 mbedtls_exit( 1 );
Janos Follath 0:1f7c5025e59d 834 ecp_clear_precomputed( &ecdsa.grp );
Janos Follath 0:1f7c5025e59d 835
Janos Follath 0:1f7c5025e59d 836 mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s",
Janos Follath 0:1f7c5025e59d 837 curve_info->name );
Janos Follath 0:1f7c5025e59d 838 TIME_PUBLIC( title, "sign",
Janos Follath 0:1f7c5025e59d 839 ret = mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->bit_size,
Janos Follath 0:1f7c5025e59d 840 tmp, &sig_len, myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 841
Janos Follath 0:1f7c5025e59d 842 mbedtls_ecdsa_free( &ecdsa );
Janos Follath 0:1f7c5025e59d 843 }
Janos Follath 0:1f7c5025e59d 844
Janos Follath 0:1f7c5025e59d 845 for( curve_info = mbedtls_ecp_curve_list();
Janos Follath 0:1f7c5025e59d 846 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Janos Follath 0:1f7c5025e59d 847 curve_info++ )
Janos Follath 0:1f7c5025e59d 848 {
Janos Follath 0:1f7c5025e59d 849 mbedtls_ecdsa_init( &ecdsa );
Janos Follath 0:1f7c5025e59d 850
Janos Follath 0:1f7c5025e59d 851 if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 ||
Janos Follath 0:1f7c5025e59d 852 mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->bit_size,
Janos Follath 0:1f7c5025e59d 853 tmp, &sig_len, myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 854 {
Janos Follath 0:1f7c5025e59d 855 mbedtls_exit( 1 );
Janos Follath 0:1f7c5025e59d 856 }
Janos Follath 0:1f7c5025e59d 857 ecp_clear_precomputed( &ecdsa.grp );
Janos Follath 0:1f7c5025e59d 858
Janos Follath 0:1f7c5025e59d 859 mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s",
Janos Follath 0:1f7c5025e59d 860 curve_info->name );
Janos Follath 0:1f7c5025e59d 861 TIME_PUBLIC( title, "verify",
Janos Follath 0:1f7c5025e59d 862 ret = mbedtls_ecdsa_read_signature( &ecdsa, buf, curve_info->bit_size,
Janos Follath 0:1f7c5025e59d 863 tmp, sig_len ) );
Janos Follath 0:1f7c5025e59d 864
Janos Follath 0:1f7c5025e59d 865 mbedtls_ecdsa_free( &ecdsa );
Janos Follath 0:1f7c5025e59d 866 }
Janos Follath 0:1f7c5025e59d 867 }
Janos Follath 0:1f7c5025e59d 868 #endif
Janos Follath 0:1f7c5025e59d 869
Janos Follath 0:1f7c5025e59d 870 #if defined(MBEDTLS_ECDH_C)
Janos Follath 0:1f7c5025e59d 871 if( todo.ecdh )
Janos Follath 0:1f7c5025e59d 872 {
Janos Follath 0:1f7c5025e59d 873 mbedtls_ecdh_context ecdh;
Janos Follath 0:1f7c5025e59d 874 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
Janos Follath 0:1f7c5025e59d 875 mbedtls_mpi z;
Janos Follath 0:1f7c5025e59d 876 #endif
Janos Follath 0:1f7c5025e59d 877 const mbedtls_ecp_curve_info *curve_info;
Janos Follath 0:1f7c5025e59d 878 size_t olen;
Janos Follath 0:1f7c5025e59d 879
Janos Follath 0:1f7c5025e59d 880 for( curve_info = mbedtls_ecp_curve_list();
Janos Follath 0:1f7c5025e59d 881 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Janos Follath 0:1f7c5025e59d 882 curve_info++ )
Janos Follath 0:1f7c5025e59d 883 {
Janos Follath 0:1f7c5025e59d 884 mbedtls_ecdh_init( &ecdh );
Janos Follath 0:1f7c5025e59d 885
Janos Follath 0:1f7c5025e59d 886 if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 ||
Janos Follath 0:1f7c5025e59d 887 mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 888 myrand, NULL ) != 0 ||
Janos Follath 0:1f7c5025e59d 889 mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 )
Janos Follath 0:1f7c5025e59d 890 {
Janos Follath 0:1f7c5025e59d 891 mbedtls_exit( 1 );
Janos Follath 0:1f7c5025e59d 892 }
Janos Follath 0:1f7c5025e59d 893 ecp_clear_precomputed( &ecdh.grp );
Janos Follath 0:1f7c5025e59d 894
Janos Follath 0:1f7c5025e59d 895 mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s",
Janos Follath 0:1f7c5025e59d 896 curve_info->name );
Janos Follath 0:1f7c5025e59d 897 TIME_PUBLIC( title, "handshake",
Janos Follath 0:1f7c5025e59d 898 ret |= mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 899 myrand, NULL );
Janos Follath 0:1f7c5025e59d 900 ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 901 myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 902 mbedtls_ecdh_free( &ecdh );
Janos Follath 0:1f7c5025e59d 903 }
Janos Follath 0:1f7c5025e59d 904
Janos Follath 0:1f7c5025e59d 905 /* Curve25519 needs to be handled separately */
Janos Follath 0:1f7c5025e59d 906 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
Janos Follath 0:1f7c5025e59d 907 mbedtls_ecdh_init( &ecdh );
Janos Follath 0:1f7c5025e59d 908 mbedtls_mpi_init( &z );
Janos Follath 0:1f7c5025e59d 909
Janos Follath 0:1f7c5025e59d 910 if( mbedtls_ecp_group_load( &ecdh.grp, MBEDTLS_ECP_DP_CURVE25519 ) != 0 ||
Janos Follath 0:1f7c5025e59d 911 mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 912 {
Janos Follath 0:1f7c5025e59d 913 mbedtls_exit( 1 );
Janos Follath 0:1f7c5025e59d 914 }
Janos Follath 0:1f7c5025e59d 915
Janos Follath 0:1f7c5025e59d 916 TIME_PUBLIC( "ECDHE-Curve25519", "handshake",
Janos Follath 0:1f7c5025e59d 917 ret |= mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q,
Janos Follath 0:1f7c5025e59d 918 myrand, NULL );
Janos Follath 0:1f7c5025e59d 919 ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
Janos Follath 0:1f7c5025e59d 920 myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 921
Janos Follath 0:1f7c5025e59d 922 mbedtls_ecdh_free( &ecdh );
Janos Follath 0:1f7c5025e59d 923 mbedtls_mpi_free( &z );
Janos Follath 0:1f7c5025e59d 924 #endif
Janos Follath 0:1f7c5025e59d 925
Janos Follath 0:1f7c5025e59d 926 for( curve_info = mbedtls_ecp_curve_list();
Janos Follath 0:1f7c5025e59d 927 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Janos Follath 0:1f7c5025e59d 928 curve_info++ )
Janos Follath 0:1f7c5025e59d 929 {
Janos Follath 0:1f7c5025e59d 930 mbedtls_ecdh_init( &ecdh );
Janos Follath 0:1f7c5025e59d 931
Janos Follath 0:1f7c5025e59d 932 if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 ||
Janos Follath 0:1f7c5025e59d 933 mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 934 myrand, NULL ) != 0 ||
Janos Follath 0:1f7c5025e59d 935 mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 ||
Janos Follath 0:1f7c5025e59d 936 mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 937 myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 938 {
Janos Follath 0:1f7c5025e59d 939 mbedtls_exit( 1 );
Janos Follath 0:1f7c5025e59d 940 }
Janos Follath 0:1f7c5025e59d 941 ecp_clear_precomputed( &ecdh.grp );
Janos Follath 0:1f7c5025e59d 942
Janos Follath 0:1f7c5025e59d 943 mbedtls_snprintf( title, sizeof( title ), "ECDH-%s",
Janos Follath 0:1f7c5025e59d 944 curve_info->name );
Janos Follath 0:1f7c5025e59d 945 TIME_PUBLIC( title, "handshake",
Janos Follath 0:1f7c5025e59d 946 ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 947 myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 948 mbedtls_ecdh_free( &ecdh );
Janos Follath 0:1f7c5025e59d 949 }
Janos Follath 0:1f7c5025e59d 950
Janos Follath 0:1f7c5025e59d 951 /* Curve25519 needs to be handled separately */
Janos Follath 0:1f7c5025e59d 952 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
Janos Follath 0:1f7c5025e59d 953 mbedtls_ecdh_init( &ecdh );
Janos Follath 0:1f7c5025e59d 954 mbedtls_mpi_init( &z );
Janos Follath 0:1f7c5025e59d 955
Janos Follath 0:1f7c5025e59d 956 if( mbedtls_ecp_group_load( &ecdh.grp, MBEDTLS_ECP_DP_CURVE25519 ) != 0 ||
Janos Follath 0:1f7c5025e59d 957 mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp,
Janos Follath 0:1f7c5025e59d 958 myrand, NULL ) != 0 ||
Janos Follath 0:1f7c5025e59d 959 mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 960 {
Janos Follath 0:1f7c5025e59d 961 mbedtls_exit( 1 );
Janos Follath 0:1f7c5025e59d 962 }
Janos Follath 0:1f7c5025e59d 963
Janos Follath 0:1f7c5025e59d 964 TIME_PUBLIC( "ECDH-Curve25519", "handshake",
Janos Follath 0:1f7c5025e59d 965 ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
Janos Follath 0:1f7c5025e59d 966 myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 967
Janos Follath 0:1f7c5025e59d 968 mbedtls_ecdh_free( &ecdh );
Janos Follath 0:1f7c5025e59d 969 mbedtls_mpi_free( &z );
Janos Follath 0:1f7c5025e59d 970 #endif
Janos Follath 0:1f7c5025e59d 971 }
Janos Follath 0:1f7c5025e59d 972 #endif
Janos Follath 0:1f7c5025e59d 973
Janos Follath 0:1f7c5025e59d 974 mbedtls_printf("\r\nDONE\r\n");
Janos Follath 0:1f7c5025e59d 975
Janos Follath 0:1f7c5025e59d 976 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Janos Follath 0:1f7c5025e59d 977 mbedtls_memory_buffer_alloc_free();
Janos Follath 0:1f7c5025e59d 978 #endif
Janos Follath 0:1f7c5025e59d 979
Janos Follath 0:1f7c5025e59d 980 return( 0 );
Janos Follath 0:1f7c5025e59d 981 }
Janos Follath 0:1f7c5025e59d 982
Janos Follath 0:1f7c5025e59d 983 int main(void) {
Janos Follath 0:1f7c5025e59d 984 int ret = benchmark(0, NULL);
Janos Follath 0:1f7c5025e59d 985 if (ret != 0) {
Janos Follath 0:1f7c5025e59d 986 mbedtls_printf("Benchmark failed with error %d\r\n", ret);
Janos Follath 0:1f7c5025e59d 987 }
Janos Follath 0:1f7c5025e59d 988 }