PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llcommon/llmd5.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 131 lines | 38 code | 22 blank | 71 comment | 0 complexity | 319d055105939a6ece16ffa5ee591f40 MD5 | raw file
  1/** 
  2 * @file llmd5.h
  3 *
  4 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5 * Second Life Viewer Source Code
  6 * Copyright (C) 2010, Linden Research, Inc.
  7 * 
  8 * This library is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU Lesser General Public
 10 * License as published by the Free Software Foundation;
 11 * version 2.1 of the License only.
 12 * 
 13 * This library is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16 * Lesser General Public License for more details.
 17 * 
 18 * You should have received a copy of the GNU Lesser General Public
 19 * License along with this library; if not, write to the Free Software
 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 21 * 
 22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 23 * $/LicenseInfo$
 24 */
 25
 26#ifndef LL_LLMD5_H
 27#define LL_LLMD5_H
 28
 29// LLMD5.CC - source code for the C++/object oriented translation and 
 30//          modification of MD5.
 31
 32// Translation and modification (c) 1995 by Mordechai T. Abzug 
 33
 34// This translation/ modification is provided "as is," without express or 
 35// implied warranty of any kind.
 36
 37// The translator/ modifier does not claim (1) that MD5 will do what you think 
 38// it does; (2) that this translation/ modification is accurate; or (3) that 
 39// this software is "merchantible."  (Language for this disclaimer partially 
 40// copied from the disclaimer below).
 41
 42/* based on:
 43
 44   MD5.H - header file for MD5C.C
 45   MDDRIVER.C - test driver for MD2, MD4 and MD5
 46
 47   Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
 48rights reserved.
 49
 50License to copy and use this software is granted provided that it
 51is identified as the "RSA Data Security, Inc. MD5 Message-Digest
 52Algorithm" in all material mentioning or referencing this software
 53or this function.
 54
 55License is also granted to make and use derivative works provided
 56that such works are identified as "derived from the RSA Data
 57Security, Inc. MD5 Message-Digest Algorithm" in all material
 58mentioning or referencing the derived work.
 59
 60RSA Data Security, Inc. makes no representations concerning either
 61the merchantability of this software or the suitability of this
 62software for any particular purpose. It is provided "as is"
 63without express or implied warranty of any kind.
 64
 65These notices must be retained in any copies of any part of this
 66documentation and/or software.
 67
 68*/
 69
 70// use for the raw digest output
 71const int MD5RAW_BYTES = 16;
 72
 73// use for outputting hex digests
 74const int MD5HEX_STR_SIZE = 33;  // char hex[MD5HEX_STR_SIZE]; with null
 75const int MD5HEX_STR_BYTES = 32; // message system fixed size
 76
 77class LL_COMMON_API LLMD5 {
 78// first, some types:
 79  typedef unsigned       int uint4; // assumes integer is 4 words long
 80  typedef unsigned short int uint2; // assumes short integer is 2 words long
 81  typedef unsigned      char uint1; // assumes char is 1 word long
 82
 83// how many bytes to grab at a time when checking files
 84  static const int BLOCK_LEN;
 85
 86public:
 87// methods for controlled operation:
 88  LLMD5              ();  // simple initializer
 89  void  update     (const uint1 *input, const uint4 input_length);
 90  void  update     (std::istream& stream);
 91  void  update     (FILE *file);
 92  void  update     (const std::string& str);
 93  void  finalize   ();
 94
 95// constructors for special circumstances.  All these constructors finalize
 96// the MD5 context.
 97  LLMD5              (const unsigned char *string); // digest string, finalize
 98  LLMD5              (std::istream& stream);       // digest stream, finalize
 99  LLMD5              (FILE *file);            // digest file, close, finalize
100  LLMD5              (const unsigned char *string, const unsigned int number);
101  
102// methods to acquire finalized result
103  void				raw_digest(unsigned char *array) const;	// provide 16-byte array for binary data
104  void				hex_digest(char *string) const;			// provide 33-byte array for ascii-hex string
105
106  friend LL_COMMON_API std::ostream&   operator<< (std::ostream&, LLMD5 context);
107
108private:
109
110
111// next, the private data:
112  uint4 state[4];
113  uint4 count[2];     // number of *bits*, mod 2^64
114  uint1 buffer[64];   // input buffer
115  uint1 digest[16];
116  uint1 finalized;
117
118// last, the private methods, mostly static:
119  void init             ();               // called by all constructors
120  void transform        (const uint1 *buffer);  // does the real update work.  Note 
121                                          // that length is implied to be 64.
122
123  static void encode    (uint1 *dest, const uint4 *src, const uint4 length);
124  static void decode    (uint4 *dest, const uint1 *src, const uint4 length);
125
126};
127
128LL_COMMON_API bool operator==(const LLMD5& a, const LLMD5& b);
129LL_COMMON_API bool operator!=(const LLMD5& a, const LLMD5& b);
130
131#endif // LL_LLMD5_H