title: Is the SecKeyRawSign/SecKeyRawVerify API implementation modified on macos10.15beta?
body: <p>First we may need to determine if SecKeyRawSign/SecKeyRawVerify can be used on macos, otherwise the discussion below will have no meaning. The API document is classified as Legacy iOS Key Operations, and the version that supports macos is not displayed on the API description page, so I don't know if using this API in macos will cause some unknown problems. The following discussion and testing is based on this API that can be used on macos.</p>
  
  <p>Background: Obtain data and signature from the server, verify on the client, verify successfully on macos 10.14, return error code -9809 (errSSLCrypto) on macos 10.15.</p>
  
  <p>Here is the case where I found the problem when testing.</p>
  
  <pre><code>-(void)case3
  {
      NSLog(@"case 3: test sign");
      // get publicKey/privateKey
      SecKeyRef publicKeyRef = [self getPublicKey:ipublickey];
      SecKeyRef privateKeyRef = [self getPrivateKey:iprivatekey];
  
      size_t signedHashBytesSize = SecKeyGetBlockSize(privateKeyRef) * sizeof(uint8_t);
      unsigned char *signedHashBytes = malloc(signedHashBytesSize);
  
      NSString *plainString = @"0";
      for (int i = 0; i &lt; 2000; ++i) {
          memset(signedHashBytes, 0, signedHashBytesSize);
          NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding];
  
          // use raw data sign
          OSStatus status = SecKeyRawSign(privateKeyRef,
                                          kSecPaddingPKCS1SHA1,
                                          plainData.bytes,
                                          plainData.length,
                                          signedHashBytes,
                                          &amp;signedHashBytesSize);
          if (status != noErr) {
              NSLog(@"raw data sign failed. data.length:%lu",
                      (unsigned long)plainData.length);
              break;
          }
  
          NSData *resultData = [[NSData alloc] initWithBytes:signedHashBytes
                                                      length:signedHashBytesSize];
  
          status = SecKeyRawVerify(publicKeyRef,
                                   kSecPaddingPKCS1SHA1,
                                   plainData.bytes,
                                   plainData.length,
                                   [resultData bytes],
                                   [resultData length]);
          if (status != noErr) {
              NSLog(@"plainData.bytes, plainData.length Verify Failed");
          }
          plainString = [plainString stringByAppendingString:@"0"];
      }
  
      plainString = @"0";
      for (int i = 0; i &lt; 2000; ++i) {
          memset(signedHashBytes, 0, signedHashBytesSize);
          NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding];
          size_t hashBytesSize = CC_SHA1_DIGEST_LENGTH;
          uint8_t* hashBytes = malloc(hashBytesSize);
          unsigned char *r = CC_SHA1([plainData bytes],
                                     (CC_LONG)[plainData length], hashBytes);
          if (r == NULL) {
              NSLog(@"SHA Failed");
          }
  
          // use raw data sign
          OSStatus status = SecKeyRawSign(privateKeyRef,
                                          kSecPaddingPKCS1SHA1,
                                          hashBytes,
                                          hashBytesSize,
                                          signedHashBytes,
                                          &amp;signedHashBytesSize);
          if (status != noErr) {
              NSLog(@"hash data sign failed. data.length:%lu",
                      (unsigned long)plainData.length);
              break;
          }
  
          NSData *resultData = [[NSData alloc] initWithBytes:signedHashBytes
                                                      length:signedHashBytesSize];
  
          status = SecKeyRawVerify(publicKeyRef,
                                   kSecPaddingPKCS1SHA1,
                                   hashBytes,
                                   hashBytesSize,
                                   [resultData bytes],
                                   [resultData length]);
          if (status != noErr) {
              NSLog(@"hashBytes, hashBytesSize Verify Failed");
              break;
          }
  
          free(hashBytes);
          plainString = [plainString stringByAppendingString:@"0"];
      }
      free(signedHashBytes);
  
      NSLog(@"\n\n");
  }
  </code></pre>
  
  <p>macos 10.14 result</p>
  
  <pre><code>2019-08-20 04:23:04.017740-0400 Demo[43169:2170797] case 3: test sign
  </code></pre>
  
  <p>macos 10.15 result</p>
  
  <pre><code>2019-08-20 05:23:04.017740-0400 Demo[43169:2170797] case 3: test sign
  2019-08-20 05:23:06.534971-0400 Demo[43169:2170797] raw data sign failed. data.length:103
  </code></pre>
  
  <p>Based on the above test I modified my verification code.</p>
  
  <pre><code>size_t hashBytesSize = CC_SHA1_DIGEST_LENGTH;
  uint8_t* hashBytes = malloc(hashBytesSize);
  unsigned char *sha_result = CC_SHA1([data bytes],
                                      (CC_LONG)[data length],
                                      hashBytes);
  if (sha_result == NULL) {
      NSLog(@"SHA Failed");
      return NO;
  }
  
  // work in macos 10.15
  OSStatus ret = SecKeyRawVerify(publicKeyRef,
                                  kSecPaddingPKCS1SHA1,
                                  hashBytes,
                                  hashBytesSize,
                                  signData.bytes,
                                  signData.length);
  if (ret != noErr) {
      NSLog(@"hash data verify failed.");
  }
  // work in macos 10.14
  ret = SecKeyRawVerify(publicKeyRef,
                          kSecPaddingPKCS1SHA1,
                          data.bytes,
                          data.length,
                          signData.bytes,
                          signData.length);
  if (ret != noErr) {
      NSLog(@"raw data verify failed.");
  }
  </code></pre>
  
  <p>I don't know why using hash data on macos 10.15beta will pass validation and macos 10.14 won't. Is the SecKeyRawSign/SecKeyRawVerify API embedding CC_SHA1 on macos 10.14?</p>