From: Guus Sliepen Date: Mon, 2 Aug 2021 22:39:05 +0000 (+0200) Subject: Let sptps_speed benchmark all cipher suites. X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=28b8e10015574784f59d4893de11d80f07412459;p=tinc Let sptps_speed benchmark all cipher suites. --- diff --git a/src/sptps_speed.c b/src/sptps_speed.c index c7c6e546..45bbeb5c 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -168,22 +168,76 @@ static int run_benchmark(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) { @@ -195,65 +249,68 @@ static int run_benchmark(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) { @@ -265,54 +322,35 @@ static int run_benchmark(int argc, char *argv[]) { } } - sptps_stop(&sptps1); - sptps_stop(&sptps2); - } - - fprintf(stderr, "%10.2lf op/s\n", rate * 2); + fprintf(stderr, "SPTPS/UDP transmit for %lg seconds: ", duration); - // 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); - - 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);