annotate libfaim/md5.h @ 1902:9aa7cd7f5948

[gaim-migrate @ 1912] whoops, wrong part committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 28 May 2001 18:47:21 +0000
parents 58a6e6e26695
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
741
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 Copyright (C) 1999 Aladdin Enterprises. All rights reserved.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 This software is provided 'as-is', without any express or implied
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 warranty. In no event will the authors be held liable for any damages
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 arising from the use of this software.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 Permission is granted to anyone to use this software for any purpose,
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 including commercial applications, and to alter it and redistribute it
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 freely, subject to the following restrictions:
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 1. The origin of this software must not be misrepresented; you must not
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 claim that you wrote the original software. If you use this software
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 in a product, an acknowledgment in the product documentation would be
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 appreciated but is not required.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 2. Altered source versions must be plainly marked as such, and must not be
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 misrepresented as being the original software.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 3. This notice may not be removed or altered from any source distribution.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 L. Peter Deutsch
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 ghost@aladdin.com
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 /*$Id: md5.h 751 2000-08-22 23:38:47Z warmenhoven $ */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 /*
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 Independent implementation of MD5 (RFC 1321).
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 This code implements the MD5 Algorithm defined in RFC 1321.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 It is derived directly from the text of the RFC and not from the
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 reference implementation.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 The original and principal author of md5.h is L. Peter Deutsch
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 <ghost@aladdin.com>. Other authors are noted in the change history
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 that follows (in reverse chronological order):
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 added conditionalization for C++ compilation from Martin
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 Purschke <purschke@bnl.gov>.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 1999-05-03 lpd Original version.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 #ifndef md5_INCLUDED
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 # define md5_INCLUDED
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 /*
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 * This code has some adaptations for the Ghostscript environment, but it
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 * will compile and run correctly in any environment with 8-bit chars and
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 * 32-bit ints. Specifically, it assumes that if the following are
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 * defined, they have the same meaning as in Ghostscript: P1, P2, P3,
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 * ARCH_IS_BIG_ENDIAN.
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 typedef unsigned char md5_byte_t; /* 8-bit byte */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 typedef unsigned int md5_word_t; /* 32-bit word */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 /* Define the state of the MD5 Algorithm. */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 typedef struct md5_state_s {
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 md5_word_t count[2]; /* message length in bits, lsw first */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 md5_word_t abcd[4]; /* digest buffer */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 md5_byte_t buf[64]; /* accumulate block */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 } md5_state_t;
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 #ifdef __cplusplus
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 extern "C"
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 {
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 #endif
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 /* Initialize the algorithm. */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 #ifdef P1
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 void md5_init(P1(md5_state_t *pms));
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 #else
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 void md5_init(md5_state_t *pms);
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 #endif
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 /* Append a string to the message. */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 #ifdef P3
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 void md5_append(P3(md5_state_t *pms, const md5_byte_t *data, int nbytes));
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 #else
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 #endif
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 /* Finish the message and return the digest. */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 #ifdef P2
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 void md5_finish(P2(md5_state_t *pms, md5_byte_t digest[16]));
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 #else
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 #endif
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 #ifdef __cplusplus
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 } /* end extern "C" */
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 #endif
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93
58a6e6e26695 [gaim-migrate @ 751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 #endif /* md5_INCLUDED */