-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_mini_mouse_cmac_8cpp_source.html
More file actions
104 lines (102 loc) · 38.7 KB
/
Copy path_mini_mouse_cmac_8cpp_source.html
File metadata and controls
104 lines (102 loc) · 38.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!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.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MiniMouse Stack: C:/GITEXT/githubdoc/LoRaWanMiniMouse.github.io/MMstack/MinimouseSrc/MiniMouseCmac.cpp Source File</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>
<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="projectlogo"><img alt="Logo" src="lora.bmp"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">MiniMouse Stack
 <span id="projectnumber">V1.0.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- 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 id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_4479a50ac3338962579017839c6d11ac.html">GITEXT</a></li><li class="navelem"><a class="el" href="dir_313566ed96e2d68b7746be4483e9b217.html">githubdoc</a></li><li class="navelem"><a class="el" href="dir_a1fe12ccd40675146f9c8376113c041e.html">LoRaWanMiniMouse.github.io</a></li><li class="navelem"><a class="el" href="dir_502a2e6a450cda7c1e5931c413e42c70.html">MMstack</a></li><li class="navelem"><a class="el" href="dir_5b21abe8128a6a1751494d478df76c40.html">MinimouseSrc</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">MiniMouseCmac.cpp</div> </div>
</div><!--header-->
<div class="contents">
<a href="_mini_mouse_cmac_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">/**************************************************************************</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">Copyright (C) 2009 Lander Casado, Philippas Tsigas</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment"></span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">All rights reserved.</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment"></span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">Permission is hereby granted, free of charge, to any person obtaining</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">a copy of this software and associated documentation files </span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">(the "Software"), to deal with the Software without restriction, including</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">without limitation the rights to use, copy, modify, merge, publish, </span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">distribute, sublicense, and/or sell copies of the Software, and to</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">permit persons to whom the Software is furnished to do so, subject to</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">the following conditions: </span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment"></span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment">Redistributions of source code must retain the above copyright notice, </span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment">this list of conditions and the following disclaimers. Redistributions in</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment">binary form must reproduce the above copyright notice, this list of</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">conditions and the following disclaimers in the documentation and/or </span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment">other materials provided with the distribution.</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"></span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment">In no event shall the authors or copyright holders be liable for any special,</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment">incidental, indirect or consequential damages of any kind, or any damages </span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="comment">whatsoever resulting from loss of use, data or profits, whether or not </span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="comment">advised of the possibility of damage, and on any theory of liability, </span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="comment">arising out of or in connection with the use or performance of this software.</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="comment"> </span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="comment">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="comment">OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="comment">FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="comment">CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="comment">LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING </span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="comment">FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER </span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="comment">DEALINGS WITH THE SOFTWARE</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="comment"></span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="comment">*****************************************************************************/</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="comment">//#include <sys/param.h></span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="comment">//#include <sys/systm.h> </span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="preprocessor">#include <stdint.h></span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="preprocessor">#include "<a class="code" href="aes_8h.html">aes.h</a>"</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="preprocessor">#include "<a class="code" href="cmac_8h.html">cmac.h</a>"</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="preprocessor">#include "<a class="code" href="utilities_8h.html">utilities.h</a>"</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> </div><div class="line"><a name="l00042"></a><span class="lineno"><a class="line" href="_mini_mouse_cmac_8cpp.html#af9ca930f6a22a67738997972244303e3"> 42</a></span> <span class="preprocessor">#define LSHIFT(v, r) do { \</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span> <span class="preprocessor"> int32_t i; \</span></div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="preprocessor"> for (i = 0; i < 15; i++) \</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> <span class="preprocessor"> (r)[i] = (v)[i] << 1 | (v)[i + 1] >> 7; \</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="preprocessor"> (r)[15] = (v)[15] << 1; \</span></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span> <span class="preprocessor"> } while (0)</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  </div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="_mini_mouse_cmac_8cpp.html#a24a57a540896e74aca18138ed0104e6e"> 49</a></span> <span class="preprocessor">#define XOR(v, r) do { \</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> <span class="preprocessor"> int32_t i; \</span></div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span> <span class="preprocessor"> for (i = 0; i < 16; i++) \</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> <span class="preprocessor"> { \</span></div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span> <span class="preprocessor"> (r)[i] = (r)[i] ^ (v)[i]; \</span></div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span> <span class="preprocessor"> } \</span></div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="preprocessor"> } while (0) \</span></div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span> <span class="preprocessor"></span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> </div><div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="_mini_mouse_cmac_8cpp.html#a0344ba56e27c8029332069892af08737"> 58</a></span> <span class="keywordtype">void</span> <a class="code" href="_mini_mouse_cmac_8cpp.html#a0344ba56e27c8029332069892af08737">AES_CMAC_Init</a>(<a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html">AES_CMAC_CTX</a> *ctx)</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span> {</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <a class="code" href="utilities_8cpp.html#a272ed6d691263d9762c98ed720b1fa3a">memset1</a>(ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>, 0, <span class="keyword">sizeof</span> ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>);</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a> = 0;</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  <a class="code" href="utilities_8cpp.html#a272ed6d691263d9762c98ed720b1fa3a">memset1</a>(ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a111583eab419917697a4ed96963f293c">rijndael</a>.<a class="code" href="structaes__context.html#ab476c78bbf83cabeb637d33c43cc35ee">ksch</a>, <span class="charliteral">'\0'</span>, 240);</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> }</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  </div><div class="line"><a name="l00065"></a><span class="lineno"><a class="line" href="_mini_mouse_cmac_8cpp.html#a0cbe43f8858ba5fbf5bbd5f03e362170"> 65</a></span> <span class="keywordtype">void</span> <a class="code" href="_mini_mouse_cmac_8cpp.html#a0cbe43f8858ba5fbf5bbd5f03e362170">AES_CMAC_SetKey</a>(<a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html">AES_CMAC_CTX</a> *ctx, <span class="keyword">const</span> uint8_t key[<a class="code" href="cmac_8h.html#a8391095f8961b29bdf0818f764d0d66a">AES_CMAC_KEY_LENGTH</a>])</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span> {</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  <span class="comment">//rijndael_set_key_enc_only(&ctx->rijndael, key, 128);</span></div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <a class="code" href="aes_8h.html#a0ffc37ee1bbb50e7147bf6e7de5d73a1">aes_set_key</a>( key, <a class="code" href="cmac_8h.html#a8391095f8961b29bdf0818f764d0d66a">AES_CMAC_KEY_LENGTH</a>, &ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a111583eab419917697a4ed96963f293c">rijndael</a>);</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span> }</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  </div><div class="line"><a name="l00071"></a><span class="lineno"><a class="line" href="_mini_mouse_cmac_8cpp.html#ad1be03bf3df1635dd5cbf8943f4d04f6"> 71</a></span> <span class="keywordtype">void</span> <a class="code" href="_mini_mouse_cmac_8cpp.html#ad1be03bf3df1635dd5cbf8943f4d04f6">AES_CMAC_Update</a>(<a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html">AES_CMAC_CTX</a> *ctx, <span class="keyword">const</span> uint8_t *data, uint32_t len)</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span> {</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  uint32_t mlen;</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  uint8_t in[16];</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  </div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordflow">if</span> (ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a> > 0) {</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  mlen = <a class="code" href="utilities_8h.html#a3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(16 - ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a>, len);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <a class="code" href="utilities_8cpp.html#abfbe672c7136122f16c9214bc4ba8d21">memcpy1</a>(ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">M_last</a> + ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a>, data, mlen);</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a> += mlen;</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  <span class="keywordflow">if</span> (ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a> < 16 || len == mlen)</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <span class="keywordflow">return</span>;</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#a24a57a540896e74aca18138ed0104e6e">XOR</a>(ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">M_last</a>, ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>);</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  <span class="comment">//rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);</span></div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  <a class="code" href="aes_8h.html#ac88fd4e9cb53f78713a8fce1a6fcffc0">aes_encrypt</a>( ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>, ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>, &ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a111583eab419917697a4ed96963f293c">rijndael</a>);</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  data += mlen;</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  len -= mlen;</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  }</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <span class="keywordflow">while</span> (len > 16) { <span class="comment">/* not last block */</span></div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span> </div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#a24a57a540896e74aca18138ed0104e6e">XOR</a>(data, ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>);</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  <span class="comment">//rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);</span></div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span> </div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <a class="code" href="utilities_8cpp.html#abfbe672c7136122f16c9214bc4ba8d21">memcpy1</a>(in, &ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>[0], 16); <span class="comment">//Bestela ez du ondo iten</span></div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <a class="code" href="aes_8h.html#ac88fd4e9cb53f78713a8fce1a6fcffc0">aes_encrypt</a>( in, in, &ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a111583eab419917697a4ed96963f293c">rijndael</a>);</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <a class="code" href="utilities_8cpp.html#abfbe672c7136122f16c9214bc4ba8d21">memcpy1</a>(&ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>[0], in, 16);</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span> </div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  data += 16;</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  len -= 16;</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  }</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="comment">/* potential last block, save it */</span></div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <a class="code" href="utilities_8cpp.html#abfbe672c7136122f16c9214bc4ba8d21">memcpy1</a>(ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">M_last</a>, data, len);</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a> = len;</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span> }</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  </div><div class="line"><a name="l00105"></a><span class="lineno"><a class="line" href="_mini_mouse_cmac_8cpp.html#a8ea4da33d50984199d8a91bc0ab86b15"> 105</a></span> <span class="keywordtype">void</span> <a class="code" href="_mini_mouse_cmac_8cpp.html#a8ea4da33d50984199d8a91bc0ab86b15">AES_CMAC_Final</a>(uint8_t digest[<a class="code" href="cmac_8h.html#a9d43ce8be9e275dc33b7992c5cf6623f">AES_CMAC_DIGEST_LENGTH</a>], <a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html">AES_CMAC_CTX</a> *ctx)</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span> {</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  uint8_t K[16];</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  uint8_t in[16];</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="comment">/* generate subkey K1 */</span></div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <a class="code" href="utilities_8cpp.html#a272ed6d691263d9762c98ed720b1fa3a">memset1</a>(K, <span class="charliteral">'\0'</span>, 16);</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span> </div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  <span class="comment">//rijndael_encrypt(&ctx->rijndael, K, K);</span></div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span> </div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <a class="code" href="aes_8h.html#ac88fd4e9cb53f78713a8fce1a6fcffc0">aes_encrypt</a>( K, K, &ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a111583eab419917697a4ed96963f293c">rijndael</a>);</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span> </div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <span class="keywordflow">if</span> (K[0] & 0x80) {</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#af9ca930f6a22a67738997972244303e3">LSHIFT</a>(K, K);</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  K[15] ^= 0x87;</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  } <span class="keywordflow">else</span></div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#af9ca930f6a22a67738997972244303e3">LSHIFT</a>(K, K);</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span> </div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span> </div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  <span class="keywordflow">if</span> (ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a> == 16) {</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  <span class="comment">/* last block was a complete block */</span></div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#a24a57a540896e74aca18138ed0104e6e">XOR</a>(K, ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">M_last</a>);</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> </div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  <span class="comment">/* generate subkey K2 */</span></div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  <span class="keywordflow">if</span> (K[0] & 0x80) {</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#af9ca930f6a22a67738997972244303e3">LSHIFT</a>(K, K);</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  K[15] ^= 0x87;</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  } <span class="keywordflow">else</span></div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#af9ca930f6a22a67738997972244303e3">LSHIFT</a>(K, K);</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> </div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="comment">/* padding(M_last) */</span></div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">M_last</a>[ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a>] = 0x80;</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  <span class="keywordflow">while</span> (++ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a> < 16)</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">M_last</a>[ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">M_n</a>] = 0;</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  </div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#a24a57a540896e74aca18138ed0104e6e">XOR</a>(K, ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">M_last</a>);</div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span> </div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span> </div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  }</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  <a class="code" href="_mini_mouse_cmac_8cpp.html#a24a57a540896e74aca18138ed0104e6e">XOR</a>(ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">M_last</a>, ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>);</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span> </div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  <span class="comment">//rijndael_encrypt(&ctx->rijndael, ctx->X, digest);</span></div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span> </div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  <a class="code" href="utilities_8cpp.html#abfbe672c7136122f16c9214bc4ba8d21">memcpy1</a>(in, &ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">X</a>[0], 16); <span class="comment">//Bestela ez du ondo iten</span></div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <a class="code" href="aes_8h.html#ac88fd4e9cb53f78713a8fce1a6fcffc0">aes_encrypt</a>(in, digest, &ctx-><a class="code" href="struct___a_e_s___c_m_a_c___c_t_x.html#a111583eab419917697a4ed96963f293c">rijndael</a>);</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  <a class="code" href="utilities_8cpp.html#a272ed6d691263d9762c98ed720b1fa3a">memset1</a>(K, 0, <span class="keyword">sizeof</span> K);</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span> </div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span> }</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span> </div><div class="ttc" id="cmac_8h_html_a9d43ce8be9e275dc33b7992c5cf6623f"><div class="ttname"><a href="cmac_8h.html#a9d43ce8be9e275dc33b7992c5cf6623f">AES_CMAC_DIGEST_LENGTH</a></div><div class="ttdeci">#define AES_CMAC_DIGEST_LENGTH</div><div class="ttdef"><b>Definition:</b> <a href="cmac_8h_source.html#l00042">cmac.h:42</a></div></div>
<div class="ttc" id="structaes__context_html_ab476c78bbf83cabeb637d33c43cc35ee"><div class="ttname"><a href="structaes__context.html#ab476c78bbf83cabeb637d33c43cc35ee">aes_context::ksch</a></div><div class="ttdeci">uint8_t ksch[(N_MAX_ROUNDS+1) *N_BLOCK]</div><div class="ttdef"><b>Definition:</b> <a href="aes_8h_source.html#l00070">aes.h:70</a></div></div>
<div class="ttc" id="struct___a_e_s___c_m_a_c___c_t_x_html_a2c48607df1e9c1847d3e4ff11612124b"><div class="ttname"><a href="struct___a_e_s___c_m_a_c___c_t_x.html#a2c48607df1e9c1847d3e4ff11612124b">_AES_CMAC_CTX::M_n</a></div><div class="ttdeci">uint32_t M_n</div><div class="ttdef"><b>Definition:</b> <a href="cmac_8h_source.html#l00048">cmac.h:48</a></div></div>
<div class="ttc" id="utilities_8h_html"><div class="ttname"><a href="utilities_8h.html">utilities.h</a></div></div>
<div class="ttc" id="_mini_mouse_cmac_8cpp_html_ad1be03bf3df1635dd5cbf8943f4d04f6"><div class="ttname"><a href="_mini_mouse_cmac_8cpp.html#ad1be03bf3df1635dd5cbf8943f4d04f6">AES_CMAC_Update</a></div><div class="ttdeci">void AES_CMAC_Update(AES_CMAC_CTX *ctx, const uint8_t *data, uint32_t len)</div><div class="ttdef"><b>Definition:</b> <a href="_mini_mouse_cmac_8cpp_source.html#l00071">MiniMouseCmac.cpp:71</a></div></div>
<div class="ttc" id="struct___a_e_s___c_m_a_c___c_t_x_html_a111583eab419917697a4ed96963f293c"><div class="ttname"><a href="struct___a_e_s___c_m_a_c___c_t_x.html#a111583eab419917697a4ed96963f293c">_AES_CMAC_CTX::rijndael</a></div><div class="ttdeci">aes_context rijndael</div><div class="ttdef"><b>Definition:</b> <a href="cmac_8h_source.html#l00045">cmac.h:45</a></div></div>
<div class="ttc" id="cmac_8h_html"><div class="ttname"><a href="cmac_8h.html">cmac.h</a></div></div>
<div class="ttc" id="aes_8h_html_ac88fd4e9cb53f78713a8fce1a6fcffc0"><div class="ttname"><a href="aes_8h.html#ac88fd4e9cb53f78713a8fce1a6fcffc0">aes_encrypt</a></div><div class="ttdeci">return_type aes_encrypt(const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK], const aes_context ctx[1])</div><div class="ttdef"><b>Definition:</b> <a href="_mini_mouse_aes_8cpp_source.html#l00568">MiniMouseAes.cpp:568</a></div></div>
<div class="ttc" id="struct___a_e_s___c_m_a_c___c_t_x_html_ac2ab3afeba7a78b17fe98404b15c4ad0"><div class="ttname"><a href="struct___a_e_s___c_m_a_c___c_t_x.html#ac2ab3afeba7a78b17fe98404b15c4ad0">_AES_CMAC_CTX::M_last</a></div><div class="ttdeci">uint8_t M_last[16]</div><div class="ttdef"><b>Definition:</b> <a href="cmac_8h_source.html#l00047">cmac.h:47</a></div></div>
<div class="ttc" id="utilities_8h_html_a3acffbd305ee72dcd4593c0d8af64a4f"><div class="ttname"><a href="utilities_8h.html#a3acffbd305ee72dcd4593c0d8af64a4f">MIN</a></div><div class="ttdeci">#define MIN(a, b)</div><div class="ttdoc">Returns the minimum value between a and b. </div><div class="ttdef"><b>Definition:</b> <a href="utilities_8h_source.html#l00033">utilities.h:33</a></div></div>
<div class="ttc" id="_mini_mouse_cmac_8cpp_html_a24a57a540896e74aca18138ed0104e6e"><div class="ttname"><a href="_mini_mouse_cmac_8cpp.html#a24a57a540896e74aca18138ed0104e6e">XOR</a></div><div class="ttdeci">#define XOR(v, r)</div><div class="ttdef"><b>Definition:</b> <a href="_mini_mouse_cmac_8cpp_source.html#l00049">MiniMouseCmac.cpp:49</a></div></div>
<div class="ttc" id="_mini_mouse_cmac_8cpp_html_a0344ba56e27c8029332069892af08737"><div class="ttname"><a href="_mini_mouse_cmac_8cpp.html#a0344ba56e27c8029332069892af08737">AES_CMAC_Init</a></div><div class="ttdeci">void AES_CMAC_Init(AES_CMAC_CTX *ctx)</div><div class="ttdef"><b>Definition:</b> <a href="_mini_mouse_cmac_8cpp_source.html#l00058">MiniMouseCmac.cpp:58</a></div></div>
<div class="ttc" id="aes_8h_html"><div class="ttname"><a href="aes_8h.html">aes.h</a></div></div>
<div class="ttc" id="_mini_mouse_cmac_8cpp_html_af9ca930f6a22a67738997972244303e3"><div class="ttname"><a href="_mini_mouse_cmac_8cpp.html#af9ca930f6a22a67738997972244303e3">LSHIFT</a></div><div class="ttdeci">#define LSHIFT(v, r)</div><div class="ttdef"><b>Definition:</b> <a href="_mini_mouse_cmac_8cpp_source.html#l00042">MiniMouseCmac.cpp:42</a></div></div>
<div class="ttc" id="_mini_mouse_cmac_8cpp_html_a0cbe43f8858ba5fbf5bbd5f03e362170"><div class="ttname"><a href="_mini_mouse_cmac_8cpp.html#a0cbe43f8858ba5fbf5bbd5f03e362170">AES_CMAC_SetKey</a></div><div class="ttdeci">void AES_CMAC_SetKey(AES_CMAC_CTX *ctx, const uint8_t key[AES_CMAC_KEY_LENGTH])</div><div class="ttdef"><b>Definition:</b> <a href="_mini_mouse_cmac_8cpp_source.html#l00065">MiniMouseCmac.cpp:65</a></div></div>
<div class="ttc" id="struct___a_e_s___c_m_a_c___c_t_x_html_a3be115a420dc4da7db29666a2ca6d850"><div class="ttname"><a href="struct___a_e_s___c_m_a_c___c_t_x.html#a3be115a420dc4da7db29666a2ca6d850">_AES_CMAC_CTX::X</a></div><div class="ttdeci">uint8_t X[16]</div><div class="ttdef"><b>Definition:</b> <a href="cmac_8h_source.html#l00046">cmac.h:46</a></div></div>
<div class="ttc" id="cmac_8h_html_a8391095f8961b29bdf0818f764d0d66a"><div class="ttname"><a href="cmac_8h.html#a8391095f8961b29bdf0818f764d0d66a">AES_CMAC_KEY_LENGTH</a></div><div class="ttdeci">#define AES_CMAC_KEY_LENGTH</div><div class="ttdef"><b>Definition:</b> <a href="cmac_8h_source.html#l00041">cmac.h:41</a></div></div>
<div class="ttc" id="struct___a_e_s___c_m_a_c___c_t_x_html"><div class="ttname"><a href="struct___a_e_s___c_m_a_c___c_t_x.html">_AES_CMAC_CTX</a></div><div class="ttdef"><b>Definition:</b> <a href="cmac_8h_source.html#l00044">cmac.h:44</a></div></div>
<div class="ttc" id="utilities_8cpp_html_a272ed6d691263d9762c98ed720b1fa3a"><div class="ttname"><a href="utilities_8cpp.html#a272ed6d691263d9762c98ed720b1fa3a">memset1</a></div><div class="ttdeci">void memset1(uint8_t *dst, uint8_t value, uint16_t size)</div><div class="ttdoc">Set size elements of dst array with value. </div><div class="ttdef"><b>Definition:</b> <a href="utilities_8cpp_source.html#l00063">utilities.cpp:63</a></div></div>
<div class="ttc" id="_mini_mouse_cmac_8cpp_html_a8ea4da33d50984199d8a91bc0ab86b15"><div class="ttname"><a href="_mini_mouse_cmac_8cpp.html#a8ea4da33d50984199d8a91bc0ab86b15">AES_CMAC_Final</a></div><div class="ttdeci">void AES_CMAC_Final(uint8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX *ctx)</div><div class="ttdef"><b>Definition:</b> <a href="_mini_mouse_cmac_8cpp_source.html#l00105">MiniMouseCmac.cpp:105</a></div></div>
<div class="ttc" id="utilities_8cpp_html_abfbe672c7136122f16c9214bc4ba8d21"><div class="ttname"><a href="utilities_8cpp.html#abfbe672c7136122f16c9214bc4ba8d21">memcpy1</a></div><div class="ttdeci">void memcpy1(uint8_t *dst, const uint8_t *src, uint16_t size)</div><div class="ttdoc">Copies size elements of src array to dst array. </div><div class="ttdef"><b>Definition:</b> <a href="utilities_8cpp_source.html#l00046">utilities.cpp:46</a></div></div>
<div class="ttc" id="aes_8h_html_a0ffc37ee1bbb50e7147bf6e7de5d73a1"><div class="ttname"><a href="aes_8h.html#a0ffc37ee1bbb50e7147bf6e7de5d73a1">aes_set_key</a></div><div class="ttdeci">return_type aes_set_key(const uint8_t key[], length_type keylen, aes_context ctx[1])</div><div class="ttdef"><b>Definition:</b> <a href="_mini_mouse_aes_8cpp_source.html#l00513">MiniMouseAes.cpp:513</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>