]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/sha256.h
Portuguese translation update. Closes: #393199
[apt.git] / apt-pkg / contrib / sha256.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 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 #include <stdint.h>
24
25 using std::string;
26 using std::min;
27
28 class SHA256Summation;
29
30 class SHA256SumValue
31 {
32 friend class SHA256Summation;
33 unsigned char Sum[32];
34
35 public:
36
37 // Accessors
38 bool operator ==(const SHA256SumValue &rhs) const;
39 string Value() const;
40 inline void Value(unsigned char S[32])
41 {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
42 inline operator string() const {return Value();};
43 bool Set(string Str);
44 inline void Set(unsigned char S[32])
45 {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
46
47 SHA256SumValue(string Str);
48 SHA256SumValue();
49 };
50
51 struct sha256_ctx {
52 uint32_t count[2];
53 uint32_t state[8];
54 uint8_t buf[128];
55 };
56
57 class SHA256Summation
58 {
59 struct sha256_ctx Sum;
60
61 bool Done;
62
63 public:
64
65 bool Add(const unsigned char *inbuf,unsigned long inlen);
66 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
67 bool AddFD(int Fd,unsigned long Size);
68 inline bool Add(const unsigned char *Beg,const unsigned char *End)
69 {return Add(Beg,End-Beg);};
70 SHA256SumValue Result();
71
72 SHA256Summation();
73 };
74
75 #endif