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 
8 #include "mbedtls.h"
9 
git_hash_sha1_global_init(void)10 int git_hash_sha1_global_init(void)
11 {
12 	return 0;
13 }
14 
git_hash_sha1_ctx_init(git_hash_sha1_ctx * ctx)15 int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
16 {
17 	return git_hash_sha1_init(ctx);
18 }
19 
git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx * ctx)20 void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
21 {
22 	if (ctx)
23 		mbedtls_sha1_free(&ctx->c);
24 }
25 
git_hash_sha1_init(git_hash_sha1_ctx * ctx)26 int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
27 {
28 	GIT_ASSERT_ARG(ctx);
29 	mbedtls_sha1_init(&ctx->c);
30 	mbedtls_sha1_starts(&ctx->c);
31 	return 0;
32 }
33 
git_hash_sha1_update(git_hash_sha1_ctx * ctx,const void * data,size_t len)34 int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
35 {
36 	GIT_ASSERT_ARG(ctx);
37 	mbedtls_sha1_update(&ctx->c, data, len);
38 	return 0;
39 }
40 
git_hash_sha1_final(git_oid * out,git_hash_sha1_ctx * ctx)41 int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
42 {
43 	GIT_ASSERT_ARG(ctx);
44 	mbedtls_sha1_finish(&ctx->c, out->id);
45 	return 0;
46 }
47