*** empty log message ***

This commit is contained in:
David Rose 2000-11-07 19:58:18 +00:00
parent 3fa8028d25
commit eefa9304cd
2 changed files with 83 additions and 83 deletions

View File

@ -1,64 +1,64 @@
// Filename: crypto_utils.cxx // Filename: crypto_utils.cxx
// Created by: drose (07Nov00) // Created by: drose (07Nov00)
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// This file is compiled only if we have crypto++ installed. // This file is compiled only if we have crypto++ installed.
#include "crypto_utils.h" #include "crypto_utils.h"
#include <md5.h> #include <md5.h>
#include <files.h> #include <files.h>
#include <string> #include <string>
USING_NAMESPACE(CryptoPP); USING_NAMESPACE(CryptoPP);
USING_NAMESPACE(std); USING_NAMESPACE(std);
uint uint
read32(istream& is) { read32(istream& is) {
unsigned int ret = 0x0; unsigned int ret = 0x0;
unsigned char b1, b2, b3, b4; unsigned char b1, b2, b3, b4;
is >> b1; is >> b1;
is >> b2; is >> b2;
is >> b3; is >> b3;
is >> b4; is >> b4;
ret = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; ret = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
return ret; return ret;
} }
void void
md5_a_file(const Filename &name, HashVal &ret) { md5_a_file(const Filename &name, HashVal &ret) {
ostringstream os; ostringstream os;
MD5 md5; MD5 md5;
string fs = name.get_fullpath(); string fs = name.get_fullpath();
FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os))); FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os)));
istringstream is(os.str()); istringstream is(os.str());
ret[0] = read32(is); ret[0] = read32(is);
ret[1] = read32(is); ret[1] = read32(is);
ret[2] = read32(is); ret[2] = read32(is);
ret[3] = read32(is); ret[3] = read32(is);
} }
void void
md5_a_buffer(unsigned char* buf, unsigned long len, HashVal& ret) { md5_a_buffer(unsigned char* buf, unsigned long len, HashVal& ret) {
MD5 md5; MD5 md5;
HashFilter hash(md5); HashFilter hash(md5);
hash.Put((byte*)buf, len); hash.Put((byte*)buf, len);
hash.Close(); hash.Close();
unsigned char* outb; unsigned char* outb;
unsigned long outl = hash.MaxRetrieveable(); unsigned long outl = hash.MaxRetrieveable();
outb = new uchar[outl]; outb = new uchar[outl];
hash.Get((byte*)outb, outl); hash.Get((byte*)outb, outl);
ret[0] = (outb[0] << 24) | (outb[1] << 16) | (outb[2] << 8) | outb[3]; 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[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[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]; ret[3] = (outb[12] << 24) | (outb[13] << 16) | (outb[14] << 8) | outb[15];
delete outb; delete outb;
} }

View File

@ -1,19 +1,19 @@
// Filename: crypto_utils.h // Filename: crypto_utils.h
// Created by: drose (07Nov00) // Created by: drose (07Nov00)
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#ifndef CRYPTO_UTILS_H #ifndef CRYPTO_UTILS_H
#define CRYPTO_UTILS_H #define CRYPTO_UTILS_H
#include <pandabase.h> #include <pandabase.h>
#include <filename.h> #include <filename.h>
#include <typedef.h> #include <typedef.h>
typedef uint HashVal[4]; typedef uint HashVal[4];
EXPCL_PANDAEXPRESS void md5_a_file(const Filename &fname, HashVal &ret); EXPCL_PANDAEXPRESS void md5_a_file(const Filename &fname, HashVal &ret);
EXPCL_PANDAEXPRESS void md5_a_buffer(uchar *buf, ulong len, HashVal &ret); EXPCL_PANDAEXPRESS void md5_a_buffer(uchar *buf, ulong len, HashVal &ret);
#endif #endif