~skinny.moey/drizzle/innodb-replication

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-11-08 22:35:57 UTC
  • mfrom: (1802.1.114 trunk)
  • Revision ID: brian@tangent.org-20101108223557-w3xzwp9hjjtjhtc1
MergeĀ inĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
66
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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
 
73
#define md5_INCLUDED
 
74
 
74
75
#include <string.h>
75
76
 
 
77
#include "CSDefs.h"
 
78
 
76
79
/* Define the state of the MD5 Algorithm. */
77
 
 
78
 
 
79
80
typedef unsigned int md5_word_t;
80
 
#define CHECKSUM_VALUE_SIZE     16
81
81
 
82
 
typedef struct {
83
 
        u_char val[CHECKSUM_VALUE_SIZE];
84
 
} Md5Digest;
 
82
#define MD5_CHECKSUM_SIZE                       CHECKSUM_VALUE_SIZE
 
83
#define MD5_CHECKSUM_STRING_SIZE        (CHECKSUM_VALUE_SIZE * 2 + 1)
85
84
 
86
85
class CSMd5 {
87
86
        private:
88
87
        struct md5_state_s {
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 */
 
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 */
92
91
        } md5_state;
93
92
 
 
93
        u_char                  digest[MD5_CHECKSUM_SIZE];
 
94
        char                    digest_cstr[MD5_CHECKSUM_STRING_SIZE];
 
95
 
94
96
        void md5_process(const u_char *data /*[64]*/);
 
97
        void md5_digest();
95
98
 
96
99
        public:
97
 
        CSMd5()
98
 
        {
 
100
        CSMd5() {
99
101
                md5_init();
100
102
        }
101
 
        
 
103
 
102
104
        void md5_init();
103
105
 
104
106
        /* Append a string to the message. */
105
107
        void md5_append(const u_char  *data, int nbytes);
106
 
        void md5_append(const char  *data)
107
 
        {
 
108
 
 
109
        void md5_append(const char  *data) {
108
110
                md5_append((const u_char  *) data, strlen(data));
109
111
        }
110
 
        
111
112
 
112
113
        /* Finish the message and return the digest. */
113
 
        void md5_digest(Md5Digest *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
        }
114
121
 
 
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
        
115
137
};
116
138
 
117
139
#endif /* md5_INCLUDED */