diff --git a/panda/src/downloader/crypto_utils.cxx b/panda/src/downloader/crypto_utils.cxx index 62aff1a572..b3a52659c2 100644 --- a/panda/src/downloader/crypto_utils.cxx +++ b/panda/src/downloader/crypto_utils.cxx @@ -1,64 +1,64 @@ -// Filename: crypto_utils.cxx -// Created by: drose (07Nov00) -// -//////////////////////////////////////////////////////////////////// - -// This file is compiled only if we have crypto++ installed. - -#include "crypto_utils.h" - -#include -#include - -#include - -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) { - ostringstream os; - MD5 md5; - - string fs = name.get_fullpath(); - FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os))); - - istringstream 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; -} - +// Filename: crypto_utils.cxx +// Created by: drose (07Nov00) +// +//////////////////////////////////////////////////////////////////// + +// This file is compiled only if we have crypto++ installed. + +#include "crypto_utils.h" + +#include +#include + +#include + +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) { + ostringstream os; + MD5 md5; + + string fs = name.get_fullpath(); + FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os))); + + istringstream 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; +} + diff --git a/panda/src/downloader/crypto_utils.h b/panda/src/downloader/crypto_utils.h index 49eafd74e4..609654eb82 100644 --- a/panda/src/downloader/crypto_utils.h +++ b/panda/src/downloader/crypto_utils.h @@ -1,19 +1,19 @@ -// Filename: crypto_utils.h -// Created by: drose (07Nov00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef CRYPTO_UTILS_H -#define CRYPTO_UTILS_H - -#include -#include -#include - -typedef uint HashVal[4]; - -EXPCL_PANDAEXPRESS void md5_a_file(const Filename &fname, HashVal &ret); -EXPCL_PANDAEXPRESS void md5_a_buffer(uchar *buf, ulong len, HashVal &ret); - -#endif - +// Filename: crypto_utils.h +// Created by: drose (07Nov00) +// +//////////////////////////////////////////////////////////////////// + +#ifndef CRYPTO_UTILS_H +#define CRYPTO_UTILS_H + +#include +#include +#include + +typedef uint HashVal[4]; + +EXPCL_PANDAEXPRESS void md5_a_file(const Filename &fname, HashVal &ret); +EXPCL_PANDAEXPRESS void md5_a_buffer(uchar *buf, ulong len, HashVal &ret); + +#endif +