mirror of
https://github.com/QuasarApp/qca.git
synced 2025-04-27 20:14:32 +00:00
Add hashing algos.
svn path=/trunk/kdesupport/qca/; revision=374188
This commit is contained in:
parent
2a1bb49334
commit
cce3f0dd74
@ -22,6 +22,14 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <botan/rng.h>
|
||||
#include <botan/md2.h>
|
||||
#include <botan/md4.h>
|
||||
#include <botan/md5.h>
|
||||
#include <botan/sha160.h>
|
||||
#include <botan/sha256.h>
|
||||
#include <botan/sha_64.h>
|
||||
#include <botan/rmd160.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
class botanRandomContext : public QCA::RandomContext
|
||||
@ -61,6 +69,325 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
class BotanMD2Context : public QCA::HashContext
|
||||
{
|
||||
public:
|
||||
BotanMD2Context(QCA::Provider *p) : QCA::HashContext(p, "md2")
|
||||
{
|
||||
hashObj = new Botan::MD2;
|
||||
}
|
||||
|
||||
~BotanMD2Context()
|
||||
{
|
||||
delete hashObj;
|
||||
}
|
||||
|
||||
Context *clone() const
|
||||
{
|
||||
return new BotanMD2Context(*this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
hashObj->clear();
|
||||
}
|
||||
|
||||
void update(const QSecureArray &a)
|
||||
{
|
||||
hashObj->update( (const Botan::byte*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
QSecureArray final()
|
||||
{
|
||||
QSecureArray a( hashObj->OUTPUT_LENGTH );
|
||||
hashObj->final( (Botan::byte *)a.data() );
|
||||
return a;
|
||||
}
|
||||
|
||||
private:
|
||||
Botan::MD2 *hashObj;
|
||||
};
|
||||
|
||||
|
||||
class BotanMD4Context : public QCA::HashContext
|
||||
{
|
||||
public:
|
||||
BotanMD4Context(QCA::Provider *p) : QCA::HashContext(p, "md4")
|
||||
{
|
||||
hashObj = new Botan::MD4;
|
||||
}
|
||||
|
||||
~BotanMD4Context()
|
||||
{
|
||||
delete hashObj;
|
||||
}
|
||||
|
||||
Context *clone() const
|
||||
{
|
||||
return new BotanMD4Context(*this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
hashObj->clear();
|
||||
}
|
||||
|
||||
void update(const QSecureArray &a)
|
||||
{
|
||||
hashObj->update( (const Botan::byte*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
QSecureArray final()
|
||||
{
|
||||
QSecureArray a( hashObj->OUTPUT_LENGTH );
|
||||
hashObj->final( (Botan::byte *)a.data() );
|
||||
return a;
|
||||
}
|
||||
|
||||
private:
|
||||
Botan::MD4 *hashObj;
|
||||
};
|
||||
|
||||
|
||||
class BotanMD5Context : public QCA::HashContext
|
||||
{
|
||||
public:
|
||||
BotanMD5Context(QCA::Provider *p) : QCA::HashContext(p, "md5")
|
||||
{
|
||||
hashObj = new Botan::MD5;
|
||||
}
|
||||
|
||||
~BotanMD5Context()
|
||||
{
|
||||
delete hashObj;
|
||||
}
|
||||
|
||||
Context *clone() const
|
||||
{
|
||||
return new BotanMD5Context(*this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
hashObj->clear();
|
||||
}
|
||||
|
||||
void update(const QSecureArray &a)
|
||||
{
|
||||
hashObj->update( (const Botan::byte*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
QSecureArray final()
|
||||
{
|
||||
QSecureArray a( hashObj->OUTPUT_LENGTH );
|
||||
hashObj->final( (Botan::byte *)a.data() );
|
||||
return a;
|
||||
}
|
||||
|
||||
private:
|
||||
Botan::MD5 *hashObj;
|
||||
};
|
||||
|
||||
|
||||
class BotanSHA1Context : public QCA::HashContext
|
||||
{
|
||||
public:
|
||||
BotanSHA1Context(QCA::Provider *p) : QCA::HashContext(p, "sha1")
|
||||
{
|
||||
hashObj = new Botan::SHA_160;
|
||||
}
|
||||
|
||||
~BotanSHA1Context()
|
||||
{
|
||||
delete hashObj;
|
||||
}
|
||||
|
||||
Context *clone() const
|
||||
{
|
||||
return new BotanSHA1Context(*this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
hashObj->clear();
|
||||
}
|
||||
|
||||
void update(const QSecureArray &a)
|
||||
{
|
||||
hashObj->update( (const Botan::byte*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
QSecureArray final()
|
||||
{
|
||||
QSecureArray a( hashObj->OUTPUT_LENGTH );
|
||||
hashObj->final( (Botan::byte *)a.data() );
|
||||
return a;
|
||||
}
|
||||
|
||||
private:
|
||||
Botan::SHA_160 *hashObj;
|
||||
};
|
||||
|
||||
|
||||
class BotanSHA256Context : public QCA::HashContext
|
||||
{
|
||||
public:
|
||||
BotanSHA256Context(QCA::Provider *p) : QCA::HashContext(p, "sha256")
|
||||
{
|
||||
hashObj = new Botan::SHA_256;
|
||||
}
|
||||
|
||||
~BotanSHA256Context()
|
||||
{
|
||||
delete hashObj;
|
||||
}
|
||||
|
||||
Context *clone() const
|
||||
{
|
||||
return new BotanSHA256Context(*this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
hashObj->clear();
|
||||
}
|
||||
|
||||
void update(const QSecureArray &a)
|
||||
{
|
||||
hashObj->update( (const Botan::byte*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
QSecureArray final()
|
||||
{
|
||||
QSecureArray a( hashObj->OUTPUT_LENGTH );
|
||||
hashObj->final( (Botan::byte *)a.data() );
|
||||
return a;
|
||||
}
|
||||
|
||||
private:
|
||||
Botan::SHA_256 *hashObj;
|
||||
};
|
||||
|
||||
class BotanSHA384Context : public QCA::HashContext
|
||||
{
|
||||
public:
|
||||
BotanSHA384Context(QCA::Provider *p) : QCA::HashContext(p, "sha384")
|
||||
{
|
||||
hashObj = new Botan::SHA_384;
|
||||
}
|
||||
|
||||
~BotanSHA384Context()
|
||||
{
|
||||
delete hashObj;
|
||||
}
|
||||
|
||||
Context *clone() const
|
||||
{
|
||||
return new BotanSHA384Context(*this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
hashObj->clear();
|
||||
}
|
||||
|
||||
void update(const QSecureArray &a)
|
||||
{
|
||||
hashObj->update( (const Botan::byte*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
QSecureArray final()
|
||||
{
|
||||
QSecureArray a( hashObj->OUTPUT_LENGTH );
|
||||
hashObj->final( (Botan::byte *)a.data() );
|
||||
return a;
|
||||
}
|
||||
|
||||
private:
|
||||
Botan::SHA_384 *hashObj;
|
||||
};
|
||||
|
||||
class BotanSHA512Context : public QCA::HashContext
|
||||
{
|
||||
public:
|
||||
BotanSHA512Context(QCA::Provider *p) : QCA::HashContext(p, "sha512")
|
||||
{
|
||||
hashObj = new Botan::SHA_512;
|
||||
}
|
||||
|
||||
~BotanSHA512Context()
|
||||
{
|
||||
delete hashObj;
|
||||
}
|
||||
|
||||
Context *clone() const
|
||||
{
|
||||
return new BotanSHA512Context(*this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
hashObj->clear();
|
||||
}
|
||||
|
||||
void update(const QSecureArray &a)
|
||||
{
|
||||
hashObj->update( (const Botan::byte*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
QSecureArray final()
|
||||
{
|
||||
QSecureArray a( hashObj->OUTPUT_LENGTH );
|
||||
hashObj->final( (Botan::byte *)a.data() );
|
||||
return a;
|
||||
}
|
||||
|
||||
private:
|
||||
Botan::SHA_512 *hashObj;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class BotanRIPEMD160Context : public QCA::HashContext
|
||||
{
|
||||
public:
|
||||
BotanRIPEMD160Context(QCA::Provider *p) : QCA::HashContext(p, "ripemd160")
|
||||
{
|
||||
hashObj = new Botan::RIPEMD_160;
|
||||
}
|
||||
|
||||
~BotanRIPEMD160Context()
|
||||
{
|
||||
delete hashObj;
|
||||
}
|
||||
|
||||
Context *clone() const
|
||||
{
|
||||
return new BotanRIPEMD160Context(*this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
hashObj->clear();
|
||||
}
|
||||
|
||||
void update(const QSecureArray &a)
|
||||
{
|
||||
hashObj->update( (const Botan::byte*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
QSecureArray final()
|
||||
{
|
||||
QSecureArray a( hashObj->OUTPUT_LENGTH );
|
||||
hashObj->final( (Botan::byte *)a.data() );
|
||||
return a;
|
||||
}
|
||||
|
||||
private:
|
||||
Botan::RIPEMD_160 *hashObj;
|
||||
};
|
||||
|
||||
|
||||
class botanProvider : public QCA::Provider
|
||||
{
|
||||
public:
|
||||
@ -68,7 +395,6 @@ public:
|
||||
{
|
||||
Botan::LibraryInitializer *init;
|
||||
init = new Botan::LibraryInitializer;
|
||||
|
||||
}
|
||||
|
||||
QString name() const
|
||||
@ -80,6 +406,14 @@ public:
|
||||
{
|
||||
QStringList list;
|
||||
list += "random";
|
||||
list += "md2";
|
||||
list += "md4";
|
||||
list += "md5";
|
||||
list += "sha1";
|
||||
list += "sha256";
|
||||
list += "sha384";
|
||||
list += "sha512";
|
||||
list += "ripemd160";
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -87,6 +421,22 @@ public:
|
||||
{
|
||||
if ( type == "random" )
|
||||
return new botanRandomContext( this );
|
||||
else if ( type == "md2" )
|
||||
return new BotanMD2Context( this );
|
||||
else if ( type == "md4" )
|
||||
return new BotanMD4Context( this );
|
||||
else if ( type == "md5" )
|
||||
return new BotanMD5Context( this );
|
||||
else if ( type == "sha1" )
|
||||
return new BotanSHA1Context( this );
|
||||
else if ( type == "sha256" )
|
||||
return new BotanSHA256Context( this );
|
||||
else if ( type == "sha384" )
|
||||
return new BotanSHA384Context( this );
|
||||
else if ( type == "sha512" )
|
||||
return new BotanSHA512Context( this );
|
||||
else if ( type == "ripemd160" )
|
||||
return new BotanRIPEMD160Context( this );
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user