Note that there are some explanatory texts on larger screens.

plurals
  1. POaesimc instruction gives incorrect result
    primarykey
    data
    text
    <p>I'm trying to implement AES cryptography using the AES machine instructions (basing it on Intel's <a href="http://software.intel.com/file/24917" rel="nofollow noreferrer">white paper</a>) available on my Sandy Bridge. Unfortunately, I've come to a halt in the phase of generating the round keys for decryption. Specifically, the instruction <code>aesimc</code> (applying the <em>Inverse Mix Columns</em> operation) returns an incorrect result. </p> <p>In their paper they have an example: <img src="https://i.stack.imgur.com/da3LE.png" alt="enter image description here"></p> <p>So with input:</p> <pre><code>48 69 28 53 68 61 79 29 5B 47 75 65 72 6F 6E 5D </code></pre> <p>I get the following using <code>_mm_aesimc_si128()</code>:</p> <pre><code>2D BF F9 31 99 CD 3A 37 B7 C7 81 FD 7D E0 3D 8E </code></pre> <p>It should have returned:</p> <pre><code>62 7A 6F 66 44 B1 09 C8 2B 18 33 0A 81 C3 B3 E5 </code></pre> <p>Not the same result. <strong>Why is this the case?</strong></p> <p>If you want to reproduce it, I tested it with the code below (remember the arguments <code>-maes -msse4</code> when compiling):</p> <pre><code>#include &lt;wmmintrin.h&gt; #include &lt;iostream&gt; using namespace std; void print_m128i(__m128i data) { unsigned char *ptr = (unsigned char*) &amp;data; for (int i = 0; i &lt; 16; i++) { int val = (int) ptr[i]; if (val &lt; 0xF) { cout &lt;&lt; "0"; } cout &lt;&lt; uppercase &lt;&lt; hex &lt;&lt; val &lt;&lt; " "; } cout &lt;&lt; endl; } int main() { unsigned char *data = (unsigned char*) "\x48\x69\x28\x53\x68\x61\x79\x29\x5B\x47\x75\x65\x72\x6F\x6E\x5D"; __m128i num = _mm_loadu_si128((__m128i*) data); __m128i num2 = _mm_aesimc_si128(num); print_m128i(num2); return 0; } </code></pre> <p><strong>EDIT:</strong> The example in Intel's white paper was wrong. As Hans suggested, my chip is little-endian so byte-swapping is necessary - to and fro.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload