]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/corecrypto/ccdigest/src/ccdigest_update.c
xnu-4570.1.46.tar.gz
[apple/xnu.git] / osfmk / corecrypto / ccdigest / src / ccdigest_update.c
index 1f8b9e54ba8d22c8d05ce4cb75fc365a41dc05e2..089928f99b02bb7dccfbb0eaf36fdecca30b5daa 100644 (file)
@@ -2,27 +2,64 @@
  *  ccdigest_update.c
  *  corecrypto
  *
- *  Created by Michael Brouwer on 11/30/10.
- *  Copyright 2010,2011 Apple Inc. All rights reserved.
+ *  Created on 11/30/2010
  *
+ *  Copyright (c) 2010,2011,2014,2015 Apple Inc. All rights reserved.
+ *
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ *
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
 #include <corecrypto/ccdigest.h>
 #include <corecrypto/cc_priv.h>
 
 void ccdigest_update(const struct ccdigest_info *di, ccdigest_ctx_t ctx,
-                     unsigned long len, const void *data) {
-    char * data_ptr = (char *) data;
+                     size_t len, const void *data) {
+    const char * data_ptr = data;
+    size_t nblocks, nbytes;
+
     while (len > 0) {
         if (ccdigest_num(di, ctx) == 0 && len > di->block_size) {
-            unsigned long nblocks = len / di->block_size;
+            //low-end processors are slow on divison
+            if(di->block_size == 1<<6 ){ //sha256
+                nblocks = len >> 6;
+                nbytes = len & 0xFFFFffC0;
+            }else if(di->block_size == 1<<7 ){ //sha512
+                nblocks = len >> 7;
+                nbytes = len & 0xFFFFff80;
+            }else {
+                nblocks = len / di->block_size;
+                nbytes = nblocks * di->block_size;
+            }
+
             di->compress(ccdigest_state(di, ctx), nblocks, data_ptr);
-            unsigned long nbytes = nblocks * di->block_size;
             len -= nbytes;
             data_ptr += nbytes;
             ccdigest_nbits(di, ctx) += nbytes * 8;
         } else {
-            unsigned long n = di->block_size - ccdigest_num(di, ctx);
+            size_t n = di->block_size - ccdigest_num(di, ctx);
             if (len < n)
                 n = len;
             CC_MEMCPY(ccdigest_data(di, ctx) + ccdigest_num(di, ctx), data_ptr, n);