title: Client-side encryption over HTTP with Diffie-Hellman Key Exchange and AES
body: <p>After watching a YouTube video on the <a href="http://www.youtube.com/watch?v=3QnD2c4Xovk">Diffie-Hellman Key Exchange</a>, I wanted to try an implementation in JavaScript (Atwood's law).</p>
  
  <p>I sketched up an cipher on Node.js with the following rules:</p>
  
  <ul>
  <li><p>Step 1: Client and server agree on a shared key:</p>
  
  <ul>
  <li><p>Client &amp; server start with a 512bit prime public key pK</p></li>
  <li><p>Client generates a 512bit prime private key kC and sends powMod(3, kC, pK)</p></li>
  <li><p>Server generates a 512bit prime private key kS and sends powMod(3, kS, pK)</p></li>
  <li><p>Client &amp; Server use powMod(response, privatekey, pK) as the shared key</p></li>
  </ul></li>
  <li><p>Step 2: Communication</p>
  
  <ul>
  <li><p>Before a client sends data it is encrypted with the shared key using the Stanford Javascript Crypto Library (256bit AES, HMAC authentication, PBKDF2 password strengthening, and CCM authenticated-encryption.)</p></li>
  <li><p>Once the server decrypts the data with the shared key, it generates a new 512bit prime private key and sends it as a SJCL encrypted response.</p></li>
  <li><p>The client and server switch to a new shared key using powMod(3, prevSharedKey, newPrivKey)</p></li>
  </ul></li>
  </ul>
  
  <p>Now I have a few questions..</p>
  
  <p>How secure would such a system be in comparison with HTTPS or other algorithms?  What are the weakest points of such a system?</p>
  
  <p>In terms of security / practicality, would it be better to use 1024 bit keys for stronger security?  Are the HMAC/PBKDF2/CCM options overkill?  Is it worth modulating the shared key?  Thanks for reading!</p>