---
title: llarp/crypto/crypto_libsodium.hpp

---

# llarp/crypto/crypto_libsodium.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::sodium](Namespaces/namespacellarp_1_1sodium.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::sodium::CryptoLibSodium](Classes/structllarp_1_1sodium_1_1CryptoLibSodium.md)**  |




## Source code

```cpp
#pragma once

#include "crypto.hpp"

namespace llarp
{
  namespace sodium
  {
    struct CryptoLibSodium final : public Crypto
    {
      CryptoLibSodium();

      ~CryptoLibSodium() override = default;

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

      bool
      xchacha20(const llarp_buffer_t&, const SharedSecret&, const TunnelNonce&) override;

      bool
      xchacha20_alt(
          const llarp_buffer_t&,
          const llarp_buffer_t&,
          const SharedSecret&,
          const byte_t*) override;

      bool
      dh_client(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&) override;
      bool
      dh_server(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&) override;
      bool
      transport_dh_client(
          SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&) override;
      bool
      transport_dh_server(
          SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&) override;
      bool
      shorthash(ShortHash&, const llarp_buffer_t&) override;
      bool
      hmac(byte_t*, const llarp_buffer_t&, const SharedSecret&) override;
      bool
      sign(Signature&, const SecretKey&, const llarp_buffer_t&) override;
      bool
      sign(Signature&, const PrivateKey&, const llarp_buffer_t&) override;
      bool
      verify(const PubKey&, const llarp_buffer_t&, const Signature&) override;

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

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

      bool
      seed_to_secretkey(llarp::SecretKey&, const llarp::IdentitySecret&) override;
      void
      randomize(const llarp_buffer_t&) override;
      void
      randbytes(byte_t*, size_t) override;
      void
      identity_keygen(SecretKey&) override;
      void
      encryption_keygen(SecretKey&) override;
      void
      pqe_keygen(PQKeyPair&) override;
      bool
      pqe_decrypt(const PQCipherBlock&, SharedSecret&, const byte_t*) override;
      bool
      pqe_encrypt(PQCipherBlock&, SharedSecret&, const PQPubKey&) override;

      bool
      check_identity_privkey(const SecretKey&) override;

      bool
      check_passwd_hash(std::string pwhash, std::string challenge) override;
    };
  }  // namespace sodium

}  // namespace llarp
```


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

Updated on 2023-01-09 at 16:43:38 +0000
