2011-07-27 00:27:22 +04:00
|
|
|
/* benchmark.c
|
|
|
|
*
|
2014-04-12 01:58:58 +04:00
|
|
|
* Copyright (C) 2006-2014 wolfSSL Inc.
|
2011-07-27 00:27:22 +04:00
|
|
|
*
|
|
|
|
* This file is part of CyaSSL.
|
|
|
|
*
|
|
|
|
* CyaSSL is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* CyaSSL is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2014-04-12 01:58:58 +04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2011-07-27 00:27:22 +04:00
|
|
|
*/
|
2011-08-05 02:42:55 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
/* CTaoCrypt benchmark */
|
|
|
|
|
2011-08-25 03:37:16 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2011-08-05 02:42:55 +04:00
|
|
|
|
2013-04-10 23:17:23 +04:00
|
|
|
#include <cyassl/ctaocrypt/settings.h>
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/des3.h>
|
|
|
|
#include <cyassl/ctaocrypt/arc4.h>
|
|
|
|
#include <cyassl/ctaocrypt/hc128.h>
|
|
|
|
#include <cyassl/ctaocrypt/rabbit.h>
|
2014-07-02 00:16:44 +04:00
|
|
|
#include <cyassl/ctaocrypt/chacha.h>
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/aes.h>
|
2014-07-02 00:16:44 +04:00
|
|
|
#include <cyassl/ctaocrypt/poly1305.h>
|
2013-01-18 09:52:31 +04:00
|
|
|
#include <cyassl/ctaocrypt/camellia.h>
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/md5.h>
|
|
|
|
#include <cyassl/ctaocrypt/sha.h>
|
|
|
|
#include <cyassl/ctaocrypt/sha256.h>
|
|
|
|
#include <cyassl/ctaocrypt/sha512.h>
|
|
|
|
#include <cyassl/ctaocrypt/rsa.h>
|
|
|
|
#include <cyassl/ctaocrypt/asn.h>
|
|
|
|
#include <cyassl/ctaocrypt/ripemd.h>
|
2011-12-23 02:59:57 +04:00
|
|
|
#include <cyassl/ctaocrypt/ecc.h>
|
2011-08-25 23:41:19 +04:00
|
|
|
|
|
|
|
#include <cyassl/ctaocrypt/dh.h>
|
2013-01-30 04:22:49 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
#include "cavium_sysdep.h"
|
|
|
|
#include "cavium_common.h"
|
|
|
|
#include "cavium_ioctl.h"
|
|
|
|
#endif
|
2013-11-07 05:29:01 +04:00
|
|
|
|
|
|
|
#if defined(CYASSL_MDK_ARM)
|
|
|
|
extern FILE * CyaSSL_fopen(const char *fname, const char *mode) ;
|
|
|
|
#define fopen CyaSSL_fopen
|
|
|
|
#endif
|
|
|
|
|
2013-01-30 21:13:56 +04:00
|
|
|
#if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)
|
|
|
|
/* include test cert and key buffers for use with NO_FILESYSTEM */
|
2013-05-16 20:47:27 +04:00
|
|
|
#if defined(CYASSL_MDK_ARM)
|
|
|
|
#include "cert_data.h" /* use certs_test.c for initial data,
|
|
|
|
so other commands can share the data. */
|
|
|
|
#else
|
|
|
|
#include <cyassl/certs_test.h>
|
|
|
|
#endif
|
2013-01-30 21:13:56 +04:00
|
|
|
#endif
|
2013-01-30 04:22:49 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-03-23 00:30:44 +04:00
|
|
|
#ifdef HAVE_BLAKE2
|
2013-01-01 01:10:47 +04:00
|
|
|
#include <cyassl/ctaocrypt/blake2.h>
|
|
|
|
void bench_blake2(void);
|
|
|
|
#endif
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
/* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
|
|
|
|
#pragma warning(disable: 4996)
|
|
|
|
#endif
|
|
|
|
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_des(void);
|
|
|
|
void bench_arc4(void);
|
|
|
|
void bench_hc128(void);
|
|
|
|
void bench_rabbit(void);
|
2014-07-02 00:16:44 +04:00
|
|
|
void bench_chacha(void);
|
2011-02-05 22:14:47 +03:00
|
|
|
void bench_aes(int);
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_aesgcm(void);
|
2013-01-11 04:38:52 +04:00
|
|
|
void bench_aesccm(void);
|
2014-03-11 06:32:16 +04:00
|
|
|
void bench_aesctr(void);
|
2014-07-02 00:16:44 +04:00
|
|
|
void bench_poly1305(void);
|
2013-01-18 09:52:31 +04:00
|
|
|
void bench_camellia(void);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_md5(void);
|
|
|
|
void bench_sha(void);
|
|
|
|
void bench_sha256(void);
|
|
|
|
void bench_sha512(void);
|
|
|
|
void bench_ripemd(void);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_rsa(void);
|
|
|
|
void bench_rsaKeyGen(void);
|
|
|
|
void bench_dh(void);
|
2011-12-23 02:59:57 +04:00
|
|
|
#ifdef HAVE_ECC
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_eccKeyGen(void);
|
|
|
|
void bench_eccKeyAgree(void);
|
2011-12-23 02:59:57 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
double current_time(int);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
2013-01-30 04:22:49 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
|
|
|
|
static int OpenNitroxDevice(int dma_mode,int dev_id)
|
|
|
|
{
|
|
|
|
Csp1CoreAssignment core_assign;
|
|
|
|
Uint32 device;
|
|
|
|
|
|
|
|
if (CspInitialize(CAVIUM_DIRECT,CAVIUM_DEV_ID))
|
|
|
|
return -1;
|
|
|
|
if (Csp1GetDevType(&device))
|
|
|
|
return -1;
|
|
|
|
if (device != NPX_DEVICE) {
|
|
|
|
if (ioctl(gpkpdev_hdlr[CAVIUM_DEV_ID], IOCTL_CSP1_GET_CORE_ASSIGNMENT,
|
|
|
|
(Uint32 *)&core_assign)!= 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
CspShutdown(CAVIUM_DEV_ID);
|
|
|
|
|
|
|
|
return CspInitialize(dma_mode, dev_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
2013-01-30 21:20:39 +04:00
|
|
|
/* so embedded projects can pull in tests on their own */
|
2013-05-16 20:47:27 +04:00
|
|
|
#if !defined(NO_MAIN_DRIVER)
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
2013-05-16 20:47:27 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
2012-09-20 10:38:41 +04:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
2013-05-16 20:47:27 +04:00
|
|
|
#else
|
|
|
|
int benchmark_test(void *args)
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CAVIUM
|
2013-01-30 04:22:49 +04:00
|
|
|
int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Cavium OpenNitroxDevice failed\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_CAVIUM */
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifndef NO_AES
|
|
|
|
bench_aes(0);
|
|
|
|
bench_aes(1);
|
2012-07-01 03:55:29 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_AESGCM
|
|
|
|
bench_aesgcm();
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
2014-03-11 06:32:16 +04:00
|
|
|
|
|
|
|
#ifdef CYASSL_AES_COUNTER
|
|
|
|
bench_aesctr();
|
|
|
|
#endif
|
|
|
|
|
2013-01-11 04:38:52 +04:00
|
|
|
#ifdef HAVE_AESCCM
|
|
|
|
bench_aesccm();
|
|
|
|
#endif
|
2013-01-18 09:52:31 +04:00
|
|
|
#ifdef HAVE_CAMELLIA
|
|
|
|
bench_camellia();
|
|
|
|
#endif
|
2012-12-01 03:45:43 +04:00
|
|
|
#ifndef NO_RC4
|
2011-02-05 22:14:47 +03:00
|
|
|
bench_arc4();
|
2012-12-01 03:45:43 +04:00
|
|
|
#endif
|
2011-09-29 00:19:05 +04:00
|
|
|
#ifdef HAVE_HC128
|
2011-02-05 22:14:47 +03:00
|
|
|
bench_hc128();
|
|
|
|
#endif
|
|
|
|
#ifndef NO_RABBIT
|
|
|
|
bench_rabbit();
|
|
|
|
#endif
|
2014-07-02 00:16:44 +04:00
|
|
|
#ifdef HAVE_CHACHA
|
|
|
|
bench_chacha();
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifndef NO_DES3
|
|
|
|
bench_des();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
2012-11-27 04:28:22 +04:00
|
|
|
#ifndef NO_MD5
|
2011-02-05 22:14:47 +03:00
|
|
|
bench_md5();
|
2012-11-27 04:28:22 +04:00
|
|
|
#endif
|
2014-07-02 00:16:44 +04:00
|
|
|
#ifdef HAVE_POLY1305
|
|
|
|
bench_poly1305();
|
|
|
|
#endif
|
2013-03-12 03:07:46 +04:00
|
|
|
#ifndef NO_SHA
|
2011-02-05 22:14:47 +03:00
|
|
|
bench_sha();
|
2013-03-12 03:07:46 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifndef NO_SHA256
|
|
|
|
bench_sha256();
|
|
|
|
#endif
|
|
|
|
#ifdef CYASSL_SHA512
|
|
|
|
bench_sha512();
|
|
|
|
#endif
|
|
|
|
#ifdef CYASSL_RIPEMD
|
|
|
|
bench_ripemd();
|
|
|
|
#endif
|
2013-03-23 00:30:44 +04:00
|
|
|
#ifdef HAVE_BLAKE2
|
2013-01-01 01:10:47 +04:00
|
|
|
bench_blake2();
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
printf("\n");
|
2012-10-30 02:39:42 +04:00
|
|
|
|
|
|
|
#ifndef NO_RSA
|
2011-02-05 22:14:47 +03:00
|
|
|
bench_rsa();
|
2012-10-30 02:39:42 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
#ifndef NO_DH
|
|
|
|
bench_dh();
|
|
|
|
#endif
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#if defined(CYASSL_KEY_GEN) && !defined(NO_RSA)
|
2011-02-05 22:14:47 +03:00
|
|
|
bench_rsaKeyGen();
|
|
|
|
#endif
|
|
|
|
|
2011-12-23 02:59:57 +04:00
|
|
|
#ifdef HAVE_ECC
|
|
|
|
bench_eccKeyGen();
|
|
|
|
bench_eccKeyAgree();
|
|
|
|
#endif
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-30 21:20:39 +04:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
#ifdef BENCH_EMBEDDED
|
2014-03-11 20:38:36 +04:00
|
|
|
enum BenchmarkBounds {
|
|
|
|
numBlocks = 25, /* how many kB to test (en/de)cryption */
|
|
|
|
ntimes = 1,
|
|
|
|
genTimes = 5, /* public key iterations */
|
|
|
|
agreeTimes = 5
|
|
|
|
};
|
|
|
|
static const char blockType[] = "kB"; /* used in printf output */
|
2013-01-31 03:19:19 +04:00
|
|
|
#else
|
2014-03-11 20:38:36 +04:00
|
|
|
enum BenchmarkBounds {
|
|
|
|
numBlocks = 5, /* how many megs to test (en/de)cryption */
|
|
|
|
ntimes = 100,
|
|
|
|
genTimes = 100,
|
|
|
|
agreeTimes = 100
|
|
|
|
};
|
|
|
|
static const char blockType[] = "megs"; /* used in printf output */
|
2013-01-31 03:19:19 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-02 23:06:41 +04:00
|
|
|
static const byte key[] =
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
|
|
|
|
0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
|
|
|
|
0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
|
|
|
|
};
|
|
|
|
|
2014-03-02 23:06:41 +04:00
|
|
|
static const byte iv[] =
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
|
|
|
|
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
|
|
|
|
0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
/* use kB instead of mB for embedded benchmarking */
|
|
|
|
#ifdef BENCH_EMBEDDED
|
2014-03-02 23:06:41 +04:00
|
|
|
static byte plain [1024];
|
|
|
|
static byte cipher[1024];
|
2013-01-31 03:19:19 +04:00
|
|
|
#else
|
2014-03-02 23:06:41 +04:00
|
|
|
static byte plain [1024*1024];
|
|
|
|
static byte cipher[1024*1024];
|
2013-01-31 03:19:19 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef NO_AES
|
|
|
|
void bench_aes(int show)
|
|
|
|
{
|
|
|
|
Aes enc;
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
2014-03-20 00:56:11 +04:00
|
|
|
int ret;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-30 04:22:49 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
2014-03-20 00:56:11 +04:00
|
|
|
if (AesInitCavium(&enc, CAVIUM_DEV_ID) != 0) {
|
2013-01-30 04:22:49 +04:00
|
|
|
printf("aes init cavium failed\n");
|
2014-03-20 00:56:11 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-30 04:22:49 +04:00
|
|
|
#endif
|
|
|
|
|
2014-03-20 00:56:11 +04:00
|
|
|
ret = AesSetKey(&enc, key, 16, iv, AES_ENCRYPTION);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("AesSetKey failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2011-02-05 22:14:47 +03:00
|
|
|
AesCbcEncrypt(&enc, plain, cipher, sizeof(plain));
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
if (show)
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("AES %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2013-01-30 04:22:49 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
AesFreeCavium(&enc);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-03-02 23:06:41 +04:00
|
|
|
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
|
|
|
|
static byte additional[13];
|
|
|
|
static byte tag[16];
|
|
|
|
#endif
|
2012-07-01 03:55:29 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_AESGCM
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_aesgcm(void)
|
2012-07-01 03:55:29 +04:00
|
|
|
{
|
|
|
|
Aes enc;
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
|
2013-01-15 03:59:53 +04:00
|
|
|
AesGcmSetKey(&enc, key, 16);
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2012-07-01 03:55:29 +04:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2013-01-15 03:59:53 +04:00
|
|
|
AesGcmEncrypt(&enc, cipher, plain, sizeof(plain), iv, 12,
|
2012-07-01 03:55:29 +04:00
|
|
|
tag, 16, additional, 13);
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2012-07-01 03:55:29 +04:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("AES-GCM %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2012-07-01 03:55:29 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-11 06:32:16 +04:00
|
|
|
#ifdef CYASSL_AES_COUNTER
|
|
|
|
void bench_aesctr(void)
|
|
|
|
{
|
|
|
|
Aes enc;
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
2012-07-01 03:55:29 +04:00
|
|
|
|
2014-03-11 06:32:16 +04:00
|
|
|
AesSetKeyDirect(&enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
|
|
|
|
start = current_time(1);
|
|
|
|
|
|
|
|
for(i = 0; i < numBlocks; i++)
|
|
|
|
AesCtrEncrypt(&enc, plain, cipher, sizeof(plain));
|
|
|
|
|
|
|
|
total = current_time(0) - start;
|
|
|
|
|
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("AES-CTR %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2014-03-11 06:32:16 +04:00
|
|
|
blockType, total, persec);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-12 16:50:37 +04:00
|
|
|
#ifdef HAVE_AESCCM
|
2013-01-11 04:38:52 +04:00
|
|
|
void bench_aesccm(void)
|
|
|
|
{
|
|
|
|
Aes enc;
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
|
2013-01-15 03:59:53 +04:00
|
|
|
AesCcmSetKey(&enc, key, 16);
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2013-01-11 04:38:52 +04:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2013-01-15 03:59:53 +04:00
|
|
|
AesCcmEncrypt(&enc, cipher, plain, sizeof(plain), iv, 12,
|
2013-01-11 04:38:52 +04:00
|
|
|
tag, 16, additional, 13);
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-11 04:38:52 +04:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("AES-CCM %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2013-01-11 04:38:52 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-07-02 00:16:44 +04:00
|
|
|
#ifdef HAVE_POLY1305
|
|
|
|
void bench_poly1305()
|
|
|
|
{
|
|
|
|
Poly1305 enc;
|
|
|
|
byte mac[16];
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
ret = Poly1305SetKey(&enc, key, 32);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Poly1305SetKey failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
start = current_time(1);
|
|
|
|
|
|
|
|
for(i = 0; i < numBlocks; i++)
|
|
|
|
Poly1305Update(&enc, plain, sizeof(plain));
|
|
|
|
|
|
|
|
Poly1305Final(&enc, mac);
|
|
|
|
total = current_time(0) - start;
|
|
|
|
|
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("POLY1305 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
|
|
|
blockType, total, persec);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_POLY1305 */
|
|
|
|
|
|
|
|
|
2013-01-18 09:52:31 +04:00
|
|
|
#ifdef HAVE_CAMELLIA
|
|
|
|
void bench_camellia(void)
|
|
|
|
{
|
|
|
|
Camellia cam;
|
|
|
|
double start, total, persec;
|
2014-04-03 19:22:48 +04:00
|
|
|
int i, ret;
|
2013-01-18 09:52:31 +04:00
|
|
|
|
2014-04-03 19:22:48 +04:00
|
|
|
ret = CamelliaSetKey(&cam, key, 16, iv);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("CamelliaSetKey failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2013-01-18 09:52:31 +04:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2013-01-18 09:52:31 +04:00
|
|
|
CamelliaCbcEncrypt(&cam, plain, cipher, sizeof(plain));
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-18 09:52:31 +04:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("Camellia %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2013-01-18 09:52:31 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifndef NO_DES3
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_des(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
Des3 enc;
|
|
|
|
double start, total, persec;
|
2014-03-25 00:37:52 +04:00
|
|
|
int i, ret;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-30 04:22:49 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
if (Des3_InitCavium(&enc, CAVIUM_DEV_ID) != 0)
|
|
|
|
printf("des3 init cavium failed\n");
|
|
|
|
#endif
|
2014-03-25 00:37:52 +04:00
|
|
|
ret = Des3_SetKey(&enc, key, iv, DES_ENCRYPTION);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Des3_SetKey failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2011-02-05 22:14:47 +03:00
|
|
|
Des3_CbcEncrypt(&enc, plain, cipher, sizeof(plain));
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("3DES %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2013-01-30 04:22:49 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
Des3_FreeCavium(&enc);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-12-01 03:45:43 +04:00
|
|
|
#ifndef NO_RC4
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_arc4(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
Arc4 enc;
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
|
2013-01-30 04:22:49 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
if (Arc4InitCavium(&enc, CAVIUM_DEV_ID) != 0)
|
|
|
|
printf("arc4 init cavium failed\n");
|
|
|
|
#endif
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
Arc4SetKey(&enc, key, 16);
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2011-02-05 22:14:47 +03:00
|
|
|
Arc4Process(&enc, cipher, plain, sizeof(plain));
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("ARC4 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2013-01-30 04:22:49 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
Arc4FreeCavium(&enc);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
2012-12-01 03:45:43 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
2011-09-29 00:19:05 +04:00
|
|
|
#ifdef HAVE_HC128
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_hc128(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
HC128 enc;
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Hc128_SetKey(&enc, key, iv);
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2011-02-05 22:14:47 +03:00
|
|
|
Hc128_Process(&enc, cipher, plain, sizeof(plain));
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("HC128 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
2011-08-25 02:54:58 +04:00
|
|
|
#endif /* HAVE_HC128 */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef NO_RABBIT
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_rabbit(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
Rabbit enc;
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
RabbitSetKey(&enc, key, iv);
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2011-02-05 22:14:47 +03:00
|
|
|
RabbitProcess(&enc, cipher, plain, sizeof(plain));
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("RABBIT %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
|
|
|
#endif /* NO_RABBIT */
|
|
|
|
|
|
|
|
|
2014-07-02 00:16:44 +04:00
|
|
|
#ifdef HAVE_CHACHA
|
|
|
|
void bench_chacha(void)
|
|
|
|
{
|
|
|
|
ChaCha enc;
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Chacha_SetKey(&enc, key, 16);
|
|
|
|
start = current_time(1);
|
|
|
|
|
|
|
|
for (i = 0; i < numBlocks; i++) {
|
|
|
|
Chacha_SetIV(&enc, iv, 0);
|
|
|
|
Chacha_Process(&enc, cipher, plain, sizeof(plain));
|
|
|
|
}
|
|
|
|
total = current_time(0) - start;
|
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("CHACHA %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks, blockType, total, persec);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* HAVE_CHACHA*/
|
|
|
|
|
|
|
|
|
2012-11-27 04:28:22 +04:00
|
|
|
#ifndef NO_MD5
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_md5(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
Md5 hash;
|
|
|
|
byte digest[MD5_DIGEST_SIZE];
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
InitMd5(&hash);
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2011-02-05 22:14:47 +03:00
|
|
|
Md5Update(&hash, plain, sizeof(plain));
|
|
|
|
|
|
|
|
Md5Final(&hash, digest);
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("MD5 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
2012-11-27 04:28:22 +04:00
|
|
|
#endif /* NO_MD5 */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
2013-03-12 03:07:46 +04:00
|
|
|
#ifndef NO_SHA
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_sha(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
Sha hash;
|
|
|
|
byte digest[SHA_DIGEST_SIZE];
|
|
|
|
double start, total, persec;
|
2014-03-26 03:01:17 +04:00
|
|
|
int i, ret;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-26 03:01:17 +04:00
|
|
|
ret = InitSha(&hash);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("InitSha failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2011-02-05 22:14:47 +03:00
|
|
|
ShaUpdate(&hash, plain, sizeof(plain));
|
|
|
|
|
|
|
|
ShaFinal(&hash, digest);
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("SHA %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
2013-03-12 03:07:46 +04:00
|
|
|
#endif /* NO_SHA */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef NO_SHA256
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_sha256(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
Sha256 hash;
|
|
|
|
byte digest[SHA256_DIGEST_SIZE];
|
|
|
|
double start, total, persec;
|
2014-04-15 19:46:43 +04:00
|
|
|
int i, ret;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-26 04:11:15 +04:00
|
|
|
ret = InitSha256(&hash);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("InitSha256 failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-04-08 18:42:31 +04:00
|
|
|
for(i = 0; i < numBlocks; i++) {
|
|
|
|
ret = Sha256Update(&hash, plain, sizeof(plain));
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Sha256Update failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-04-08 18:42:31 +04:00
|
|
|
ret = Sha256Final(&hash, digest);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Sha256Final failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("SHA-256 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CYASSL_SHA512
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_sha512(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
Sha512 hash;
|
|
|
|
byte digest[SHA512_DIGEST_SIZE];
|
|
|
|
double start, total, persec;
|
2014-03-28 01:03:12 +04:00
|
|
|
int i, ret;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-28 01:03:12 +04:00
|
|
|
ret = InitSha512(&hash);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("InitSha512 failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-04-08 18:42:31 +04:00
|
|
|
for(i = 0; i < numBlocks; i++) {
|
|
|
|
ret = Sha512Update(&hash, plain, sizeof(plain));
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Sha512Update failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = Sha512Final(&hash, digest);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Sha512Final failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("SHA-512 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CYASSL_RIPEMD
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_ripemd(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
RipeMd hash;
|
|
|
|
byte digest[RIPEMD_DIGEST_SIZE];
|
|
|
|
double start, total, persec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
InitRipeMd(&hash);
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:19:19 +04:00
|
|
|
for(i = 0; i < numBlocks; i++)
|
2011-02-05 22:14:47 +03:00
|
|
|
RipeMdUpdate(&hash, plain, sizeof(plain));
|
|
|
|
|
|
|
|
RipeMdFinal(&hash, digest);
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-01-31 03:19:19 +04:00
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("RIPEMD %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-01-31 03:19:19 +04:00
|
|
|
blockType, total, persec);
|
2013-01-01 01:10:47 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-03-23 00:30:44 +04:00
|
|
|
#ifdef HAVE_BLAKE2
|
2013-01-01 01:10:47 +04:00
|
|
|
void bench_blake2(void)
|
|
|
|
{
|
2013-03-25 22:35:33 +04:00
|
|
|
Blake2b b2b;
|
|
|
|
byte digest[64];
|
|
|
|
double start, total, persec;
|
2014-04-15 19:46:43 +04:00
|
|
|
int i, ret;
|
2013-03-23 00:30:44 +04:00
|
|
|
|
2014-04-15 19:46:43 +04:00
|
|
|
ret = InitBlake2b(&b2b, 64);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("InitBlake2b failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-23 03:52:20 +04:00
|
|
|
start = current_time(1);
|
2013-01-01 01:10:47 +04:00
|
|
|
|
2014-04-15 19:46:43 +04:00
|
|
|
for(i = 0; i < numBlocks; i++) {
|
|
|
|
ret = Blake2bUpdate(&b2b, plain, sizeof(plain));
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Blake2bUpdate failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-01-01 01:10:47 +04:00
|
|
|
|
2014-04-15 19:46:43 +04:00
|
|
|
ret = Blake2bFinal(&b2b, digest, 64);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("Blake2bFinal failed, ret = %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-01 01:10:47 +04:00
|
|
|
|
2013-02-23 03:52:20 +04:00
|
|
|
total = current_time(0) - start;
|
|
|
|
persec = 1 / total * numBlocks;
|
|
|
|
#ifdef BENCH_EMBEDDED
|
|
|
|
/* since using kB, convert to MB/s */
|
|
|
|
persec = persec / 1024;
|
|
|
|
#endif
|
2013-01-01 01:10:47 +04:00
|
|
|
|
2014-03-18 23:28:54 +04:00
|
|
|
printf("BLAKE2b %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks,
|
2013-02-23 03:52:20 +04:00
|
|
|
blockType, total, persec);
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#if !defined(NO_RSA) || !defined(NO_DH) \
|
|
|
|
|| defined(CYASSL_KEYGEN) || defined(HAVE_ECC)
|
2014-03-02 23:06:41 +04:00
|
|
|
static RNG rng;
|
2012-10-30 02:39:42 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#ifndef NO_RSA
|
2013-05-16 20:47:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
|
|
|
|
defined(CYASSL_MDK_SHELL)
|
|
|
|
static char *certRSAname = "certs/rsa2048.der" ;
|
2014-03-02 23:06:41 +04:00
|
|
|
static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
|
2013-05-16 20:47:27 +04:00
|
|
|
/* set by shell command */
|
|
|
|
#elif defined(CYASSL_MDK_SHELL)
|
|
|
|
/* nothing */
|
|
|
|
#else
|
|
|
|
static const char *certRSAname = "certs/rsa2048.der" ;
|
|
|
|
#endif
|
|
|
|
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_rsa(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
int i;
|
2013-02-15 02:09:41 +04:00
|
|
|
int ret;
|
2012-10-31 04:35:12 +04:00
|
|
|
byte tmp[3072];
|
2011-02-05 22:14:47 +03:00
|
|
|
size_t bytes;
|
|
|
|
word32 idx = 0;
|
|
|
|
|
|
|
|
byte message[] = "Everyone gets Friday off.";
|
2012-09-21 02:39:15 +04:00
|
|
|
byte enc[512]; /* for up to 4096 bit */
|
2011-02-05 22:14:47 +03:00
|
|
|
const int len = (int)strlen((char*)message);
|
|
|
|
double start, total, each, milliEach;
|
|
|
|
|
2012-09-21 02:39:15 +04:00
|
|
|
RsaKey rsaKey;
|
2013-01-30 21:13:56 +04:00
|
|
|
int rsaKeySz = 2048; /* used in printf */
|
|
|
|
|
|
|
|
#ifdef USE_CERT_BUFFERS_1024
|
2013-05-16 20:47:27 +04:00
|
|
|
XMEMCPY(tmp, rsa_key_der_1024, sizeof_rsa_key_der_1024);
|
|
|
|
bytes = sizeof_rsa_key_der_1024;
|
2013-01-30 21:13:56 +04:00
|
|
|
rsaKeySz = 1024;
|
|
|
|
#elif defined(USE_CERT_BUFFERS_2048)
|
2013-05-16 20:47:27 +04:00
|
|
|
XMEMCPY(tmp, rsa_key_der_2048, sizeof_rsa_key_der_2048);
|
|
|
|
bytes = sizeof_rsa_key_der_2048;
|
2013-01-30 21:13:56 +04:00
|
|
|
#else
|
2013-05-16 20:47:27 +04:00
|
|
|
FILE* file = fopen(certRSAname, "rb");
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
if (!file) {
|
2013-05-16 20:47:27 +04:00
|
|
|
printf("can't find %s, Please run from CyaSSL home dir\n", certRSAname);
|
2011-02-05 22:14:47 +03:00
|
|
|
return;
|
|
|
|
}
|
2013-01-30 21:13:56 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
bytes = fread(tmp, 1, sizeof(tmp), file);
|
2013-02-15 04:00:45 +04:00
|
|
|
fclose(file);
|
2013-01-30 21:13:56 +04:00
|
|
|
#endif /* USE_CERT_BUFFERS */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-05-16 20:47:27 +04:00
|
|
|
|
2013-02-01 03:55:29 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
if (RsaInitCavium(&rsaKey, CAVIUM_DEV_ID) != 0)
|
|
|
|
printf("RSA init cavium failed\n");
|
|
|
|
#endif
|
2013-02-15 02:09:41 +04:00
|
|
|
ret = InitRng(&rng);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("InitRNG failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-04-02 00:08:48 +04:00
|
|
|
ret = InitRsaKey(&rsaKey, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("InitRsaKey failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-02-15 02:09:41 +04:00
|
|
|
ret = RsaPrivateKeyDecode(tmp, &idx, &rsaKey, (word32)bytes);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-11-21 05:03:19 +04:00
|
|
|
for (i = 0; i < ntimes; i++)
|
2013-02-15 02:09:41 +04:00
|
|
|
ret = RsaPublicEncrypt(message,len,enc,sizeof(enc), &rsaKey, &rng);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-11-21 05:03:19 +04:00
|
|
|
each = total / ntimes; /* per second */
|
2011-02-05 22:14:47 +03:00
|
|
|
milliEach = each * 1000; /* milliseconds */
|
|
|
|
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("RSA %d encryption took %6.3f milliseconds, avg over %d"
|
2013-11-21 05:03:19 +04:00
|
|
|
" iterations\n", rsaKeySz, milliEach, ntimes);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-02-15 02:09:41 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
printf("Rsa Public Encrypt failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-11-21 05:03:19 +04:00
|
|
|
for (i = 0; i < ntimes; i++) {
|
2013-01-15 03:14:46 +04:00
|
|
|
byte out[512]; /* for up to 4096 bit */
|
2013-02-15 02:09:41 +04:00
|
|
|
RsaPrivateDecrypt(enc, (word32)ret, out, sizeof(out), &rsaKey);
|
2013-01-15 03:14:46 +04:00
|
|
|
}
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-11-21 05:03:19 +04:00
|
|
|
each = total / ntimes; /* per second */
|
2011-02-05 22:14:47 +03:00
|
|
|
milliEach = each * 1000; /* milliseconds */
|
|
|
|
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("RSA %d decryption took %6.3f milliseconds, avg over %d"
|
2013-11-21 05:03:19 +04:00
|
|
|
" iterations\n", rsaKeySz, milliEach, ntimes);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2012-09-21 02:39:15 +04:00
|
|
|
FreeRsaKey(&rsaKey);
|
2013-02-01 03:55:29 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
RsaFreeCavium(&rsaKey);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
2012-10-30 02:39:42 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef NO_DH
|
2013-05-16 20:47:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
|
|
|
|
defined(CYASSL_MDK_SHELL)
|
|
|
|
static char *certDHname = "certs/dh2048.der" ;
|
|
|
|
void set_Bench_DH_File(char * cert) { certDHname = cert ; }
|
|
|
|
/* set by shell command */
|
|
|
|
#elif defined(CYASSL_MDK_SHELL)
|
|
|
|
/* nothing */
|
|
|
|
#else
|
|
|
|
static const char *certDHname = "certs/dh2048.der" ;
|
|
|
|
#endif
|
|
|
|
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_dh(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
2014-07-02 00:16:44 +04:00
|
|
|
int i, ret;
|
2011-02-05 22:14:47 +03:00
|
|
|
byte tmp[1024];
|
|
|
|
size_t bytes;
|
2014-03-02 23:11:39 +04:00
|
|
|
word32 idx = 0, pubSz, privSz = 0, pubSz2, privSz2, agreeSz;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2011-10-24 22:41:25 +04:00
|
|
|
byte pub[256]; /* for 2048 bit */
|
|
|
|
byte priv[256]; /* for 2048 bit */
|
|
|
|
byte pub2[256]; /* for 2048 bit */
|
|
|
|
byte priv2[256]; /* for 2048 bit */
|
|
|
|
byte agree[256]; /* for 2048 bit */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
double start, total, each, milliEach;
|
2012-09-21 02:39:15 +04:00
|
|
|
DhKey dhKey;
|
2013-01-31 03:54:43 +04:00
|
|
|
int dhKeySz = 2048; /* used in printf */
|
2013-01-30 21:13:56 +04:00
|
|
|
|
2013-05-16 20:47:27 +04:00
|
|
|
|
2013-01-30 21:13:56 +04:00
|
|
|
#ifdef USE_CERT_BUFFERS_1024
|
2013-05-16 20:47:27 +04:00
|
|
|
XMEMCPY(tmp, dh_key_der_1024, sizeof_dh_key_der_1024);
|
|
|
|
bytes = sizeof_dh_key_der_1024;
|
2013-01-31 03:54:43 +04:00
|
|
|
dhKeySz = 1024;
|
2013-01-30 21:13:56 +04:00
|
|
|
#elif defined(USE_CERT_BUFFERS_2048)
|
2013-05-16 20:47:27 +04:00
|
|
|
XMEMCPY(tmp, dh_key_der_2048, sizeof_dh_key_der_2048);
|
|
|
|
bytes = sizeof_dh_key_der_2048;
|
2013-01-30 21:13:56 +04:00
|
|
|
#else
|
2013-05-16 20:47:27 +04:00
|
|
|
FILE* file = fopen(certDHname, "rb");
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
if (!file) {
|
2013-05-16 20:47:27 +04:00
|
|
|
printf("can't find %s, Please run from CyaSSL home dir\n", certDHname);
|
2011-02-05 22:14:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-31 21:43:48 +04:00
|
|
|
ret = InitRng(&rng);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("InitRNG failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-10-24 22:41:25 +04:00
|
|
|
bytes = fread(tmp, 1, sizeof(tmp), file);
|
2013-01-30 21:13:56 +04:00
|
|
|
#endif /* USE_CERT_BUFFERS */
|
|
|
|
|
2013-05-16 20:47:27 +04:00
|
|
|
|
2012-09-21 02:39:15 +04:00
|
|
|
InitDhKey(&dhKey);
|
|
|
|
bytes = DhKeyDecode(tmp, &idx, &dhKey, (word32)bytes);
|
2012-12-13 06:03:32 +04:00
|
|
|
if (bytes != 0) {
|
|
|
|
printf("dhekydecode failed, can't benchmark\n");
|
2013-02-15 02:09:41 +04:00
|
|
|
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
|
|
|
|
fclose(file);
|
|
|
|
#endif
|
2012-12-13 06:03:32 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-11-21 05:03:19 +04:00
|
|
|
for (i = 0; i < ntimes; i++)
|
2012-09-21 02:39:15 +04:00
|
|
|
DhGenerateKeyPair(&dhKey, &rng, priv, &privSz, pub, &pubSz);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-11-21 05:03:19 +04:00
|
|
|
each = total / ntimes; /* per second */
|
2011-02-05 22:14:47 +03:00
|
|
|
milliEach = each * 1000; /* milliseconds */
|
|
|
|
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("DH %d key generation %6.3f milliseconds, avg over %d"
|
2013-11-21 05:03:19 +04:00
|
|
|
" iterations\n", dhKeySz, milliEach, ntimes);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2012-09-21 02:39:15 +04:00
|
|
|
DhGenerateKeyPair(&dhKey, &rng, priv2, &privSz2, pub2, &pubSz2);
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-11-21 05:03:19 +04:00
|
|
|
for (i = 0; i < ntimes; i++)
|
2012-09-21 02:39:15 +04:00
|
|
|
DhAgree(&dhKey, agree, &agreeSz, priv, privSz, pub2, pubSz2);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2013-11-21 05:03:19 +04:00
|
|
|
each = total / ntimes; /* per second */
|
2011-02-05 22:14:47 +03:00
|
|
|
milliEach = each * 1000; /* milliseconds */
|
|
|
|
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("DH %d key agreement %6.3f milliseconds, avg over %d"
|
2013-11-21 05:03:19 +04:00
|
|
|
" iterations\n", dhKeySz, milliEach, ntimes);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-01-30 21:13:56 +04:00
|
|
|
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
|
2011-02-05 22:14:47 +03:00
|
|
|
fclose(file);
|
2013-01-30 21:13:56 +04:00
|
|
|
#endif
|
2012-09-21 02:39:15 +04:00
|
|
|
FreeDhKey(&dhKey);
|
2011-02-05 22:14:47 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#if defined(CYASSL_KEY_GEN) && !defined(NO_RSA)
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_rsaKeyGen(void)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
RsaKey genKey;
|
|
|
|
double start, total, each, milliEach;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* 1024 bit */
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
for(i = 0; i < genTimes; i++) {
|
|
|
|
InitRsaKey(&genKey, 0);
|
|
|
|
MakeRsaKey(&genKey, 1024, 65537, &rng);
|
|
|
|
FreeRsaKey(&genKey);
|
|
|
|
}
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2011-02-05 22:14:47 +03:00
|
|
|
each = total / genTimes; /* per second */
|
|
|
|
milliEach = each * 1000; /* millisconds */
|
|
|
|
printf("\n");
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("RSA 1024 key generation %6.3f milliseconds, avg over %d"
|
2011-02-05 22:14:47 +03:00
|
|
|
" iterations\n", milliEach, genTimes);
|
|
|
|
|
|
|
|
/* 2048 bit */
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
for(i = 0; i < genTimes; i++) {
|
|
|
|
InitRsaKey(&genKey, 0);
|
|
|
|
MakeRsaKey(&genKey, 2048, 65537, &rng);
|
|
|
|
FreeRsaKey(&genKey);
|
|
|
|
}
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2011-02-05 22:14:47 +03:00
|
|
|
each = total / genTimes; /* per second */
|
|
|
|
milliEach = each * 1000; /* millisconds */
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("RSA 2048 key generation %6.3f milliseconds, avg over %d"
|
2011-02-05 22:14:47 +03:00
|
|
|
" iterations\n", milliEach, genTimes);
|
|
|
|
}
|
|
|
|
#endif /* CYASSL_KEY_GEN */
|
|
|
|
|
2011-12-23 02:59:57 +04:00
|
|
|
#ifdef HAVE_ECC
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_eccKeyGen(void)
|
2011-12-23 02:59:57 +04:00
|
|
|
{
|
|
|
|
ecc_key genKey;
|
|
|
|
double start, total, each, milliEach;
|
2013-10-31 21:43:48 +04:00
|
|
|
int i, ret;
|
2011-12-23 02:59:57 +04:00
|
|
|
|
2013-10-31 21:43:48 +04:00
|
|
|
ret = InitRng(&rng);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("InitRNG failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-12-23 02:59:57 +04:00
|
|
|
/* 256 bit */
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-12-23 02:59:57 +04:00
|
|
|
|
|
|
|
for(i = 0; i < genTimes; i++) {
|
2012-10-10 01:04:27 +04:00
|
|
|
ecc_make_key(&rng, 32, &genKey);
|
2011-12-23 02:59:57 +04:00
|
|
|
ecc_free(&genKey);
|
|
|
|
}
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2011-12-23 02:59:57 +04:00
|
|
|
each = total / genTimes; /* per second */
|
|
|
|
milliEach = each * 1000; /* millisconds */
|
|
|
|
printf("\n");
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("ECC 256 key generation %6.3f milliseconds, avg over %d"
|
2011-12-23 02:59:57 +04:00
|
|
|
" iterations\n", milliEach, genTimes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-20 10:38:41 +04:00
|
|
|
void bench_eccKeyAgree(void)
|
2011-12-23 02:59:57 +04:00
|
|
|
{
|
|
|
|
ecc_key genKey, genKey2;
|
|
|
|
double start, total, each, milliEach;
|
2013-02-20 00:53:58 +04:00
|
|
|
int i, ret;
|
2011-12-23 02:59:57 +04:00
|
|
|
byte shared[1024];
|
|
|
|
byte sig[1024];
|
|
|
|
byte digest[32];
|
2014-03-04 01:27:52 +04:00
|
|
|
word32 x = 0;
|
2013-02-20 00:53:58 +04:00
|
|
|
|
|
|
|
ecc_init(&genKey);
|
|
|
|
ecc_init(&genKey2);
|
|
|
|
|
2013-10-31 21:43:48 +04:00
|
|
|
ret = InitRng(&rng);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("InitRNG failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-20 00:53:58 +04:00
|
|
|
ret = ecc_make_key(&rng, 32, &genKey);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("ecc_make_key failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ret = ecc_make_key(&rng, 32, &genKey2);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("ecc_make_key failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-12-23 02:59:57 +04:00
|
|
|
|
|
|
|
/* 256 bit */
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-12-23 02:59:57 +04:00
|
|
|
|
|
|
|
for(i = 0; i < agreeTimes; i++) {
|
|
|
|
x = sizeof(shared);
|
2013-10-31 21:43:48 +04:00
|
|
|
ret = ecc_shared_secret(&genKey, &genKey2, shared, &x);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("ecc_shared_secret failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-12-23 02:59:57 +04:00
|
|
|
}
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2011-12-23 02:59:57 +04:00
|
|
|
each = total / agreeTimes; /* per second */
|
|
|
|
milliEach = each * 1000; /* millisconds */
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("EC-DHE key agreement %6.3f milliseconds, avg over %d"
|
2011-12-23 02:59:57 +04:00
|
|
|
" iterations\n", milliEach, agreeTimes);
|
|
|
|
|
|
|
|
/* make dummy digest */
|
2012-10-10 01:04:27 +04:00
|
|
|
for (i = 0; i < (int)sizeof(digest); i++)
|
2014-03-04 04:46:48 +04:00
|
|
|
digest[i] = (byte)i;
|
2011-12-23 02:59:57 +04:00
|
|
|
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
start = current_time(1);
|
2011-12-23 02:59:57 +04:00
|
|
|
|
|
|
|
for(i = 0; i < agreeTimes; i++) {
|
|
|
|
x = sizeof(sig);
|
2013-10-31 21:43:48 +04:00
|
|
|
ret = ecc_sign_hash(digest, sizeof(digest), sig, &x, &rng, &genKey);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("ecc_sign_hash failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-12-23 02:59:57 +04:00
|
|
|
}
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
total = current_time(0) - start;
|
2011-12-23 02:59:57 +04:00
|
|
|
each = total / agreeTimes; /* per second */
|
|
|
|
milliEach = each * 1000; /* millisconds */
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("EC-DSA sign time %6.3f milliseconds, avg over %d"
|
2013-08-10 04:06:02 +04:00
|
|
|
" iterations\n", milliEach, agreeTimes);
|
|
|
|
|
|
|
|
start = current_time(1);
|
|
|
|
|
|
|
|
for(i = 0; i < agreeTimes; i++) {
|
|
|
|
int verify = 0;
|
2013-10-31 21:43:48 +04:00
|
|
|
ret = ecc_verify_hash(sig, x, digest, sizeof(digest), &verify, &genKey);
|
|
|
|
if (ret != 0) {
|
|
|
|
printf("ecc_verify_hash failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-08-10 04:06:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
total = current_time(0) - start;
|
|
|
|
each = total / agreeTimes; /* per second */
|
|
|
|
milliEach = each * 1000; /* millisconds */
|
2014-03-11 06:32:16 +04:00
|
|
|
printf("EC-DSA verify time %6.3f milliseconds, avg over %d"
|
2011-12-23 02:59:57 +04:00
|
|
|
" iterations\n", milliEach, agreeTimes);
|
|
|
|
|
|
|
|
ecc_free(&genKey2);
|
|
|
|
ecc_free(&genKey);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ECC */
|
|
|
|
|
2014-07-02 00:16:44 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
double current_time(int reset)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
|
|
|
static int init = 0;
|
|
|
|
static LARGE_INTEGER freq;
|
|
|
|
|
|
|
|
LARGE_INTEGER count;
|
|
|
|
|
2013-11-12 03:21:41 +04:00
|
|
|
(void)reset;
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
if (!init) {
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
init = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryPerformanceCounter(&count);
|
|
|
|
|
|
|
|
return (double)count.QuadPart / freq.QuadPart;
|
|
|
|
}
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
#elif defined MICROCHIP_PIC32
|
2013-11-12 03:12:01 +04:00
|
|
|
#if defined(CYASSL_MICROCHIP_PIC32MZ)
|
2014-07-02 00:16:44 +04:00
|
|
|
#define CLOCK 8000000.0
|
2013-11-12 03:12:01 +04:00
|
|
|
#else
|
|
|
|
#include <peripheral/timer.h>
|
2014-07-02 00:16:44 +04:00
|
|
|
#define CLOCK 4000000.0
|
2013-11-12 03:12:01 +04:00
|
|
|
#endif
|
2013-01-31 03:29:15 +04:00
|
|
|
|
|
|
|
double current_time(int reset)
|
|
|
|
{
|
|
|
|
unsigned int ns;
|
|
|
|
|
|
|
|
if (reset) {
|
|
|
|
WriteCoreTimer(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get timer in ns */
|
2013-11-12 03:12:01 +04:00
|
|
|
ns = ReadCoreTimer();
|
2013-01-31 03:29:15 +04:00
|
|
|
|
|
|
|
/* return seconds as a double */
|
2013-11-12 03:12:01 +04:00
|
|
|
return ( ns / CLOCK * 2.0);
|
2013-01-31 03:29:15 +04:00
|
|
|
}
|
2013-11-12 03:12:01 +04:00
|
|
|
|
2014-07-02 00:16:44 +04:00
|
|
|
#elif defined CYASSL_MDK_ARM
|
|
|
|
|
|
|
|
extern double current_time(int reset) ;
|
|
|
|
|
2013-11-21 04:03:58 +04:00
|
|
|
#elif defined FREERTOS
|
|
|
|
|
|
|
|
double current_time(int reset)
|
|
|
|
{
|
|
|
|
(void) reset;
|
|
|
|
|
|
|
|
portTickType tickCount;
|
|
|
|
|
|
|
|
/* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
|
|
|
|
tickCount = xTaskGetTickCount();
|
|
|
|
return (double)tickCount / 1000;
|
|
|
|
}
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
#else
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2013-01-31 03:29:15 +04:00
|
|
|
double current_time(int reset)
|
2011-02-05 22:14:47 +03:00
|
|
|
{
|
2013-11-12 03:21:41 +04:00
|
|
|
struct timeval tv;
|
|
|
|
|
2013-11-07 23:00:56 +04:00
|
|
|
(void)reset;
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
|
|
|
|
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _WIN32 */
|