libUTL++
SHA256.h
1 #pragma once
2 
4 
5 #include <libutl/Object.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
13 class SHA256sum;
14 
16 // SHA256 //////////////////////////////////////////////////////////////////////////////////////////
18 
32 
34 class SHA256 : public Object
35 {
40 
41 public:
43  void clear();
44 
46  void process(const byte_t* data, size_t dataLen);
47 
49  void finalize(SHA256sum& sum);
50 
51 private:
52  void
53  init()
54  {
55  clear();
56  }
57  void
58  deInit()
59  {
60  }
61  void transform(const byte_t* data, size_t numBlocks = 1);
62 
63 private:
64  byte_t _data[64];
65  byte_t* _dataPtr;
66  byte_t* _dataLim;
67  uint64_t _bitLen;
68  uint32_t _h[8];
69  static uint32_t k[64];
70 };
71 
73 // SHA256sum ///////////////////////////////////////////////////////////////////////////////////////
75 
83 
85 class SHA256sum : public Object
86 {
89 
90 public:
91  virtual int compare(const Object& rhs) const;
92 
93  virtual void copy(const Object& rhs);
94 
95  virtual size_t hash(size_t size) const;
96 
97  virtual void serialize(Stream& stream, uint_t io, uint_t mode);
98 
100  void set(const uint32_t* hash);
101 
103  void set(const String& str);
104 
106  virtual String toString() const;
107 
108 private:
109  uint32_t _h[8];
110 };
111 
113 
114 UTL_NS_END;
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
void deInit()
De-initialize UTL++.
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
unsigned char byte_t
Unsigned character.
Definition: types.h:31
Character string.
Definition: String.h:31
unsigned int uint32_t
Unsigned 32-bit integer.
Definition: types.h:115
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
unsigned long uint64_t
Unsigned 64-bit integer.
Definition: types.h:154
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
#define UTL_CLASS_NO_SERIALIZE
Declare that a class cannot do serialize().
Definition: macros.h:384
Stream I/O abstraction.
Definition: Stream.h:68
#define UTL_CLASS_NO_COMPARE
Declare that a class cannot do compare().
Definition: macros.h:344
#define UTL_CLASS_NO_COPY
Declare that a class cannot do copy().
Definition: macros.h:358
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
Compute SHA256 cryptographic hash.
Definition: SHA256.h:34
void init()
Initialize UTL++.
Store a SHA256 sum.
Definition: SHA256.h:85