Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Triple DES ECB Decryption Fails on Last Block


  • Please log in to reply
No replies to this topic

#1 arunsoman

arunsoman

  • Members
  • 1 posts
  • OFFLINE
  •  
  • Local time:12:36 AM

Posted 27 July 2017 - 05:45 AM

HI,

Currently I am working on a embedded device project . It requires Triple DES ECB decryption using 24 byte key.

I am using the code from mbedtls library for the decryption . the problem is for some crypt text i am getting corrupted blocks on decryption. 

 

this is the TEST key i am using 

 

 char des3_test_keys1[] = "KEYBS87654321KEY01112013";

 

 and the crypt text is  

 

char des3_test_buf[] = "hZ+JjLErMq4UcVboAGWc0w==";

 

and the code for the decryption is  the following 

 

int Decrypt_Pin(char* value,char* out)
{
int i, j, u, v, ret = 0,part=0,enclen=0;
mbedtls_des_context ctx;
mbedtls_des3_context ctx3;
unsigned char buf[60];// = { "400111996242" };
 
unsigned char prv[8];
unsigned char iv[8];
 
unsigned char * base64_out=NULL;
unsigned char dec_block[40];
unsigned int len = 0;
mbedtls_des_init(&ctx);
mbedtls_des3_init(&ctx3);
/*
* ECB mode
*/
std::string vl{ value };
std::string output = base64_decode1(vl);
len = output.length();
part = len / 8;
enclen = len % 8;
if (enclen > 0)
part = part + 1;
memset(dec_block,0x04, len + 1);
dec_block[len + 1] = '\0';
strncpy((char*)dec_block,(char*)output.c_str(),len);
 
mbedtls_des3_set3key_dec(&ctx3, des3_test_keys);
for (i = 0; i < part; i++)
{
 
mbedtls_des3_crypt_ecb(&ctx3, (unsigned char*)&dec_block[i*8], &buf[i*8 ]);
 
}
strcpy(out, (const char*)buf);
out[len] = '\0';
printf("decrypted string :%s", out);
mbedtls_des_free(&ctx);
mbedtls_des3_free(&ctx3);
 
return(ret);
}


BC AdBot (Login to Remove)

 


m



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users