title: How to generate key schedule for openssl 3des decryption on iphone
body: <p>I need to decrypt some data that has been 3des encoded on system running mono (C#)</p>
  
  <p>I need to use openssl and decrypt on the iPhone.</p>
  
  <p>I found an example which looks like this, and it runs without error on the iphone when I have openssl etc installed, but generates the wrong result for my test case which I've verified on the encoding system. The initialisation vector is correct, but what should I set the key schedule to since the only information I have is the input? </p>
  
  <pre><code>   DES_cblock ivec[] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};   
     DES_key_schedule  ks1, ks2, ks3; 
  
     // What (and how) should I set ks1/2/3 to?
  
     DES_ede3_cbc_encrypt(input,output, 24*8, &amp;ks1, &amp;ks2, &amp;ks3,ivec, DES_DECRYPT);
  </code></pre>
  
  <p>The decoding on the mono system is done with the following code; </p>
  
  <pre><code>   TripleDESCryptoServiceProvider m_des = new TripleDESCryptoServiceProvider();
  
     byte[] IV ={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
     m_des.KeySize = 24*8;
  
     MemoryStream memStream = new MemoryStream();
     CryptoStream cryptStream = new CryptoStream(memStream,m_des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
  
     cryptStream.Write(input, 0, input.Length);
     cryptStream.FlushFinalBlock();
  </code></pre>
  
  <p>As far as I can tell, the key schedule isn't being specified, so I don't know what to set it to? I guess it gets derived from the key ... penny starting to drop ... but how?</p>
  
  <p>Any ideas? (ideally from people with openssl expertise, use of this library is a pre-requisite for the project)</p>