AES(Advanced Encryption Standard) Intrinsics各函数介绍
生活随笔
收集整理的這篇文章主要介紹了
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
總結
以上是生活随笔為你收集整理的AES(Advanced Encryption Standard) Intrinsics各函数介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SSE4.1和SSE4.2 Intrin
- 下一篇: C++中的封装、继承、多态