~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSMd5.h

  • Committer: Monty Taylor
  • Date: 2010-09-26 21:24:15 UTC
  • mto: (1796.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1797.
  • Revision ID: mordred@inaugust.com-20100926212415-5fn3p3q75pgiei7r
Moved protocol doc into the docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
  1999-05-03 lpd Original version.
48
48
 */
49
49
 
50
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
 
50
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
51
51
 *
52
52
 * PrimeBase S3Daemon
53
53
 *
63
63
 *
64
64
 * You should have received a copy of the GNU General Public License
65
65
 * along with this program; if not, write to the Free Software
66
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
66
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
67
67
 *
68
68
 *  Modified by Barry Leslie on 10/17/08.
69
69
 *      I have put a C++ wrapper around the data and functions to create an Md5 class.
70
70
 *
71
71
 */
72
72
#ifndef md5_INCLUDED
73
 
#define md5_INCLUDED
74
 
 
 
73
#  define md5_INCLUDED
75
74
#include <string.h>
76
75
 
77
 
#include "CSDefs.h"
78
 
 
79
76
/* Define the state of the MD5 Algorithm. */
 
77
 
 
78
 
80
79
typedef unsigned int md5_word_t;
 
80
#define CHECKSUM_VALUE_SIZE     16
81
81
 
82
 
#define MD5_CHECKSUM_SIZE                       CHECKSUM_VALUE_SIZE
83
 
#define MD5_CHECKSUM_STRING_SIZE        (CHECKSUM_VALUE_SIZE * 2 + 1)
 
82
typedef struct {
 
83
        u_char val[CHECKSUM_VALUE_SIZE];
 
84
} Md5Digest;
84
85
 
85
86
class CSMd5 {
86
87
        private:
87
88
        struct md5_state_s {
88
 
                md5_word_t      count[2];               /* message length in bits, lsw first */
89
 
                md5_word_t      abcd[4];                /* digest buffer */
90
 
                u_char          buf[64];                /* accumulate block */
 
89
                md5_word_t count[2];            /* message length in bits, lsw first */
 
90
                md5_word_t abcd[4];             /* digest buffer */
 
91
                u_char buf[64];         /* accumulate block */
91
92
        } md5_state;
92
93
 
93
 
        u_char                  digest[MD5_CHECKSUM_SIZE];
94
 
        char                    digest_cstr[MD5_CHECKSUM_STRING_SIZE];
95
 
 
96
94
        void md5_process(const u_char *data /*[64]*/);
97
 
        void md5_digest();
98
95
 
99
96
        public:
100
 
        CSMd5() {
 
97
        CSMd5()
 
98
        {
101
99
                md5_init();
102
100
        }
103
 
 
 
101
        
104
102
        void md5_init();
105
103
 
106
104
        /* Append a string to the message. */
107
105
        void md5_append(const u_char  *data, int nbytes);
108
 
 
109
 
        void md5_append(const char  *data) {
 
106
        void md5_append(const char  *data)
 
107
        {
110
108
                md5_append((const u_char  *) data, strlen(data));
111
109
        }
 
110
        
112
111
 
113
112
        /* Finish the message and return the digest. */
114
 
        
115
 
        // Returns the raw bin digest.
116
 
        const u_char *md5_get_digest() {
117
 
                if (!digest_cstr[0])
118
 
                        md5_digest();
119
 
                return digest;
120
 
        }
 
113
        void md5_digest(Md5Digest *digest);
121
114
 
122
 
        // Returns the bin/hex digest.
123
 
        void md5_get_digest(Md5Digest *d) {
124
 
                if (!digest_cstr[0])
125
 
                        md5_digest();
126
 
                        
127
 
                memcpy(d->val, digest, CHECKSUM_VALUE_SIZE);
128
 
        }
129
 
        
130
 
        // Returns the bin/hex digest.
131
 
        const char *md5_get_digest_cstr() {
132
 
                if (!digest_cstr[0])
133
 
                        md5_digest();
134
 
                return digest_cstr;
135
 
        }
136
 
        
137
115
};
138
116
 
139
117
#endif /* md5_INCLUDED */