1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Random Number Generator API</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Kernel Crypto API"><link rel="up" href="User.html" title="Chapter 4. User Space Interface"><link rel="prev" href="ch04s06.html" title="AEAD Cipher API"><link rel="next" href="ch04s08.html" title="Zero-Copy Interface"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Random Number Generator API</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s06.html">Prev</a> </td><th width="60%" align="center">Chapter 4. User Space Interface</th><td width="20%" align="right"> <a accesskey="n" href="ch04s08.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idp1097380532"></a>Random Number Generator API</h2></div></div></div><p> 2 Again, the operation is very similar to the other APIs. 3 During initialization, the struct sockaddr data structure must be 4 filled as follows: 5 </p><pre class="programlisting"> 6struct sockaddr_alg sa = { 7 .salg_family = AF_ALG, 8 .salg_type = "rng", /* this selects the symmetric cipher */ 9 .salg_name = "drbg_nopr_sha256" /* this is the cipher name */ 10}; 11 </pre><p> 12 Depending on the RNG type, the RNG must be seeded. The seed is provided 13 using the setsockopt interface to set the key. For example, the 14 ansi_cprng requires a seed. The DRBGs do not require a seed, but 15 may be seeded. 16 </p><p> 17 Using the read()/recvmsg() system calls, random numbers can be obtained. 18 The kernel generates at most 128 bytes in one call. If user space 19 requires more data, multiple calls to read()/recvmsg() must be made. 20 </p><p> 21 WARNING: The user space caller may invoke the initially mentioned 22 accept system call multiple times. In this case, the returned file 23 descriptors have the same state. 24 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s06.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="User.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch04s08.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">AEAD Cipher API </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Zero-Copy Interface</td></tr></table></div></body></html> 25