Base Framework
Public Member Functions | Static Public Attributes | List of all members
SHA1 Class Reference

SHA-1 message-digest. More...

#include <base/security/SHA1.h>

Inherits Object, and PushInterface.

Public Member Functions

 SHA1 () noexcept
 
MemorySize push (const uint8 *buffer, MemorySize size)
 
void pushEnd () noexcept
 
uint64 getTotalSize () const noexcept
 
String getValue () const noexcept
 
String getBase64 () const noexcept
 
- Public Member Functions inherited from PushInterface
virtual void flush ()
 
virtual bool pushBegin (uint64 totalSize)
 

Static Public Attributes

static const unsigned int BLOCK_SIZE = 64
 
static const uint64 MAXIMUM_SIZE = (1ULL << (64 - 3)) - 1
 
static const unsigned int MESSAGE_SCHEDULE = 80
 

Detailed Description

SHA-1 message-digest.

Implementation of the SHA-1 message-digest algorithm (see FIPS PUB 180-2). This class takes a message of arbitrary length and produces a 128-bit "fingerprint"/"message digest" of the message. According to the RFC it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest.

The SHA-1 is designed to have the following properties: it is computationally infeasible to find a message which corresponds to a given message digest, or to find two different messages which produce the same message digest.

String message = "abcdefghijklmnopqrstuvwxyz";
SHA1 checksum;
checksum.push(message.getBytes(), message.getLength());
checksum.pushEnd();
fout << "message digest: " << checksum.getValue() << ENDL;
See also
MD5Sum SHA256 SHA384 SHA512
Version
1.0
Examples
testsuite/digest.cpp.

Constructor & Destructor Documentation

◆ SHA1()

SHA1::SHA1 ( )
noexcept

Initializes object.

Member Function Documentation

◆ getBase64()

String SHA1::getBase64 ( ) const
noexcept

Returns the message digest encoded in Base64. This is only valid after pushEnd() has been invoked.

◆ getTotalSize()

uint64 SHA1::getTotalSize ( ) const
inlinenoexcept

Returns the total size of the original message.

◆ getValue()

String SHA1::getValue ( ) const
noexcept

Returns the message digest encoded in hex. This is only valid after pushEnd() has been invoked.

Examples
testsuite/digest.cpp.

◆ push()

MemorySize SHA1::push ( const uint8 *  buffer,
MemorySize  size 
)
virtual

Updates the checksum corresponding to the specified data. May be called multiple times. Raises OutOfRange if the total number of octets exceed the limit specified by MAXIMUM_SIZE.

Parameters
bufferThe buffer holding the data.
sizeThe number of octets in the buffer.

Implements PushInterface.

Examples
testsuite/digest.cpp.

◆ pushEnd()

void SHA1::pushEnd ( )
virtualnoexcept

This function should be invoked when the entire message has been pushed. Do NOT use push() after invoking this function.

Reimplemented from PushInterface.

Examples
testsuite/digest.cpp.

Member Data Documentation

◆ BLOCK_SIZE

const unsigned int SHA1::BLOCK_SIZE = 64
static

Internal block size in bytes.

◆ MAXIMUM_SIZE

const uint64 SHA1::MAXIMUM_SIZE = (1ULL << (64 - 3)) - 1
static

Specifies the maximum length (in bytes) of the original message.

◆ MESSAGE_SCHEDULE

const unsigned int SHA1::MESSAGE_SCHEDULE = 80
static

The message schedule size.

String::getBytes
const uint8 * getBytes() const noexcept
Definition: String.h:1510
String::getLength
MemorySize getLength() const noexcept
Definition: String.h:510
SHA1::getValue
String getValue() const noexcept
SHA1
SHA-1 message-digest.
Definition: SHA1.h:48
SHA1::push
MemorySize push(const uint8 *buffer, MemorySize size)
String
String.
Definition: String.h:102
SHA1::pushEnd
void pushEnd() noexcept