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

Skip to content
Merged
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
mbedtls: use libmbedcrypto for hashing
  • Loading branch information
tiennou committed Apr 11, 2018
commit 6c6be3ce6ff23429089c0211870971b17246a992
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ OPTION( PROFILE "Generate profiling information" OFF )
OPTION( ENABLE_TRACE "Enables tracing support" OFF )
OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )

SET(SHA1_BACKEND "CollisionDetection" CACHE STRING "Backend to use for SHA1. One of Generic, OpenSSL, Win32, CommonCrypto, CollisionDetection. ")
SET(SHA1_BACKEND "CollisionDetection" CACHE STRING "Backend to use for SHA1. One of Generic, OpenSSL, Win32, CommonCrypto, mbedTLS, CollisionDetection. ")
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
OPTION( USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON )
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ ELSEIF(SHA1_BACKEND STREQUAL "Win32")
ELSEIF(SHA1_BACKEND STREQUAL "CommonCrypto")
ADD_FEATURE_INFO(SHA ON "using CommonCrypto")
SET(GIT_SHA1_COMMON_CRYPTO 1)
ELSEIF (SHA1_BACKEND STREQUAL "mbedTLS")
ADD_FEATURE_INFO(SHA ON "using mbedTLS")
SET(GIT_SHA1_MBEDTLS 1)
FILE(GLOB SRC_SHA1 src/hash/hash_mbedtls.c)
LIST(APPEND LIBGIT2_PC_REQUIRES "mbedtls")
ELSE()
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend ${SHA1_BACKEND}")
ENDIF()
Expand Down
1 change: 1 addition & 0 deletions src/features.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
#cmakedefine GIT_SHA1_WIN32 1
#cmakedefine GIT_SHA1_COMMON_CRYPTO 1
#cmakedefine GIT_SHA1_OPENSSL 1
#cmakedefine GIT_SHA1_MBEDTLS 1

#endif
2 changes: 2 additions & 0 deletions src/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void git_hash_ctx_cleanup(git_hash_ctx *ctx);
# include "hash/hash_openssl.h"
#elif defined(GIT_SHA1_WIN32)
# include "hash/hash_win32.h"
#elif defined(GIT_SHA1_MBEDTLS)
# include "hash/hash_mbedtls.h"
#else
# include "hash/hash_generic.h"
#endif
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__ */