Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
fe709df0
Commit
fe709df0
authored
5 years ago
by
Joe Donofry
Browse files
Options
Downloads
Patches
Plain Diff
Remove explicit pointer use in crypto utils
parent
d0a6c8fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/mtxclient/crypto/client.hpp
+0
-10
0 additions, 10 deletions
include/mtxclient/crypto/client.hpp
include/mtxclient/crypto/utils.hpp
+12
-0
12 additions, 0 deletions
include/mtxclient/crypto/utils.hpp
lib/crypto/utils.cpp
+6
-10
6 additions, 10 deletions
lib/crypto/utils.cpp
with
18 additions
and
20 deletions
include/mtxclient/crypto/client.hpp
+
0
−
10
View file @
fe709df0
...
...
@@ -68,16 +68,6 @@ private:
std
::
string
msg_
;
};
//! Create a uint8_t buffer which is initialized with random bytes.
inline
BinaryBuf
create_buffer
(
std
::
size_t
nbytes
)
{
auto
buf
=
BinaryBuf
(
nbytes
);
randombytes_buf
(
buf
.
data
(),
buf
.
size
());
return
buf
;
}
template
<
class
T
>
std
::
string
pickle
(
typename
T
::
olm_type
*
object
,
const
std
::
string
&
key
)
...
...
This diff is collapsed.
Click to expand it.
include/mtxclient/crypto/utils.hpp
+
12
−
0
View file @
fe709df0
...
...
@@ -9,6 +9,8 @@
#include
<openssl/hmac.h>
#include
<openssl/sha.h>
#include
<sodium.h>
#include
<boost/algorithm/string.hpp>
namespace
mtx
{
...
...
@@ -20,6 +22,16 @@ using BinaryBuf = std::vector<uint8_t>;
const
std
::
string
HEADER_LINE
(
"-----BEGIN MEGOLM SESSION DATA-----"
);
const
std
::
string
TRAILER_LINE
(
"-----END MEGOLM SESSION DATA-----"
);
//! Create a uint8_t buffer which is initialized with random bytes.
inline
BinaryBuf
create_buffer
(
std
::
size_t
nbytes
)
{
auto
buf
=
BinaryBuf
(
nbytes
);
randombytes_buf
(
buf
.
data
(),
buf
.
size
());
return
buf
;
}
//! Simple wrapper around the OpenSSL PKCS5_PBKDF2_HMAC function
BinaryBuf
PBKDF2_HMAC_SHA_512
(
const
std
::
string
pass
,
const
BinaryBuf
salt
,
uint32_t
iterations
);
...
...
This diff is collapsed.
Click to expand it.
lib/crypto/utils.cpp
+
6
−
10
View file @
fe709df0
...
...
@@ -32,7 +32,7 @@ AES_CTR_256_Encrypt(const std::string plaintext, const BinaryBuf aes256Key, Bina
int
ciphertext_len
;
unsigned
char
*
cipher
=
new
unsigned
char
[
plaintext
.
size
()
]
;
BinaryBuf
encrypted
=
create_buffer
(
plaintext
.
size
()
)
;
uint8_t
*
iv_data
=
iv
.
data
();
// need to set bit 63 to 0
...
...
@@ -51,7 +51,7 @@ AES_CTR_256_Encrypt(const std::string plaintext, const BinaryBuf aes256Key, Bina
* EVP_EncryptUpdate can be called multiple times if necessary
*/
if
(
1
!=
EVP_EncryptUpdate
(
ctx
,
cipher
,
encrypted
.
data
()
,
&
len
,
reinterpret_cast
<
const
unsigned
char
*>
(
&
plaintext
.
c_str
()[
0
]),
plaintext
.
size
()))
{
...
...
@@ -62,7 +62,7 @@ AES_CTR_256_Encrypt(const std::string plaintext, const BinaryBuf aes256Key, Bina
/* Finalise the encryption. Further ciphertext bytes may be written at
* this stage.
*/
if
(
1
!=
EVP_EncryptFinal_ex
(
ctx
,
cipher
+
len
,
&
len
))
{
if
(
1
!=
EVP_EncryptFinal_ex
(
ctx
,
encrypted
.
data
()
+
len
,
&
len
))
{
// handleErrors();
}
...
...
@@ -71,8 +71,6 @@ AES_CTR_256_Encrypt(const std::string plaintext, const BinaryBuf aes256Key, Bina
/* Clean up */
EVP_CIPHER_CTX_free
(
ctx
);
BinaryBuf
encrypted
(
reinterpret_cast
<
uint8_t
*>
(
cipher
),
cipher
+
ciphertext_len
);
delete
[]
cipher
;
return
encrypted
;
}
...
...
@@ -85,7 +83,7 @@ AES_CTR_256_Decrypt(const std::string ciphertext, const BinaryBuf aes256Key, Bin
int
plaintext_len
;
unsigned
char
*
plaintext
=
new
unsigned
char
[
ciphertext
.
size
()
]
;
BinaryBuf
decrypted
=
create_buffer
(
ciphertext
.
size
()
)
;
/* Create and initialise the context */
if
(
!
(
ctx
=
EVP_CIPHER_CTX_new
()))
{
...
...
@@ -105,7 +103,7 @@ AES_CTR_256_Decrypt(const std::string ciphertext, const BinaryBuf aes256Key, Bin
* EVP_DecryptUpdate can be called multiple times if necessary
*/
if
(
1
!=
EVP_DecryptUpdate
(
ctx
,
plaintext
,
decrypted
.
data
()
,
&
len
,
reinterpret_cast
<
const
unsigned
char
*>
(
&
ciphertext
.
data
()[
0
]),
ciphertext
.
size
()))
{
...
...
@@ -116,7 +114,7 @@ AES_CTR_256_Decrypt(const std::string ciphertext, const BinaryBuf aes256Key, Bin
/* Finalise the decryption. Further plaintext bytes may be written at
* this stage.
*/
if
(
1
!=
EVP_DecryptFinal_ex
(
ctx
,
plaintext
+
len
,
&
len
))
{
if
(
1
!=
EVP_DecryptFinal_ex
(
ctx
,
decrypted
.
data
()
+
len
,
&
len
))
{
// handleErrors();
}
plaintext_len
+=
len
;
...
...
@@ -124,8 +122,6 @@ AES_CTR_256_Decrypt(const std::string ciphertext, const BinaryBuf aes256Key, Bin
/* Clean up */
EVP_CIPHER_CTX_free
(
ctx
);
BinaryBuf
decrypted
(
reinterpret_cast
<
uint8_t
*>
(
plaintext
),
plaintext
+
plaintext_len
);
delete
[]
plaintext
;
return
decrypted
;
}
...
...
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