Community
cancel
Showing results for 
Search instead for 
Did you mean: 
58 Views

How to declare ippsDESEncryptCBC initial vector parameter

Hi there,

I'm tring to write a simple code about the DES encypt in CBC mode.
I was only found the ippsDESEncyptECB sample code below.
It's works fine, and in this mode we don't need the initial vector parameter.
I don't know how to declare the parameter of initial vector, can anyone show me a example about the ippsDESEncryptCBC function?

#include
#include
#include "include/ipp.h"

int main() {
int ctxSize, i;
ippsDESGetSize(&ctxSize);
printf("ctxSize=%d\n", ctxSize);
const int desBlkSize = 8;
IppsDESSpec* pCtx = (IppsDESSpec*) malloc(ctxSize);
Ipp8u key[] = {0x01,0x2,0x3,0x4,0x5,0x6,0x7,0x8};
ippsDESInit(key, pCtx);
Ipp8u ptext[] = {"quick brown fox jupm over lazy dog"};
printf("original string:%s\n", ptext);
printf("size of ptext=%d, ~desBlkSize=%d, size=%d\n", sizeof(ptext), ~(desBlkSize-1), ((sizeof(ptext)+desBlkSize-1) &~(desBlkSize-1)));
Ipp8u ctext[(sizeof(ptext)+desBlkSize-1) &~(desBlkSize-1)];
ippsDESEncryptECB(ptext, ctext, sizeof(ctext),
pCtx,
IppsCPPaddingNONE);
for(i=0;i printf("%x", ctext);
printf("\n");
Ipp8u rtext[sizeof(ctext)];
ippsDESDecryptECB(ctext, rtext, sizeof(ctext),
pCtx,
IppsCPPaddingNONE);
for(i=0;i printf("%c", rtext);

printf("\n");

return 0;
}

best regards.
0 Kudos
1 Reply
Vladimir_Dudnik
Employee
58 Views

Hello,

according our expert you may find similar sample in IPP documentation, see"Example 2-2 AES Encryption and Decryption"

Regards,
Vladimir
Reply