77
88#include "openssl.h"
99
10+ #ifdef GIT_SHA1_OPENSSL
11+
1012int git_hash_sha1_global_init (void )
1113{
1214 return 0 ;
@@ -27,7 +29,7 @@ int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
2729 GIT_ASSERT_ARG (ctx );
2830
2931 if (SHA1_Init (& ctx -> c ) != 1 ) {
30- git_error_set (GIT_ERROR_SHA , "hash_openssl: failed to initialize hash context" );
32+ git_error_set (GIT_ERROR_SHA , "failed to initialize sha1 context" );
3133 return -1 ;
3234 }
3335
@@ -39,7 +41,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
3941 GIT_ASSERT_ARG (ctx );
4042
4143 if (SHA1_Update (& ctx -> c , data , len ) != 1 ) {
42- git_error_set (GIT_ERROR_SHA , "hash_openssl: failed to update hash " );
44+ git_error_set (GIT_ERROR_SHA , "failed to update sha1 " );
4345 return -1 ;
4446 }
4547
@@ -51,9 +53,66 @@ int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
5153 GIT_ASSERT_ARG (ctx );
5254
5355 if (SHA1_Final (out , & ctx -> c ) != 1 ) {
54- git_error_set (GIT_ERROR_SHA , "hash_openssl: failed to finalize hash" );
56+ git_error_set (GIT_ERROR_SHA , "failed to finalize sha1" );
57+ return -1 ;
58+ }
59+
60+ return 0 ;
61+ }
62+
63+ #endif
64+
65+ #ifdef GIT_SHA256_OPENSSL
66+
67+ int git_hash_sha256_global_init (void )
68+ {
69+ return 0 ;
70+ }
71+
72+ int git_hash_sha256_ctx_init (git_hash_sha256_ctx * ctx )
73+ {
74+ return git_hash_sha256_init (ctx );
75+ }
76+
77+ void git_hash_sha256_ctx_cleanup (git_hash_sha256_ctx * ctx )
78+ {
79+ GIT_UNUSED (ctx );
80+ }
81+
82+ int git_hash_sha256_init (git_hash_sha256_ctx * ctx )
83+ {
84+ GIT_ASSERT_ARG (ctx );
85+
86+ if (SHA256_Init (& ctx -> c ) != 1 ) {
87+ git_error_set (GIT_ERROR_SHA , "failed to initialize sha256 context" );
88+ return -1 ;
89+ }
90+
91+ return 0 ;
92+ }
93+
94+ int git_hash_sha256_update (git_hash_sha256_ctx * ctx , const void * data , size_t len )
95+ {
96+ GIT_ASSERT_ARG (ctx );
97+
98+ if (SHA256_Update (& ctx -> c , data , len ) != 1 ) {
99+ git_error_set (GIT_ERROR_SHA , "failed to update sha256" );
55100 return -1 ;
56101 }
57102
58103 return 0 ;
59104}
105+
106+ int git_hash_sha256_final (unsigned char * out , git_hash_sha256_ctx * ctx )
107+ {
108+ GIT_ASSERT_ARG (ctx );
109+
110+ if (SHA256_Final (out , & ctx -> c ) != 1 ) {
111+ git_error_set (GIT_ERROR_SHA , "failed to finalize sha256" );
112+ return -1 ;
113+ }
114+
115+ return 0 ;
116+ }
117+
118+ #endif
0 commit comments