00001
00002 #ifndef SST_SHA2_H
00003 #define SST_SHA2_H
00004
00005 #include <QIODevice>
00006
00007 #include <openssl/fips_sha.h>
00008
00009 class QByteArray;
00010
00011
00012 namespace SST {
00013
00014
00015 struct SecureHash : public QIODevice
00016 {
00017 SecureHash(QObject *parent = NULL);
00018 SecureHash(const SecureHash &other);
00019
00020 bool isSequential() const;
00021 bool open(OpenMode mode);
00022 qint64 readData(char * data, qint64 maxSize);
00023
00024 inline void init() { reset(); }
00025 inline void update(const void *buf, size_t size)
00026 { writeData((const char*)buf, size); }
00027 inline void update(const QByteArray &buf)
00028 { writeData(buf.constData(), buf.size()); }
00029
00030 virtual int outSize() = 0;
00031 virtual QByteArray final() = 0;
00032 };
00033
00034 struct Sha256 : public SecureHash
00035 {
00036 SHA256_CTX ctx;
00037
00038 Sha256(QObject *parent = NULL);
00039 int outSize();
00040 bool reset();
00041 qint64 writeData(const char *data, qint64 len);
00042 QByteArray final();
00043
00044 static QByteArray hash(const void*, size_t);
00045 static QByteArray hash(const QByteArray &);
00046 };
00047
00048 struct Sha384 : public SecureHash
00049 {
00050 SHA512_CTX ctx;
00051
00052 Sha384(QObject *parent = NULL);
00053 int outSize();
00054 bool reset();
00055 qint64 writeData(const char *data, qint64 len);
00056 QByteArray final();
00057
00058 static QByteArray hash(const void*, size_t);
00059 static QByteArray hash(const QByteArray &);
00060 };
00061
00062 struct Sha512 : public SecureHash
00063 {
00064 SHA512_CTX ctx;
00065
00066 Sha512(QObject *parent = NULL);
00067 int outSize();
00068 bool reset();
00069 qint64 writeData(const char *data, qint64 len);
00070 QByteArray final();
00071
00072 static QByteArray hash(const void*, size_t);
00073 static QByteArray hash(const QByteArray &);
00074 };
00075
00076 }
00077
00078 #endif