Basic cryptographic hashes.
More...
|
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 |
|
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:
- MD5
- SHA1
- SHA224
- SHA256
- SHA384
- SHA512
Examples
This code prints the MD5 hash of the contents of a file:
limes::files::File file { "/my/file.txt" };
- Todo:
- CLI tool docs, tests
- Todo:
- HashTable data structure
◆ 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.