title: AES ECB known-text attack
body: <p>I'm trying to perform known-text attack to obtain 32 byte key.
  BlockSize is 16 byte.</p>
  
  <p>Regarding this: <a href="https://crypto.stackexchange.com/a/12512">https://crypto.stackexchange.com/a/12512</a></p>
  
  <p>Or this: <a href="https://security.stackexchange.com/a/102110">https://security.stackexchange.com/a/102110</a></p>
  
  <p>As far as I understood:</p>
  
  <p>1) Encrypt known 15 byte block</p>
  
  <p>2) Encrypt known 256 16 byte blocks with different tailing byte</p>
  
  <p>3) Compare blocks and get one byte of secret</p>
  
  <pre><code>void test() {
      unsigned char KnownText[15];
      memset(KnownText, 'A', 15);
  
      unsigned char EncryptedText[32];
      int result_size = AES_ECB.EncryptBlock(EncryptedText, KnownText, 15);
  
      unsigned char CKnownText[16];
      for (int i = 0; i &lt; 256; ++i) {
          memset(CKnownText, 'A', 16);
          CKnownText[15] = i;
  
          unsigned char Encrypted[32];
          int enc_result = AES_ECB.EncryptBlock(Encrypted, CKnownText, 16);
  
          if(memcmp(EncryptedText, Encrypted, 16) == 0) {
              //match found
          }
      }
  }
  </code></pre>
  
  <p>I get only one match when i=0 (suppose because 0 was appended to first 15 byte block) and it is not even any of secret key bytes.</p>
  
  <p>I can encrypt any length of any known data and get encrypted result.</p>
  
  <p>How can I get the key using this attack?</p>