diff --git a/md5.c b/md5.c
index 932f6ca16b9f4060c745c7d8e99ca74f992b932d..20568d9057d7225c7d8b882a18c4751870e7ba3f 100644
--- a/md5.c
+++ b/md5.c
@@ -91,7 +91,7 @@ md5_update(struct md5_ctx *ctx,
 /* Final wrapup - pad to MD5_DATA_SIZE-byte boundary with the bit
  * pattern 1 0* (64-bit count of bits processed, LSB-first) */
 
-void
+static void
 md5_final(struct md5_ctx *ctx)
 {
   uint32_t data[MD5_DATA_LENGTH];
@@ -136,7 +136,7 @@ md5_final(struct md5_ctx *ctx)
 }
 
 void
-md5_digest(const struct md5_ctx *ctx,
+md5_digest(struct md5_ctx *ctx,
 	   unsigned length,
 	   uint8_t *digest)
 {
@@ -146,6 +146,8 @@ md5_digest(const struct md5_ctx *ctx,
   
   assert(length <= MD5_DIGEST_SIZE);
 
+  md5_final(ctx);
+  
   words = length / 4;
   leftover = length % 4;
   
@@ -165,6 +167,7 @@ md5_digest(const struct md5_ctx *ctx,
 	   j++, word >>= 8)
 	digest[j] = word & 0xff;
     }
+  md5_init(ctx);
 }
 
 /* MD5 functions */
diff --git a/md5.h b/md5.h
index b376f7db0d9483e1d8e6f35546000c91c7394d30..c93bcc19219485d26cb8e6f422e4c664514a78d5 100644
--- a/md5.h
+++ b/md5.h
@@ -51,10 +51,7 @@ md5_update(struct md5_ctx *ctx,
 	   const uint8_t *data);
 
 void
-md5_final(struct md5_ctx *ctx);
-
-void
-md5_digest(const struct md5_ctx *ctx,
+md5_digest(struct md5_ctx *ctx,
 	   unsigned length,
 	   uint8_t *digest);
 
diff --git a/sha.h b/sha.h
index 0cf9b8ca860e4402ee1b5c54cbc66f08de2e1a7f..f9eb69bdf3de2c064168a07eae18cba2e2c9c822 100644
--- a/sha.h
+++ b/sha.h
@@ -53,10 +53,7 @@ sha1_update(struct sha1_ctx *ctx,
 	    const uint8_t *data);
 
 void
-sha1_final(struct sha1_ctx *ctx);
-
-void
-sha1_digest(const struct sha1_ctx *ctx,
+sha1_digest(struct sha1_ctx *ctx,
 	    unsigned length,
 	    uint8_t *digest);
 
@@ -85,10 +82,7 @@ sha256_update(struct sha256_ctx *ctx,
 	      const uint8_t *data);
 
 void
-sha256_final(struct sha256_ctx *ctx);
-
-void
-sha256_digest(const struct sha256_ctx *ctx,
+sha256_digest(struct sha256_ctx *ctx,
 	      unsigned length,
 	      uint8_t *digest);
 
diff --git a/sha1.c b/sha1.c
index a0982fb47da23fb978f0bb18982bad39be098d0b..f1c18c63fd3550abd563cdc921b3d54cc6448797 100644
--- a/sha1.c
+++ b/sha1.c
@@ -294,7 +294,7 @@ sha1_update(struct sha1_ctx *ctx,
 /* Final wrapup - pad to SHA1_DATA_SIZE-byte boundary with the bit pattern
    1 0* (64-bit count of bits processed, MSB-first) */
 
-void
+static void
 sha1_final(struct sha1_ctx *ctx)
 {
   uint32_t data[SHA1_DATA_LENGTH];
@@ -338,7 +338,7 @@ sha1_final(struct sha1_ctx *ctx)
 }
 
 void
-sha1_digest(const struct sha1_ctx *ctx,
+sha1_digest(struct sha1_ctx *ctx,
 	    unsigned length,
 	    uint8_t *digest)
 {
@@ -348,6 +348,8 @@ sha1_digest(const struct sha1_ctx *ctx,
   
   assert(length <= SHA1_DIGEST_SIZE);
 
+  sha1_final(ctx);
+  
   words = length / 4;
   leftover = length % 4;
 
@@ -377,4 +379,5 @@ sha1_digest(const struct sha1_ctx *ctx,
 	  digest[--j] = (word >> 24) & 0xff;
 	}
     }
+  sha1_init(ctx);
 }
diff --git a/sha256.c b/sha256.c
index ec8fb5097457f4b9fe3fb898202d1f5de608734b..76ce5f35399ff2523a16d120e4c49ecde72a71c2 100644
--- a/sha256.c
+++ b/sha256.c
@@ -268,7 +268,7 @@ sha256_update(struct sha256_ctx *ctx,
 /* Final wrapup - pad to SHA1_DATA_SIZE-byte boundary with the bit pattern
    1 0* (64-bit count of bits processed, MSB-first) */
 
-void
+static void
 sha256_final(struct sha256_ctx *ctx)
 {
   uint32_t data[SHA256_DATA_LENGTH];
@@ -312,7 +312,7 @@ sha256_final(struct sha256_ctx *ctx)
 }
 
 void
-sha256_digest(const struct sha256_ctx *ctx,
+sha256_digest(struct sha256_ctx *ctx,
 	      unsigned length,
 	      uint8_t *digest)
 {
@@ -322,6 +322,8 @@ sha256_digest(const struct sha256_ctx *ctx,
   
   assert(length <= SHA256_DIGEST_SIZE);
 
+  sha256_final(ctx);
+  
   words = length / 4;
   leftover = length % 4;
 
@@ -351,4 +353,5 @@ sha256_digest(const struct sha256_ctx *ctx,
 	  digest[--j] = (word >> 24) & 0xff;
 	}
     }
+  sha256_init(ctx);
 }