1
/* md5.c - Functions to compute MD5 message digest of files or memory blocks
2
* according to the definition of MD5 in RFC 1321 from April 1992.
4
* Thanks to Ulrich Drepper for the md5sum example code
6
* Copyright (C) 2002 by the Widelands Development Team
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License
10
* as published by the Free Software Foundation; either version 2
11
* of the License, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32
* This class is responsible of creating a streamind md5 checksum.
33
* You simply pass it the data (using pass_data()) and if you want
34
* to read the checksum, you do a finish_chksum() and a get_chksum()
36
* Pros: Checksum can be generated by streaming: simply call pass_data()
37
* with every junk of data you've read from a file
39
* Cons: 16 byte checksum is to big for network transport
41
* ... sending checksums on every single packet is pointless when it's so
42
* trivial to just fake them anyway.
43
* The checksums are really most useful to verify that the game data
44
* file(s) used on each host haven't accidently been modified.
46
* Let's face it, certain kinds of cheats can only be fought by security
47
* through obscurity, and that's impossible in open-source (unless we write
48
* absolutely horrible spaghetti code ...)
51
ChkSum(const ChkSum&);
52
ChkSum operator=(const ChkSum&);
57
void pass_data(const void*, uint);
58
void finish_chksum(void);
59
ulong* get_chksum(void) const { if(can_handle_data) return 0; return (ulong*)sum; }
63
enum { BLOCKSIZE = 4096 };
64
static const unsigned char fillbuf[64];
66
/* Structure to save state of computation between the single steps. */
79
void md5_process_block (const void*, ulong, md5_ctx*);
80
void md5_process_bytes (const void*, ulong, md5_ctx*);
81
void* md5_finish_ctx (md5_ctx*, void*);
83
char buf[BLOCKSIZE+72];
91
// operator overloading
92
bool operator==(ChkSum&, ChkSum&);
93
bool operator==(ChkSum&, const void*);
94
std::ostream& operator<<(std::ostream&, ChkSum&);
96
#endif /* __S__MD5_H */