int crypto_ed25519_sign( const ed25519_key *key, const byte *message, size_t message_size, byte *signature, size_t *signature_size ) { if (signature_size == NULL) { return -1; } if (*signature_size < ED25519_SIG_SIZE) { *signature_size = ED25519_SIG_SIZE; return -2; } word32 len = *signature_size; int r = wc_ed25519_sign_msg( message, message_size, signature, &len, (ed25519_key *)key ); *signature_size = len; return r; }
void bench_ed25519KeySign(void) { int ret; ed25519_key genKey; #ifdef HAVE_ED25519_SIGN double start, total, milliEach; int i; byte sig[ED25519_SIG_SIZE]; byte msg[512]; word32 x = 0; #endif wc_ed25519_init(&genKey); ret = wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &genKey); if (ret != 0) { printf("ed25519_make_key failed\r\n"); return; } #ifdef HAVE_ED25519_SIGN /* make dummy msg */ for (i = 0; i < (int) sizeof(msg); i++) msg[i] = (byte) i; start = current_time(1); for (i = 0; i < agreeTimes; i++) { x = sizeof(sig); ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey); if (ret != 0) { printf("ed25519_sign_msg failed\r\n"); return; } } total = current_time(0) - start; milliEach = total / agreeTimes / 1000; /* per second */ printf("ED25519 sign time %6.3f milliseconds, avg over %d" " iterations\r\n", milliEach, agreeTimes); #ifdef HAVE_ED25519_VERIFY start = current_time(1); for (i = 0; i < agreeTimes; i++) { int verify = 0; ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify, &genKey); if (ret != 0 || verify != 1) { printf("ed25519_verify_msg failed\r\n"); return; } } total = current_time(0) - start; milliEach = total / agreeTimes / 1000; printf("ED25519 verify time %6.3f milliseconds, avg over %d" " iterations\r\n", milliEach, agreeTimes); #endif /* HAVE_ED25519_VERIFY */ #endif /* HAVE_ED25519_SIGN */ wc_ed25519_free(&genKey); }