-
- if ( !WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return -1;
- if ( !(resp.arg[0] & 0xff)) return -2;
-
- uint8_t enc_resp[8] = { 0 };
- uint8_t resp_random_a[8] = { 0 };
- memcpy(enc_resp, resp.d.asBytes+1, 8);
-
- des3_set2key_dec(&ctx, key);
- // context, mode, length, IV, input, output
- des3_crypt_cbc( &ctx, DES_DECRYPT, 8, enc_random_b, enc_resp, resp_random_a);
-
- if ( !memcmp(resp_random_a, random_a, 8))
- return 1;
- return 0;
-
- //PrintAndLog(" RndA :%s", sprint_hex(random_a, 8));
- //PrintAndLog(" enc(RndB) :%s", sprint_hex(enc_random_b, 8));
- //PrintAndLog(" RndB :%s", sprint_hex(random_b, 8));
- //PrintAndLog(" A+B :%s", sprint_hex(random_a_and_b, 16));
- //PrintAndLog(" enc(A+B) :%s", sprint_hex(random_a_and_b, 16));
- //PrintAndLog(" enc(RndA') :%s", sprint_hex(data2+1, 8));
-}
-
-/**
-A test function to validate that the polarssl-function works the same
-was as the openssl-implementation.
-Commented out, since it requires openssl
-
-int CmdTestDES(const char * cmd)
-{
- uint8_t key[16] = {0x00};
-
- memcpy(key,key3_3des_data,16);
- DES_cblock RndA, RndB;
-
- PrintAndLog("----------OpenSSL DES implementation----------");
- {
- uint8_t e_RndB[8] = {0x00};
- unsigned char RndARndB[16] = {0x00};
-
- DES_cblock iv = { 0 };
- DES_key_schedule ks1,ks2;
- DES_cblock key1,key2;
-
- memcpy(key,key3_3des_data,16);
- memcpy(key1,key,8);
- memcpy(key2,key+8,8);
-
-
- DES_set_key((DES_cblock *)key1,&ks1);
- DES_set_key((DES_cblock *)key2,&ks2);
-
- DES_random_key(&RndA);
- PrintAndLog(" RndA:%s",sprint_hex(RndA, 8));
- PrintAndLog(" e_RndB:%s",sprint_hex(e_RndB, 8));
- //void DES_ede2_cbc_encrypt(const unsigned char *input,
- // unsigned char *output, long length, DES_key_schedule *ks1,
- // DES_key_schedule *ks2, DES_cblock *ivec, int enc);
- DES_ede2_cbc_encrypt(e_RndB,RndB,sizeof(e_RndB),&ks1,&ks2,&iv,0);
-
- PrintAndLog(" RndB:%s",sprint_hex(RndB, 8));
- rol(RndB,8);
- memcpy(RndARndB,RndA,8);
- memcpy(RndARndB+8,RndB,8);
- PrintAndLog(" RA+B:%s",sprint_hex(RndARndB, 16));
- DES_ede2_cbc_encrypt(RndARndB,RndARndB,sizeof(RndARndB),&ks1,&ks2,&e_RndB,1);
- PrintAndLog("enc(RA+B):%s",sprint_hex(RndARndB, 16));
-