nil::crypto3::static_digest< DigestBits > Class Template Reference

#include <static_digest.hpp>

+ Inheritance diagram for nil::crypto3::static_digest< DigestBits >:
+ Collaboration diagram for nil::crypto3::static_digest< DigestBits >:

Public Attributes

 STL member. More...

Detailed Description

template<std::size_t DigestBits>
class nil::crypto3::static_digest< DigestBits >

The digest class template stores a DigestBits-bit message digest as a sequence of 8-bit octets. Octets are stored in the smallest std::size_t type able to hold 8 bits, hereinafter referred to as octet_type. DigestBits must be a multiple of 8.

It is independent of any particular algorithm; For example sha2<224> and cubehash<224> both produce a digest<224>. Each algorithm generates its digest such that it will be displayed in the canonical order for that algorithm. The truncate and resize function templates are provided to handle digests with lengths other than you're expecting. For instance, generating name-based UUIDs uses only 128 bits but SHA-1 provides a 160-bit digest, so it would be truncated. (Using truncate instead of resize means that a compilation error will result from trying to use a hash algorithm with too small an output.) On the other hand, for storing as much as possible of the results of various algorithms, resize allows you to pad them out to a large size, such as a digest<512>.

digest<DigestBits> derives publicly from std::array<octet_type, DigestBits/8> and supports all of its operations in order to provide direct access to the contained octets. Note that a digest is not an aggregate; A default-constructed digest has all its contained octets set to zero. The base_array() member function provides a reference to the std::array sub-object.

digests with different numbers of bits may be compared. For the comparison, the smaller is considered as though it were padded with 0s out to the size of the larger. The operator< provides a strict total order. For convenience, equality comparison with narrow c-style strings is also provided.

Always stored internally as a sequence of octets in display order. This allows digests from different algorithms to have the same type, allowing them to be more easily stored and compared.

Template Parameters

Member Data Documentation

◆ elements

T std::array< T >::elements

STL member.

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