---
title: llarp::sodium::CryptoLibSodium

---

# llarp::sodium::CryptoLibSodium





Inherits from [llarp::Crypto](Classes/structllarp_1_1Crypto.md)

## Public Functions

|                | Name           |
| -------------- | -------------- |
| | **[CryptoLibSodium](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-cryptolibsodium)**() |
| | **[~CryptoLibSodium](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-~cryptolibsodium)**() override =default |
| virtual std::optional< [AlignedBuffer](Classes/structllarp_1_1AlignedBuffer.md)< 32 > > | **[maybe_decrypt_name](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-maybe-decrypt-name)**(std::string_view ciphertext, [SymmNonce](Classes/structllarp_1_1AlignedBuffer.md) nounce, std::string_view name) override<br>decrypt cipherText given the key generated from name  |
| virtual bool | **[xchacha20](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-xchacha20)**(const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & , const [SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & , const [TunnelNonce](Classes/structllarp_1_1AlignedBuffer.md) & ) override<br>xchacha symmetric cipher  |
| virtual bool | **[xchacha20_alt](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-xchacha20-alt)**(const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & , const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & , const [SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & , const byte_t * ) override<br>xchacha symmetric cipher (multibuffer)  |
| virtual bool | **[dh_client](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-dh-client)**([SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & , const [PubKey](Classes/structllarp_1_1PubKey.md) & , const [SecretKey](Classes/structllarp_1_1SecretKey.md) & , const [TunnelNonce](Classes/structllarp_1_1AlignedBuffer.md) & ) override<br>path dh creator's side  |
| virtual bool | **[dh_server](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-dh-server)**([SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & , const [PubKey](Classes/structllarp_1_1PubKey.md) & , const [SecretKey](Classes/structllarp_1_1SecretKey.md) & , const [TunnelNonce](Classes/structllarp_1_1AlignedBuffer.md) & ) override<br>path dh relay side  |
| virtual bool | **[transport_dh_client](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-transport-dh-client)**([SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & , const [PubKey](Classes/structllarp_1_1PubKey.md) & , const [SecretKey](Classes/structllarp_1_1SecretKey.md) & , const [TunnelNonce](Classes/structllarp_1_1AlignedBuffer.md) & ) override<br>transport dh client side  |
| virtual bool | **[transport_dh_server](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-transport-dh-server)**([SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & , const [PubKey](Classes/structllarp_1_1PubKey.md) & , const [SecretKey](Classes/structllarp_1_1SecretKey.md) & , const [TunnelNonce](Classes/structllarp_1_1AlignedBuffer.md) & ) override<br>transport dh server side  |
| virtual bool | **[shorthash](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-shorthash)**([ShortHash](Classes/structllarp_1_1AlignedBuffer.md) & , const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & ) override<br>blake2b 256 bit  |
| virtual bool | **[hmac](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-hmac)**(byte_t * , const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & , const [SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & ) override<br>blake2s 256 bit hmac  |
| virtual bool | **[sign](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-sign)**([Signature](Classes/structllarp_1_1Signature.md) & , const [SecretKey](Classes/structllarp_1_1SecretKey.md) & , const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & ) override<br>ed25519 sign  |
| virtual bool | **[sign](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-sign)**([Signature](Classes/structllarp_1_1Signature.md) & , const [PrivateKey](Classes/structllarp_1_1PrivateKey.md) & , const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & ) override<br>ed25519 sign (custom with derived keys)  |
| virtual bool | **[verify](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-verify)**(const [PubKey](Classes/structllarp_1_1PubKey.md) & , const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & , const [Signature](Classes/structllarp_1_1Signature.md) & ) override<br>ed25519 verify  |
| virtual bool | **[derive_subkey](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-derive-subkey)**([PubKey](Classes/structllarp_1_1PubKey.md) & derived, const [PubKey](Classes/structllarp_1_1PubKey.md) & root, uint64_t key_n, const [AlignedBuffer](Classes/structllarp_1_1AlignedBuffer.md)< 32 > * hash =nullptr) override<br>derive sub keys for public keys.  |
| virtual bool | **[derive_subkey_private](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-derive-subkey-private)**([PrivateKey](Classes/structllarp_1_1PrivateKey.md) & derived, const [SecretKey](Classes/structllarp_1_1SecretKey.md) & root, uint64_t key_n, const [AlignedBuffer](Classes/structllarp_1_1AlignedBuffer.md)< 32 > * hash =nullptr) override<br>derive sub keys for private keys.  |
| virtual bool | **[seed_to_secretkey](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-seed-to-secretkey)**([llarp::SecretKey](Classes/structllarp_1_1SecretKey.md) & , const [llarp::IdentitySecret](Classes/structllarp_1_1IdentitySecret.md) & ) override<br>seed to secretkey  |
| virtual void | **[randomize](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-randomize)**(const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & ) override<br>randomize buffer  |
| virtual void | **[randbytes](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-randbytes)**(byte_t * , size_t ) override<br>randomizer memory  |
| virtual void | **[identity_keygen](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-identity-keygen)**([SecretKey](Classes/structllarp_1_1SecretKey.md) & ) override<br>generate signing keypair  |
| virtual void | **[encryption_keygen](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-encryption-keygen)**([SecretKey](Classes/structllarp_1_1SecretKey.md) & ) override<br>generate encryption keypair  |
| virtual void | **[pqe_keygen](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-pqe-keygen)**([PQKeyPair](Classes/structllarp_1_1AlignedBuffer.md) & ) override<br>generate post quantum encrytion key  |
| virtual bool | **[pqe_decrypt](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-pqe-decrypt)**(const [PQCipherBlock](Classes/structllarp_1_1AlignedBuffer.md) & , [SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & , const byte_t * ) override<br>post quantum decrypt (buffer, sharedkey_dst, sec)  |
| virtual bool | **[pqe_encrypt](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-pqe-encrypt)**([PQCipherBlock](Classes/structllarp_1_1AlignedBuffer.md) & , [SharedSecret](Classes/structllarp_1_1AlignedBuffer.md) & , const [PQPubKey](Classes/structllarp_1_1AlignedBuffer.md) & ) override<br>post quantum encrypt (buffer, sharedkey_dst, pub)  |
| virtual bool | **[check_identity_privkey](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-check-identity-privkey)**(const [SecretKey](Classes/structllarp_1_1SecretKey.md) & ) override |
| virtual bool | **[check_passwd_hash](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md#function-check-passwd-hash)**(std::string pwhash, std::string challenge) override<br>check if a password hash string matches the challenge  |

## Additional inherited members

**Public Functions inherited from [llarp::Crypto](Classes/structllarp_1_1Crypto.md)**

|                | Name           |
| -------------- | -------------- |
| virtual | **[~Crypto](Classes/structllarp_1_1Crypto.md#function-~crypto)**() =0 |


## Public Functions Documentation

### function CryptoLibSodium

```cpp
CryptoLibSodium()
```


### function ~CryptoLibSodium

```cpp
~CryptoLibSodium() override =default
```


### function maybe_decrypt_name

```cpp
virtual std::optional< AlignedBuffer< 32 > > maybe_decrypt_name(
    std::string_view ciphertext,
    SymmNonce nounce,
    std::string_view name
) override
```

decrypt cipherText given the key generated from name 

**Reimplements**: [llarp::Crypto::maybe_decrypt_name](Classes/structllarp_1_1Crypto.md#function-maybe-decrypt-name)


### function xchacha20

```cpp
virtual bool xchacha20(
    const llarp_buffer_t & ,
    const SharedSecret & ,
    const TunnelNonce & 
) override
```

xchacha symmetric cipher 

**Reimplements**: [llarp::Crypto::xchacha20](Classes/structllarp_1_1Crypto.md#function-xchacha20)


### function xchacha20_alt

```cpp
virtual bool xchacha20_alt(
    const llarp_buffer_t & ,
    const llarp_buffer_t & ,
    const SharedSecret & ,
    const byte_t * 
) override
```

xchacha symmetric cipher (multibuffer) 

**Reimplements**: [llarp::Crypto::xchacha20_alt](Classes/structllarp_1_1Crypto.md#function-xchacha20-alt)


### function dh_client

```cpp
virtual bool dh_client(
    SharedSecret & ,
    const PubKey & ,
    const SecretKey & ,
    const TunnelNonce & 
) override
```

path dh creator's side 

**Reimplements**: [llarp::Crypto::dh_client](Classes/structllarp_1_1Crypto.md#function-dh-client)


### function dh_server

```cpp
virtual bool dh_server(
    SharedSecret & ,
    const PubKey & ,
    const SecretKey & ,
    const TunnelNonce & 
) override
```

path dh relay side 

**Reimplements**: [llarp::Crypto::dh_server](Classes/structllarp_1_1Crypto.md#function-dh-server)


### function transport_dh_client

```cpp
virtual bool transport_dh_client(
    SharedSecret & ,
    const PubKey & ,
    const SecretKey & ,
    const TunnelNonce & 
) override
```

transport dh client side 

**Reimplements**: [llarp::Crypto::transport_dh_client](Classes/structllarp_1_1Crypto.md#function-transport-dh-client)


### function transport_dh_server

```cpp
virtual bool transport_dh_server(
    SharedSecret & ,
    const PubKey & ,
    const SecretKey & ,
    const TunnelNonce & 
) override
```

transport dh server side 

**Reimplements**: [llarp::Crypto::transport_dh_server](Classes/structllarp_1_1Crypto.md#function-transport-dh-server)


### function shorthash

```cpp
virtual bool shorthash(
    ShortHash & ,
    const llarp_buffer_t & 
) override
```

blake2b 256 bit 

**Reimplements**: [llarp::Crypto::shorthash](Classes/structllarp_1_1Crypto.md#function-shorthash)


### function hmac

```cpp
virtual bool hmac(
    byte_t * ,
    const llarp_buffer_t & ,
    const SharedSecret & 
) override
```

blake2s 256 bit hmac 

**Reimplements**: [llarp::Crypto::hmac](Classes/structllarp_1_1Crypto.md#function-hmac)


### function sign

```cpp
virtual bool sign(
    Signature & ,
    const SecretKey & ,
    const llarp_buffer_t & 
) override
```

ed25519 sign 

**Reimplements**: [llarp::Crypto::sign](Classes/structllarp_1_1Crypto.md#function-sign)


### function sign

```cpp
virtual bool sign(
    Signature & ,
    const PrivateKey & ,
    const llarp_buffer_t & 
) override
```

ed25519 sign (custom with derived keys) 

**Reimplements**: [llarp::Crypto::sign](Classes/structllarp_1_1Crypto.md#function-sign)


### function verify

```cpp
virtual bool verify(
    const PubKey & ,
    const llarp_buffer_t & ,
    const Signature & 
) override
```

ed25519 verify 

**Reimplements**: [llarp::Crypto::verify](Classes/structllarp_1_1Crypto.md#function-verify)


### function derive_subkey

```cpp
virtual bool derive_subkey(
    PubKey & derived,
    const PubKey & root,
    uint64_t key_n,
    const AlignedBuffer< 32 > * hash =nullptr
) override
```

derive sub keys for public keys. 

**Reimplements**: [llarp::Crypto::derive_subkey](Classes/structllarp_1_1Crypto.md#function-derive-subkey)


hash is really only intended for testing and overrides key_n if given. 


### function derive_subkey_private

```cpp
virtual bool derive_subkey_private(
    PrivateKey & derived,
    const SecretKey & root,
    uint64_t key_n,
    const AlignedBuffer< 32 > * hash =nullptr
) override
```

derive sub keys for private keys. 

**Reimplements**: [llarp::Crypto::derive_subkey_private](Classes/structllarp_1_1Crypto.md#function-derive-subkey-private)


hash is really only intended for testing and overrides key_n if given. 


### function seed_to_secretkey

```cpp
virtual bool seed_to_secretkey(
    llarp::SecretKey & ,
    const llarp::IdentitySecret & 
) override
```

seed to secretkey 

**Reimplements**: [llarp::Crypto::seed_to_secretkey](Classes/structllarp_1_1Crypto.md#function-seed-to-secretkey)


### function randomize

```cpp
virtual void randomize(
    const llarp_buffer_t & 
) override
```

randomize buffer 

**Reimplements**: [llarp::Crypto::randomize](Classes/structllarp_1_1Crypto.md#function-randomize)


### function randbytes

```cpp
virtual void randbytes(
    byte_t * ,
    size_t 
) override
```

randomizer memory 

**Reimplements**: [llarp::Crypto::randbytes](Classes/structllarp_1_1Crypto.md#function-randbytes)


### function identity_keygen

```cpp
virtual void identity_keygen(
    SecretKey & 
) override
```

generate signing keypair 

**Reimplements**: [llarp::Crypto::identity_keygen](Classes/structllarp_1_1Crypto.md#function-identity-keygen)


### function encryption_keygen

```cpp
virtual void encryption_keygen(
    SecretKey & 
) override
```

generate encryption keypair 

**Reimplements**: [llarp::Crypto::encryption_keygen](Classes/structllarp_1_1Crypto.md#function-encryption-keygen)


### function pqe_keygen

```cpp
virtual void pqe_keygen(
    PQKeyPair & 
) override
```

generate post quantum encrytion key 

**Reimplements**: [llarp::Crypto::pqe_keygen](Classes/structllarp_1_1Crypto.md#function-pqe-keygen)


### function pqe_decrypt

```cpp
virtual bool pqe_decrypt(
    const PQCipherBlock & ,
    SharedSecret & ,
    const byte_t * 
) override
```

post quantum decrypt (buffer, sharedkey_dst, sec) 

**Reimplements**: [llarp::Crypto::pqe_decrypt](Classes/structllarp_1_1Crypto.md#function-pqe-decrypt)


### function pqe_encrypt

```cpp
virtual bool pqe_encrypt(
    PQCipherBlock & ,
    SharedSecret & ,
    const PQPubKey & 
) override
```

post quantum encrypt (buffer, sharedkey_dst, pub) 

**Reimplements**: [llarp::Crypto::pqe_encrypt](Classes/structllarp_1_1Crypto.md#function-pqe-encrypt)


### function check_identity_privkey

```cpp
virtual bool check_identity_privkey(
    const SecretKey & 
) override
```


**Reimplements**: [llarp::Crypto::check_identity_privkey](Classes/structllarp_1_1Crypto.md#function-check-identity-privkey)


### function check_passwd_hash

```cpp
virtual bool check_passwd_hash(
    std::string pwhash,
    std::string challenge
) override
```

check if a password hash string matches the challenge 

**Reimplements**: [llarp::Crypto::check_passwd_hash](Classes/structllarp_1_1Crypto.md#function-check-passwd-hash)


-------------------------------

Updated on 2022-11-08 at 16:19:49 +0000