@@ -120,6 +120,79 @@ int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
120120
121121#endif
122122
123+ #ifdef GIT_SHA1_OPENSSL_FIPS
124+
125+ static const EVP_MD * SHA1_ENGINE_DIGEST_TYPE = NULL ;
126+
127+ int git_hash_sha1_global_init (void )
128+ {
129+ SHA1_ENGINE_DIGEST_TYPE = EVP_sha1 ();
130+ return SHA1_ENGINE_DIGEST_TYPE != NULL ? 0 : -1 ;
131+ }
132+
133+ int git_hash_sha1_ctx_init (git_hash_sha1_ctx * ctx )
134+ {
135+ return git_hash_sha1_init (ctx );
136+ }
137+
138+ void git_hash_sha1_ctx_cleanup (git_hash_sha1_ctx * ctx )
139+ {
140+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
141+ EVP_MD_CTX_destroy (ctx -> c );
142+ #else
143+ EVP_MD_CTX_free (ctx -> c );
144+ #endif
145+ }
146+
147+ int git_hash_sha1_init (git_hash_sha1_ctx * ctx )
148+ {
149+ GIT_ASSERT_ARG (ctx );
150+ GIT_ASSERT (SHA1_ENGINE_DIGEST_TYPE );
151+
152+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
153+ ctx -> c = EVP_MD_CTX_create ();
154+ #else
155+ ctx -> c = EVP_MD_CTX_new ();
156+ #endif
157+
158+ GIT_ASSERT (ctx -> c );
159+
160+ if (EVP_DigestInit_ex (ctx -> c , SHA1_ENGINE_DIGEST_TYPE , NULL ) != 1 ) {
161+ git_hash_sha1_ctx_cleanup (ctx );
162+ git_error_set (GIT_ERROR_SHA , "failed to initialize sha1 context" );
163+ return -1 ;
164+ }
165+
166+ return 0 ;
167+ }
168+
169+ int git_hash_sha1_update (git_hash_sha1_ctx * ctx , const void * data , size_t len )
170+ {
171+ GIT_ASSERT_ARG (ctx );
172+
173+ if (EVP_DigestUpdate (ctx -> c , data , len ) != 1 ) {
174+ git_error_set (GIT_ERROR_SHA , "failed to update sha1" );
175+ return -1 ;
176+ }
177+
178+ return 0 ;
179+ }
180+
181+ int git_hash_sha1_final (unsigned char * out , git_hash_sha1_ctx * ctx )
182+ {
183+ unsigned int len = 0 ;
184+ GIT_ASSERT_ARG (ctx );
185+
186+ if (EVP_DigestFinal (ctx -> c , out , & len ) != 1 ) {
187+ git_error_set (GIT_ERROR_SHA , "failed to finalize sha1" );
188+ return -1 ;
189+ }
190+
191+ return 0 ;
192+ }
193+
194+ #endif
195+
123196#ifdef GIT_SHA256_OPENSSL
124197
125198# ifdef GIT_OPENSSL_DYNAMIC
@@ -196,7 +269,7 @@ int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *ctx)
196269
197270#ifdef GIT_SHA256_OPENSSL_FIPS
198271
199- static const EVP_MD * SHA256_ENGINE_DIGEST_TYPE = NULL ;
272+ static const EVP_MD * SHA256_ENGINE_DIGEST_TYPE = NULL ;
200273
201274int git_hash_sha256_global_init (void )
202275{
@@ -221,13 +294,14 @@ void git_hash_sha256_ctx_cleanup(git_hash_sha256_ctx *ctx)
221294int git_hash_sha256_init (git_hash_sha256_ctx * ctx )
222295{
223296 GIT_ASSERT_ARG (ctx );
224-
225297 GIT_ASSERT (SHA256_ENGINE_DIGEST_TYPE );
298+
226299#if OPENSSL_VERSION_NUMBER < 0x10100000L
227300 ctx -> c = EVP_MD_CTX_create ();
228301#else
229302 ctx -> c = EVP_MD_CTX_new ();
230303#endif
304+
231305 GIT_ASSERT (ctx -> c );
232306
233307 if (EVP_DigestInit_ex (ctx -> c , SHA256_ENGINE_DIGEST_TYPE , NULL ) != 1 ) {
@@ -264,4 +338,4 @@ int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *ctx)
264338 return 0 ;
265339}
266340
267- #endif
341+ #endif
0 commit comments