<trclass="memdesc:ga65c6dc4a24eb0844f9a82e5a02306c14"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Asymmetrically encrypt a message. <ahref="#ga65c6dc4a24eb0844f9a82e5a02306c14"></a><br/></td></tr>
<trclass="memdesc:ga73788bf0c6828922f98e57f1568dd845"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Asymmetrically decrypt a message. <ahref="#ga73788bf0c6828922f98e57f1568dd845"></a><br/></td></tr>
<trclass="memdesc:gadbdb839246cac65ff20ef63902041597"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Asymmetrically encrypt a file or a buffer stream. <ahref="#gadbdb839246cac65ff20ef63902041597"></a><br/></td></tr>
<trclass="memdesc:ga949053e8f2a9ddfa2421d578951f7cf5"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Symmetrically encrypt a file or a buffer stream. <ahref="#ga949053e8f2a9ddfa2421d578951f7cf5"></a><br/></td></tr>
<trclass="memdesc:gaeb1196ed4a3edc911e77d1d15612c539"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Asymmetrically decrypt a file or a buffer stream. <ahref="#gaeb1196ed4a3edc911e77d1d15612c539"></a><br/></td></tr>
<trclass="memdesc:ga98322a73045d7d3e069e1afeb7fe2918"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Symmetrically decrypt a file or a buffer stream. <ahref="#ga98322a73045d7d3e069e1afeb7fe2918"></a><br/></td></tr>
<trclass="memdesc:gaf9ec9f99af7315fa9f1a5f9649f27347"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Symmetrically encrypt a message. <ahref="#gaf9ec9f99af7315fa9f1a5f9649f27347"></a><br/></td></tr>
<p>Functions for symmetrical or asymmetrical encryption using NaCL. </p>
<h1><aclass="anchor"id="intro"></a>
Introduction</h1>
<p>Encryption is done 32k blockwise using an ephemeral key.</p>
<p>If using asymmetrical encryption the ephemeral key is encrypted asymmetrically using Curve25519 for all recipients and added to the output.</p>
<p>If sign+crypt is requested, a hash of the clear content plus the recipient list will be made and signed. That signature will be encrypted using the ephemeral key as well and appended to the output.</p>
<p>For each encryption cycle (per block) a unique nonce will be used.</p>
<h1><aclass="anchor"id="format"></a>
Encrypted Output Format</h1>
<p>Encrypted output will always written as binary files. No armoring supported yet. The encryption process works as this:</p>
<ul>
<li>generate a random symetric 32 byte key B<S></li>
<li>encrypt it asymetrically for each recipient using a unique nonce (B<R>)</li>
<li>encrypt the input file 32k blockwise using the symetric key</li>
</ul>
<p>Symmetric encryption works the very same with the recipient stuff left out.</p>
<p>Formal format description, asymmetric encrypted files: </p>
</pre><p>R is calculated using public key encryption using the senders secret key, the recipients public key and a random nonce.</p>
<p>Pseudocode:</p>
<divclass="fragment"><divclass="line">R = <spanclass="keywordflow">foreach</span> P: N | crypto_box(S, N, P, SK)</div>
<divclass="line">L = len(R)</div>
<divclass="line">T = 5</div>
<divclass="line">write (T | L | R)</div>
<divclass="line">foreach I: write (N | crypto_secret_box(I, N, S))</div>
</div><!-- fragment --><p>where P is the public key of a recipient, SK is the senders secret key, R is the recipient list, L is the number of recipients, T is the filetype header, I is a block of input with a size of 32k, N is a nonce (new per block) and S the symmetric key. </p>
<p>This function is used internally and normally a user doesn't need to use it. However, from time to time there maybe the requirement to work with raw NaCL crypto_box() output. This function adds the neccessary padding and it uses PCP key structures.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">secret</td><td>The secret key structure from the sender.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">pub</td><td>The public key structure from the recipient.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">ciphersize</td><td>The size in bytes of the encrypted message.</td></tr>
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">dsize</td><td>A pointer which will be set to the size of the decrypted result if successful.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns an allocated unsigned char array of the size csize which contains the encrypted result. In case of an error, it returns NULL sets csize to 0. Use <aclass="el"href="group__FATALS.html#ga0ea01da59af8a06c55258d78da6cb0cb"title="Prints error messages to STDERR, if there are some.">fatals_ifany()</a> to check for errors. </dd></dl>
<p>This function is used internally and normally a user doesn't need to use it. However, from time to time there maybe the requirement to work with raw NaCL crypto_box() output. This function adds the neccessary padding and it uses PCP key structures.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">secret</td><td>The secret key structure from the sender.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">pub</td><td>The public key structure from the recipient.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">messagesize</td><td>The size in bytes of the message.</td></tr>
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">csize</td><td>A pointer which will be set to the size of the encrypted result if successful.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns an allocated unsigned char array of the size csize which contains the encrypted result. In case of an error, it returns NULL sets csize to 0. Use <aclass="el"href="group__FATALS.html#ga0ea01da59af8a06c55258d78da6cb0cb"title="Prints error messages to STDERR, if there are some.">fatals_ifany()</a> to check for errors. </dd></dl>
<p>Asymmetrically decrypt a file or a buffer stream. </p>
<p>This function decrypts a stream 32k+16-blockwise for a number of recipients.</p>
<p>Calls <aclass="el"href="group__CRYPTO.html#ga98322a73045d7d3e069e1afeb7fe2918"title="Symmetrically decrypt a file or a buffer stream.">pcp_decrypt_stream_sym()</a> after assembling the encrypted recipient list.</p>
<p>FIXME: should return the pcp_rec_t structure upon successfull verification somehow.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">in</td><td>Stream to read the data to decrypt from.</td></tr>
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">out</td><td>Stream to write decrypted result to.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">s</td><td>Secret key structure of the recipient.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">symkey</td><td>Ephemeral key for symmetric decryption. Set to NULL if you call this function directly.</td></tr>
<tr><tdclass="paramdir"></td><tdclass="paramname">verify</td><td>Flag to indicate sign+crypt. If 1 it tries to verify a signature, otherwise not.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns the size of the output written to the output stream or 0 in case of errors. </dd></dl>
<p>Symmetrically decrypt a file or a buffer stream. </p>
<p>This function decrypts a stream 32k+16-blockwise using a given ephemeral key. Usually compute this key using the pcp_scrypt() function. If not called directly, the key have been extracted from the recipient list.</p>
<p>Uses crypto_secret_box_open() for each 32k+16-block with a random nonce for each.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">in</td><td>Stream to read the data to decrypt from.</td></tr>
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">out</td><td>Stream to write decrypted result to.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">symkey</td><td>Ephemeral key to use for decryption.</td></tr>
<tr><tdclass="paramdir"></td><tdclass="paramname">recverify</td><td>Flag to indicate sign+crypt. If 1 it tries to verify a signature, otherwise not.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns the size of the output written to the output stream or 0 in case of errors. </dd></dl>
<p>Asymmetrically encrypt a file or a buffer stream. </p>
<p>This function encrypts a stream 32k-blockwise for a number of recipients.</p>
<p>Calls <aclass="el"href="group__CRYPTO.html#ga949053e8f2a9ddfa2421d578951f7cf5"title="Symmetrically encrypt a file or a buffer stream.">pcp_encrypt_stream_sym()</a> after assembling the encrypted recipient list.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">in</td><td>Stream to read the data to encrypt from.</td></tr>
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">out</td><td>Stream to write encrypted result to.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">s</td><td>Secret key structure of the sender.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">p</td><td>Public key hash containing a list of the recipients.</td></tr>
<tr><tdclass="paramdir"></td><tdclass="paramname">signcrypt</td><td>Flag to indicate sign+crypt. If 1 it adds a signature, otherwise not.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns the size of the output written to the output stream or 0 in case of errors. </dd></dl>
<p>Symmetrically encrypt a file or a buffer stream. </p>
<p>This function encrypts a stream 32k-blockwise using a given ephemeral key. Usually compute this key using the pcp_scrypt() function.</p>
<p>Uses crypto_secret_box() for each 32k-block with a random nonce for each.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">in</td><td>Stream to read the data to encrypt from.</td></tr>
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">out</td><td>Stream to write encrypted result to.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">symkey</td><td>Ephemeral key to use for encryption.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">havehead</td><td>Flag to indicate if the file header has already been written. Set to 0 if you call this function directly in order to do symmetrical encryption.</td></tr>
<tr><tdclass="paramdir"></td><tdclass="paramname">recsign</td><td>Recipient list, set this to NULL if you call this function directly.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns the size of the output written to the output stream or 0 in case of errors. </dd></dl>