TI中文支持网
TI专业的中文技术问题搜集分享网站

TM4C129 AES CBC模式加解密官方例子都没有看到在哪里设置填充模式

但是整个工程是可以实现加密解密, 我测试过不用16的倍数,加解密出来的密文长度与明文长度是一致。 

有点疑惑,哪位帮忙解疑一下

user4346240:

//*****************************************************************************
//
//! Used to process(transform) blocks of data, either encrypt or decrypt it.
//!
//! \param ui32Base is the base address of the AES module.
//! \param pui32Src is a pointer to the memory location where the input data
//! is stored.The data must be padded to the 16-byte boundary.
//! \param pui32Dest is a pointer to the memory location output is written.
//! The space for written data must be rounded up to the 16-byte boundary.
//! \param ui32Length is the length of the cryptographic data in bytes.
//!
//! This function iterates the encryption or decryption mechanism number over
//! the data length.Before calling this function, ensure that the AES
//! module is properly configured the key, data size, mode, etc.Only ECB,
//! CBC, CTR, ICM, CFB, XTS and F8 operating modes should be used.The data
//! is processed in 4-word (16-byte) blocks.
//!
//! \note This function only supports values of \e ui32Length less than 2^32,
//! because the memory size is restricted to between 0 to 2^32 bytes.
//!
//! \return Returns true if data was processed successfully.Returns false
//! if data processing failed.
//
//*****************************************************************************
bool AESDataProcess(uint32_t ui32Base, uint32_t *pui32Src, uint32_t *pui32Dest, uint32_t ui32Length)
{uint32_t ui32Count;
//// Check the arguments.//ASSERT(ui32Base == AES_BASE);
//// Write the length register first, which triggers the engine to start// using this context.//AESLengthSet(AES_BASE, (uint64_t)ui32Length);
//// Now loop until the blocks are written.//for(ui32Count = 0; ui32Count < ui32Length; ui32Count += 16) {//19//// Write the data registers.//AESDataWrite(ui32Base, pui32Src + (ui32Count / 4));
//// Read the data registers.//AESDataRead(ui32Base, pui32Dest + (ui32Count / 4));}
//// Return true to indicate successful completion of the function.//return(true);
}

//*****************************************************************************
//
//! Used to set the write crypto data length in the AES module.
//!
//! \param ui32Base is the base address of the AES module.
//! \param ui64Length is the crypto data length in bytes.
//!
//! This function stores the cryptographic data length in blocks for all modes.
//! Data lengths up to (2^61 – 1) bytes are allowed.For GCM, any value up
//! to (2^36 – 2) bytes are allowed because a 32-bit block counter is used.
//! For basic modes (ECB/CBC/CTR/ICM/CFB128), zero can be programmed into the
//! length field, indicating that the length is infinite.
//!
//! When this function is called, the engine is triggered to start using
//! this context.
//!
//! \note This length does not include the authentication-only data used in
//! some modes.Use the AESAuthLengthSet() function to specify the
//! authentication data length.
//!
//! \return None
//
//*****************************************************************************
void AESLengthSet(uint32_t ui32Base, uint64_t ui64Length)
{//// Check the arguments.//ASSERT(ui32Base == AES_BASE);
//// Write the length register by shifting the 64-bit ui64Length.//HWREG(ui32Base + AES_O_C_LENGTH_0) = (uint32_t)(ui64Length);HWREG(ui32Base + AES_O_C_LENGTH_1) = (uint32_t)(ui64Length >> 32);
}

AESDataProcess这个函数定义明文与密文是16字节的倍数,而我的程序试过好多不是16的倍数都可以正确的加密解密
#defineENCRYPT_LEN_MAX19
uint8_tg_pui8AESPlainText[ENCRYPT_LEN_MAX];
uint8_tg_pui8AESCipherText[ENCRYPT_LEN_MAX];
uint32_t ui32Keysize, startTick,endTick;
voidAES_cbcTest(void)
{uint32_t i;#if1for(i=0;i<ENCRYPT_LEN_MAX;i++)g_pui8AESPlainText[i]=i;AESCBCEncrypt(gTcpAesPara.Mode, (uint32_t*)g_pui8AESPlainText, (uint32_t*)g_pui8AESCipherText,(uint32_t*)gTcpAesPara.Aes192,(uint32_t*)gTcpAesPara.AESIV,ENCRYPT_LEN_MAX);//字节数//解密for(i=0;i<ENCRYPT_LEN_MAX;i++)g_pui8AESPlainText[i]=0;AESCBCDecrypt(gTcpAesPara.Mode,(uint32_t*)g_pui8AESCipherText,(uint32_t*)g_pui8AESPlainText,(uint32_t*)gTcpAesPara.Aes192,(uint32_t*)gTcpAesPara.AESIV,ENCRYPT_LEN_MAX);#endif
}

Susan Yang:

这个问题我已经转给了相关的同事,请您等待一下

user4346240:

回复 Susan Yang:

已经知道 明文若不是16的倍数,实际操作的是16的倍数,因此明文需要16的倍数!

赞(0)
未经允许不得转载:TI中文支持网 » TM4C129 AES CBC模式加解密官方例子都没有看到在哪里设置填充模式
分享到: 更多 (0)