C++ Distributed Hash Table
crypto.h
1 /*
2  * Copyright (C) 2014-2022 Savoir-faire Linux Inc.
3  * Author : Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com>
4  * Vsevolod Ivanov <vsevolod.ivanov@savoirfairelinux.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include "infohash.h"
23 #include "utils.h"
24 #include "rng.h"
25 
26 extern "C" {
27 #include <gnutls/gnutls.h>
28 #include <gnutls/abstract.h>
29 #include <gnutls/x509.h>
30 #include <gnutls/ocsp.h>
31 }
32 
33 #include <vector>
34 #include <memory>
35 
36 #ifdef _WIN32
37 #include <iso646.h>
38 #endif
39 
40 namespace dht {
41 
45 namespace crypto {
46 
47 class OPENDHT_PUBLIC CryptoException : public std::runtime_error {
48 public:
49  explicit CryptoException(const std::string& str) : std::runtime_error(str) {};
50  explicit CryptoException(const char* str) : std::runtime_error(str) {};
51  CryptoException(const CryptoException& e) noexcept = default;
52  CryptoException& operator=(const CryptoException&) noexcept = default;
53 };
54 
58 class OPENDHT_PUBLIC DecryptError : public CryptoException {
59 public:
60  explicit DecryptError(const std::string& str) : CryptoException(str) {};
61  explicit DecryptError(const char* str) : CryptoException(str) {};
62  DecryptError(const DecryptError& e) noexcept = default;
63  DecryptError& operator=(const DecryptError&) noexcept = default;
64 };
65 
66 struct PrivateKey;
67 struct Certificate;
68 class RevocationList;
69 
70 using Identity = std::pair<std::shared_ptr<PrivateKey>, std::shared_ptr<Certificate>>;
71 
75 struct OPENDHT_PUBLIC PublicKey
76 {
77  PublicKey();
78 
82  PublicKey(gnutls_pubkey_t k) : pk(k) {}
83 
85  PublicKey(const uint8_t* dat, size_t dat_size);
86  PublicKey(const Blob& pk) : PublicKey(pk.data(), pk.size()) {}
87  PublicKey(PublicKey&& o) noexcept : pk(o.pk) { o.pk = nullptr; };
88 
89  ~PublicKey();
90  explicit operator bool() const { return pk; }
91  bool operator ==(const PublicKey& o) const {
92  return pk == o.pk || getId() == o.getId();
93  }
94  bool operator !=(const PublicKey& o) const {
95  return !(*this == o);
96  }
97 
98  PublicKey& operator=(PublicKey&& o) noexcept;
99 
103  InfoHash getId() const;
104 
108  PkId getLongId() const;
109 
110  bool checkSignature(const uint8_t* data, size_t data_len, const uint8_t* signature, size_t signature_len) const;
111  inline bool checkSignature(const Blob& data, const Blob& signature) const {
112  return checkSignature(data.data(), data.size(), signature.data(), signature.size());
113  }
114 
115  Blob encrypt(const uint8_t* data, size_t data_len) const;
116  inline Blob encrypt(const Blob& data) const {
117  return encrypt(data.data(), data.size());
118  }
119 
120  void pack(Blob& b) const;
121  int pack(uint8_t* out, size_t* out_len) const;
122  void unpack(const uint8_t* dat, size_t dat_size);
123 
124  std::string toString() const;
125 
126  template <typename Packer>
127  void msgpack_pack(Packer& p) const
128  {
129  Blob b;
130  pack(b);
131  p.pack_bin(b.size());
132  p.pack_bin_body((const char*)b.data(), b.size());
133  }
134 
135  void msgpack_unpack(const msgpack::object& o);
136 
137  gnutls_digest_algorithm_t getPreferredDigest() const;
138 
139  gnutls_pubkey_t pk {nullptr};
140 private:
141  PublicKey(const PublicKey&) = delete;
142  PublicKey& operator=(const PublicKey&) = delete;
143  void encryptBloc(const uint8_t* src, size_t src_size, uint8_t* dst, size_t dst_size) const;
144 };
145 
149 struct OPENDHT_PUBLIC PrivateKey
150 {
151  PrivateKey();
152  //PrivateKey(gnutls_privkey_t k) : key(k) {}
153 
157  PrivateKey(gnutls_x509_privkey_t k);
158 
159  PrivateKey(PrivateKey&& o) noexcept;
160  PrivateKey& operator=(PrivateKey&& o) noexcept;
161 
162  PrivateKey(const uint8_t* src, size_t src_size, const char* password = nullptr);
163  PrivateKey(const Blob& src, const std::string& password = {}) : PrivateKey(src.data(), src.size(), password.data()) {}
164  ~PrivateKey();
165  explicit operator bool() const { return key; }
166 
167  const PublicKey& getPublicKey() const;
168  const std::shared_ptr<PublicKey>& getSharedPublicKey() const;
169 
170  int serialize(uint8_t* out, size_t* out_len, const std::string& password = {}) const;
171  Blob serialize(const std::string& password = {}) const;
172 
177  Blob sign(const uint8_t* data, size_t data_len) const;
178  inline Blob sign(const Blob& dat) const { return sign(dat.data(), dat.size()); }
179 
185  Blob decrypt(const uint8_t* cypher, size_t cypher_len) const;
186  Blob decrypt(const Blob& cypher) const { return decrypt(cypher.data(), cypher.size()); }
187 
194  static PrivateKey generate(unsigned key_length = 4096);
195  static PrivateKey generateEC();
196 
197  gnutls_privkey_t key {};
198  gnutls_x509_privkey_t x509_key {};
199 private:
200  PrivateKey(const PrivateKey&) = delete;
201  PrivateKey& operator=(const PrivateKey&) = delete;
202  Blob decryptBloc(const uint8_t* src, size_t src_size) const;
203 
204  mutable std::shared_ptr<PublicKey> publicKey_ {};
205 };
206 
207 class OPENDHT_PUBLIC RevocationList
208 {
209  using clock = std::chrono::system_clock;
210  using time_point = clock::time_point;
211  using duration = clock::duration;
212 public:
213  RevocationList();
214  RevocationList(const Blob& b);
215  RevocationList(RevocationList&& o) noexcept : crl(o.crl) { o.crl = nullptr; }
216  ~RevocationList();
217 
218  RevocationList& operator=(RevocationList&& o) { crl = o.crl; o.crl = nullptr; return *this; }
219 
220  void pack(Blob& b) const;
221  void unpack(const uint8_t* dat, size_t dat_size);
222  Blob getPacked() const {
223  Blob b;
224  pack(b);
225  return b;
226  }
227 
228  template <typename Packer>
229  void msgpack_pack(Packer& p) const
230  {
231  Blob b = getPacked();
232  p.pack_bin(b.size());
233  p.pack_bin_body((const char*)b.data(), b.size());
234  }
235 
236  void msgpack_unpack(const msgpack::object& o);
237 
238  void revoke(const Certificate& crt, time_point t = time_point::min());
239 
240  bool isRevoked(const Certificate& crt) const;
241 
246  void sign(const PrivateKey&, const Certificate&, duration validity_period = {});
247  void sign(const Identity& id) { sign(*id.first, *id.second); }
248 
249  bool isSignedBy(const Certificate& issuer) const;
250 
251  std::string toString() const;
252 
256  Blob getNumber() const;
257 
259  std::string getIssuerName() const;
260 
262  std::string getIssuerUID() const;
263 
264  time_point getUpdateTime() const;
265  time_point getNextUpdateTime() const;
266 
267  gnutls_x509_crl_t get() { return crl; }
268  gnutls_x509_crl_t getCopy() const {
269  if (not crl)
270  return nullptr;
271  auto copy = RevocationList(getPacked());
272  gnutls_x509_crl_t ret = copy.crl;
273  copy.crl = nullptr;
274  return ret;
275  }
276 
277 private:
278  gnutls_x509_crl_t crl {};
279  RevocationList(const RevocationList&) = delete;
280  RevocationList& operator=(const RevocationList&) = delete;
281 };
282 
283 enum class NameType { UNKNOWN = 0, RFC822, DNS, URI, IP };
284 
285 class OPENDHT_PUBLIC CertificateRequest {
286 public:
288  CertificateRequest(const uint8_t* data, size_t size);
289  CertificateRequest(const Blob& data) : CertificateRequest(data.data(), data.size()) {}
290 
291  CertificateRequest(CertificateRequest&& o) noexcept : request(std::move(o.request)) {
292  o.request = nullptr;
293  }
294  CertificateRequest& operator=(CertificateRequest&& o) noexcept;
295 
297 
298  void setName(const std::string& name);
299  void setUID(const std::string& name);
300  void setAltName(NameType type, const std::string& name);
301 
302  std::string getName() const;
303  std::string getUID() const;
304 
305  void sign(const PrivateKey& key, const std::string& password = {});
306 
307  bool verify() const;
308 
309  Blob pack() const;
310  std::string toString() const;
311 
312  gnutls_x509_crq_t get() const { return request; }
313 private:
314  CertificateRequest(const CertificateRequest& o) = delete;
315  CertificateRequest& operator=(const CertificateRequest& o) = delete;
316  gnutls_x509_crq_t request {nullptr};
317 };
318 
319 class OPENDHT_PUBLIC OcspRequest
320 {
321 public:
322  OcspRequest(gnutls_ocsp_req_t r) : request(r) {};
323  OcspRequest(const uint8_t* dat_ptr, size_t dat_size);
324  ~OcspRequest();
325 
326  /*
327  * Get OCSP Request in readable format.
328  */
329  std::string toString(const bool compact = true) const;
330 
331  Blob pack() const;
332  Blob getNonce() const;
333 private:
334  gnutls_ocsp_req_t request;
335 };
336 
337 class OPENDHT_PUBLIC OcspResponse
338 {
339 public:
340  OcspResponse(const uint8_t* dat_ptr, size_t dat_size);
341  OcspResponse(const std::string& response) : OcspResponse((const uint8_t*)response.data(), response.size()) {};
342  ~OcspResponse();
343 
344  Blob pack() const;
345  /*
346  * Get OCSP Response in readable format.
347  */
348  std::string toString(const bool compact = true) const;
349 
350  /*
351  * Get OCSP response certificate status.
352  * Return certificate status.
353  * http://www.gnu.org/software/gnutls/reference/gnutls-ocsp.html#gnutls-ocsp-cert-status-t
354  */
355  gnutls_ocsp_cert_status_t getCertificateStatus() const;
356 
357  /*
358  * Verify OCSP response and return OCSP status.
359  * Throws CryptoException in case of error in the response.
360  * http://www.gnu.org/software/gnutls/reference/gnutls-ocsp.html#gnutls-ocsp-verify-reason-t
361  */
362  gnutls_ocsp_cert_status_t verifyDirect(const Certificate& crt, const Blob& nonce);
363 
364 private:
365  gnutls_ocsp_resp_t response;
366 };
367 
368 struct OPENDHT_PUBLIC Certificate {
369  Certificate() noexcept {}
370 
374  Certificate(gnutls_x509_crt_t crt) noexcept : cert(crt) {}
375 
376  Certificate(Certificate&& o) noexcept : cert(o.cert), issuer(std::move(o.issuer)) { o.cert = nullptr; };
377 
382  Certificate(const Blob& crt);
383  Certificate(const std::string& pem) : cert(nullptr) {
384  unpack((const uint8_t*)pem.data(), pem.size());
385  }
386  Certificate(const uint8_t* dat, size_t dat_size) : cert(nullptr) {
387  unpack(dat, dat_size);
388  }
389 
394  template<typename Iterator>
395  Certificate(const Iterator& begin, const Iterator& end) {
396  unpack(begin, end);
397  }
398 
403  template<typename Iterator>
404  Certificate(const std::vector<std::pair<Iterator, Iterator>>& certs) {
405  unpack(certs);
406  }
407 
408  Certificate& operator=(Certificate&& o) noexcept;
409  ~Certificate();
410 
411  void pack(Blob& b) const;
412  void unpack(const uint8_t* dat, size_t dat_size);
413  Blob getPacked() const {
414  Blob b;
415  pack(b);
416  return b;
417  }
418 
427  template<typename Iterator>
428  void unpack(const Iterator& begin, const Iterator& end)
429  {
430  std::shared_ptr<Certificate> tmp_subject {};
431  std::shared_ptr<Certificate> first {};
432  for (Iterator icrt = begin; icrt < end; ++icrt) {
433  auto tmp_crt = std::make_shared<Certificate>(*icrt);
434  if (tmp_subject)
435  tmp_subject->issuer = tmp_crt;
436  tmp_subject = std::move(tmp_crt);
437  if (!first)
438  first = tmp_subject;
439  }
440  *this = first ? std::move(*first) : Certificate();
441  }
442 
454  template<typename Iterator>
455  void unpack(const std::vector<std::pair<Iterator, Iterator>>& certs)
456  {
457  std::shared_ptr<Certificate> tmp_issuer;
458  // reverse iteration
459  for (auto li = certs.rbegin(); li != certs.rend(); ++li) {
460  Certificate tmp_crt;
461  gnutls_x509_crt_init(&tmp_crt.cert);
462  const gnutls_datum_t crt_dt {(uint8_t*)&(*li->first), (unsigned)(li->second-li->first)};
463  int err = gnutls_x509_crt_import(tmp_crt.cert, &crt_dt, GNUTLS_X509_FMT_PEM);
464  if (err != GNUTLS_E_SUCCESS)
465  err = gnutls_x509_crt_import(tmp_crt.cert, &crt_dt, GNUTLS_X509_FMT_DER);
466  if (err != GNUTLS_E_SUCCESS)
467  throw CryptoException(std::string("Could not read certificate - ") + gnutls_strerror(err));
468  tmp_crt.issuer = tmp_issuer;
469  tmp_issuer = std::make_shared<Certificate>(std::move(tmp_crt));
470  }
471  *this = tmp_issuer ? std::move(*tmp_issuer) : Certificate();
472  }
473 
474  template <typename Packer>
475  void msgpack_pack(Packer& p) const
476  {
477  Blob b;
478  pack(b);
479  p.pack_bin(b.size());
480  p.pack_bin_body((const char*)b.data(), b.size());
481  }
482 
483  void msgpack_unpack(const msgpack::object& o);
484 
485  explicit operator bool() const { return cert; }
486  PublicKey getPublicKey() const;
487 
489  InfoHash getId() const;
491  PkId getLongId() const;
492 
493  Blob getSerialNumber() const;
494 
496  std::string getName() const;
497 
499  std::string getUID() const;
500 
502  std::string getIssuerName() const;
503 
505  std::string getIssuerUID() const;
506 
508  std::vector<std::pair<NameType, std::string>> getAltNames() const;
509 
510  std::chrono::system_clock::time_point getActivation() const;
511  std::chrono::system_clock::time_point getExpiration() const;
512 
517  bool isCA() const;
518 
523  std::string toString(bool chain = true) const;
524 
525  std::string print() const;
526 
531  void revoke(const PrivateKey&, const Certificate&);
532 
536  std::vector<std::shared_ptr<RevocationList>> getRevocationLists() const;
537 
541  void addRevocationList(RevocationList&&);
542  void addRevocationList(std::shared_ptr<RevocationList>);
543 
544  static Certificate generate(const PrivateKey& key, const std::string& name = "dhtnode", const Identity& ca = {}, bool is_ca = false, int64_t validity = 0);
545  static Certificate generate(const CertificateRequest& request, const Identity& ca, int64_t validity = 0);
546 
547  gnutls_x509_crt_t getCopy() const {
548  if (not cert)
549  return nullptr;
550  auto copy = Certificate(getPacked());
551  gnutls_x509_crt_t ret = copy.cert;
552  copy.cert = nullptr;
553  return ret;
554  }
555 
556  std::vector<gnutls_x509_crt_t>
557  getChain(bool copy = false) const
558  {
559  if (not cert)
560  return {};
561  std::vector<gnutls_x509_crt_t> crts;
562  for (auto c = this; c; c = c->issuer.get())
563  crts.emplace_back(copy ? c->getCopy() : c->cert);
564  return crts;
565  }
566 
567  std::pair<
568  std::vector<gnutls_x509_crt_t>,
569  std::vector<gnutls_x509_crl_t>
570  >
571  getChainWithRevocations(bool copy = false) const
572  {
573  if (not cert)
574  return {};
575  std::vector<gnutls_x509_crt_t> crts;
576  std::vector<gnutls_x509_crl_t> crls;
577  for (auto c = this; c; c = c->issuer.get()) {
578  crts.emplace_back(copy ? c->getCopy() : c->cert);
579  crls.reserve(crls.size() + c->revocation_lists.size());
580  for (const auto& crl : c->revocation_lists)
581  crls.emplace_back(copy ? crl->getCopy() : crl->get());
582  }
583  return {crts, crls};
584  }
585 
586  gnutls_digest_algorithm_t getPreferredDigest() const;
587 
588  /*
589  * Generate OCSP request.
590  * Return GnuTLS error code.
591  * https://www.gnutls.org/manual/html_node/Error-codes.html
592  */
593  std::pair<std::string, Blob> generateOcspRequest(gnutls_x509_crt_t& issuer);
594 
598  void setValidity(const Identity& ca, int64_t validity);
599  void setValidity(const PrivateKey& key, int64_t validity);
600 
601  gnutls_x509_crt_t cert {nullptr};
602  std::shared_ptr<Certificate> issuer {};
603  std::shared_ptr<OcspResponse> ocspResponse;
604 private:
605  Certificate(const Certificate&) = delete;
606  Certificate& operator=(const Certificate&) = delete;
607  mutable InfoHash cachedId_ {};
608  mutable PkId cachedLongId_ {};
609 
610  struct crlNumberCmp {
611  bool operator() (const std::shared_ptr<RevocationList>& lhs, const std::shared_ptr<RevocationList>& rhs) const {
612  return lhs->getNumber() < rhs->getNumber();
613  }
614  };
615 
616  std::set<std::shared_ptr<RevocationList>, crlNumberCmp> revocation_lists;
617 };
618 
619 struct OPENDHT_PUBLIC TrustList
620 {
621  struct VerifyResult {
622  int ret;
623  unsigned result;
624  bool hasError() const { return ret < 0; }
625  bool isValid() const { return !hasError() and !(result & GNUTLS_CERT_INVALID); }
626  explicit operator bool() const { return isValid(); }
627  std::string toString() const;
628  OPENDHT_PUBLIC friend std::ostream& operator<< (std::ostream& s, const VerifyResult& h);
629  };
630 
631  TrustList();
632  TrustList(TrustList&& o) noexcept : trust(std::move(o.trust)) {
633  o.trust = nullptr;
634  }
635  TrustList& operator=(TrustList&& o) noexcept;
636  ~TrustList();
637  void add(const Certificate& crt);
638  void add(const RevocationList& crl);
639  void remove(const Certificate& crt, bool parents = true);
640  VerifyResult verify(const Certificate& crt) const;
641 
642 private:
643  TrustList(const TrustList& o) = delete;
644  TrustList& operator=(const TrustList& o) = delete;
645  gnutls_x509_trust_list_t trust {nullptr};
646 };
647 
648 template <class T>
649 class OPENDHT_PUBLIC secure_vector
650 {
651 public:
652  secure_vector() {}
653  secure_vector(secure_vector<T> const&) = default;
654  secure_vector(secure_vector<T> &&) = default;
655  explicit secure_vector(unsigned size): data_(size) {}
656  explicit secure_vector(unsigned size, T _item): data_(size, _item) {}
657  explicit secure_vector(const std::vector<T>& c): data_(c) {}
658  secure_vector(std::vector<T>&& c): data_(std::move(c)) {}
659  ~secure_vector() { clean(); }
660 
661  static secure_vector<T> getRandom(size_t size) {
662  secure_vector<T> ret(size);
663  crypto::random_device rdev;
664 #ifdef _WIN32
665  std::uniform_int_distribution<int> rand_byte{ 0, std::numeric_limits<uint8_t>::max() };
666 #else
667  std::uniform_int_distribution<uint8_t> rand_byte;
668 #endif
669  std::generate_n((uint8_t*)ret.data_.data(), ret.size()*sizeof(T), std::bind(rand_byte, std::ref(rdev)));
670  return ret;
671  }
672  secure_vector<T>& operator=(const secure_vector<T>& c) {
673  if (&c == this)
674  return *this;
675  clean();
676  data_ = c.data_;
677  return *this;
678  }
679  secure_vector<T>& operator=(secure_vector<T>&& c) {
680  if (&c == this)
681  return *this;
682  clean();
683  data_ = std::move(c.data_);
684  return *this;
685  }
686  secure_vector<T>& operator=(std::vector<T>&& c) {
687  clean();
688  data_ = std::move(c);
689  return *this;
690  }
691  std::vector<T>& writable() { clean(); return data_; }
692  const std::vector<T>& makeInsecure() const { return data_; }
693  const uint8_t* data() const { return data_.data(); }
694 
695  void clean() {
696  clean(data_.begin(), data_.end());
697  }
698 
699  void clear() { clean(); data_.clear(); }
700 
701  size_t size() const { return data_.size(); }
702  bool empty() const { return data_.empty(); }
703 
704  void swap(secure_vector<T>& other) { data_.swap(other.data_); }
705  void resize(size_t s) {
706  if (s == data_.size()) return;
707  if (s < data_.size()) {
708  //shrink
709  clean(data_.begin()+s, data_.end());
710  data_.resize(s);
711  } else {
712  //grow
713  auto data = std::move(data_); // move protected data
714  clear();
715  data_.resize(s);
716  std::copy(data.begin(), data.end(), data_.begin());
717  clean(data.begin(), data.end());
718  }
719  }
720 
721 private:
725  static void clean(const typename std::vector<T>::iterator& i, const typename std::vector<T>::iterator& j) {
726  volatile uint8_t* b = reinterpret_cast<uint8_t*>(&*i);
727  volatile uint8_t* e = reinterpret_cast<uint8_t*>(&*j);
728  std::fill(b, e, 0);
729  }
730 
731  std::vector<T> data_;
732 };
733 
735 
743 OPENDHT_PUBLIC Identity generateIdentity(const std::string& name, const Identity& ca, unsigned key_length, bool is_ca);
744 OPENDHT_PUBLIC Identity generateIdentity(const std::string& name = "dhtnode", const Identity& ca = {}, unsigned key_length = 4096);
745 
746 OPENDHT_PUBLIC Identity generateEcIdentity(const std::string& name, const Identity& ca, bool is_ca);
747 OPENDHT_PUBLIC Identity generateEcIdentity(const std::string& name = "dhtnode", const Identity& ca = {});
748 
749 OPENDHT_PUBLIC void saveIdentity(const Identity& id, const std::string& path, const std::string& privkey_password = {});
750 
759 OPENDHT_PUBLIC Blob hash(const Blob& data, size_t hash_length = 512/8);
760 
761 OPENDHT_PUBLIC void hash(const uint8_t* data, size_t data_length, uint8_t* hash, size_t hash_length);
762 
770 OPENDHT_PUBLIC Blob stretchKey(const std::string& password, Blob& salt, size_t key_length = 512/8);
771 
775 OPENDHT_PUBLIC Blob aesEncrypt(const uint8_t* data, size_t data_length, const Blob& key);
776 OPENDHT_PUBLIC inline Blob aesEncrypt(const Blob& data, const Blob& key) {
777  return aesEncrypt(data.data(), data.size(), key);
778 }
779 OPENDHT_PUBLIC Blob aesEncrypt(const Blob& data, const std::string& password);
780 
784 OPENDHT_PUBLIC Blob aesDecrypt(const uint8_t* data, size_t data_length, const Blob& key);
785 OPENDHT_PUBLIC inline Blob aesDecrypt(const Blob& data, const Blob& key) { return aesDecrypt(data.data(), data.size(), key); }
786 OPENDHT_PUBLIC Blob aesDecrypt(const uint8_t* data, size_t data_length, const std::string& password);
787 OPENDHT_PUBLIC inline Blob aesDecrypt(const Blob& data, const std::string& password) { return aesDecrypt(data.data(), data.size(), password); }
788 
789 }
790 }
OPENDHT_PUBLIC Identity generateIdentity(const std::string &name, const Identity &ca, unsigned key_length, bool is_ca)
Certificate(const Iterator &begin, const Iterator &end)
Definition: crypto.h:395
OPENDHT_PUBLIC Blob hash(const Blob &data, size_t hash_length=512/8)
Certificate(gnutls_x509_crt_t crt) noexcept
Definition: crypto.h:374
OPENDHT_PUBLIC Blob aesEncrypt(const uint8_t *data, size_t data_length, const Blob &key)
OPENDHT_PUBLIC Blob stretchKey(const std::string &password, Blob &salt, size_t key_length=512/8)
void unpack(const std::vector< std::pair< Iterator, Iterator >> &certs)
Definition: crypto.h:455
PublicKey(gnutls_pubkey_t k)
Definition: crypto.h:82
OPENDHT_PUBLIC Blob aesDecrypt(const uint8_t *data, size_t data_length, const Blob &key)
std::vector< uint8_t > Blob
Definition: utils.h:151
Definition: callbacks.h:35
Certificate(const std::vector< std::pair< Iterator, Iterator >> &certs)
Definition: crypto.h:404
void unpack(const Iterator &begin, const Iterator &end)
Definition: crypto.h:428