SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Toggle main menu visibility
Loading...
Searching...
No Matches
AES.cpp
Go to the documentation of this file.
1
#include <
sourcepp/crypto/AES.h
>
2
3
#include <tomcrypt.h>
4
5
#include <
sourcepp/crypto/Globals.h
>
6
7
using namespace
sourcepp
;
8
9
namespace
sourcepp::crypto
{
10
11
const
std::array<std::byte, 16>
NULL_IV
{};
12
13
}
// namespace sourcepp::crypto
14
15
bool
crypto::decryptAES_CFB
(std::span<std::byte> buffer, std::span<const std::byte> key, std::span<const std::byte> iv) {
16
if
(!
LTM_MATH
||
AES_INDEX
< 0 || buffer.empty()) {
17
return
{};
18
}
19
20
const
std::unique_ptr<symmetric_CFB, void(*)(symmetric_CFB*)> cfb{
new
symmetric_CFB, [](symmetric_CFB* c) { cfb_done(c);
delete
c; }};
21
if
(cfb_start(
AES_INDEX
,
reinterpret_cast<
const
unsigned
char
*
>
(iv.data()),
reinterpret_cast<
const
unsigned
char
*
>
(key.data()),
static_cast<
int
>
(key.size()), 0, cfb.get()) != CRYPT_OK) {
22
return
{};
23
}
24
const
unsigned
long
bufferLen = buffer.size();
25
return
cfb_decrypt(
reinterpret_cast<
const
unsigned
char
*
>
(buffer.data()),
reinterpret_cast<
unsigned
char
*
>
(buffer.data()), bufferLen, cfb.get()) == CRYPT_OK;
26
}
27
28
bool
crypto::encryptAES_CFB
(std::span<std::byte> buffer, std::span<const std::byte> key, std::span<const std::byte> iv) {
29
if
(!
LTM_MATH
||
AES_INDEX
< 0 || buffer.empty()) {
30
return
{};
31
}
32
33
const
std::unique_ptr<symmetric_CFB, void(*)(symmetric_CFB*)> cfb{
new
symmetric_CFB, [](symmetric_CFB* c) { cfb_done(c);
delete
c; }};
34
if
(cfb_start(
AES_INDEX
,
reinterpret_cast<
const
unsigned
char
*
>
(iv.data()),
reinterpret_cast<
const
unsigned
char
*
>
(key.data()),
static_cast<
int
>
(key.size()), 0, cfb.get()) != CRYPT_OK) {
35
return
{};
36
}
37
const
unsigned
long
bufferLen = buffer.size();
38
return
cfb_encrypt(
reinterpret_cast<
const
unsigned
char
*
>
(buffer.data()),
reinterpret_cast<
unsigned
char
*
>
(buffer.data()), bufferLen, cfb.get()) == CRYPT_OK;
39
}
AES.h
Globals.h
sourcepp::crypto
Definition
Adler32.h:8
sourcepp::crypto::decryptAES_CFB
bool decryptAES_CFB(std::span< std::byte > buffer, std::span< const std::byte > key, std::span< const std::byte > iv=NULL_IV)
Definition
AES.cpp:15
sourcepp::crypto::AES_INDEX
const int AES_INDEX
Definition
Globals.cpp:12
sourcepp::crypto::LTM_MATH
const bool LTM_MATH
Definition
Globals.cpp:7
sourcepp::crypto::encryptAES_CFB
bool encryptAES_CFB(std::span< std::byte > buffer, std::span< const std::byte > key, std::span< const std::byte > iv=NULL_IV)
Definition
AES.cpp:28
sourcepp::crypto::NULL_IV
const std::array< std::byte, 16 > NULL_IV
Definition
AES.cpp:11
sourcepp
Definition
LZMA.h:11
src
sourcepp
crypto
AES.cpp
Generated on
for SourcePP by
1.17.0