Browse Source

*** empty log message ***

Mike Goslin 25 years ago
parent
commit
59ea273e43
2 changed files with 62 additions and 0 deletions
  1. 58 0
      panda/src/downloader/download_utils.cxx
  2. 4 0
      panda/src/downloader/download_utils.h

+ 58 - 0
panda/src/downloader/download_utils.cxx

@@ -60,3 +60,61 @@ check_adler(Filename name) {
 
   return adler;
 }
+
+#include <md5.h>
+#include <files.h>
+
+#include <iostream>
+#include <string>
+#include <strstream>
+
+USING_NAMESPACE(CryptoPP);
+USING_NAMESPACE(std);
+
+uint 
+read32(istream& is) {
+  unsigned int ret = 0x0;
+  unsigned char b1, b2, b3, b4;
+  is >> b1;
+  is >> b2;
+  is >> b3;
+  is >> b4;
+  ret = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
+  return ret;
+}
+
+void 
+md5_a_file(const Filename &name, HashVal &ret) {
+  ostrstream os;
+  MD5 md5;
+
+  string fs = name.get_fullpath();
+  FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os)));
+
+  istrstream is(os.str());
+
+  ret[0] = read32(is);
+  ret[1] = read32(is);
+  ret[2] = read32(is);
+  ret[3] = read32(is);
+}
+
+void 
+md5_a_buffer(unsigned char* buf, unsigned long len, HashVal& ret) {
+  MD5 md5;
+
+  HashFilter hash(md5);
+  hash.Put((byte*)buf, len);
+  hash.Close();
+
+  unsigned char* outb;
+  unsigned long outl = hash.MaxRetrieveable();
+  outb = new uchar[outl];
+  hash.Get((byte*)outb, outl);
+  ret[0] = (outb[0] << 24) | (outb[1] << 16) | (outb[2] << 8) | outb[3];
+  ret[1] = (outb[4] << 24) | (outb[5] << 16) | (outb[6] << 8) | outb[7];
+  ret[2] = (outb[8] << 24) | (outb[9] << 16) | (outb[10] << 8) | outb[11];
+  ret[3] = (outb[12] << 24) | (outb[13] << 16) | (outb[14] << 8) | outb[15];
+  delete outb;
+}
+

+ 4 - 0
panda/src/downloader/download_utils.h

@@ -10,8 +10,12 @@
 #include <typedef.h>
 #include <filename.h>
 
+typedef uint HashVal[4];
+
 EXPCL_PANDAEXPRESS ulong check_crc(Filename name);
 EXPCL_PANDAEXPRESS ulong check_adler(Filename name);
+EXPCL_PANDAEXPRESS void md5_a_file(const Filename &fname, HashVal &ret);
+EXPCL_PANDAEXPRESS void md5_a_buffer(uchar *buf, ulong len, HashVal &ret);
 
 #endif