Detect availability of Linux kernel's AF_ALG sockets for userland crypto?
<p>The Linux kernel added a user space API to its crypto functions at 2.6 via a new new socket family <em><code>AF_ALG</code></em>. Also see <a href="http://lwn.net/Articles/410536/" rel="nofollow">crypto: af_alg - User-space interface for Crypto API</a> on LWN.</p>

<p>I'm working with Gentoo, and it requires one to configure and build the kernel. It appears the default settings omit <em><code>AF_ALG</code></em>, so I'm [currently] working with a kernel that lacks the support. OpenSSL 1.1.0 has an Engine interface into the crypto API. Its failing its self tests due to lack of support for <em><code>AF_ALG</code></em>.</p>

<p>I'd like to know how to detect availability of <em><code>AF_ALG</code></em> at both compile time and runtime. I have not found a way to detect availability at compile time. I think we can use <em><code>alg_get_type</code></em> to detect runtime availability, but I'm not certain.</p>

<p>How can I determine availability of <em><code>AF_ALG</code></em> at compile time and at runtime?</p>

<hr>

<p>The <a href="http://man7.org/linux/man-pages/man2/socket.2.html" rel="nofollow"><code>socket(2)</code></a> man pages has this to say: <em>"Some socket types may not be implemented by all protocol families."</em> But it does not discuss how to detect availability.</p>

<p>The kernel docs cover the API in <a href="http://www.kernel.org/doc/htmldocs/crypto-API/User.html" rel="nofollow">Chapter 4. User Space Interface</a>, but it does not appear to discuss how to detect availability.</p>

<hr>

<p>For completeness, it looks like the following kernel configuration parameters need to be set for Gentoo (from Marek Vašut's <a href="https://events.linuxfoundation.org/sites/events/files/slides/lcj-2014-crypto-user.pdf" rel="nofollow">Utilizing the crypto accelerators</a>):</p>

<ul>
<li><code>CONFIG_CRYPTO_USER_API=m</code></li>
<li><code>CONFIG_CRYPTO_USER_API_HASH=m</code></li>
<li><code>CONFIG_CRYPTO_USER_API_SKCIPHER=m</code></li>
</ul>