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

本文介绍了AES加密标准及SIMD指令集的相关头文件,包括MMX、SSE等,并详细解释了AES加密和解密过程中的关键指令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)新指令是一种针对AES加密算法的硬件指令集。AES是一种对称加密算法,广泛应用于计算机系统的数据加密和保护领域。Inte的AES新指令旨在通过硬件加速的方式提高AES算法的性能。 传统的AES算法在软件层面上实现,需要通过多次的矩阵运算和逻辑处理来完成加密和解密过程,这会消耗较多的计算资源和时间。而英特尔处理器通过引入AES新指令,可以在硬件层面上直接支持AES算法的相关运算,极大地提高了加密和解密的速度和效率。 具体来说,英特尔AES新指令包含了多个指令集,如AES-ECB(电子密码本模式)、AES-CBC(密码分组链接模式)和AES-CTR(计数器模式)等。这些指令针对不同的AES算法运算方式进行了优化,可以在硬件层面上执行高效的密钥扩展、数据转换、轮函数和密钥调度等操作,从而加速整个AES算法的执行过程。 通过使用英特尔AES新指令,计算机系统可以在执行AES加密和解密任务时获得更高的性能和吞吐量。这对于那些对数据安全性要求较高,需要频繁进行加密和解密操作的应用程序和系统来说尤为重要。此外,英特尔AES新指令还有助于降低CPU的负载,提高系统的整体效能。 总之,英特尔AES新指令是一项优化AES加密算法性能的技术,通过在硬件层面上支持和加速AES算法的相关运算,提高了加密和解密的效率和速度,同时降低了CPU负载,对于数据安全和高性能计算具有重要意义。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值