00001 #ifndef SST_CHK32_H
00002 #define SST_CHK32_H
00003
00004 #include <stdint.h>
00005
00006 namespace SST {
00007
00008
00009
00010
00011
00012
00013 class Chk32
00014 {
00015 private:
00016
00017 static const uint32_t InitA = 0;
00018 static const uint32_t InitB = 0;
00019
00020
00021 static const int Modulus = 65537;
00022
00023
00024
00025 static const int MaxRun = 23726740;
00026
00027 uint64_t a;
00028 uint64_t b;
00029 int run;
00030 union {
00031 uint8_t b[2];
00032 uint16_t w;
00033 } oddbuf;
00034 bool haveodd;
00035
00036 public:
00037 inline Chk32() : a(InitA), b(InitB), run(MaxRun), haveodd(false) { }
00038
00039
00040 inline void init16()
00041 { a = InitA; b = InitB; run = MaxRun; haveodd = false; }
00042 void update16(const uint16_t *buf, int nwords);
00043 uint32_t final16();
00044
00045
00046 inline void init() { init16(); }
00047 void update(const void *buf, size_t size);
00048 uint32_t final();
00049
00050
00051 static inline uint32_t sum(const void *buf, size_t size) {
00052 Chk32 c; c.update(buf, size); return c.final(); }
00053 };
00054
00055
00056 }
00057
00058 #endif // SST_CHK32_H