acl  3.5.3.0
sha1.hpp
浏览该文件的文档.
1 /*
2  * sha1.h
3  *
4  * Copyright (C) 1998, 2009
5  * Paul E. Jones <paulej@packetizer.com>
6  * All Rights Reserved.
7  *
8  *****************************************************************************
9  * $Id: sha1.h 12 2009-06-22 19:34:25Z paulej $
10  *****************************************************************************
11  *
12  * Description:
13  * This class implements the Secure Hashing Standard as defined
14  * in FIPS PUB 180-1 published April 17, 1995.
15  *
16  * Many of the variable names in this class, especially the single
17  * character names, were used because those were the names used
18  * in the publication.
19  *
20  * Please read the file sha1.cpp for more information.
21  *
22  */
23 
24 #pragma once
25 #include "noncopyable.hpp"
26 
27 namespace acl
28 {
29 
30 class sha1 : public noncopyable
31 {
32 public:
33  sha1();
34  virtual ~sha1();
35 
36  /*
37  * Re-initialize the class
38  */
39  void reset();
40 
41  /*
42  * Returns the message digest, message_digest_array's length must >= 20
43  */
44  bool result(unsigned char *message_digest_array);
45  bool result2(unsigned *message_digest_array);
46 
47  /*
48  * Provide input to SHA1
49  */
50  void input(const unsigned char *message_array, unsigned length);
51  void input(const char *message_array, unsigned length);
52  void input(unsigned char message_element);
53  void input(char message_element);
54  sha1& operator<<(const char *message_array);
55  sha1& operator<<(const unsigned char *message_array);
56  sha1& operator<<(const char message_element);
57  sha1& operator<<(const unsigned char message_element);
58 
59 private:
60  /*
61  * Process the next 512 bits of the message
62  */
63  void process_message_block();
64 
65  /*
66  * Pads the current message block to 512 bits
67  */
68  void pad_message();
69 
70  /*
71  * Performs a circular left shift operation
72  */
73  inline unsigned circular_shift(int bits, unsigned word);
74 
75  unsigned h_[5]; // Message digest buffers
76 
77  unsigned length_low_; // Message length in bits
78  unsigned length_high_; // Message length in bits
79 
80  unsigned char message_block_[64]; // 512-bit message blocks
81  int message_block_index_; // Index into message block array
82 
83  bool computed_; // Is the digest computed?
84  bool corrupted_; // Is the message digest corruped?
85 };
86 
87 } // namespace acl
sha1 & operator<<(const char *message_array)
bool result2(unsigned *message_digest_array)
void reset()
bool result(unsigned char *message_digest_array)
virtual ~sha1()
void input(const unsigned char *message_array, unsigned length)