Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Chen_Chen
Beginner
47 Views

the different encrypt result of ipp and openssl

recently, i used ipp and openssl libraries to encrypt the same plain text ,but i get two different results,
the encrypt algorithm is aes and the encrypt mode is cfb, the codes are as follows:
#include
#include
#include
#include
#include
#include
#include "ipp.h"
#include "ippcore.h"
#define keylen 32
int main()
{
int size=64;
ippInit();
Ipp8u iv[32];// change unsigned char --->Ipp8u;
Ipp8u key[32];
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<32; i++) /*generate the init-vector*/
{
iv=rand()%10;
//printf("%d ",iv);
}
for (i=0;i<32;i++) /*generate the key*/
{
key=rand()%10;
//printf("%d ",key);
}
len=size;
c_len=len;
unsigned char *plaintext=(Ipp8u *)malloc(len);;//change unsigned char-->Ipp8u;
unsigned char *ciphertext=(Ipp8u *)malloc(c_len);
memset(ciphertext,0,c_len);
for(i=0;i
{
plaintext=rand()%10+'0';
}
printf("\\n the plaintext is %s\\n",plaintext);
//the encrypto process;
/*the part next is the encrypt process operated by Intel@IPP cryptography library*/
//--------------------encrypt with ipp----------------------------
ippsRijndael256GetSize(&ctxsize);
IppsRijndael256Spec* pCtx = (IppsRijndael256Spec*)(new Ipp8u [ctxsize]);
ippsRijndael256Init(key,IppsRijndaelKey256,pCtx);//??????
ippsRijndael256EncryptCFB(plaintext,ciphertext,len,32,pCtx,iv,IppsCPPaddingNONE);
delete (Ipp8u*)pCtx;
printf("the ipp ciphertext is %s\\n",ciphertext);
//--------------------encrypt with openssl---------------------------
EVP_CIPHER_CTX enc_ctx;
EVP_CIPHER *cipher=(EVP_CIPHER *)EVP_aes_256_cfb();
EVP_CIPHER_CTX_init(&enc_ctx);
EVP_EncryptInit_ex(&enc_ctx, cipher, NULL, key, iv);
EVP_EncryptUpdate(&enc_ctx, ciphertext, &c_len, plaintext, len);
EVP_CIPHER_CTX_cleanup(&enc_ctx);
printf("the openssl ciphertext is %s\\n",ciphertext);
return 0;
}
hope someone can give me a help
0 Kudos
3 Replies
IDZ_A_Intel
Employee
47 Views

Hi Chen,

We can reproduce the problem andare investigating it. Get back to you soon.

Regards,
Ying
Ying_H_Intel
Employee
47 Views

Hi Chen,

I'm afraid the OpenSSL AES EVP_CIPHER *cipher=(EVP_CIPHER *)EVP_aes_256_cfb() are notexactly equivalent to the IPP Rigndael256 here.

IPP Rigndael256 means implementation of general Rijndael algorithm with 256 bit data block size.
If i haven't made mistake, OpenSSL aes 256 are based on CFB 128bit.
/* crypto/evp/evp.h */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
# define EVP_aes_256_cfb EVP_aes_256_cfb128

So the result is different.

You may Use IPP Rijndael128 instead. For example , change the code as below.

//--------------------encrypt with ipp----------------------------
ippsRijndael128GetSize(&ctxsize);
IppsRijndael128Spec* pCtx = (IppsRijndael128Spec*)(new Ipp8u [ctxsize]);
ippsRijndael128Init(key,IppsRijndaelKey128,pCtx);//??????
IppStatus status=ippsRijndael128EncryptCFB(plaintext,ciphertext,len,16,pCtx,iv,NONE); //Size of the CFB block is128bit.

EVP_CIPHER *cipher=(EVP_CIPHER *)EVP_aes_128_cfb();
Then you may get same result.

Regards,
Ying
Ying_H_Intel
Employee
47 Views

One more discussion at http://software.intel.com/en-us/forums/showthread.php?t=75650, AES Cryptography Primitive Malfunctioning?
where Andrzej Ch giveawonderfulexplanation and sample.

Reagards,
Ying

Reply