dht::crypto Namespace Reference

## Classes

struct | Certificate
class | CryptoException
class | DecryptError
struct | PrivateKey
struct | PublicKey
class | RevocationList
class | secure_vector
struct | TrustList

## Typedefs

using | Identity = std::pair< std::shared_ptr< PrivateKey >, std::shared_ptr< Certificate > >
using | SecureBlob = secure_vector< uint8_t >
using | random_device = std::random_device

## Functions

OPENDHT_PUBLIC Identity | generateIdentity (const std::string &name, Identity ca, unsigned key_length, bool is_ca)
OPENDHT_PUBLIC Identity | generateIdentity (const std::string &name="dhtnode", Identity ca={}, unsigned key_length=4096)
OPENDHT_PUBLIC Identity | generateEcIdentity (const std::string &name, Identity ca, bool is_ca)
OPENDHT_PUBLIC Identity | generateEcIdentity (const std::string &name="dhtnode", Identity ca={})
OPENDHT_PUBLIC Blob | hash (const Blob &data, size_t hash_length=512/8)
OPENDHT_PUBLIC void | hash (const uint8_t *data, size_t data_length, uint8_t *hash, size_t hash_length)
OPENDHT_PUBLIC Blob | stretchKey (const std::string &password, Blob &salt, size_t key_length=512/8)
OPENDHT_PUBLIC Blob | aesEncrypt (const Blob &data, const Blob &key)
OPENDHT_PUBLIC Blob | aesEncrypt (const Blob &data, const std::string &password)
OPENDHT_PUBLIC Blob | aesDecrypt (const Blob &data, const Blob &key)
OPENDHT_PUBLIC Blob | aesDecrypt (const Blob &data, const std::string &password)
template<class T = std::mt19937, std::size_t N = T::state_size>
auto | getSeededRandomEngine () -> typename std::enable_if<!!N, T >::type

## Detailed Description

Contains all crypto primitives

## Typedef Documentation

## Identity

using dht::crypto::Identity = typedef std::pair<std::shared_ptr<PrivateKey>, std::shared_ptr<Certificate> >

Definition at line 62 of file crypto.h.

## random_device

using dht::crypto::random_device = typedef std::random_device

Definition at line 104 of file rng.h.

## SecureBlob

using dht::crypto::SecureBlob = typedef secure_vector<uint8_t>

Definition at line 579 of file crypto.h.

## Function Documentation

## aesDecrypt()

OPENDHT_PUBLIC Blob dht::crypto::aesDecrypt | ( | const Blob & | data,
|  | const Blob & | key
| ) |  |

AES-GCM decryption.

## aesEncrypt()

OPENDHT_PUBLIC Blob dht::crypto::aesEncrypt | ( | const Blob & | data,
|  | const Blob & | key
| ) |  |

AES-GCM encryption. Key must be 128, 192 or 256 bits long (16, 24 or 32 bytes).

## generateIdentity()

OPENDHT_PUBLIC Identity dht::crypto::generateIdentity | ( | const std::string & | name,
|  | Identity | ca,
|  | unsigned | key_length,
|  | bool | is_ca
| ) |  |

Generate an RSA key pair (4096 bits) and a certificate.

Parameters

  name | the name used in the generated certificate
  ca | if set, the certificate authority that will sign the generated certificate. If not set, the generated certificate will be a self-signed CA.
  key_length | stength of the generated private key (bits).

## getSeededRandomEngine()

template<class T = std::mt19937, std::size_t N = T::state_size>

auto dht::crypto::getSeededRandomEngine | ( |  | ) | -> typename std::enable_if<!!N, T>::type

Definition at line 112 of file rng.h.

## hash()

OPENDHT_PUBLIC Blob dht::crypto::hash | ( | const Blob & | data,
|  | size_t | hash_length = `512/8`
| ) |  |

Performs SHA512, SHA256 or SHA1, depending on hash_length. Attempts to choose an hash function with output size of at least hash_length bytes, Current implementation will use SHA1 for hash_length up to 20 bytes, will use SHA256 for hash_length up to 32 bytes, will use SHA512 for hash_length of 33 bytes and more.

## stretchKey()

OPENDHT_PUBLIC Blob dht::crypto::stretchKey | ( | const std::string & | password,
|  | Blob & | salt,
|  | size_t | key_length = `512/8`
| ) |  |

Generates an encryption key from a text password, making the key longer to bruteforce. The generated key also depends on a unique salt value of any size, that can be transmitted in clear, and will be generated if not provided (32 bytes).