0

When I am encrypting data with CCCrypt() with 3DES algorithm I have to provide 24bytes long key like for 3TDEA option of 3DES. From a reason I have use 2TDEA with 16bytes long key. But when I use 16byte key, CCCrypt() fails. What to do with it?

result = CCCrypt(kCCEncrypt, 
                 kCCAlgorithm3DES, 
                 kCCOptionPKCS7Padding | kCCOptionECBMode, 
                 desKey, 
                 24, 
                 nil,
                 dataBlock, 
                 dataBlockSize, 
                 outputData.mutableBytes, 
                 outputData.length, 
                 &outLength); 
  • Don't. [It's obsolete and not secure.](https://www.researchgate.net/publication/301898398_On_the_security_of_2-key_triple_DES). Get first 8 bytes of the key and append them at the end (xxxxxxxxyyyyyyyy -> xxxxxxxxyyyyyyyyxxxxxxxx). – zrzka Jun 10 '20 at 19:12
  • I do not have a choice, it's client's requirement :-/ I have almost no chance to influence how the key will be handled on server. They simply expect 2TDES encryption and the 112bit key delivered in another way. When I encode it this way, they will not decode it by this 112bit key until they adjust algorithm, right? – Jindřich Skeldal Jun 10 '20 at 20:09
  • [Triple DES - Keying options](https://en.wikipedia.org/wiki/Triple_DES#Keying_options) - Keying option 2 - K1 and K2 are independent, and K3 = K1. Sometimes known as 2TDEA or double-length keys. – zrzka Jun 10 '20 at 20:28
  • Oh my! You are right! Thank you! – Jindřich Skeldal Jun 10 '20 at 20:47

1 Answers1

2

Disclaimer

Anyone who will read this:

It's obsolete, deprecated and not secure.

3DES & 2TDEA

Triple DES = 3DES, TDES, TDEA, Triple DEA. It has many names, but all of them refer to the same cipher. It's a DES applied three times to each data block.

You can visit Triple DES article on Wikipedia to learn more about it. Several Keying options exists and you're interested in the 2nd one:

K1 and K2 are independent, and K3 = K1. Sometimes known as 2TDEA or double-length keys. This provides a shorter key length of 112 bits and a reasonable compromise between DES and Keying option 1, with the same caveat as above. This is an improvement over "double DES" which only requires 256 steps to attack. NIST has deprecated this option.

You have 16 bytes (K1, K2). This keying option says that K3 = K1. Which means that you have to copy the first 8 bytes and append them.

  • AAAAAAAA11111111 (16 bytes, K1, K2)
  • AAAAAAAA11111111???????? (24 bytes, K1, K2, K3?)
  • AAAAAAAA11111111AAAAAAAA (24 bytes, K1, K2, K3 where K3 = K1)
zrzka
  • 20,249
  • 5
  • 47
  • 73