AES-CMAC加密算法使用

本文详细介绍了如何使用AES-CMAC算法对大文件进行分块加密,确保文件完整性的检查。通过将文件分成start、mid和end三个部分进行加密,经验证,分块加密的结果与整体加密一致,证明了这种方法的有效性。CMAC算法在文件传输中起到关键的校验作用,确保数据在传输过程中的安全性。

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

AES-CMAC加密算法使用

AES-CMAC加密算法对于大文件的分开加密算法的介绍

由于公司项目的需求,需要使用AES-CMAC算法对文件进行加密,将加密后的密文附带到文件的后边,都发送出去,接收方收到文件后,也按照AES-CMAC算法进行加密,将加密得到的密文与发送过来的进行比较,如果一致,说明接收的文件没有被破坏,这样就实现了对文件完整性的检查。

CMAC算法示意图
由图可知,我们需要两个秘钥,K1 K2,然后将文件按照一定的长度进行加密,将前一次的加密结果作为中间值,与后一次的文件进行CMAC,最后一段文件,按照是否为CMAC分组的整数倍进行加密,如果是,则将K1添加,如果不是,则添加K2

  1. CMAC的算法实现
    CMAC算法是基于AES算法的,具体可以参考AES算法,在这里我就不做过多的介绍了,先看结果,然后再详细介绍。

实现方式

由于发送的文件较大,可能程序不能一次加载完成,所以对于CMAC的加密,也需要分开来进行,我这里主要分成了3个部分,start(开始部分),mid(中间部分,处理的代码较多,执行循环操作,多次调用mid函数),end(处理最后的部分,用于将K1 K2添加进去),<

详细介绍了AES-CMAC的算法的原理与实现,附有C语言写的样例程序。 以下是原文的introduction: The National Institute of Standards and Technology (NIST) has recently specified the Cipher-based Message Authentication Code(CMAC). CMAC [NIST-CMAC] is a keyed hash function that is based on a symmetric key block cipher, such as the Advanced Encryption Standard [NIST-AES]. CMAC is equivalent to the One-Key CBC MAC1 (OMAC1) submitted by Iwata and Kurosawa [OMAC1a, OMAC1b]. OMAC1 is an improvement of the eXtended Cipher Block Chaining mode (XCBC) submitted by Black and Rogaway [XCBCa, XCBCb], which itself is an improvement of the basic Cipher Block Chaining-Message Authentication Code (CBC-MAC). XCBC efficiently addresses the security deficiencies of CBC-MAC, and OMAC1 efficiently reduces the key size of XCBC. AES-CMAC provides stronger assurance of data integrity than a checksum or an error-detecting code. The verification of a checksum or an error-detecting code detects only accidental modifications of the data, while CMAC is designed to detect intentional, unauthorized modifications of the data, as well as accidental modifications. AES-CMAC achieves a security goal similar to that of HMAC [RFC-HMAC]. Since AES-CMAC is based on a symmetric key block cipher, AES, and HMAC is based on a hash function, such as SHA-1, AES-CMAC is appropriate for information systems in which AES is more readily available than a hash function. This memo specifies the authentication algorithm based on CMAC with AES-128. This new authentication algorithm is named AES-CMAC.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值