mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-12 18:49:07 +00:00
add curve25519 multiply to test_speed
This commit is contained in:
parent
a8c7e5ef20
commit
b617568068
44
test_speed.c
44
test_speed.c
@ -8,6 +8,7 @@
|
||||
#include "secp256k1.h"
|
||||
#include "nist256p1.h"
|
||||
#include "ed25519.h"
|
||||
#include "curve25519-donna.h"
|
||||
|
||||
static uint8_t msg[32];
|
||||
|
||||
@ -18,7 +19,8 @@ void prepare_msg(void)
|
||||
}
|
||||
}
|
||||
|
||||
void bench_secp256k1(void) {
|
||||
void bench_secp256k1(void)
|
||||
{
|
||||
uint8_t sig[64], pub[33], priv[32], pby;
|
||||
|
||||
const ecdsa_curve *curve = &secp256k1;
|
||||
@ -35,7 +37,8 @@ void bench_secp256k1(void) {
|
||||
printf("SECP256k1 verifying speed: %0.2f sig/s\n", 500.0f / ((float)(clock() - t) / CLOCKS_PER_SEC));
|
||||
}
|
||||
|
||||
void bench_nist256p1(void) {
|
||||
void bench_nist256p1(void)
|
||||
{
|
||||
uint8_t sig[64], pub[33], priv[32], pby;
|
||||
|
||||
const ecdsa_curve *curve = &nist256p1;
|
||||
@ -52,7 +55,8 @@ void bench_nist256p1(void) {
|
||||
printf("NIST256p1 verifying speed: %0.2f sig/s\n", 500.0f / ((float)(clock() - t) / CLOCKS_PER_SEC));
|
||||
}
|
||||
|
||||
void bench_ed25519(void) {
|
||||
void bench_ed25519(void)
|
||||
{
|
||||
ed25519_public_key pk;
|
||||
ed25519_secret_key sk;
|
||||
ed25519_signature sig;
|
||||
@ -69,13 +73,35 @@ void bench_ed25519(void) {
|
||||
printf("Ed25519 verifying speed: %0.2f sig/s\n", 500.0f / ((float)(clock() - t) / CLOCKS_PER_SEC));
|
||||
}
|
||||
|
||||
void test_verify_speed(void) {
|
||||
void test_verify_speed(void)
|
||||
{
|
||||
prepare_msg();
|
||||
bench_secp256k1();
|
||||
bench_nist256p1();
|
||||
bench_ed25519();
|
||||
}
|
||||
|
||||
void bench_curve25519(void)
|
||||
{
|
||||
uint8_t result[32];
|
||||
uint8_t secret[32];
|
||||
uint8_t basepoint[32];
|
||||
|
||||
memcpy(secret, "\xc5\x5e\xce\x85\x8b\x0d\xdd\x52\x63\xf9\x68\x10\xfe\x14\x43\x7c\xd3\xb5\xe1\xfb\xd7\xc6\xa2\xec\x1e\x03\x1f\x05\xe8\x6d\x8b\xd5", 32);
|
||||
memcpy(basepoint, "\x96\x47\xda\xbe\x1e\xea\xaf\x25\x47\x1e\x68\x0b\x4d\x7c\x6f\xd1\x14\x38\x76\xbb\x77\x59\xd8\x3d\x0f\xf7\xa2\x49\x08\xfd\xda\xbc", 32);
|
||||
|
||||
clock_t t = clock();
|
||||
for (int i = 0 ; i < 500; i++) {
|
||||
curve25519_scalarmult(result, secret, basepoint);
|
||||
}
|
||||
printf("Curve25519 multiplying speed: %0.2f mul/s\n", 500.0f / ((float)(clock() - t) / CLOCKS_PER_SEC));
|
||||
}
|
||||
|
||||
void test_multiply_speed(void)
|
||||
{
|
||||
bench_curve25519();
|
||||
}
|
||||
|
||||
static HDNode root;
|
||||
|
||||
void prepare_node(void)
|
||||
@ -84,7 +110,8 @@ void prepare_node(void)
|
||||
hdnode_fill_public_key(&root);
|
||||
}
|
||||
|
||||
void bench_ckd_normal(int iterations) {
|
||||
void bench_ckd_normal(int iterations)
|
||||
{
|
||||
char addr[MAX_ADDR_SIZE];
|
||||
HDNode node;
|
||||
clock_t t = clock();
|
||||
@ -100,7 +127,8 @@ void bench_ckd_normal(int iterations) {
|
||||
printf("CKD normal speed: %0.2f iter/s\n", iterations / ((float)(clock() - t) / CLOCKS_PER_SEC));
|
||||
}
|
||||
|
||||
void bench_ckd_optimized(int iterations) {
|
||||
void bench_ckd_optimized(int iterations)
|
||||
{
|
||||
char addr[MAX_ADDR_SIZE];
|
||||
curve_point pub;
|
||||
ecdsa_read_pubkey(&secp256k1, root.public_key, &pub);
|
||||
@ -114,7 +142,8 @@ void bench_ckd_optimized(int iterations) {
|
||||
printf("CKD optim speed: %0.2f iter/s\n", iterations / ((float)(clock() - t) / CLOCKS_PER_SEC));
|
||||
}
|
||||
|
||||
void test_ckd_speed(int iterations) {
|
||||
void test_ckd_speed(int iterations)
|
||||
{
|
||||
prepare_node();
|
||||
bench_ckd_normal(iterations);
|
||||
bench_ckd_optimized(iterations);
|
||||
@ -122,6 +151,7 @@ void test_ckd_speed(int iterations) {
|
||||
|
||||
int main(void) {
|
||||
test_verify_speed();
|
||||
test_multiply_speed();
|
||||
test_ckd_speed(1000);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user