Felix Palmen :freebsd: :c64:<p>About the <a href="https://mastodon.bsd.cafe/tags/random" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>random</span></a> thingie ... I need random data in <a href="https://mastodon.bsd.cafe/tags/swad" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>swad</span></a> to generate unpredictable <a href="https://mastodon.bsd.cafe/tags/session" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>session</span></a> IDs.</p><p>I previously had an implementation trying the <a href="https://mastodon.bsd.cafe/tags/Linux" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Linux</span></a>-originating <a href="https://mastodon.bsd.cafe/tags/getrandom" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>getrandom</span></a> if available, with a fallback to a stupid internal <a href="https://mastodon.bsd.cafe/tags/xorshift" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>xorshift</span></a> <a href="https://mastodon.bsd.cafe/tags/PRNG" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PRNG</span></a>, which could be disabled because it's obviously NOT cryptographically secure, and WAS disabled for the generation of session IDs.</p><p>Then I learned <a href="https://mastodon.bsd.cafe/tags/arc4random" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>arc4random</span></a> is available on many systems nowadays (<a href="https://mastodon.bsd.cafe/tags/FreeBSD" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>FreeBSD</span></a>, <a href="https://mastodon.bsd.cafe/tags/NetBSD" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>NetBSD</span></a>, even Linux with a recent-enough glibc), so I decided to add a compile check for it and replace the whole mess with nothing but an arc4random call IF it is available.</p><p>arc4random originates from <a href="https://mastodon.bsd.cafe/tags/OpenBSD" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>OpenBSD</span></a> and provides the only sane way to get cryptographically secure random data. It automatically and transparently (re-)seeds from OS entropy sources, but uses an internal CSPRNG most of the time (nowadays typically <a href="https://mastodon.bsd.cafe/tags/ChaCha20" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>ChaCha20</span></a>, so it's a misnomer, but hey ...). It never fails, it never blocks. It just works. Awesome.</p>