]>
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 ##################################################################### */
19 #include "sha2_internal.h"
20 #include "hashsum_template.h"
22 #ifndef APT_10_CLEANER_HEADERS
29 typedef HashSumValue
<512> SHA512SumValue
;
30 typedef HashSumValue
<256> SHA256SumValue
;
32 class SHA2SummationBase
: public SummationImplementation
37 bool Add(const unsigned char *inbuf
, unsigned long long len
) APT_OVERRIDE
APT_NONNULL(2) = 0;
42 class SHA256Summation
: public SHA2SummationBase
45 unsigned char Sum
[32];
48 bool Add(const unsigned char *inbuf
, unsigned long long len
) APT_OVERRIDE
APT_NONNULL(2)
52 SHA256_Update(&ctx
, inbuf
, len
);
55 using SummationImplementation::Add
;
57 SHA256SumValue
Result()
60 SHA256_Final(Sum
, &ctx
);
71 memset(&Sum
, 0, sizeof(Sum
));
75 class SHA512Summation
: public SHA2SummationBase
78 unsigned char Sum
[64];
81 bool Add(const unsigned char *inbuf
, unsigned long long len
) APT_OVERRIDE
APT_NONNULL(2)
85 SHA512_Update(&ctx
, inbuf
, len
);
88 using SummationImplementation::Add
;
90 SHA512SumValue
Result()
93 SHA512_Final(Sum
, &ctx
);
104 memset(&Sum
, 0, sizeof(Sum
));