`
jgsj
  • 浏览: 961762 次
文章分类
社区版块
存档分类
最新评论

AES(Advanced Encryption Standard) Intrinsics各函数介绍

 
阅读更多

AES为高级加密标准,是较流行的一种密码算法。

SIMD相关头文件包括:

//#include <ivec.h>//MMX
//#include <fvec.h>//SSE(also include ivec.h)
//#include <dvec.h>//SSE2(also include fvec.h)


#include <mmintrin.h> //MMX
#include <xmmintrin.h> //SSE(include mmintrin.h)
#include <emmintrin.h> //SSE2(include xmmintrin.h)
#include <pmmintrin.h> //SSE3(include emmintrin.h)
#include <tmmintrin.h>//SSSE3(include pmmintrin.h)
#include <smmintrin.h>//SSE4.1(include tmmintrin.h)
#include <nmmintrin.h>//SSE4.2(include smmintrin.h)
#include <wmmintrin.h>//AES(include nmmintrin.h)
#include <immintrin.h>//AVX(include wmmintrin.h)
#include <intrin.h>//(include immintrin.h)

mmintrin.h为MMX 头文件,其中__m64的定义为:

typedef union __declspec(intrin_type) _CRT_ALIGN(8) __m64
{
    unsigned __int64    m64_u64;
    float               m64_f32[2];
    __int8              m64_i8[8];
    __int16             m64_i16[4];
    __int32             m64_i32[2];    
    __int64             m64_i64;
    unsigned __int8     m64_u8[8];
    unsigned __int16    m64_u16[4];
    unsigned __int32    m64_u32[2];
} __m64;

xmmintrin.h为SSE 头文件,此头文件里包含MMX头文件,其中__m128的定义为:

typedef union __declspec(intrin_type) _CRT_ALIGN(16) __m128 {
     float               m128_f32[4];
     unsigned __int64    m128_u64[2];
     __int8              m128_i8[16];
     __int16             m128_i16[8];
     __int32             m128_i32[4];
     __int64             m128_i64[2];
     unsigned __int8     m128_u8[16];
     unsigned __int16    m128_u16[8];
     unsigned __int32    m128_u32[4];
 } __m128;

emmintrin.h为SSE2头文件,此头文件里包含SSE头文件,其中__m128i和__m128d的定义为:

typedef union __declspec(intrin_type) _CRT_ALIGN(16) __m128i {
    __int8              m128i_i8[16];
    __int16             m128i_i16[8];
    __int32             m128i_i32[4];    
    __int64             m128i_i64[2];
    unsigned __int8     m128i_u8[16];
    unsigned __int16    m128i_u16[8];
    unsigned __int32    m128i_u32[4];
    unsigned __int64    m128i_u64[2];
} __m128i;

typedef struct __declspec(intrin_type) _CRT_ALIGN(16) __m128d {
    double              m128d_f64[2];
} __m128d;

wmmintrin.h为AES头文件,其文件中各函数的介绍:

	/*
	* Performs 1 round of AES decryption of the first m128i using 
	* the second m128i as a round key. 
	*/
	//The decrypted data. This instruction decrypts data by using an Equivalent Inverse
	//Cipher with a 128 bit key. AES decryption requires 10 iterations of decryption by
	//using a cipher key that is 128 bits. Each iteration uses this instruction, except
	//for the last iteration.The last iteration must be performed by _mm_aesdeclast_si128.
	extern __m128i _mm_aesdec_si128(__m128i v, __m128i rkey);

	/*
	* Performs the last round of AES decryption of the first m128i 
	* using the second m128i as a round key.
	*/
	//The decrypted data for v. This instruction decrypts data by using an Equivalent 
	//Inverse Cipher with a 128 bit key. AES decryption requires 10 iterations of decryption
	//and uses a cipher key that consists of 128 bits. The final iteration must be performed
	//by this instruction. The previous nine iterations use _mm_aesdec_si128.
	extern __m128i _mm_aesdeclast_si128(__m128i v, __m128i rkey);

	/*
	* Performs 1 round of AES encryption of the first m128i using 
	* the second m128i as a round key.
	*/
	//The encrypted form of the data in v. This instruction encrypts data by using an
	//Equivalent Inverse Cipher with a 128 bit key. AES encryption requires 10 
	//iterations of encryption by using a cipher key that is 128 bits. Each iteration 
	//uses this instruction, except for the last iteration. The last iteration must 
	//be performed by _mm_aesenclast_si128.
	extern __m128i _mm_aesenc_si128(__m128i v, __m128i rkey);

	/*
	* Performs the last round of AES encryption of the first m128i
	* using the second m128i as a round key.
	*/
	//The encrypted form of the data in v. This instruction encrypts data by using an 
	//Equivalent Inverse Cipher with a 128 bit key. AES encryption requires 10 iterations
	//of encryption by using a cipher key that is 128 bits. You must perform the final 
	//iteration with this instruction. The previous nine iterations use _mm_aesenc_si128.
	extern __m128i _mm_aesenclast_si128(__m128i v, __m128i rkey);

	/*
	* Performs the InverseMixColumn operation on the source m128i 
	* and stores the result into m128i destination.
	*/
	//The inverted data. To perform decryption, you should use the aesimc instruction on 
	//all the AES expanded round keys. This prepares them for decryption by using the 
	//Equivalent Inverse Cipher.
	extern __m128i _mm_aesimc_si128(__m128i v);

	/*
	* Generates a m128i round key for the input m128i 
	* AES cipher key and byte round constant. 
	* The second parameter must be a compile time constant.
	*/
	//The AES encryption key. AES encryption requires 10 iterations of encryption with 
	//a 128 bit round key. Each round of encryption requires a different key. This 
	//instruction helps generate the round keys. The round keys can be generated 
	//independently of the encryption phase.
	extern __m128i _mm_aeskeygenassist_si128(__m128i ckey, const int rcon);

	/* 
	* Performs carry-less integer multiplication of 64-bit halves 
	* of 128-bit input operands. 
	* The third parameter inducates which 64-bit haves of the input parameters 
	* v1 and v2 should be used. It must be a compile time constant.
	*/
	//The product calculated by multiplying 64 bits of v1 and 64 bits of v2.
	// This instruction performs a multiplication of two 64-bit integers.
	//The multiplication does not calculate a carry bit.详见参考文献
	extern __m128i _mm_clmulepi64_si128(__m128i v1, __m128i v2, const int imm8);

参考文献:http://msdn.microsoft.com/en-us/library/cc664767(v=vs.100).aspx

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics