]>
Commit | Line | Data |
---|---|---|
fe8ab488 A |
1 | /* |
2 | * ccdigest_final_64be.c | |
3 | * corecrypto | |
4 | * | |
3e170ce0 A |
5 | * Created on 12/06/2010 |
6 | * | |
7 | * Copyright (c) 2010,2011,2015 Apple Inc. All rights reserved. | |
fe8ab488 A |
8 | * |
9 | */ | |
10 | ||
11 | #include <corecrypto/ccdigest_priv.h> | |
12 | #include <corecrypto/cc_priv.h> | |
13 | ||
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; | |
19 | ||
20 | /* If we don't have at least 8 bytes (for the length) left we need to add | |
21 | a second block. */ | |
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; | |
25 | } | |
26 | di->compress(ccdigest_state(di, ctx), 1, ccdigest_data(di, ctx)); | |
27 | ccdigest_num(di, ctx) = 0; | |
28 | } | |
29 | ||
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; | |
33 | } | |
34 | ||
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)); | |
37 | ||
38 | /* copy output */ | |
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)); | |
41 | } | |
42 | } |