@@ -204,29 +204,30 @@ static void generate_command_wrapping(uint8_t *command_Header, int command_heade
204204 uint8_t asn1_tag_cryptograph [2 ] = {0x85 , ARRAYLEN (padded_encrypted_Command )};
205205 uint8_t asn1_tag_mac [2 ] = {0x8e , 0x08 };
206206 uint8_t command_trailer [2 ] = {0x97 , 0x00 };
207- int padded_command_trailer_len = ARRAYLEN (command_trailer );
208- uint8_t padded_command_trailer [padded_command_trailer_len + block_size ];
209- padToBlockSize (command_trailer , & padded_command_trailer_len , block_size , padded_command_trailer );
210207
211- uint8_t toEncrypt [ARRAYLEN (rndCounter ) + padded_Command_Header_len + ARRAYLEN (asn1_tag_cryptograph ) + ARRAYLEN (padded_encrypted_Command ) + padded_command_trailer_len ];
208+ uint8_t toEncrypt [ARRAYLEN (rndCounter ) + padded_Command_Header_len + ARRAYLEN (asn1_tag_cryptograph ) + ARRAYLEN (padded_encrypted_Command ) + ARRAYLEN ( command_trailer ) ];
212209
213210 memcpy (toEncrypt , rndCounter , ARRAYLEN (rndCounter ));
214211 memcpy (toEncrypt + ARRAYLEN (rndCounter ), padded_Command_Header , padded_Command_Header_len );
215212 memcpy (toEncrypt + ARRAYLEN (rndCounter ) + padded_Command_Header_len , asn1_tag_cryptograph , ARRAYLEN (asn1_tag_cryptograph ));
216213 memcpy (toEncrypt + ARRAYLEN (rndCounter ) + padded_Command_Header_len + ARRAYLEN (asn1_tag_cryptograph ), padded_encrypted_Command , ARRAYLEN (padded_encrypted_Command ));
217- memcpy (toEncrypt + ARRAYLEN (rndCounter ) + padded_Command_Header_len + ARRAYLEN (asn1_tag_cryptograph ) + ARRAYLEN (padded_encrypted_Command ), padded_command_trailer , padded_command_trailer_len );
214+ memcpy (toEncrypt + ARRAYLEN (rndCounter ) + padded_Command_Header_len + ARRAYLEN (asn1_tag_cryptograph ) + ARRAYLEN (padded_encrypted_Command ), command_trailer , ARRAYLEN (command_trailer ));
215+
216+ int padded_toEncrypt_len = ARRAYLEN (toEncrypt );
217+ uint8_t padded_toEncrypt [padded_toEncrypt_len + block_size ];
218+ padToBlockSize (toEncrypt , & padded_toEncrypt_len , block_size , padded_toEncrypt );
218219
219220 // Breakdown
220221 // 0181e43801010201 + 0000000000000001 + 0CCB3FFF800000000000000000000000 + 8510EB54DA90CB43AEE7FBFE816ECA25A10D + 9700 + 800000000000000000000000
221222
222223 uint8_t mac [8 ];
223- create_cmac (diversified_mac_key , toEncrypt , mac , sizeof ( toEncrypt ) , encryption_algorithm );
224+ create_cmac (diversified_mac_key , padded_toEncrypt , mac , padded_toEncrypt_len , encryption_algorithm );
224225
225226 // PrintAndLogEx(SUCCESS, "Encryption Key................... " _YELLOW_("%s"), sprint_hex_inrow(diversified_enc_key, 24));
226227 // PrintAndLogEx(SUCCESS, "MAC Key.......................... " _YELLOW_("%s"), sprint_hex_inrow(diversified_mac_key, 24));
227228 // PrintAndLogEx(SUCCESS, "rndCounter....................... " _YELLOW_("%s"), sprint_hex_inrow(rndCounter,sizeof(rndCounter)));
228229 // PrintAndLogEx(SUCCESS, "padded_encrypted_Command......... " _YELLOW_("%s"), sprint_hex_inrow(padded_encrypted_Command,sizeof(padded_encrypted_Command)));
229- // PrintAndLogEx(SUCCESS, "toEncrypt ........................ " _YELLOW_("%s"), sprint_hex_inrow(toEncrypt,sizeof(toEncrypt) ));
230+ // PrintAndLogEx(SUCCESS, "padded_toEncrypt ................. " _YELLOW_("%s"), sprint_hex_inrow(padded_toEncrypt,padded_toEncrypt_len ));
230231 // PrintAndLogEx(SUCCESS, "MAC.............................. " _YELLOW_("%s"), sprint_hex_inrow(mac,sizeof(mac)));
231232
232233 uint8_t sizeofcommand [1 ] = {ARRAYLEN (asn1_tag_cryptograph ) + ARRAYLEN (padded_encrypted_Command ) + ARRAYLEN (command_trailer ) + ARRAYLEN (asn1_tag_mac ) + ARRAYLEN (mac )};
0 commit comments