X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/fe8ab488e9161c46dd9885d58fc52996dc0249ff..5ba3f43ea354af8ad55bea84372a2bc834d8757c:/osfmk/corecrypto/ccdigest/src/ccdigest_update.c diff --git a/osfmk/corecrypto/ccdigest/src/ccdigest_update.c b/osfmk/corecrypto/ccdigest/src/ccdigest_update.c index 1f8b9e54b..089928f99 100644 --- a/osfmk/corecrypto/ccdigest/src/ccdigest_update.c +++ b/osfmk/corecrypto/ccdigest/src/ccdigest_update.c @@ -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 #include 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);