PageRenderTime 33ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLMD5_H
  26. #define LL_LLMD5_H
  27. // LLMD5.CC - source code for the C++/object oriented translation and
  28. // modification of MD5.
  29. // Translation and modification (c) 1995 by Mordechai T. Abzug
  30. // This translation/ modification is provided "as is," without express or
  31. // implied warranty of any kind.
  32. // The translator/ modifier does not claim (1) that MD5 will do what you think
  33. // it does; (2) that this translation/ modification is accurate; or (3) that
  34. // this software is "merchantible." (Language for this disclaimer partially
  35. // copied from the disclaimer below).
  36. /* based on:
  37. MD5.H - header file for MD5C.C
  38. MDDRIVER.C - test driver for MD2, MD4 and MD5
  39. Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  40. rights reserved.
  41. License to copy and use this software is granted provided that it
  42. is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  43. Algorithm" in all material mentioning or referencing this software
  44. or this function.
  45. License is also granted to make and use derivative works provided
  46. that such works are identified as "derived from the RSA Data
  47. Security, Inc. MD5 Message-Digest Algorithm" in all material
  48. mentioning or referencing the derived work.
  49. RSA Data Security, Inc. makes no representations concerning either
  50. the merchantability of this software or the suitability of this
  51. software for any particular purpose. It is provided "as is"
  52. without express or implied warranty of any kind.
  53. These notices must be retained in any copies of any part of this
  54. documentation and/or software.
  55. */
  56. // use for the raw digest output
  57. const int MD5RAW_BYTES = 16;
  58. // use for outputting hex digests
  59. const int MD5HEX_STR_SIZE = 33; // char hex[MD5HEX_STR_SIZE]; with null
  60. const int MD5HEX_STR_BYTES = 32; // message system fixed size
  61. class LL_COMMON_API LLMD5 {
  62. // first, some types:
  63. typedef unsigned int uint4; // assumes integer is 4 words long
  64. typedef unsigned short int uint2; // assumes short integer is 2 words long
  65. typedef unsigned char uint1; // assumes char is 1 word long
  66. // how many bytes to grab at a time when checking files
  67. static const int BLOCK_LEN;
  68. public:
  69. // methods for controlled operation:
  70. LLMD5 (); // simple initializer
  71. void update (const uint1 *input, const uint4 input_length);
  72. void update (std::istream& stream);
  73. void update (FILE *file);
  74. void update (const std::string& str);
  75. void finalize ();
  76. // constructors for special circumstances. All these constructors finalize
  77. // the MD5 context.
  78. LLMD5 (const unsigned char *string); // digest string, finalize
  79. LLMD5 (std::istream& stream); // digest stream, finalize
  80. LLMD5 (FILE *file); // digest file, close, finalize
  81. LLMD5 (const unsigned char *string, const unsigned int number);
  82. // methods to acquire finalized result
  83. void raw_digest(unsigned char *array) const; // provide 16-byte array for binary data
  84. void hex_digest(char *string) const; // provide 33-byte array for ascii-hex string
  85. friend LL_COMMON_API std::ostream& operator<< (std::ostream&, LLMD5 context);
  86. private:
  87. // next, the private data:
  88. uint4 state[4];
  89. uint4 count[2]; // number of *bits*, mod 2^64
  90. uint1 buffer[64]; // input buffer
  91. uint1 digest[16];
  92. uint1 finalized;
  93. // last, the private methods, mostly static:
  94. void init (); // called by all constructors
  95. void transform (const uint1 *buffer); // does the real update work. Note
  96. // that length is implied to be 64.
  97. static void encode (uint1 *dest, const uint4 *src, const uint4 length);
  98. static void decode (uint4 *dest, const uint1 *src, const uint4 length);
  99. };
  100. LL_COMMON_API bool operator==(const LLMD5& a, const LLMD5& b);
  101. LL_COMMON_API bool operator!=(const LLMD5& a, const LLMD5& b);
  102. #endif // LL_LLMD5_H