Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6712 Discussions

ippsRijndael128EncryptCBC fails for input files larger than 33MB

o_ganot
Beginner
245 Views

Hi,

Iv'e implemented a C++ native dll which allocates a CTR(counter) mode/CBC mode session, encrypts and decrypts buffers.

Iv'e implemented a corresponding C# tester, which takes an input file, and using BinaryReader, readsthe file buffer-buffer, encryptseach buffer using the dll above and writes the encrypted file using a BinaryWriter.

Iv'e tested encryption in CTR mode using different file sizes and different buffer sizes, and all succeeded.

When I tested encryption in CBC mode, I found out that input files larger than 33MB fail in the middle of encryption, producing the error:

ippStsUnderRunErr = -124, /* Data under run error */

I tried changing the buffer size, but the error presists. I tried using CTR mode on the same file (34MB) and it succeeded.

Here is the tester code:

///

Encrypt a file

///

/// the handle of the session to use

/// the file to encrypt

/// the encrypted file

/// const IV to be used

///

private bool EncryptFile(uint SessionHandle, string InFile,

string OutFile, byte[] IV, int BlockSize, out TimeSpan TestDuration)

{

// Init output params

TestDuration =

TimeSpan.MinValue;

// Open the input file

FileStream Infs = new FileStream(InFile, FileMode.Open, FileAccess.Read);

if(Infs.Length == 0)

{

MessageBox.Show("Input file is empty", "AES Transform Tester",

MessageBoxButtons.OK, MessageBoxIcon.Error);

Infs.Close();

return false;

}

// Create the output file

FileStream Outfs = new FileStream(OutFile, FileMode.Create, FileAccess.Write);

BinaryReader br = new BinaryReader(Infs);

BinaryWriter bw = new BinaryWriter(Outfs,System.Text.Encoding.Default);

byte[] PlainTextBlock;

byte[] EncryptedBlock;

try

{

// Get the current time

DateTime TestStart = DateTime.Now;

// Read the file block by block

while((PlainTextBlock = br.ReadBytes(BlockSize)).Length != 0)

{

// Encrypt the byte array

EncryptedBlock =

new byte[PlainTextBlock.Length];

if(!AESTstrUtil.EncryptPacket(SessionHandle,PlainTextBlock,

IV, EncryptedBlock))

{

MessageBox.Show("Failed to encrypt block", "AE S Transform Tester",

MessageBoxButtons.OK, MessageBoxIcon.Error);

return false;

}

bw.Write(EncryptedBlock);

}

// Set the test duration

TestDuration =

DateTime.Now - TestStart;

}

finally

{

bw.Close();

Outfs.Close();

br.Close();

Infs.Close();

}

return true;

}

Any ideas / same experience?

Thanks

0 Kudos
2 Replies
Chao_Y_Intel
Moderator
245 Views

HI,

Some suggest from expert for this problem:

The single case when ippsRijndael128EncryptCBC() returns ippStsUnderRunErr status is
0!=(len%16) and padding==NONE, where len is data length (in bytes ) to be encrypted.
Pay attention that behavior of all symmetric ciphers has been changed in IPP v5.1 - padding scheme parameter does not use actually and always assumes NONE

0 Kudos
o_ganot
Beginner
245 Views

Hi,

Thanks.
I just found out myself that indeed the case you suggested was the one I confronted.

I think that a different error name or appropriate documentation (Iv'e looked for such anywhere) would have prevented the mess I got in...

0 Kudos
Reply