Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
b03df3f7
Commit
b03df3f7
authored
1 year ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
aesEncrypt: allow to provide salt
parent
6a6816ad
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/crypto.h
+4
-1
4 additions, 1 deletion
include/opendht/crypto.h
src/crypto.cpp
+4
-4
4 additions, 4 deletions
src/crypto.cpp
with
8 additions
and
5 deletions
include/opendht/crypto.h
+
4
−
1
View file @
b03df3f7
...
@@ -807,8 +807,11 @@ OPENDHT_PUBLIC inline Blob aesEncrypt(const Blob& data, const Blob& key) {
...
@@ -807,8 +807,11 @@ OPENDHT_PUBLIC inline Blob aesEncrypt(const Blob& data, const Blob& key) {
* This function uses `stretchKey` to generate an AES key from the password and a random salt.
* 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)`.
* 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`.
* If needed, the salt or encrypted data can be individually extracted from the bundle with `aesGetSalt` and `aesGetEncrypted`.
* @param data: data to encrypt
* @param password: password to encrypt the data with
* @param salt: optional salt to use for key derivation. If not provided, a random salt will be generated.
*/
*/
OPENDHT_PUBLIC
Blob
aesEncrypt
(
const
Blob
&
data
,
std
::
string_view
password
);
OPENDHT_PUBLIC
Blob
aesEncrypt
(
const
Blob
&
data
,
std
::
string_view
password
,
const
Blob
&
salt
=
{}
);
/**
/**
* AES-GCM decryption.
* AES-GCM decryption.
...
...
This diff is collapsed.
Click to expand it.
src/crypto.cpp
+
4
−
4
View file @
b03df3f7
...
@@ -103,11 +103,11 @@ Blob aesEncrypt(const uint8_t* data, size_t data_length, const Blob& key)
...
@@ -103,11 +103,11 @@ Blob aesEncrypt(const uint8_t* data, size_t data_length, const Blob& key)
return
ret
;
return
ret
;
}
}
Blob
aesEncrypt
(
const
Blob
&
data
,
std
::
string_view
password
)
Blob
aesEncrypt
(
const
Blob
&
data
,
std
::
string_view
password
,
const
Blob
&
salt
)
{
{
Blob
salt
;
Blob
salt_actual
=
salt
;
Blob
key
=
stretchKey
(
password
,
salt
,
256
/
8
);
Blob
key
=
stretchKey
(
password
,
salt
_actual
,
256
/
8
);
return
aesBuildEncrypted
(
aesEncrypt
(
data
,
key
),
salt
);
return
aesBuildEncrypted
(
aesEncrypt
(
data
,
key
),
salt
_actual
);
}
}
Blob
aesDecrypt
(
const
uint8_t
*
data
,
size_t
data_length
,
const
Blob
&
key
)
Blob
aesDecrypt
(
const
uint8_t
*
data
,
size_t
data_length
,
const
Blob
&
key
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment