blob: ef7f3225cbcac2e949565ac91c76b71fc19a4cdc [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Platform Security Architecture — cryptography and keystore interface: Message digests</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Platform Security Architecture — cryptography and keystore interface
&#160;<span id="projectnumber">beta 2 — 2019-02-22</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li class="current"><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">Message digests</div> </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:ga6ab7fe8d3500bc2f21be840b4f4f8d1d"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#ga6ab7fe8d3500bc2f21be840b4f4f8d1d">PSA_HASH_OPERATION_INIT</a>&#160;&#160;&#160;{0}</td></tr>
<tr class="separator:ga6ab7fe8d3500bc2f21be840b4f4f8d1d"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:ga3c4205d2ce66c4095fc5c78c25273fab"><td class="memItemLeft" align="right" valign="top">typedef struct psa_hash_operation_s&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a></td></tr>
<tr class="separator:ga3c4205d2ce66c4095fc5c78c25273fab"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gac69f7f19d96a56c28cf3799d11b12156"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#gac69f7f19d96a56c28cf3799d11b12156">psa_hash_compute</a> (<a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> alg, const uint8_t *input, size_t input_length, uint8_t *hash, size_t hash_size, size_t *hash_length)</td></tr>
<tr class="separator:gac69f7f19d96a56c28cf3799d11b12156"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0bb6dbd3c310648c3cf7d202413ff0bc"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#ga0bb6dbd3c310648c3cf7d202413ff0bc">psa_hash_compare</a> (<a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> alg, const uint8_t *input, size_t input_length, const uint8_t *hash, const size_t hash_length)</td></tr>
<tr class="separator:ga0bb6dbd3c310648c3cf7d202413ff0bc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8d72896cf70fc4d514c5c6b978912515"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup</a> (<a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *operation, <a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> alg)</td></tr>
<tr class="separator:ga8d72896cf70fc4d514c5c6b978912515"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga65b16ef97d7f650899b7db4b7d1112ff"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#ga65b16ef97d7f650899b7db4b7d1112ff">psa_hash_update</a> (<a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *operation, const uint8_t *input, size_t input_length)</td></tr>
<tr class="separator:ga65b16ef97d7f650899b7db4b7d1112ff"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4795fd06a0067b0adcd92e9627b8c97e"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#ga4795fd06a0067b0adcd92e9627b8c97e">psa_hash_finish</a> (<a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *operation, uint8_t *hash, size_t hash_size, size_t *hash_length)</td></tr>
<tr class="separator:ga4795fd06a0067b0adcd92e9627b8c97e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga7be923c5700c9c70ef77ee9b76d1a5c0"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#ga7be923c5700c9c70ef77ee9b76d1a5c0">psa_hash_verify</a> (<a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *operation, const uint8_t *hash, size_t hash_length)</td></tr>
<tr class="separator:ga7be923c5700c9c70ef77ee9b76d1a5c0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab0b4d5f9912a615559497a467b532928"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#gab0b4d5f9912a615559497a467b532928">psa_hash_abort</a> (<a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *operation)</td></tr>
<tr class="separator:gab0b4d5f9912a615559497a467b532928"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga39673348f3302b4646bd780034a5aeda"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hash.html#ga39673348f3302b4646bd780034a5aeda">psa_hash_clone</a> (const <a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *source_operation, <a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *target_operation)</td></tr>
<tr class="separator:ga39673348f3302b4646bd780034a5aeda"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<h2 class="groupheader">Macro Definition Documentation</h2>
<a class="anchor" id="ga6ab7fe8d3500bc2f21be840b4f4f8d1d"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define PSA_HASH_OPERATION_INIT&#160;&#160;&#160;{0}</td>
</tr>
</table>
</div><div class="memdoc">
<p>This macro returns a suitable initializer for a hash operation object of type <a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a>. </p>
</div>
</div>
<h2 class="groupheader">Typedef Documentation</h2>
<a class="anchor" id="ga3c4205d2ce66c4095fc5c78c25273fab"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">typedef struct psa_hash_operation_s <a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a></td>
</tr>
</table>
</div><div class="memdoc">
<p>The type of the state data structure for multipart hash operations.</p>
<p>Before calling any function on a hash operation object, the application must initialize it by any of the following means:</p><ul>
<li>Set the structure to all-bits-zero, for example: <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;psa_hash_operation_t operation;</div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;memset(&amp;operation, 0, sizeof(operation));</div></div><!-- fragment --></li>
<li>Initialize the structure to logical zero values, for example: <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;psa_hash_operation_t operation = {0};</div></div><!-- fragment --></li>
<li>Initialize the structure to the initializer <a class="el" href="group__hash.html#ga6ab7fe8d3500bc2f21be840b4f4f8d1d">PSA_HASH_OPERATION_INIT</a>, for example: <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;</div></div><!-- fragment --></li>
<li>Assign the result of the function psa_hash_operation_init() to the structure, for example: <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;psa_hash_operation_t operation;</div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;operation = psa_hash_operation_init();</div></div><!-- fragment --></li>
</ul>
<p>This is an implementation-defined <code>struct</code>. Applications should not make any assumptions about the content of this structure except as directed by the documentation of a specific implementation. </p>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="gab0b4d5f9912a615559497a467b532928"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_hash_abort </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *&#160;</td>
<td class="paramname"><em>operation</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Abort a hash operation.</p>
<p>Aborting an operation frees all associated resources except for the <code>operation</code> structure itself. Once aborted, the operation object can be reused for another operation by calling <a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup()</a> again.</p>
<p>You may call this function any time after the operation object has been initialized by any of the following methods:</p><ul>
<li>A call to <a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup()</a>, whether it succeeds or not.</li>
<li>Initializing the <code>struct</code> to all-bits-zero.</li>
<li>Initializing the <code>struct</code> to logical zeros, e.g. <code>psa_hash_operation_t operation = {0}</code>.</li>
</ul>
<p>In particular, calling <a class="el" href="group__hash.html#gab0b4d5f9912a615559497a467b532928">psa_hash_abort()</a> after the operation has been terminated by a call to <a class="el" href="group__hash.html#gab0b4d5f9912a615559497a467b532928">psa_hash_abort()</a>, <a class="el" href="group__hash.html#ga4795fd06a0067b0adcd92e9627b8c97e">psa_hash_finish()</a> or <a class="el" href="group__hash.html#ga7be923c5700c9c70ef77ee9b76d1a5c0">psa_hash_verify()</a> is safe and has no effect.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>Initialized hash operation.</td></tr>
</table>
</dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td><code>operation</code> is not an active hash operation. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="ga39673348f3302b4646bd780034a5aeda"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_hash_clone </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *&#160;</td>
<td class="paramname"><em>source_operation</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *&#160;</td>
<td class="paramname"><em>target_operation</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Clone a hash operation.</p>
<p>This function copies the state of an ongoing hash operation to a new operation object. In other words, this function is equivalent to calling <a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup()</a> on <code>target_operation</code> with the same algorithm that <code>source_operation</code> was set up for, then <a class="el" href="group__hash.html#ga65b16ef97d7f650899b7db4b7d1112ff">psa_hash_update()</a> on <code>target_operation</code> with the same input that that was passed to <code>source_operation</code>. After this function returns, the two objects are independent, i.e. subsequent calls involving one of the objects do not affect the other object.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">source_operation</td><td>The active hash operation to clone. </td></tr>
<tr><td class="paramdir">[in,out]</td><td class="paramname">target_operation</td><td>The operation object to set up. It must be initialized but not active.</td></tr>
</table>
</dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td><code>source_operation</code> is not an active hash operation. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td><code>target_operation</code> is active. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="ga0bb6dbd3c310648c3cf7d202413ff0bc"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_hash_compare </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a>&#160;</td>
<td class="paramname"><em>alg</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const uint8_t *&#160;</td>
<td class="paramname"><em>input</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>input_length</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const uint8_t *&#160;</td>
<td class="paramname"><em>hash</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const size_t&#160;</td>
<td class="paramname"><em>hash_length</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Calculate the hash (digest) of a message and compare it with a reference value.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir"></td><td class="paramname">alg</td><td>The hash algorithm to compute (<code>PSA_ALG_XXX</code> value such that <a class="el" href="group__crypto__types.html#gac9280662bb482590b4b33d1dcd32930f">PSA_ALG_IS_HASH</a>(<code>alg</code>) is true). </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Buffer containing the message to hash. </td></tr>
<tr><td class="paramdir"></td><td class="paramname">input_length</td><td>Size of the <code>input</code> buffer in bytes. </td></tr>
<tr><td class="paramdir">[out]</td><td class="paramname">hash</td><td>Buffer containing the expected hash value. </td></tr>
<tr><td class="paramdir"></td><td class="paramname">hash_length</td><td>Size of the <code>hash</code> buffer in bytes.</td></tr>
</table>
</dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>The expected hash is identical to the actual hash of the input. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga35927f755d232c4766de600f2c49e9f2">PSA_ERROR_INVALID_SIGNATURE</a></td><td>The hash of the message was calculated successfully, but it differs from the expected hash. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga1dcc6d130633ed5db8942257581b55dd">PSA_ERROR_NOT_SUPPORTED</a></td><td><code>alg</code> is not supported or is not a hash algorithm. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="gac69f7f19d96a56c28cf3799d11b12156"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_hash_compute </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a>&#160;</td>
<td class="paramname"><em>alg</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const uint8_t *&#160;</td>
<td class="paramname"><em>input</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>input_length</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t *&#160;</td>
<td class="paramname"><em>hash</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>hash_size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>hash_length</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Calculate the hash (digest) of a message.</p>
<dl class="section note"><dt>Note</dt><dd>To verify the hash of a message against an expected value, use <a class="el" href="group__hash.html#ga0bb6dbd3c310648c3cf7d202413ff0bc">psa_hash_compare()</a> instead.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir"></td><td class="paramname">alg</td><td>The hash algorithm to compute (<code>PSA_ALG_XXX</code> value such that <a class="el" href="group__crypto__types.html#gac9280662bb482590b4b33d1dcd32930f">PSA_ALG_IS_HASH</a>(<code>alg</code>) is true). </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Buffer containing the message to hash. </td></tr>
<tr><td class="paramdir"></td><td class="paramname">input_length</td><td>Size of the <code>input</code> buffer in bytes. </td></tr>
<tr><td class="paramdir">[out]</td><td class="paramname">hash</td><td>Buffer where the hash is to be written. </td></tr>
<tr><td class="paramdir"></td><td class="paramname">hash_size</td><td>Size of the <code>hash</code> buffer in bytes. </td></tr>
<tr><td class="paramdir">[out]</td><td class="paramname">hash_length</td><td>On success, the number of bytes that make up the hash value. This is always <a class="el" href="crypto__sizes_8h.html#aef340331ce3cba2b57e1fc5624bf1f99">PSA_HASH_SIZE</a>(<code>alg</code>).</td></tr>
</table>
</dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga1dcc6d130633ed5db8942257581b55dd">PSA_ERROR_NOT_SUPPORTED</a></td><td><code>alg</code> is not supported or is not a hash algorithm. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="ga4795fd06a0067b0adcd92e9627b8c97e"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_hash_finish </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *&#160;</td>
<td class="paramname"><em>operation</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t *&#160;</td>
<td class="paramname"><em>hash</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>hash_size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>hash_length</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Finish the calculation of the hash of a message.</p>
<p>The application must call <a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup()</a> before calling this function. This function calculates the hash of the message formed by concatenating the inputs passed to preceding calls to <a class="el" href="group__hash.html#ga65b16ef97d7f650899b7db4b7d1112ff">psa_hash_update()</a>.</p>
<p>When this function returns, the operation becomes inactive.</p>
<dl class="section warning"><dt>Warning</dt><dd>Applications should not call this function if they expect a specific value for the hash. Call <a class="el" href="group__hash.html#ga7be923c5700c9c70ef77ee9b76d1a5c0">psa_hash_verify()</a> instead. Beware that comparing integrity or authenticity data such as hash values with a function such as <code>memcmp</code> is risky because the time taken by the comparison may leak information about the hashed data which could allow an attacker to guess a valid hash and thereby bypass security controls.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>Active hash operation. </td></tr>
<tr><td class="paramdir">[out]</td><td class="paramname">hash</td><td>Buffer where the hash is to be written. </td></tr>
<tr><td class="paramdir"></td><td class="paramname">hash_size</td><td>Size of the <code>hash</code> buffer in bytes. </td></tr>
<tr><td class="paramdir">[out]</td><td class="paramname">hash_length</td><td>On success, the number of bytes that make up the hash value. This is always <a class="el" href="crypto__sizes_8h.html#aef340331ce3cba2b57e1fc5624bf1f99">PSA_HASH_SIZE</a>(<code>alg</code>) where <code>alg</code> is the hash algorithm that is calculated.</td></tr>
</table>
</dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td>The operation state is not valid (not set up, or already completed). </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga695025f4ec11249aee7ea3d0f65e01c8">PSA_ERROR_BUFFER_TOO_SMALL</a></td><td>The size of the <code>hash</code> buffer is too small. You can determine a sufficient buffer size by calling <a class="el" href="crypto__sizes_8h.html#aef340331ce3cba2b57e1fc5624bf1f99">PSA_HASH_SIZE</a>(<code>alg</code>) where <code>alg</code> is the hash algorithm that is calculated. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="ga8d72896cf70fc4d514c5c6b978912515"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_hash_setup </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *&#160;</td>
<td class="paramname"><em>operation</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a>&#160;</td>
<td class="paramname"><em>alg</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Set up a multipart hash operation.</p>
<p>The sequence of operations to calculate a hash (message digest) is as follows:</p><ol type="1">
<li>Allocate an operation object which will be passed to all the functions listed here.</li>
<li>Initialize the operation object with one of the methods described in the documentation for <a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a>, e.g. PSA_HASH_OPERATION_INIT.</li>
<li>Call <a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup()</a> to specify the algorithm.</li>
<li>Call <a class="el" href="group__hash.html#ga65b16ef97d7f650899b7db4b7d1112ff">psa_hash_update()</a> zero, one or more times, passing a fragment of the message each time. The hash that is calculated is the hash of the concatenation of these messages in order.</li>
<li>To calculate the hash, call <a class="el" href="group__hash.html#ga4795fd06a0067b0adcd92e9627b8c97e">psa_hash_finish()</a>. To compare the hash with an expected value, call <a class="el" href="group__hash.html#ga7be923c5700c9c70ef77ee9b76d1a5c0">psa_hash_verify()</a>.</li>
</ol>
<p>The application may call <a class="el" href="group__hash.html#gab0b4d5f9912a615559497a467b532928">psa_hash_abort()</a> at any time after the operation has been initialized.</p>
<p>After a successful call to <a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup()</a>, the application must eventually terminate the operation. The following events terminate an operation:</p><ul>
<li>A failed call to <a class="el" href="group__hash.html#ga65b16ef97d7f650899b7db4b7d1112ff">psa_hash_update()</a>.</li>
<li>A call to <a class="el" href="group__hash.html#ga4795fd06a0067b0adcd92e9627b8c97e">psa_hash_finish()</a>, <a class="el" href="group__hash.html#ga7be923c5700c9c70ef77ee9b76d1a5c0">psa_hash_verify()</a> or <a class="el" href="group__hash.html#gab0b4d5f9912a615559497a467b532928">psa_hash_abort()</a>.</li>
</ul>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>The operation object to set up. It must have been initialized as per the documentation for <a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> and not yet in use. </td></tr>
<tr><td class="paramdir"></td><td class="paramname">alg</td><td>The hash algorithm to compute (<code>PSA_ALG_XXX</code> value such that <a class="el" href="group__crypto__types.html#gac9280662bb482590b4b33d1dcd32930f">PSA_ALG_IS_HASH</a>(<code>alg</code>) is true).</td></tr>
</table>
</dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga1dcc6d130633ed5db8942257581b55dd">PSA_ERROR_NOT_SUPPORTED</a></td><td><code>alg</code> is not supported or is not a hash algorithm. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="ga65b16ef97d7f650899b7db4b7d1112ff"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_hash_update </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *&#160;</td>
<td class="paramname"><em>operation</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const uint8_t *&#160;</td>
<td class="paramname"><em>input</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>input_length</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Add a message fragment to a multipart hash operation.</p>
<p>The application must call <a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup()</a> before calling this function.</p>
<p>If this function returns an error status, the operation becomes inactive.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>Active hash operation. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Buffer containing the message fragment to hash. </td></tr>
<tr><td class="paramdir"></td><td class="paramname">input_length</td><td>Size of the <code>input</code> buffer in bytes.</td></tr>
</table>
</dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td>The operation state is not valid (not set up, or already completed). </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="ga7be923c5700c9c70ef77ee9b76d1a5c0"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_hash_verify </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__hash.html#ga3c4205d2ce66c4095fc5c78c25273fab">psa_hash_operation_t</a> *&#160;</td>
<td class="paramname"><em>operation</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const uint8_t *&#160;</td>
<td class="paramname"><em>hash</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>hash_length</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Finish the calculation of the hash of a message and compare it with an expected value.</p>
<p>The application must call <a class="el" href="group__hash.html#ga8d72896cf70fc4d514c5c6b978912515">psa_hash_setup()</a> before calling this function. This function calculates the hash of the message formed by concatenating the inputs passed to preceding calls to <a class="el" href="group__hash.html#ga65b16ef97d7f650899b7db4b7d1112ff">psa_hash_update()</a>. It then compares the calculated hash with the expected hash passed as a parameter to this function.</p>
<p>When this function returns, the operation becomes inactive.</p>
<dl class="section note"><dt>Note</dt><dd>Implementations shall make the best effort to ensure that the comparison between the actual hash and the expected hash is performed in constant time.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>Active hash operation. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">hash</td><td>Buffer containing the expected hash value. </td></tr>
<tr><td class="paramdir"></td><td class="paramname">hash_length</td><td>Size of the <code>hash</code> buffer in bytes.</td></tr>
</table>
</dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>The expected hash is identical to the actual hash of the message. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga35927f755d232c4766de600f2c49e9f2">PSA_ERROR_INVALID_SIGNATURE</a></td><td>The hash of the message was calculated successfully, but it differs from the expected hash. </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td>The operation state is not valid (not set up, or already completed). </td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr>
<tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr>
</table>
</dd>
</dl>
</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>