Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Liang_Lu
Beginner
63 Views

problem about encryption and decryption

Hi,
I tried to decryptthe ciphertext which was encrypted by ippsRijindael128EncryptCBC using the function AES_cbc_decrypt in openssl ,but i failed , then i encrypted the same plaintext using the two funtions respectively, the ciphertext was different, but i think it should be the same because the algorithmand the iput was the same, i confused.

thanks
0 Kudos
5 Replies
Andrzej_Chrzeszczyk
New Contributor I
63 Views

Hello
Maybe the example from page 43 of our guide
http://software.intel.com/en-us/articles/ipp-crypto-guide/
will be helpful

Andrzej Chrzeszczyk
Ying_H_Intel
Employee
63 Views

Hi

Could you pelase provide somecode snippet toshow the parameterdefination for two functions and functions call details?
or a entire test case will begreat.

Best Regards,
Ying H.
Liang_Lu
Beginner
63 Views

Hi,
This is the code snippet.

int ippTimingAES_CBC(int minLen,int maxLen)

{

Ipp8u *pPText = ippsMalloc_8u(maxLen);

Ipp8u *pPPText = ippsMalloc_8u(maxLen);

Ipp8u *pCText = ippsMalloc_8u(maxLen);

Ipp8u *pCCText = ippsMalloc_8u(maxLen);

if(pPText&&pPPText&&pCText&&pCCText)

{

Ipp8u iv[16];

Ipp8u saved_iv[16];

Ipp8u secret_key[32];

Ipp8u* pBuffer;

int pSize;

AES_KEY aes_enc;

AES_KEY aes_dec;

setRandom8u(secret_key,32);

setRandom8u(saved_iv,16);

setRandom8u(pPText,maxLen);

memcpy(pPPText,pPText,maxLen);

memcpy(iv,saved_iv,sizeof(saved_iv));

AES_set_encrypt_key(secret_key,IppsRijndaelkey128,&aes_enc);

ippsRijndael128GetSize(&pSize);

pBuffer = ippsMalloc_8u(pSize);

if(pBuffer){

ippsRijndael128Init(aes_enc.rd_key,IppsRijndaelKey128,pBuffer);

}

else{

ippsFree(pPText);

ippsFree(pPPText);

ippsFree(pCText);

ippsFree(pCCText);

}

ippsRijndael128EncryptCBC(pPText,pCText,minLen,pBuffer,iv,IppsCppaddingNONE);

memcpy(iv,saved_iv,sizeof(saved_iv));

AES_cbc_encrypt(pPPText,pCCText,minLen,&aes_enc,iv,1);

}

... ...

}

int main(){

... ...

ippTimingAES_CBC(256,256);

... ...

}

The result is that pCText is different form pCCText.

Andrzej_Chrzeszczyk
New Contributor I
63 Views

Hi
Compare the example where IPP and SSL give the same results:

//icpc -ipp=crypto diff3.cpp -lssl
#include
#include
#include
#include
#include
#include
#include
#include "ipp.h"
#include "ippcore.h"
#include
#define keylen 16
using namespace std;
int main()
{
int size=64;
const int blkSize = 16;
ippInit();
Ipp8u iv[16];
Ipp8u iv1[16];
Ipp8u iv2[16];
Ipp8u iv3[16];
Ipp8u key[16];
int num_threads;
int i;
int count=0;
int c_len; //ciphertext len;
int len; //plaintext len;
double costtime;
int j;
int ctxsize;
double timesum;
for (i=0; i<16; i++) /*init-vector*/
{
iv=rand()%10;
}
for (i=0;i<16;i++) /*key*/
{
key=rand()%10;
}
len=size;
c_len=len;
unsigned char *plaintext=(Ipp8u *)malloc(len);

memcpy(iv1,iv,sizeof(iv));
memcpy(iv2,iv,sizeof(iv));
memcpy(iv3,iv,sizeof(iv));
Ipp8u ciphertext[c_len];
memset(ciphertext,0,len);

for(i=0;i{
plaintext=(Ipp8u)rand()%10+'0';
}
printf("the plaintext is %s\n",plaintext);

//IPP
ippsRijndael128GetSize(&ctxsize);
IppsRijndael128Spec* pCtx = (IppsRijndael128Spec*)(new Ipp8u [ctxsize]);
ippsRijndael128Init(key,IppsRijndaelKey128,pCtx);
ippsRijndael128EncryptCBC(plaintext,ciphertext,len,pCtx,iv,IppsCPPaddingNONE);
Ipp8u deciph[sizeof(ciphertext)];
ippsRijndael128DecryptCBC(ciphertext, deciph, sizeof(ciphertext),pCtx,iv,IppsCPPaddingNONE);
cout<<"the IPP ciphertext:"<<<cout << "the IPP deciphered text: ";
for(i=0;i cout<;
cout<delete (Ipp8u*)pCtx;

//SSL
Ipp8u ciphertext2[c_len];
Ipp8u deciph2[sizeof(ciphertext2)];
EVP_CIPHER_CTX enc_ctx;
EVP_CIPHER *cipher=(EVP_CIPHER *)EVP_aes_128_cbc();
EVP_CIPHER_CTX_init(&enc_ctx);
EVP_EncryptInit_ex(&enc_ctx, cipher, NULL, key, iv2);
EVP_EncryptUpdate(&enc_ctx, ciphertext2, &c_len, plaintext, len);
EVP_CIPHER_CTX dec_ctx;
EVP_CIPHER_CTX_init(&dec_ctx);
EVP_DecryptInit_ex(&dec_ctx, cipher, NULL, key, iv3);
EVP_DecryptUpdate(&dec_ctx, deciph2, &c_len, ciphertext2, len);
cout<<"the SSL ciphertext:"<<<cout << "the SSL deciphered text: ";
for(i=0;i cout<;
cout<EVP_CIPHER_CTX_cleanup(&enc_ctx);
EVP_CIPHER_CTX_cleanup(&dec_ctx);
return 0;
}
Liang_Lu
Beginner
63 Views

Thank you very much.

Reply