]> granicus.if.org Git - pdns/commitdiff
Changed to use PolarSSL md5 hashing
authorAki Tuomi <cmouse@desteem.org>
Mon, 27 May 2013 09:17:13 +0000 (12:17 +0300)
committerAki Tuomi <cmouse@desteem.org>
Mon, 27 May 2013 09:17:13 +0000 (12:17 +0300)
pdns/md5.hh

index d559a4ff5ca5399378aa5f9d430dd4e7d9538de3..46b47f9c3709202be997a7866458998950719bba 100644 (file)
@@ -3,32 +3,37 @@
 
 #include <string>
 #include <stdint.h>
+#ifdef HAVE_LIBPOLARSSLSSL
+#include <polarssl/md5.h>
+#else
+#include "ext/polarssl-1.1.2/include/polarssl/md5.h"
+#endif
+
 class MD5Summer
 {
 public:
-  MD5Summer();
-  void feed(const std::string &str);
-  void feed(const char* ptr, size_t len);
-  const std::string get() const;
-
-  struct md5_context
-  {
-    uint32_t total[2];
-    uint32_t state[4];
-    uint8_t buffer[64];
+  MD5Summer() { md5_starts(&d_context); };
+  void feed(const std::string &str) { feed(str.c_str(), str.length()); }
+  void feed(const char* ptr, size_t len) { md5_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
+  const std::string get() const {  
+    md5_context ctx2;
+    unsigned char result[16] = {0};
+    ctx2=d_context;
+    md5_finish(&ctx2, result);
+    return std::string(result, result + sizeof result);
   };
-
 private:
   MD5Summer(const MD5Summer&);
   MD5Summer& operator=(const MD5Summer&);
-  struct md5_context d_context;
+
+  md5_context d_context;
 };
 
 inline std::string pdns_md5sum(const std::string& input)
 {
-  MD5Summer md5;
-  md5.feed(input);
-  return md5.get();
+  unsigned char result[16] = {0};
+  md5(reinterpret_cast<const unsigned char*>(input.c_str()), input.length(), result);
+  return std::string(result, result + sizeof result);
 }
 
 #endif /* md5.h */