]>
Commit | Line | Data |
---|---|---|
d9c0dbb0 CMN |
1 | /* |
2 | * Copyright (C) the libgit2 contributors. All rights reserved. | |
3 | * | |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
7 | ||
22a2d3d5 | 8 | #include "common_crypto.h" |
d9c0dbb0 | 9 | |
eae0bfdc PP |
10 | #define CC_LONG_MAX ((CC_LONG)-1) |
11 | ||
22a2d3d5 | 12 | int git_hash_sha1_global_init(void) |
ac3d33df JK |
13 | { |
14 | return 0; | |
15 | } | |
16 | ||
22a2d3d5 UG |
17 | int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) |
18 | { | |
19 | return git_hash_sha1_init(ctx); | |
20 | } | |
21 | ||
22 | void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) | |
23 | { | |
24 | GIT_UNUSED(ctx); | |
25 | } | |
26 | ||
27 | int git_hash_sha1_init(git_hash_sha1_ctx *ctx) | |
d9c0dbb0 | 28 | { |
c25aa7cd | 29 | GIT_ASSERT_ARG(ctx); |
d9c0dbb0 CMN |
30 | CC_SHA1_Init(&ctx->c); |
31 | return 0; | |
32 | } | |
33 | ||
22a2d3d5 | 34 | int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len) |
d9c0dbb0 | 35 | { |
eae0bfdc PP |
36 | const unsigned char *data = _data; |
37 | ||
c25aa7cd | 38 | GIT_ASSERT_ARG(ctx); |
eae0bfdc PP |
39 | |
40 | while (len > 0) { | |
41 | CC_LONG chunk = (len > CC_LONG_MAX) ? CC_LONG_MAX : (CC_LONG)len; | |
42 | ||
43 | CC_SHA1_Update(&ctx->c, data, chunk); | |
44 | ||
45 | data += chunk; | |
46 | len -= chunk; | |
47 | } | |
48 | ||
d9c0dbb0 CMN |
49 | return 0; |
50 | } | |
51 | ||
e579e0f7 | 52 | int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx) |
d9c0dbb0 | 53 | { |
c25aa7cd | 54 | GIT_ASSERT_ARG(ctx); |
e579e0f7 | 55 | CC_SHA1_Final(out, &ctx->c); |
d9c0dbb0 CMN |
56 | return 0; |
57 | } |