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:
Thu Jul 19 15:30:05 2018 +0100
Revision:
70:72c865037f5d
Parent:
63:9f7e5224fc60
Child:
76:68ac2a548d58
Merge pull request #116 from RonEld/benchmark_refactor

The only failing CI test was a known issue
.
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 *
mbed_official 70:72c865037f5d 4 * Copyright (C) 2006-2018, 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 70:72c865037f5d 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 volatile int alarmed;
Janos Follath 0:1f7c5025e59d 184 static void alarm() { alarmed = 1; }
Janos Follath 0:1f7c5025e59d 185
Janos Follath 0:1f7c5025e59d 186 #define TIME_AND_TSC( TITLE, CODE ) \
Janos Follath 0:1f7c5025e59d 187 do { \
mbed_official 33:0af60cd5226d 188 unsigned long i; \
Janos Follath 0:1f7c5025e59d 189 Timeout t; \
Janos Follath 0:1f7c5025e59d 190 \
Janos Follath 0:1f7c5025e59d 191 mbedtls_printf( HEADER_FORMAT, TITLE ); \
Janos Follath 0:1f7c5025e59d 192 \
Janos Follath 0:1f7c5025e59d 193 for( i = 1, alarmed = 0, t.attach( alarm, 1.0 ); !alarmed; i++ ) \
Janos Follath 0:1f7c5025e59d 194 { \
Janos Follath 0:1f7c5025e59d 195 CODE; \
Janos Follath 0:1f7c5025e59d 196 } \
Janos Follath 0:1f7c5025e59d 197 \
mbed_official 33:0af60cd5226d 198 mbedtls_printf( "%9lu KB/s\r\n", \
mbed_official 33:0af60cd5226d 199 i * BUFSIZE / 1024 ); \
Janos Follath 0:1f7c5025e59d 200 } while( 0 )
Janos Follath 0:1f7c5025e59d 201
Janos Follath 0:1f7c5025e59d 202 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG)
Janos Follath 0:1f7c5025e59d 203
Janos Follath 0:1f7c5025e59d 204 #define MEMORY_MEASURE_INIT \
Janos Follath 0:1f7c5025e59d 205 size_t max_used, max_blocks, max_bytes; \
Janos Follath 0:1f7c5025e59d 206 size_t prv_used, prv_blocks; \
Janos Follath 0:1f7c5025e59d 207 mbedtls_memory_buffer_alloc_cur_get( &prv_used, &prv_blocks ); \
Janos Follath 0:1f7c5025e59d 208 mbedtls_memory_buffer_alloc_max_reset( );
Janos Follath 0:1f7c5025e59d 209
Janos Follath 0:1f7c5025e59d 210 #define MEMORY_MEASURE_PRINT( title_len ) \
Janos Follath 0:1f7c5025e59d 211 mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \
Janos Follath 0:1f7c5025e59d 212 for( i = 12 - title_len; i != 0; i-- ) mbedtls_printf( " " ); \
Janos Follath 0:1f7c5025e59d 213 max_used -= prv_used; \
Janos Follath 0:1f7c5025e59d 214 max_blocks -= prv_blocks; \
Janos Follath 0:1f7c5025e59d 215 max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \
Janos Follath 0:1f7c5025e59d 216 mbedtls_printf( "%6u heap bytes", (unsigned) max_bytes );
Janos Follath 0:1f7c5025e59d 217
Janos Follath 0:1f7c5025e59d 218 #else
Janos Follath 0:1f7c5025e59d 219 #define MEMORY_MEASURE_INIT
Janos Follath 0:1f7c5025e59d 220 #define MEMORY_MEASURE_PRINT( title_len )
Janos Follath 0:1f7c5025e59d 221 #endif
Janos Follath 0:1f7c5025e59d 222
Janos Follath 0:1f7c5025e59d 223 #define TIME_PUBLIC( TITLE, TYPE, CODE ) \
Janos Follath 0:1f7c5025e59d 224 do { \
Janos Follath 0:1f7c5025e59d 225 unsigned long ms; \
Janos Follath 0:1f7c5025e59d 226 int ret = 0; \
Janos Follath 0:1f7c5025e59d 227 Timer t; \
Janos Follath 0:1f7c5025e59d 228 MEMORY_MEASURE_INIT; \
Janos Follath 0:1f7c5025e59d 229 \
Janos Follath 0:1f7c5025e59d 230 mbedtls_printf( HEADER_FORMAT, TITLE ); \
Janos Follath 0:1f7c5025e59d 231 fflush( stdout ); \
Janos Follath 0:1f7c5025e59d 232 \
Janos Follath 0:1f7c5025e59d 233 t.start(); \
Janos Follath 0:1f7c5025e59d 234 CODE; \
Janos Follath 0:1f7c5025e59d 235 t.stop(); \
Janos Follath 0:1f7c5025e59d 236 ms = t.read_ms(); \
Janos Follath 0:1f7c5025e59d 237 \
Janos Follath 0:1f7c5025e59d 238 if( ret != 0 ) \
Janos Follath 0:1f7c5025e59d 239 { \
Janos Follath 0:1f7c5025e59d 240 PRINT_ERROR; \
Janos Follath 0:1f7c5025e59d 241 } \
Janos Follath 0:1f7c5025e59d 242 else \
Janos Follath 0:1f7c5025e59d 243 { \
Janos Follath 0:1f7c5025e59d 244 mbedtls_printf( "%6lu ms/" TYPE, ms ); \
Janos Follath 0:1f7c5025e59d 245 MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 ); \
Janos Follath 0:1f7c5025e59d 246 mbedtls_printf( "\r\n" ); \
Janos Follath 0:1f7c5025e59d 247 } \
Janos Follath 0:1f7c5025e59d 248 } while( 0 )
Janos Follath 0:1f7c5025e59d 249
Janos Follath 0:1f7c5025e59d 250 static int myrand( void *rng_state, unsigned char *output, size_t len )
Janos Follath 0:1f7c5025e59d 251 {
Janos Follath 0:1f7c5025e59d 252 size_t use_len;
Janos Follath 0:1f7c5025e59d 253 int rnd;
Janos Follath 0:1f7c5025e59d 254
Janos Follath 0:1f7c5025e59d 255 if( rng_state != NULL )
Janos Follath 0:1f7c5025e59d 256 rng_state = NULL;
Janos Follath 0:1f7c5025e59d 257
Janos Follath 0:1f7c5025e59d 258 while( len > 0 )
Janos Follath 0:1f7c5025e59d 259 {
Janos Follath 0:1f7c5025e59d 260 use_len = len;
Janos Follath 0:1f7c5025e59d 261 if( use_len > sizeof(int) )
Janos Follath 0:1f7c5025e59d 262 use_len = sizeof(int);
Janos Follath 0:1f7c5025e59d 263
Janos Follath 0:1f7c5025e59d 264 rnd = rand();
Janos Follath 0:1f7c5025e59d 265 memcpy( output, &rnd, use_len );
Janos Follath 0:1f7c5025e59d 266 output += use_len;
Janos Follath 0:1f7c5025e59d 267 len -= use_len;
Janos Follath 0:1f7c5025e59d 268 }
Janos Follath 0:1f7c5025e59d 269
Janos Follath 0:1f7c5025e59d 270 return( 0 );
Janos Follath 0:1f7c5025e59d 271 }
Janos Follath 0:1f7c5025e59d 272
Janos Follath 0:1f7c5025e59d 273 /*
Janos Follath 0:1f7c5025e59d 274 * Clear some memory that was used to prepare the context
Janos Follath 0:1f7c5025e59d 275 */
Janos Follath 0:1f7c5025e59d 276 #if defined(MBEDTLS_ECP_C)
Janos Follath 0:1f7c5025e59d 277 void ecp_clear_precomputed( mbedtls_ecp_group *grp )
Janos Follath 0:1f7c5025e59d 278 {
Janos Follath 0:1f7c5025e59d 279 if( grp->T != NULL )
Janos Follath 0:1f7c5025e59d 280 {
Janos Follath 0:1f7c5025e59d 281 size_t i;
Janos Follath 0:1f7c5025e59d 282 for( i = 0; i < grp->T_size; i++ )
Janos Follath 0:1f7c5025e59d 283 mbedtls_ecp_point_free( &grp->T[i] );
Janos Follath 0:1f7c5025e59d 284 mbedtls_free( grp->T );
Janos Follath 0:1f7c5025e59d 285 }
Janos Follath 0:1f7c5025e59d 286 grp->T = NULL;
Janos Follath 0:1f7c5025e59d 287 grp->T_size = 0;
Janos Follath 0:1f7c5025e59d 288 }
Janos Follath 0:1f7c5025e59d 289 #else
Janos Follath 0:1f7c5025e59d 290 #define ecp_clear_precomputed( g )
Janos Follath 0:1f7c5025e59d 291 #endif
Janos Follath 0:1f7c5025e59d 292
Janos Follath 0:1f7c5025e59d 293 unsigned char buf[BUFSIZE];
Janos Follath 0:1f7c5025e59d 294
Janos Follath 0:1f7c5025e59d 295 typedef struct {
Janos Follath 0:1f7c5025e59d 296 char md4, md5, ripemd160, sha1, sha256, sha512,
mbed_official 30:e0ea8c1ef9f5 297 arc4, des3, des, aes_cbc, aes_ctr, aes_gcm, aes_ccm,
mbed_official 11:6ccae3ebafd5 298 aes_cmac, des3_cmac, camellia, blowfish,
Janos Follath 0:1f7c5025e59d 299 havege, ctr_drbg, hmac_drbg,
Janos Follath 0:1f7c5025e59d 300 rsa, dhm, ecdsa, ecdh;
Janos Follath 0:1f7c5025e59d 301 } todo_list;
Janos Follath 0:1f7c5025e59d 302
mbed_official 70:72c865037f5d 303 static int test_md( const todo_list * todo, mbedtls_platform_context* ctx )
Janos Follath 0:1f7c5025e59d 304 {
Janos Follath 0:1f7c5025e59d 305 unsigned char tmp[200];
mbed_official 63:9f7e5224fc60 306 // The call below is used to avoid the "unused parameter" warning.
mbed_official 63:9f7e5224fc60 307 // The context itself can be used by cryptographic calls which require it.
mbed_official 63:9f7e5224fc60 308 // Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
mbed_official 63:9f7e5224fc60 309 (void)ctx;
Janos Follath 0:1f7c5025e59d 310 memset( tmp, 0xBB, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 311
Janos Follath 0:1f7c5025e59d 312 #if defined(MBEDTLS_MD4_C)
mbed_official 70:72c865037f5d 313 if( todo->md4 )
Janos Follath 0:1f7c5025e59d 314 TIME_AND_TSC( "MD4", mbedtls_md4( buf, BUFSIZE, tmp ) );
Janos Follath 0:1f7c5025e59d 315 #endif
Janos Follath 0:1f7c5025e59d 316
Janos Follath 0:1f7c5025e59d 317 #if defined(MBEDTLS_MD5_C)
mbed_official 70:72c865037f5d 318 if( todo->md5 )
Janos Follath 0:1f7c5025e59d 319 TIME_AND_TSC( "MD5", mbedtls_md5( buf, BUFSIZE, tmp ) );
Janos Follath 0:1f7c5025e59d 320 #endif
Janos Follath 0:1f7c5025e59d 321
Janos Follath 0:1f7c5025e59d 322 #if defined(MBEDTLS_RIPEMD160_C)
mbed_official 70:72c865037f5d 323 if( todo->ripemd160 )
Janos Follath 0:1f7c5025e59d 324 TIME_AND_TSC( "RIPEMD160", mbedtls_ripemd160( buf, BUFSIZE, tmp ) );
Janos Follath 0:1f7c5025e59d 325 #endif
Janos Follath 0:1f7c5025e59d 326
Janos Follath 0:1f7c5025e59d 327 #if defined(MBEDTLS_SHA1_C)
mbed_official 70:72c865037f5d 328 if( todo->sha1 )
Janos Follath 0:1f7c5025e59d 329 TIME_AND_TSC( "SHA-1", mbedtls_sha1( buf, BUFSIZE, tmp ) );
Janos Follath 0:1f7c5025e59d 330 #endif
Janos Follath 0:1f7c5025e59d 331
Janos Follath 0:1f7c5025e59d 332 #if defined(MBEDTLS_SHA256_C)
mbed_official 70:72c865037f5d 333 if( todo->sha256 )
Janos Follath 0:1f7c5025e59d 334 TIME_AND_TSC( "SHA-256", mbedtls_sha256( buf, BUFSIZE, tmp, 0 ) );
Janos Follath 0:1f7c5025e59d 335 #endif
Janos Follath 0:1f7c5025e59d 336
Janos Follath 0:1f7c5025e59d 337 #if defined(MBEDTLS_SHA512_C)
mbed_official 70:72c865037f5d 338 if( todo->sha512 )
Janos Follath 0:1f7c5025e59d 339 TIME_AND_TSC( "SHA-512", mbedtls_sha512( buf, BUFSIZE, tmp, 0 ) );
Janos Follath 0:1f7c5025e59d 340 #endif
mbed_official 70:72c865037f5d 341 return ( 0 );
mbed_official 70:72c865037f5d 342 }
mbed_official 70:72c865037f5d 343
mbed_official 70:72c865037f5d 344 static int test_crypt( const todo_list * todo, mbedtls_platform_context* ctx )
mbed_official 70:72c865037f5d 345 {
mbed_official 70:72c865037f5d 346 unsigned char tmp[200];
mbed_official 70:72c865037f5d 347 char title[TITLE_LEN];
mbed_official 70:72c865037f5d 348 // The call below is used to avoid the "unused parameter" warning.
mbed_official 70:72c865037f5d 349 // The context itself can be used by cryptographic calls which require it.
mbed_official 70:72c865037f5d 350 // Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
mbed_official 70:72c865037f5d 351 (void)ctx;
mbed_official 70:72c865037f5d 352 memset( tmp, 0xBB, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 353
Janos Follath 0:1f7c5025e59d 354 #if defined(MBEDTLS_ARC4_C)
mbed_official 70:72c865037f5d 355 if( todo->arc4 )
Janos Follath 0:1f7c5025e59d 356 {
Janos Follath 0:1f7c5025e59d 357 mbedtls_arc4_context arc4;
Janos Follath 0:1f7c5025e59d 358 mbedtls_arc4_init( &arc4 );
Janos Follath 0:1f7c5025e59d 359 mbedtls_arc4_setup( &arc4, tmp, 32 );
Janos Follath 0:1f7c5025e59d 360 TIME_AND_TSC( "ARC4", mbedtls_arc4_crypt( &arc4, BUFSIZE, buf, buf ) );
Janos Follath 0:1f7c5025e59d 361 mbedtls_arc4_free( &arc4 );
Janos Follath 0:1f7c5025e59d 362 }
Janos Follath 0:1f7c5025e59d 363 #endif
Janos Follath 0:1f7c5025e59d 364
Janos Follath 0:1f7c5025e59d 365 #if defined(MBEDTLS_DES_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
mbed_official 70:72c865037f5d 366 if( todo->des3 )
Janos Follath 0:1f7c5025e59d 367 {
Janos Follath 0:1f7c5025e59d 368 mbedtls_des3_context des3;
Janos Follath 0:1f7c5025e59d 369 mbedtls_des3_init( &des3 );
Janos Follath 0:1f7c5025e59d 370 mbedtls_des3_set3key_enc( &des3, tmp );
Janos Follath 0:1f7c5025e59d 371 TIME_AND_TSC( "3DES",
Janos Follath 0:1f7c5025e59d 372 mbedtls_des3_crypt_cbc( &des3, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 373 mbedtls_des3_free( &des3 );
Janos Follath 0:1f7c5025e59d 374 }
Janos Follath 0:1f7c5025e59d 375
mbed_official 70:72c865037f5d 376 if( todo->des )
Janos Follath 0:1f7c5025e59d 377 {
Janos Follath 0:1f7c5025e59d 378 mbedtls_des_context des;
Janos Follath 0:1f7c5025e59d 379 mbedtls_des_init( &des );
Janos Follath 0:1f7c5025e59d 380 mbedtls_des_setkey_enc( &des, tmp );
Janos Follath 0:1f7c5025e59d 381 TIME_AND_TSC( "DES",
Janos Follath 0:1f7c5025e59d 382 mbedtls_des_crypt_cbc( &des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 383 mbedtls_des_free( &des );
Janos Follath 0:1f7c5025e59d 384 }
mbed_official 11:6ccae3ebafd5 385 #if defined(MBEDTLS_CMAC_C)
mbed_official 70:72c865037f5d 386 if( todo->des3_cmac )
mbed_official 11:6ccae3ebafd5 387 {
mbed_official 11:6ccae3ebafd5 388 unsigned char output[8];
mbed_official 11:6ccae3ebafd5 389 const mbedtls_cipher_info_t *cipher_info;
mbed_official 11:6ccae3ebafd5 390
mbed_official 11:6ccae3ebafd5 391 memset( buf, 0, sizeof( buf ) );
mbed_official 11:6ccae3ebafd5 392 memset( tmp, 0, sizeof( tmp ) );
mbed_official 11:6ccae3ebafd5 393
mbed_official 11:6ccae3ebafd5 394 cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_DES_EDE3_ECB );
mbed_official 11:6ccae3ebafd5 395
mbed_official 11:6ccae3ebafd5 396 TIME_AND_TSC( "3DES-CMAC",
mbed_official 11:6ccae3ebafd5 397 mbedtls_cipher_cmac( cipher_info, tmp, 192, buf,
mbed_official 11:6ccae3ebafd5 398 BUFSIZE, output ) );
mbed_official 11:6ccae3ebafd5 399 }
mbed_official 11:6ccae3ebafd5 400 #endif /* MBEDTLS_CMAC_C */
Janos Follath 0:1f7c5025e59d 401 #endif
Janos Follath 0:1f7c5025e59d 402
Janos Follath 0:1f7c5025e59d 403 #if defined(MBEDTLS_AES_C)
Janos Follath 0:1f7c5025e59d 404 #if defined(MBEDTLS_CIPHER_MODE_CBC)
mbed_official 70:72c865037f5d 405 if( todo->aes_cbc )
Janos Follath 0:1f7c5025e59d 406 {
Janos Follath 0:1f7c5025e59d 407 int keysize;
Janos Follath 0:1f7c5025e59d 408 mbedtls_aes_context aes;
Janos Follath 0:1f7c5025e59d 409 mbedtls_aes_init( &aes );
Janos Follath 0:1f7c5025e59d 410 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 411 {
Janos Follath 0:1f7c5025e59d 412 mbedtls_snprintf( title, sizeof( title ), "AES-CBC-%d", keysize );
Janos Follath 0:1f7c5025e59d 413
Janos Follath 0:1f7c5025e59d 414 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 415 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 416 mbedtls_aes_setkey_enc( &aes, tmp, keysize );
Janos Follath 0:1f7c5025e59d 417
Janos Follath 0:1f7c5025e59d 418 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 419 mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 420 }
Janos Follath 0:1f7c5025e59d 421 mbedtls_aes_free( &aes );
Janos Follath 0:1f7c5025e59d 422 }
Janos Follath 0:1f7c5025e59d 423 #endif
mbed_official 30:e0ea8c1ef9f5 424
mbed_official 30:e0ea8c1ef9f5 425 #if defined(MBEDTLS_CIPHER_MODE_CTR)
mbed_official 70:72c865037f5d 426 if( todo->aes_ctr )
mbed_official 30:e0ea8c1ef9f5 427 {
mbed_official 30:e0ea8c1ef9f5 428 int keysize;
mbed_official 30:e0ea8c1ef9f5 429 size_t nc_offset = 0;
mbed_official 30:e0ea8c1ef9f5 430 unsigned char stream_block[16];
mbed_official 30:e0ea8c1ef9f5 431 mbedtls_aes_context aes;
mbed_official 30:e0ea8c1ef9f5 432 mbedtls_aes_init( &aes );
mbed_official 30:e0ea8c1ef9f5 433 for( keysize = 128; keysize <= 256; keysize += 64 )
mbed_official 30:e0ea8c1ef9f5 434 {
mbed_official 30:e0ea8c1ef9f5 435 mbedtls_snprintf( title, sizeof( title ), "AES-CTR-%d", keysize );
mbed_official 30:e0ea8c1ef9f5 436
mbed_official 30:e0ea8c1ef9f5 437 memset( buf, 0, sizeof( buf ) );
mbed_official 30:e0ea8c1ef9f5 438 memset( tmp, 0, sizeof( tmp ) );
mbed_official 30:e0ea8c1ef9f5 439 mbedtls_aes_setkey_enc( &aes, tmp, keysize );
mbed_official 30:e0ea8c1ef9f5 440
mbed_official 30:e0ea8c1ef9f5 441 TIME_AND_TSC( title,
mbed_official 30:e0ea8c1ef9f5 442 mbedtls_aes_crypt_ctr( &aes, BUFSIZE, &nc_offset, tmp, stream_block, buf, buf ) );
mbed_official 30:e0ea8c1ef9f5 443 }
mbed_official 30:e0ea8c1ef9f5 444 mbedtls_aes_free( &aes );
mbed_official 30:e0ea8c1ef9f5 445 }
mbed_official 30:e0ea8c1ef9f5 446 #endif
mbed_official 30:e0ea8c1ef9f5 447
Janos Follath 0:1f7c5025e59d 448 #if defined(MBEDTLS_GCM_C)
mbed_official 70:72c865037f5d 449 if( todo->aes_gcm )
Janos Follath 0:1f7c5025e59d 450 {
Janos Follath 0:1f7c5025e59d 451 int keysize;
Janos Follath 0:1f7c5025e59d 452 mbedtls_gcm_context gcm;
Janos Follath 0:1f7c5025e59d 453
Janos Follath 0:1f7c5025e59d 454 mbedtls_gcm_init( &gcm );
Janos Follath 0:1f7c5025e59d 455 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 456 {
Janos Follath 0:1f7c5025e59d 457 mbedtls_snprintf( title, sizeof( title ), "AES-GCM-%d", keysize );
Janos Follath 0:1f7c5025e59d 458
Janos Follath 0:1f7c5025e59d 459 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 460 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 461 mbedtls_gcm_setkey( &gcm, MBEDTLS_CIPHER_ID_AES, tmp, keysize );
Janos Follath 0:1f7c5025e59d 462
Janos Follath 0:1f7c5025e59d 463 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 464 mbedtls_gcm_crypt_and_tag( &gcm, MBEDTLS_GCM_ENCRYPT, BUFSIZE, tmp,
Janos Follath 0:1f7c5025e59d 465 12, NULL, 0, buf, buf, 16, tmp ) );
Janos Follath 0:1f7c5025e59d 466
Janos Follath 0:1f7c5025e59d 467 mbedtls_gcm_free( &gcm );
Janos Follath 0:1f7c5025e59d 468 }
Janos Follath 0:1f7c5025e59d 469 }
Janos Follath 0:1f7c5025e59d 470 #endif
Janos Follath 0:1f7c5025e59d 471 #if defined(MBEDTLS_CCM_C)
mbed_official 70:72c865037f5d 472 if( todo->aes_ccm )
Janos Follath 0:1f7c5025e59d 473 {
Janos Follath 0:1f7c5025e59d 474 int keysize;
Janos Follath 0:1f7c5025e59d 475 mbedtls_ccm_context ccm;
Janos Follath 0:1f7c5025e59d 476
Janos Follath 0:1f7c5025e59d 477 mbedtls_ccm_init( &ccm );
Janos Follath 0:1f7c5025e59d 478 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 479 {
Janos Follath 0:1f7c5025e59d 480 mbedtls_snprintf( title, sizeof( title ), "AES-CCM-%d", keysize );
Janos Follath 0:1f7c5025e59d 481
Janos Follath 0:1f7c5025e59d 482 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 483 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 484 mbedtls_ccm_setkey( &ccm, MBEDTLS_CIPHER_ID_AES, tmp, keysize );
Janos Follath 0:1f7c5025e59d 485
Janos Follath 0:1f7c5025e59d 486 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 487 mbedtls_ccm_encrypt_and_tag( &ccm, BUFSIZE, tmp,
Janos Follath 0:1f7c5025e59d 488 12, NULL, 0, buf, buf, tmp, 16 ) );
Janos Follath 0:1f7c5025e59d 489
Janos Follath 0:1f7c5025e59d 490 mbedtls_ccm_free( &ccm );
Janos Follath 0:1f7c5025e59d 491 }
Janos Follath 0:1f7c5025e59d 492 }
Janos Follath 0:1f7c5025e59d 493 #endif
mbed_official 11:6ccae3ebafd5 494 #if defined(MBEDTLS_CMAC_C)
mbed_official 70:72c865037f5d 495 if( todo->aes_cmac )
mbed_official 11:6ccae3ebafd5 496 {
mbed_official 11:6ccae3ebafd5 497 unsigned char output[16];
mbed_official 11:6ccae3ebafd5 498 const mbedtls_cipher_info_t *cipher_info;
mbed_official 11:6ccae3ebafd5 499 mbedtls_cipher_type_t cipher_type;
mbed_official 11:6ccae3ebafd5 500 int keysize;
mbed_official 11:6ccae3ebafd5 501
mbed_official 11:6ccae3ebafd5 502 cipher_type = MBEDTLS_CIPHER_AES_128_ECB;
mbed_official 11:6ccae3ebafd5 503 for( keysize = 128; keysize <= 256; keysize += 64 )
mbed_official 11:6ccae3ebafd5 504 {
mbed_official 11:6ccae3ebafd5 505 mbedtls_snprintf( title, sizeof( title ), "AES-CMAC-%d", keysize );
mbed_official 11:6ccae3ebafd5 506
mbed_official 11:6ccae3ebafd5 507 memset( buf, 0, sizeof( buf ) );
mbed_official 11:6ccae3ebafd5 508 memset( tmp, 0, sizeof( tmp ) );
mbed_official 11:6ccae3ebafd5 509
mbed_official 11:6ccae3ebafd5 510 cipher_info = mbedtls_cipher_info_from_type( cipher_type );
mbed_official 11:6ccae3ebafd5 511
mbed_official 11:6ccae3ebafd5 512 TIME_AND_TSC( title,
mbed_official 11:6ccae3ebafd5 513 mbedtls_cipher_cmac( cipher_info, tmp, keysize,
mbed_official 11:6ccae3ebafd5 514 buf, BUFSIZE, output ) );
mbed_official 11:6ccae3ebafd5 515 cipher_type = (mbedtls_cipher_type_t)( cipher_type + 1 );
mbed_official 11:6ccae3ebafd5 516 }
mbed_official 11:6ccae3ebafd5 517
mbed_official 11:6ccae3ebafd5 518 memset( buf, 0, sizeof( buf ) );
mbed_official 11:6ccae3ebafd5 519 memset( tmp, 0, sizeof( tmp ) );
mbed_official 11:6ccae3ebafd5 520 TIME_AND_TSC( "AES-CMAC-PRF-128",
mbed_official 11:6ccae3ebafd5 521 mbedtls_aes_cmac_prf_128( tmp, 16, buf, BUFSIZE,
mbed_official 11:6ccae3ebafd5 522 output ) );
mbed_official 11:6ccae3ebafd5 523 }
mbed_official 11:6ccae3ebafd5 524 #endif /* MBEDTLS_CMAC_C */
Janos Follath 0:1f7c5025e59d 525 #endif
Janos Follath 0:1f7c5025e59d 526
Janos Follath 0:1f7c5025e59d 527 #if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
mbed_official 70:72c865037f5d 528 if( todo->camellia )
Janos Follath 0:1f7c5025e59d 529 {
Janos Follath 0:1f7c5025e59d 530 int keysize;
Janos Follath 0:1f7c5025e59d 531 mbedtls_camellia_context camellia;
Janos Follath 0:1f7c5025e59d 532 mbedtls_camellia_init( &camellia );
Janos Follath 0:1f7c5025e59d 533 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 534 {
Janos Follath 0:1f7c5025e59d 535 mbedtls_snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize );
Janos Follath 0:1f7c5025e59d 536
Janos Follath 0:1f7c5025e59d 537 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 538 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 539 mbedtls_camellia_setkey_enc( &camellia, tmp, keysize );
Janos Follath 0:1f7c5025e59d 540
Janos Follath 0:1f7c5025e59d 541 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 542 mbedtls_camellia_crypt_cbc( &camellia, MBEDTLS_CAMELLIA_ENCRYPT,
Janos Follath 0:1f7c5025e59d 543 BUFSIZE, tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 544 }
Janos Follath 0:1f7c5025e59d 545 mbedtls_camellia_free( &camellia );
Janos Follath 0:1f7c5025e59d 546 }
Janos Follath 0:1f7c5025e59d 547 #endif
Janos Follath 0:1f7c5025e59d 548
Janos Follath 0:1f7c5025e59d 549 #if defined(MBEDTLS_BLOWFISH_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
mbed_official 70:72c865037f5d 550 if( todo->blowfish )
Janos Follath 0:1f7c5025e59d 551 {
Janos Follath 0:1f7c5025e59d 552 int keysize;
Janos Follath 0:1f7c5025e59d 553 mbedtls_blowfish_context blowfish;
Janos Follath 0:1f7c5025e59d 554 mbedtls_blowfish_init( &blowfish );
Janos Follath 0:1f7c5025e59d 555
Janos Follath 0:1f7c5025e59d 556 for( keysize = 128; keysize <= 256; keysize += 64 )
Janos Follath 0:1f7c5025e59d 557 {
Janos Follath 0:1f7c5025e59d 558 mbedtls_snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize );
Janos Follath 0:1f7c5025e59d 559
Janos Follath 0:1f7c5025e59d 560 memset( buf, 0, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 561 memset( tmp, 0, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 562 mbedtls_blowfish_setkey( &blowfish, tmp, keysize );
Janos Follath 0:1f7c5025e59d 563
Janos Follath 0:1f7c5025e59d 564 TIME_AND_TSC( title,
Janos Follath 0:1f7c5025e59d 565 mbedtls_blowfish_crypt_cbc( &blowfish, MBEDTLS_BLOWFISH_ENCRYPT, BUFSIZE,
Janos Follath 0:1f7c5025e59d 566 tmp, buf, buf ) );
Janos Follath 0:1f7c5025e59d 567 }
Janos Follath 0:1f7c5025e59d 568
Janos Follath 0:1f7c5025e59d 569 mbedtls_blowfish_free( &blowfish );
Janos Follath 0:1f7c5025e59d 570 }
Janos Follath 0:1f7c5025e59d 571 #endif
Janos Follath 0:1f7c5025e59d 572
mbed_official 70:72c865037f5d 573 return ( 0 );
mbed_official 70:72c865037f5d 574 }
mbed_official 70:72c865037f5d 575
mbed_official 70:72c865037f5d 576 static int test_rng( const todo_list * todo, mbedtls_platform_context* ctx )
mbed_official 70:72c865037f5d 577 {
mbed_official 70:72c865037f5d 578 unsigned char tmp[200];
mbed_official 70:72c865037f5d 579 // The call below is used to avoid the "unused parameter" warning.
mbed_official 70:72c865037f5d 580 // The context itself can be used by cryptographic calls which require it.
mbed_official 70:72c865037f5d 581 // Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
mbed_official 70:72c865037f5d 582 (void)ctx;
mbed_official 70:72c865037f5d 583 memset( tmp, 0xBB, sizeof( tmp ) );
mbed_official 70:72c865037f5d 584
Janos Follath 0:1f7c5025e59d 585 #if defined(MBEDTLS_HAVEGE_C)
mbed_official 70:72c865037f5d 586 if( todo->havege )
Janos Follath 0:1f7c5025e59d 587 {
Janos Follath 0:1f7c5025e59d 588 mbedtls_havege_state hs;
Janos Follath 0:1f7c5025e59d 589 mbedtls_havege_init( &hs );
Janos Follath 0:1f7c5025e59d 590 TIME_AND_TSC( "HAVEGE", mbedtls_havege_random( &hs, buf, BUFSIZE ) );
Janos Follath 0:1f7c5025e59d 591 mbedtls_havege_free( &hs );
Janos Follath 0:1f7c5025e59d 592 }
Janos Follath 0:1f7c5025e59d 593 #endif
Janos Follath 0:1f7c5025e59d 594
Janos Follath 0:1f7c5025e59d 595 #if defined(MBEDTLS_CTR_DRBG_C)
mbed_official 70:72c865037f5d 596 if( todo->ctr_drbg )
Janos Follath 0:1f7c5025e59d 597 {
Janos Follath 0:1f7c5025e59d 598 mbedtls_ctr_drbg_context ctr_drbg;
Janos Follath 0:1f7c5025e59d 599
Janos Follath 0:1f7c5025e59d 600 mbedtls_ctr_drbg_init( &ctr_drbg );
Janos Follath 0:1f7c5025e59d 601
Janos Follath 0:1f7c5025e59d 602 if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
mbed_official 63:9f7e5224fc60 603 return(1);
Janos Follath 0:1f7c5025e59d 604 TIME_AND_TSC( "CTR_DRBG (NOPR)",
Janos Follath 0:1f7c5025e59d 605 if( mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
mbed_official 70:72c865037f5d 606 return(1) );
Janos Follath 0:1f7c5025e59d 607
Janos Follath 0:1f7c5025e59d 608 if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
mbed_official 63:9f7e5224fc60 609 return(1);
Janos Follath 0:1f7c5025e59d 610 mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON );
Janos Follath 0:1f7c5025e59d 611 TIME_AND_TSC( "CTR_DRBG (PR)",
Janos Follath 0:1f7c5025e59d 612 if( mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
mbed_official 70:72c865037f5d 613 return(1) );
Janos Follath 0:1f7c5025e59d 614 mbedtls_ctr_drbg_free( &ctr_drbg );
Janos Follath 0:1f7c5025e59d 615 }
Janos Follath 0:1f7c5025e59d 616 #endif
Janos Follath 0:1f7c5025e59d 617
Janos Follath 0:1f7c5025e59d 618 #if defined(MBEDTLS_HMAC_DRBG_C)
mbed_official 70:72c865037f5d 619 if( todo->hmac_drbg )
Janos Follath 0:1f7c5025e59d 620 {
Janos Follath 0:1f7c5025e59d 621 mbedtls_hmac_drbg_context hmac_drbg;
Janos Follath 0:1f7c5025e59d 622 const mbedtls_md_info_t *md_info;
Janos Follath 0:1f7c5025e59d 623
Janos Follath 0:1f7c5025e59d 624 mbedtls_hmac_drbg_init( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 625
Janos Follath 0:1f7c5025e59d 626 #if defined(MBEDTLS_SHA1_C)
Janos Follath 0:1f7c5025e59d 627 if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 ) ) == NULL )
mbed_official 63:9f7e5224fc60 628 return(1);
Janos Follath 0:1f7c5025e59d 629
Janos Follath 0:1f7c5025e59d 630 if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
mbed_official 63:9f7e5224fc60 631 return(1);
Janos Follath 0:1f7c5025e59d 632 TIME_AND_TSC( "HMAC_DRBG SHA-1 (NOPR)",
Janos Follath 0:1f7c5025e59d 633 if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
mbed_official 70:72c865037f5d 634 return(1) );
Janos Follath 0:1f7c5025e59d 635 mbedtls_hmac_drbg_free( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 636
Janos Follath 0:1f7c5025e59d 637 if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
mbed_official 63:9f7e5224fc60 638 return(1);
Janos Follath 0:1f7c5025e59d 639 mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg,
Janos Follath 0:1f7c5025e59d 640 MBEDTLS_HMAC_DRBG_PR_ON );
Janos Follath 0:1f7c5025e59d 641 TIME_AND_TSC( "HMAC_DRBG SHA-1 (PR)",
Janos Follath 0:1f7c5025e59d 642 if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
mbed_official 70:72c865037f5d 643 return(1) );
Janos Follath 0:1f7c5025e59d 644 mbedtls_hmac_drbg_free( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 645 #endif
Janos Follath 0:1f7c5025e59d 646
Janos Follath 0:1f7c5025e59d 647 #if defined(MBEDTLS_SHA256_C)
Janos Follath 0:1f7c5025e59d 648 if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ) ) == NULL )
mbed_official 63:9f7e5224fc60 649 return(1);
Janos Follath 0:1f7c5025e59d 650
Janos Follath 0:1f7c5025e59d 651 if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
mbed_official 63:9f7e5224fc60 652 return(1);
Janos Follath 0:1f7c5025e59d 653 TIME_AND_TSC( "HMAC_DRBG SHA-256 (NOPR)",
Janos Follath 0:1f7c5025e59d 654 if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
mbed_official 70:72c865037f5d 655 return(1) );
Janos Follath 0:1f7c5025e59d 656 mbedtls_hmac_drbg_free( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 657
Janos Follath 0:1f7c5025e59d 658 if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
mbed_official 63:9f7e5224fc60 659 return(1);
Janos Follath 0:1f7c5025e59d 660 mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg,
Janos Follath 0:1f7c5025e59d 661 MBEDTLS_HMAC_DRBG_PR_ON );
Janos Follath 0:1f7c5025e59d 662 TIME_AND_TSC( "HMAC_DRBG SHA-256 (PR)",
Janos Follath 0:1f7c5025e59d 663 if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
mbed_official 70:72c865037f5d 664 return(1) );
Janos Follath 0:1f7c5025e59d 665 mbedtls_hmac_drbg_free( &hmac_drbg );
Janos Follath 0:1f7c5025e59d 666 #endif
Janos Follath 0:1f7c5025e59d 667 }
Janos Follath 0:1f7c5025e59d 668 #endif
mbed_official 70:72c865037f5d 669 return (0 );
mbed_official 70:72c865037f5d 670 }
mbed_official 70:72c865037f5d 671
mbed_official 70:72c865037f5d 672 static int test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
mbed_official 70:72c865037f5d 673 {
mbed_official 70:72c865037f5d 674 unsigned char tmp[200];
mbed_official 70:72c865037f5d 675 char title[TITLE_LEN];
mbed_official 70:72c865037f5d 676 // The call below is used to avoid the "unused parameter" warning.
mbed_official 70:72c865037f5d 677 // The context itself can be used by cryptographic calls which require it.
mbed_official 70:72c865037f5d 678 // Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
mbed_official 70:72c865037f5d 679 (void)ctx;
mbed_official 70:72c865037f5d 680 memset( tmp, 0xBB, sizeof( tmp ) );
Janos Follath 0:1f7c5025e59d 681
Janos Follath 0:1f7c5025e59d 682 #if defined(MBEDTLS_RSA_C) && \
Janos Follath 0:1f7c5025e59d 683 defined(MBEDTLS_PEM_PARSE_C) && defined(MBEDTLS_PK_PARSE_C)
mbed_official 70:72c865037f5d 684 if( todo->rsa )
Janos Follath 0:1f7c5025e59d 685 {
Janos Follath 0:1f7c5025e59d 686 mbedtls_pk_context pk;
Janos Follath 0:1f7c5025e59d 687 mbedtls_rsa_context *rsa;
Janos Follath 0:1f7c5025e59d 688 const char *rsa_keys[] = { RSA_PRIVATE_KEY_2048, RSA_PRIVATE_KEY_4096 };
Janos Follath 0:1f7c5025e59d 689 size_t i;
Janos Follath 0:1f7c5025e59d 690
Janos Follath 0:1f7c5025e59d 691 for( i = 0; i < sizeof( rsa_keys ) / sizeof( rsa_keys[0] ); i++ )
Janos Follath 0:1f7c5025e59d 692 {
Janos Follath 0:1f7c5025e59d 693 mbedtls_pk_init( &pk );
Janos Follath 0:1f7c5025e59d 694 mbedtls_pk_parse_key( &pk, (const unsigned char *) rsa_keys[i],
Janos Follath 0:1f7c5025e59d 695 strlen( rsa_keys[i] ) + 1, NULL, 0 );
Janos Follath 0:1f7c5025e59d 696 rsa = mbedtls_pk_rsa( pk );
Janos Follath 0:1f7c5025e59d 697
Janos Follath 0:1f7c5025e59d 698 mbedtls_snprintf( title, sizeof( title ), "RSA-%d", mbedtls_pk_get_bitlen( &pk ) );
Janos Follath 0:1f7c5025e59d 699
Janos Follath 0:1f7c5025e59d 700 TIME_PUBLIC( title, " public",
Janos Follath 0:1f7c5025e59d 701 buf[0] = 0;
Janos Follath 0:1f7c5025e59d 702 ret = mbedtls_rsa_public( rsa, buf, buf ) );
Janos Follath 0:1f7c5025e59d 703
Janos Follath 0:1f7c5025e59d 704 TIME_PUBLIC( title, "private",
Janos Follath 0:1f7c5025e59d 705 buf[0] = 0;
Janos Follath 0:1f7c5025e59d 706 ret = mbedtls_rsa_private( rsa, myrand, NULL, buf, buf ) );
Janos Follath 0:1f7c5025e59d 707
Janos Follath 0:1f7c5025e59d 708 mbedtls_pk_free( &pk );
Janos Follath 0:1f7c5025e59d 709 }
Janos Follath 0:1f7c5025e59d 710 }
Janos Follath 0:1f7c5025e59d 711 #endif
Janos Follath 0:1f7c5025e59d 712
Janos Follath 0:1f7c5025e59d 713 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_BIGNUM_C)
mbed_official 70:72c865037f5d 714 if( todo->dhm )
Janos Follath 0:1f7c5025e59d 715 {
Janos Follath 0:1f7c5025e59d 716 int dhm_sizes[] = { 2048, 3072 };
Janos Follath 0:1f7c5025e59d 717 const char *dhm_P[] = {
Janos Follath 0:1f7c5025e59d 718 MBEDTLS_DHM_RFC3526_MODP_2048_P,
Janos Follath 0:1f7c5025e59d 719 MBEDTLS_DHM_RFC3526_MODP_3072_P,
Janos Follath 0:1f7c5025e59d 720 };
Janos Follath 0:1f7c5025e59d 721 const char *dhm_G[] = {
Janos Follath 0:1f7c5025e59d 722 MBEDTLS_DHM_RFC3526_MODP_2048_G,
Janos Follath 0:1f7c5025e59d 723 MBEDTLS_DHM_RFC3526_MODP_3072_G,
Janos Follath 0:1f7c5025e59d 724 };
Janos Follath 0:1f7c5025e59d 725
Janos Follath 0:1f7c5025e59d 726 mbedtls_dhm_context dhm;
Janos Follath 0:1f7c5025e59d 727 size_t olen;
Janos Follath 0:1f7c5025e59d 728 for( i = 0; (size_t) i < sizeof( dhm_sizes ) / sizeof( dhm_sizes[0] ); i++ )
Janos Follath 0:1f7c5025e59d 729 {
Janos Follath 0:1f7c5025e59d 730 mbedtls_dhm_init( &dhm );
Janos Follath 0:1f7c5025e59d 731
Janos Follath 0:1f7c5025e59d 732 if( mbedtls_mpi_read_string( &dhm.P, 16, dhm_P[i] ) != 0 ||
Janos Follath 0:1f7c5025e59d 733 mbedtls_mpi_read_string( &dhm.G, 16, dhm_G[i] ) != 0 )
Janos Follath 0:1f7c5025e59d 734 {
mbed_official 63:9f7e5224fc60 735 return( 1 );
Janos Follath 0:1f7c5025e59d 736 }
Janos Follath 0:1f7c5025e59d 737
Janos Follath 0:1f7c5025e59d 738 dhm.len = mbedtls_mpi_size( &dhm.P );
Janos Follath 0:1f7c5025e59d 739 mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL );
Janos Follath 0:1f7c5025e59d 740 if( mbedtls_mpi_copy( &dhm.GY, &dhm.GX ) != 0 )
mbed_official 63:9f7e5224fc60 741 return( 1 );
Janos Follath 0:1f7c5025e59d 742
Janos Follath 0:1f7c5025e59d 743 mbedtls_snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] );
Janos Follath 0:1f7c5025e59d 744 TIME_PUBLIC( title, "handshake",
Janos Follath 0:1f7c5025e59d 745 ret |= mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len,
Janos Follath 0:1f7c5025e59d 746 myrand, NULL );
Janos Follath 0:1f7c5025e59d 747 ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 748
Janos Follath 0:1f7c5025e59d 749 mbedtls_snprintf( title, sizeof( title ), "DH-%d", dhm_sizes[i] );
Janos Follath 0:1f7c5025e59d 750 TIME_PUBLIC( title, "handshake",
Janos Follath 0:1f7c5025e59d 751 ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 752
Janos Follath 0:1f7c5025e59d 753 mbedtls_dhm_free( &dhm );
Janos Follath 0:1f7c5025e59d 754 }
Janos Follath 0:1f7c5025e59d 755 }
Janos Follath 0:1f7c5025e59d 756 #endif
Janos Follath 0:1f7c5025e59d 757
mbed_official 11:6ccae3ebafd5 758 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_SHA256_C) && defined(ENABLE_ECDSA)
mbed_official 70:72c865037f5d 759 if( todo->ecdsa )
Janos Follath 0:1f7c5025e59d 760 {
Janos Follath 0:1f7c5025e59d 761 mbedtls_ecdsa_context ecdsa;
Janos Follath 0:1f7c5025e59d 762 const mbedtls_ecp_curve_info *curve_info;
Janos Follath 0:1f7c5025e59d 763 size_t sig_len;
Janos Follath 0:1f7c5025e59d 764
Janos Follath 0:1f7c5025e59d 765 memset( buf, 0x2A, sizeof( buf ) );
Janos Follath 0:1f7c5025e59d 766
Janos Follath 0:1f7c5025e59d 767 for( curve_info = mbedtls_ecp_curve_list();
Janos Follath 0:1f7c5025e59d 768 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Janos Follath 0:1f7c5025e59d 769 curve_info++ )
Janos Follath 0:1f7c5025e59d 770 {
Janos Follath 0:1f7c5025e59d 771 mbedtls_ecdsa_init( &ecdsa );
Janos Follath 0:1f7c5025e59d 772
Janos Follath 0:1f7c5025e59d 773 if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 )
mbed_official 63:9f7e5224fc60 774 return( 1 );
Janos Follath 0:1f7c5025e59d 775 ecp_clear_precomputed( &ecdsa.grp );
Janos Follath 0:1f7c5025e59d 776
Janos Follath 0:1f7c5025e59d 777 mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s",
Janos Follath 0:1f7c5025e59d 778 curve_info->name );
Janos Follath 0:1f7c5025e59d 779 TIME_PUBLIC( title, "sign",
mbed_official 70:72c865037f5d 780 ret = mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, ( curve_info->bit_size + 7 ) / 8,
Janos Follath 0:1f7c5025e59d 781 tmp, &sig_len, myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 782
Janos Follath 0:1f7c5025e59d 783 mbedtls_ecdsa_free( &ecdsa );
Janos Follath 0:1f7c5025e59d 784 }
Janos Follath 0:1f7c5025e59d 785
Janos Follath 0:1f7c5025e59d 786 for( curve_info = mbedtls_ecp_curve_list();
Janos Follath 0:1f7c5025e59d 787 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Janos Follath 0:1f7c5025e59d 788 curve_info++ )
Janos Follath 0:1f7c5025e59d 789 {
Janos Follath 0:1f7c5025e59d 790 mbedtls_ecdsa_init( &ecdsa );
Janos Follath 0:1f7c5025e59d 791
Janos Follath 0:1f7c5025e59d 792 if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 ||
mbed_official 70:72c865037f5d 793 mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, ( curve_info->bit_size + 7 ) / 8,
Janos Follath 0:1f7c5025e59d 794 tmp, &sig_len, myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 795 {
mbed_official 63:9f7e5224fc60 796 return( 1 );
Janos Follath 0:1f7c5025e59d 797 }
Janos Follath 0:1f7c5025e59d 798 ecp_clear_precomputed( &ecdsa.grp );
Janos Follath 0:1f7c5025e59d 799
Janos Follath 0:1f7c5025e59d 800 mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s",
Janos Follath 0:1f7c5025e59d 801 curve_info->name );
Janos Follath 0:1f7c5025e59d 802 TIME_PUBLIC( title, "verify",
mbed_official 70:72c865037f5d 803 ret = mbedtls_ecdsa_read_signature( &ecdsa, buf, ( curve_info->bit_size + 7 ) / 8,
Janos Follath 0:1f7c5025e59d 804 tmp, sig_len ) );
Janos Follath 0:1f7c5025e59d 805
Janos Follath 0:1f7c5025e59d 806 mbedtls_ecdsa_free( &ecdsa );
Janos Follath 0:1f7c5025e59d 807 }
Janos Follath 0:1f7c5025e59d 808 }
Janos Follath 0:1f7c5025e59d 809 #endif
Janos Follath 0:1f7c5025e59d 810
Janos Follath 0:1f7c5025e59d 811 #if defined(MBEDTLS_ECDH_C)
mbed_official 70:72c865037f5d 812 if( todo->ecdh )
Janos Follath 0:1f7c5025e59d 813 {
Janos Follath 0:1f7c5025e59d 814 mbedtls_ecdh_context ecdh;
Janos Follath 0:1f7c5025e59d 815 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
Janos Follath 0:1f7c5025e59d 816 mbedtls_mpi z;
Janos Follath 0:1f7c5025e59d 817 #endif
Janos Follath 0:1f7c5025e59d 818 const mbedtls_ecp_curve_info *curve_info;
Janos Follath 0:1f7c5025e59d 819 size_t olen;
Janos Follath 0:1f7c5025e59d 820
Janos Follath 0:1f7c5025e59d 821 for( curve_info = mbedtls_ecp_curve_list();
Janos Follath 0:1f7c5025e59d 822 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Janos Follath 0:1f7c5025e59d 823 curve_info++ )
Janos Follath 0:1f7c5025e59d 824 {
Janos Follath 0:1f7c5025e59d 825 mbedtls_ecdh_init( &ecdh );
Janos Follath 0:1f7c5025e59d 826
Janos Follath 0:1f7c5025e59d 827 if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 ||
Janos Follath 0:1f7c5025e59d 828 mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 829 myrand, NULL ) != 0 ||
Janos Follath 0:1f7c5025e59d 830 mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 )
Janos Follath 0:1f7c5025e59d 831 {
mbed_official 63:9f7e5224fc60 832 return( 1 );
Janos Follath 0:1f7c5025e59d 833 }
Janos Follath 0:1f7c5025e59d 834 ecp_clear_precomputed( &ecdh.grp );
Janos Follath 0:1f7c5025e59d 835
Janos Follath 0:1f7c5025e59d 836 mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s",
Janos Follath 0:1f7c5025e59d 837 curve_info->name );
Janos Follath 0:1f7c5025e59d 838 TIME_PUBLIC( title, "handshake",
Janos Follath 0:1f7c5025e59d 839 ret |= mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 840 myrand, NULL );
Janos Follath 0:1f7c5025e59d 841 ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 842 myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 843 mbedtls_ecdh_free( &ecdh );
Janos Follath 0:1f7c5025e59d 844 }
Janos Follath 0:1f7c5025e59d 845
Janos Follath 0:1f7c5025e59d 846 /* Curve25519 needs to be handled separately */
Janos Follath 0:1f7c5025e59d 847 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
Janos Follath 0:1f7c5025e59d 848 mbedtls_ecdh_init( &ecdh );
Janos Follath 0:1f7c5025e59d 849 mbedtls_mpi_init( &z );
Janos Follath 0:1f7c5025e59d 850
Janos Follath 0:1f7c5025e59d 851 if( mbedtls_ecp_group_load( &ecdh.grp, MBEDTLS_ECP_DP_CURVE25519 ) != 0 ||
Janos Follath 0:1f7c5025e59d 852 mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 853 {
mbed_official 63:9f7e5224fc60 854 return( 1 );
Janos Follath 0:1f7c5025e59d 855 }
Janos Follath 0:1f7c5025e59d 856
Janos Follath 0:1f7c5025e59d 857 TIME_PUBLIC( "ECDHE-Curve25519", "handshake",
Janos Follath 0:1f7c5025e59d 858 ret |= mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q,
Janos Follath 0:1f7c5025e59d 859 myrand, NULL );
Janos Follath 0:1f7c5025e59d 860 ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
Janos Follath 0:1f7c5025e59d 861 myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 862
Janos Follath 0:1f7c5025e59d 863 mbedtls_ecdh_free( &ecdh );
Janos Follath 0:1f7c5025e59d 864 mbedtls_mpi_free( &z );
Janos Follath 0:1f7c5025e59d 865 #endif
Janos Follath 0:1f7c5025e59d 866
Janos Follath 0:1f7c5025e59d 867 for( curve_info = mbedtls_ecp_curve_list();
Janos Follath 0:1f7c5025e59d 868 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Janos Follath 0:1f7c5025e59d 869 curve_info++ )
Janos Follath 0:1f7c5025e59d 870 {
Janos Follath 0:1f7c5025e59d 871 mbedtls_ecdh_init( &ecdh );
Janos Follath 0:1f7c5025e59d 872
Janos Follath 0:1f7c5025e59d 873 if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 ||
Janos Follath 0:1f7c5025e59d 874 mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 875 myrand, NULL ) != 0 ||
Janos Follath 0:1f7c5025e59d 876 mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 ||
Janos Follath 0:1f7c5025e59d 877 mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 878 myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 879 {
mbed_official 63:9f7e5224fc60 880 return( 1 );
Janos Follath 0:1f7c5025e59d 881 }
Janos Follath 0:1f7c5025e59d 882 ecp_clear_precomputed( &ecdh.grp );
Janos Follath 0:1f7c5025e59d 883
Janos Follath 0:1f7c5025e59d 884 mbedtls_snprintf( title, sizeof( title ), "ECDH-%s",
Janos Follath 0:1f7c5025e59d 885 curve_info->name );
Janos Follath 0:1f7c5025e59d 886 TIME_PUBLIC( title, "handshake",
Janos Follath 0:1f7c5025e59d 887 ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
Janos Follath 0:1f7c5025e59d 888 myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 889 mbedtls_ecdh_free( &ecdh );
Janos Follath 0:1f7c5025e59d 890 }
Janos Follath 0:1f7c5025e59d 891
Janos Follath 0:1f7c5025e59d 892 /* Curve25519 needs to be handled separately */
Janos Follath 0:1f7c5025e59d 893 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
Janos Follath 0:1f7c5025e59d 894 mbedtls_ecdh_init( &ecdh );
Janos Follath 0:1f7c5025e59d 895 mbedtls_mpi_init( &z );
Janos Follath 0:1f7c5025e59d 896
Janos Follath 0:1f7c5025e59d 897 if( mbedtls_ecp_group_load( &ecdh.grp, MBEDTLS_ECP_DP_CURVE25519 ) != 0 ||
Janos Follath 0:1f7c5025e59d 898 mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp,
Janos Follath 0:1f7c5025e59d 899 myrand, NULL ) != 0 ||
Janos Follath 0:1f7c5025e59d 900 mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL ) != 0 )
Janos Follath 0:1f7c5025e59d 901 {
mbed_official 63:9f7e5224fc60 902 return( 1 );
Janos Follath 0:1f7c5025e59d 903 }
Janos Follath 0:1f7c5025e59d 904
Janos Follath 0:1f7c5025e59d 905 TIME_PUBLIC( "ECDH-Curve25519", "handshake",
Janos Follath 0:1f7c5025e59d 906 ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
Janos Follath 0:1f7c5025e59d 907 myrand, NULL ) );
Janos Follath 0:1f7c5025e59d 908
Janos Follath 0:1f7c5025e59d 909 mbedtls_ecdh_free( &ecdh );
Janos Follath 0:1f7c5025e59d 910 mbedtls_mpi_free( &z );
Janos Follath 0:1f7c5025e59d 911 #endif
Janos Follath 0:1f7c5025e59d 912 }
Janos Follath 0:1f7c5025e59d 913 #endif
mbed_official 70:72c865037f5d 914 return ( 0 );
mbed_official 70:72c865037f5d 915
mbed_official 70:72c865037f5d 916 }
mbed_official 70:72c865037f5d 917
mbed_official 70:72c865037f5d 918 static int benchmark( int argc, char *argv[], mbedtls_platform_context* ctx )
mbed_official 70:72c865037f5d 919 {
mbed_official 70:72c865037f5d 920 int i;
mbed_official 70:72c865037f5d 921 todo_list todo;
mbed_official 70:72c865037f5d 922 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
mbed_official 70:72c865037f5d 923 unsigned char malloc_buf[HEAP_SIZE] = { 0 };
mbed_official 70:72c865037f5d 924 #endif
mbed_official 70:72c865037f5d 925
mbed_official 70:72c865037f5d 926 if( argc <= 1 )
mbed_official 70:72c865037f5d 927 {
mbed_official 70:72c865037f5d 928 memset( &todo, 1, sizeof( todo ) );
mbed_official 70:72c865037f5d 929 }
mbed_official 70:72c865037f5d 930 else
mbed_official 70:72c865037f5d 931 {
mbed_official 70:72c865037f5d 932 memset( &todo, 0, sizeof( todo ) );
mbed_official 70:72c865037f5d 933
mbed_official 70:72c865037f5d 934 for( i = 1; i < argc; i++ )
mbed_official 70:72c865037f5d 935 {
mbed_official 70:72c865037f5d 936 if( strcmp( argv[i], "md4" ) == 0 )
mbed_official 70:72c865037f5d 937 todo.md4 = 1;
mbed_official 70:72c865037f5d 938 else if( strcmp( argv[i], "md5" ) == 0 )
mbed_official 70:72c865037f5d 939 todo.md5 = 1;
mbed_official 70:72c865037f5d 940 else if( strcmp( argv[i], "ripemd160" ) == 0 )
mbed_official 70:72c865037f5d 941 todo.ripemd160 = 1;
mbed_official 70:72c865037f5d 942 else if( strcmp( argv[i], "sha1" ) == 0 )
mbed_official 70:72c865037f5d 943 todo.sha1 = 1;
mbed_official 70:72c865037f5d 944 else if( strcmp( argv[i], "sha256" ) == 0 )
mbed_official 70:72c865037f5d 945 todo.sha256 = 1;
mbed_official 70:72c865037f5d 946 else if( strcmp( argv[i], "sha512" ) == 0 )
mbed_official 70:72c865037f5d 947 todo.sha512 = 1;
mbed_official 70:72c865037f5d 948 else if( strcmp( argv[i], "arc4" ) == 0 )
mbed_official 70:72c865037f5d 949 todo.arc4 = 1;
mbed_official 70:72c865037f5d 950 else if( strcmp( argv[i], "des3" ) == 0 )
mbed_official 70:72c865037f5d 951 todo.des3 = 1;
mbed_official 70:72c865037f5d 952 else if( strcmp( argv[i], "des" ) == 0 )
mbed_official 70:72c865037f5d 953 todo.des = 1;
mbed_official 70:72c865037f5d 954 else if( strcmp( argv[i], "aes_cbc" ) == 0 )
mbed_official 70:72c865037f5d 955 todo.aes_cbc = 1;
mbed_official 70:72c865037f5d 956 else if( strcmp( argv[i], "aes_ctr" ) == 0 )
mbed_official 70:72c865037f5d 957 todo.aes_ctr = 1;
mbed_official 70:72c865037f5d 958 else if( strcmp( argv[i], "aes_gcm" ) == 0 )
mbed_official 70:72c865037f5d 959 todo.aes_gcm = 1;
mbed_official 70:72c865037f5d 960 else if( strcmp( argv[i], "aes_ccm" ) == 0 )
mbed_official 70:72c865037f5d 961 todo.aes_ccm = 1;
mbed_official 70:72c865037f5d 962 else if( strcmp( argv[i], "aes_cmac" ) == 0 )
mbed_official 70:72c865037f5d 963 todo.aes_cmac = 1;
mbed_official 70:72c865037f5d 964 else if( strcmp( argv[i], "des3_cmac" ) == 0 )
mbed_official 70:72c865037f5d 965 todo.des3_cmac = 1;
mbed_official 70:72c865037f5d 966 else if( strcmp( argv[i], "camellia" ) == 0 )
mbed_official 70:72c865037f5d 967 todo.camellia = 1;
mbed_official 70:72c865037f5d 968 else if( strcmp( argv[i], "blowfish" ) == 0 )
mbed_official 70:72c865037f5d 969 todo.blowfish = 1;
mbed_official 70:72c865037f5d 970 else if( strcmp( argv[i], "havege" ) == 0 )
mbed_official 70:72c865037f5d 971 todo.havege = 1;
mbed_official 70:72c865037f5d 972 else if( strcmp( argv[i], "ctr_drbg" ) == 0 )
mbed_official 70:72c865037f5d 973 todo.ctr_drbg = 1;
mbed_official 70:72c865037f5d 974 else if( strcmp( argv[i], "hmac_drbg" ) == 0 )
mbed_official 70:72c865037f5d 975 todo.hmac_drbg = 1;
mbed_official 70:72c865037f5d 976 else if( strcmp( argv[i], "rsa" ) == 0 )
mbed_official 70:72c865037f5d 977 todo.rsa = 1;
mbed_official 70:72c865037f5d 978 else if( strcmp( argv[i], "dhm" ) == 0 )
mbed_official 70:72c865037f5d 979 todo.dhm = 1;
mbed_official 70:72c865037f5d 980 else if( strcmp( argv[i], "ecdsa" ) == 0 )
mbed_official 70:72c865037f5d 981 todo.ecdsa = 1;
mbed_official 70:72c865037f5d 982 else if( strcmp( argv[i], "ecdh" ) == 0 )
mbed_official 70:72c865037f5d 983 todo.ecdh = 1;
mbed_official 70:72c865037f5d 984 else
mbed_official 70:72c865037f5d 985 {
mbed_official 70:72c865037f5d 986 mbedtls_printf( "Unrecognized option: %s\r\n", argv[i] );
mbed_official 70:72c865037f5d 987 mbedtls_printf( "Available options: " OPTIONS );
mbed_official 70:72c865037f5d 988 }
mbed_official 70:72c865037f5d 989 }
mbed_official 70:72c865037f5d 990 }
mbed_official 70:72c865037f5d 991
mbed_official 70:72c865037f5d 992 mbedtls_printf( "\r\n\r\n" );
mbed_official 70:72c865037f5d 993
mbed_official 70:72c865037f5d 994 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
mbed_official 70:72c865037f5d 995 mbedtls_memory_buffer_alloc_init( malloc_buf, sizeof( malloc_buf ) );
mbed_official 70:72c865037f5d 996 #endif
mbed_official 70:72c865037f5d 997 memset( buf, 0xAA, sizeof( buf ) );
mbed_official 70:72c865037f5d 998
mbed_official 70:72c865037f5d 999 if( test_md( &todo, ctx ) != 0)
mbed_official 70:72c865037f5d 1000 return ( 1 );
mbed_official 70:72c865037f5d 1001 if( test_crypt( &todo, ctx ) != 0)
mbed_official 70:72c865037f5d 1002 return ( 1 );
mbed_official 70:72c865037f5d 1003 if( test_rng( &todo, ctx ) != 0)
mbed_official 70:72c865037f5d 1004 return ( 1 );
mbed_official 70:72c865037f5d 1005 if( test_pk( &todo, ctx ) != 0)
mbed_official 70:72c865037f5d 1006 return ( 1 );
Janos Follath 0:1f7c5025e59d 1007
Janos Follath 0:1f7c5025e59d 1008 mbedtls_printf("\r\nDONE\r\n");
Janos Follath 0:1f7c5025e59d 1009
Janos Follath 0:1f7c5025e59d 1010 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Janos Follath 0:1f7c5025e59d 1011 mbedtls_memory_buffer_alloc_free();
Janos Follath 0:1f7c5025e59d 1012 #endif
Janos Follath 0:1f7c5025e59d 1013
Janos Follath 0:1f7c5025e59d 1014 return( 0 );
Janos Follath 0:1f7c5025e59d 1015 }
Janos Follath 0:1f7c5025e59d 1016
Janos Follath 0:1f7c5025e59d 1017 int main(void) {
mbed_official 63:9f7e5224fc60 1018 mbedtls_platform_context platform_ctx;
mbed_official 63:9f7e5224fc60 1019 int exit_code = MBEDTLS_EXIT_FAILURE;
mbed_official 63:9f7e5224fc60 1020
mbed_official 63:9f7e5224fc60 1021 if((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) {
mbed_official 63:9f7e5224fc60 1022 printf("Platform initialization failed with error %d\r\n", exit_code);
mbed_official 63:9f7e5224fc60 1023 return MBEDTLS_EXIT_FAILURE;
Janos Follath 0:1f7c5025e59d 1024 }
mbed_official 63:9f7e5224fc60 1025
mbed_official 63:9f7e5224fc60 1026 exit_code = benchmark(0, NULL, &platform_ctx);
mbed_official 63:9f7e5224fc60 1027 if (exit_code != 0) {
mbed_official 63:9f7e5224fc60 1028 mbedtls_printf("Benchmark failed with error %d\r\n", exit_code);
mbed_official 63:9f7e5224fc60 1029 exit_code = MBEDTLS_EXIT_FAILURE;
mbed_official 63:9f7e5224fc60 1030 }
mbed_official 63:9f7e5224fc60 1031
mbed_official 63:9f7e5224fc60 1032 mbedtls_platform_teardown(&platform_ctx);
mbed_official 63:9f7e5224fc60 1033 return exit_code;
Janos Follath 0:1f7c5025e59d 1034 }