⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocf_cipher.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
字号:
/*////               INTEL CORPORATION PROPRIETARY INFORMATION//  This software is supplied under the terms of a license agreement or//  nondisclosure agreement with Intel Corporation and may not be copied//  or disclosed except in accordance with the terms of that agreement.//        Copyright (c) 2005 Intel Corporation. All Rights Reserved.//*/#if defined( _OCF_ )#include "ocf_cipher.h"#include <string.h>////////////////////////////////////////////////////// OCF cipher//OCFCipher::OCFCipher(AlgoName a, const u8* pKey, int keyLen){   algo = a;   algoBlockSize = CipherBlockSize(a);      // get clone of crypto dev descriptor   fd = cdevClone();      if(-1 != fd) {      int isCipher = ocfCipherEnabled(fd, a);      int isSession = ocfOccupyCipherSession(fd, &ses, a, pKey, keyLen);      error = !isCipher || !isSession;   }   else      error = 1;}void OCFCipher::ResetKey(const u8* pKey, int keyLen){   error = !ocfVacateCipherSession(fd, &ses)        || !ocfOccupyCipherSession(fd, &ses, algo, pKey, keyLen);}OCFCipher::~OCFCipher(){   ocfVacateCipherSession(fd, &ses);   cdevCloneClose(fd);}int OCFCipher::doCipher(u8* pDst, const u8* pSrc, int srcLen){   Ipp8u newIV[MAX_BLKLEN];   switch (mode) {      case ECB:         error = !ocfCipherECB(fd, &ses, operation, pDst, pSrc, srcLen);         break;      case CBC:         if(DECRYPT==operation)            memcpy(newIV, pSrc+srcLen-algoBlockSize, algoBlockSize);                  error = !ocfCipherCBC(fd, &ses, operation, iv, pDst, pSrc, srcLen);                     if(ENCRYPT==operation)            memcpy(newIV, pDst+srcLen-algoBlockSize, algoBlockSize);                     if(!error)            memcpy(iv, newIV, algoBlockSize);         break;      case CFB:         if(DECRYPT==operation) {            if(srcLen<algoBlockSize) {               memcpy(newIV, iv+srcLen, algoBlockSize-srcLen);               memcpy(newIV+algoBlockSize-srcLen, pSrc, srcLen);            }            else               memcpy(newIV, pSrc+srcLen-algoBlockSize, algoBlockSize);         }                  error = !ocfCipherCFB(fd, &ses, operation, iv, param, pDst, pSrc, srcLen);                     if(ENCRYPT==operation) {            if(srcLen<algoBlockSize) {               memcpy(newIV, iv+srcLen, algoBlockSize-srcLen);               memcpy(newIV+algoBlockSize-srcLen, pDst, srcLen);            }            else               memcpy(newIV, pDst+srcLen-algoBlockSize, algoBlockSize);         }                     if(!error)            memcpy(iv, newIV, algoBlockSize);         break;      case CTR:         error = !ocfCipherCTR(fd, &ses, operation, iv, param, pDst, pSrc, srcLen);         break;      default:         error = 1; // unsupported mode         break;   }   return !error;}#endif // _OCF_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -