md5.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 02 Feb 2006 07:07:03 +0000
changeset 104 339482f858af
parent 0 31eee864ed5d
permissions -rw-r--r--
Argh, really fix byte order serialization.
icculus@0
     1
/*
icculus@0
     2
  Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
icculus@0
     3
icculus@0
     4
  This software is provided 'as-is', without any express or implied
icculus@0
     5
  warranty.  In no event will the authors be held liable for any damages
icculus@0
     6
  arising from the use of this software.
icculus@0
     7
icculus@0
     8
  Permission is granted to anyone to use this software for any purpose,
icculus@0
     9
  including commercial applications, and to alter it and redistribute it
icculus@0
    10
  freely, subject to the following restrictions:
icculus@0
    11
icculus@0
    12
  1. The origin of this software must not be misrepresented; you must not
icculus@0
    13
     claim that you wrote the original software. If you use this software
icculus@0
    14
     in a product, an acknowledgment in the product documentation would be
icculus@0
    15
     appreciated but is not required.
icculus@0
    16
  2. Altered source versions must be plainly marked as such, and must not be
icculus@0
    17
     misrepresented as being the original software.
icculus@0
    18
  3. This notice may not be removed or altered from any source distribution.
icculus@0
    19
icculus@0
    20
  L. Peter Deutsch
icculus@0
    21
  ghost@@aladdin.com
icculus@0
    22
icculus@0
    23
 */
icculus@0
    24
/*$Id: md5.h,v 1.1 2004/01/05 18:54:19 icculus Exp $ */
icculus@0
    25
/*
icculus@0
    26
  Independent implementation of MD5 (RFC 1321).
icculus@0
    27
icculus@0
    28
  This code implements the MD5 Algorithm defined in RFC 1321.
icculus@0
    29
  It is derived directly from the text of the RFC and not from the
icculus@0
    30
  reference implementation.
icculus@0
    31
icculus@0
    32
  The original and principal author of md5.h is L. Peter Deutsch
icculus@0
    33
  <ghost@@aladdin.com>.  Other authors are noted in the change history
icculus@0
    34
  that follows (in reverse chronological order):
icculus@0
    35
icculus@0
    36
  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
icculus@0
    37
  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
icculus@0
    38
	added conditionalization for C++ compilation from Martin
icculus@0
    39
	Purschke <purschke@@bnl.gov>.
icculus@0
    40
  1999-05-03 lpd Original version.
icculus@0
    41
 */
icculus@0
    42
icculus@0
    43
#ifndef md5_INCLUDED
icculus@0
    44
#  define md5_INCLUDED
icculus@0
    45
icculus@0
    46
#if ((PLATFORM_WIN32) || (defined WIN32))
icculus@0
    47
#define ARCH_IS_BIG_ENDIAN 0
icculus@0
    48
icculus@0
    49
#elif (defined PLATFORM_UNIX)
icculus@0
    50
icculus@0
    51
/* thanks to SDL headers for this. */
icculus@0
    52
#if  defined(__i386__) || defined(__ia64__) || defined(WIN32) || \
icculus@0
    53
    (defined(__alpha__) || defined(__alpha)) || \
icculus@0
    54
     defined(__arm__) || \
icculus@0
    55
    (defined(__mips__) && defined(__MIPSEL__)) || \
icculus@0
    56
     defined(__LITTLE_ENDIAN__)
icculus@0
    57
  #define ARCH_IS_BIG_ENDIAN 0
icculus@0
    58
#else
icculus@0
    59
  #define ARCH_IS_BIG_ENDIAN 1
icculus@0
    60
#endif
icculus@0
    61
icculus@0
    62
#else
icculus@0
    63
#error Please add your platform.
icculus@0
    64
#endif
icculus@0
    65
icculus@0
    66
/*
icculus@0
    67
 * This code has some adaptations for the Ghostscript environment, but it
icculus@0
    68
 * will compile and run correctly in any environment with 8-bit chars and
icculus@0
    69
 * 32-bit ints.  Specifically, it assumes that if the following are
icculus@0
    70
 * defined, they have the same meaning as in Ghostscript: P1, P2, P3,
icculus@0
    71
 * ARCH_IS_BIG_ENDIAN.
icculus@0
    72
 */
icculus@0
    73
icculus@0
    74
typedef unsigned char md5_byte_t; /* 8-bit byte */
icculus@0
    75
typedef unsigned int md5_word_t; /* 32-bit word */
icculus@0
    76
icculus@0
    77
/* Define the state of the MD5 Algorithm. */
icculus@0
    78
typedef struct md5_state_s {
icculus@0
    79
    md5_word_t count[2];	/* message length in bits, lsw first */
icculus@0
    80
    md5_word_t abcd[4];		/* digest buffer */
icculus@0
    81
    md5_byte_t buf[64];		/* accumulate block */
icculus@0
    82
} md5_state_t;
icculus@0
    83
icculus@0
    84
#ifdef __cplusplus
icculus@0
    85
extern "C" 
icculus@0
    86
{
icculus@0
    87
#endif
icculus@0
    88
icculus@0
    89
/* Initialize the algorithm. */
icculus@0
    90
#ifdef P1
icculus@0
    91
void md5_init(P1(md5_state_t *pms));
icculus@0
    92
#else
icculus@0
    93
void md5_init(md5_state_t *pms);
icculus@0
    94
#endif
icculus@0
    95
icculus@0
    96
/* Append a string to the message. */
icculus@0
    97
#ifdef P3
icculus@0
    98
void md5_append(P3(md5_state_t *pms, const md5_byte_t *data, int nbytes));
icculus@0
    99
#else
icculus@0
   100
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
icculus@0
   101
#endif
icculus@0
   102
icculus@0
   103
/* Finish the message and return the digest. */
icculus@0
   104
#ifdef P2
icculus@0
   105
void md5_finish(P2(md5_state_t *pms, md5_byte_t digest[16]));
icculus@0
   106
#else
icculus@0
   107
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
icculus@0
   108
#endif
icculus@0
   109
icculus@0
   110
#ifdef __cplusplus
icculus@0
   111
}  /* end extern "C" */
icculus@0
   112
#endif
icculus@0
   113
icculus@0
   114
#endif /* md5_INCLUDED */
icculus@0
   115