yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sha1.h
Go to the documentation of this file.
1 /*
2  sha1.h - header of
3 
4  ============
5  SHA-1 in C++
6  ============
7 
8  100% Public Domain.
9 
10  Original C Code
11  -- Steve Reid <steve@edmweb.com>
12  Small changes to fit into bglibs
13  -- Bruce Guenter <bruce@untroubled.org>
14  Translation to simpler C++ Code
15  -- Volker Grabsch <vog@notjusthosting.com>
16  Fixing bugs and improving style
17  -- Eugene Hopkinson <slowriot at voxelstorm dot com>
18 */
19 
20 #ifndef SHA1_HPP
21 #define SHA1_HPP
22 
23 
24 #include <iostream>
25 #include <string>
26 #include <stdint.h>
27 
28 class SHA1
29 {
30 public:
31  SHA1();
32  void update(const std::string &s);
33  void update(std::istream &is);
34  std::string final();
35  static std::string from_file(const std::string &filename);
36 
37 private:
38  static const unsigned int DIGEST_INTS = 5; /* number of 32bit integers per SHA1 digest */
39  static const unsigned int BLOCK_INTS = 16; /* number of 32bit integers per SHA1 block */
40  static const unsigned int BLOCK_BYTES = BLOCK_INTS * 4;
41 
42  uint32_t digest[DIGEST_INTS];
43  std::string buffer;
44  uint64_t transforms;
45 
46  void reset();
47  void transform(uint32_t block[BLOCK_BYTES]);
48 
49  static void read(std::istream &is, std::string &s, size_t max);
50  static void buffer_to_block(const std::string &buffer, uint32_t block[BLOCK_INTS]);
51 };
52 
53 std::string sha1(const std::string &string);
54 
55 
56 
57 #endif /* SHA1_HPP */
void transform(uint32_t block[BLOCK_BYTES])
Definition: sha1.cpp:142
void reset()
Definition: sha1.cpp:123
std::string sha1(const std::string &string)
Definition: sha1.cpp:270
static void read(std::istream &is, std::string &s, size_t max)
Definition: sha1.cpp:259
Definition: sha1.h:28
uint32_t digest[DIGEST_INTS]
Definition: sha1.h:42
static const unsigned int BLOCK_INTS
Definition: sha1.h:39
static const unsigned int DIGEST_INTS
Definition: sha1.h:38
static std::string from_file(const std::string &filename)
Definition: sha1.cpp:114
static const unsigned int BLOCK_BYTES
Definition: sha1.h:40
static void buffer_to_block(const std::string &buffer, uint32_t block[BLOCK_INTS])
Definition: sha1.cpp:246
uint64_t transforms
Definition: sha1.h:44
std::string buffer
Definition: sha1.h:43
SHA1()
Definition: sha1.cpp:36
void update(const std::string &s)
Definition: sha1.cpp:42