UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AES.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "HAL/UnrealMemory.h"
7
8// AES-256 implementation - using ECB mode for multiple blocks
9
10// The currently implemented approach has the shortcoming that it encrypts and decrypts each
11// 128-bit block separately. If the plaintext contains identical 128-byte blocks, the blocks
12// will be encrypted identically. This makes some of the plaintext structure visible in the
13// ciphertext, even to someone who does not have the key.
14
15// DO NOT USE this functionality for any new place where you might need encryption. Because
16// current code is meant for keeping backwards compatiblity with existing data. Better way
17// to use AES would be integrated with authentication, for example, in AES-GCM mode.
18
19struct FAES
20{
21 static constexpr uint32 AESBlockSize = 16;
22
26 struct FAESKey
27 {
28 static constexpr int32 KeySize = 32;
29
31
33 {
34 Reset();
35 }
36
37 bool IsValid() const
38 {
39 uint32* Words = (uint32*)Key;
40 for (int32 Index = 0; Index < KeySize / 4; ++Index)
41 {
42 if (Words[Index] != 0)
43 {
44 return true;
45 }
46 }
47 return false;
48 }
49
50 void Reset()
51 {
53 }
54
55 bool operator == (const FAESKey& Other) const
56 {
57 return FMemory::Memcmp(Key, Other.Key, KeySize) == 0;
58 }
59 };
60
68 static CORE_API void EncryptData(uint8* Contents, uint64 NumBytes, const FAESKey& Key);
69
77 static CORE_API void EncryptData(uint8* Contents, uint64 NumBytes, const ANSICHAR* Key);
78
87 static CORE_API void EncryptData(uint8* Contents, uint64 NumBytes, const uint8* KeyBytes, uint32 NumKeyBytes);
88
96 static CORE_API void DecryptData(uint8* Contents, uint64 NumBytes, const FAESKey& Key);
97
105 static CORE_API void DecryptData(uint8* Contents, uint64 NumBytes, const ANSICHAR* Key);
106
115 static CORE_API void DecryptData(uint8* Contents, uint64 NumBytes, const uint8* KeyBytes, uint32 NumKeyBytes);
116};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::ANSICHAR ANSICHAR
An ANSI character. Normally a signed type.
Definition Platform.h:1131
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
U16 Index
Definition radfft.cpp:71
Definition AES.h:27
FAESKey()
Definition AES.h:32
uint8 Key[KeySize]
Definition AES.h:30
void Reset()
Definition AES.h:50
bool IsValid() const
Definition AES.h:37
static constexpr int32 KeySize
Definition AES.h:28
bool operator==(const FAESKey &Other) const
Definition AES.h:55
Definition AES.h:20
static constexpr uint32 AESBlockSize
Definition AES.h:21
static CORE_API void DecryptData(uint8 *Contents, uint64 NumBytes, const FAESKey &Key)
Definition AES.cpp:1129
static CORE_API void EncryptData(uint8 *Contents, uint64 NumBytes, const FAESKey &Key)
Definition AES.cpp:1110
static UE_FORCEINLINE_HINT int32 Memcmp(const void *Buf1, const void *Buf2, SIZE_T Count)
Definition UnrealMemory.h:114
static UE_FORCEINLINE_HINT void * Memset(void *Dest, uint8 Char, SIZE_T Count)
Definition UnrealMemory.h:119