Cryptography for Intel(R) Integrated Performance Primitives Developer Reference

ID 768738
Date 12/16/2022
Document Table of Contents

Example of Using AES Functions

AES Encryption and Decryption

    // use of the CTR mode
int AES_sample(void)
   // secret key
   Ipp8u key[] = "\x00\x01\x02\x03\x04\x05\x06\x07"
   // define and setup AES cipher
   int ctxSize;
   IppsAESSpec* pAES = (IppsAESSpec*)( new Ipp8u [ctxSize] );
   ippsAESInit(key, sizeof(key)-1, pAES, ctxSize);

   // message to be encrypted
   Ipp8u msg[] = "the quick brown fox jumps over the lazy dog";
   // and initial counter
   Ipp8u ctr0[] = "\xff\xee\xdd\xcc\xbb\xaa\x99\x88"

   // counter
   Ipp8u ctr[16];

   // init counter before encryption
   memcpy(ctr, ctr0, sizeof(ctr));
   // encrypted message
   Ipp8u ctext[sizeof(msg)];
   // encryption
   ippsAESEncryptCTR(msg, ctext, sizeof(msg), pAES, ctr, 64);

   // init counter before decryption
   memcpy(ctr, ctr0, sizeof(ctr));
   // decrypted message
   Ipp8u rtext[sizeof(ctext)];
   // decryption
   ippsAESDecryptCTR(ctext, rtext, sizeof(ctext), pAES, ctr, 64);

   // remove secret and release resource
   ippsAESInit(0, sizeof(key)-1, pAES, ctxSize);
   delete [] (Ipp8u*)pAES;

   int error = memcmp(rtext, msg, sizeof(msg));
   return 0==error;

Did you find the information on this page useful?

Characters remaining:

Feedback Message