{"id":2500,"date":"2012-10-17T21:34:40","date_gmt":"2012-10-17T21:34:40","guid":{"rendered":"http:\/\/really.zonky.org\/?p=2500"},"modified":"2012-10-22T18:12:19","modified_gmt":"2012-10-22T18:12:19","slug":"debian-adding-entropy-to-devrandom","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=2500","title":{"rendered":"Debian: Adding Entropy to \/dev\/random"},"content":{"rendered":"<p>I have recently become interested in the amount of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Entropy_(computing)\">entropy<\/a> available in Linux and decided to spend some time poking around on my Debian workstation. Specifically looking to increase the amount of entropy available to improve the speed of random number generation. There are a variety of different ways of accomplishing this including hardware devices (some of which cost rather too much for a simple experiment).<\/p>\n<h2>Eh?<\/h2>\n<p>Linux has a device (<em>\/dev\/random<\/em>) which makes available random numbers to software packages that\u00a0<em>really<\/em> need access to a high quality source of random numbers. Any decently written cryptographic software will use\u00a0<em>\/dev\/random<\/em> (and not\u00a0<em>\/dev\/urandom<\/em> which does not generate &#8220;proper&#8221; random numbers of quality) to implement encryption.<\/p>\n<p>Using poor quality random numbers can potentially result in encryption not being secure. Or perhaps more realistically<em>,\u00a0<\/em>because Linux waits until there is sufficient entropy available before releasing numbers through<em>\u00a0<\/em><em>\/dev\/random<\/em>, software reading from that device may be subject to random stalling. Not necessarily long enough to cause a\u00a0<em>major<\/em> problem, but perhaps enough to have an effect on performance.<\/p>\n<p>Especially for a server in a virtualised environment!<\/p>\n<h2>Adding Entropy The Software Way (haveged)<\/h2>\n<p><a href=\"http:\/\/www.issihosts.com\/haveged\/\">HAVEGED<\/a> is a way of using processor flutter to add entropy to the Linux\u00a0<em>\/dev\/random<\/em> device. It can be installed relatively easily with :-<\/p>\n<pre>apt-get install haveged\r\n\/etc\/init.d\/haveged start<\/pre>\n<p>As soon as this was running the amount of entropy available (<em>cat \/proc\/sys\/kernel\/random\/entropy_avail<\/em>) jumped from several hundred to close to 4,000.<\/p>\n<p>Now does this increased entropy have an effect on performance? Copying a CD-sized ISO image file using ssh :-<\/p>\n<table>\n<tbody>\n<tr>\n<th>Default entropy<\/th>\n<td>29.496<\/td>\n<\/tr>\n<tr>\n<th>With HAVEGED<\/th>\n<td>28.636<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>A 2% improvement in performance is hardly a dramatic improvement, but every little bit helps and it may well have a more dramatic effect on a server which regularly exhausts entropy.<\/p>\n<h2>Checking The Randomness<\/h2>\n<p>But hang on &#8230; more important than performance is the randomness of the numbers generated. And you cannot mess with the generation of random numbers without checking the results. The first part of checking the randomness is making sure you have the right tools installed :-<\/p>\n<pre>apt-get install rng-tools<\/pre>\n<p>Once installed you can test the current set of random numbers :-<\/p>\n<pre>dd if=\/dev\/random bs=1k count=32768 iflag=fullblock| rngtest<\/pre>\n<p>This produces a whole bunch of output, but the key bits of output are the &#8220;FIPS 140-2 failures&#8221; and &#8220;FIPS 140-2 successes&#8221;; if you have too many failures something is wrong. For the record my failure rate is 0.05% with\u00a0<em>haveged<\/em> running (without: tests ongoing).<\/p>\n<h2>Links<\/h2>\n<p>&#8230; to more information.<\/p>\n<ul>\n<li><a href=\"http:\/\/strugglers.net\/~andy\/blog\/2010\/06\/06\/adventures-in-entropy-part-1\/\">Adventures in Entropy<\/a>.<\/li>\n<li><a href=\"http:\/\/www.entropykey.co.uk\/\">The Entropy Key<\/a> &#8211; a hardware device for adding entropy.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I have recently become interested in the amount of entropy available in Linux and decided to spend some time poking around on my Debian workstation. Specifically looking to increase the amount of entropy available to improve the speed of random number generation. There are a variety of different ways of accomplishing this including hardware devices <a href='https:\/\/really.zonky.org\/?p=2500' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[4,209,489],"tags":[1018,1017,1019],"class_list":["post-2500","post","type-post","status-publish","format-standard","hentry","category-it","category-linux-it","category-security","tag-devrandom","tag-debian","tag-entropy","category-4-id","category-209-id","category-489-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1f2KI-Ek","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/2500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2500"}],"version-history":[{"count":5,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/2500\/revisions"}],"predecessor-version":[{"id":2504,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/2500\/revisions\/2504"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}