1 /* -*- Mode: C++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil -*-
2  *
3  * Quadra, an action puzzle game
4  * Copyright (C) 1998-2000  Ludus Design
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 
21 #ifndef _HEADER_CRYPT
22 #define _HEADER_CRYPT
23 
24 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
25 rights reserved.
26 
27 License to copy and use this software is granted provided that it
28 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
29 Algorithm" in all material mentioning or referencing this software
30 or this function.
31 
32 License is also granted to make and use derivative works provided
33 that such works are identified as "derived from the RSA Data
34 Security, Inc. MD5 Message-Digest Algorithm" in all material
35 mentioning or referencing the derived work.
36 
37 RSA Data Security, Inc. makes no representations concerning either
38 the merchantability of this software or the suitability of this
39 software for any particular purpose. It is provided "as is"
40 without express or implied warranty of any kind.
41 
42 These notices must be retained in any copies of any part of this
43 documentation and/or software.
44 */
45 
46 #include "types.h"
47 
48 typedef unsigned char *POINTER;
49 typedef unsigned short int UINT2;
50 typedef unsigned long int UINT4;
51 
52 typedef struct {
53 	UINT4 state[4];                                   // state (ABCD)
54 	UINT4 count[2];        // number of bits, modulo 2^64 (lsb first)
55 	unsigned char buffer[64];                         // input buffer
56 } MD5_CTX;
57 
58 class Crypt {
59 	MD5_CTX context;
60 	Byte digest[16];
61 	char result[33];
62 	void MD5Init(MD5_CTX *);
63 	void MD5Update(MD5_CTX *, unsigned char *, unsigned int);
64 	void MD5Update2(MD5_CTX *, unsigned char *, unsigned int);
65 	void MD5Final(unsigned char [16], MD5_CTX *);
66 	void shuffle();
67 	bool finalized;
68 public:
69 	Crypt();
70 	Crypt(const char *s, bool do_shuffle);
71 	virtual ~Crypt();
72 	void step(Byte *buf, Dword size);
73 	void step2(Byte *buf, Dword size);
74 	void finalize(bool do_shuffle);
75 	const char *get_digest_string() const;
76 	const Byte *get_digest() const;
77 };
78 
79 #endif
80