]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/sha2.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: sha512.h,v 1.3 2001/05/07 05:05:47 jgg Exp $
4 /* ######################################################################
6 SHA{512,256}SumValue - Storage for a SHA-{512,256} hash.
7 SHA{512,256}Summation - SHA-{512,256} Secure Hash Algorithm.
9 This is a C++ interface to a set of SHA{512,256}Sum functions, that mirrors
10 the equivalent MD5 & SHA1 classes.
12 ##################################################################### */
22 #include "sha2_internal.h"
23 #include "hashsum_template.h"
28 class SHA512Summation
;
29 class SHA256Summation
;
31 typedef HashSumValue
<512> SHA512SumValue
;
32 typedef HashSumValue
<256> SHA256SumValue
;
34 class SHA2SummationBase
39 virtual bool Add(const unsigned char *inbuf
,unsigned long inlen
) = 0;
40 virtual bool AddFD(int Fd
,unsigned long Size
);
42 inline bool Add(const char *Data
)
44 return Add((unsigned char *)Data
,strlen(Data
));
46 inline bool Add(const unsigned char *Beg
,const unsigned char *End
)
48 return Add(Beg
,End
-Beg
);
53 class SHA256Summation
: public SHA2SummationBase
56 unsigned char Sum
[32];
59 virtual bool Add(const unsigned char *inbuf
, unsigned long len
)
63 SHA256_Update(&ctx
, inbuf
, len
);
66 SHA256SumValue
Result()
69 SHA256_Final(Sum
, &ctx
);
83 class SHA512Summation
: public SHA2SummationBase
86 unsigned char Sum
[64];
89 virtual bool Add(const unsigned char *inbuf
, unsigned long len
)
93 SHA512_Update(&ctx
, inbuf
, len
);
96 SHA512SumValue
Result()
99 SHA512_Final(Sum
, &ctx
);