mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-26 17:37:47 +01:00
clang format 120 length
This commit is contained in:
@@ -23,15 +23,16 @@ std::vector<char> AES::encrypt(const std::vector<char> &in, const std::array<uin
|
||||
if (!ctx) throw Exception("Error initializing encryption context!");
|
||||
|
||||
std::vector<char> out(in.size() + AES_BLOCK_SIZE + 32);
|
||||
if (!RAND_bytes(reinterpret_cast<unsigned char *>(out.data()), 32))
|
||||
throw Exception("Error generating IV!");
|
||||
if (!RAND_bytes(reinterpret_cast<unsigned char *>(out.data()), 32)) throw Exception("Error generating IV!");
|
||||
|
||||
if (!EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_cbc(), nullptr, key.data(), reinterpret_cast<const unsigned char *>(out.data())))
|
||||
if (!EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_cbc(), nullptr, key.data(),
|
||||
reinterpret_cast<const unsigned char *>(out.data())))
|
||||
throw Exception("Error encrypting!");
|
||||
|
||||
int outlen = static_cast<int>(out.size()) - 32;
|
||||
|
||||
if (!EVP_EncryptUpdate(ctx.get(), reinterpret_cast<unsigned char *>(out.data() + 32), &outlen, reinterpret_cast<const unsigned char *>(in.data()), static_cast<int>(in.size())))
|
||||
if (!EVP_EncryptUpdate(ctx.get(), reinterpret_cast<unsigned char *>(out.data() + 32), &outlen,
|
||||
reinterpret_cast<const unsigned char *>(in.data()), static_cast<int>(in.size())))
|
||||
throw Exception("Error encrypting!");
|
||||
|
||||
int finlen = 0;
|
||||
@@ -52,11 +53,13 @@ std::vector<char> AES::decrypt(const std::vector<char> &in, const std::array<uin
|
||||
std::vector<char> out(in.size() - 32);
|
||||
int outlen = static_cast<int>(out.size());
|
||||
|
||||
if (!EVP_DecryptInit_ex(ctx.get(), EVP_aes_256_cbc(), nullptr, key.data(), reinterpret_cast<const unsigned char *>(in.data())))
|
||||
if (!EVP_DecryptInit_ex(ctx.get(), EVP_aes_256_cbc(), nullptr, key.data(),
|
||||
reinterpret_cast<const unsigned char *>(in.data())))
|
||||
throw Exception("Error decrypting!");
|
||||
|
||||
|
||||
if (!EVP_DecryptUpdate(ctx.get(), reinterpret_cast<unsigned char *>(out.data()), &outlen, reinterpret_cast<const unsigned char *>(in.data() + 32), static_cast<int>(in.size() - 32)))
|
||||
if (!EVP_DecryptUpdate(ctx.get(), reinterpret_cast<unsigned char *>(out.data()), &outlen,
|
||||
reinterpret_cast<const unsigned char *>(in.data() + 32), static_cast<int>(in.size() - 32)))
|
||||
throw Exception("Error decrypting!");
|
||||
|
||||
int finlen = 0;
|
||||
@@ -70,13 +73,9 @@ std::vector<char> AES::decrypt(const std::vector<char> &in, const std::array<uin
|
||||
|
||||
std::array<uint8_t, 32> AES::deriveKey(const std::string &password, const std::string &salt) {
|
||||
std::array<uint8_t, 32> key;//NOLINT
|
||||
if (!PKCS5_PBKDF2_HMAC_SHA1(password.data(),
|
||||
static_cast<int>(password.length()),
|
||||
reinterpret_cast<const unsigned char *>(salt.data()),
|
||||
static_cast<int>(salt.length()),
|
||||
10000,
|
||||
32,
|
||||
key.data()))
|
||||
if (!PKCS5_PBKDF2_HMAC_SHA1(password.data(), static_cast<int>(password.length()),
|
||||
reinterpret_cast<const unsigned char *>(salt.data()), static_cast<int>(salt.length()),
|
||||
10000, 32, key.data()))
|
||||
throw Exception("Error deriving key!");
|
||||
return key;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user