<table><tr><td style="">langbeck added inline comments.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D16134">View Revision</a></tr></table><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88020">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">History.cpp:234</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">is there any error handling in case this goes wrong? does it throw or assert?</p>

<p style="padding: 0; margin: 8px;">passing in strings like that looks extremely error prone (and system config error prone), unfortunately most crypto APIs like that (botan is a bit better).</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">The default provider (OpenSSL) does support <tt style="background: #ebebeb; font-size: 13px;">AES128</tt> and will never fails.<br />
I can try do address this unlikely-but-still-possible error case during migration to OpenSSL.</p>

<p style="padding: 0; margin: 8px;">Note that this solution depends that the cipher has 128 bits block size and the algorithm will not be available to be configured by the user.<br />
The code can be changed to work with any block size, but it will require more code.<br />
Such change can be made later in a second pull-request. What do you think?</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88014">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">History.cpp:237</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">use camelCase not snake_case</p>

<p style="padding: 0; margin: 8px;">and could probably do with a comment to explain what is happening and why. I guess you're generating 8 random bytes and padding with 8 zeroes?</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Yes, you are right. The zeros is the counter part of the IV.<br />
Remembering that the IV size is 16 bytes because 16 is the block size of AES.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88019">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">History.cpp:238</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">I'm not sure I understand what does does, and that casting doesn't look safe (but I could be wrong, I just don't immediately understand what is happening).</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">This is just accessing the counter part of of the IV (last 64 bits).<br />
The counter must be big-endian to allow random single-block read match with random multi-block reads.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88013">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">History.cpp:240</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">why 1KB?</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Just a buffer size that's larger than the bigger read request that I saw in my machine during my tests.<br />
But this value is just an initial guess to minimize unecessary allocations.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88016">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">History.cpp:254</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">what does this do</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">This is only clearing the lower 4 bits of the initial cell address.<br />
The result is the address of the block that contains the cell that we want.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88017">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">History.cpp:255</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">samesies</p>

<p style="padding: 0; margin: 8px;">if it does what I think it does the usual (and more understandable, imho) way of doing this is to use division and modulo</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">When the modulo is a power of 2, use mask is the way to go (and that's the case for AES128).<br />
These operations are well known among those who already worked with memory paging.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88018">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">History.cpp:260</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">what type is decrypted?</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">It's <tt style="background: #ebebeb; font-size: 13px;">QCA::MemoryRegion</tt>, as can be seen just 4 lines bellow.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88015">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">History.h:92</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">camelCase</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">I'll keep that in mind when I change the code to move from QCA to <tt style="background: #ebebeb; font-size: 13px;">libssl</tt>.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D16134#inline-88023">View Inline</a><span style="color: #4b4d51; font-weight: bold;">sandsmark</span> wrote in <span style="color: #4b4d51; font-weight: bold;">main.cpp:91</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">make it locally static in the SecureHistory constructor, then we get less ifdefs (that is also threadsafe, fwiw, so shouldn't be any different from this).</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">I wasn't remembering of locally static variables. Great idea.</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R319 Konsole</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D16134">https://phabricator.kde.org/D16134</a></div></div><br /><div><strong>To: </strong>langbeck, tcanabrava, hindenburg, Konsole, sandsmark<br /><strong>Cc: </strong>langbeck, ngraham, sandsmark, pino, frederico, konsole-devel, herrold, maximilianocuria, hindenburg<br /></div>