]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/corecrypto/ccsha1/src/ccdigest_final_64be.c
2 * ccdigest_final_64be.c
5 * Created on 12/06/2010
7 * Copyright (c) 2010,2011,2015 Apple Inc. All rights reserved.
11 #include <corecrypto/ccdigest_priv.h>
12 #include <corecrypto/cc_priv.h>
14 /* This can be used for SHA1, SHA256 and SHA224 */
15 void ccdigest_final_64be(const struct ccdigest_info
*di
, ccdigest_ctx_t ctx
,
16 unsigned char *digest
) {
17 ccdigest_nbits(di
, ctx
) += ccdigest_num(di
, ctx
) * 8;
18 ccdigest_data(di
, ctx
)[ccdigest_num(di
, ctx
)++] = 0x80;
20 /* If we don't have at least 8 bytes (for the length) left we need to add
22 if (ccdigest_num(di
, ctx
) > 64 - 8) {
23 while (ccdigest_num(di
, ctx
) < 64) {
24 ccdigest_data(di
, ctx
)[ccdigest_num(di
, ctx
)++] = 0;
26 di
->compress(ccdigest_state(di
, ctx
), 1, ccdigest_data(di
, ctx
));
27 ccdigest_num(di
, ctx
) = 0;
30 /* pad upto block_size minus 8 with 0s */
31 while (ccdigest_num(di
, ctx
) < 64 - 8) {
32 ccdigest_data(di
, ctx
)[ccdigest_num(di
, ctx
)++] = 0;
35 CC_STORE64_BE(ccdigest_nbits(di
, ctx
), ccdigest_data(di
, ctx
) + 64 - 8);
36 di
->compress(ccdigest_state(di
, ctx
), 1, ccdigest_data(di
, ctx
));
39 for (unsigned int i
= 0; i
< di
->output_size
/ 4; i
++) {
40 CC_STORE32_BE(ccdigest_state_u32(di
, ctx
)[i
], digest
+(4*i
));