OpenClonk
sha1 Class Reference

#include <SHA1.h>

Public Types

typedef unsigned int(& digest_type)[5]
 

Public Member Functions

 sha1 ()
 
void reset ()
 
void process_byte (unsigned char byte)
 
void process_block (void const *bytes_begin, void const *bytes_end)
 
void process_bytes (void const *buffer, std::size_t byte_count)
 
void get_digest (digest_type digest)
 

Detailed Description

Definition at line 44 of file SHA1.h.

Member Typedef Documentation

◆ digest_type

typedef unsigned int(& sha1::digest_type)[5]

Definition at line 47 of file SHA1.h.

Constructor & Destructor Documentation

◆ sha1()

sha1::sha1 ( )
inline

Definition at line 75 of file SHA1.h.

76 {
77  reset();
78 }
void reset()
Definition: SHA1.h:80

References reset().

Here is the call graph for this function:

Member Function Documentation

◆ get_digest()

void sha1::get_digest ( digest_type  digest)
inline

Definition at line 169 of file SHA1.h.

170 {
171  std::size_t bit_count = byte_count_*8;
172 
173  // append the bit '1' to the message
174  process_byte(0x80);
175 
176  // append k bits '0', where k is the minimum number >= 0
177  // such that the resulting message length is congruent to 56 (mod 64)
178  // check if there is enough space for padding and bit_count
179  if (block_byte_index_ > 56) {
180  // finish this block
181  while (block_byte_index_ != 0) {
182  process_byte(0);
183  }
184 
185  // one more block
186  while (block_byte_index_ < 56) {
187  process_byte(0);
188  }
189  } else {
190  while (block_byte_index_ < 56) {
191  process_byte(0);
192  }
193  }
194 
195  // append length of message (before pre-processing)
196  // as a 64-bit big-endian integer
197  process_byte(0);
198  process_byte(0);
199  process_byte(0);
200  process_byte(0);
201  process_byte( static_cast<unsigned char>((bit_count>>24) & 0xFF));
202  process_byte( static_cast<unsigned char>((bit_count>>16) & 0xFF));
203  process_byte( static_cast<unsigned char>((bit_count>>8 ) & 0xFF));
204  process_byte( static_cast<unsigned char>((bit_count) & 0xFF));
205 
206  // get final digest
207  digest[0] = h_[0];
208  digest[1] = h_[1];
209  digest[2] = h_[2];
210  digest[3] = h_[3];
211  digest[4] = h_[4];
212 }
void process_byte(unsigned char byte)
Definition: SHA1.h:92

References process_byte().

Referenced by GetFileSHA1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_block()

void sha1::process_block ( void const *  bytes_begin,
void const *  bytes_end 
)
inline

Definition at line 102 of file SHA1.h.

103 {
104  unsigned char const* begin = static_cast<unsigned char const*>(bytes_begin);
105  unsigned char const* end = static_cast<unsigned char const*>(bytes_end);
106  for(; begin != end; ++begin) {
107  process_byte(*begin);
108  }
109 }

References process_block(), and process_byte().

Referenced by process_block(), process_byte(), and process_bytes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_byte()

void sha1::process_byte ( unsigned char  byte)
inline

Definition at line 92 of file SHA1.h.

93 {
94  block_[block_byte_index_++] = byte;
95  ++byte_count_;
96  if (block_byte_index_ == 64) {
97  block_byte_index_ = 0;
98  process_block();
99  }
100 }
void process_block(void const *bytes_begin, void const *bytes_end)
Definition: SHA1.h:102

References process_block().

Referenced by get_digest(), and process_block().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_bytes()

void sha1::process_bytes ( void const *  buffer,
std::size_t  byte_count 
)
inline

Definition at line 111 of file SHA1.h.

112 {
113  unsigned char const* b = static_cast<unsigned char const*>(buffer);
114  process_block(b, b+byte_count);
115 }
#define b

References b, and process_block().

Referenced by GetFileSHA1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void sha1::reset ( )
inline

Definition at line 80 of file SHA1.h.

81 {
82  h_[0] = 0x67452301;
83  h_[1] = 0xEFCDAB89;
84  h_[2] = 0x98BADCFE;
85  h_[3] = 0x10325476;
86  h_[4] = 0xC3D2E1F0;
87 
88  block_byte_index_ = 0;
89  byte_count_ = 0;
90 }

Referenced by sha1().

Here is the caller graph for this function:

The documentation for this class was generated from the following file: