X-Git-Url: http://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsptps_speed.c;h=45bbeb5cbce1ce1cc697310e30092c2d916fa8f5;hb=28b8e10015574784f59d4893de11d80f07412459;hp=cc05b8656352e8bcc0000c9abfc29c597e959533;hpb=28b7a53b693f6b4e70218a926e68a36ece54cda1;p=tinc diff --git a/src/sptps_speed.c b/src/sptps_speed.c index cc05b865..45bbeb5c 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -29,6 +29,7 @@ #include "meta.h" #include "protocol.h" #include "sptps.h" +#include "random.h" // Symbols necessary to link with logger.o bool send_request(struct connection_t *c, const char *msg, ...) { @@ -45,7 +46,6 @@ bool send_meta(struct connection_t *c, const void *msg, size_t len) { (void)len; return false; } -char *logfilename = NULL; bool do_detach = false; struct timeval now; @@ -105,15 +105,13 @@ static bool clock_countto(double seconds) { return false; } -int main(int argc, char *argv[]) { +static int run_benchmark(int argc, char *argv[]) { ecdsa_t *key1, *key2; ecdh_t *ecdh1, *ecdh2; sptps_t sptps1, sptps2; uint8_t buf1[4096], buf2[4096], buf3[4096]; double duration = argc > 1 ? atof(argv[1]) : 10; - crypto_init(); - randomize(buf1, sizeof(buf1)); randomize(buf2, sizeof(buf2)); randomize(buf3, sizeof(buf3)); @@ -170,22 +168,76 @@ int main(int argc, char *argv[]) { fprintf(stderr, "%28.2lf op/s\n", rate); ecdh_free(ecdh1); - // SPTPS authentication phase - int fd[2]; + struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}}; + + sptps_params_t params1 = { + .handle = fd + 0, + .initiator = true, + .datagram = false, + .mykey = key1, + .hiskey = key2, + .label = "sptps_speed", + .send_data = send_data, + .receive_record = receive_record, + }; + + sptps_params_t params2 = { + .handle = fd + 1, + .initiator = false, + .datagram = false, + .mykey = key2, + .hiskey = key1, + .label = "sptps_speed", + .send_data = send_data, + .receive_record = receive_record, + }; + + static const char *suite_names[] = { + "Chacha20-Poly1305", + "AES-256-GCM", + }; + + for(uint8_t suite = 0; suite < 2; suite++) { + fprintf(stderr, "\nCipher suite %u (%s):\n", suite, suite_names[suite]); + params1.preferred_suite = params2.preferred_suite = suite; + + // SPTPS authentication phase + + fprintf(stderr, "SPTPS/TCP authenticate for %lg seconds: ", duration); + + if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); + return 1; + } - if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { - fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); - return 1; - } + pfd[0].fd = fd[0], pfd[1].fd = fd[1]; + params1.datagram = params2.datagram = false; - struct pollfd pfd[2] = {{fd[0], POLLIN, 0}, {fd[1], POLLIN, 0}}; + for(clock_start(); clock_countto(duration);) { + sptps_start(&sptps1, ¶ms1); + sptps_start(&sptps2, ¶ms2); - fprintf(stderr, "SPTPS/TCP authenticate for %lg seconds: ", duration); + while(poll(pfd, 2, 0)) { + if(pfd[0].revents) { + receive_data(&sptps1); + } - for(clock_start(); clock_countto(duration);) { - sptps_start(&sptps1, fd + 0, true, false, key1, key2, "sptps_speed", 11, send_data, receive_record); - sptps_start(&sptps2, fd + 1, false, false, key2, key1, "sptps_speed", 11, send_data, receive_record); + if(pfd[1].revents) { + receive_data(&sptps2); + } + } + + sptps_stop(&sptps1); + sptps_stop(&sptps2); + } + + fprintf(stderr, "%10.2lf op/s\n", rate * 2); + + // SPTPS data + + sptps_start(&sptps1, ¶ms1); + sptps_start(&sptps2, ¶ms2); while(poll(pfd, 2, 0)) { if(pfd[0].revents) { @@ -197,65 +249,68 @@ int main(int argc, char *argv[]) { } } - sptps_stop(&sptps1); - sptps_stop(&sptps2); - } + fprintf(stderr, "SPTPS/TCP transmit for %lg seconds: ", duration); - fprintf(stderr, "%10.2lf op/s\n", rate * 2); + for(clock_start(); clock_countto(duration);) { + if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { + abort(); + } - // SPTPS data + receive_data(&sptps2); + } - sptps_start(&sptps1, fd + 0, true, false, key1, key2, "sptps_speed", 11, send_data, receive_record); - sptps_start(&sptps2, fd + 1, false, false, key2, key1, "sptps_speed", 11, send_data, receive_record); + rate *= 2 * 1451 * 8; - while(poll(pfd, 2, 0)) { - if(pfd[0].revents) { - receive_data(&sptps1); + if(rate > 1e9) { + fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); + } else if(rate > 1e6) { + fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); + } else if(rate > 1e3) { + fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); } - if(pfd[1].revents) { - receive_data(&sptps2); - } - } + sptps_stop(&sptps1); + sptps_stop(&sptps2); - fprintf(stderr, "SPTPS/TCP transmit for %lg seconds: ", duration); + close(fd[0]); + close(fd[1]); - for(clock_start(); clock_countto(duration);) { - if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { - abort(); + // SPTPS datagram authentication phase + + if(socketpair(AF_UNIX, SOCK_DGRAM, 0, fd)) { + fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); + return 1; } - receive_data(&sptps2); - } + pfd[0].fd = fd[0], pfd[1].fd = fd[1]; + params1.datagram = params2.datagram = true; - rate *= 2 * 1451 * 8; + fprintf(stderr, "SPTPS/UDP authenticate for %lg seconds: ", duration); - if(rate > 1e9) { - fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); - } else if(rate > 1e6) { - fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); - } else if(rate > 1e3) { - fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); - } + for(clock_start(); clock_countto(duration);) { + sptps_start(&sptps1, ¶ms1); + sptps_start(&sptps2, ¶ms2); - sptps_stop(&sptps1); - sptps_stop(&sptps2); + while(poll(pfd, 2, 0)) { + if(pfd[0].revents) { + receive_data(&sptps1); + } - // SPTPS datagram authentication phase + if(pfd[1].revents) { + receive_data(&sptps2); + } + } - close(fd[0]); - close(fd[1]); + sptps_stop(&sptps1); + sptps_stop(&sptps2); + } - if(socketpair(AF_UNIX, SOCK_DGRAM, 0, fd)) { - fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); - return 1; - } + fprintf(stderr, "%10.2lf op/s\n", rate * 2); - fprintf(stderr, "SPTPS/UDP authenticate for %lg seconds: ", duration); + // SPTPS datagram data - for(clock_start(); clock_countto(duration);) { - sptps_start(&sptps1, fd + 0, true, true, key1, key2, "sptps_speed", 11, send_data, receive_record); - sptps_start(&sptps2, fd + 1, false, true, key2, key1, "sptps_speed", 11, send_data, receive_record); + sptps_start(&sptps1, ¶ms1); + sptps_start(&sptps2, ¶ms2); while(poll(pfd, 2, 0)) { if(pfd[0].revents) { @@ -267,57 +322,48 @@ int main(int argc, char *argv[]) { } } - sptps_stop(&sptps1); - sptps_stop(&sptps2); - } - - fprintf(stderr, "%10.2lf op/s\n", rate * 2); - - // SPTPS datagram data - - sptps_start(&sptps1, fd + 0, true, true, key1, key2, "sptps_speed", 11, send_data, receive_record); - sptps_start(&sptps2, fd + 1, false, true, key2, key1, "sptps_speed", 11, send_data, receive_record); + fprintf(stderr, "SPTPS/UDP transmit for %lg seconds: ", duration); - while(poll(pfd, 2, 0)) { - if(pfd[0].revents) { - receive_data(&sptps1); - } + for(clock_start(); clock_countto(duration);) { + if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { + abort(); + } - if(pfd[1].revents) { receive_data(&sptps2); } - } - fprintf(stderr, "SPTPS/UDP transmit for %lg seconds: ", duration); + rate *= 2 * 1451 * 8; - for(clock_start(); clock_countto(duration);) { - if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { - abort(); + if(rate > 1e9) { + fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); + } else if(rate > 1e6) { + fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); + } else if(rate > 1e3) { + fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); } - receive_data(&sptps2); - } - - rate *= 2 * 1451 * 8; + sptps_stop(&sptps1); + sptps_stop(&sptps2); - if(rate > 1e9) { - fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); - } else if(rate > 1e6) { - fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); - } else if(rate > 1e3) { - fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); + close(fd[0]); + close(fd[1]); } - sptps_stop(&sptps1); - sptps_stop(&sptps2); - // Clean up - close(fd[0]); - close(fd[1]); ecdsa_free(key1); ecdsa_free(key2); - crypto_exit(); return 0; } + +int main(int argc, char *argv[]) { + random_init(); + crypto_init(); + + int result = run_benchmark(argc, argv); + + random_exit(); + + return result; +}