1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

add speed test

This commit is contained in:
Pavol Rusnak 2013-08-18 17:30:23 +02:00
parent 1bd0592c26
commit 8e7bee7043
4 changed files with 71 additions and 7 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.o
test
test-speed
test-verify

View File

@ -1,13 +1,17 @@
CC = gcc
CFLAGS = -Wall
OBJS = aux.o ecdsa.o secp256k1.o sha256.o rand.o test.o
NAME = test
OBJS = aux.o ecdsa.o secp256k1.o sha256.o rand.o
all: test-speed test-verify
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
$(NAME): $(OBJS)
gcc $(OBJS) -o $(NAME) -lcrypto
test-speed: test-speed.o $(OBJS)
gcc test-speed.o $(OBJS) -o test-speed -lcrypto
test-verify: test-verify.o $(OBJS)
gcc test-verify.o $(OBJS) -o test-verify -lcrypto
clean:
rm -f $(OBJS) $(NAME)
rm -f $(OBJS) test-speed test-verify

58
test-speed.c Normal file
View File

@ -0,0 +1,58 @@
/**
* Copyright (c) 2013 Tomas Dzetkulic
* Copyright (c) 2013 Pavol Rusnak
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <time.h>
#include "ecdsa.h"
#include "rand.h"
int main()
{
uint8_t sig[70], priv_key[32], msg[256];
uint32_t sig_len, i, msg_len;
int cnt = 0;
init_rand();
clock_t t = clock();
for (;;) {
// random message len between 1 and 256
msg_len = (random32() & 0xFF) + 1;
// create random message
for (i = 0; i < msg_len; i++) {
msg[i] = random32() & 0xFF;
}
// create random privkey
for (i = 0; i < 32; i++) {
priv_key[i] = random32() & 0xFF;
}
// use our ECDSA signer to sign the message with the key
ecdsa_sign(priv_key, msg, msg_len, sig, &sig_len);
cnt++;
if ((cnt % 100) == 0) printf("Speed: %f sig/s \n", 1.0f * cnt / ((float)(clock() - t) / CLOCKS_PER_SEC));
}
return 0;
}

View File

@ -24,6 +24,7 @@
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
#include <openssl/sha.h>
#include <stdio.h>
#include <stdint.h>
#include "ecdsa.h"
@ -44,7 +45,7 @@ int main()
// random message len between 1 and 256
msg_len = (random32() & 0xFF) + 1;
// create random message
for (i = 0; i <msg_len; i++) {
for (i = 0; i < msg_len; i++) {
msg[i] = random32() & 0xFF;
}
// new ECDSA key