00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef APTPKG_SHA256_H
00015 #define APTPKG_SHA256_H
00016
00017 #include <string>
00018 #include <cstring>
00019 #include <algorithm>
00020 #include <stdint.h>
00021
00022 using std::string;
00023 using std::min;
00024
00025 class SHA256Summation;
00026
00027 class SHA256SumValue
00028 {
00029 friend class SHA256Summation;
00030 unsigned char Sum[32];
00031
00032 public:
00033
00034
00035 bool operator ==(const SHA256SumValue &rhs) const;
00036 string Value() const;
00037 inline void Value(unsigned char S[32])
00038 {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
00039 inline operator string() const {return Value();};
00040 bool Set(string Str);
00041 inline void Set(unsigned char S[32])
00042 {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
00043
00044 SHA256SumValue(string Str);
00045 SHA256SumValue();
00046 };
00047
00048 struct sha256_ctx {
00049 uint32_t count[2];
00050 uint32_t state[8];
00051 uint8_t buf[128];
00052 };
00053
00054 class SHA256Summation
00055 {
00056 struct sha256_ctx Sum;
00057
00058 bool Done;
00059
00060 public:
00061
00062 bool Add(const unsigned char *inbuf,unsigned long inlen);
00063 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
00064 bool AddFD(int Fd,unsigned long Size);
00065 inline bool Add(const unsigned char *Beg,const unsigned char *End)
00066 {return Add(Beg,End-Beg);};
00067 SHA256SumValue Result();
00068
00069 SHA256Summation();
00070 };
00071
00072 #endif