src/md5.h
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6574 e1d1a12faaf7
child 10429 1b99254f9607
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
    29 /*
    29 /*
    30   Independent implementation of MD5 (RFC 1321).
    30   Independent implementation of MD5 (RFC 1321).
    31 
    31 
    32   This code implements the MD5 Algorithm defined in RFC 1321, whose
    32   This code implements the MD5 Algorithm defined in RFC 1321, whose
    33   text is available at
    33   text is available at
    34 	http://www.ietf.org/rfc/rfc1321.txt
    34   http://www.ietf.org/rfc/rfc1321.txt
    35   The code is derived from the text of the RFC, including the test suite
    35   The code is derived from the text of the RFC, including the test suite
    36   (section A.5) but excluding the rest of Appendix A.  It does not include
    36   (section A.5) but excluding the rest of Appendix A.  It does not include
    37   any code or documentation that is identified in the RFC as being
    37   any code or documentation that is identified in the RFC as being
    38   copyrighted.
    38   copyrighted.
    39 
    39 
    40   The original and principal author of md5.h is L. Peter Deutsch
    40   The original and principal author of md5.h is L. Peter Deutsch
    41   <ghost@aladdin.com>.  Other authors are noted in the change history
    41   <ghost@aladdin.com>.  Other authors are noted in the change history
    42   that follows (in reverse chronological order):
    42   that follows (in reverse chronological order):
    43 
    43 
       
    44   2007-12-24 Changed to C++ and adapted to OpenTTD source
    44   2002-04-13 lpd Removed support for non-ANSI compilers; removed
    45   2002-04-13 lpd Removed support for non-ANSI compilers; removed
    45 	references to Ghostscript; clarified derivation from RFC 1321;
    46              references to Ghostscript; clarified derivation from RFC 1321;
    46 	now handles byte order either statically or dynamically.
    47              now handles byte order either statically or dynamically.
    47   1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
    48   1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
    48   1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
    49   1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
    49 	added conditionalization for C++ compilation from Martin
    50              added conditionalization for C++ compilation from Martin
    50 	Purschke <purschke@bnl.gov>.
    51              Purschke <purschke@bnl.gov>.
    51   1999-05-03 lpd Original version.
    52   1999-05-03 lpd Original version.
    52  */
    53  */
    53 
    54 
    54 #ifndef MD5_INCLUDED
    55 #ifndef MD5_INCLUDED
    55 #define MD5_INCLUDED
    56 #define MD5_INCLUDED
    62  * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
    63  * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
    63  * run on either big- or little-endian CPUs, but will run slightly less
    64  * run on either big- or little-endian CPUs, but will run slightly less
    64  * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
    65  * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
    65  */
    66  */
    66 
    67 
    67 typedef unsigned char md5_byte_t; /* 8-bit byte */
    68 struct Md5 {
    68 typedef unsigned int md5_word_t; /* 32-bit word */
    69 private:
       
    70 	uint32 count[2]; ///< message length in bits, lsw first
       
    71 	uint32 abcd[4];  ///< digest buffer
       
    72 	uint8 buf[64];   ///< accumulate block
    69 
    73 
    70 /* Define the state of the MD5 Algorithm. */
    74 	void Process(const uint8 *data);
    71 struct md5_state_t {
    75 
    72     md5_word_t count[2]; /* message length in bits, lsw first */
    76 public:
    73     md5_word_t abcd[4];  /* digest buffer */
    77 	Md5();
    74     md5_byte_t buf[64];  /* accumulate block */
    78 	void Append(const void *data, const size_t nbytes);
       
    79 	void Finish(uint8 digest[16]);
    75 };
    80 };
    76 
    81 
    77 /* Initialize the algorithm. */
       
    78 void md5_init(md5_state_t *pms);
       
    79 
       
    80 /* Append a string to the message. */
       
    81 void md5_append(md5_state_t *pms, const void *data, size_t nbytes);
       
    82 
       
    83 /* Finish the message and return the digest. */
       
    84 void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
       
    85 
       
    86 #endif /* MD5_INCLUDED */
    82 #endif /* MD5_INCLUDED */