1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
#pike __REAL_VERSION__ 
#pragma strict_types 
 
//! Base class for hash algorithms. 
//! 
//! Note that no actual hash algorithm is implemented 
//! in the base class. They are implemented in classes 
//! that inherit this class. 
 
//! Returns a human readable name for the algorithm. 
string(7bit) name(); 
 
//! Returns the size of a hash digest. 
int(0..) digest_size(); 
 
//! Returns the internal block size of the hash algorithm. 
int(1..) block_size(); 
 
//! This is the context for a single incrementally updated hash. 
//! 
//! Most of the functions here are only prototypes, and need to 
//! be overrided via inherit. 
class State 
{ 
  //! Create the new context, and optionally 
  //! add some initial data to hash. 
  //! 
  //! The default implementation calls @[update()] with @[data] if any, 
  //! so there's usually no reason to override this function, since 
  //! overriding @[update()] should be sufficient. 
  protected void create(string|void data) 
  { 
    if (data) { 
      update(data); 
    } 
  } 
 
  //! Reset the context, and optionally 
  //! add some initial data to the hash. 
  this_program init(string|void data); 
 
  //! Add some more data to hash. 
  this_program update(string data); 
 
  //! Generates a digest, and resets the hashing contents. 
  //! 
  //! @param length 
  //!   If the length argument is provided, the digest is truncated 
  //!   to the given length. 
  //! 
  //! @returns 
  //!   The digest. 
  string(8bit) digest(int|void length); 
 
  //! Returns a human readable name for the algorithm. 
  string name() 
  { 
    return global::name(); 
  } 
 
  //! Returns the size of a hash digest. 
  int(0..) digest_size() 
  { 
    return global::digest_size(); 
  } 
 
  //! Returns the internal block size of the hash algorithm. 
  int(1..) block_size() 
  { 
    return global::block_size(); 
  } 
}