-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathAESParameters.h
More file actions
54 lines (40 loc) · 1.46 KB
/
AESParameters.h
File metadata and controls
54 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.
#pragma once
#include "Data.h"
#include <nlohmann/json.hpp>
#include <TrustWalletCore/TWStoredKeyEncryption.h>
namespace TW::Keystore {
enum AESKeySize : std::int32_t {
Uninitialized = 0,
A128 = 16,
A192 = 24,
A256 = 32,
};
inline constexpr std::size_t gBlockSize{16};
inline constexpr const char* gAes128Ctr{"aes-128-ctr"};
inline constexpr const char* gAes192Ctr{"aes-192-ctr"};
inline constexpr const char* gAes256Ctr{"aes-256-ctr"};
enum class AESValidationError {
InvalidIV,
};
std::string toString(AESValidationError error);
// AES128/192/256 parameters.
struct AESParameters {
// For AES, your block length is always going to be 128 bits/16 bytes
std::int32_t mBlockSize{gBlockSize};
std::int32_t mKeyLength{A128};
std::string mCipher{gAes128Ctr};
TWStoredKeyEncryption mCipherEncryption{TWStoredKeyEncryptionAes128Ctr};
Data iv;
/// Initializes `AESParameters` with a encryption cipher.
static AESParameters AESParametersFromEncryption(TWStoredKeyEncryption encryption);
/// Initializes `AESParameters` with a JSON object.
static AESParameters AESParametersFromJson(const nlohmann::json& json, const std::string& cipher);
/// Saves `this` as a JSON object.
nlohmann::json json() const;
/// Validates AES parameters.
[[nodiscard]] std::optional<AESValidationError> validate() const noexcept;
};
} // namespace TW::Keystore