The Implementation of ALG_DES_MAC8_ISO9797_1_M2_ALG3

本文介绍如何在JavaCard环境中实现DES MAC8 (ALG_DES_MAC8_ISO9797_1_M2_ALG3)算法。该算法使用双DES密钥生成8字节的消息认证码(MAC),遵循ISO9797-1标准中的MAC算法3及方法2。具体步骤包括对数据进行填充、使用CBC和ECB模式进行加密和解密。

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

In order to work with the Java Card, we need to implement the algorithm ALG_DES_MAC8_ISO9797_1_M2_ALG3 outside the card.

 

Here is the instruction from Java Card Application Programming Interface:

 

public static final byte ALG_DES_MAC8_ISO9797_1_M2_ALG3Signature algorithm ALG_DES_MAC8_ISO9797_1_M2_ALG3 generates an 8-byte MAC using a 2-key DES3 key according to ISO9797-1 MAC algorithm 3 with method 2 (also EMV'96, EMV'2000), where input data is padded using method 2 and the data is processed as described in MAC Algorithm 3 of the ISO 9797-1 specification. The left key block of the triple DES key is used as a single DES key(K) and the right key block of the triple DES key is used as a single DES Key (K') during MAC processing. The final result is truncated to 8 bytes as described in ISO9797-1.

 

The instruction is too simple to implement the algorithm, so I have to get into the other document, and csme into the calculation process:

1, Pad the data to be signed with method 2:

2, Encrypt the padded data with K1 in DES CBC mode

3, Decrypt the last block with K2 in DES ECB mode

4, Encrypt the last block with K1 in DES ECB mode

Then the last block is our signature.

 

 

The Padding method:

Pad the message M according to ISO 7816-4 (which is equivalent to method 2 of ISO/IEC 9797), hence add a mandatory ‘80’ byte to the right of MSG, and then add the smallest number of ‘00’ bytes to the right such that the length of resulting message MSG := (MSG || ‘80’ || ‘00’ || ‘00’ || . . . || ‘00’) is a multiple of 8 bytes.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值