MD5.h
Go to the documentation of this file.
1 /* MD5
2 converted to C++ class by Frank Thilo (thilo@unix-ag.org)
3 for bzflag (http://www.bzflag.org)
4 
5 based on:
6 
7 md5.h and md5.c
8 reference implementation of RFC 1321
9 
10 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
11 rights reserved.
12 
13 License to copy and use this software is granted provided that it
14 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
15 Algorithm" in all material mentioning or referencing this software
16 or this function.
17 
18 License is also granted to make and use derivative works provided
19 that such works are identified as "derived from the RSA Data
20 Security, Inc. MD5 Message-Digest Algorithm" in all material
21 mentioning or referencing the derived work.
22 
23 RSA Data Security, Inc. makes no representations concerning either
24 the merchantability of this software or the suitability of this
25 software for any particular purpose. It is provided "as is"
26 without express or implied warranty of any kind.
27 
28 These notices must be retained in any copies of any part of this
29 documentation and/or software.
30 
31 */
32 
33 #ifndef BZF_MD5_H
34 #define BZF_MD5_H
35 
36 #include <string>
37 #include <iostream>
38 
39 namespace visionary
40 {
41 
42 // a small class for calculating MD5 hashes of strings or byte arrays
43 // it is not meant to be fast or secure
44 //
45 // usage: 1) feed it blocks of uchars with update()
46 // 2) finalize()
47 // 3) get hexdigest() string
48 // or
49 // MD5(std::string).hexdigest()
50 //
51 // assumes that char is 8 bit and int is 32 bit
52 class MD5
53 {
54 public:
55  typedef unsigned int size_type; // must be 32bit
56 
57  MD5();
58  explicit MD5(const std::string& text);
59 
60  void update(const unsigned char *buf, size_type length);
61  void update(const char *buf, size_type length);
62  MD5& finalize();
63  std::string hexdigest() const;
64  const unsigned char* getDigest() const;
65  friend std::ostream& operator<<(std::ostream&, const MD5 &md5);
66 
67 private:
68  void init();
69  typedef unsigned char uint1; // 8bit
70  typedef unsigned int uint4; // 32bit
71  enum { blocksize = 64 }; // VC6 won't eat a const static int here
72 
73  void transform(const uint1 block[blocksize]);
74  static void decode(uint4 output[], const uint1 input[], size_type len);
75  static void encode(uint1 output[], const uint4 input[], size_type len);
76 
77  bool finalized;
78  uint1 buffer[blocksize]; // bytes that didn't fit in last 64 byte chunk
79  uint4 count[2]; // 64bit counter for number of bits (lo, hi)
80  uint4 state[4]; // digest so far
81  uint1 digest[16]; // the result
82 
83  // low level logic operations
84  static inline uint4 F(uint4 x, uint4 y, uint4 z);
85  static inline uint4 G(uint4 x, uint4 y, uint4 z);
86  static inline uint4 H(uint4 x, uint4 y, uint4 z);
87  static inline uint4 I(uint4 x, uint4 y, uint4 z);
88  static inline uint4 rotate_left(uint4 x, int n);
89  static inline void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
90  static inline void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
91  static inline void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
92  static inline void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
93 };
94 
95 std::string md5(const std::string& str);
96 
97 }
98 
99 #endif
visionary::MD5::init
void init()
Definition: MD5.cpp:129
visionary::MD5::G
static uint4 G(uint4 x, uint4 y, uint4 z)
Definition: MD5.cpp:72
visionary::MD5::size_type
unsigned int size_type
Definition: MD5.h:55
visionary::md5
std::string md5(const std::string &str)
Definition: MD5.cpp:369
visionary::MD5::count
uint4 count[2]
Definition: MD5.h:79
visionary
Definition: MD5.cpp:44
visionary::MD5::finalized
bool finalized
Definition: MD5.h:77
visionary::MD5::finalize
MD5 & finalize()
Definition: MD5.cpp:307
visionary::MD5::digest
uint1 digest[16]
Definition: MD5.h:81
visionary::MD5::decode
static void decode(uint4 output[], const uint1 input[], size_type len)
Definition: MD5.cpp:146
visionary::MD5::HH
static void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: MD5.cpp:99
visionary::MD5::encode
static void encode(uint1 output[], const uint4 input[], size_type len)
Definition: MD5.cpp:157
visionary::MD5::update
void update(const unsigned char *buf, size_type length)
visionary::MD5::MD5
MD5()
Definition: MD5.cpp:110
visionary::MD5
Definition: MD5.h:52
visionary::MD5::II
static void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: MD5.cpp:103
visionary::MD5::getDigest
const unsigned char * getDigest() const
Definition: MD5.cpp:357
visionary::MD5::operator<<
friend std::ostream & operator<<(std::ostream &, const MD5 &md5)
Definition: MD5.cpp:362
visionary::MD5::buffer
uint1 buffer[blocksize]
Definition: MD5.h:78
visionary::MD5::uint4
unsigned int uint4
Definition: MD5.h:70
visionary::MD5::transform
void transform(const uint1 block[blocksize])
Definition: MD5.cpp:170
visionary::MD5::I
static uint4 I(uint4 x, uint4 y, uint4 z)
Definition: MD5.cpp:80
visionary::MD5::FF
static void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: MD5.cpp:91
visionary::MD5::F
static uint4 F(uint4 x, uint4 y, uint4 z)
Definition: MD5.cpp:68
visionary::MD5::hexdigest
std::string hexdigest() const
Definition: MD5.cpp:344
visionary::MD5::GG
static void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
Definition: MD5.cpp:95
visionary::MD5::rotate_left
static uint4 rotate_left(uint4 x, int n)
Definition: MD5.cpp:85
visionary::MD5::state
uint4 state[4]
Definition: MD5.h:80
visionary::MD5::uint1
unsigned char uint1
Definition: MD5.h:69
visionary::MD5::blocksize
@ blocksize
Definition: MD5.h:71
visionary::MD5::H
static uint4 H(uint4 x, uint4 y, uint4 z)
Definition: MD5.cpp:76


sick_visionary_ros
Author(s): SICK AG TechSupport 3D Snapshot
autogenerated on Thu Feb 8 2024 03:44:21