32 bit hash function introduced

This commit is contained in:
Syping 2020-10-25 14:17:36 +01:00
parent d115b6fc8b
commit 11ae78cc2f
3 changed files with 33 additions and 5 deletions

View file

@ -21,10 +21,18 @@
#include <cstdint>
#include <cstring>
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc) : hash32Func(hash32Func)
{
p_formatName = QString::fromUtf8(formatFunc());
p_checksumSize = hashSzFunc();
p_funcBit = 64;
}
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
{
p_formatName = QString::fromUtf8(formatFunc());
p_checksumSize = hashSzFunc();
p_funcBit = 32;
}
QByteArray checksum_lib::generateChecksum(const QByteArray &data)
@ -32,9 +40,16 @@ QByteArray checksum_lib::generateChecksum(const QByteArray &data)
const size_t size = data.size();
unsigned char *udata = new unsigned char[size];
std::memcpy(udata, data.constData(), size);
const u_int64_t hash = hash64Func(udata, size);
free(udata);
return QByteArray::number((quint64)hash, 16);
if (p_funcBit == 32) {
const u_int32_t hash = hash32Func(udata, size);
free(udata);
return QByteArray::number((quint32)hash, 16);
}
else {
const u_int64_t hash = hash64Func(udata, size);
free(udata);
return QByteArray::number((quint64)hash, 16);
}
}
const QString checksum_lib::formatName()

View file

@ -24,21 +24,25 @@
typedef int (*PluginHashSzFunction)();
typedef const char* (*PluginFormatFunction)();
typedef const char* (*PluginVersionFunction)();
typedef u_int32_t (*PluginHash32Function)(unsigned char*, size_t);
typedef u_int64_t (*PluginHash64Function)(unsigned char*, size_t);
class checksum_lib : public checksum
{
Q_OBJECT
public:
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc);
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc);
QByteArray generateChecksum(const QByteArray &data);
const QString formatName();
int checksumSize();
private:
PluginHash32Function hash32Func;
PluginHash64Function hash64Func;
QString p_formatName;
int p_checksumSize;
int p_funcBit;
};
#endif // CHECKSUM_LIB_H

View file

@ -36,7 +36,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("checkbrute");
a.setApplicationVersion("0.2.1");
a.setApplicationVersion("0.3");
QCommandLineParser commandLineParser;
commandLineParser.addHelpOption();
@ -111,11 +111,20 @@ int main(int argc, char *argv[])
QTextStream(stderr) << "INFO: Load plugin " << fileName << "..." << Qt::endl;
QLibrary plugin(filePath);
if (plugin.load()) {
PluginHash32Function hash32Func = (PluginHash32Function)plugin.resolve("checkbrute_hash32");
PluginHash64Function hash64Func = (PluginHash64Function)plugin.resolve("checkbrute_hash64");
PluginHashSzFunction hashSzFunc = (PluginHashSzFunction)plugin.resolve("checkbrute_hashsz");
PluginFormatFunction formatFunc = (PluginFormatFunction)plugin.resolve("checkbrute_format");
PluginVersionFunction versionFunc = (PluginVersionFunction)plugin.resolve("checkbrute_version");
if (formatFunc && hash64Func && hashSzFunc) {
if (formatFunc && hash32Func && hashSzFunc) {
QString version = "undefined";
const char *format = formatFunc();
if (versionFunc)
version = QString::fromUtf8(versionFunc());
checksum_map[format] = new checksum_lib(formatFunc, hash32Func, hashSzFunc);
QTextStream(stderr) << "INFO: " << format << " plugin " << fileName << " loaded" << Qt::endl;
}
else if (formatFunc && hash64Func && hashSzFunc) {
QString version = "undefined";
const char *format = formatFunc();
if (versionFunc)