title: CC_SHA256 generates same output for different input
body: <p>Here's a basic CC_SHA256 example:</p>
  
  <pre><code>-(void)hash:(NSData *)input
  {
      NSLog(@"Input is %@", [self NSDataToHex:input]);
  
      NSMutableData *result = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH];
  
      CC_SHA256(CFBridgingRetain(input), input.length, result.mutableBytes);
  
      NSLog(@"RESULT is %@", result);
  }
  </code></pre>
  
  <p>This algorithm appears to be working correctly. A little test:</p>
  
  <pre><code>NSString* str = @"abcde";
  NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
  
  [self hash:data];
  
  NSString* str2 = @"fghijk";
  NSData* data2 = [str2 dataUsingEncoding:NSUTF8StringEncoding];
  
  [self hash:data2];
  </code></pre>
  
  <p>Gives the following output:</p>
  
  <pre><code>Input is 6162636465
  RESULT is &lt;91681b5f 162cf494 238e5cac 0debbe92 c3ede9bf 4bcc7e79 845b774f b33e99f7&gt;
  Input is 666768696A6B
  RESULT is &lt;cccf7b6f 9acb96ae 84e9852b 1a753825 d6750555 57175c78 f86cf5fb bb3cfca7&gt;
  </code></pre>
  
  <p>Now, if I change the second argument (input.length) to 3, I get the following output:</p>
  
  <pre><code>Input is 6162636465
  RESULT is &lt;5e83c408 f722bb9a 9f602d85 c186bcb1 ebb8fa2f 0df2cc08 5eaf2522 92b01570&gt;
  Input is 666768696A6B
  RESULT is &lt;5e83c408 f722bb9a 9f602d85 c186bcb1 ebb8fa2f 0df2cc08 5eaf2522 92b01570&gt;
  </code></pre>
  
  <p>These hashes are the same. I would expect the CC_SHA256 algorithm to just hash the first 3 characters of my input, but apparently, it doesn't work like that. Furthermore, if I relaunch the simulator, the hashes that are generated are different than the first time (but still equal to each other).</p>
  
  <p>Why is this behaviour happening? Please don't give an (obvious) workaround for this problem. I really want to know why the algorithm behaves this way.</p>