// implied warranty of any kind.
//
// The translators/modifiers do not claim:
-// (1) that MD5 will do what you think it does;
-// (2) that this translation/ modification is accurate; or
+// (1) that MD5 will do what you think it does;
+// (2) that this translation/ modification is accurate; or
// (3) that this software is "merchantible."
//
// based on:
// is identified as the "RSA Data Security, Inc. MD5 Message-Digest
// Algorithm" in all material mentioning or referencing this software
// or this function.
-//
+//
// License is also granted to make and use derivative works provided
// that such works are identified as "derived from the RSA Data
// Security, Inc. MD5 Message-Digest Algorithm" in all material
// mentioning or referencing the derived work.
-//
+//
// RSA Data Security, Inc. makes no representations concerning either
// the merchantability of this software or the suitability of this
// software for any particular purpose. It is provided "as is"
// without express or implied warranty of any kind.
-//
+//
// These notices must be retained in any copies of any part of this
// documentation and/or software.
-//
+//
-#include "md5.hpp"
+#include "addon/md5.hpp"
#include <assert.h>
-#include <strings.h>
-#include <iostream>
#include <stdexcept>
-MD5::MD5() {
+MD5::MD5() :
+ buffer(),
+ digest(),
+ finalized()
+{
init();
}
count[1] += ((uint32_t)input_length >> 29);
-
buffer_space = 64 - buffer_index; // how much space is left in buffer
// Transform as many times as possible.
} else
input_index=0; // so we can buffer the whole input
-
// and here we do the buffering:
memcpy(buffer+buffer_index, input+input_index, input_length-input_index);
}
void MD5::update(FILE *file) {
- uint8_t buffer[1024];
+ uint8_t buffer_[1024];
int len;
- while ((len=fread(buffer, 1, 1024, file))) update(buffer, len);
+ while ((len=fread(buffer_, 1, 1024, file))) update(buffer_, len);
fclose (file);
}
void MD5::update(std::istream& stream) {
- uint8_t buffer[1024];
- int len;
+ uint8_t buffer_[1024];
while (stream.good()) {
- stream.read((char*)buffer, 1024); // note that return value of read is unusable.
- len=stream.gcount();
- update(buffer, len);
+ stream.read((char*)buffer_, 1024); // note that return value of read is unusable.
+ int len = stream.gcount();
+ update(buffer_, len);
}
}
void MD5::update(std::ifstream& stream) {
- uint8_t buffer[1024];
- int len;
+ uint8_t buffer_[1024];
while (stream.good()) {
- stream.read((char*)buffer, 1024); // note that return value of read is unusable.
- len=stream.gcount();
- update(buffer, len);
+ stream.read((char*)buffer_, 1024); // note that return value of read is unusable.
+ int len = stream.gcount();
+ update(buffer_, len);
}
}
-
-MD5::MD5(FILE *file) {
+MD5::MD5(FILE *file) :
+ finalized()
+{
init(); // must be called be all constructors
update(file);
finalize ();
}
-MD5::MD5(std::istream& stream) {
+MD5::MD5(std::istream& stream) :
+ finalized()
+{
init(); // must called by all constructors
update (stream);
finalize();
}
-MD5::MD5(std::ifstream& stream) {
+MD5::MD5(std::ifstream& stream) :
+ finalized()
+{
init(); // must called by all constructors
update (stream);
finalize();
s[32]='\0';
- return s;
+ // Create string from 's'
+ std::string s_str = std::string(s);
+ delete[] s;
+
+ return s_str;
}
std::ostream& operator<<(std::ostream &stream, MD5 context) {
return stream;
}
-
// PRIVATE METHODS:
void MD5::init() {
a += I(b, c, d) + x + ac;
a = rotate_left (a, s) +b;
}
+
+/* EOF */