Files
libaaruformat/docs/html/ps3__crypto_8c_source.html

268 lines
36 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.16.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libaaruformat: src/ps3/ps3_crypto.c 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>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="cookie.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 id="projectrow">
<td id="projectalign">
<div id="projectname">libaaruformat<span id="projectnumber">&#160;1.0</span>
</div>
<div id="projectbrief">Aaru Data Preservation Suite - Format Library</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.16.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(); });
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search',true);
$(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(function(){initNavTree('ps3__crypto_8c_source.html','',''); });
</script>
<div id="container">
<div id="doc-content">
<!-- 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">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">ps3_crypto.c</div></div>
</div><!--header-->
<div class="contents">
<a href="ps3__crypto_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span><span class="comment">/*</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno"> 2</span><span class="comment"> * This file is part of the Aaru Data Preservation Suite.</span></div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno"> 3</span><span class="comment"> * Copyright (c) 2019-2026 Natalia Portillo.</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno"> 4</span><span class="comment"> *</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno"> 5</span><span class="comment"> * This library is free software; you can redistribute it and/or modify</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"> 6</span><span class="comment"> * it under the terms of the GNU Lesser General Public License as</span></div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"> 7</span><span class="comment"> * published by the Free Software Foundation; version 2.1 of the License.</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"> 8</span><span class="comment"> *</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"> 9</span><span class="comment"> * This library is distributed in the hope that it will be useful, but</span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span><span class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span><span class="comment"> * Lesser General Public License for more details.</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="comment"> *</span></div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="comment"> * You should have received a copy of the GNU Lesser General Public</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="comment"> * License along with this library; if not, see</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="comment"> * &lt;https://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="comment"> *</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span><span class="comment"> * PS3 disc encryption: key derivation, sector encrypt/decrypt, IV derivation.</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span><span class="comment"> */</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span> </div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span><span class="preprocessor">#include &lt;stdint.h&gt;</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span><span class="preprocessor">#include &lt;string.h&gt;</span></div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> </div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span><span class="preprocessor">#include &lt;<a class="code" href="aaruformat_8h.html">aaruformat.h</a>&gt;</span></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> </div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span><span class="preprocessor">#include &quot;<a class="code" href="aes128_8h.html">../lib/aes128.h</a>&quot;</span></div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span><span class="preprocessor">#include &quot;<a class="code" href="ps3__crypto_8h.html">ps3_crypto.h</a>&quot;</span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span><span class="preprocessor">#include &quot;<a class="code" href="ps3__encryption__map_8h.html">ps3_encryption_map.h</a>&quot;</span></div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> </div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span><span class="comment">/* PS3 Encryption Round Key — publicly known constant */</span></div>
<div class="foldopen" id="foldopen00032" data-start="{" data-end="};">
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"><a class="line" href="ps3__crypto_8c.html#acc35345c5e7216dd7b459a5214c560a9"> 32</a></span><span class="keyword">static</span> <span class="keyword">const</span> uint8_t <a class="code hl_variable" href="ps3__crypto_8c.html#acc35345c5e7216dd7b459a5214c560a9">PS3_ERK</a>[16] = {0x38, 0x0B, 0xCF, 0x0B, 0x53, 0x45, 0x5B, 0x3C,</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> 0x78, 0x17, 0xAB, 0x4F, 0xA3, 0xBA, 0x90, 0xED};</div>
</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> </div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span><span class="comment">/* PS3 ERK IV — publicly known constant */</span></div>
<div class="foldopen" id="foldopen00036" data-start="{" data-end="};">
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"><a class="line" href="ps3__crypto_8c.html#a1cb0bb57269e771ed42f5619ce222864"> 36</a></span><span class="keyword">static</span> <span class="keyword">const</span> uint8_t <a class="code hl_variable" href="ps3__crypto_8c.html#a1cb0bb57269e771ed42f5619ce222864">PS3_ERK_IV</a>[16] = {0x69, 0x47, 0x47, 0x72, 0xAF, 0x6F, 0xDA, 0xB3,</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> 0x42, 0x74, 0x3A, 0xEF, 0xAA, 0x18, 0x62, 0x87};</div>
</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> </div>
<div class="foldopen" id="foldopen00039" data-start="{" data-end="}">
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"><a class="line" href="ps3__crypto_8c.html#a8ee401b8bd7370fef44a5cfdcf361ee6"> 39</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="ps3__crypto_8c.html#a8ee401b8bd7370fef44a5cfdcf361ee6">ps3_derive_disc_key</a>(<span class="keyword">const</span> uint8_t data1[16], uint8_t disc_key[16])</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span>{</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> memcpy(disc_key, data1, 16);</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> <a class="code hl_function" href="aes128_8c.html#ae5b59a027bc443c26cc5626455d77eb9">aes128_cbc_encrypt</a>(<a class="code hl_variable" href="ps3__crypto_8c.html#acc35345c5e7216dd7b459a5214c560a9">PS3_ERK</a>, <a class="code hl_variable" href="ps3__crypto_8c.html#a1cb0bb57269e771ed42f5619ce222864">PS3_ERK_IV</a>, disc_key, 16);</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span>}</div>
</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> </div>
<div class="foldopen" id="foldopen00045" data-start="{" data-end="}">
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"><a class="line" href="ps3__crypto_8c.html#a9c59bc8ce8ecd8457a8eb62287b09915"> 45</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="ps3__crypto_8c.html#a9c59bc8ce8ecd8457a8eb62287b09915">ps3_derive_iv</a>(uint64_t sector_num, uint8_t iv[16])</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span>{</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> memset(iv, 0, 16);</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> </div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 15; i &gt;= 0 &amp;&amp; sector_num &gt; 0; i--)</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> {</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span> iv[i] = (uint8_t)(sector_num &amp; 0xFF);</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> sector_num &gt;&gt;= 8;</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> }</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span>}</div>
</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> </div>
<div class="foldopen" id="foldopen00056" data-start="{" data-end="}">
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"><a class="line" href="ps3__crypto_8c.html#af9a3081e827ba140edc64fda2e93ee96"> 56</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="ps3__crypto_8c.html#af9a3081e827ba140edc64fda2e93ee96">ps3_encrypt_sector</a>(<span class="keyword">const</span> uint8_t disc_key[16], uint64_t sector_num, uint8_t *data, uint32_t length)</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span>{</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> uint8_t iv[16];</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> <a class="code hl_function" href="ps3__crypto_8c.html#a9c59bc8ce8ecd8457a8eb62287b09915">ps3_derive_iv</a>(sector_num, iv);</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <a class="code hl_function" href="aes128_8c.html#ae5b59a027bc443c26cc5626455d77eb9">aes128_cbc_encrypt</a>(disc_key, iv, data, length);</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span>}</div>
</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> </div>
<div class="foldopen" id="foldopen00063" data-start="{" data-end="}">
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"><a class="line" href="ps3__crypto_8c.html#af7ff1fb41dd6ad9c3449d7c48bc5a462"> 63</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="ps3__crypto_8c.html#af7ff1fb41dd6ad9c3449d7c48bc5a462">ps3_decrypt_sector</a>(<span class="keyword">const</span> uint8_t disc_key[16], uint64_t sector_num, uint8_t *data, uint32_t length)</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span>{</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> uint8_t iv[16];</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <a class="code hl_function" href="ps3__crypto_8c.html#a9c59bc8ce8ecd8457a8eb62287b09915">ps3_derive_iv</a>(sector_num, iv);</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> <a class="code hl_function" href="aes128_8c.html#a86c652b61efa48d45729e9eea1bab8b1">aes128_cbc_decrypt</a>(disc_key, iv, data, length);</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span>}</div>
</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> </div>
<div class="foldopen" id="foldopen00070" data-start="{" data-end="}">
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"><a class="line" href="ps3__crypto_8c.html#a8c99822e07011d07362d5d40487eded6"> 70</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="ps3__crypto_8c.html#a8c99822e07011d07362d5d40487eded6">ps3_lazy_init</a>(<a class="code hl_struct" href="structaaruformat__context.html">aaruformat_context</a> *ctx)</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span>{</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> <span class="keywordflow">if</span>(ctx == NULL) <span class="keywordflow">return</span>;</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> </div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> <span class="comment">/* Read disc key from media tags */</span></div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> <span class="keywordflow">if</span>(ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a016a2c15a10105ff17628c9ee7f5c424">ps3_disc_key</a> == NULL)</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> {</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> <a class="code hl_struct" href="structmediaTagEntry.html">mediaTagEntry</a> *item = NULL;</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> int32_t tag = <a class="code hl_enumvalue" href="group__MediaTags.html#ggabdd09c559df8f34ae68fcb2ff1892ebea3484025e0fcd8a29a5c86b04c02488dc">kMediaTagPs3DiscKey</a>;</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> HASH_FIND_INT(ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a8b769e9fb9467aa11d4a2936cf5cf5ed">mediaTags</a>, &amp;tag, item);</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> </div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> <span class="keywordflow">if</span>(item != NULL &amp;&amp; item-&gt;<a class="code hl_variable" href="structmediaTagEntry.html#aa96c6684fd98145d0089d72957d2afa7">length</a> == 16)</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> {</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a016a2c15a10105ff17628c9ee7f5c424">ps3_disc_key</a> = (uint8_t *)malloc(16);</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> </div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <span class="keywordflow">if</span>(ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a016a2c15a10105ff17628c9ee7f5c424">ps3_disc_key</a> != NULL) memcpy(ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a016a2c15a10105ff17628c9ee7f5c424">ps3_disc_key</a>, item-&gt;<a class="code hl_variable" href="structmediaTagEntry.html#a334fc65b37efdfb624e804e98c398927">data</a>, 16);</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> }</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> <span class="keywordflow">else</span></div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> {</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> <span class="comment">/* Try deriving from data1 */</span></div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> tag = <a class="code hl_enumvalue" href="group__MediaTags.html#ggabdd09c559df8f34ae68fcb2ff1892ebea829647f60fd9e3636b195750ee1d032b">kMediaTagPs3Data1</a>;</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> HASH_FIND_INT(ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a8b769e9fb9467aa11d4a2936cf5cf5ed">mediaTags</a>, &amp;tag, item);</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> </div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> <span class="keywordflow">if</span>(item != NULL &amp;&amp; item-&gt;<a class="code hl_variable" href="structmediaTagEntry.html#aa96c6684fd98145d0089d72957d2afa7">length</a> == 16)</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> {</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a016a2c15a10105ff17628c9ee7f5c424">ps3_disc_key</a> = (uint8_t *)malloc(16);</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> </div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> <span class="keywordflow">if</span>(ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a016a2c15a10105ff17628c9ee7f5c424">ps3_disc_key</a> != NULL) <a class="code hl_function" href="ps3__crypto_8c.html#a8ee401b8bd7370fef44a5cfdcf361ee6">ps3_derive_disc_key</a>(item-&gt;<a class="code hl_variable" href="structmediaTagEntry.html#a334fc65b37efdfb624e804e98c398927">data</a>, ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a016a2c15a10105ff17628c9ee7f5c424">ps3_disc_key</a>);</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> }</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> }</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> }</div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> </div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> <span class="comment">/* Read and deserialize encryption map from media tags */</span></div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> <span class="keywordflow">if</span>(ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#acf62eadb2e019323fdbe8bbf536ad82c">ps3_plaintext_regions</a> == NULL)</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> {</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> <a class="code hl_struct" href="structmediaTagEntry.html">mediaTagEntry</a> *item = NULL;</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> int32_t tag = <a class="code hl_enumvalue" href="group__MediaTags.html#ggabdd09c559df8f34ae68fcb2ff1892ebea5affd41305575bf9f71ace8d93787713">kMediaTagPs3EncryptionMap</a>;</div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> HASH_FIND_INT(ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a8b769e9fb9467aa11d4a2936cf5cf5ed">mediaTags</a>, &amp;tag, item);</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> </div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> <span class="keywordflow">if</span>(item != NULL &amp;&amp; item-&gt;<a class="code hl_variable" href="structmediaTagEntry.html#aa96c6684fd98145d0089d72957d2afa7">length</a> &gt;= 4)</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> {</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> <a class="code hl_struct" href="structPs3PlaintextRegion.html">Ps3PlaintextRegion</a> *regions = NULL;</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> uint32_t count = 0;</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> </div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> <span class="keywordflow">if</span>(<a class="code hl_function" href="ps3__encryption__map_8c.html#a49a5e6c2b524988714513c446e2d200d">ps3_deserialize_encryption_map</a>(item-&gt;<a class="code hl_variable" href="structmediaTagEntry.html#a334fc65b37efdfb624e804e98c398927">data</a>, item-&gt;<a class="code hl_variable" href="structmediaTagEntry.html#aa96c6684fd98145d0089d72957d2afa7">length</a>, &amp;regions, &amp;count) == 0)</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> {</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#acf62eadb2e019323fdbe8bbf536ad82c">ps3_plaintext_regions</a> = regions;</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> ctx-&gt;<a class="code hl_variable" href="structaaruformat__context.html#a1bfda8e3b76471a7b526d05f4855f8f1">ps3_plaintext_region_count</a> = count;</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> }</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> }</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> }</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span>}</div>
</div>
<div class="ttc" id="aaaruformat_8h_html"><div class="ttname"><a href="aaruformat_8h.html">aaruformat.h</a></div></div>
<div class="ttc" id="aaes128_8c_html_a86c652b61efa48d45729e9eea1bab8b1"><div class="ttname"><a href="aes128_8c.html#a86c652b61efa48d45729e9eea1bab8b1">aes128_cbc_decrypt</a></div><div class="ttdeci">void aes128_cbc_decrypt(const uint8_t key[16], const uint8_t iv[16], uint8_t *data, uint32_t length)</div><div class="ttdoc">AES-128 CBC decrypt data in-place.</div><div class="ttdef"><b>Definition</b> <a href="aes128_8c_source.html#l00290">aes128.c:290</a></div></div>
<div class="ttc" id="aaes128_8c_html_ae5b59a027bc443c26cc5626455d77eb9"><div class="ttname"><a href="aes128_8c.html#ae5b59a027bc443c26cc5626455d77eb9">aes128_cbc_encrypt</a></div><div class="ttdeci">void aes128_cbc_encrypt(const uint8_t key[16], const uint8_t iv[16], uint8_t *data, uint32_t length)</div><div class="ttdoc">AES-128 CBC encrypt data in-place.</div><div class="ttdef"><b>Definition</b> <a href="aes128_8c_source.html#l00274">aes128.c:274</a></div></div>
<div class="ttc" id="aaes128_8h_html"><div class="ttname"><a href="aes128_8h.html">aes128.h</a></div></div>
<div class="ttc" id="agroup__MediaTags_html_ggabdd09c559df8f34ae68fcb2ff1892ebea3484025e0fcd8a29a5c86b04c02488dc"><div class="ttname"><a href="group__MediaTags.html#ggabdd09c559df8f34ae68fcb2ff1892ebea3484025e0fcd8a29a5c86b04c02488dc">kMediaTagPs3DiscKey</a></div><div class="ttdeci">@ kMediaTagPs3DiscKey</div><div class="ttdoc">PS3 derived disc key (16 bytes).</div><div class="ttdef"><b>Definition</b> <a href="aaru_8h_source.html#l01080">aaru.h:1080</a></div></div>
<div class="ttc" id="agroup__MediaTags_html_ggabdd09c559df8f34ae68fcb2ff1892ebea5affd41305575bf9f71ace8d93787713"><div class="ttname"><a href="group__MediaTags.html#ggabdd09c559df8f34ae68fcb2ff1892ebea5affd41305575bf9f71ace8d93787713">kMediaTagPs3EncryptionMap</a></div><div class="ttdeci">@ kMediaTagPs3EncryptionMap</div><div class="ttdoc">PS3 encryption region map (serialized from sector 0).</div><div class="ttdef"><b>Definition</b> <a href="aaru_8h_source.html#l01084">aaru.h:1084</a></div></div>
<div class="ttc" id="agroup__MediaTags_html_ggabdd09c559df8f34ae68fcb2ff1892ebea829647f60fd9e3636b195750ee1d032b"><div class="ttname"><a href="group__MediaTags.html#ggabdd09c559df8f34ae68fcb2ff1892ebea829647f60fd9e3636b195750ee1d032b">kMediaTagPs3Data1</a></div><div class="ttdeci">@ kMediaTagPs3Data1</div><div class="ttdoc">PS3 data1 key (16 bytes, from disc).</div><div class="ttdef"><b>Definition</b> <a href="aaru_8h_source.html#l01081">aaru.h:1081</a></div></div>
<div class="ttc" id="aps3__crypto_8c_html_a1cb0bb57269e771ed42f5619ce222864"><div class="ttname"><a href="ps3__crypto_8c.html#a1cb0bb57269e771ed42f5619ce222864">PS3_ERK_IV</a></div><div class="ttdeci">static const uint8_t PS3_ERK_IV[16]</div><div class="ttdef"><b>Definition</b> <a href="#l00036">ps3_crypto.c:36</a></div></div>
<div class="ttc" id="aps3__crypto_8c_html_a8c99822e07011d07362d5d40487eded6"><div class="ttname"><a href="ps3__crypto_8c.html#a8c99822e07011d07362d5d40487eded6">ps3_lazy_init</a></div><div class="ttdeci">void ps3_lazy_init(aaruformat_context *ctx)</div><div class="ttdoc">Lazy-initialize PS3 encryption state from context media tags.</div><div class="ttdef"><b>Definition</b> <a href="#l00070">ps3_crypto.c:70</a></div></div>
<div class="ttc" id="aps3__crypto_8c_html_a8ee401b8bd7370fef44a5cfdcf361ee6"><div class="ttname"><a href="ps3__crypto_8c.html#a8ee401b8bd7370fef44a5cfdcf361ee6">ps3_derive_disc_key</a></div><div class="ttdeci">void ps3_derive_disc_key(const uint8_t data1[16], uint8_t disc_key[16])</div><div class="ttdoc">Derive a PS3 disc key from a data1 key.</div><div class="ttdef"><b>Definition</b> <a href="#l00039">ps3_crypto.c:39</a></div></div>
<div class="ttc" id="aps3__crypto_8c_html_a9c59bc8ce8ecd8457a8eb62287b09915"><div class="ttname"><a href="ps3__crypto_8c.html#a9c59bc8ce8ecd8457a8eb62287b09915">ps3_derive_iv</a></div><div class="ttdeci">void ps3_derive_iv(uint64_t sector_num, uint8_t iv[16])</div><div class="ttdoc">Derive the per-sector AES IV from a sector number.</div><div class="ttdef"><b>Definition</b> <a href="#l00045">ps3_crypto.c:45</a></div></div>
<div class="ttc" id="aps3__crypto_8c_html_acc35345c5e7216dd7b459a5214c560a9"><div class="ttname"><a href="ps3__crypto_8c.html#acc35345c5e7216dd7b459a5214c560a9">PS3_ERK</a></div><div class="ttdeci">static const uint8_t PS3_ERK[16]</div><div class="ttdef"><b>Definition</b> <a href="#l00032">ps3_crypto.c:32</a></div></div>
<div class="ttc" id="aps3__crypto_8c_html_af7ff1fb41dd6ad9c3449d7c48bc5a462"><div class="ttname"><a href="ps3__crypto_8c.html#af7ff1fb41dd6ad9c3449d7c48bc5a462">ps3_decrypt_sector</a></div><div class="ttdeci">void ps3_decrypt_sector(const uint8_t disc_key[16], uint64_t sector_num, uint8_t *data, uint32_t length)</div><div class="ttdoc">Decrypt a sector using PS3 disc encryption (AES-128-CBC).</div><div class="ttdef"><b>Definition</b> <a href="#l00063">ps3_crypto.c:63</a></div></div>
<div class="ttc" id="aps3__crypto_8c_html_af9a3081e827ba140edc64fda2e93ee96"><div class="ttname"><a href="ps3__crypto_8c.html#af9a3081e827ba140edc64fda2e93ee96">ps3_encrypt_sector</a></div><div class="ttdeci">void ps3_encrypt_sector(const uint8_t disc_key[16], uint64_t sector_num, uint8_t *data, uint32_t length)</div><div class="ttdoc">Encrypt a sector using PS3 disc encryption (AES-128-CBC).</div><div class="ttdef"><b>Definition</b> <a href="#l00056">ps3_crypto.c:56</a></div></div>
<div class="ttc" id="aps3__crypto_8h_html"><div class="ttname"><a href="ps3__crypto_8h.html">ps3_crypto.h</a></div></div>
<div class="ttc" id="aps3__encryption__map_8c_html_a49a5e6c2b524988714513c446e2d200d"><div class="ttname"><a href="ps3__encryption__map_8c.html#a49a5e6c2b524988714513c446e2d200d">ps3_deserialize_encryption_map</a></div><div class="ttdeci">int32_t ps3_deserialize_encryption_map(const uint8_t *data, uint32_t length, Ps3PlaintextRegion **regions, uint32_t *count)</div><div class="ttdoc">Deserialize plaintext regions from little-endian binary (media tag format).</div><div class="ttdef"><b>Definition</b> <a href="ps3__encryption__map_8c_source.html#l00117">ps3_encryption_map.c:117</a></div></div>
<div class="ttc" id="aps3__encryption__map_8h_html"><div class="ttname"><a href="ps3__encryption__map_8h.html">ps3_encryption_map.h</a></div></div>
<div class="ttc" id="astructPs3PlaintextRegion_html"><div class="ttname"><a href="structPs3PlaintextRegion.html">Ps3PlaintextRegion</a></div><div class="ttdoc">A plaintext (unencrypted) region on a PS3 disc.</div><div class="ttdef"><b>Definition</b> <a href="ps3__encryption__map_8h_source.html#l00033">ps3_encryption_map.h:34</a></div></div>
<div class="ttc" id="astructaaruformat__context_html"><div class="ttname"><a href="structaaruformat__context.html">aaruformat_context</a></div><div class="ttdoc">Master context representing an open or increation Aaru image.</div><div class="ttdef"><b>Definition</b> <a href="context_8h_source.html#l00174">context.h:175</a></div></div>
<div class="ttc" id="astructaaruformat__context_html_a016a2c15a10105ff17628c9ee7f5c424"><div class="ttname"><a href="structaaruformat__context.html#a016a2c15a10105ff17628c9ee7f5c424">aaruformat_context::ps3_disc_key</a></div><div class="ttdeci">uint8_t * ps3_disc_key</div><div class="ttdoc">Cached disc key (16 bytes), NULL if not loaded.</div><div class="ttdef"><b>Definition</b> <a href="context_8h_source.html#l00348">context.h:348</a></div></div>
<div class="ttc" id="astructaaruformat__context_html_a1bfda8e3b76471a7b526d05f4855f8f1"><div class="ttname"><a href="structaaruformat__context.html#a1bfda8e3b76471a7b526d05f4855f8f1">aaruformat_context::ps3_plaintext_region_count</a></div><div class="ttdeci">uint32_t ps3_plaintext_region_count</div><div class="ttdoc">Number of plaintext regions.</div><div class="ttdef"><b>Definition</b> <a href="context_8h_source.html#l00350">context.h:350</a></div></div>
<div class="ttc" id="astructaaruformat__context_html_a8b769e9fb9467aa11d4a2936cf5cf5ed"><div class="ttname"><a href="structaaruformat__context.html#a8b769e9fb9467aa11d4a2936cf5cf5ed">aaruformat_context::mediaTags</a></div><div class="ttdeci">mediaTagEntry * mediaTags</div><div class="ttdoc">Hash table of extra media tags (uthash root).</div><div class="ttdef"><b>Definition</b> <a href="context_8h_source.html#l00267">context.h:267</a></div></div>
<div class="ttc" id="astructaaruformat__context_html_acf62eadb2e019323fdbe8bbf536ad82c"><div class="ttname"><a href="structaaruformat__context.html#acf62eadb2e019323fdbe8bbf536ad82c">aaruformat_context::ps3_plaintext_regions</a></div><div class="ttdeci">void * ps3_plaintext_regions</div><div class="ttdoc">Parsed Ps3PlaintextRegion array (max 32), NULL if not loaded.</div><div class="ttdef"><b>Definition</b> <a href="context_8h_source.html#l00349">context.h:349</a></div></div>
<div class="ttc" id="astructmediaTagEntry_html"><div class="ttname"><a href="structmediaTagEntry.html">mediaTagEntry</a></div><div class="ttdoc">Hash table entry for an arbitrary media tag (e.g., proprietary drive/medium descriptor).</div><div class="ttdef"><b>Definition</b> <a href="context_8h_source.html#l00121">context.h:122</a></div></div>
<div class="ttc" id="astructmediaTagEntry_html_a334fc65b37efdfb624e804e98c398927"><div class="ttname"><a href="structmediaTagEntry.html#a334fc65b37efdfb624e804e98c398927">mediaTagEntry::data</a></div><div class="ttdeci">uint8_t * data</div><div class="ttdoc">Tag data blob (opaque to library core); length bytes long.</div><div class="ttdef"><b>Definition</b> <a href="context_8h_source.html#l00123">context.h:123</a></div></div>
<div class="ttc" id="astructmediaTagEntry_html_aa96c6684fd98145d0089d72957d2afa7"><div class="ttname"><a href="structmediaTagEntry.html#aa96c6684fd98145d0089d72957d2afa7">mediaTagEntry::length</a></div><div class="ttdeci">uint32_t length</div><div class="ttdoc">Length in bytes of data.</div><div class="ttdef"><b>Definition</b> <a href="context_8h_source.html#l00125">context.h:125</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
</div><!-- container -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a href="dir_334a95085ca661c6475619df5f6eaf52.html">ps3</a></li><li class="navelem"><a href="ps3__crypto_8c.html">ps3_crypto.c</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.16.1 </li>
</ul>
</div>
</body>
</html>