+/**
+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));
+
+ }
+ PrintAndLog("----------PolarSSL implementation----------");
+ {
+ uint8_t random_a[8] = { 0 };
+ uint8_t enc_random_a[8] = { 0 };
+ uint8_t random_b[8] = { 0 };
+ uint8_t enc_random_b[8] = { 0 };
+ uint8_t random_a_and_b[16] = { 0 };
+ des3_context ctx = { 0 };
+
+ memcpy(random_a, RndA,8);
+
+ uint8_t output[8] = { 0 };
+ uint8_t iv[8] = { 0 };
+
+ PrintAndLog(" RndA :%s",sprint_hex(random_a, 8));
+ PrintAndLog(" e_RndB:%s",sprint_hex(enc_random_b, 8));
+
+ des3_set2key_dec(&ctx, key);
+
+ des3_crypt_cbc(&ctx // des3_context *ctx
+ , DES_DECRYPT // int mode
+ , sizeof(random_b) // size_t length
+ , iv // unsigned char iv[8]
+ , enc_random_b // const unsigned char *input
+ , random_b // unsigned char *output
+ );
+
+ PrintAndLog(" RndB:%s",sprint_hex(random_b, 8));
+
+ rol(random_b,8);
+ memcpy(random_a_and_b ,random_a,8);
+ memcpy(random_a_and_b+8,random_b,8);
+
+ PrintAndLog(" RA+B:%s",sprint_hex(random_a_and_b, 16));
+
+ des3_set2key_enc(&ctx, key);