- Timestamp:
- 2007-11-23T22:25:04Z (17 years ago)
- Branches:
- master
- Children:
- 77bfd07
- Parents:
- 56f260a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/md5.h
r56f260a rdf6d1da 1 1 /* 2 Copyright (C) 1999 Aladdin Enterprises. All rights reserved. 3 4 This software is provided 'as-is', without any express or implied 5 warranty. In no event will the authors be held liable for any damages 6 arising from the use of this software. 7 8 Permission is granted to anyone to use this software for any purpose, 9 including commercial applications, and to alter it and redistribute it 10 freely, subject to the following restrictions: 11 12 1. The origin of this software must not be misrepresented; you must not 13 claim that you wrote the original software. If you use this software 14 in a product, an acknowledgment in the product documentation would be 15 appreciated but is not required. 16 2. Altered source versions must be plainly marked as such, and must not be 17 misrepresented as being the original software. 18 3. This notice may not be removed or altered from any source distribution. 19 20 L. Peter Deutsch 21 ghost@aladdin.com 22 23 */ 24 /* 25 Independent implementation of MD5 (RFC 1321). 26 27 This code implements the MD5 Algorithm defined in RFC 1321. 28 It is derived directly from the text of the RFC and not from the 29 reference implementation. 30 31 The original and principal author of md5.h is L. Peter Deutsch 32 <ghost@aladdin.com>. Other authors are noted in the change history 33 that follows (in reverse chronological order): 34 35 2004-03-09 Jelmer Vernooij add G_MODULE_EXPORT for Bitlbee 36 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. 37 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); 38 added conditionalization for C++ compilation from Martin 39 Purschke <purschke@bnl.gov>. 40 1999-05-03 lpd Original version. 2 * MD5 hashing code copied from Lepton's crack <http://usuarios.lycos.es/reinob/> 3 * 4 * Adapted to be API-compatible with the previous (GPL-incompatible) code. 41 5 */ 42 6 43 #ifndef md5_INCLUDED 44 # define md5_INCLUDED 7 /* 8 * This code implements the MD5 message-digest algorithm. 9 * The algorithm is due to Ron Rivest. This code was 10 * written by Colin Plumb in 1993, no copyright is claimed. 11 * This code is in the public domain; do with it what you wish. 12 * 13 * Equivalent code is available from RSA Data Security, Inc. 14 * This code has been tested against that, and is equivalent, 15 * except that you don't need to include two pages of legalese 16 * with every copy. 17 * 18 * To compute the message digest of a chunk of bytes, declare an 19 * MD5Context structure, pass it to MD5Init, call MD5Update as 20 * needed on buffers full of bytes, and then call MD5Final, which 21 * will fill a supplied 16-byte array with the digest. 22 */ 45 23 46 #include <glib.h> 24 #ifndef _MD5_H 25 #define _MD5_H 26 27 #include <sys/types.h> 47 28 #include <gmodule.h> 48 29 49 /* 50 * This code has some adaptations for the Ghostscript environment, but it 51 * will compile and run correctly in any environment with 8-bit chars and 52 * 32-bit ints. Specifically, it assumes that if the following are 53 * defined, they have the same meaning as in Ghostscript: P1, P2, P3, 54 * ARCH_IS_BIG_ENDIAN. 55 */ 56 57 typedef unsigned char md5_byte_t; /* 8-bit byte */ 58 typedef unsigned int md5_word_t; /* 32-bit word */ 59 60 /* Define the state of the MD5 Algorithm. */ 61 typedef struct md5_state_s { 62 md5_word_t count[2]; /* message length in bits, lsw first */ 63 md5_word_t abcd[4]; /* digest buffer */ 64 md5_byte_t buf[64]; /* accumulate block */ 30 typedef u_int8_t md5_byte_t; 31 typedef struct MD5Context { 32 u_int32_t buf[4]; 33 u_int32_t bits[2]; 34 unsigned char in[64]; 65 35 } md5_state_t; 66 36 67 #ifdef __cplusplus 68 extern "C" 69 { 37 G_MODULE_EXPORT void md5_init(struct MD5Context *context); 38 G_MODULE_EXPORT void md5_append(struct MD5Context *context, const md5_byte_t *buf, unsigned int len); 39 G_MODULE_EXPORT void md5_finish(struct MD5Context *context, md5_byte_t digest[16]); 40 70 41 #endif 71 72 /* Initialize the algorithm. */73 G_MODULE_EXPORT void md5_init(md5_state_t *pms);74 75 /* Append a string to the message. */76 G_MODULE_EXPORT void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);77 78 /* Finish the message and return the digest. */79 G_MODULE_EXPORT void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);80 81 #ifdef __cplusplus82 } /* end extern "C" */83 #endif84 85 #endif /* md5_INCLUDED */
Note: See TracChangeset
for help on using the changeset viewer.