The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
md5.hpp
Go to the documentation of this file.
1 // MD5.CC - source code for the C++/object oriented translation and
2 // modification of MD5.
3 
4 // Translation and modification (c) 1995 by Mordechai T. Abzug
5 
6 // This translation/ modification is provided "as is," without express or
7 // implied warranty of any kind.
8 
9 // The translator/ modifier does not claim (1) that MD5 will do what you think
10 // it does; (2) that this translation/ modification is accurate; or (3) that
11 // this software is "merchantible." (Language for this disclaimer partially
12 // copied from the disclaimer below).
13 
14 /* based on:
15 
16  MD5.H - header file for MD5C.C
17  MDDRIVER.C - test driver for MD2, MD4 and MD5
18 
19  Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
20 rights reserved.
21 
22 License to copy and use this software is granted provided that it
23 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
24 Algorithm" in all material mentioning or referencing this software
25 or this function.
26 
27 License is also granted to make and use derivative works provided
28 that such works are identified as "derived from the RSA Data
29 Security, Inc. MD5 Message-Digest Algorithm" in all material
30 mentioning or referencing the derived work.
31 
32 RSA Data Security, Inc. makes no representations concerning either
33 the merchantability of this software or the suitability of this
34 software for any particular purpose. It is provided "as is"
35 without express or implied warranty of any kind.
36 
37 These notices must be retained in any copies of any part of this
38 documentation and/or software.
39 
40 */
41 
42 #ifndef MD5_HPP_INCLUDED
43 #define MD5_HPP_INCLUDED
44 
45 #include <array>
46 #include <cstdint>
47 
48 class MD5 {
49 
50 public:
51 // methods for controlled operation:
52  MD5 (); // simple initializer
53  void update (const uint8_t* input, const uint32_t input_length);
54  void finalize ();
55 
56 // methods to acquire finalized result
57  std::array<uint8_t, 16> raw_digest (); // digest as a 16-byte binary array
58 
59 
60 private:
61 
62 // first, some types:
63  typedef uint32_t uint4;
64  typedef uint16_t uint2;
65  typedef uint8_t uint1;
66 
67 // next, the private data:
68  uint4 state[4];
69  uint4 count[2]; // number of *bits*, mod 2^64
70  uint1 buffer[64]; // input buffer
71  uint1 digest[16];
72  uint1 finalized;
73 
74 // last, the private methods, mostly static:
75  void init (); // called by all constructors
76  void transform (const uint1 buffer[64]); // does the real update work. Note
77  // that length is implied to be 64.
78 
79  static void encode (uint1 *dest, uint4 *src, uint4 length);
80  static void decode (uint4 *dest, const uint1 *src, uint4 length);
81 
82  static inline uint4 rotate_left (uint4 x, uint4 n);
83  static inline uint4 F (uint4 x, uint4 y, uint4 z);
84  static inline uint4 G (uint4 x, uint4 y, uint4 z);
85  static inline uint4 H (uint4 x, uint4 y, uint4 z);
86  static inline uint4 I (uint4 x, uint4 y, uint4 z);
87  static inline void FF (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
88  uint4 s, uint4 ac);
89  static inline void GG (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
90  uint4 s, uint4 ac);
91  static inline void HH (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
92  uint4 s, uint4 ac);
93  static inline void II (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
94  uint4 s, uint4 ac);
95 
96 };
97 
98 #endif
GLdouble GLdouble z
Definition: glew.h:1527
uint4 state[4]
Definition: md5.hpp:68
static void decode(uint4 *dest, const uint1 *src, uint4 length)
Definition: md5.cpp:327
uint1 finalized
Definition: md5.hpp:72
void update(const uint8_t *input, const uint32_t input_length)
Definition: md5.cpp:75
const GLfloat * c
Definition: glew.h:12741
boost::uint32_t uint32_t
Definition: xbrz.hpp:45
GLenum GLenum GLenum input
Definition: glew.h:10668
static uint4 F(uint4 x, uint4 y, uint4 z)
Definition: md5.cpp:352
static uint4 I(uint4 x, uint4 y, uint4 z)
Definition: md5.cpp:364
static void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: md5.cpp:392
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
GLenum src
Definition: glew.h:2392
#define d
void transform(const uint1 buffer[64])
Definition: md5.cpp:216
uint1 buffer[64]
Definition: md5.hpp:70
uint32_t uint4
Definition: md5.hpp:63
static uint4 rotate_left(uint4 x, uint4 n)
Definition: md5.cpp:343
GLuint GLsizei GLsizei * length
Definition: glew.h:1793
uint8_t uint1
Definition: md5.hpp:65
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
static uint4 G(uint4 x, uint4 y, uint4 z)
Definition: md5.cpp:356
static void encode(uint1 *dest, uint4 *src, uint4 length)
Definition: md5.cpp:310
static void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: md5.cpp:386
Definition: md5.hpp:48
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
GLuint GLuint GLsizei count
Definition: glew.h:1221
void init()
Definition: md5.cpp:175
static void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: md5.cpp:374
std::array< uint8_t, 16 > raw_digest()
Definition: md5.cpp:159
uint1 digest[16]
Definition: md5.hpp:71
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
uint16_t uint2
Definition: md5.hpp:64
static void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: md5.cpp:380
void finalize()
Definition: md5.cpp:122
MD5()
Definition: md5.cpp:61
GLclampd n
Definition: glew.h:5903
static uint4 H(uint4 x, uint4 y, uint4 z)
Definition: md5.cpp:360
GLdouble s
Definition: glew.h:1358