-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathaes.h
73 lines (63 loc) · 1.76 KB
/
aes.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* .============.
* // M A K E / \
* // C++ DEV / \
* // E A S Y / \/ \
* ++ ----------. \/\ .
* \\ \ \ /\ /
* \\ \ \ /
* \\ \ \ /
* -============'
*
* Copyright (c) 2018 Hevake and contributors, all rights reserved.
*
* This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
* Use of this source code is governed by MIT license that can be found
* in the LICENSE file in the root of the source tree. All contributing
* project authors may be found in the CONTRIBUTORS.md file in the root
* of the source tree.
*/
#ifndef TBOX_CRYPTO_AES_H_20221219
#define TBOX_CRYPTO_AES_H_20221219
#include <cstdint>
namespace tbox {
namespace crypto {
/**
* AES 加密 & 解密,仅实现单个块的运算
*
* 示例:
* char key[16] = { ... }; //! 密钥,任意16字节
* char plain_text[16] = { ... }; //! 明文,任意16字节
* char crypto_text[16]; //! 密文
* AES aes(key);
* aes.cipher(plain_text, crypto);
*/
class AES {
public:
AES(const uint8_t *key);
/**
* \brief 设置密钥
* \param key 密钥地址,16字节长度
*/
void setKey(const uint8_t *key);
/**
* \brief 加密
* \param input 明文输入地址,16字节长度
* \param output 密文输出地址,16字节长度
*/
void cipher(const uint8_t *input, uint8_t *output);
/**
* \brief 解密
*
* \param input 密文输入地址,16字节长度
* \param output 明文输出地址,16字节长度
*/
void invcipher(const uint8_t *input, uint8_t *output);
private:
void keyExpansion(const uint8_t *key);
private:
uint8_t w[11][4][4];
};
}
}
#endif //TBOX_CRYPTO_AES_H_20221219