Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
6670 Discussions

Windows Crypto & ippsRijndael128EncryptCBC

lionel_carminati
Beginner
255 Views

Hi,

I'm developping a Windows application that relies on AES 128 CBC algorithm and I'm considering both OpenSSL & IPP implementations !  To that purpose I'm testing the following Windows IPP Crypto 7 code provided in http://software.intel.com/sites/default/files/article/181895/intelcrypt710.pdf (page 16) compiled with visual studio 10.0 ....

const int blkSize = 16; // block size
int ctxSize; // context size
ippsRijndael128GetSize(&ctxSize); // evaluating context size
IppsRijndael128Spec* ctx = (IppsRijndael128Spec*)( new Ipp8u [ctxSize] );
Ipp8u key[16] = {0xff,0xee,0xdd,0xcc,0xbb,0xaa,0x99,0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11,0x00};
ippsRijndael128Init(key,IppsRijndaelKey128,ctx);//128-bit key
Ipp8u plain[] = "Rijndael-128 Cipher Block Chaining mode";
Ipp8u ciph[(sizeof(plain)+blkSize-1) &~(blkSize-1)];
Ipp8u iv[blkSize] = {0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
ippsRijndael128EncryptCBC(plain,ciph,sizeof(plain),ctx,iv,IppsCPPaddingNONE);
Ipp8u deciph[sizeof(ciph)];
ippsRijndael128DecryptCBC(ciph,deciph,sizeof(ciph),ctx,iv,IppsCPPaddingNONE);
cout <<"Decrypted text: "<< deciph << endl;
delete (Ipp8u*) ctx;

and I'm confused  plaintext & deciph text are not the same ! what's wrong ? where is (are) my mistake(s) ?


Plain text: Rijndael-128 Cipher Block Chaining mode
IN      (40)    00000000: 52 69 6a 6e 64 61 65 6c 2d 31 32 38 20 43 69 70  Rijndael-128 Cip
IN      (40)    00000010: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc  ................
IN      (40)    00000020: cc cc cc cc cc cc cc cc                          ........
Decrypted text: xµ-gEŧ!4♥M└¥?‗ä╗$ýºéI0Õ ╔q±?H╗$ýºéI0Õ ╔q±?H╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠►hG
OUT     (48)    00000000: 78 e6 2d 67 45 8f f5 21 34 03 4d c0 be 3f f2 84  x.-gE..!4.M..?..
OUT     (48)    00000010: cc cc cc cc cc cc cc cc 10 68 47 00 00 00 00 00  .........hG.....
OUT     (48)    00000020: cc cc cc cc cc cc cc cc fe b5 3c fb f7 be 00 00  ..........<.....

second question : in case we consider CBC & Padding (such PK7 for instance) how to retreive the real deciph buffer size I mean the plain text size ??

0 Kudos
7 Replies
SergeyKostrov
Valued Contributor II
255 Views
... ippsRijndael128DecryptCBC( ciph, deciph, ??? sizeof(ciph) ???, ctx, iv, IppsCPPaddingNONE ); ... Could you verify the actual length of encrypted text with the length of the 3rd parameter 'sizeof(ciph)'?
lionel_carminati
Beginner
255 Views
sizeof(plain) == 40, sizeof(ciph) == 48, sizeof(deciph) == 48
SergeyKostrov
Valued Contributor II
255 Views
>>...sizeof(ciph) == 48 This is an example that demonstrates the sizeof and actual length of some data could be different: ... chat szData[48]; strcpy( szData, "1234567" ); int iLen1 = sizeof( szData / szData[0] ); int iLen2 = strlen( &szData[0] ); ...
Andrzej_Chrzeszczyk
New Contributor I
255 Views
Hello Lionel In the example in our book the plain text is: Ipp8u plain[] = "Rijndael-128 Cipher Block Chaining mode "; With 8 trailing spaces at the end which are invisible in this post (compare pdf) Your code with this improvement works for me. Andrzej Chrzeszczyk
SergeyKostrov
Valued Contributor II
255 Views
Hi everybody, >>...In the example in our book... What book are you talking about?
Andrzej_Chrzeszczyk
New Contributor I
255 Views
Hi Sergey I mean the book IPP Crypto Guide mentioned by Lionel http://software.intel.com/sites/default/files/article/181895/intelcrypt710.pdf It can be downloaded from http://software.intel.com/en-us/articles/ipp-crypto-guide A Ch
SergeyKostrov
Valued Contributor II
255 Views
>>I mean the book IPP Crypto Guide mentioned by Lionel >>http://software.intel.com/sites/default/files/article/181895/intelcrypt7... >> >>It can be downloaded from >>http://software.intel.com/en-us/articles/ipp-crypto-guide Thank you!
Reply