AESEncrypt.h

[code="java"][/code]#ifndef AESENCRYPT_H
#define AESENCRYPT_H

#include "device.h"
#include <string.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>

#include <CL/opencl.h>


class AESEncrypt:public Device
{
public:

//CL Objects and memory buffers
int status;
cl_uchar* output;
cl_mem rKeyBuffer;
cl_mem sBoxBuffer;

cl_uint keySizeBits;
cl_uint keySize;
cl_uint explandedKeySize;
cl_uint rounds;

cl_uchar *key; // Encryption Key
cl_uchar *expandedKey; //Encryption Key after expanding
cl_uchar *roundKey; // Encryption Key after expanding rounded

AESEncrypt();
//~AESEncrypt();

//Create context
int createContext();

//Create command queue
int createQueue();

//Create buffer objects
int createBuffers();

//Write buffer into kernel
int enqueueWriteBuffer();

//Create program object
int createProgram(const char **source, const size_t *sourceSize);

//Build program objects
int buildProgram();

//Create kernel objects
int createKernel();

//Set arguments for kernel
int setKernelArgs();

//Migrate memory objects between different devices
int enqueueMigrateMemObjects();

//Execute kernel
int enqueueKernel();

//Waite for kernel to be complete
int waitForKernel();

//Get the running time of the kernel
int getKernelTime();

//Read the result data to Host
int enqueueReadData();

//Check the results
int verifyResults();

//Query the command queue status
int getEventInfo();

//Clean up the resources
int cleanupResources();

//setup AES
int setupAESEncryp();

/* encrypt functions */
void mixColumns(cl_uchar * state);
void subBytes(cl_uchar * state);
void addRoundKey(cl_uchar * state, cl_uchar * roundKey);
void shiftRows(cl_uchar * state);
cl_uchar galoisMultiplication(cl_uchar a, cl_uchar b);

void aesMain(cl_uchar * state, cl_uchar * expandedKey, cl_uint rounds);
void aesRound(cl_uchar * state, cl_uchar * roundKey);
void mixColumn(cl_uchar *column);
void shiftRow(cl_uchar * state, cl_uchar nbr);
cl_uchar getSBoxValue(cl_uint num);

/* key generation functions */
void createRoundKey(cl_uchar * expandedKey, cl_uchar * roundKey);
cl_uchar getRconValue(cl_uint num);
void rotate(cl_uchar * word);
void core(cl_uchar * word, cl_uint iter);
void keyExpansion(cl_uchar * key, cl_uchar * expandedKey,
cl_uint keySize, cl_uint explandedKeySize);
};

// Read a file into a string
std::string convertToString(const char * filename);

int initializeCL();
//calls runCPU(), runSingleGPU() and runMultiGPU().
int initializeHost();

int run();


//case 1: Use single CPU to compute
int runCPU();

//case 2: Use single GPU to compute
int runSingleGPU();

//case 3: Use all GPU devices to compute
int runMultiGPU();

//work balance
int workLoadBalance();

// Releases program's resources
void cleanupHost(void);

#endif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值