title: CryptoSwift with AES128 CTR Mode - Buggy counter increment?
body: <p>i've encountered a problem on the <code>CryptoSwift-API (krzyzanowskim)</code> while using <code>AES128</code> with the <code>CTR-Mode</code> and my test function <code>(nullArrayBugTest())</code> that produces on specific counter values (between 0 and 25 = on 13 and 24) a wrong array count that should usually be 16!
  Even if I use the manually incremented "iv_13" with the buggy value 13 instead of the default "iv_0" and the counter 13...
   Test it out to get an idea what I mean.</p>
  
  <pre><code>  func nullArrayBugTest() {
      var ctr:CTR
      let nilArrayToEncrypt = Data(hex: "00000000000000000000000000000000")
      let key_ = Data(hex: "000a0b0c0d0e0f010203040506070809")
      let iv_0:  Array&lt;UInt8&gt; = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
      //let iv_13:  Array&lt;UInt8&gt; = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x1c]
      var decryptedNilArray = [UInt8]()
  
      for i in 0...25 {
          ctr = CTR(iv: iv_0, counter: i)
          do {
              let aes = try AES(key: key_.bytes, blockMode: ctr)
              decryptedNilArray = try aes.decrypt([UInt8](nilArrayToEncrypt))
              print("AES_testcase_\(i) for ctr: \(ctr) withArrayCount: \(decryptedNilArray.count)")
          }catch {
              print("De-/En-CryptData failed with: \(error)")
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/nCTNK.png" rel="nofollow noreferrer">Output with buggy values</a></p>
  
  <p>The question why I always need the encrypted array with 16 values is not important :D.</p>
  
  <p>Does anybody know why the <code>aes.decrypt()</code>-function handles that like I received?</p>
  
  <p>Thanks for your time. </p>
  
  <p>Michael S.</p>