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

📄 aesengine1.h

📁 algorithm provide basic encryption/decryption using AES for with Secret Key.
💻 H
字号:

#include <stdio.h>

#ifndef AFX_AESENGINE_H__
#define AFX_AESENGINE_H__

typedef	unsigned char byte;
typedef	unsigned int uint;


#define	MAXROUNDS	14
#define	MAXKC		64
#define BLOCK_SIZE	64
#define BLOCK_BITS	128

#define AES_BLOCK_SIZE 16

#define CBC_MODE	151
#define ECB_MODE	152


class AESEngine1 
{
public:
 	AESEngine1();

	~AESEngine1();
	
	int encrypt( byte plainData[], int plainDataLength, byte*& encryptedData );

	int decrypt( byte encryptedData[], int encryptedDataLength, byte*& decryptedData );

	void init( byte key[], int keyLength, int mode );

private:

//--------------------------------------------------------------------------
// cipher params
//--------------------------------------------------------------------------
    static const byte Logtable[];

	static const byte Alogtable[];

	static const byte S[]; 

	static const byte Si[];

	static const int rcon[];

//--------------------------------------------------------------------------
// instance variables
//--------------------------------------------------------------------------
	
    int			ROUNDS;
    int			workingKey_[ MAXROUNDS + 1 ] [ 4 ];
    int			A0;
    int			A1;
    int			A2;
    int			A3;
    bool	    forEncryption_;
	int			keyLength_;
	byte		cbcV_[ AES_BLOCK_SIZE ];
	int			mode_;
//--------------------------------------------------------------------------

private:

//--------------------------------------------------------------------------
// cipher methods
//--------------------------------------------------------------------------

	byte mul0x2( int b );

	byte mul0x3( int b );

	byte mul0x9( int b );

	byte mul0xb( int b );

	byte mul0xd( int b );

	byte mul0xe( int b );

	void KeyAddition( int rk[] );
	
	int  shift( int r, int shift );
	
	void ShiftRow();
	
	void InvShiftRow();

	int  applyS( int r, const byte* box );
	
	void Substitution( const byte* box );
	
	void MixColumn();

	void InvMixColumn();
	
	void generateWorkingKey( byte key[] );

	int processBlock( byte in[], int inOff, byte out[], int outOff);

	void unpackBlock( byte bytes[], int off );
	
	void packBlock( byte bytes[], int off );

	void encryptBlock( int rk[][4] );

	void decryptBlock( int rk[][4] );

};

#endif // AFX_AESENGINE_H__



⌨️ 快捷键说明

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