Example of Using DES/TDES Functions

DES/TDES Encryption and Decryption 

   // use of the ECB mode
void DES_sample(void){
   // size of the DES algorithm block is equal to 8
   const int desBlkSize = 8;
 
   // get size of the context needed for the encryption/decryption operation
   int ctxSize;
   ippsDESGetSize(&ctxSize);
   // and allocate one
   IppsDESSpec* pCtx = (IppsDESSpec*)( new Ipp8u [ctxSize] );
 
 
    // define the key
   Ipp8u key[] = {0x01,0x2,0x3,0x4,0x5,0x6,0x7,0x8};
   // and prepare the context for the DES usage
   ippsDESInit(key, pCtx);
   // define the message to be encrypted
   Ipp8u ptext[] = {"quick brown fox jupm over lazy dog"};
 
   // allocate enough memory for the ciphertext
   // note that
   // the size of ciphertext is always multiple of cipher block size
   Ipp8u ctext[(sizeof(ptext)+desBlkSize-1) &~(desBlkSize-1)];
   // encrypt (ECB mode) ptext message
   // pay attention to the 'length' parameter
   // it defines the number of bytes to be encrypted
   ippsDESEncryptECB(ptext, ctext, sizeof(ctext),
                     pCtx,
                     IppsCPPaddingNONE);
      // allocate memory for the decrypted message
   Ipp8u rtext[sizeof(ctext)];
   // decrypt (ECB mode) ctext message
   // pay attention to the 'length' parameter
   // it defines the number of bytes to be decrypted
   ippsDESDecryptECB(ctext, rtext, sizeof(ctext),
                     pCtx,
                     IppsCPPaddingNONE);
   delete (Ipp8u*)pCtx;
}
 

Submit feedback on this help topic

Copyright © 2000 - 2010, Intel Corporation. All rights reserved.