]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: sha1.h,v 1.3 2001/05/07 05:05:47 jgg Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | SHA256SumValue - Storage for a SHA-256 hash. | |
7 | SHA256Summation - SHA-256 Secure Hash Algorithm. | |
8 | ||
9 | This is a C++ interface to a set of SHA256Sum functions, that mirrors | |
10 | the equivalent MD5 & SHA1 classes. | |
11 | ||
12 | ##################################################################### */ | |
13 | /*}}}*/ | |
14 | #ifndef APTPKG_SHA256_H | |
15 | #define APTPKG_SHA256_H | |
16 | ||
17 | #ifdef __GNUG__ | |
18 | #pragma interface "apt-pkg/sha256.h" | |
19 | #endif | |
20 | ||
21 | #include <string> | |
22 | #include <algorithm> | |
23 | ||
24 | using std::string; | |
25 | using std::min; | |
26 | ||
27 | class SHA256Summation; | |
28 | ||
29 | class SHA256SumValue | |
30 | { | |
31 | friend class SHA256Summation; | |
32 | unsigned char Sum[32]; | |
33 | ||
34 | public: | |
35 | ||
36 | // Accessors | |
37 | bool operator ==(const SHA256SumValue &rhs) const; | |
38 | string Value() const; | |
39 | inline void Value(unsigned char S[32]) | |
40 | {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];}; | |
41 | inline operator string() const {return Value();}; | |
42 | bool Set(string Str); | |
43 | inline void Set(unsigned char S[32]) | |
44 | {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];}; | |
45 | ||
46 | SHA256SumValue(string Str); | |
47 | SHA256SumValue(); | |
48 | }; | |
49 | ||
50 | struct sha256_ctx { | |
51 | uint32_t count[2]; | |
52 | uint32_t state[8]; | |
53 | uint8_t buf[128]; | |
54 | }; | |
55 | ||
56 | class SHA256Summation | |
57 | { | |
58 | struct sha256_ctx Sum; | |
59 | ||
60 | bool Done; | |
61 | ||
62 | public: | |
63 | ||
64 | bool Add(const unsigned char *inbuf,unsigned long inlen); | |
65 | inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));}; | |
66 | bool AddFD(int Fd,unsigned long Size); | |
67 | inline bool Add(const unsigned char *Beg,const unsigned char *End) | |
68 | {return Add(Beg,End-Beg);}; | |
69 | SHA256SumValue Result(); | |
70 | ||
71 | SHA256Summation(); | |
72 | }; | |
73 | ||
74 | #endif |