Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use libmbedcrypto for SHA1
  • Loading branch information
wildart committed Jul 29, 2016
commit 46db15f45bb8c3e36ceb4c48da9b2e54016282c0
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ ELSEIF (OPENSSL_FOUND AND NOT SHA1_TYPE STREQUAL "builtin")
ELSE()
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl")
ENDIF ()
ELSEIF (MBEDTLS_FOUND AND NOT SHA1_TYPE STREQUAL "builtin")
ADD_DEFINITIONS(-DMBEDTLS_SHA1)
FILE(GLOB SRC_SHA1 src/hash/hash_mbedtls.c)
ELSE()
FILE(GLOB SRC_SHA1 src/hash/hash_generic.c)
ENDIF()
Expand Down
2 changes: 2 additions & 0 deletions src/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void git_hash_ctx_cleanup(git_hash_ctx *ctx);
# include "hash/hash_common_crypto.h"
#elif defined(OPENSSL_SHA1)
# include "hash/hash_openssl.h"
#elif defined(MBEDTLS_SHA1)
# include "hash/hash_mbedtls.h"
#elif defined(WIN32_SHA1)
# include "hash/hash_win32.h"
#else
Expand Down
38 changes: 38 additions & 0 deletions src/hash/hash_mbedtls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/

#include "common.h"
#include "hash.h"
#include "hash/hash_mbedtls.h"

void git_hash_ctx_cleanup(git_hash_ctx *ctx)
{
assert(ctx);
mbedtls_sha1_free(&ctx->c);
}

int git_hash_init(git_hash_ctx *ctx)
{
assert(ctx);
mbedtls_sha1_init(&ctx->c);
mbedtls_sha1_starts(&ctx->c);
return 0;
}

int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
{
assert(ctx);
mbedtls_sha1_update(&ctx->c, data, len);
return 0;
}

int git_hash_final(git_oid *out, git_hash_ctx *ctx)
{
assert(ctx);
mbedtls_sha1_finish(&ctx->c, out->id);
return 0;
}
20 changes: 20 additions & 0 deletions src/hash/hash_mbedtls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/

#ifndef INCLUDE_hash_mbedtld_h__
#define INCLUDE_hash_mbedtld_h__

#include <mbedtls/sha1.h>

struct git_hash_ctx {
mbedtls_sha1_context c;
};

#define git_hash_global_init() 0
#define git_hash_ctx_init(ctx) git_hash_init(ctx)

#endif /* INCLUDE_hash_mbedtld_h__ */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line ending is missing.