tools/gamedata_md5/md5.h
author Nicholas Hastings <skamonkey@gmail.com>
Mon Jun 14 09:32:50 2010 -0400 (2010-06-14)
changeset 3041 a0587dee87ae
parent 2230 e650c36ac67b
permissions -rw-r--r--
Fixed outputname null pointer crash in sdktools (bug 4422, r=fyren)
pred@2125
     1
// MD5.CC - source code for the C++/object oriented translation and 
pred@2125
     2
//          modification of MD5.
pred@2125
     3
pred@2125
     4
// Translation and modification (c) 1995 by Mordechai T. Abzug 
pred@2125
     5
pred@2125
     6
// This translation/ modification is provided "as is," without express or 
pred@2125
     7
// implied warranty of any kind.
pred@2125
     8
pred@2125
     9
// The translator/ modifier does not claim (1) that MD5 will do what you think 
pred@2125
    10
// it does; (2) that this translation/ modification is accurate; or (3) that 
pred@2125
    11
// this software is "merchantible."  (Language for this disclaimer partially 
pred@2125
    12
// copied from the disclaimer below).
pred@2125
    13
pred@2125
    14
/* based on:
pred@2125
    15
pred@2125
    16
   MD5.H - header file for MD5C.C
pred@2125
    17
   MDDRIVER.C - test driver for MD2, MD4 and MD5
pred@2125
    18
pred@2125
    19
   Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
pred@2125
    20
rights reserved.
pred@2125
    21
pred@2125
    22
License to copy and use this software is granted provided that it
pred@2125
    23
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
pred@2125
    24
Algorithm" in all material mentioning or referencing this software
pred@2125
    25
or this function.
pred@2125
    26
pred@2125
    27
License is also granted to make and use derivative works provided
pred@2125
    28
that such works are identified as "derived from the RSA Data
pred@2125
    29
Security, Inc. MD5 Message-Digest Algorithm" in all material
pred@2125
    30
mentioning or referencing the derived work.
pred@2125
    31
pred@2125
    32
RSA Data Security, Inc. makes no representations concerning either
pred@2125
    33
the merchantability of this software or the suitability of this
pred@2125
    34
software for any particular purpose. It is provided "as is"
pred@2125
    35
without express or implied warranty of any kind.
pred@2125
    36
pred@2125
    37
These notices must be retained in any copies of any part of this
pred@2125
    38
documentation and/or software.
pred@2125
    39
pred@2125
    40
*/
pred@2125
    41
pred@2125
    42
#include <stdio.h>
pred@2125
    43
//#include <fstream.h>
pred@2125
    44
//#include <iostream.h>
pred@2125
    45
pred@2125
    46
class MD5 {
pred@2125
    47
pred@2125
    48
public:
pred@2125
    49
// methods for controlled operation:
pred@2125
    50
  MD5              ();  // simple initializer
pred@2125
    51
  void  update     (unsigned char *input, unsigned int input_length);
pred@2125
    52
  void  update     (FILE *file);
pred@2125
    53
  void  finalize   ();
pred@2125
    54
pred@2125
    55
// constructors for special circumstances.  All these constructors finalize
pred@2125
    56
// the MD5 context.
pred@2125
    57
  MD5              (unsigned char *string); // digest string, finalize
pred@2125
    58
  MD5              (FILE *file);            // digest file, close, finalize
pred@2125
    59
pred@2125
    60
// methods to acquire finalized result
pred@2125
    61
  unsigned char    *raw_digest ();  // digest as a 16-byte binary array
pred@2125
    62
  unsigned char		*raw_digest(unsigned char buffer[16]);
pred@2125
    63
  char *            hex_digest ();  // digest as a 33-byte ascii-hex string
pred@2125
    64
  char *			hex_digest (char buffer[33]); //same as above, passing buffer
pred@2125
    65
pred@2125
    66
pred@2125
    67
pred@2125
    68
private:
pred@2125
    69
pred@2125
    70
// first, some types:
pred@2125
    71
  typedef unsigned       int uint4; // assumes integer is 4 words long
pred@2125
    72
  typedef unsigned short int uint2; // assumes short integer is 2 words long
pred@2125
    73
  typedef unsigned      char uint1; // assumes char is 1 word long
pred@2125
    74
pred@2125
    75
// next, the private data:
pred@2125
    76
  uint4 state[4];
pred@2125
    77
  uint4 count[2];     // number of *bits*, mod 2^64
pred@2125
    78
  uint1 buffer[64];   // input buffer
pred@2125
    79
  uint1 digest[16];
pred@2125
    80
  uint1 finalized;
pred@2125
    81
pred@2125
    82
// last, the private methods, mostly static:
pred@2125
    83
  void init             ();               // called by all constructors
pred@2125
    84
  void transform        (uint1 *buffer);  // does the real update work.  Note 
pred@2125
    85
                                          // that length is implied to be 64.
pred@2125
    86
pred@2125
    87
  static void encode    (uint1 *dest, uint4 *src, uint4 length);
pred@2125
    88
  static void decode    (uint4 *dest, uint1 *src, uint4 length);
pred@2125
    89
  static void memcpy    (uint1 *dest, uint1 *src, uint4 length);
pred@2125
    90
  static void memset    (uint1 *start, uint1 val, uint4 length);
pred@2125
    91
pred@2125
    92
  static inline uint4  rotate_left (uint4 x, uint4 n);
pred@2125
    93
  static inline uint4  F           (uint4 x, uint4 y, uint4 z);
pred@2125
    94
  static inline uint4  G           (uint4 x, uint4 y, uint4 z);
pred@2125
    95
  static inline uint4  H           (uint4 x, uint4 y, uint4 z);
pred@2125
    96
  static inline uint4  I           (uint4 x, uint4 y, uint4 z);
pred@2125
    97
  static inline void   FF  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 
pred@2125
    98
			    uint4 s, uint4 ac);
pred@2125
    99
  static inline void   GG  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 
pred@2125
   100
			    uint4 s, uint4 ac);
pred@2125
   101
  static inline void   HH  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 
pred@2125
   102
			    uint4 s, uint4 ac);
pred@2125
   103
  static inline void   II  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 
pred@2125
   104
			    uint4 s, uint4 ac);
pred@2125
   105
pred@2125
   106
};