1be878f60SRene Gollent/*
2be878f60SRene Gollent *  Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.
3be878f60SRene Gollent *
4be878f60SRene Gollent *  License to copy and use this software is granted provided that it is identified
5be878f60SRene Gollent *  as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material
6be878f60SRene Gollent *  mentioning or referencing this software or this function.
7be878f60SRene Gollent *
8be878f60SRene Gollent *  License is also granted to make and use derivative works provided that such
9be878f60SRene Gollent *  works are identified as "derived from the RSA Data Security, Inc. MD5 Message-
10be878f60SRene Gollent *  Digest Algorithm" in all material mentioning or referencing the derived work.
11be878f60SRene Gollent *
12be878f60SRene Gollent *  RSA Data Security, Inc. makes no representations concerning either the
13be878f60SRene Gollent *  merchantability of this software or the suitability of this software for any
14be878f60SRene Gollent *  particular purpose. It is provided "as is" without express or implied warranty
15be878f60SRene Gollent *  of any kind. These notices must be retained in any copies of any part of this
16be878f60SRene Gollent *  documentation and/or software.
17be878f60SRene Gollent */
18be878f60SRene Gollent
19be878f60SRene Gollent#ifndef MD5SUM_MD5_H
20be878f60SRene Gollent#define MD5SUM_MD5_H
21be878f60SRene Gollent
22be878f60SRene Gollenttypedef unsigned int uint32_t;
23be878f60SRene Gollenttypedef unsigned char uint8_t;
24be878f60SRene Gollent
25be878f60SRene Gollent/*
26be878f60SRene Gollent *  Define the MD5 context structure
27be878f60SRene Gollent *  Please DO NOT change the order or contents of the structure as various assembler files depend on it !!
28be878f60SRene Gollent */
29be878f60SRene Gollent
30be878f60SRene Gollenttypedef struct {
31be878f60SRene Gollent   uint32_t  state  [ 4];     /* state (ABCD) */
32be878f60SRene Gollent   uint32_t  count  [ 2];     /* number of bits, modulo 2^64 (least sig word first) */
33be878f60SRene Gollent   uint8_t   buffer [64];     /* input buffer for incomplete buffer data */
34be878f60SRene Gollent} MD5_CTX;
35be878f60SRene Gollent
36be878f60SRene Gollentvoid   MD5Init   ( MD5_CTX* ctx );
37be878f60SRene Gollentvoid   MD5Update ( MD5_CTX* ctx, const uint8_t* buf, size_t len );
38be878f60SRene Gollentvoid   MD5Final  ( uint8_t digest [16], MD5_CTX* ctx );
39be878f60SRene Gollent
40be878f60SRene Gollentclass CMD5Helper
41be878f60SRene Gollent{
42be878f60SRene Gollentpublic:
43be878f60SRene Gollent
44be878f60SRene Gollent    CMD5Helper(BOOL bInitialize = TRUE)
45be878f60SRene Gollent    {
46be878f60SRene Gollent        if (bInitialize)
47be878f60SRene Gollent            Initialize();
48be878f60SRene Gollent    }
49be878f60SRene Gollent
50be878f60SRene Gollent    BOOL Initialize()
51be878f60SRene Gollent    {
52be878f60SRene Gollent        memset(&m_MD5Context, 0, sizeof(m_MD5Context));
53be878f60SRene Gollent        MD5Init(&m_MD5Context);
54be878f60SRene Gollent        m_nTotalBytes = 0;
55be878f60SRene Gollent        return TRUE;
56be878f60SRene Gollent    }
57be878f60SRene Gollent
58be878f60SRene Gollent    inline void AddData(const void * pData, int nBytes)
59be878f60SRene Gollent    {
60be878f60SRene Gollent        MD5Update(&m_MD5Context, (const unsigned char *) pData, nBytes);
61be878f60SRene Gollent        m_nTotalBytes += nBytes;
62be878f60SRene Gollent    }
63be878f60SRene Gollent
64be878f60SRene Gollent    BOOL GetResult(unsigned char cResult[16])
65be878f60SRene Gollent    {
66be878f60SRene Gollent        memset(cResult, 0, 16);
67be878f60SRene Gollent        MD5Final(cResult, &m_MD5Context);
68be878f60SRene Gollent        return TRUE;
69be878f60SRene Gollent    }
70be878f60SRene Gollent
71be878f60SRene Gollentprotected:
72be878f60SRene Gollent
73be878f60SRene Gollent    MD5_CTX m_MD5Context;
74be878f60SRene Gollent    BOOL m_bStopped;
75be878f60SRene Gollent    int m_nTotalBytes;
76be878f60SRene Gollent};
77be878f60SRene Gollent
78be878f60SRene Gollent
79be878f60SRene Gollent#endif /* MD5SUM_MD5_H */