]>
Commit | Line | Data |
---|---|---|
54ce88fd MV |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
3 | // $Id: sha512.h,v 1.3 2001/05/07 05:05:47 jgg Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | SHA512SumValue - Storage for a SHA-512 hash. | |
7 | SHA512Summation - SHA-512 Secure Hash Algorithm. | |
8 | ||
9 | This is a C++ interface to a set of SHA512Sum functions, that mirrors | |
10 | the equivalent MD5 & SHA1 classes. | |
11 | ||
12 | ##################################################################### */ | |
13 | /*}}}*/ | |
14 | #ifndef APTPKG_SHA512_H | |
15 | #define APTPKG_SHA512_H | |
16 | ||
17 | #include <string> | |
18 | #include <cstring> | |
19 | #include <algorithm> | |
20 | #include <stdint.h> | |
21 | ||
22 | #include "sha2.h" | |
23 | ||
24 | using std::string; | |
25 | using std::min; | |
26 | ||
27 | class SHA512Summation; | |
28 | ||
29 | class SHA512SumValue | |
30 | { | |
31 | friend class SHA512Summation; | |
32 | unsigned char Sum[64]; | |
33 | ||
34 | public: | |
35 | ||
36 | // Accessors | |
37 | bool operator ==(const SHA512SumValue &rhs) const; | |
38 | string Value() const; | |
39 | inline void Value(unsigned char S[64]) | |
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[64]) | |
44 | {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];}; | |
45 | ||
46 | SHA512SumValue(string Str); | |
47 | SHA512SumValue(); | |
48 | }; | |
49 | ||
50 | class SHA512Summation | |
51 | { | |
52 | SHA512_CTX ctx; | |
53 | unsigned char Sum[64]; | |
54 | bool Done; | |
55 | ||
56 | public: | |
57 | ||
58 | bool Add(const unsigned char *inbuf,unsigned long inlen); | |
59 | inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));}; | |
60 | bool AddFD(int Fd,unsigned long Size); | |
61 | inline bool Add(const unsigned char *Beg,const unsigned char *End) | |
62 | {return Add(Beg,End-Beg);}; | |
63 | SHA512SumValue Result(); | |
64 | ||
65 | SHA512Summation(); | |
66 | }; | |
67 | ||
68 | #endif |