]> FriiDump Source - friidump.git/blob - libmultihash/md5.h
FriiDump 0.5.3.16: finalize release identity and documentation
[friidump.git] / libmultihash / md5.h
1 #ifndef __MD5_H__
2 #define __MD5_H__
3 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4 //  WjCryptLib_Md5
5 //
6 //  Implementation of MD5 hash function. Originally written by Alexander Peslyak. Modified by WaterJuice retaining
7 //  Public Domain license.
8 //
9 //  This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
10 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
12 #pragma once
13
14 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15 //  IMPORTS
16 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17
18 #include <stdint.h>
19 #include <stdio.h>
20
21 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
22 //  TYPES
23 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24
25 // Md5Context - This must be initialised using Md5Initialised. Do not modify the contents of this structure directly.
26 typedef struct
27 {
28     uint32_t     lo;
29     uint32_t     hi;
30     uint32_t     a;
31     uint32_t     b;
32     uint32_t     c;
33     uint32_t     d;
34     uint8_t      buffer[64];
35     uint32_t     block[16];
36 } Md5Context;
37
38 #define MD5_HASH_SIZE           ( 128 / 8 )
39
40 typedef struct
41 {
42     uint8_t      bytes [MD5_HASH_SIZE];
43 } MD5_HASH;
44
45 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
46 //  PUBLIC FUNCTIONS
47 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48
49 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50 //  Md5Initialise
51 //
52 //  Initialises an MD5 Context. Use this to initialise/reset a context.
53 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54 void
55     Md5Initialise
56     (
57         Md5Context*         Context         // [out]
58     );
59
60 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 //  Md5Update
62 //
63 //  Adds data to the MD5 context. This will process the data and update the internal state of the context. Keep on
64 //  calling this function until all the data has been added. Then call Md5Finalise to calculate the hash.
65 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66 void
67     Md5Update
68     (
69         Md5Context*         Context,        // [in out]
70         void const*         Buffer,         // [in]
71         uint32_t            BufferSize      // [in]
72     );
73
74 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 //  Md5Finalise
76 //
77 //  Performs the final calculation of the hash and returns the digest (16 byte buffer containing 128bit hash). After
78 //  calling this, Md5Initialised must be used to reuse the context.
79 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80 void
81     Md5Finalise
82     (
83         Md5Context*         Context,        // [in out]
84         MD5_HASH*           Digest          // [in]
85     );
86
87 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88 //  Md5Calculate
89 //
90 //  Combines Md5Initialise, Md5Update, and Md5Finalise into one function. Calculates the MD5 hash of the buffer.
91 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92 void
93     Md5Calculate
94     (
95         void  const*        Buffer,         // [in]
96         uint32_t            BufferSize,     // [in]
97         MD5_HASH*           Digest          // [in]
98     );
99 #endif /* __MD5_H__ */