]> git.saurik.com Git - apple/xnu.git/blame - osfmk/corecrypto/ccdigest/src/ccdigest_update.c
xnu-3248.60.10.tar.gz
[apple/xnu.git] / osfmk / corecrypto / ccdigest / src / ccdigest_update.c
CommitLineData
fe8ab488
A
1/*
2 * ccdigest_update.c
3 * corecrypto
4 *
3e170ce0
A
5 * Created on 11/30/2010
6 *
7 * Copyright (c) 2010,2011,2014,2015 Apple Inc. All rights reserved.
fe8ab488
A
8 *
9 */
10
11#include <corecrypto/ccdigest.h>
12#include <corecrypto/cc_priv.h>
13
14void ccdigest_update(const struct ccdigest_info *di, ccdigest_ctx_t ctx,
15 unsigned long len, const void *data) {
3e170ce0 16 const char * data_ptr = data;
fe8ab488
A
17 while (len > 0) {
18 if (ccdigest_num(di, ctx) == 0 && len > di->block_size) {
19 unsigned long nblocks = len / di->block_size;
20 di->compress(ccdigest_state(di, ctx), nblocks, data_ptr);
21 unsigned long nbytes = nblocks * di->block_size;
22 len -= nbytes;
23 data_ptr += nbytes;
24 ccdigest_nbits(di, ctx) += nbytes * 8;
25 } else {
26 unsigned long n = di->block_size - ccdigest_num(di, ctx);
27 if (len < n)
28 n = len;
29 CC_MEMCPY(ccdigest_data(di, ctx) + ccdigest_num(di, ctx), data_ptr, n);
30 /* typecast: less than block size, will always fit into an int */
31 ccdigest_num(di, ctx) += (unsigned int)n;
32 len -= n;
33 data_ptr += n;
34 if (ccdigest_num(di, ctx) == di->block_size) {
35 di->compress(ccdigest_state(di, ctx), 1, ccdigest_data(di, ctx));
36 ccdigest_nbits(di, ctx) += ccdigest_num(di, ctx) * 8;
37 ccdigest_num(di, ctx) = 0;
38 }
39 }
40 }
41}