mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-11 22:07:10 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef0bd6db77 | ||
|
|
111bfea6f3 | ||
|
|
e35a11a495 | ||
|
|
0592b9ff51 | ||
|
|
297e182576 | ||
|
|
b285e6fd2b |
No files matched your search
@@ -57,7 +57,7 @@ jobs:
|
||||
|
||||
build-macos:
|
||||
name: macOS/Clang build
|
||||
runs-on: macos-11
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Dependencies
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ include(cmake/CheckAtomic.cmake)
|
||||
include(CTest)
|
||||
|
||||
set (opendht_VERSION_MAJOR 3)
|
||||
set (opendht_VERSION_MINOR 1.3)
|
||||
set (opendht_VERSION_MINOR 1.4)
|
||||
set (opendht_VERSION ${opendht_VERSION_MAJOR}.${opendht_VERSION_MINOR})
|
||||
set (PACKAGE_VERSION ${opendht_VERSION})
|
||||
set (VERSION "${opendht_VERSION}")
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
dnl define macros
|
||||
m4_define([opendht_major_version], 3)
|
||||
m4_define([opendht_minor_version], 1)
|
||||
m4_define([opendht_patch_version], 3)
|
||||
m4_define([opendht_patch_version], 4)
|
||||
m4_define([opendht_version],
|
||||
[opendht_major_version.opendht_minor_version.opendht_patch_version])
|
||||
|
||||
|
||||
@@ -802,6 +802,12 @@ OPENDHT_PUBLIC Blob aesEncrypt(const uint8_t* data, size_t data_length, const Bl
|
||||
OPENDHT_PUBLIC inline Blob aesEncrypt(const Blob& data, const Blob& key) {
|
||||
return aesEncrypt(data.data(), data.size(), key);
|
||||
}
|
||||
/**
|
||||
* AES-GCM encryption with argon2 key derivation.
|
||||
* This function uses `stretchKey` to generate an AES key from the password and a random salt.
|
||||
* The result is a bundle including the salt that can be decrypted with `aesDecrypt(data, password)`.
|
||||
* If needed, the salt or encrypted data can be individually extracted from the bundle with `aesGetSalt` and `aesGetEncrypted`.
|
||||
*/
|
||||
OPENDHT_PUBLIC Blob aesEncrypt(const Blob& data, std::string_view password);
|
||||
|
||||
/**
|
||||
@@ -827,12 +833,24 @@ OPENDHT_PUBLIC Blob aesGetSalt(const uint8_t* data, size_t data_length);
|
||||
OPENDHT_PUBLIC Blob inline aesGetSalt(const Blob& data) {
|
||||
return aesGetSalt(data.data(), data.size());
|
||||
}
|
||||
/** Get the salt part of data password-encrypted with `aesEncrypt(data, password)` */
|
||||
/** Get the encrypted data part of data password-encrypted with `aesEncrypt(data, password)` */
|
||||
OPENDHT_PUBLIC std::string_view aesGetEncrypted(const uint8_t* data, size_t data_length);
|
||||
OPENDHT_PUBLIC std::string_view inline aesGetEncrypted(const Blob& data) {
|
||||
return aesGetEncrypted(data.data(), data.size());
|
||||
}
|
||||
|
||||
/** Build an encrypted bundle that can be decrypted with aesDecrypt(data, password).
|
||||
* @param encryptedData: result of `aesEncrypt(data, key)` or `aesGetEncrypted`
|
||||
* @param salt: should match the encryption key and password so that `stretchKey(password, salk) == key`.
|
||||
* Can be obtained from an existing bundle with `aesGetSalt`.
|
||||
**/
|
||||
OPENDHT_PUBLIC Blob aesBuildEncrypted(const uint8_t* encryptedData, size_t data_length, const Blob& salt);
|
||||
OPENDHT_PUBLIC Blob inline aesBuildEncrypted(const Blob& encryptedData, const Blob& salt) {
|
||||
return aesBuildEncrypted(encryptedData.data(), encryptedData.size(), salt);
|
||||
}
|
||||
OPENDHT_PUBLIC Blob inline aesBuildEncrypted(std::string_view encryptedData, const Blob& salt) {
|
||||
return aesBuildEncrypted((const uint8_t*)encryptedData.data(), encryptedData.size(), salt);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
project('opendht', 'c', 'cpp',
|
||||
version: '3.1.3',
|
||||
version: '3.1.4',
|
||||
default_options: [
|
||||
'cpp_std=c++17',
|
||||
'warning_level=3'
|
||||
|
||||
+10
-3
@@ -107,9 +107,7 @@ Blob aesEncrypt(const Blob& data, std::string_view password)
|
||||
{
|
||||
Blob salt;
|
||||
Blob key = stretchKey(password, salt, 256 / 8);
|
||||
Blob encrypted = aesEncrypt(data, key);
|
||||
encrypted.insert(encrypted.begin(), salt.begin(), salt.end());
|
||||
return encrypted;
|
||||
return aesBuildEncrypted(aesEncrypt(data, key), salt);
|
||||
}
|
||||
|
||||
Blob aesDecrypt(const uint8_t* data, size_t data_length, const Blob& key)
|
||||
@@ -174,6 +172,15 @@ std::string_view aesGetEncrypted(const uint8_t* data, size_t data_length)
|
||||
return std::string_view((const char*)(data+PASSWORD_SALT_LENGTH), data_length - PASSWORD_SALT_LENGTH);
|
||||
}
|
||||
|
||||
Blob aesBuildEncrypted(const uint8_t* data, size_t data_length, const Blob& salt)
|
||||
{
|
||||
Blob ret;
|
||||
ret.reserve(data_length + salt.size());
|
||||
ret.insert(ret.end(), salt.begin(), salt.end());
|
||||
ret.insert(ret.end(), data, data + data_length);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Blob aesGetKey(const uint8_t* data, size_t data_length, std::string_view password)
|
||||
{
|
||||
Blob salt = aesGetSalt(data, data_length);
|
||||
|
||||
+6
-1
@@ -854,12 +854,17 @@ Dht::Search::insertNode(const Sp<Node>& snode, time_point now, const Blob& token
|
||||
expired = false;
|
||||
}
|
||||
|
||||
while (nodes.size() - bad > SEARCH_NODES) {
|
||||
while (nodes.size() - bad > SEARCH_NODES) {
|
||||
bool removingNode = nodes.back()->node == snode;
|
||||
if (not expired and nodes.back()->isBad())
|
||||
bad--;
|
||||
nodes.pop_back();
|
||||
if (removingNode)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (n == nodes.end() or not *n)
|
||||
return false;
|
||||
if (not token.empty()) {
|
||||
(*n)->candidate = false;
|
||||
(*n)->last_get_reply = now;
|
||||
|
||||
@@ -208,6 +208,12 @@ void CryptoTester::testAesEncryption() {
|
||||
|
||||
CPPUNIT_ASSERT(salt1 != salt2);
|
||||
|
||||
auto encrypted11 = dht::crypto::aesBuildEncrypted(encrypted1_data, salt1);
|
||||
auto encrypted22 = dht::crypto::aesBuildEncrypted(encrypted2_data, salt2);
|
||||
|
||||
CPPUNIT_ASSERT(encrypted11 == encrypted1);
|
||||
CPPUNIT_ASSERT(encrypted22 == encrypted2);
|
||||
|
||||
auto key12 = dht::crypto::stretchKey(password, salt1, 256/8);
|
||||
auto key22 = dht::crypto::stretchKey(password, salt2, 256/8);
|
||||
|
||||
@@ -219,6 +225,18 @@ void CryptoTester::testAesEncryption() {
|
||||
|
||||
CPPUNIT_ASSERT(data1 == decrypted1);
|
||||
CPPUNIT_ASSERT(data2 == decrypted2);
|
||||
|
||||
auto encrypted12_data = dht::crypto::aesEncrypt(data1, key12);
|
||||
auto encrypted22_data = dht::crypto::aesEncrypt(data2, key22);
|
||||
|
||||
encrypted11 = dht::crypto::aesBuildEncrypted(encrypted12_data, salt1);
|
||||
encrypted22 = dht::crypto::aesBuildEncrypted(encrypted22_data, salt2);
|
||||
|
||||
decrypted1 = dht::crypto::aesDecrypt(encrypted11, password);
|
||||
decrypted2 = dht::crypto::aesDecrypt(encrypted22, password);
|
||||
|
||||
CPPUNIT_ASSERT(data1 == decrypted1);
|
||||
CPPUNIT_ASSERT(data2 == decrypted2);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in new issue
Block a user