]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/sha1.h
e7683fa7b034527d8742421971e25755dc087917
[apt.git] / apt-pkg / contrib / sha1.h
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 SHA1SumValue - Storage for a SHA-1 hash.
7 SHA1Summation - SHA-1 Secure Hash Algorithm.
8
9 This is a C++ interface to a set of SHA1Sum functions, that mirrors
10 the equivalent MD5 classes.
11
12 ##################################################################### */
13 /*}}}*/
14 #ifndef APTPKG_SHA1_H
15 #define APTPKG_SHA1_H
16
17 #include <string>
18 #include <cstring>
19 #include <algorithm>
20
21 using std::string;
22 using std::min;
23
24 #include "hashsum_template.h"
25
26 class SHA1Summation;
27
28 typedef HashSumValue<160> SHA1SumValue;
29
30 class SHA1Summation
31 {
32 /* assumes 64-bit alignment just in case */
33 unsigned char Buffer[64] __attribute__((aligned(8)));
34 unsigned char State[5*4] __attribute__((aligned(8)));
35 unsigned char Count[2*4] __attribute__((aligned(8)));
36 bool Done;
37
38 public:
39
40 bool Add(const unsigned char *inbuf,unsigned long inlen);
41 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
42 bool AddFD(int Fd,unsigned long Size);
43 inline bool Add(const unsigned char *Beg,const unsigned char *End)
44 {return Add(Beg,End-Beg);};
45 SHA1SumValue Result();
46
47 SHA1Summation();
48 };
49
50 #endif