登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

面包会有的

... ...

 
 
 

日志

 
 

AES算法的核心代码VC++(头文件)  

2011-10-23 23:27:30|  分类: 加密算法 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
// rijndael.h: interface for the rijndael class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_RIJNDAEL_H__65AE854C_7E77_4488_AC14_66161F67B341__INCLUDED_)
#define AFX_RIJNDAEL_H__65AE854C_7E77_4488_AC14_66161F67B341__INCLUDED_
typedef unsigned char   u1byte; /* an 8 bit unsigned character type */
typedef unsigned short  u2byte; /* a 16 bit unsigned integer type   */
typedef unsigned long   u4byte; /* a 32 bit unsigned integer type   */
typedef signed char     s1byte; /* an 8 bit signed character type   */
typedef signed short    s2byte; /* a 16 bit signed integer type     */
typedef signed long     s4byte; /* a 32 bit signed integer type     */
/* 2. Standard interface for AES cryptographic routines             */
/* These are all based on 32 bit unsigned values and may require    */
/* endian conversion for big-endian architectures                   */
#define LITTLE_ENDIAN
class AES
{
public:
 virtual void set_key(const u1byte key[], const u4byte key_bits) = 0;
 virtual void encrypt(const u1byte in_blk[16], u1byte out_blk[16]) = 0;
 virtual void decrypt(const u1byte in_blk[16], u1byte out_blk[16]) = 0;
}; 
/* 3. Basic macros for speeding up generic operations               */
/* Circular rotate of 32 bit values                                 */
#ifdef _MSC_VER
 include <stdlib.h>
 pragma intrinsic(_lrotr,_lrotl)
 define rotr(x,n) _lrotr(x,n)
 define rotl(x,n) _lrotl(x,n)
#else
#define rotr(x,n)   (((x) >> ((int)(n))) | ((x) << (32 - (int)(n))))
#define rotl(x,n)   (((x) << ((int)(n))) | ((x) >> (32 - (int)(n))))
#endif
/* Invert byte order in a 32 bit variable                           */
#define bswap(x)    (rotl(x, 8) & 0x00ff00ff | rotr(x, 8) & 0xff00ff00)
/* Extract byte from a 32 bit quantity (little endian notation)     */
#define byte(x,n)   ((u1byte)((x) >> (8 * n)))
/* Input or output a 32 bit word in machine order     */
#ifdef LITTLE_ENDIAN
#define u4byte_in(x)  (*(u4byte*)(x))
#define u4byte_out(x, v) (*(u4byte*)(x) = (v))
#else
#define u4byte_in(x)  bswap(*(u4byte)(x))
#define u4byte_out(x, v) (*(u4byte*)(x) = bswap(v))
#endif
 

class rijndael 
{
public:
 rijndael();
 virtual ~rijndael();
public:
 char *name(void);
 void set_key(const u1byte key[], const u4byte key_len);
 void encrypt(const u1byte in_blk[16], u1byte out_blk[16]);
 void decrypt(const u1byte in_blk[16], u1byte out_blk[16]);

private:
 u4byte  k_len;
 u4byte  e_key[64];
 u4byte  d_key[64];
};
 
#endif // !defined(AFX_RIJNDAEL_H__65AE854C_7E77_4488_AC14_66161F67B341__INCLUDED_)
  评论这张
 
阅读(1075)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018