{"id":2255,"date":"2016-06-01T18:28:26","date_gmt":"2016-06-01T16:28:26","guid":{"rendered":"http:\/\/possiblelossofprecision.net\/?p=2255"},"modified":"2021-05-15T11:46:37","modified_gmt":"2021-05-15T09:46:37","slug":"openssh-cipher-performance","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=2255","title":{"rendered":"OpenSSH cipher performance"},"content":{"rendered":"<p>The achievable speed of copying a file with OpenSSH (e.g. with <code>scp<\/code>) will depend on quite a few different factors such as CPU speed, CPU architecture, Network throughput, OpenSSH implementation, OS, hard drive speed, etc. But how much of a difference does choosing a different cipher algorithm make? And what&#8217;s the fastest OpenSSH cipher algorithm?<\/p>\n<p>Turns out, there&#8217;s no simple answer to this question, since most of the factors that influence the transfer speed can be ruled out, but the results will at least depend on the hardware platform and OpenSSH version. There&#8217;s quite a few different benchmarks out there, e.g. for the <a href=\"https:\/\/blog.famzah.net\/2010\/06\/11\/openssh-ciphers-performance-benchmark\">Bifferbord<\/a>, <a href=\"https:\/\/blog.famzah.net\/2015\/06\/26\/openssh-ciphers-performance-benchmark-update-2015\/\">E5 xeon CPUs<\/a> or different <a href=\"https:\/\/blog.klingt.net\/posts\/ssh-cipher-performance-comparision\/\">consumer grade CPUs and ARM processors<\/a>. But since the results are so heavily platform dependent, it&#8217;s a good idea to run your own benchmark on the particular platform you are interested in. So here&#8217;s another data point for an <a href=\"http:\/\/ark.intel.com\/de\/products\/64591\/Intel-Xeon-Processor-E5-2640-15M-Cache-2_50-GHz-7_20-GTs-Intel-QPI\">Intel Xeon E5-2640<\/a> and OpenSSH 6.9p1 (OpenSSL 1.0.1k).<\/p>\n<p>The test setup is quite similar to the one described at <a href=\"https:\/\/blog.famzah.net\/2010\/06\/11\/openssh-ciphers-performance-benchmark\">blog.famzah.net<\/a>. The bash script used to produce the data is:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nfor cipher in aes128-ctr aes192-ctr aes256-ctr arcfour256 arcfour128 aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc aes256-cbc arcfour\r\ndo\r\n   echo &quot;$cipher&quot;\r\n   for try in 1 2\r\n   do\r\n      scp -c &quot;$cipher&quot; \/tank\/fs\/testfile.img root@localhost:\/tank2\/fs\/\r\n   done\r\ndone\r\n<\/pre>\n<p>The test file consists of <strong>5GiB<\/strong> random data. Both the source and target file system are <a href=\"https:\/\/possiblelossofprecision.net\/?p=2248\">RAM backed<\/a> to remove the influence of HDD read and write speeds. In addition to that, the test file is written to localhost to ensure that network speed, load and NIC drivers do not influence the test results.<\/p>\n<div id=\"attachment_2257\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a data-rokbox href=\"wordpress\/wp-content\/uploads\/2016\/04\/scp-cipher-speed.png\" data-rokbox-album=\"p2255\" data-rokbox-caption=\"SCP file transfer speed\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2257\" src=\"wordpress\/wp-content\/uploads\/2016\/04\/scp-cipher-speed.png\" alt=\"\" \/><\/a><p id=\"caption-attachment-2257\" class=\"wp-caption-text\">SCP file transfer speed<\/p><\/div>\n<p>The results clearly show, that the Xeon&#8217;s AES instruction set is used. <a href=\"https:\/\/en.wikipedia.org\/wiki\/AES_instruction_set\">Most modern x86 CPUs<\/a> do come with this extension these days.<\/p>\n<p>While this data clearly suggests, that <a href=\"https:\/\/en.wikipedia.org\/wiki\/Advanced_Encryption_Standard\">AES encryption<\/a> is the faster cipher OpenSSH cipher (if there is hardware support for it as in this case), copying large amounts of data with <code>scp<\/code> is not a particularly interesting use case. Sending big streams of data through a pipe into ssh, as you do when you <a href=\"https:\/\/docs.oracle.com\/cd\/E18752_01\/html\/819-5461\/gbchx.html\">send and receive ZFS snapshots<\/a> over ssh, is a very common application. For benchmarking reasons, sending actual ZFS snapshots is not ideal, since ZFS takes some extra time to check the receiving file system (and its snapshots) before starting the sending process. So here&#8217;s an altered script that should tell us, what the fastest cipher for that particular use case is:<\/p>\n<pre class=\"brush: bash; highlight: [6]; title: ; notranslate\" title=\"\">\r\nfor cipher in aes128-ctr aes192-ctr aes256-ctr arcfour256 arcfour128 aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc aes256-cbc arcfour\r\ndo\r\n   echo &quot;$cipher&quot;\r\n   for try in 1 2\r\n   do\r\n      cat \/tank\/fs\/testfile.img | pv | ssh -c &quot;$cipher&quot; root@localhost &quot;cat - &gt; \/dev\/null&quot;\r\n   done\r\ndone\r\n<\/pre>\n<p>The only difference can be found in the highlighted line: Instead of using <code>scp<\/code> the file is now piped directly into ssh and discarded on the receiving side. Again, the <strong>5GiB<\/strong> test file lives on a RAM backed file system and the transfer is done to localhost.<\/p>\n<div id=\"attachment_2257\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a data-rokbox href=\"wordpress\/wp-content\/uploads\/2016\/04\/ssh-cipher-speed.png\" data-rokbox-album=\"p2255\" data-rokbox-caption=\"SSH piped file transfer speed\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2257\" src=\"wordpress\/wp-content\/uploads\/2016\/04\/ssh-cipher-speed.png\" alt=\"\" \/><\/a><p id=\"caption-attachment-2257\" class=\"wp-caption-text\">SSH piped file transfer speed<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The achievable speed of copying a file with OpenSSH (e.g. with scp) will depend on quite a few different factors such as CPU speed, CPU architecture, Network throughput, OpenSSH implementation, OS, hard drive speed, etc. But how much of a difference does choosing a different cipher algorithm make? And what&#8217;s the fastest OpenSSH cipher algorithm? Turns out, there&#8217;s no simple&#8230; <a href=\"https:\/\/possiblelossofprecision.net\/?p=2255\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[76,15,75],"class_list":["post-2255","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-linux","tag-ssh","tag-zfs"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2255"}],"version-history":[{"count":14,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2255\/revisions"}],"predecessor-version":[{"id":2271,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2255\/revisions\/2271"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}