Note that there are some explanatory texts on larger screens.

plurals
  1. POCrypto++ low level AES API (a la SJCL)
    primarykey
    data
    text
    <p>I'm trying to reverse engineer a protocol from a javascript implementation, and I'm stuck on an AES encryption method. I'm programming this in C++, with the Crypto++ library. It's using the SJCL library, and it calls <code>ciphertext = (new sjcl.cipher.aes(key)).encrypt(plaintext)</code>. From the SJCL documentation, I can see that this is a low-level interface. <code>ciphertext</code>, <code>key</code>, and <code>plaintext</code> are all 4-element arrays of 32-bit integers. As far as I know, and could find on google, Crypto++ only provides high-level interfaces. Is there any way to get Crypto++ to do what SJCL is doing? Also, what exactly does that <code>encrypt</code> method do?</p> <p><a href="http://bitwiseshiftleft.github.com/sjcl/doc/symbols/sjcl.cipher.aes.html" rel="nofollow">http://bitwiseshiftleft.github.com/sjcl/doc/symbols/sjcl.cipher.aes.html</a></p> <p>Edit: I noticed the javascript code converted <code>plantext</code> from a string to ints, and I think I tried every combination of changing endianess of every variable. I tried all combinations that made sense, anyway. I also tried creating arrays of <code>int32_t</code>'s and initializing them with what was input into that line of javascript. Here's what I've got now:</p> <pre><code>void crypto() { SecByteBlock key(16); int32_t plain[4] = { 0x93C467E3, 0x7DB0C7A4, 0xD1BE3F81, 0x0152CB56 }, cipher[4]; int32_t* keyBuf = (int32_t*) key.BytePtr(); keyBuf[0] = 1885434739; keyBuf[1] = 2003792484; keyBuf[2] = 0; keyBuf[3] = 0; cout &lt;&lt; "plain = [" &lt;&lt; plain[0] &lt;&lt; ", " &lt;&lt; plain[1] &lt;&lt; ", " &lt;&lt; plain[2] &lt;&lt; ", " &lt;&lt; plain[3] &lt;&lt; "]\n"; cout &lt;&lt; "key = [" &lt;&lt; keyBuf[0] &lt;&lt; ", " &lt;&lt; keyBuf[1] &lt;&lt; ", " &lt;&lt; keyBuf[2] &lt;&lt; ", " &lt;&lt; keyBuf[3] &lt;&lt; "]\n"; ECB_Mode&lt;AES&gt;::Encryption e; e.SetKey(key, key.size()); StringSource((const byte*) plain, 16, true, new StreamTransformationFilter( e, new ArraySink((byte*)cipher, 16) ) ); cout &lt;&lt; "cipher = [" &lt;&lt; cipher[0] &lt;&lt; ", " &lt;&lt; cipher[1] &lt;&lt; ", " &lt;&lt; cipher[2] &lt;&lt; ", " &lt;&lt; cipher[3] &lt;&lt; "]\n"; } function crypto() { var key = [1885434739, 2003792484, 1885434739, 2003792484]; var plain = [0x93C467E3,0x7DB0C7A4,0xD1BE3F81,0x0152CB56]; console.log("plain = "+plain); console.log("key = "+key); var cipher = (new sjcl.cipher.aes(key)).encrypt(plain); console.log("cipher = "+cipher); } </code></pre> <p>Here's the output of the C++ version:</p> <pre><code>plain = [2479122403, 2108737444, 3518906241, 22203222] key = [1885434739, 2003792484, 1885434739, 2003792484] cipher = [3437909595, 1341853431, 2532744872, 2416113380] </code></pre> <p>and JavaScript:</p> <pre><code>plain = 2479122403,2108737444,3518906241,22203222 key = 1885434739,2003792484,1885434739,2003792484 cipher = -1974659585,-1567997661,-1863224381,-318378846 </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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