AlbumShaper 1.0a3
md5.h
Go to the documentation of this file.
1//==============================================
2// copyright : (C) 2003-2005 by Will Stokes
3//==============================================
4// This program is free software; you can redistribute it
5// and/or modify it under the terms of the GNU General
6// Public License as published by the Free Software
7// Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//==============================================
10
11//=====================================
15//=====================================
16
17
18// MD5.CC - source code for the C++/object oriented translation and
19// modification of MD5.
20
21// Translation and modification (c) 1995 by Mordechai T. Abzug
22
23// This translation/ modification is provided "as is," without express or
24// implied warranty of any kind.
25
26// The translator/ modifier does not claim (1) that MD5 will do what you think
27// it does; (2) that this translation/ modification is accurate; or (3) that
28// this software is "merchantible." (Language for this disclaimer partially
29// copied from the disclaimer below).
30
31/* based on:
32
33 MD5.H - header file for MD5C.C
34 MDDRIVER.C - test driver for MD2, MD4 and MD5
35
36 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
37rights reserved.
38
39License to copy and use this software is granted provided that it
40is identified as the "RSA Data Security, Inc. MD5 Message-Digest
41Algorithm" in all material mentioning or referencing this software
42or this function.
43
44License is also granted to make and use derivative works provided
45that such works are identified as "derived from the RSA Data
46Security, Inc. MD5 Message-Digest Algorithm" in all material
47mentioning or referencing the derived work.
48
49RSA Data Security, Inc. makes no representations concerning either
50the merchantability of this software or the suitability of this
51software for any particular purpose. It is provided "as is"
52without express or implied warranty of any kind.
53
54These notices must be retained in any copies of any part of this
55documentation and/or software.
56
57*/
58
59#include <fstream>
60#include <qstring.h>
61
62#ifndef BACKEND_TOOLS_MD5_H
63#define BACKEND_TOOLS_MD5_H
64
65class MD5 {
66
67public:
68// methods for controlled operation:
69 MD5 (); // simple initializer
70 void update (unsigned char *input, unsigned int input_length);
71 void update (std::istream& stream);
72 void update (FILE *file);
73 void update (std::ifstream& stream);
74 void finalize ();
75
76// constructors for special circumstances. All these constructors finalize
77// the MD5 context.
78 MD5 (unsigned char *string); // digest string, finalize
79 MD5 (std::istream& stream); // digest stream, finalize
80 MD5 (FILE *file); // digest file, close, finalize
81 MD5 (std::ifstream& stream); // digest stream, close, finalize
82
83// methods to acquire finalized result
84 unsigned char *raw_digest (); // digest as a 16-byte binary array
85 QString hex_digest (); // digest as a 33-byte ascii-hex string
86
87
88private:
89
90// first, some types:
91 typedef unsigned int uint4; // assumes integer is 4 words long
92 typedef unsigned short int uint2; // assumes short integer is 2 words long
93 typedef unsigned char uint1; // assumes char is 1 word long
94
95// next, the private data:
97 uint4 count[2]; // number of *bits*, mod 2^64
98 uint1 buffer[64]; // input buffer
101
102// last, the private methods, mostly static:
103 void init (); // called by all constructors
104 void transform (uint1 *buffer); // does the real update work. Note
105 // that length is implied to be 64.
106
107 static void encode (uint1 *dest, uint4 *src, uint4 length);
108 static void decode (uint4 *dest, uint1 *src, uint4 length);
109 static void memcpy (uint1 *dest, uint1 *src, uint4 length);
110 static void memset (uint1 *start, uint1 val, uint4 length);
111
112 static inline uint4 rotate_left (uint4 x, uint4 n);
113 static inline uint4 F (uint4 x, uint4 y, uint4 z);
114 static inline uint4 G (uint4 x, uint4 y, uint4 z);
115 static inline uint4 H (uint4 x, uint4 y, uint4 z);
116 static inline uint4 I (uint4 x, uint4 y, uint4 z);
117 static inline void FF (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
118 uint4 s, uint4 ac);
119 static inline void GG (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
120 uint4 s, uint4 ac);
121 static inline void HH (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
122 uint4 s, uint4 ac);
123 static inline void II (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
124 uint4 s, uint4 ac);
125
126};
127
128//returns md5 for a given file
129QString getMD5(std::ifstream& stream);
130
131//compares md5's for two files
132//returns -1 if unable ot open file
133//returns 0 if files are different
134//returns 1 if files are same
135bool filesMatch(std::ifstream& stream, QString oldMD5);
136
137#endif //BACKEND_TOOLS_MD5_H
MD5 Support allows checksums to be computed for images, determing if they have changed since the albu...
Definition: md5.h:65
void update(unsigned char *input, unsigned int input_length)
Definition: md5.cpp:71
void transform(uint1 *buffer)
Definition: md5.cpp:338
MD5(unsigned char *string)
static uint4 F(uint4 x, uint4 y, uint4 z)
Definition: md5.cpp:495
uint1 buffer[64]
Definition: md5.h:98
unsigned int uint4
Definition: md5.h:91
uint1 digest[16]
Definition: md5.h:99
static void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: md5.cpp:517
uint1 finalized
Definition: md5.h:100
unsigned char uint1
Definition: md5.h:93
uint4 count[2]
Definition: md5.h:97
static uint4 rotate_left(uint4 x, uint4 n)
Definition: md5.cpp:486
void init()
Definition: md5.cpp:297
QString hex_digest()
Definition: md5.cpp:271
static void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: md5.cpp:535
static void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: md5.cpp:523
unsigned short int uint2
Definition: md5.h:92
static uint4 G(uint4 x, uint4 y, uint4 z)
Definition: md5.cpp:499
static void encode(uint1 *dest, uint4 *src, uint4 length)
Definition: md5.cpp:432
static void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: md5.cpp:529
uint4 state[4]
Definition: md5.h:96
unsigned char * raw_digest()
Definition: md5.cpp:255
static uint4 I(uint4 x, uint4 y, uint4 z)
Definition: md5.cpp:507
void finalize()
Definition: md5.cpp:188
static void memset(uint1 *start, uint1 val, uint4 length)
Definition: md5.cpp:474
static uint4 H(uint4 x, uint4 y, uint4 z)
Definition: md5.cpp:503
static void decode(uint4 *dest, uint1 *src, uint4 length)
Definition: md5.cpp:449
MD5()
Definition: md5.cpp:62
static void memcpy(uint1 *dest, uint1 *src, uint4 length)
Definition: md5.cpp:463
long b
Definition: jpegInternal.h:125
QString getMD5(std::ifstream &stream)
Definition: md5.cpp:542
bool filesMatch(std::ifstream &stream, QString oldMD5)
Definition: md5.cpp:549