Gilles Peskine | 89f0a53 | 2019-01-31 11:47:57 +0100 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
| 5 | <meta http-equiv="X-UA-Compatible" content="IE=9"/> |
| 6 | <meta name="generator" content="Doxygen 1.8.11"/> |
| 7 | <title>Platform Security Architecture — cryptography and keystore interface: Message authentication codes</title> |
| 8 | <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| 9 | <script type="text/javascript" src="jquery.js"></script> |
| 10 | <script type="text/javascript" src="dynsections.js"></script> |
| 11 | <link href="search/search.css" rel="stylesheet" type="text/css"/> |
| 12 | <script type="text/javascript" src="search/searchdata.js"></script> |
| 13 | <script type="text/javascript" src="search/search.js"></script> |
| 14 | <script type="text/javascript"> |
| 15 | $(document).ready(function() { init_search(); }); |
| 16 | </script> |
| 17 | <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| 18 | </head> |
| 19 | <body> |
| 20 | <div id="top"><!-- do not remove this div, it is closed by doxygen! --> |
| 21 | <div id="titlearea"> |
| 22 | <table cellspacing="0" cellpadding="0"> |
| 23 | <tbody> |
| 24 | <tr style="height: 56px;"> |
| 25 | <td id="projectalign" style="padding-left: 0.5em;"> |
| 26 | <div id="projectname">Platform Security Architecture — cryptography and keystore interface |
Gilles Peskine | 45adc5b | 2019-03-05 16:34:20 +0100 | [diff] [blame^] | 27 |  <span id="projectnumber">beta 2 — 2019-02-22</span> |
Gilles Peskine | 89f0a53 | 2019-01-31 11:47:57 +0100 | [diff] [blame] | 28 | </div> |
| 29 | </td> |
| 30 | </tr> |
| 31 | </tbody> |
| 32 | </table> |
| 33 | </div> |
| 34 | <!-- end header part --> |
| 35 | <!-- Generated by Doxygen 1.8.11 --> |
| 36 | <script type="text/javascript"> |
| 37 | var searchBox = new SearchBox("searchBox", "search",false,'Search'); |
| 38 | </script> |
| 39 | <div id="navrow1" class="tabs"> |
| 40 | <ul class="tablist"> |
| 41 | <li><a href="index.html"><span>Main Page</span></a></li> |
| 42 | <li class="current"><a href="modules.html"><span>Modules</span></a></li> |
| 43 | <li><a href="annotated.html"><span>Classes</span></a></li> |
| 44 | <li><a href="files.html"><span>Files</span></a></li> |
| 45 | <li> |
| 46 | <div id="MSearchBox" class="MSearchBoxInactive"> |
| 47 | <span class="left"> |
| 48 | <img id="MSearchSelect" src="search/mag_sel.png" |
| 49 | onmouseover="return searchBox.OnSearchSelectShow()" |
| 50 | onmouseout="return searchBox.OnSearchSelectHide()" |
| 51 | alt=""/> |
| 52 | <input type="text" id="MSearchField" value="Search" accesskey="S" |
| 53 | onfocus="searchBox.OnSearchFieldFocus(true)" |
| 54 | onblur="searchBox.OnSearchFieldFocus(false)" |
| 55 | onkeyup="searchBox.OnSearchFieldChange(event)"/> |
| 56 | </span><span class="right"> |
| 57 | <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> |
| 58 | </span> |
| 59 | </div> |
| 60 | </li> |
| 61 | </ul> |
| 62 | </div> |
| 63 | </div><!-- top --> |
| 64 | <!-- window showing the filter options --> |
| 65 | <div id="MSearchSelectWindow" |
| 66 | onmouseover="return searchBox.OnSearchSelectShow()" |
| 67 | onmouseout="return searchBox.OnSearchSelectHide()" |
| 68 | onkeydown="return searchBox.OnSearchSelectKey(event)"> |
| 69 | </div> |
| 70 | |
| 71 | <!-- iframe showing the search results (closed by default) --> |
| 72 | <div id="MSearchResultsWindow"> |
| 73 | <iframe src="javascript:void(0)" frameborder="0" |
| 74 | name="MSearchResults" id="MSearchResults"> |
| 75 | </iframe> |
| 76 | </div> |
| 77 | |
| 78 | <div class="header"> |
| 79 | <div class="summary"> |
| 80 | <a href="#define-members">Macros</a> | |
| 81 | <a href="#typedef-members">Typedefs</a> | |
| 82 | <a href="#func-members">Functions</a> </div> |
| 83 | <div class="headertitle"> |
| 84 | <div class="title">Message authentication codes</div> </div> |
| 85 | </div><!--header--> |
| 86 | <div class="contents"> |
| 87 | <table class="memberdecls"> |
| 88 | <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a> |
| 89 | Macros</h2></td></tr> |
| 90 | <tr class="memitem:ga441b6efc161a4573d06465bd22d9dc2d"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#ga441b6efc161a4573d06465bd22d9dc2d">PSA_MAC_OPERATION_INIT</a>   {0}</td></tr> |
| 91 | <tr class="separator:ga441b6efc161a4573d06465bd22d9dc2d"><td class="memSeparator" colspan="2"> </td></tr> |
| 92 | </table><table class="memberdecls"> |
| 93 | <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a> |
| 94 | Typedefs</h2></td></tr> |
| 95 | <tr class="memitem:ga78f0838b0c4e3db28b26355624d4bd37"><td class="memItemLeft" align="right" valign="top">typedef struct psa_mac_operation_s </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a></td></tr> |
| 96 | <tr class="separator:ga78f0838b0c4e3db28b26355624d4bd37"><td class="memSeparator" colspan="2"> </td></tr> |
| 97 | </table><table class="memberdecls"> |
| 98 | <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a> |
| 99 | Functions</h2></td></tr> |
| 100 | <tr class="memitem:gace78d9b51394f9d4f77952963665897a"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#gace78d9b51394f9d4f77952963665897a">psa_mac_compute</a> (<a class="el" href="group__platform.html#gabf6d5fd4e2ea89ecd425c88f057e7f75">psa_key_handle_t</a> handle, <a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> alg, const uint8_t *input, size_t input_length, uint8_t *mac, size_t mac_size, size_t *mac_length)</td></tr> |
| 101 | <tr class="separator:gace78d9b51394f9d4f77952963665897a"><td class="memSeparator" colspan="2"> </td></tr> |
| 102 | <tr class="memitem:ga08e2e8c21bfe762a907266f3bdd1d07c"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#ga08e2e8c21bfe762a907266f3bdd1d07c">psa_mac_verify</a> (<a class="el" href="group__platform.html#gabf6d5fd4e2ea89ecd425c88f057e7f75">psa_key_handle_t</a> handle, <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 *mac, const size_t mac_length)</td></tr> |
| 103 | <tr class="separator:ga08e2e8c21bfe762a907266f3bdd1d07c"><td class="memSeparator" colspan="2"> </td></tr> |
| 104 | <tr class="memitem:gad33f2b15119593571ca6b8e7c757ab0e"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#gad33f2b15119593571ca6b8e7c757ab0e">psa_mac_sign_setup</a> (<a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> *operation, <a class="el" href="group__platform.html#gabf6d5fd4e2ea89ecd425c88f057e7f75">psa_key_handle_t</a> handle, <a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> alg)</td></tr> |
| 105 | <tr class="separator:gad33f2b15119593571ca6b8e7c757ab0e"><td class="memSeparator" colspan="2"> </td></tr> |
| 106 | <tr class="memitem:gaa721a59ae6d085ec90c7dc918879a027"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#gaa721a59ae6d085ec90c7dc918879a027">psa_mac_verify_setup</a> (<a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> *operation, <a class="el" href="group__platform.html#gabf6d5fd4e2ea89ecd425c88f057e7f75">psa_key_handle_t</a> handle, <a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> alg)</td></tr> |
| 107 | <tr class="separator:gaa721a59ae6d085ec90c7dc918879a027"><td class="memSeparator" colspan="2"> </td></tr> |
| 108 | <tr class="memitem:ga5560af371497babefe03c9da4e8a1c05"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#ga5560af371497babefe03c9da4e8a1c05">psa_mac_update</a> (<a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> *operation, const uint8_t *input, size_t input_length)</td></tr> |
| 109 | <tr class="separator:ga5560af371497babefe03c9da4e8a1c05"><td class="memSeparator" colspan="2"> </td></tr> |
| 110 | <tr class="memitem:gac22bc0125580c96724a09226cfbc97f2"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#gac22bc0125580c96724a09226cfbc97f2">psa_mac_sign_finish</a> (<a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> *operation, uint8_t *mac, size_t mac_size, size_t *mac_length)</td></tr> |
| 111 | <tr class="separator:gac22bc0125580c96724a09226cfbc97f2"><td class="memSeparator" colspan="2"> </td></tr> |
| 112 | <tr class="memitem:gac92b2930d6728e1be4d011c05d485822"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#gac92b2930d6728e1be4d011c05d485822">psa_mac_verify_finish</a> (<a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> *operation, const uint8_t *mac, size_t mac_length)</td></tr> |
| 113 | <tr class="separator:gac92b2930d6728e1be4d011c05d485822"><td class="memSeparator" colspan="2"> </td></tr> |
| 114 | <tr class="memitem:gacd8dd54855ba1bc0a03f104f252884fd"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__MAC.html#gacd8dd54855ba1bc0a03f104f252884fd">psa_mac_abort</a> (<a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> *operation)</td></tr> |
| 115 | <tr class="separator:gacd8dd54855ba1bc0a03f104f252884fd"><td class="memSeparator" colspan="2"> </td></tr> |
| 116 | </table> |
| 117 | <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2> |
| 118 | <h2 class="groupheader">Macro Definition Documentation</h2> |
| 119 | <a class="anchor" id="ga441b6efc161a4573d06465bd22d9dc2d"></a> |
| 120 | <div class="memitem"> |
| 121 | <div class="memproto"> |
| 122 | <table class="memname"> |
| 123 | <tr> |
| 124 | <td class="memname">#define PSA_MAC_OPERATION_INIT   {0}</td> |
| 125 | </tr> |
| 126 | </table> |
| 127 | </div><div class="memdoc"> |
| 128 | <p>This macro returns a suitable initializer for a MAC operation object of type <a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a>. </p> |
| 129 | |
| 130 | </div> |
| 131 | </div> |
| 132 | <h2 class="groupheader">Typedef Documentation</h2> |
| 133 | <a class="anchor" id="ga78f0838b0c4e3db28b26355624d4bd37"></a> |
| 134 | <div class="memitem"> |
| 135 | <div class="memproto"> |
| 136 | <table class="memname"> |
| 137 | <tr> |
| 138 | <td class="memname">typedef struct psa_mac_operation_s <a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a></td> |
| 139 | </tr> |
| 140 | </table> |
| 141 | </div><div class="memdoc"> |
| 142 | <p>The type of the state data structure for multipart MAC operations.</p> |
| 143 | <p>Before calling any function on a MAC operation object, the application must initialize it by any of the following means:</p><ul> |
| 144 | <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> psa_mac_operation_t operation;</div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> memset(&operation, 0, sizeof(operation));</div></div><!-- fragment --></li> |
| 145 | <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> psa_mac_operation_t operation = {0};</div></div><!-- fragment --></li> |
| 146 | <li>Initialize the structure to the initializer <a class="el" href="group__MAC.html#ga441b6efc161a4573d06465bd22d9dc2d">PSA_MAC_OPERATION_INIT</a>, for example: <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;</div></div><!-- fragment --></li> |
| 147 | <li>Assign the result of the function psa_mac_operation_init() to the structure, for example: <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> psa_mac_operation_t operation;</div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> operation = psa_mac_operation_init();</div></div><!-- fragment --></li> |
| 148 | </ul> |
| 149 | <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> |
| 150 | |
| 151 | </div> |
| 152 | </div> |
| 153 | <h2 class="groupheader">Function Documentation</h2> |
| 154 | <a class="anchor" id="gacd8dd54855ba1bc0a03f104f252884fd"></a> |
| 155 | <div class="memitem"> |
| 156 | <div class="memproto"> |
| 157 | <table class="memname"> |
| 158 | <tr> |
| 159 | <td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_mac_abort </td> |
| 160 | <td>(</td> |
| 161 | <td class="paramtype"><a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> * </td> |
| 162 | <td class="paramname"><em>operation</em></td><td>)</td> |
| 163 | <td></td> |
| 164 | </tr> |
| 165 | </table> |
| 166 | </div><div class="memdoc"> |
| 167 | <p>Abort a MAC operation.</p> |
| 168 | <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__MAC.html#gad33f2b15119593571ca6b8e7c757ab0e">psa_mac_sign_setup()</a> or <a class="el" href="group__MAC.html#gaa721a59ae6d085ec90c7dc918879a027">psa_mac_verify_setup()</a> again.</p> |
| 169 | <p>You may call this function any time after the operation object has been initialized by any of the following methods:</p><ul> |
| 170 | <li>A call to <a class="el" href="group__MAC.html#gad33f2b15119593571ca6b8e7c757ab0e">psa_mac_sign_setup()</a> or <a class="el" href="group__MAC.html#gaa721a59ae6d085ec90c7dc918879a027">psa_mac_verify_setup()</a>, whether it succeeds or not.</li> |
| 171 | <li>Initializing the <code>struct</code> to all-bits-zero.</li> |
| 172 | <li>Initializing the <code>struct</code> to logical zeros, e.g. <code>psa_mac_operation_t operation = {0}</code>.</li> |
| 173 | </ul> |
| 174 | <p>In particular, calling <a class="el" href="group__MAC.html#gacd8dd54855ba1bc0a03f104f252884fd">psa_mac_abort()</a> after the operation has been terminated by a call to <a class="el" href="group__MAC.html#gacd8dd54855ba1bc0a03f104f252884fd">psa_mac_abort()</a>, <a class="el" href="group__MAC.html#gac22bc0125580c96724a09226cfbc97f2">psa_mac_sign_finish()</a> or <a class="el" href="group__MAC.html#gac92b2930d6728e1be4d011c05d485822">psa_mac_verify_finish()</a> is safe and has no effect.</p> |
| 175 | <dl class="params"><dt>Parameters</dt><dd> |
| 176 | <table class="params"> |
| 177 | <tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>Initialized MAC operation.</td></tr> |
| 178 | </table> |
| 179 | </dd> |
| 180 | </dl> |
| 181 | <dl class="retval"><dt>Return values</dt><dd> |
| 182 | <table class="retval"> |
| 183 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td></td></tr> |
| 184 | <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 MAC operation. </td></tr> |
| 185 | <tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr> |
| 186 | <tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr> |
| 187 | <tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr> |
| 188 | </table> |
| 189 | </dd> |
| 190 | </dl> |
| 191 | |
| 192 | </div> |
| 193 | </div> |
| 194 | <a class="anchor" id="gace78d9b51394f9d4f77952963665897a"></a> |
| 195 | <div class="memitem"> |
| 196 | <div class="memproto"> |
| 197 | <table class="memname"> |
| 198 | <tr> |
| 199 | <td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_mac_compute </td> |
| 200 | <td>(</td> |
| 201 | <td class="paramtype"><a class="el" href="group__platform.html#gabf6d5fd4e2ea89ecd425c88f057e7f75">psa_key_handle_t</a> </td> |
| 202 | <td class="paramname"><em>handle</em>, </td> |
| 203 | </tr> |
| 204 | <tr> |
| 205 | <td class="paramkey"></td> |
| 206 | <td></td> |
| 207 | <td class="paramtype"><a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> </td> |
| 208 | <td class="paramname"><em>alg</em>, </td> |
| 209 | </tr> |
| 210 | <tr> |
| 211 | <td class="paramkey"></td> |
| 212 | <td></td> |
| 213 | <td class="paramtype">const uint8_t * </td> |
| 214 | <td class="paramname"><em>input</em>, </td> |
| 215 | </tr> |
| 216 | <tr> |
| 217 | <td class="paramkey"></td> |
| 218 | <td></td> |
| 219 | <td class="paramtype">size_t </td> |
| 220 | <td class="paramname"><em>input_length</em>, </td> |
| 221 | </tr> |
| 222 | <tr> |
| 223 | <td class="paramkey"></td> |
| 224 | <td></td> |
| 225 | <td class="paramtype">uint8_t * </td> |
| 226 | <td class="paramname"><em>mac</em>, </td> |
| 227 | </tr> |
| 228 | <tr> |
| 229 | <td class="paramkey"></td> |
| 230 | <td></td> |
| 231 | <td class="paramtype">size_t </td> |
| 232 | <td class="paramname"><em>mac_size</em>, </td> |
| 233 | </tr> |
| 234 | <tr> |
| 235 | <td class="paramkey"></td> |
| 236 | <td></td> |
| 237 | <td class="paramtype">size_t * </td> |
| 238 | <td class="paramname"><em>mac_length</em> </td> |
| 239 | </tr> |
| 240 | <tr> |
| 241 | <td></td> |
| 242 | <td>)</td> |
| 243 | <td></td><td></td> |
| 244 | </tr> |
| 245 | </table> |
| 246 | </div><div class="memdoc"> |
| 247 | <p>Calculate the MAC (message authentication code) of a message.</p> |
| 248 | <dl class="section note"><dt>Note</dt><dd>To verify the MAC of a message against an expected value, use <a class="el" href="group__MAC.html#ga08e2e8c21bfe762a907266f3bdd1d07c">psa_mac_verify()</a> instead. Beware that comparing integrity or authenticity data such as MAC values with a function such as <code>memcmp</code> is risky because the time taken by the comparison may leak information about the MAC value which could allow an attacker to guess a valid MAC and thereby bypass security controls.</dd></dl> |
| 249 | <dl class="params"><dt>Parameters</dt><dd> |
| 250 | <table class="params"> |
| 251 | <tr><td class="paramdir"></td><td class="paramname">handle</td><td>Handle to the key to use for the operation. </td></tr> |
Gilles Peskine | 45adc5b | 2019-03-05 16:34:20 +0100 | [diff] [blame^] | 252 | <tr><td class="paramdir"></td><td class="paramname">alg</td><td>The MAC algorithm to compute (<code>PSA_ALG_XXX</code> value such that <a class="el" href="group__crypto__types.html#gaca7aee4c9dde316b3b1a150a26eab776">PSA_ALG_IS_MAC</a>(<code>alg</code>) is true). </td></tr> |
Gilles Peskine | 89f0a53 | 2019-01-31 11:47:57 +0100 | [diff] [blame] | 253 | <tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Buffer containing the input message. </td></tr> |
| 254 | <tr><td class="paramdir"></td><td class="paramname">input_length</td><td>Size of the <code>input</code> buffer in bytes. </td></tr> |
| 255 | <tr><td class="paramdir">[out]</td><td class="paramname">mac</td><td>Buffer where the MAC value is to be written. </td></tr> |
| 256 | <tr><td class="paramdir"></td><td class="paramname">mac_size</td><td>Size of the <code>mac</code> buffer in bytes. </td></tr> |
Gilles Peskine | 45adc5b | 2019-03-05 16:34:20 +0100 | [diff] [blame^] | 257 | <tr><td class="paramdir">[out]</td><td class="paramname">mac_length</td><td>On success, the number of bytes that make up the MAC value.</td></tr> |
Gilles Peskine | 89f0a53 | 2019-01-31 11:47:57 +0100 | [diff] [blame] | 258 | </table> |
| 259 | </dd> |
| 260 | </dl> |
| 261 | <dl class="retval"><dt>Return values</dt><dd> |
| 262 | <table class="retval"> |
| 263 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr> |
| 264 | <tr><td class="paramname"><a class="el" href="group__error.html#gadf22718935657c2c3168c228204085f9">PSA_ERROR_INVALID_HANDLE</a></td><td></td></tr> |
| 265 | <tr><td class="paramname"><a class="el" href="group__error.html#gaba00e3e6ceb2b12965a81e5ac02ae040">PSA_ERROR_EMPTY_SLOT</a></td><td></td></tr> |
| 266 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4d1b8dd8526177a15a210b7afc1accb1">PSA_ERROR_NOT_PERMITTED</a></td><td></td></tr> |
| 267 | <tr><td class="paramname"><a class="el" href="group__error.html#ga798df25a505ebf931f7bec1f80f1f85f">PSA_ERROR_INVALID_ARGUMENT</a></td><td><code>key</code> is not compatible with <code>alg</code>. </td></tr> |
| 268 | <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 MAC algorithm. </td></tr> |
| 269 | <tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr> |
| 270 | <tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr> |
| 271 | <tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr> |
| 272 | <tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr> |
| 273 | <tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td>The library has not been previously initialized by <a class="el" href="group__initialization.html#ga2de150803fc2f7dc6101d5af7e921dd9" title="Library initialization. ">psa_crypto_init()</a>. It is implementation-dependent whether a failure to initialize results in this error code. </td></tr> |
| 274 | </table> |
| 275 | </dd> |
| 276 | </dl> |
| 277 | |
| 278 | </div> |
| 279 | </div> |
| 280 | <a class="anchor" id="gac22bc0125580c96724a09226cfbc97f2"></a> |
| 281 | <div class="memitem"> |
| 282 | <div class="memproto"> |
| 283 | <table class="memname"> |
| 284 | <tr> |
| 285 | <td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_mac_sign_finish </td> |
| 286 | <td>(</td> |
| 287 | <td class="paramtype"><a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> * </td> |
| 288 | <td class="paramname"><em>operation</em>, </td> |
| 289 | </tr> |
| 290 | <tr> |
| 291 | <td class="paramkey"></td> |
| 292 | <td></td> |
| 293 | <td class="paramtype">uint8_t * </td> |
| 294 | <td class="paramname"><em>mac</em>, </td> |
| 295 | </tr> |
| 296 | <tr> |
| 297 | <td class="paramkey"></td> |
| 298 | <td></td> |
| 299 | <td class="paramtype">size_t </td> |
| 300 | <td class="paramname"><em>mac_size</em>, </td> |
| 301 | </tr> |
| 302 | <tr> |
| 303 | <td class="paramkey"></td> |
| 304 | <td></td> |
| 305 | <td class="paramtype">size_t * </td> |
| 306 | <td class="paramname"><em>mac_length</em> </td> |
| 307 | </tr> |
| 308 | <tr> |
| 309 | <td></td> |
| 310 | <td>)</td> |
| 311 | <td></td><td></td> |
| 312 | </tr> |
| 313 | </table> |
| 314 | </div><div class="memdoc"> |
| 315 | <p>Finish the calculation of the MAC of a message.</p> |
| 316 | <p>The application must call <a class="el" href="group__MAC.html#gad33f2b15119593571ca6b8e7c757ab0e">psa_mac_sign_setup()</a> before calling this function. This function calculates the MAC of the message formed by concatenating the inputs passed to preceding calls to <a class="el" href="group__MAC.html#ga5560af371497babefe03c9da4e8a1c05">psa_mac_update()</a>.</p> |
| 317 | <p>When this function returns, the operation becomes inactive.</p> |
| 318 | <dl class="section warning"><dt>Warning</dt><dd>Applications should not call this function if they expect a specific value for the MAC. Call <a class="el" href="group__MAC.html#gac92b2930d6728e1be4d011c05d485822">psa_mac_verify_finish()</a> instead. Beware that comparing integrity or authenticity data such as MAC values with a function such as <code>memcmp</code> is risky because the time taken by the comparison may leak information about the MAC value which could allow an attacker to guess a valid MAC and thereby bypass security controls.</dd></dl> |
| 319 | <dl class="params"><dt>Parameters</dt><dd> |
| 320 | <table class="params"> |
| 321 | <tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>Active MAC operation. </td></tr> |
| 322 | <tr><td class="paramdir">[out]</td><td class="paramname">mac</td><td>Buffer where the MAC value is to be written. </td></tr> |
| 323 | <tr><td class="paramdir"></td><td class="paramname">mac_size</td><td>Size of the <code>mac</code> buffer in bytes. </td></tr> |
| 324 | <tr><td class="paramdir">[out]</td><td class="paramname">mac_length</td><td>On success, the number of bytes that make up the MAC value. This is always <a class="el" href="crypto__sizes_8h.html#aa84c5fb384ac7cb1bfc52adde96588ee">PSA_MAC_FINAL_SIZE</a>(<code>key_type</code>, <code>key_bits</code>, <code>alg</code>) where <code>key_type</code> and <code>key_bits</code> are the type and bit-size respectively of the key and <code>alg</code> is the MAC algorithm that is calculated.</td></tr> |
| 325 | </table> |
| 326 | </dd> |
| 327 | </dl> |
| 328 | <dl class="retval"><dt>Return values</dt><dd> |
| 329 | <table class="retval"> |
| 330 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr> |
| 331 | <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> |
| 332 | <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>mac</code> buffer is too small. You can determine a sufficient buffer size by calling <a class="el" href="crypto__sizes_8h.html#aa84c5fb384ac7cb1bfc52adde96588ee">PSA_MAC_FINAL_SIZE()</a>. </td></tr> |
| 333 | <tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr> |
| 334 | <tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr> |
| 335 | <tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr> |
| 336 | <tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr> |
| 337 | </table> |
| 338 | </dd> |
| 339 | </dl> |
| 340 | |
| 341 | </div> |
| 342 | </div> |
| 343 | <a class="anchor" id="gad33f2b15119593571ca6b8e7c757ab0e"></a> |
| 344 | <div class="memitem"> |
| 345 | <div class="memproto"> |
| 346 | <table class="memname"> |
| 347 | <tr> |
| 348 | <td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_mac_sign_setup </td> |
| 349 | <td>(</td> |
| 350 | <td class="paramtype"><a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> * </td> |
| 351 | <td class="paramname"><em>operation</em>, </td> |
| 352 | </tr> |
| 353 | <tr> |
| 354 | <td class="paramkey"></td> |
| 355 | <td></td> |
| 356 | <td class="paramtype"><a class="el" href="group__platform.html#gabf6d5fd4e2ea89ecd425c88f057e7f75">psa_key_handle_t</a> </td> |
| 357 | <td class="paramname"><em>handle</em>, </td> |
| 358 | </tr> |
| 359 | <tr> |
| 360 | <td class="paramkey"></td> |
| 361 | <td></td> |
| 362 | <td class="paramtype"><a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> </td> |
| 363 | <td class="paramname"><em>alg</em> </td> |
| 364 | </tr> |
| 365 | <tr> |
| 366 | <td></td> |
| 367 | <td>)</td> |
| 368 | <td></td><td></td> |
| 369 | </tr> |
| 370 | </table> |
| 371 | </div><div class="memdoc"> |
| 372 | <p>Set up a multipart MAC calculation operation.</p> |
| 373 | <p>This function sets up the calculation of the MAC (message authentication code) of a byte string. To verify the MAC of a message against an expected value, use <a class="el" href="group__MAC.html#gaa721a59ae6d085ec90c7dc918879a027">psa_mac_verify_setup()</a> instead.</p> |
| 374 | <p>The sequence of operations to calculate a MAC is as follows:</p><ol type="1"> |
| 375 | <li>Allocate an operation object which will be passed to all the functions listed here.</li> |
| 376 | <li>Initialize the operation object with one of the methods described in the documentation for <a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a>, e.g. PSA_MAC_OPERATION_INIT.</li> |
| 377 | <li>Call <a class="el" href="group__MAC.html#gad33f2b15119593571ca6b8e7c757ab0e">psa_mac_sign_setup()</a> to specify the algorithm and key.</li> |
| 378 | <li>Call <a class="el" href="group__MAC.html#ga5560af371497babefe03c9da4e8a1c05">psa_mac_update()</a> zero, one or more times, passing a fragment of the message each time. The MAC that is calculated is the MAC of the concatenation of these messages in order.</li> |
| 379 | <li>At the end of the message, call <a class="el" href="group__MAC.html#gac22bc0125580c96724a09226cfbc97f2">psa_mac_sign_finish()</a> to finish calculating the MAC value and retrieve it.</li> |
| 380 | </ol> |
| 381 | <p>The application may call <a class="el" href="group__MAC.html#gacd8dd54855ba1bc0a03f104f252884fd">psa_mac_abort()</a> at any time after the operation has been initialized.</p> |
| 382 | <p>After a successful call to <a class="el" href="group__MAC.html#gad33f2b15119593571ca6b8e7c757ab0e">psa_mac_sign_setup()</a>, the application must eventually terminate the operation through one of the following methods:</p><ul> |
| 383 | <li>A failed call to <a class="el" href="group__MAC.html#ga5560af371497babefe03c9da4e8a1c05">psa_mac_update()</a>.</li> |
| 384 | <li>A call to <a class="el" href="group__MAC.html#gac22bc0125580c96724a09226cfbc97f2">psa_mac_sign_finish()</a> or <a class="el" href="group__MAC.html#gacd8dd54855ba1bc0a03f104f252884fd">psa_mac_abort()</a>.</li> |
| 385 | </ul> |
| 386 | <dl class="params"><dt>Parameters</dt><dd> |
| 387 | <table class="params"> |
| 388 | <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__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> and not yet in use. </td></tr> |
| 389 | <tr><td class="paramdir"></td><td class="paramname">handle</td><td>Handle to the key to use for the operation. It must remain valid until the operation terminates. </td></tr> |
Gilles Peskine | 45adc5b | 2019-03-05 16:34:20 +0100 | [diff] [blame^] | 390 | <tr><td class="paramdir"></td><td class="paramname">alg</td><td>The MAC algorithm to compute (<code>PSA_ALG_XXX</code> value such that <a class="el" href="group__crypto__types.html#gaca7aee4c9dde316b3b1a150a26eab776">PSA_ALG_IS_MAC</a>(<code>alg</code>) is true).</td></tr> |
Gilles Peskine | 89f0a53 | 2019-01-31 11:47:57 +0100 | [diff] [blame] | 391 | </table> |
| 392 | </dd> |
| 393 | </dl> |
| 394 | <dl class="retval"><dt>Return values</dt><dd> |
| 395 | <table class="retval"> |
| 396 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr> |
| 397 | <tr><td class="paramname"><a class="el" href="group__error.html#gadf22718935657c2c3168c228204085f9">PSA_ERROR_INVALID_HANDLE</a></td><td></td></tr> |
| 398 | <tr><td class="paramname"><a class="el" href="group__error.html#gaba00e3e6ceb2b12965a81e5ac02ae040">PSA_ERROR_EMPTY_SLOT</a></td><td></td></tr> |
| 399 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4d1b8dd8526177a15a210b7afc1accb1">PSA_ERROR_NOT_PERMITTED</a></td><td></td></tr> |
| 400 | <tr><td class="paramname"><a class="el" href="group__error.html#ga798df25a505ebf931f7bec1f80f1f85f">PSA_ERROR_INVALID_ARGUMENT</a></td><td><code>key</code> is not compatible with <code>alg</code>. </td></tr> |
| 401 | <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 MAC algorithm. </td></tr> |
| 402 | <tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr> |
| 403 | <tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr> |
| 404 | <tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr> |
| 405 | <tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr> |
| 406 | <tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td>The library has not been previously initialized by <a class="el" href="group__initialization.html#ga2de150803fc2f7dc6101d5af7e921dd9" title="Library initialization. ">psa_crypto_init()</a>. It is implementation-dependent whether a failure to initialize results in this error code. </td></tr> |
| 407 | </table> |
| 408 | </dd> |
| 409 | </dl> |
| 410 | |
| 411 | </div> |
| 412 | </div> |
| 413 | <a class="anchor" id="ga5560af371497babefe03c9da4e8a1c05"></a> |
| 414 | <div class="memitem"> |
| 415 | <div class="memproto"> |
| 416 | <table class="memname"> |
| 417 | <tr> |
| 418 | <td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_mac_update </td> |
| 419 | <td>(</td> |
| 420 | <td class="paramtype"><a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> * </td> |
| 421 | <td class="paramname"><em>operation</em>, </td> |
| 422 | </tr> |
| 423 | <tr> |
| 424 | <td class="paramkey"></td> |
| 425 | <td></td> |
| 426 | <td class="paramtype">const uint8_t * </td> |
| 427 | <td class="paramname"><em>input</em>, </td> |
| 428 | </tr> |
| 429 | <tr> |
| 430 | <td class="paramkey"></td> |
| 431 | <td></td> |
| 432 | <td class="paramtype">size_t </td> |
| 433 | <td class="paramname"><em>input_length</em> </td> |
| 434 | </tr> |
| 435 | <tr> |
| 436 | <td></td> |
| 437 | <td>)</td> |
| 438 | <td></td><td></td> |
| 439 | </tr> |
| 440 | </table> |
| 441 | </div><div class="memdoc"> |
| 442 | <p>Add a message fragment to a multipart MAC operation.</p> |
| 443 | <p>The application must call <a class="el" href="group__MAC.html#gad33f2b15119593571ca6b8e7c757ab0e">psa_mac_sign_setup()</a> or <a class="el" href="group__MAC.html#gaa721a59ae6d085ec90c7dc918879a027">psa_mac_verify_setup()</a> before calling this function.</p> |
| 444 | <p>If this function returns an error status, the operation becomes inactive.</p> |
| 445 | <dl class="params"><dt>Parameters</dt><dd> |
| 446 | <table class="params"> |
| 447 | <tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>Active MAC operation. </td></tr> |
| 448 | <tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Buffer containing the message fragment to add to the MAC calculation. </td></tr> |
| 449 | <tr><td class="paramdir"></td><td class="paramname">input_length</td><td>Size of the <code>input</code> buffer in bytes.</td></tr> |
| 450 | </table> |
| 451 | </dd> |
| 452 | </dl> |
| 453 | <dl class="retval"><dt>Return values</dt><dd> |
| 454 | <table class="retval"> |
| 455 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr> |
| 456 | <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> |
| 457 | <tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr> |
| 458 | <tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr> |
| 459 | <tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr> |
| 460 | <tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr> |
| 461 | </table> |
| 462 | </dd> |
| 463 | </dl> |
| 464 | |
| 465 | </div> |
| 466 | </div> |
| 467 | <a class="anchor" id="ga08e2e8c21bfe762a907266f3bdd1d07c"></a> |
| 468 | <div class="memitem"> |
| 469 | <div class="memproto"> |
| 470 | <table class="memname"> |
| 471 | <tr> |
| 472 | <td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_mac_verify </td> |
| 473 | <td>(</td> |
| 474 | <td class="paramtype"><a class="el" href="group__platform.html#gabf6d5fd4e2ea89ecd425c88f057e7f75">psa_key_handle_t</a> </td> |
| 475 | <td class="paramname"><em>handle</em>, </td> |
| 476 | </tr> |
| 477 | <tr> |
| 478 | <td class="paramkey"></td> |
| 479 | <td></td> |
| 480 | <td class="paramtype"><a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> </td> |
| 481 | <td class="paramname"><em>alg</em>, </td> |
| 482 | </tr> |
| 483 | <tr> |
| 484 | <td class="paramkey"></td> |
| 485 | <td></td> |
| 486 | <td class="paramtype">const uint8_t * </td> |
| 487 | <td class="paramname"><em>input</em>, </td> |
| 488 | </tr> |
| 489 | <tr> |
| 490 | <td class="paramkey"></td> |
| 491 | <td></td> |
| 492 | <td class="paramtype">size_t </td> |
| 493 | <td class="paramname"><em>input_length</em>, </td> |
| 494 | </tr> |
| 495 | <tr> |
| 496 | <td class="paramkey"></td> |
| 497 | <td></td> |
| 498 | <td class="paramtype">const uint8_t * </td> |
| 499 | <td class="paramname"><em>mac</em>, </td> |
| 500 | </tr> |
| 501 | <tr> |
| 502 | <td class="paramkey"></td> |
| 503 | <td></td> |
| 504 | <td class="paramtype">const size_t </td> |
| 505 | <td class="paramname"><em>mac_length</em> </td> |
| 506 | </tr> |
| 507 | <tr> |
| 508 | <td></td> |
| 509 | <td>)</td> |
| 510 | <td></td><td></td> |
| 511 | </tr> |
| 512 | </table> |
| 513 | </div><div class="memdoc"> |
| 514 | <p>Calculate the MAC of a message and compare it with a reference value.</p> |
| 515 | <dl class="params"><dt>Parameters</dt><dd> |
| 516 | <table class="params"> |
| 517 | <tr><td class="paramdir"></td><td class="paramname">handle</td><td>Handle to the key to use for the operation. </td></tr> |
Gilles Peskine | 45adc5b | 2019-03-05 16:34:20 +0100 | [diff] [blame^] | 518 | <tr><td class="paramdir"></td><td class="paramname">alg</td><td>The MAC algorithm to compute (<code>PSA_ALG_XXX</code> value such that <a class="el" href="group__crypto__types.html#gaca7aee4c9dde316b3b1a150a26eab776">PSA_ALG_IS_MAC</a>(<code>alg</code>) is true). </td></tr> |
Gilles Peskine | 89f0a53 | 2019-01-31 11:47:57 +0100 | [diff] [blame] | 519 | <tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Buffer containing the input message. </td></tr> |
| 520 | <tr><td class="paramdir"></td><td class="paramname">input_length</td><td>Size of the <code>input</code> buffer in bytes. </td></tr> |
| 521 | <tr><td class="paramdir">[out]</td><td class="paramname">mac</td><td>Buffer containing the expected MAC value. </td></tr> |
| 522 | <tr><td class="paramdir"></td><td class="paramname">mac_length</td><td>Size of the <code>mac</code> buffer in bytes.</td></tr> |
| 523 | </table> |
| 524 | </dd> |
| 525 | </dl> |
| 526 | <dl class="retval"><dt>Return values</dt><dd> |
| 527 | <table class="retval"> |
| 528 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>The expected MAC is identical to the actual MAC of the input. </td></tr> |
| 529 | <tr><td class="paramname"><a class="el" href="group__error.html#ga35927f755d232c4766de600f2c49e9f2">PSA_ERROR_INVALID_SIGNATURE</a></td><td>The MAC of the message was calculated successfully, but it differs from the expected value. </td></tr> |
| 530 | <tr><td class="paramname"><a class="el" href="group__error.html#gadf22718935657c2c3168c228204085f9">PSA_ERROR_INVALID_HANDLE</a></td><td></td></tr> |
| 531 | <tr><td class="paramname"><a class="el" href="group__error.html#gaba00e3e6ceb2b12965a81e5ac02ae040">PSA_ERROR_EMPTY_SLOT</a></td><td></td></tr> |
| 532 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4d1b8dd8526177a15a210b7afc1accb1">PSA_ERROR_NOT_PERMITTED</a></td><td></td></tr> |
| 533 | <tr><td class="paramname"><a class="el" href="group__error.html#ga798df25a505ebf931f7bec1f80f1f85f">PSA_ERROR_INVALID_ARGUMENT</a></td><td><code>key</code> is not compatible with <code>alg</code>. </td></tr> |
| 534 | <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 MAC algorithm. </td></tr> |
| 535 | <tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr> |
| 536 | <tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr> |
| 537 | <tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr> |
| 538 | <tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr> |
| 539 | </table> |
| 540 | </dd> |
| 541 | </dl> |
| 542 | |
| 543 | </div> |
| 544 | </div> |
| 545 | <a class="anchor" id="gac92b2930d6728e1be4d011c05d485822"></a> |
| 546 | <div class="memitem"> |
| 547 | <div class="memproto"> |
| 548 | <table class="memname"> |
| 549 | <tr> |
| 550 | <td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_mac_verify_finish </td> |
| 551 | <td>(</td> |
| 552 | <td class="paramtype"><a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> * </td> |
| 553 | <td class="paramname"><em>operation</em>, </td> |
| 554 | </tr> |
| 555 | <tr> |
| 556 | <td class="paramkey"></td> |
| 557 | <td></td> |
| 558 | <td class="paramtype">const uint8_t * </td> |
| 559 | <td class="paramname"><em>mac</em>, </td> |
| 560 | </tr> |
| 561 | <tr> |
| 562 | <td class="paramkey"></td> |
| 563 | <td></td> |
| 564 | <td class="paramtype">size_t </td> |
| 565 | <td class="paramname"><em>mac_length</em> </td> |
| 566 | </tr> |
| 567 | <tr> |
| 568 | <td></td> |
| 569 | <td>)</td> |
| 570 | <td></td><td></td> |
| 571 | </tr> |
| 572 | </table> |
| 573 | </div><div class="memdoc"> |
| 574 | <p>Finish the calculation of the MAC of a message and compare it with an expected value.</p> |
| 575 | <p>The application must call <a class="el" href="group__MAC.html#gaa721a59ae6d085ec90c7dc918879a027">psa_mac_verify_setup()</a> before calling this function. This function calculates the MAC of the message formed by concatenating the inputs passed to preceding calls to <a class="el" href="group__MAC.html#ga5560af371497babefe03c9da4e8a1c05">psa_mac_update()</a>. It then compares the calculated MAC with the expected MAC passed as a parameter to this function.</p> |
| 576 | <p>When this function returns, the operation becomes inactive.</p> |
| 577 | <dl class="section note"><dt>Note</dt><dd>Implementations shall make the best effort to ensure that the comparison between the actual MAC and the expected MAC is performed in constant time.</dd></dl> |
| 578 | <dl class="params"><dt>Parameters</dt><dd> |
| 579 | <table class="params"> |
| 580 | <tr><td class="paramdir">[in,out]</td><td class="paramname">operation</td><td>Active MAC operation. </td></tr> |
| 581 | <tr><td class="paramdir">[in]</td><td class="paramname">mac</td><td>Buffer containing the expected MAC value. </td></tr> |
| 582 | <tr><td class="paramdir"></td><td class="paramname">mac_length</td><td>Size of the <code>mac</code> buffer in bytes.</td></tr> |
| 583 | </table> |
| 584 | </dd> |
| 585 | </dl> |
| 586 | <dl class="retval"><dt>Return values</dt><dd> |
| 587 | <table class="retval"> |
| 588 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>The expected MAC is identical to the actual MAC of the message. </td></tr> |
| 589 | <tr><td class="paramname"><a class="el" href="group__error.html#ga35927f755d232c4766de600f2c49e9f2">PSA_ERROR_INVALID_SIGNATURE</a></td><td>The MAC of the message was calculated successfully, but it differs from the expected MAC. </td></tr> |
| 590 | <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> |
| 591 | <tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr> |
| 592 | <tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr> |
| 593 | <tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr> |
| 594 | <tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr> |
| 595 | </table> |
| 596 | </dd> |
| 597 | </dl> |
| 598 | |
| 599 | </div> |
| 600 | </div> |
| 601 | <a class="anchor" id="gaa721a59ae6d085ec90c7dc918879a027"></a> |
| 602 | <div class="memitem"> |
| 603 | <div class="memproto"> |
| 604 | <table class="memname"> |
| 605 | <tr> |
| 606 | <td class="memname"><a class="el" href="group__error.html#ga05676e70ba5c6a7565aff3c36677c1f9">psa_status_t</a> psa_mac_verify_setup </td> |
| 607 | <td>(</td> |
| 608 | <td class="paramtype"><a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> * </td> |
| 609 | <td class="paramname"><em>operation</em>, </td> |
| 610 | </tr> |
| 611 | <tr> |
| 612 | <td class="paramkey"></td> |
| 613 | <td></td> |
| 614 | <td class="paramtype"><a class="el" href="group__platform.html#gabf6d5fd4e2ea89ecd425c88f057e7f75">psa_key_handle_t</a> </td> |
| 615 | <td class="paramname"><em>handle</em>, </td> |
| 616 | </tr> |
| 617 | <tr> |
| 618 | <td class="paramkey"></td> |
| 619 | <td></td> |
| 620 | <td class="paramtype"><a class="el" href="group__crypto__types.html#gac2e4d47f1300d73c2f829a6d99252d69">psa_algorithm_t</a> </td> |
| 621 | <td class="paramname"><em>alg</em> </td> |
| 622 | </tr> |
| 623 | <tr> |
| 624 | <td></td> |
| 625 | <td>)</td> |
| 626 | <td></td><td></td> |
| 627 | </tr> |
| 628 | </table> |
| 629 | </div><div class="memdoc"> |
| 630 | <p>Set up a multipart MAC verification operation.</p> |
| 631 | <p>This function sets up the verification of the MAC (message authentication code) of a byte string against an expected value.</p> |
| 632 | <p>The sequence of operations to verify a MAC is as follows:</p><ol type="1"> |
| 633 | <li>Allocate an operation object which will be passed to all the functions listed here.</li> |
| 634 | <li>Initialize the operation object with one of the methods described in the documentation for <a class="el" href="group__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a>, e.g. PSA_MAC_OPERATION_INIT.</li> |
| 635 | <li>Call <a class="el" href="group__MAC.html#gaa721a59ae6d085ec90c7dc918879a027">psa_mac_verify_setup()</a> to specify the algorithm and key.</li> |
| 636 | <li>Call <a class="el" href="group__MAC.html#ga5560af371497babefe03c9da4e8a1c05">psa_mac_update()</a> zero, one or more times, passing a fragment of the message each time. The MAC that is calculated is the MAC of the concatenation of these messages in order.</li> |
| 637 | <li>At the end of the message, call <a class="el" href="group__MAC.html#gac92b2930d6728e1be4d011c05d485822">psa_mac_verify_finish()</a> to finish calculating the actual MAC of the message and verify it against the expected value.</li> |
| 638 | </ol> |
| 639 | <p>The application may call <a class="el" href="group__MAC.html#gacd8dd54855ba1bc0a03f104f252884fd">psa_mac_abort()</a> at any time after the operation has been initialized.</p> |
| 640 | <p>After a successful call to <a class="el" href="group__MAC.html#gaa721a59ae6d085ec90c7dc918879a027">psa_mac_verify_setup()</a>, the application must eventually terminate the operation through one of the following methods:</p><ul> |
| 641 | <li>A failed call to <a class="el" href="group__MAC.html#ga5560af371497babefe03c9da4e8a1c05">psa_mac_update()</a>.</li> |
| 642 | <li>A call to <a class="el" href="group__MAC.html#gac92b2930d6728e1be4d011c05d485822">psa_mac_verify_finish()</a> or <a class="el" href="group__MAC.html#gacd8dd54855ba1bc0a03f104f252884fd">psa_mac_abort()</a>.</li> |
| 643 | </ul> |
| 644 | <dl class="params"><dt>Parameters</dt><dd> |
| 645 | <table class="params"> |
| 646 | <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__MAC.html#ga78f0838b0c4e3db28b26355624d4bd37">psa_mac_operation_t</a> and not yet in use. </td></tr> |
| 647 | <tr><td class="paramdir"></td><td class="paramname">handle</td><td>Handle to the key to use for the operation. It must remain valid until the operation terminates. </td></tr> |
| 648 | <tr><td class="paramdir"></td><td class="paramname">alg</td><td>The MAC algorithm to compute (<code>PSA_ALG_XXX</code> value such that <a class="el" href="group__crypto__types.html#gaca7aee4c9dde316b3b1a150a26eab776">PSA_ALG_IS_MAC</a>(<code>alg</code>) is true).</td></tr> |
| 649 | </table> |
| 650 | </dd> |
| 651 | </dl> |
| 652 | <dl class="retval"><dt>Return values</dt><dd> |
| 653 | <table class="retval"> |
| 654 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4cc859e2c66ca381c7418db3527a65e1">PSA_SUCCESS</a></td><td>Success. </td></tr> |
| 655 | <tr><td class="paramname"><a class="el" href="group__error.html#gadf22718935657c2c3168c228204085f9">PSA_ERROR_INVALID_HANDLE</a></td><td></td></tr> |
| 656 | <tr><td class="paramname"><a class="el" href="group__error.html#gaba00e3e6ceb2b12965a81e5ac02ae040">PSA_ERROR_EMPTY_SLOT</a></td><td></td></tr> |
| 657 | <tr><td class="paramname"><a class="el" href="group__error.html#ga4d1b8dd8526177a15a210b7afc1accb1">PSA_ERROR_NOT_PERMITTED</a></td><td></td></tr> |
| 658 | <tr><td class="paramname"><a class="el" href="group__error.html#ga798df25a505ebf931f7bec1f80f1f85f">PSA_ERROR_INVALID_ARGUMENT</a></td><td><code>key</code> is not compatible with <code>alg</code>. </td></tr> |
| 659 | <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 MAC algorithm. </td></tr> |
| 660 | <tr><td class="paramname"><a class="el" href="group__error.html#ga91b2ad8a867517a2651f1b076c5216e5">PSA_ERROR_INSUFFICIENT_MEMORY</a></td><td></td></tr> |
| 661 | <tr><td class="paramname"><a class="el" href="group__error.html#ga5cdb6948371d49e916106249020ea3f7">PSA_ERROR_COMMUNICATION_FAILURE</a></td><td></td></tr> |
| 662 | <tr><td class="paramname"><a class="el" href="group__error.html#ga08b10e70fa5ff0b05c631d9f8f6b2c6b">PSA_ERROR_HARDWARE_FAILURE</a></td><td></td></tr> |
| 663 | <tr><td class="paramname"><a class="el" href="group__error.html#ga2c5dda1485cb54f2385cb9c1279a7004">PSA_ERROR_TAMPERING_DETECTED</a></td><td></td></tr> |
| 664 | <tr><td class="paramname"><a class="el" href="group__error.html#ga933d40fa2a591004f2e93aa91e11db84">PSA_ERROR_BAD_STATE</a></td><td>The library has not been previously initialized by <a class="el" href="group__initialization.html#ga2de150803fc2f7dc6101d5af7e921dd9" title="Library initialization. ">psa_crypto_init()</a>. It is implementation-dependent whether a failure to initialize results in this error code. </td></tr> |
| 665 | </table> |
| 666 | </dd> |
| 667 | </dl> |
| 668 | |
| 669 | </div> |
| 670 | </div> |
| 671 | </div><!-- contents --> |
| 672 | <!-- start footer part --> |
| 673 | <hr class="footer"/><address class="footer"><small> |
| 674 | Generated by  <a href="http://www.doxygen.org/index.html"> |
| 675 | <img class="footer" src="doxygen.png" alt="doxygen"/> |
| 676 | </a> 1.8.11 |
| 677 | </small></address> |
| 678 | </body> |
| 679 | </html> |