lhashes  1.0.0
C++ hashes library
limes_hashes

Basic cryptographic hashes. More...

Files

file  lhashes.h
 The main header for the limes_hashes library.
 
file  lhashes_common.h
 This file defines internal utilities common to the various hash algorithms.
 
file  lhashes_hash.h
 This file defines the hash::Hasher class and the hash::hash() free functions.
 
file  lhashes_md5.h
 This file defines the hash::MD5 class.
 
file  lhashes_sha1.h
 This file defines the hash::SHA1 class.
 
file  lhashes_sha224.h
 This file defines the hash::SHA224 class.
 
file  lhashes_sha256.h
 This file defines the hash::SHA256 class.
 
file  lhashes_sha384.h
 This file defines the hash::SHA384 class.
 
file  lhashes_sha512.h
 This file defines the hash::SHA512 class.
 

Functions

LHASH_EXPORT std::string md5 (const char *input, std::size_t length)
 Calculates an MD5 hash for the given data. More...
 
LHASH_EXPORT std::string md5 (std::string_view input)
 Calculates an MD5 hash for the given string. More...
 
LHASH_EXPORT std::string sha1 (const char *input, std::size_t length)
 Calculates a SHA1 hash for the given data. More...
 
LHASH_EXPORT std::string sha1 (std::string_view input)
 Calculates a SHA1 hash for the given string. More...
 
LHASH_EXPORT std::string sha224 (const char *input, std::size_t length)
 Calculates a SHA224 hash for the given data. More...
 
LHASH_EXPORT std::string sha224 (std::string_view input)
 Calculates a SHA224 hash for the given data. More...
 
LHASH_EXPORT std::string sha256 (const char *input, std::size_t length)
 Calculates a SHA256 hash for the given data. More...
 
LHASH_EXPORT std::string sha256 (std::string_view input)
 Calculates a SHA256 hash for the given string. More...
 
LHASH_EXPORT std::string sha384 (const char *input, std::size_t length)
 Calculates a SHA384 hash for the given data. More...
 
LHASH_EXPORT std::string sha384 (std::string_view input)
 Calculates a SHA384 hash for the given string. More...
 
LHASH_EXPORT std::string sha512 (const char *input, std::size_t length)
 Calculates a SHA512 hash for the given data. More...
 
LHASH_EXPORT std::string sha512 (std::string_view input)
 Calculates a SHA512 hash for the given string. More...
 
LHASH_NO_EXPORT void limes::hash::util::pack32 (const unsigned char *str, std::uint32_t &x) noexcept
 

Detailed Description

Basic cryptographic hashes.

Overview

All classes and functions in this module are accessible after linking to the limes::lhashes library and including lhashes.h.

This library provides utilities for performing various basic cryptographic hash functions. The hash functions themselves are treated in an object oriented manner, but also provide free functions for quick and easy hashing.

Design goals

This library is object oriented; each hash function is computed by a hasher object that implements the Hasher base class interface. Addition of new hash algorithms is possible by implementing this interface; however, the createHasherForType() function is not designed to be extensible. Hash algorithm types are stored in an enum, not allowing code from outside Limes to add new types dynamically. The overhead in this kind of "registry" design seemed to outweigh its benefit here, as this library already includes the most common hash algorithms and adding new ones seems like a rare need. If you create a new hash algorithm that implements the Hasher interface, feel free to submit a pull request and it will be added directly to this library.

The easiest way to compute a hash for some data is with this library's free functions; each hash type has a free function (such as hash::md5() , hash::sha256 , etc), and there is also hash::createHasherForType() and hash::hash() .

Features

This library provides the following hash functions:

Examples

This code prints the MD5 hash of the contents of a file:

limes::files::File file { "/my/file.txt" };
std::cout << limes::hashes::md5 (file.loadAsString());
md5
An MD5 hash.
Definition: lhashes_hash.h:41
Todo:
CLI tool docs, tests
Todo:
HashTable data structure

Function Documentation

◆ md5() [1/2]

LHASH_EXPORT std::string md5 ( const char *  input,
std::size_t  length 
)
related

Calculates an MD5 hash for the given data.

◆ md5() [2/2]

LHASH_EXPORT std::string md5 ( std::string_view  input)
related

Calculates an MD5 hash for the given string.

◆ sha1() [1/2]

LHASH_EXPORT std::string sha1 ( const char *  input,
std::size_t  length 
)
related

Calculates a SHA1 hash for the given data.

◆ sha1() [2/2]

LHASH_EXPORT std::string sha1 ( std::string_view  input)
related

Calculates a SHA1 hash for the given string.

◆ sha224() [1/2]

LHASH_EXPORT std::string sha224 ( const char *  input,
std::size_t  length 
)
related

Calculates a SHA224 hash for the given data.

◆ sha224() [2/2]

LHASH_EXPORT std::string sha224 ( std::string_view  input)
related

Calculates a SHA224 hash for the given data.

◆ sha256() [1/2]

LHASH_EXPORT std::string sha256 ( const char *  input,
std::size_t  length 
)
related

Calculates a SHA256 hash for the given data.

◆ sha256() [2/2]

LHASH_EXPORT std::string sha256 ( std::string_view  input)
related

Calculates a SHA256 hash for the given string.

◆ sha384() [1/2]

LHASH_EXPORT std::string sha384 ( const char *  input,
std::size_t  length 
)
related

Calculates a SHA384 hash for the given data.

◆ sha384() [2/2]

LHASH_EXPORT std::string sha384 ( std::string_view  input)
related

Calculates a SHA384 hash for the given string.

◆ sha512() [1/2]

LHASH_EXPORT std::string sha512 ( const char *  input,
std::size_t  length 
)
related

Calculates a SHA512 hash for the given data.

◆ sha512() [2/2]

LHASH_EXPORT std::string sha512 ( std::string_view  input)
related

Calculates a SHA512 hash for the given string.