OSDN Git Service

Simplified QKeccakHash and added self-test function.
[lamexp/LameXP.git] / etc / Prerequisites / keccak / src / qkeccakhash.h
index 7e71d1c..df5c41f 100644 (file)
 // Section from KeccakSponge.h
 // needed here, since hashState needs to be explicitly 32-byte aligned and therefore can't be
 // transformed into a class (in order to forward declarate) like in the other hash wrappers.
-namespace KeccakImpl {
-#define KeccakPermutationSize 1600
-#define KeccakPermutationSizeInBytes (KeccakPermutationSize/8)
-#define KeccakMaximumRate 1536
-#define KeccakMaximumRateInBytes (KeccakMaximumRate/8)
+namespace KeccakImpl
+{
+       #define KeccakPermutationSize 1600
+       #define KeccakPermutationSizeInBytes (KeccakPermutationSize/8)
+       #define KeccakMaximumRate 1536
+       #define KeccakMaximumRateInBytes (KeccakMaximumRate/8)
 
-#if defined(__GNUC__)
-#define ALIGN __attribute__ ((aligned(32)))
-#elif defined(_MSC_VER)
-#define ALIGN __declspec(align(32))
-#else
-#define ALIGN
-#endif
+       #if defined(__GNUC__)
+       #define ALIGN __attribute__ ((aligned(32)))
+       #elif defined(_MSC_VER)
+       #define ALIGN __declspec(align(32))
+       #else
+       #define ALIGN
+       #endif
 
-ALIGN typedef struct spongeStateStruct {
-    ALIGN unsigned char state[KeccakPermutationSizeInBytes];
-    ALIGN unsigned char dataQueue[KeccakMaximumRateInBytes];
-    unsigned int rate;
-    unsigned int capacity;
-    unsigned int bitsInQueue;
-    unsigned int fixedOutputLength;
-    int squeezing;
-    unsigned int bitsAvailableForSqueezing;
-} spongeState;
-typedef spongeState hashState;
+       ALIGN typedef struct spongeStateStruct {
+               ALIGN unsigned char state[KeccakPermutationSizeInBytes];
+               ALIGN unsigned char dataQueue[KeccakMaximumRateInBytes];
+               unsigned int rate;
+               unsigned int capacity;
+               unsigned int bitsInQueue;
+               unsigned int fixedOutputLength;
+               int squeezing;
+               unsigned int bitsAvailableForSqueezing;
+       } spongeState;
+       typedef spongeState hashState;
 }
 // End Section from KeccakSponge.h
 
 class QKeccakHash
 {
 public:
-  enum HashBits {hb224, hb256, hb384, hb512};
-  QKeccakHash();
-  QKeccakHash(const QString &asciiMessage, HashBits hashBits=hb256);
-  ~QKeccakHash();
-  QByteArray toRaw() const;
-  QByteArray toHex() const;
-  QString toHexString() const;
-  bool file(const QString &fileName, HashBits hashBits=hb256, int blockSize=8388608); // 8 KiB default blockSize
-  bool startBatch(HashBits hashBits=hb256);
-  bool putBatch(const QByteArray &ba);
-  bool putBatch(const char *data, int size);
-  bool stopBatch();
-  bool isBatchRunning() const;
+       enum HashBits {hb224, hb256, hb384, hb512};
+       
+       QKeccakHash();
+       ~QKeccakHash();
+       
+       static bool selfTest(void);
+
+       bool init(HashBits hashBits=hb256);
+       bool addData(const QByteArray &data);
+       bool addData(const char *data, int size);
+       const QByteArray &finalize();
+
 protected:
-  bool setHashBitLength(HashBits hashBits);
-  KeccakImpl::hashState *mState;
-  QByteArray mHashResult;
-  int mHashBitLength;
+       bool m_initialized;
+       KeccakImpl::hashState *m_state;
+       QByteArray m_hashResult;
 };
 
 #endif // QKECCAKHASH_H