Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
SHA1 Class Reference

Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1. More...

Public Member Functions

 SHA1 ()
 Construct null. More...
 
 SHA1 (const std::string &)
 Construct null and append initial std::string. More...
 
 SHA1 (const char *)
 Construct null and append initial string. More...
 
void clear ()
 Reset the hashed data before appending more. More...
 
SHA1append (const char *data, size_t len)
 Append data for processing. More...
 
SHA1append (const std::string &)
 Append string for processing. More...
 
SHA1append (const char *str)
 Append string for processing. More...
 
bool finalize ()
 Finalized the calculations (normally not needed directly). More...
 
SHA1Digest digest () const
 Calculate current digest from appended data. More...
 
bool operator== (const SHA1 &) const
 Equality operator, compares digests. More...
 
bool operator== (const SHA1Digest &) const
 Compare digest. More...
 
bool operator== (const std::string &hexdigits) const
 Compare digest to (40-byte) text representation (eg, from sha1sum) More...
 
bool operator== (const char *hexdigits) const
 Compare digest to (40-byte) text representation (eg, from sha1sum) More...
 
bool operator!= (const SHA1 &) const
 Inequality operator, compares digests. More...
 
bool operator!= (const SHA1Digest &) const
 Inequality operator, compare digest. More...
 
bool operator!= (const std::string &hexdigits) const
 Inequality operator, compares digests. More...
 
bool operator!= (const char *hexdigits) const
 Inequality operator, compare digest. More...
 
 operator SHA1Digest () const
 Convert to a SHA1Digest,. More...
 

Private Member Functions

void processBlock (const void *data, size_t len)
 Process data block-wise, LEN must be a multiple of 64! More...
 
void processBytes (const void *data, size_t len)
 Process for the next LEN bytes, LEN need not be a multiple of 64. More...
 
void calcDigest (SHA1Digest &) const
 Calculate current digest from appended data. More...
 

Static Private Member Functions

static uint32_t swapBytes (uint32_t)
 Swap bytes from internal to network (big-endian) order. More...
 
static void set_uint32 (unsigned char *cp, uint32_t)
 Copy the 4-byte value into the memory location pointed to by *dst. More...
 

Private Attributes

bool finalized_
 Track if the hashsum has been finalized (added count, etc) More...
 
uint32_t hashsumA_
 The hash sums. More...
 
uint32_t hashsumB_
 
uint32_t hashsumC_
 
uint32_t hashsumD_
 
uint32_t hashsumE_
 
uint32_t bufTotal_ [2]
 The total number processed, saved as 64-bit. More...
 
uint32_t bufLen_
 The number of elements pending in the buffer. More...
 
uint32_t buffer_ [32]
 The input processing buffer. More...
 

Friends

Ostreamoperator<< (Ostream &, const SHA1 &)
 Output the digest. More...
 

Detailed Description

Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.

Adapted from the gnulib implementation.

See also
Foam::SHA1Digest
Source files

Definition at line 68 of file SHA1.H.

Constructor & Destructor Documentation

◆ SHA1() [1/3]

SHA1 ( )
inline

Construct null.

Definition at line 31 of file SHA1I.H.

References SHA1::clear().

Here is the call graph for this function:

◆ SHA1() [2/3]

SHA1 ( const std::string &  str)
inlineexplicit

Construct null and append initial std::string.

Definition at line 37 of file SHA1I.H.

References clear().

Here is the call graph for this function:

◆ SHA1() [3/3]

SHA1 ( const char *  str)
inlineexplicit

Construct null and append initial string.

Definition at line 44 of file SHA1I.H.

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ swapBytes()

uint32_t swapBytes ( uint32_t  n)
inlinestaticprivate

Swap bytes from internal to network (big-endian) order.

Definition at line 57 of file SHA1.C.

References n, and x.

◆ set_uint32()

void set_uint32 ( unsigned char *  cp,
uint32_t  v 
)
inlinestaticprivate

Copy the 4-byte value into the memory location pointed to by *dst.

If the architecture allows unaligned access this is equivalent to (uint32_t *) cp = val

Definition at line 95 of file SHA1.C.

References Foam::cp().

Here is the call graph for this function:

◆ processBlock()

void processBlock ( const void *  data,
size_t  len 
)
private

Process data block-wise, LEN must be a multiple of 64!

Definition at line 183 of file SHA1.C.

References Foam::constant::physicoChemical::b, Foam::constant::universal::c, Foam::e, F1, F2, F3, F4, K1, K2, K3, K4, M, R, and x.

◆ processBytes()

void processBytes ( const void *  data,
size_t  len 
)
private

Process for the next LEN bytes, LEN need not be a multiple of 64.

Definition at line 103 of file SHA1.C.

References Foam::add(), and clear().

Here is the call graph for this function:

◆ calcDigest()

void calcDigest ( SHA1Digest dig) const
private

Calculate current digest from appended data.

Definition at line 319 of file SHA1.C.

References SHA1Digest::clear(), and SHA1Digest::v_.

Referenced by SHA1::digest().

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

◆ clear()

void clear ( )

Reset the hashed data before appending more.

Definition at line 341 of file SHA1.C.

Referenced by main(), OSHA1stream::rewind(), and SHA1::SHA1().

Here is the caller graph for this function:

◆ append() [1/3]

Foam::SHA1 & append ( const char *  data,
size_t  len 
)
inline

Append data for processing.

Definition at line 53 of file SHA1I.H.

Referenced by main(), and sha1streambuf::xsputn().

Here is the caller graph for this function:

◆ append() [2/3]

Foam::SHA1 & append ( const std::string &  str)
inline

Append string for processing.

Definition at line 60 of file SHA1I.H.

◆ append() [3/3]

Foam::SHA1 & append ( const char *  str)
inline

Append string for processing.

Definition at line 67 of file SHA1I.H.

◆ finalize()

bool finalize ( )

Finalized the calculations (normally not needed directly).

Returns false if no bytes were passed for processing

Definition at line 356 of file SHA1.C.

Referenced by SHA1::digest().

Here is the caller graph for this function:

◆ digest()

Foam::SHA1Digest digest ( ) const

Calculate current digest from appended data.

Definition at line 395 of file SHA1.C.

References SHA1::calcDigest(), and SHA1::finalize().

Referenced by OSHA1stream::digest(), Foam::operator<<(), and SHA1::operator==().

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

◆ operator==() [1/4]

bool operator== ( const SHA1 rhs) const
inline

Equality operator, compares digests.

Definition at line 79 of file SHA1I.H.

References SHA1::digest().

Here is the call graph for this function:

◆ operator==() [2/4]

bool operator== ( const SHA1Digest rhs) const
inline

Compare digest.

Definition at line 85 of file SHA1I.H.

◆ operator==() [3/4]

bool operator== ( const std::string &  hexdigits) const
inline

Compare digest to (40-byte) text representation (eg, from sha1sum)

An empty string is equivalent to "0000000000000000000000000000000000000000"

Definition at line 91 of file SHA1I.H.

◆ operator==() [4/4]

bool operator== ( const char *  hexdigits) const
inline

Compare digest to (40-byte) text representation (eg, from sha1sum)

A null or empty string is equivalent to "0000000000000000000000000000000000000000"

Definition at line 97 of file SHA1I.H.

◆ operator!=() [1/4]

bool operator!= ( const SHA1 rhs) const
inline

Inequality operator, compares digests.

Definition at line 103 of file SHA1I.H.

References Foam::operator==().

Here is the call graph for this function:

◆ operator!=() [2/4]

bool operator!= ( const SHA1Digest rhs) const
inline

Inequality operator, compare digest.

Definition at line 109 of file SHA1I.H.

References Foam::operator==().

Here is the call graph for this function:

◆ operator!=() [3/4]

bool operator!= ( const std::string &  hexdigits) const
inline

Inequality operator, compares digests.

Definition at line 115 of file SHA1I.H.

References Foam::operator==().

Here is the call graph for this function:

◆ operator!=() [4/4]

bool operator!= ( const char *  hexdigits) const
inline

Inequality operator, compare digest.

Definition at line 121 of file SHA1I.H.

References Foam::operator==().

Here is the call graph for this function:

◆ operator SHA1Digest()

operator SHA1Digest ( ) const
inline

Convert to a SHA1Digest,.

calculate current digest from appended data

Friends And Related Function Documentation

◆ operator<<

Ostream& operator<< ( Ostream ,
const SHA1  
)
friend

Output the digest.

Field Documentation

◆ finalized_

bool finalized_
private

Track if the hashsum has been finalized (added count, etc)

Definition at line 73 of file SHA1.H.

◆ hashsumA_

uint32_t hashsumA_
private

The hash sums.

Definition at line 76 of file SHA1.H.

◆ hashsumB_

uint32_t hashsumB_
private

Definition at line 77 of file SHA1.H.

◆ hashsumC_

uint32_t hashsumC_
private

Definition at line 78 of file SHA1.H.

◆ hashsumD_

uint32_t hashsumD_
private

Definition at line 79 of file SHA1.H.

◆ hashsumE_

uint32_t hashsumE_
private

Definition at line 80 of file SHA1.H.

◆ bufTotal_

uint32_t bufTotal_[2]
private

The total number processed, saved as 64-bit.

Definition at line 83 of file SHA1.H.

◆ bufLen_

uint32_t bufLen_
private

The number of elements pending in the buffer.

Definition at line 86 of file SHA1.H.

◆ buffer_

uint32_t buffer_[32]
private

The input processing buffer.

Definition at line 89 of file SHA1.H.


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