Refactor #includes and headers
[fio.git] / crc / md5.c
index 0da85e43f3c50fbfd23c12021e6b1f32d949f269..ade4f69721c7668a644c3459828ba250992b3d41 100644 (file)
--- a/crc/md5.c
+++ b/crc/md5.c
@@ -2,7 +2,6 @@
  * Shamelessly lifted from the 2.6 kernel (crypto/md5.c)
  */
 #include <string.h>
-#include <stdint.h>
 #include "md5.h"
 
 static void md5_transform(uint32_t *hash, uint32_t const *in)
@@ -125,3 +124,23 @@ void fio_md5_update(struct fio_md5_ctx *mctx, const uint8_t *data,
 
        memcpy(mctx->block, data, len);
 }
+
+void fio_md5_final(struct fio_md5_ctx *mctx)
+{
+       const unsigned int offset = mctx->byte_count & 0x3f;
+       char *p = (char *)mctx->block + offset;
+       int padding = 56 - (offset + 1);
+
+       *p++ = 0x80;
+       if (padding < 0) {
+               memset(p, 0x00, padding + sizeof (uint64_t));
+               md5_transform(mctx->hash, mctx->block);
+               p = (char *)mctx->block;
+               padding = 56;
+       }
+
+       memset(p, 0, padding);
+       mctx->block[14] = mctx->byte_count << 3;
+       mctx->block[15] = mctx->byte_count >> 29;
+       md5_transform(mctx->hash, mctx->block);
+}