@@ -168,7 +168,7 @@ int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
168168
169169int git_hash_sha1_update (git_hash_sha1_ctx * ctx , const void * data , size_t len )
170170{
171- GIT_ASSERT_ARG (ctx );
171+ GIT_ASSERT_ARG (ctx && ctx -> c );
172172
173173 if (EVP_DigestUpdate (ctx -> c , data , len ) != 1 ) {
174174 git_error_set (GIT_ERROR_SHA , "failed to update sha1" );
@@ -181,13 +181,16 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
181181int git_hash_sha1_final (unsigned char * out , git_hash_sha1_ctx * ctx )
182182{
183183 unsigned int len = 0 ;
184- GIT_ASSERT_ARG (ctx );
184+
185+ GIT_ASSERT_ARG (ctx && ctx -> c );
185186
186187 if (EVP_DigestFinal (ctx -> c , out , & len ) != 1 ) {
187188 git_error_set (GIT_ERROR_SHA , "failed to finalize sha1" );
188189 return -1 ;
189190 }
190191
192+ ctx -> c = NULL ;
193+
191194 return 0 ;
192195}
193196
@@ -315,7 +318,7 @@ int git_hash_sha256_init(git_hash_sha256_ctx *ctx)
315318
316319int git_hash_sha256_update (git_hash_sha256_ctx * ctx , const void * data , size_t len )
317320{
318- GIT_ASSERT_ARG (ctx );
321+ GIT_ASSERT_ARG (ctx && ctx -> c );
319322
320323 if (EVP_DigestUpdate (ctx -> c , data , len ) != 1 ) {
321324 git_error_set (GIT_ERROR_SHA , "failed to update sha256" );
@@ -328,13 +331,16 @@ int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *data, size_t le
328331int git_hash_sha256_final (unsigned char * out , git_hash_sha256_ctx * ctx )
329332{
330333 unsigned int len = 0 ;
331- GIT_ASSERT_ARG (ctx );
334+
335+ GIT_ASSERT_ARG (ctx && ctx -> c );
332336
333337 if (EVP_DigestFinal (ctx -> c , out , & len ) != 1 ) {
334338 git_error_set (GIT_ERROR_SHA , "failed to finalize sha256" );
335339 return -1 ;
336340 }
337341
342+ ctx -> c = NULL ;
343+
338344 return 0 ;
339345}
340346
0 commit comments