Note that there are some explanatory texts on larger screens.

plurals
  1. POmacos: CCCrypt() decrypt output does not match original plaintext
    text
    copied!<p>In the code below, the decrypted text does not match the original plaintext. The first 12 bytes are messed up. Note that block cipher padding has been disabled. I have tried different values for BUF_SIZE, all multiples of 16 - every time the first 12 bytes of the decrypted data is wrong. Here's the output:</p> <pre><code> plain buf[32]: 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 outlen=32 outlen=32 dec buf[32]: 0C 08 01 46 6D 3D FC E9 98 0A 2D E1 AF A3 95 3A 0B 31 1B 9D 11 11 11 11 11 11 11 11 11 11 11 11 </code></pre> <p>Here's the code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;CommonCrypto/CommonCryptor.h&gt; static void dumpbuf(const char* label, const unsigned char* pkt, unsigned int len) { const int bytesPerLine = 16; if (label) { printf("%s[%d]:\n", label, len); } for (int i = 0; i &lt; int(len); i++) { if (i &amp;&amp; ((i % bytesPerLine) == 0)) { printf("\n"); } unsigned int c = (unsigned int)pkt[i] &amp; 0xFFu; printf("%02X ", c); } printf("\n"); } int main(int argc, char* argv[]) { unsigned char key[16]; unsigned char iv[16]; memset(key, 0x22, sizeof(key)); memset(iv, 0x33, sizeof(iv)); #define BUF_SIZE 32 unsigned char plainBuf[BUF_SIZE]; unsigned char encBuf[BUF_SIZE]; memset(plainBuf, 0x11, sizeof(plainBuf)); dumpbuf("plain buf", plainBuf, sizeof(plainBuf)); int outlen; CCCryptorStatus status; status = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, 0, key, kCCKeySizeAES128, iv, plainBuf, sizeof(plainBuf), encBuf, sizeof(encBuf), (size_t*)&amp;outlen); if (kCCSuccess != status) { fprintf(stderr, "FEcipher: CCCrypt failure\n"); return -1; } printf("outlen=%d\n", outlen); status = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0, key, kCCKeySizeAES128, iv, encBuf, sizeof(encBuf), plainBuf, sizeof(plainBuf), (size_t*)&amp;outlen); if (kCCSuccess != status) { fprintf(stderr, "FEcipher: CCCrypt failure\n"); return -1; } printf("outlen=%d\n", outlen); dumpbuf("dec buf", plainBuf, sizeof(plainBuf)); return 0; } </code></pre> <p>Thanks, Hari</p>
 

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