<story><title>Typing The Letters A-E-S Into Your Code? You’re Doing It Wrong</title><url>http://www.matasano.com/log/1749/typing-the-letters-a-e-s-into-your-code-youre-doing-it-wrong/</url></story><parent_chain></parent_chain><comment><author>tptacek</author><text>It&apos;s probably worth pointing out: you have the same problems if you&apos;re using CFB, OFB, or CTR mode (these are the &quot;stream cipher&quot; modes for DES/AES/whatever that encrypt one byte at a time). There&apos;s apocrypha about these modes not being vulnerable to the attack. Bad apocrypha:&lt;p&gt;Set up an encryptor:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  irb&amp;#62; e = OpenSSL::Cipher::Cipher.new(&apos;aes-256-ofb&apos;)
  =&amp;#62; #&amp;#60;OpenSSL::Cipher::Cipher:0x647100&amp;#62;
  irb&amp;#62; e.key = &quot;\x11&quot; * 32
  irb&amp;#62; e.iv = &quot;\x00&quot; * 16
&lt;/code&gt;&lt;/pre&gt;
A decryptor:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  irb&amp;#62; d = OpenSSL::Cipher::Cipher.new(&apos;aes-256-ofb&apos;)
  =&amp;#62; #&amp;#60;OpenSSL::Cipher::Cipher:0x647120&amp;#62;
  irb&amp;#62; d.decrypt
  irb&amp;#62; d.key = &quot;\x11&quot; * 32
  irb&amp;#62; d.iv = &quot;\x00&quot; * 16
 &lt;/code&gt;&lt;/pre&gt;
Encrypt something:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  irb&amp;#62; ciphertext = (e &amp;#60;&amp;#60; &quot;A * 40&quot;)
  =&amp;#62; &quot;a\255N\211XEn\001\347$\275)\311%Ht\2356\254m\b\234z\375\311\006\335\305F\231~\201\243\236\3628w\267\3454&quot;
&lt;/code&gt;&lt;/pre&gt;
Make an XOR mask:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  irb&amp;#62; mask = (&quot;187 she wrote&quot;.to_bignum ^ (&quot;A&quot; * 13).to_bignum).to_rawstring
  =&amp;#62; &quot;pyva2)$a63.5$&quot;
&lt;/code&gt;&lt;/pre&gt;
XOR it into the ciphertext:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  irb&amp;#62; new_ciphertext = (ciphertext.to_bignum ^ mask.to_bignum).to_rawstring
&lt;/code&gt;&lt;/pre&gt;
NOW decrypt it:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  irb&amp;#62; d &amp;#60;&amp;#60; nct
  =&amp;#62; &quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA187 she wrote&quot;&lt;/code&gt;&lt;/pre&gt;</text></comment>
<story><title>Typing The Letters A-E-S Into Your Code? You’re Doing It Wrong</title><url>http://www.matasano.com/log/1749/typing-the-letters-a-e-s-into-your-code-youre-doing-it-wrong/</url></story><parent_chain></parent_chain><comment><author>smanek</author><text>I didn&apos;t buy the GPG/TLS thing before. After reading this I do. I just realized how completely out of my depth I am for crypto stuff. At least now I know ...</text></comment>